3

When the user calls the delegatecallSetN function of contract D below, the msg.sender in contract E is the address of the user (as shown in this example).

contract D {
  uint public n;
  address public sender;

  function delegatecallSetN(address _e, uint _n) {
    _e.delegatecall(bytes4(sha3("setN(uint256)")), _n); // D's storage is set, E is not modified 
  }
}

contract E {
  uint public n;
  address public sender;
  function setN(uint _n) {
    n = _n;
    sender = msg.sender;
  }
}

My question is: How can we check in contract E that the call was done through contract D and not directly through the user?

1
  • stackoverflow.com/questions/37644395/… .. Please look at Manuel Aráoz Answer.. I think you can make use of Iscontract function mentioned and check only Contract D has invoked Contract E and not by user.
    – Rangesh
    Commented Sep 11, 2017 at 17:35

2 Answers 2

2

Should work if you use tx.origin. However this is usually advised against.

1

See this answer, https://stackoverflow.com/a/40939341/7482810

using some EVM assembly code to get the address' code size:

 function isContract(address addr) returns (bool) {
 uint size;
 assembly { size := extcodesize(addr) }
 return size > 0;}

As to why this function works, see https://ethereum.stackexchange.com/a/14016/19016

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.