Closed jamil-wittmann closed 1 year ago
Solved.
The recover_weth function takes in an input that dictates the amt of weth to withdraw, if this value isn't passed then it will just try withdrawing 0. so in this case to recover 0.005 weth, you first convert 0.005 weth to wei and then convert the wei value to hex. This means that the calldata to recover ur weth will be equal to
0x420000000000000000000000000000000000000000000000000011C37937E08000
@jamil-wittmann Do you mind posting the exact command you used ? I am having issues recovering.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import {IWETH} from "../interfaces/IWETH.sol";
import "forge-std/Script.sol";
import "forge-std/console.sol";
contract RecoverWeth is Script {
IWETH weth = IWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
address sandwich;
address admin;
address helper;
// serachers
function setUp() public {
//change this
sandwich = 0x0000000000000000000000000000000000000000;
}
function run() public view {
console.log(address(sandwich));
uint256 sandwichBalanceBefore = weth.balanceOf(sandwich);
console.log("Sandwich Balance: %s", sandwichBalanceBefore);
//string memory functionName = "recoverWeth"; //0x42 or 66
bytes memory payload = abi.encodePacked(
uint8(66),
sandwichBalanceBefore
);
console.log("Payload: ");
console.logBytes(payload);
}
}
//save this file to "contract/script" folder and run the following commands from "contract" folder
//forge script ./script/RecoverWeth.s.sol --rpc-url http://127.0.0.1:8545
//get the payload hex from the logs
//cast send --rpc-url http://127.0.0.1:8545 --private-key <xxxx> <sandwich address> <payload hex>
I deployed the sandwich contract and I've been able to interact with it using foundry's "cast send" commands. I was able to successfully Seppuku one of the contracts I deployed so I'm at least sure that I'm using the command correctly in some capacity.
However, I've deposited some Weth to the contract and I've attempted to use the "cast send" with JUMPDEST 0x42 so that I can Recover the Weth I sent to the contract. The command works to some degree but for some reason the wad it passes stays at 0 which makes it impossible for me to recover my Weth.
Here is the transaction on etherscan: https://etherscan.io/tx/0xd9a9caf2bef63eea110c1596d655aa5926c95f4dec6af35706748e84ba47e2ce
Here is the log: https://etherscan.io/tx/0xd9a9caf2bef63eea110c1596d655aa5926c95f4dec6af35706748e84ba47e2ce#eventlog
In the log you can see that the command is correctly using the addresses but the wad is 0.
Am I missing something? How can I recover the Weth on the contract <3