You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: EIPS/eip-663.md
+23-26Lines changed: 23 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,29 +31,26 @@ Introducing `SWAPN`, `DUPN` and `EXCHANGE` will provide an option to compilers t
31
31
32
32
We introduce two new instructions:
33
33
34
-
1.`DUPN` (`0xe6`)
35
-
1.`SWAPN` (`0xe7`)
36
-
2.`EXCHANGE` (`0xe8`)
34
+
1.`DUPN` (`0xe6`)
35
+
2.`SWAPN` (`0xe7`)
36
+
3.`EXCHANGE` (`0xe8`)
37
37
38
38
If the code is legacy bytecode, any of these instructions result in an *exceptional halt*. (*Note: This means no change to behaviour.*)
39
39
40
40
If the code is valid EOF1, the following rules apply:
41
41
42
-
1. The instructions are followed by an 8-bit immediate value, which we call `imm`, and can have a value of 0 to 255.
43
-
1.1 In the case of `DUPN` and `SWAPN`, we introduce the variable `n` which equals to `imm + 1`.
44
-
1.2 In the case of `EXCHANGE`, we introduce the variable `n` which is equal to `imm >> 4 + 1`, and the variable `m` which is equal to `imm & 0x0F + 1` (i.e., the first and second nibbles of `imm`, converted to one-indexing).
45
-
46
-
2. Code validation is extended to check that no relative jump instruction (`RJUMP`/`RJUMPI`/`RJUMPV`) targets immediate values of `DUPN`, `SWAPN` or `EXCHANGE`.
47
-
48
-
3. The stack validation algorithm of [EIP-5450](./eip-5450.md) is extended:
49
-
3.1. Before `DUPN` if the current stack height is less than `n`, code is invalid. After `DUPN`, the stack height is incremented.
50
-
3.2. Before `SWAPN` if the current stack height is less than `n + 1`, code is invalid. After `SWAPN`, the stack height is unchanged.
51
-
3.2. Before `EXCHANGE` if the current stack height is less than `n + m + 1`, code is invalid. After `EXCHANGE`, the stack height is unchanged.
52
-
53
-
4. Execution rules:
54
-
4.1. `DUPN`: the `n`'th stack item is duplicated at the top of the stack. (*Note: We use 1-based indexing here.*)
55
-
4.2. `SWAPN`: the `n + 1`'th stack item is swapped with the top of the stack.
56
-
4.3 `EXCHANGE`: the `n + 1`'th stack item is swapped with the `n + m + 1`'th stack item.
42
+
1. The instructions are followed by an 8-bit immediate value, which we call `imm`, and can have a value of 0 to 255.
43
+
1. In the case of `DUPN` and `SWAPN`, we introduce the variable `n` which equals to `imm + 1`.
44
+
2. In the case of `EXCHANGE`, we introduce the variable `n` which is equal to `imm >> 4 + 1`, and the variable `m` which is equal to `imm & 0x0F + 1` (i.e., the first and second nibbles of `imm`, converted to one-indexing).
45
+
2. Code validation is extended to check that no relative jump instruction (`RJUMP`/`RJUMPI`/`RJUMPV`) targets immediate values of `DUPN`, `SWAPN` or `EXCHANGE`.
46
+
3. The stack validation algorithm of [EIP-5450](./eip-5450.md) is extended:
47
+
1. Before `DUPN` if the current stack height is less than `n`, code is invalid. After `DUPN`, the stack height is incremented.
48
+
2. Before `SWAPN` if the current stack height is less than `n + 1`, code is invalid. After `SWAPN`, the stack height is unchanged.
49
+
3. Before `EXCHANGE` if the current stack height is less than `n + m + 1`, code is invalid. After `EXCHANGE`, the stack height is unchanged.
50
+
4. Execution rules:
51
+
1.`DUPN`: the `n`'th stack item is duplicated at the top of the stack. (*Note: We use 1-based indexing here.*)
52
+
2.`SWAPN`: the `n + 1`'th stack item is swapped with the top of the stack.
53
+
3 `EXCHANGE`: the `n + 1`'th stack item is swapped with the `n + m + 1`'th stack item.
57
54
58
55
The gas cost for all three instructions is set at 3.
59
56
@@ -88,14 +85,14 @@ This has no effect on backwards compatibility because the opcodes were not previ
88
85
89
86
Given `stack[]` is a 0-based data structure, and `n`, `m` and `imm` are defined as according to the spec:
90
87
91
-
- `DUPN imm` to fail validation if `stack_height < n`.
92
-
- `SWAPN imm` to fail validation if `stack_height < n + 1`.
93
-
- `EXCHANGE imm` to fail validation if `stack_height < n + m + 1`.
94
-
- `DUPN imm` to increment maximum stack height of a function. Validation fails if maximum stack height exceeds limit of 1023.
95
-
- `DUPN imm`, `SWAPN imm`, and `EXCHANGE imm` to fail at run-time if gas available is less than 3.
96
-
- `DUPN imm` should duplicate the `stack[n - 1]` item and push it to the stack
97
-
- `SWAPN imm` should swap `stack[n]` with `stack[stack.top()]`
98
-
- `EXCHANGE imm` should swap `stack[n]` with `stack[n + m]`.
88
+
-`DUPN imm` to fail validation if `stack_height < n`.
89
+
-`SWAPN imm` to fail validation if `stack_height < n + 1`.
90
+
-`EXCHANGE imm` to fail validation if `stack_height < n + m + 1`.
91
+
-`DUPN imm` to increment maximum stack height of a function. Validation fails if maximum stack height exceeds limit of 1023.
92
+
-`DUPN imm`, `SWAPN imm`, and `EXCHANGE imm` to fail at run-time if gas available is less than 3.
93
+
-`DUPN imm` should duplicate the `stack[n - 1]` item and push it to the stack
94
+
-`SWAPN imm` should swap `stack[n]` with `stack[stack.top()]`
95
+
-`EXCHANGE imm` should swap `stack[n]` with `stack[n + m]`.
0 commit comments