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](https://private-user-images.githubusercontent.com/29842127/277123199-043a1b8b-0a39-4cc8-a2b7-a64947e92264.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM3MDkzNzAsIm5iZiI6MTcyMzcwOTA3MCwicGF0aCI6Ii8yOTg0MjEyNy8yNzcxMjMxOTktMDQzYTFiOGItMGEzOS00Y2M4LWEyYjctYTY0OTQ3ZTkyMjY0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE1VDA4MDQzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg2MWQ4MDMxYTAxNDUzMWJmZWY5ZmFiM2FjY2VkMWJkOGE2MmNhMTFjNGE1NTM5NDVmNTczNzhhNWIxZTk3ZmYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0._ve2JI62SwBRR4p6cOaka5i5xikcon_wuCqP1WI5ZZk)
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
}