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( )?
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
.