Skip to content

Commit 9cb01c7

Browse files
authored
Update EIP-663: Fix markdown rendering
Merged by EIP-Bot.
1 parent e469fd6 commit 9cb01c7

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

EIPS/eip-663.md

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,26 @@ Introducing `SWAPN`, `DUPN` and `EXCHANGE` will provide an option to compilers t
3131

3232
We introduce two new instructions:
3333

34-
1. `DUPN` (`0xe6`)
35-
1. `SWAPN` (`0xe7`)
36-
2. `EXCHANGE` (`0xe8`)
34+
1. `DUPN` (`0xe6`)
35+
2. `SWAPN` (`0xe7`)
36+
3. `EXCHANGE` (`0xe8`)
3737

3838
If the code is legacy bytecode, any of these instructions result in an *exceptional halt*. (*Note: This means no change to behaviour.*)
3939

4040
If the code is valid EOF1, the following rules apply:
4141

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.
5754

5855
The gas cost for all three instructions is set at 3.
5956

@@ -88,14 +85,14 @@ This has no effect on backwards compatibility because the opcodes were not previ
8885

8986
Given `stack[]` is a 0-based data structure, and `n`, `m` and `imm` are defined as according to the spec:
9087

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]`.
9996

10097
## Security Considerations
10198

0 commit comments

Comments
 (0)