-
Notifications
You must be signed in to change notification settings - Fork 19
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
Change definition of m
in EXCHANGE
#174
base: main
Are you sure you want to change the base?
Conversation
m
in EXCHANGE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Interesting that EEST's Making a self note to propose a change for evmone to align, if we decide to go ahead here. And in general, I think I support this change, but I'd like to hear from others too. |
- `n = imm >> 4 + 1`, `m = imm & 0x0F + 1` | ||
- `n + 1`th stack item is swapped with `n + m + 1`th stack item (1-based). | ||
- Stack validation: `stack_height >= n + m + 1` | ||
- `i = imm >> 4`, `j = imm & 0x0F` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I didn't see this has been changed to i/j already. I propose to align with EEST (and be compatible with past version), so:
- n and m remain what they were
- x and y are the new args
- end with: "
x
th stack item is swapped withy
th stack item (1-based)."
This way, any EVM/test/whatever code, which doesn't update to your convention, still uses the same names for the same things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given the SWAPn/SWAPN/EXCHANGE consistency argument, I take the above comment back. Pls make sure then that conventions are sound within this document (I think they are as of 44b5781), and I think we'll work from there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
welp, there's no equivalence with the old SWAP1..16, but that I think is not fixable, so
EXCHANGE x y ≡ SWAPN x SWAPN y SWAPN x ≡ SWAP[x-1] SWAP[y-1] SWAP[x-1]
encoded in bytecode as
0xe8nibble[x-2]nibble[y-x-1] ≡ 0xe7[x-2] 0xe7[y-2] 0xe7[x-2] ≡ 0x[90+x-2][90+y-2][90+x-2]
Concretely
EXCHANGE 2 3 ≡ SWAPN 2 SWAPN 3 SWAPN 2 ≡ SWAP1 SWAP2 SWAP3
0xe800 ≡ 0xe700e701e700 ≡ 0x909190
The not fixable part can be swept under the rug by the assembler, which would not allow verbatim SWAP1..16 in assembler code, but would use them in output bytecode for low instances of SWAPN[...] as optimization.
I risk to say that DUP/DUPN are aligned (and similarly "unfixable" and it's similarly "fine"). But please double check my above ramblings, I made like 3 errors in the +-1
's there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the notation/encoding I have in mind. For example, I'd write SWAPN 1
(n=1, encoded 0xe700
) as equivalent to SWAP1
(0x90
).
I'm going to write some more comprehensive notes to try to get everyone aligned.
Based on this test it looks like The problem with this is that it doesn't match the established notation for
My understanding is that in EEST It's true that the current definitions of |
This seems to refer to the SWAPN indexing, whereby But I would expect Edited to fix the encoding. |
I think I'm open to
By the way I think it's the other way around, |
Yes, good point. I think this should take precedence and EEST/code needs to be cleaned up if necessary. |
I described 3 possible approaches in this document: https://hackmd.io/@frangio/Bk4Vjj6V1l My original proposal was the Traditional approach. @wjmelements is vouching for the Exact approach. I feel pretty strongly that |
Thanks, this is really helpful. I personally prefer Exact on all 3 EIP-663 instructions, departing from both SWAPn/DUPn instructions (which, as I proposed in the other comment, can possibly be removed from the assembly language). To me SWAPn/DUPn were always confusing and inconsistent, to the point I don't really treat the "n"s there seriously. If you look at them in conjunction with PUSHn and (taking the argument to the extreme - CREATEn, MSTOREn, LOGn), n is something else every time. We should detach from this convention when we have the chance. I even prefer Verbatim over Traditional |
The encoding of the operands in the bytecode remains the same, but conceptually
m
is defined as an absolute stack depth rather than relative ton
.This is meant to be reflected in the textual representation of the instruction in assembly, which should be
EXCHANGE n m
. The notation should be more intuitive with this change. In particular:EXCHANGE n m
andEXCHANGE m n
are equivalent.EXCHANGE n m
can be understood as exactly equivalent toSWAPN n SWAPN m SWAPN n
(minus different valid ranges for n,m).