10

The RETURN opcode in the EVM takes 2 arguments(ie, consumes two elements from the stack), but what do they represent? I tried to understand the yellow paper describing them, but I don't understand the notation used.

For reference this is the section in the yellow paper: enter image description here

Earlz
  • 471
  • 4
  • 16

1 Answers1

5

The 2 arguments to the RETURN opcode are a starting offset and length specifying a segment of memory.

The EVM execution is stopped and data consisting of the memory bytes from [start, start+len-1] are the output of the execution.

Example:

If memory is [5, 6, 7, 8, 9, 10], a return with starting offset=1 and length=4 would produce a result (output) of 4 bytes (6, 7, 8, 9).

eth
  • 85,679
  • 53
  • 285
  • 406
  • 1
    Memory as in the "storage" mechanism, or as in treating the stack like a flat array of memory? – Earlz Aug 15 '16 at 21:17
  • Memory as what is stored by the MSTORE opcode. – eth Aug 15 '16 at 23:27
  • By chance do you know of a "plain text" reference for all the opcode arguments? Other than the yellow paper's mathy notation, I can't find any actual reference beyond the code itself (which isn't always too clear) – Earlz Aug 16 '16 at 17:52
  • Regarding EVM code, since there's implementations across a number of languages that may help reason about them. I don't know of a simpler reference and IMHO a new, clearer reference is more than welcome but it should still be complete. – eth Aug 17 '16 at 11:00
  • You may find our implementation is fairly readable reference for opcodes (though I would like increase the number of comments there): https://github.com/eris-ltd/eris-db/blob/develop/manager/eris-mint/evm/vm.go#L187. @Ethan has a nice low-level guide, though not completely comprehensive as a spec https://github.com/ebuchman/evm-tools/blob/master/analysis/guide.md. I too would like to see the Ethereum spec presented in a more appropriate format than the yellow paper... – Silas Davis Oct 04 '16 at 14:47
  • The two arguments of RETURN are not start and end of the return data, but start and length. – gernot Sep 06 '22 at 17:20
  • @gernot Yikes, really try avoiding making a mistake through the years and should have been more careful on this one. Please comment if you see others answers with an error. Thanks. – eth Sep 07 '22 at 02:03