From 6ac3649202cb569a3588e34a1a6915cebcb28b45 Mon Sep 17 00:00:00 2001 From: Magamedrasul Ibragimov Date: Tue, 9 Apr 2024 18:27:34 +0300 Subject: [PATCH 1/5] feature: add MCOPY spec --- specs/opcode/94MCOPY.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 specs/opcode/94MCOPY.md diff --git a/specs/opcode/94MCOPY.md b/specs/opcode/94MCOPY.md new file mode 100644 index 000000000..5940e5a31 --- /dev/null +++ b/specs/opcode/94MCOPY.md @@ -0,0 +1 @@ +# MCOPY opcode From 453c706f73852250c89432a1a58ac7973cc20b6a Mon Sep 17 00:00:00 2001 From: Magamedrasul Ibragimov Date: Tue, 16 Apr 2024 18:06:23 +0300 Subject: [PATCH 2/5] feature: add frame for MCOPY spec --- specs/opcode/94MCOPY.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/specs/opcode/94MCOPY.md b/specs/opcode/94MCOPY.md index 5940e5a31..8b045fde6 100644 --- a/specs/opcode/94MCOPY.md +++ b/specs/opcode/94MCOPY.md @@ -1 +1,23 @@ # MCOPY opcode + +## Constraints + +1. OpcodeId check + +- opId == OpcodeId(0x5E) + +2. State Transition + + 1. + 2. + 3. + +3. Lookups + + 1. + 2. + +## Exceptions + +1. +2. From deff931c2d4cbe63229fe18600f92c0b23d278ff Mon Sep 17 00:00:00 2001 From: Magamedrasul Ibragimov Date: Tue, 16 Apr 2024 23:00:54 +0300 Subject: [PATCH 3/5] feat: add explanation for MCOPY --- specs/opcode/94MCOPY.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/specs/opcode/94MCOPY.md b/specs/opcode/94MCOPY.md index 8b045fde6..aa8dc4fb9 100644 --- a/specs/opcode/94MCOPY.md +++ b/specs/opcode/94MCOPY.md @@ -1,5 +1,15 @@ # MCOPY opcode +## Procedure + +The `MCOPY` opcode pops `dest_offset`, `offset` and `size` from the stack. +It then copies `size` bytes in the current environment from memory at an `offset` to the memory at a `dest_offset`. For out-of-bounds scenarios - the memory is extended with respective gas cost applied. + +The gas cost of `MCOPY` opcode consists of two parts: + +1. A constant gas cost: `3 gas` +2. A dynamic gas cost: cost of memory expansion and copying (variable depending on the `size` copied to memory) + ## Constraints 1. OpcodeId check @@ -19,5 +29,5 @@ ## Exceptions -1. -2. +1. stack underflow: `1022 <= stack_pointer <= 1024` +2. out of gas: remaining gas is not enough From 929bb70042674e0a5a8e5352a7669f91cfc9c04d Mon Sep 17 00:00:00 2001 From: Magamedrasul Ibragimov Date: Wed, 17 Apr 2024 22:40:29 +0300 Subject: [PATCH 4/5] feat: finish MCOPY spec --- specs/opcode/94MCOPY.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/specs/opcode/94MCOPY.md b/specs/opcode/94MCOPY.md index aa8dc4fb9..b35a4935b 100644 --- a/specs/opcode/94MCOPY.md +++ b/specs/opcode/94MCOPY.md @@ -18,14 +18,21 @@ The gas cost of `MCOPY` opcode consists of two parts: 2. State Transition - 1. - 2. - 3. - -3. Lookups - - 1. - 2. +- rw_counter += 3 stack_reads + ??? +- stack_pointer += 3 +- pc += 1 +- gas += 3 + dynamic_gas_cost +- reversible_write_counter += 1 +- memory_size + - `prev_memory_size` if `size = 0` + - `max(prev_memory_size, (offset + size + 31) / 32)` if `size > 0` + +3. Lookups: 4 + + 1. `dest_offset` is at the 1st position of the stack + 2. `offset` is at the 2nd position of the stack + 3. `size` is at the 3rd position of the stack + 4. CopyTable lookup ## Exceptions From c5bdf26f5e9adbd17d33e320c7b16cef9a90fd6d Mon Sep 17 00:00:00 2001 From: Magamedrasul Ibragimov Date: Mon, 29 Apr 2024 16:16:58 +0300 Subject: [PATCH 5/5] fix: minor changes in MCOPY spec --- specs/opcode/94MCOPY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/opcode/94MCOPY.md b/specs/opcode/94MCOPY.md index b35a4935b..7a15cefc0 100644 --- a/specs/opcode/94MCOPY.md +++ b/specs/opcode/94MCOPY.md @@ -18,7 +18,7 @@ The gas cost of `MCOPY` opcode consists of two parts: 2. State Transition -- rw_counter += 3 stack_reads + ??? +- rw_counter += 3 stack_reads - stack_pointer += 3 - pc += 1 - gas += 3 + dynamic_gas_cost