Most ERC20 contracts have a permit function that can be called, while WETH does not.
- Victim gives infinite approval for
ERC20Bank.solto spendWETH. - Victim calls
depositand deposits 1WETHintoERC20Bank. - Attacker calls
depositWithPermitand passes an empty signature and transfers all tokens from Victim intoERC20Bank, which is credited to the attacker's deposit inERC20Bank. - Attacker calls
withdrawfunction.
- Install Foundryup.
- Run the following command in your directory to install dependecies
forge install foundry-rs/forge-std. - Run the following to build your contract
forge build. - Run
forge test -vvvto execute your tests.