Solidity Delegatecall Attack
Solidity’s delegatecall is vulnerable to override the storage values in the caller contract.
Last updated
Solidity’s delegatecall is vulnerable to override the storage values in the caller contract.
Last updated
Reference:
Below is the example contracts from Ethernaut. That uses delegatecall
method in the fallback()
function.
Call the pwn
function by sending transaction because delegatecall
exists in fallback
function. This changes the owner of the DelegateA contract to msg.sender
because the delegatecall
overrides the slot value in the callee contract (it's DelegateA). In short, we can become the owner of this contract.
If the contract is upgradeable using Proxy contract and the slot order is difference, we may be able to manipulate arbitrary slot values with delegatecall.