From f2db669da93ca4ce1605866e147bfa4f56303fc6 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 30 Nov 2022 16:17:09 +0100 Subject: [PATCH] Clarifications to EIP-663 (#6055) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Rewrite the specification of EIP-663 * Some wording improvements Co-authored-by: Paweł Bylica * Linter 😳 Co-authored-by: Paweł Bylica --- EIPS/eip-663.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/EIPS/eip-663.md b/EIPS/eip-663.md index b8ae76e96466d..2b3f8bd0c4ade 100644 --- a/EIPS/eip-663.md +++ b/EIPS/eip-663.md @@ -36,14 +36,20 @@ If the code is legacy bytecode, both of these instructions result in an *excepti If the code is valid EOF1, the following execution rules apply: -These instructions are followed by an 8-bit immediate value, which we call `imm`, and can have a value of 0 to 255. We introduce the variable `n` which equals to `imm + 1`. + 1. These instructions are followed by an 8-bit immediate value, which we call `imm`, and can have a value of 0 to 255. We introduce the variable `n` which equals to `imm + 1`. -If the current stack depth is less than `n`, then a stack underflow exception is issued. If the current stack depth is at the limit, a stack overflow exception is issued. In both of these cases the EVM stops and all gas is consumed. + 2. For `DUPN`: -Otherwise + - If the current stack height is less than `n`, then a stack underflow exception is issued. + - If the current stack height is at the limit (1024), a stack overflow exception is issued. + - Otherwise the `n`'th stack item is duplicated at the top of the stack. (*Note: We use 1-based indexing here.*) -- for `DUPN` the stack item at depth `n - 1` is duplicated at the top of the stack -- for `SWAPN` the top stack item is swapped with the item at depth `n` + 3. For `SWAPN`: + + - If the current stack height is less than `n + 1`, then a stack underflow exception is issued. + - Otherwise the `n + 1`th stack item is swapped with the top stack item. + +Clarification: the "stack underflow/overflow exception" means the EVM execution is halted and all gas is consumed. The gas cost for both instructions is set at 3.