2

I'm interested in techniques to perform multiple sends/contract calls inside of a single transaction but with the EOA that originates the transaction still being the sender for all operations (not a wallet contract or other non-EOA account).

Is it possible in either solidity or EVM assembly to have a transaction (as opposed to an inter-contract call) use delegatecall? It would be great if an EOA could claim the operations of a library contract as its own while retaining the EOA's msg.sender and msg.value.

Example flow:

My externally owned secp256k1 account delegatecalls a contract library X whose solidity code a) calls some other contract Y to check whether a certain variable is equal to a certain value, and then b) calls the method of a different contract Z if and only if it is, sending along 1 ETH.

Both the call to Y to check the variable in a), and the call to the method of Z in b) should have msg.sender being my externally owned secp256k1 account, and the outward send/call in b) should spend the balance of my externally owned secp256k1 account. Neither X nor Y should think anything different has happened than just that they were directly called by my EOA.

  • I think delegatecall does exactly that. Find this in the docs solidity.readthedocs.io/en/develop/… (see call and delegatecall section) – joifsi Jun 7 '17 at 15:18
  • 2
    I don't think you understand. Delegatecall certainly does this when a contract delegatecalls a code library. I'm asking about whether I can do this from an externally owned account in a transaction itself (the externally signed lump of code I submit with a transaction fee attached to perform an action on the chain). – Jeff Coleman Jun 7 '17 at 19:17
7
+25

DELEGATECALL is an instruction interpreted by EVM. So to execute DELEGATECALL you have to have a program (contract) that gets executed on EVM.

DELEGATECALL takes six operands, one of them is the address of the calee. So it can only call deployed contracts. Note that so called library is just a special contract which operations are called with DELEGATECALL.

So to answer your question directly as I understand it: No - it is not possible to execute arbitrary code from an external account.

What you can do though is you can create a contract that implements the logic as you want it and uses DELEGATECALL to preserve sender and value when calling other contracts.

  • I'm pretty sure your answer is correct, but for the sake of completeness: the function signature and arguments referenced by an externally-signed transaction do have to get translated into EVM opcodes at some point. Can you specifically clarify that this process is unable to result in a delegatecall operation? – Jeff Coleman Jun 14 '17 at 2:36
  • Because data field in the transaction payload can only specify contract methods and arguments - it is completely different language, not EVM bytecode. See: github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI – Michał Kłeczek Jun 14 '17 at 8:28
  • Right, but when this non-EVM encoded content is actually run, the EVM does get fired up to process the function call. That was the process I was referring to. – Jeff Coleman Jun 15 '17 at 1:43
  • Exactly. The existing contract function is called. Whether this function uses DELEGATECALL is up to this function implementation. But it has to be deployed on the blockchain beforehand. There is no way you can execute DELEGATECALL by just providing some data in the transaction payload. – Michał Kłeczek Jun 16 '17 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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