8

Solidity docs say "only the code of the given address is used, all other aspects (storage, balance, ...) are taken from the current contract." This is useful when creating a library.

But what happens if you chain delegatecall( )?

1 Answer 1

6

Chains of delegatecall(..) will still retain the original msg.sender, storage, balance, etc values from the calling contract.

contract A {
    function indirect() {
        B.doit();
    }
    function direct() {
        C.doit();
    }
}

library B {
    function doit() {
        C.doit();
    }
}

library C {
    function doit() {
        msg.sender.send(this.balance);
    }
}

In the above set of contracts, A.direct() and A.indirect() will behave the same. The only difference is that A.indirect() will involve an additional stack depth increase since it chains A > B > C rather than directly from A > C.

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.