7

using for example inline assembly with calldatacopy(t, f, s), which copies s bytes from calldata at position f to memory at position t

in a call to for example function newContract(bytes data) { ... }

is it possible for a contract to know at what position in the callcode the data bytecode begins ?

3

The general answer is that it follows the conventions of the ABI. You can work it out based on those rules.

In this particular case, the encoding of data will start at position 36. The first four bytes will be the message signature, and the next 32 will be a pointer to the location of data's representation.

Note that the first 32 bytes of data will give the length parameter, so if you actually want just the raw data inside the bytes, that begins at 68.

  • This is the answer for parsing calldata in a function, but is it the same if the function is invoked by callcode? The question asks about calldata within a callcode... won't the calldata be different from the original calldata? (An example could also be helpful.) – eth Jun 13 '16 at 11:32
  • I don't believe the question is actually asking about callcode, it seems to be a typo for calldata. That said, my understanding is that it should be the same. callcode and delegatecall attempt to work as similarly to a normal message as possible. One place where it might be different is solidity "internal" functions. To be honest, I don't fully understand how those work. – PeterBB Jun 14 '16 at 3:49

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.