0

let's assume following solidity contracts:

 contract EntryPointContract {

    address one = '0x...';
    address two = '0x...';
    address delegateContract;

    constructor(address _delegateContract) {
        delegateContract = _delegateContract;
    }
 
    function test() public returns(bool) {

        (bool success,) = delegateContract.call(abi.encodeWithSignature("checkSender()"));
        return success
    }

}

contract DelegateContract {

    function checkSender() public {
        msgs = msg.sender;
    }
    
} 

Can I modify the EntryPointContract in some way that i will get address one value from EntryPointContract as msg.sender in DelegateContract ? Is it doable with assembly or opcodes for example or another way?

1 Answer 1

0

In Solidity, it is not possible to directly set msg.sender in the called contract (DelegateContract) to a specific address like address one from EntryPointContract. The msg.sender is determined by the caller of the contract, and it cannot be manipulated within the contract itself.

The msg.sender in DelegateContract will always be the address of the contract or external entity that calls the checkSender() function. You cannot change this behavior through assembly, opcodes, or any other means within the Solidity code.

If you need to pass specific information to DelegateContract that you want to be treated as the sender, you would need to pass it as an argument to a function in DelegateContract. For example:

contract EntryPointContract {
    address one = '0x...';
    address delegateContract;

    constructor(address _delegateContract) {
        delegateContract = _delegateContract;
    }
 
    function test() public returns(bool) {
        bool success = DelegateContract(delegateContract).checkSender(one);
        return success;
    }
}

contract DelegateContract {
    address public sender;

    function checkSender(address specificSender) public {
        sender = specificSender;
    }
}

In this modified example, the test() function of EntryPointContract explicitly passes the desired sender address (one) to the checkSender() function in DelegateContract.

3
  • for exmaple what if DelagateContract is already deployed and I need somehow pass 'address one' in msg.sender? Sep 18 at 14:53
  • In this case, if the contract is upgradable, the code can be changed and the new method implemented, otherwise it cannot be done and it must be redeployed.
    – Mehran Ra
    Sep 18 at 15:57
  • Read this link, maybe it can give you an idea: soliditydeveloper.com/erc20-permit
    – Mehran Ra
    Sep 18 at 16:04

Your Answer

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

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