From 08a061bc4d92e47337e5b31abf3c045f5dda61f4 Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Wed, 24 May 2023 10:29:34 +0200 Subject: [PATCH] Implement LOG* gas and remove panic (#1054) * Implement LOG* gas and remove panic * Remove stubs --- evm/src/cpu/kernel/aggregator.rs | 1 + evm/src/cpu/kernel/asm/core/log.asm | 75 +++++++++++++++++++ evm/src/cpu/kernel/asm/core/syscall_stubs.asm | 15 ---- 3 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 evm/src/cpu/kernel/asm/core/log.asm diff --git a/evm/src/cpu/kernel/aggregator.rs b/evm/src/cpu/kernel/aggregator.rs index 1da28e0b..67fab89c 100644 --- a/evm/src/cpu/kernel/aggregator.rs +++ b/evm/src/cpu/kernel/aggregator.rs @@ -41,6 +41,7 @@ pub(crate) fn combined_kernel() -> Kernel { include_str!("asm/core/transfer.asm"), include_str!("asm/core/util.asm"), include_str!("asm/core/access_lists.asm"), + include_str!("asm/core/log.asm"), include_str!("asm/core/selfdestruct_list.asm"), include_str!("asm/core/touched_addresses.asm"), include_str!("asm/core/precompiles/main.asm"), diff --git a/evm/src/cpu/kernel/asm/core/log.asm b/evm/src/cpu/kernel/asm/core/log.asm new file mode 100644 index 00000000..88098588 --- /dev/null +++ b/evm/src/cpu/kernel/asm/core/log.asm @@ -0,0 +1,75 @@ +// TODO: Implement receipts + +global sys_log0: + %check_static + // stack: kexit_info, offset, size + DUP3 DUP3 + %add_or_fault + // stack: offset+size, kexit_info, offset, size + DUP1 %ensure_reasonable_offset + %update_mem_bytes + // stack: kexit_info, offset, size + DUP3 %mul_const(@GAS_LOGDATA) %add_const(@GAS_LOG) + // stack: gas, kexit_info, offset, size + %charge_gas + %stack (kexit_info, offset, size) -> (kexit_info) + EXIT_KERNEL + +global sys_log1: + %check_static + // stack: kexit_info, offset, size, topic + DUP3 DUP3 + %add_or_fault + // stack: offset+size, kexit_info, offset, size, topic + DUP1 %ensure_reasonable_offset + %update_mem_bytes + // stack: kexit_info, offset, size, topic + DUP3 %mul_const(@GAS_LOGDATA) %add_const(@GAS_LOG) %add_const(@GAS_LOGTOPIC) + // stack: gas, kexit_info, offset, size, topic + %charge_gas + %stack (kexit_info, offset, size, topic) -> (kexit_info) + EXIT_KERNEL + +global sys_log2: + %check_static + // stack: kexit_info, offset, size, topic1, topic2 + DUP3 DUP3 + %add_or_fault + // stack: offset+size, kexit_info, offset, size, topic1, topic2 + DUP1 %ensure_reasonable_offset + %update_mem_bytes + // stack: kexit_info, offset, size, topic1, topic2 + DUP3 %mul_const(@GAS_LOGDATA) %add_const(@GAS_LOG) %add_const(@GAS_LOGTOPIC) %add_const(@GAS_LOGTOPIC) + // stack: gas, kexit_info, offset, size, topic1, topic2 + %charge_gas + %stack (kexit_info, offset, size, topic1, topic2) -> (kexit_info) + EXIT_KERNEL +global sys_log3: + %check_static + // stack: kexit_info, offset, size, topic1, topic2, topic3 + DUP3 DUP3 + %add_or_fault + // stack: offset+size, kexit_info, offset, size, topic1, topic2, topic3 + DUP1 %ensure_reasonable_offset + %update_mem_bytes + // stack: kexit_info, offset, size, topic1, topic2, topic3 + DUP3 %mul_const(@GAS_LOGDATA) %add_const(@GAS_LOG) %add_const(@GAS_LOGTOPIC) %add_const(@GAS_LOGTOPIC) %add_const(@GAS_LOGTOPIC) + // stack: gas, kexit_info, offset, size, topic1, topic2, topic3 + %charge_gas + %stack (kexit_info, offset, size, topic1, topic2, topic3) -> (kexit_info) + EXIT_KERNEL + +global sys_log4: + %check_static + // stack: kexit_info, offset, size, topic1, topic2, topic3, topic4 + DUP3 DUP3 + %add_or_fault + // stack: offset+size, kexit_info, offset, size, topic1, topic2, topic3, topic4 + DUP1 %ensure_reasonable_offset + %update_mem_bytes + // stack: kexit_info, offset, size, topic1, topic2, topic3, topic4 + DUP3 %mul_const(@GAS_LOGDATA) %add_const(@GAS_LOG) %add_const(@GAS_LOGTOPIC) %add_const(@GAS_LOGTOPIC) %add_const(@GAS_LOGTOPIC) %add_const(@GAS_LOGTOPIC) + // stack: gas, kexit_info, offset, size, topic1, topic2, topic3, topic4 + %charge_gas + %stack (kexit_info, offset, size, topic1, topic2, topic3, topic4) -> (kexit_info) + EXIT_KERNEL diff --git a/evm/src/cpu/kernel/asm/core/syscall_stubs.asm b/evm/src/cpu/kernel/asm/core/syscall_stubs.asm index 1232576c..1530872c 100644 --- a/evm/src/cpu/kernel/asm/core/syscall_stubs.asm +++ b/evm/src/cpu/kernel/asm/core/syscall_stubs.asm @@ -6,18 +6,3 @@ global sys_blockhash: global sys_prevrandao: // TODO: What semantics will this have for Edge? PANIC -global sys_log0: - %check_static - PANIC -global sys_log1: - %check_static - PANIC -global sys_log2: - %check_static - PANIC -global sys_log3: - %check_static - PANIC -global sys_log4: - %check_static - PANIC