In this challenge the user is provided with a contract called Delegate.sol
. The goal of this challenge claim the ownership of the contract.
This challenge requires user to be familiar with the following concepts..
- Solidity
delegtecall
function & storage layout. - Fallback functions.
- We can simply invoke fallback of Delegation which has the exact same storage variable layout as Delegate. It will make a
delegatecall
to Delegate contract which will set the owner to out address i.emsg.sender
. - This storage layout is important because whenever a
delegatecall
is made to another contractmsg.sender
&msg.value
are preserved but the storage changes will be made to the contract from which thdelegatecall
started. - In other word, whenever a
delegatecall
is made fromA
to function in another contractB
that function behaves as it was the the part of the contractA
. If any state changes are made, they are made in contractA
storage.
- Run Exploit!
forge test -vv -m test_challenge_6