libevm / subway

A practical example on how to perform sandwich attacks on Ethereum
MIT License
2.14k stars 534 forks source link

Could you explain the calling of call() function in Sandwich.sol? #10

Closed Neronjust2017 closed 1 year ago

Neronjust2017 commented 1 year ago

Hi, I'm confused by the usage of the call function in the Sandwich contract.

 let s1 := call(sub(gas(), 5000), token, 0, 0x7c, 0x44, 0, 0)  
 let s2 := call(sub(gas(), 5000), pair, 0, 0x7c, 0xa4, 0, 0)

0x7c is the address of ERC20_TRANSFER_ID/PAIR_SWAP_ID bytes in the memory. According to https://ethervm.io/ ,
image this calls a method in another contract. For example, the first line calls the transfer function (ERC20_TRANSFER_ID) of the token, and the calldata is bytecodes from 0x7c to (0x7c+0x44), which means calling token.transfer(pair, amountIn), right? I'm confused because the amountIn is the amount of WETH and why transfer tokens to the pair address? And where can I find the signature of the contract function (for example, transfer(address,uint256), 0xa9059cbb) ? Thanks!

kr-manav commented 1 year ago

Its a syntax to call the function of smart contract in assembly language