The contract UnwrapAndSendETH
contains 2 critical issues:
It doesn't have access control. Anyone can call it and withdraw all the WETH from the contract. i.e. An attacker can monitor the mempool and check when this contract will receive any WETH/ETH, once this is done the bot can call the
unwrapAndSendETH
function and withdraw all the ETH balance from the contract.
The function doesn't validate the
to
address, if the address is an invalid zero address, funds will be lost.
Even though this contract can be used by the "Pipeline" from Beanstalk, it will depend totally on the Frontend/consumer logic to avoid customer losses either when a transaction is first done to load the contract with WETH or the recipient address is zero.
Any ETH/WETH sent to this contract will be completely lost. Drained by the attacker.
If the frontend/user passes an invalid address, funds will be burned/lost.
Prepare the environment to work with Foundry + Updated Mocks
https://gist.github.com/h0lydev/fcdb00c797adfdf8e4816031e095fd6c
To avoid compilation errors, UnwrapAndSendETH
should use the solidity version pragma solidity 0.7.6;
.
Make sure to have the mainnet forked through Anvil: anvil --fork-url https://rpc.ankr.com/eth
Create the UnwrapAndSendETH.t.sol
file under the folder foundry
and paste the code below. Then run forge test --match-contract UnwrapAndSendETHTest -vv
.
Output:
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 26.19s
Manual Review & Foundry
Add access control by adding the
onlyOwner
modifier from OZ(Ownable2Step). https://docs.openzeppelin.com/contracts/4.x/api/access
Check whether the address is valid
(Additional) consider adding a function to withdraw only ether in case any ether is sent accidentally to this contract.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.