When calling another smart contract using the standard way by specifying the interface of the smart contract being called and then calling that function as follows: contract.functionName(params)
, the Solidity compiler checks if the target function is marked as "view" or "pure" in its interface. However, when using delegatecall
, Solidity does not have knowledge of the exact function being called or whether it modifies the state or not.
A possible workaround would be to use the staticcall
function instead of delegatecall
. This would work as long as staticcall
is not invoking a function where the calling context (storage/state-variables, msg.sender, msg.value, etc..) needs to be preserved. Since delegatecall
preserves the calling context, while staticcall
doesn't. staticcall
works exactly the same as call
with only difference that it cannot modify state of the contract being called.