From ccdfe3f95c986633bea5741e4588c28b88555717 Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 10:55:11 -0300 Subject: [PATCH 01/21] Add div opcode --- system-contracts/contracts/EvmInterpreter.yul | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index dc18644a1..14ad73f99 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -247,6 +247,15 @@ object "EVMInterpreter" { sp := pushStackItem(sp, sub(a, b)) evmGasLeft := chargeGas(evmGasLeft, 3) } + case 0x04 { + let a, b + + a, sp := popStackItem(sp) + b, sp := popStackItem(sp) + + sp := pushStackItem(sp, div(a, b)) + evmGasLeft := chargeGas(evmGasLeft, 5) + } case 0x17 { // OP_OR let a, b From bb65d93f42495bcf5d4f71f61327177df7ea634e Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 11:28:25 -0300 Subject: [PATCH 02/21] Add sdiv opcode --- system-contracts/contracts/EvmInterpreter.yul | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 14ad73f99..1dfcaaced 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -247,7 +247,7 @@ object "EVMInterpreter" { sp := pushStackItem(sp, sub(a, b)) evmGasLeft := chargeGas(evmGasLeft, 3) } - case 0x04 { + case 0x04 { // OP_DIV let a, b a, sp := popStackItem(sp) @@ -256,6 +256,15 @@ object "EVMInterpreter" { sp := pushStackItem(sp, div(a, b)) evmGasLeft := chargeGas(evmGasLeft, 5) } + case 0x05 { // OP_SDIV + let a, b + + a, sp := popStackItem(sp) + b, sp := popStackItem(sp) + + sp := pushStackItem(sp, sdiv(a, b)) + evmGasLeft := chargeGas(evmGasLeft, 5) + } case 0x17 { // OP_OR let a, b From 97d173a46be36621de47be918bb8fcb9cfe1d5a5 Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 11:45:43 -0300 Subject: [PATCH 03/21] Add mod opcode --- system-contracts/contracts/EvmInterpreter.yul | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 1dfcaaced..33349ba9f 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -265,6 +265,15 @@ object "EVMInterpreter" { sp := pushStackItem(sp, sdiv(a, b)) evmGasLeft := chargeGas(evmGasLeft, 5) } + case 0x06 { // OP_MOD + let a, b + + a, sp := popStackItem(sp) + b, sp := popStackItem(sp) + + sp := pushStackItem(sp, mod(a, b)) + evmGasLeft := chargeGas(evmGasLeft, 5) + } case 0x17 { // OP_OR let a, b From 5cbf7731c00c45622ab873d35c1c21533ac9f616 Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 11:59:59 -0300 Subject: [PATCH 04/21] Add smod opcode --- system-contracts/contracts/EvmInterpreter.yul | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 33349ba9f..33c178a1b 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -274,6 +274,15 @@ object "EVMInterpreter" { sp := pushStackItem(sp, mod(a, b)) evmGasLeft := chargeGas(evmGasLeft, 5) } + case 0x07 { // OP_SMOD + let a, b + + a, sp := popStackItem(sp) + b, sp := popStackItem(sp) + + sp := pushStackItem(sp, smod(a, b)) + evmGasLeft := chargeGas(evmGasLeft, 5) + } case 0x17 { // OP_OR let a, b From 4f0fa33c0f5b87994b7e938f0c0c2f223ff93b65 Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 12:32:27 -0300 Subject: [PATCH 05/21] Optimize readBytes function used by pushN opcodes With this change, the function will stop doing N (from pushN) `add`s, but only one, whatever N be. --- system-contracts/contracts/EvmInterpreter.yul | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index dc3470df6..6d787c4ff 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -68,8 +68,9 @@ object "EVMInterpreter" { } function readBytes(start, length) -> value { - for { let i := 0 } lt(i, length) { i := add(i, 1) } { - let next_byte := readIP(add(start, i)) + let max := add(start, length) + for {} lt(start, max) { start := add(start, 1) } { + let next_byte := readIP(start) value := or(shl(8, value), next_byte) } From aef11c0265d088cf5ff9cdb9ed07dc9b76078516 Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 15:44:50 -0300 Subject: [PATCH 06/21] Add jump and jumpdest opcodes --- system-contracts/contracts/EvmInterpreter.yul | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index dc3470df6..82e2ff9c5 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -289,6 +289,21 @@ object "EVMInterpreter" { sp := pushStackItem(sp, mulmod(a, b, N)) } + // NOTE: We don't currently do full jumpdest validation + // (i.e. validating a jumpdest isn't in PUSH data) + case 0x56 { // OP_JUMP + let counter + + counter, sp := popStackItem(sp) + + ip := add(add(BYTECODE_OFFSET(), 32), counter) + + // Check next opcode is JUMPDEST + let nextOpcode := readIP(ip) + if iszero(eq(nextOpcode, 0x5B)) { + revert(0, 0) + } + } case 0x55 { // OP_SSTORE let key, value @@ -299,6 +314,7 @@ object "EVMInterpreter" { // TODO: Handle cold/warm slots and updates, etc for gas costs. evmGasLeft := chargeGas(evmGasLeft, 100) } + case 0x5B {} // OP_JUMPDEST case 0x5F { // OP_PUSH0 let value := 0 From fd7fb79dae4c90e042c5f0178d22d0c6ce9a93fd Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 16:09:35 -0300 Subject: [PATCH 07/21] Add jumpi opcode --- system-contracts/contracts/EvmInterpreter.yul | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 82e2ff9c5..d9d98111b 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -304,6 +304,24 @@ object "EVMInterpreter" { revert(0, 0) } } + case 0x57 { // OP_JUMPI + let counter, b + + counter, sp := popStackItem(sp) + b, sp := popStackItem(sp) + + if iszero(b) { + continue + } + + ip := add(add(BYTECODE_OFFSET(), 32), counter) + + // Check next opcode is JUMPDEST + let nextOpcode := readIP(ip) + if iszero(eq(nextOpcode, 0x5B)) { + revert(0, 0) + } + } case 0x55 { // OP_SSTORE let key, value From 3fc1b85a699594bc63770999ab574ddab41913e6 Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 16:42:09 -0300 Subject: [PATCH 08/21] Charge gas on jumps --- system-contracts/contracts/EvmInterpreter.yul | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index d9d98111b..474882222 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -298,6 +298,8 @@ object "EVMInterpreter" { ip := add(add(BYTECODE_OFFSET(), 32), counter) + evmGasLeft = chargeGas(evmGasLeft, 8) + // Check next opcode is JUMPDEST let nextOpcode := readIP(ip) if iszero(eq(nextOpcode, 0x5B)) { @@ -310,6 +312,8 @@ object "EVMInterpreter" { counter, sp := popStackItem(sp) b, sp := popStackItem(sp) + evmGasLeft = chargeGas(evmGasLeft, 10) + if iszero(b) { continue } From 8d599fb29cec1a4c665aa1fc50b32bca4edb8ce8 Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 16:50:10 -0300 Subject: [PATCH 09/21] Add lt opcode --- system-contracts/contracts/EvmInterpreter.yul | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index b78d997ce..6aebd3b56 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -326,6 +326,16 @@ object "EVMInterpreter" { sp := pushStackItem(sp, mulmod(a, b, N)) } + case 0x10 { // OP_LT + let a, b + + a, sp := popStackItem(sp) + b, sp := popStackItem(sp) + + sp := pushStackItem(sp, lt(a, b)) + + evmGasLeft := chargeGas(evmGasLeft, 3) + } case 0x55 { // OP_SSTORE let key, value From 34eeb1cdb8e9a183dc3094ad2f68c2f75c9999fa Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 16:59:09 -0300 Subject: [PATCH 10/21] Add gt opcode --- system-contracts/contracts/EvmInterpreter.yul | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 6aebd3b56..987389afd 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -336,6 +336,16 @@ object "EVMInterpreter" { evmGasLeft := chargeGas(evmGasLeft, 3) } + case 0x11 { // OP_GT + let a, b + + a, sp := popStackItem(sp) + b, sp := popStackItem(sp) + + sp := pushStackItem(sp, gt(a, b)) + + evmGasLeft := chargeGas(evmGasLeft, 3) + } case 0x55 { // OP_SSTORE let key, value From e73e62729866a3babdc645e0aa3bf563240ba186 Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 17:15:18 -0300 Subject: [PATCH 11/21] Add slt opcode --- system-contracts/contracts/EvmInterpreter.yul | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 987389afd..da8f5f34c 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -346,6 +346,16 @@ object "EVMInterpreter" { evmGasLeft := chargeGas(evmGasLeft, 3) } + case 0x12 { // OP_SLT + let a, b + + a, sp := popStackItem(sp) + b, sp := popStackItem(sp) + + sp := pushStackItem(sp, slt(a, b)) + + evmGasLeft := chargeGas(evmGasLeft, 3) + } case 0x55 { // OP_SSTORE let key, value From 65e5776363ab79b2f6221dc33d591ac2d3f597be Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 17:21:59 -0300 Subject: [PATCH 12/21] Add sgt opcode --- system-contracts/contracts/EvmInterpreter.yul | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index da8f5f34c..e5dd44ec6 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -356,6 +356,16 @@ object "EVMInterpreter" { evmGasLeft := chargeGas(evmGasLeft, 3) } + case 0x13 { // OP_SGT + let a, b + + a, sp := popStackItem(sp) + b, sp := popStackItem(sp) + + sp := pushStackItem(sp, sgt(a, b)) + + evmGasLeft := chargeGas(evmGasLeft, 3) + } case 0x55 { // OP_SSTORE let key, value From 8feb51f6c84b408c1e57d457560fce68bd43ee8b Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 17:30:29 -0300 Subject: [PATCH 13/21] Add eq opcode --- system-contracts/contracts/EvmInterpreter.yul | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index e5dd44ec6..73ce5dfe0 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -366,6 +366,16 @@ object "EVMInterpreter" { evmGasLeft := chargeGas(evmGasLeft, 3) } + case 0x14 { // OP_EQ + let a, b + + a, sp := popStackItem(sp) + b, sp := popStackItem(sp) + + sp := pushStackItem(sp, eq(a, b)) + + evmGasLeft := chargeGas(evmGasLeft, 3) + } case 0x55 { // OP_SSTORE let key, value From f7bf68eda7ff97e94233c447409d1e01657e272d Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 17:36:41 -0300 Subject: [PATCH 14/21] Add iszero opcode --- system-contracts/contracts/EvmInterpreter.yul | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 73ce5dfe0..49a578629 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -376,6 +376,15 @@ object "EVMInterpreter" { evmGasLeft := chargeGas(evmGasLeft, 3) } + case 0x15 { // OP_ISZERO + let a + + a, sp := popStackItem(sp) + + sp := pushStackItem(sp, iszero(a)) + + evmGasLeft := chargeGas(evmGasLeft, 3) + } case 0x55 { // OP_SSTORE let key, value From 67d035740c19d904f383f5b6a5f593aa66df16f1 Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 17:47:07 -0300 Subject: [PATCH 15/21] Add xor opcode --- system-contracts/contracts/EvmInterpreter.yul | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 49a578629..904308d1f 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -385,6 +385,16 @@ object "EVMInterpreter" { evmGasLeft := chargeGas(evmGasLeft, 3) } + case 0x18 { // OP_XOR + let a, b + + a, sp := popStackItem(sp) + b, sp := popStackItem(sp) + + sp := pushStackItem(sp, xor(a, b)) + + evmGasLeft := chargeGas(evmGasLeft, 3) + } case 0x55 { // OP_SSTORE let key, value From f4b310e520ec8ce91d4abb08c157e60619d9f68b Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Tue, 9 Apr 2024 17:52:08 -0300 Subject: [PATCH 16/21] Add basic "print" functions --- system-contracts/contracts/EvmInterpreter.yul | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index b78d997ce..7abe81528 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -182,6 +182,16 @@ object "EVMInterpreter" { gasRemaining := sub(prevGas, toCharge) } + function printHex(value) { + mstore(0, value) + log1(0, 32, 0x00debdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebde) + } + + function printString(value) { + mstore(0, value) + log1(0, 32, 0x00debdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdf) + } + //////////////////////////////////////////////////////////////// // FALLBACK //////////////////////////////////////////////////////////////// From d2a33c33dd8fc3ee835fdeb23baee361f2e5305b Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Tue, 9 Apr 2024 17:53:29 -0300 Subject: [PATCH 17/21] Add not opcode --- system-contracts/contracts/EvmInterpreter.yul | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 904308d1f..231954ba9 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -395,6 +395,15 @@ object "EVMInterpreter" { evmGasLeft := chargeGas(evmGasLeft, 3) } + case 0x19 { // OP_NOT + let a + + a, sp := popStackItem(sp) + + sp := pushStackItem(sp, not(a)) + + evmGasLeft := chargeGas(evmGasLeft, 3) + } case 0x55 { // OP_SSTORE let key, value From 0b86f675b0b194fd3e4df3f91219908e8a56f3cb Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Wed, 10 Apr 2024 10:34:39 -0300 Subject: [PATCH 18/21] Add byte opcode --- system-contracts/contracts/EvmInterpreter.yul | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 231954ba9..69f6b8a96 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -404,6 +404,16 @@ object "EVMInterpreter" { evmGasLeft := chargeGas(evmGasLeft, 3) } + case 0x1A { // OP_BYTE + let i, x + + i, sp := popStackItem(sp) + x, sp := popStackItem(sp) + + sp := pushStackItem(sp, byte(i, x)) + + evmGasLeft := chargeGas(evmGasLeft, 3) + } case 0x55 { // OP_SSTORE let key, value From 3dafe74bb6e139b4baf3416ed669925aeeba6def Mon Sep 17 00:00:00 2001 From: Manuel Bilbao Date: Wed, 10 Apr 2024 12:07:27 -0300 Subject: [PATCH 19/21] Fix sintaxis error --- system-contracts/contracts/EvmInterpreter.yul | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 0c6df778d..d45f31e91 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -345,7 +345,7 @@ object "EVMInterpreter" { ip := add(add(BYTECODE_OFFSET(), 32), counter) - evmGasLeft = chargeGas(evmGasLeft, 8) + evmGasLeft := chargeGas(evmGasLeft, 8) // Check next opcode is JUMPDEST let nextOpcode := readIP(ip) @@ -359,7 +359,7 @@ object "EVMInterpreter" { counter, sp := popStackItem(sp) b, sp := popStackItem(sp) - evmGasLeft = chargeGas(evmGasLeft, 10) + evmGasLeft := chargeGas(evmGasLeft, 10) if iszero(b) { continue From 6eb9ced9b8136495146a7af3934da82218a06cb6 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Wed, 10 Apr 2024 12:56:43 -0300 Subject: [PATCH 20/21] Better print functionality --- system-contracts/contracts/EvmInterpreter.yul | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index 7abe81528..d3dbbb93d 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -183,20 +183,21 @@ object "EVMInterpreter" { } function printHex(value) { - mstore(0, value) - log1(0, 32, 0x00debdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebde) + mstore(add(DEBUG_SLOT_OFFSET(), 0x20), 0x00debdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebde) + mstore(add(DEBUG_SLOT_OFFSET(), 0x40), value) + mstore(DEBUG_SLOT_OFFSET(), 0x4A15830341869CAA1E99840C97043A1EA15D2444DA366EFFF5C43B4BEF299681) } function printString(value) { - mstore(0, value) - log1(0, 32, 0x00debdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdf) + mstore(add(DEBUG_SLOT_OFFSET(), 0x20), 0x00debdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdf) + mstore(add(DEBUG_SLOT_OFFSET(), 0x40), value) + mstore(DEBUG_SLOT_OFFSET(), 0x4A15830341869CAA1E99840C97043A1EA15D2444DA366EFFF5C43B4BEF299681) } //////////////////////////////////////////////////////////////// // FALLBACK //////////////////////////////////////////////////////////////// - // TALK ABOUT THE DIFFERENCE BETWEEN VERBATIM AND DOING A STATIC CALL. // IN SOLIDITY A STATIC CALL IS REPLACED BY A VERBATIM IF THE ADDRES IS ONE // OF THE ONES IN THE SYSTEM CONTRACT LIST WHATEVER. From c49c0eda67403403839deb490151ed091147b83c Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Wed, 10 Apr 2024 14:35:28 -0300 Subject: [PATCH 21/21] Make prints not clobber each other when called in succesion --- system-contracts/contracts/EvmInterpreter.yul | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/system-contracts/contracts/EvmInterpreter.yul b/system-contracts/contracts/EvmInterpreter.yul index d3dbbb93d..85ce817ea 100644 --- a/system-contracts/contracts/EvmInterpreter.yul +++ b/system-contracts/contracts/EvmInterpreter.yul @@ -182,16 +182,23 @@ object "EVMInterpreter" { gasRemaining := sub(prevGas, toCharge) } + // Essentially a NOP that will not get optimized away by the compiler + function $llvm_NoInline_llvm$_unoptimized() { + pop(1) + } + function printHex(value) { mstore(add(DEBUG_SLOT_OFFSET(), 0x20), 0x00debdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebde) mstore(add(DEBUG_SLOT_OFFSET(), 0x40), value) mstore(DEBUG_SLOT_OFFSET(), 0x4A15830341869CAA1E99840C97043A1EA15D2444DA366EFFF5C43B4BEF299681) + $llvm_NoInline_llvm$_unoptimized() } function printString(value) { mstore(add(DEBUG_SLOT_OFFSET(), 0x20), 0x00debdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdebdf) mstore(add(DEBUG_SLOT_OFFSET(), 0x40), value) mstore(DEBUG_SLOT_OFFSET(), 0x4A15830341869CAA1E99840C97043A1EA15D2444DA366EFFF5C43B4BEF299681) + $llvm_NoInline_llvm$_unoptimized() } ////////////////////////////////////////////////////////////////