Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Erroneous example in the Jump Labels section and ambiguous stack comments #82

Open
3Squ4red opened this issue Oct 21, 2023 · 0 comments

Comments

@3Squ4red
Copy link

The example given for the Jump Labels section in Huff By Examples, is causing stack underflow error on the mstore opcode under the success label. You can try it out here quickly.

image

It seems to me that 0x00 mstore part is unnecessary as the following line simply returns the "Hello, World!" string already stored in the memory (with some weird characters in the beginning cause of the padded zeroes which could be fixed with 0x0d 0x13 return).

Also, the comments representing the state of the stack seem a bit off.

Following is how I think the example should have been:

#define macro MAIN() = takes (0) returns (0) {
    // Store "Hello, World!" in memory
    0x48656c6c6f2c20576f726c6421 // ["Hello, World!"]
    0x00 mstore // [ ]

    // Jump to success label, skipping the revert statement
    success     // [success_label_pc]
    jump        // [ ]

    // Revert if this point is reached
    0x00 0x00 revert

    // Labels are defined within macros or functions, and are designated
    // by a word followed by a colon. Note that while it may appear as if
    // labels are scoped code blocks due to the indentation, they are simply
    // destinations to jump to in the bytecode. If operations exist below a label,
    // they will be executed unless the program counter is altered or execution is
    // halted by a `revert`, `return`, `stop`, or `selfdestruct` opcode.
    success:
        0x0d 0x13 return
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant