Ethernaut Delegation
The Delegate Call
In order for a contract to interact with other contracts, solidity provides 3 methods: call
, delegatecall
and staticcall
.
Call
The call
function is a way for one contract to interact with another contract by invoking its functions. This execution happens in the context of the called contract till returning the value and the context back to the calling contract.
DelegateCall
The delegatecall
function is how one can create libraries in ethereum. A contract having a bulk of functions that can have its methods used in various scenarios by other contracts, multiple times. This execution will happen in the context of the calling contract only.
StaticCall
The staticcall function is similar to the call, in the way that it also invokes other contract functions. However, it can only be used in read-only functions, as it makes sure the called function won’t change any state. In case the called function would change any state, the execution will be unsuccessful.
This post scope will mainly focus on the call
and delegatecall
solidity functions.
The challenge consists of two contracts, Delegate and Delegation. The Delegation contracts keeps track of the address of Delegate…