I know how to check if a current contract's function is been called using CALL or DELEGATECALL (by comparing address(this) to the contract's address that must have been previously saved as an immutable variable).

However I was wondering if it would be possible to check if a DELEGATECALL has taken place at any point in the transaction, for instance:

user -> Contract A -> (delegatecall) -> Contract B -> (call) -> Contract C

As far as I know from Contract's C perspective, it is receiving a CALL from Contract A and I do not really see any way for Contract C to "detect" the DELEGATECALL that took place between Contract A and B....

1 Answer 1


I think you are right, considering that you cannot control or write the logic in A and B, it seems impossible.

However, if we consider only your example of 3 contracts, there could be an expensive way to detect if A is a proxy or A has DELEGATECALL in it's code from smart contract C. When A (the caller) has DELEGATECALL or has bytecode similar to some of the popular proxy patterns, A may have used DELEGATECALL to call C. It can be done very expensive by copy A's bytecode into memory while executing contract C and analyze it. I think you may find this EXTCODECOPY opcode interesting: link . Assumming you can write your logic to analyze all the bytecode getting from EXTCODECOPY (msg.sender) in pure solidity to check if its bytecode is similar to a proxy, you may have a chance to say "it's probably delegate call".

But coming back to the question "any point" means it may be a long call chain and the DELEGATECALL could happen 5-10 calls in the chain before the target contract C. I think it's impossible on smart contract. The only way is to use evm tracing tx to check the execution trace like everyone is using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.