0

I have user A which calls contract B which calls contract C which calls contract D.
How to call external library D from contract C while preserving msg.sender==B ? Of course, I cannot use tx.origin since tx.origin is A.

User A created address of C and address of D, but not B.

DELEGATECALL isn’t the solution, isn’t it ?

3
  • 1
    Each times, the address (this) is different. Please note the answer is not tx.origin in anyway. Ever ! Jun 17, 2018 at 16:57
  • why not to pass B address as a parameter to C and have C to pass this as a parameter to D.
    – Jaime
    Jun 18, 2018 at 9:55
  • @Jaime because ERC20 interface of C is source code verifiable on etherescan whereas I would keep D closed source. The less parameters I’m passing to D, the less peoples would have an idea of D. Jun 18, 2018 at 16:33

2 Answers 2

2

From contract C you can make a delegatecall to D, this will preserve the sender (B)

But it will not change the storage, it will continue to access storage of contract C.

This only works if contract D doesn't need storage, or it was written to access storage from C (for example if D is a library contract).

1

It all depends if you're the author of all these contracts or not. You can achieve this with combinations of DELEGATECALL, see this answer. But always beware, if you are not the only one in charge of critical aspects of the contracts (e.g. when they have proxy features, so somebody could redirect calls to unexpected code) , I would not recommend relying on delegatecall. Another solution would be msg.sender as a function parameter to another contract, and passing that address to the next one, and so on.

1
  • But If I understand correctly, the answer you’re referencing seems to tell delagatecall can only be used for calling the same address (this of B would equals this of C) with other data. But in my case, I want to have contract C solidity code verified on etherscan.io and library D closed source (which is why I’d like to avoid knowing D uses msg.sender through C code) which means all contracts are stored into different addresses account. By depends if you're the author of all these contracts or not do you mean all stored at the same Ethereum address ? Jun 18, 2018 at 0:37

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.