Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/vm: Enhance Callable Opcodes #102

Merged
merged 1 commit into from
Apr 7, 2023
Merged

tools/vm: Enhance Callable Opcodes #102

merged 1 commit into from
Apr 7, 2023

Conversation

marioevz
Copy link
Member

@marioevz marioevz commented Apr 7, 2023

Makes Op opcodes callable and the resulting bytecode automatically sets the stack up.

If the opcode has data portion, the first argument is required and it becomes the data that is appended after the opcode.

The rest of the arguments are considered the stack, and they are appended before opcode byte, in LIFO order (the last argument is pushed first to the stack, and the first argument is pushed last).

E.g.

Op.SSTORE(
             -1,
             Op.CALL(
                 Op.GAS,
                 Op.ADDRESS,
                 Op.PUSH1(0x20),
                 0,
                 0,
                 0x20,
                 0x1234,
             ),
         ),

In this example, the Op.SSTORE saves the result of the Op.CALL into the 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff key of the storage, and the parameters of Op.CALL are pushed into the stack before its execution (0x1234 is pushed first to the stack using an implicit Op.PUSH2, then 0x20 using Op.PUSH1, and so on until Op.GAS).

@marioevz marioevz requested a review from spencer-tb April 7, 2023 23:24
Copy link
Collaborator

@spencer-tb spencer-tb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice! No more Opcode mistakes now (hopefully) 👍

@marioevz marioevz merged commit 6363b17 into main Apr 7, 2023
@marioevz marioevz deleted the callable-opcodes branch February 6, 2024 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants