From dcbfef6df9750f39d00cf7466743d810926d5665 Mon Sep 17 00:00:00 2001 From: vuittont60 <81072379+vuittont60@users.noreply.github.com> Date: Tue, 9 Jan 2024 17:33:17 +0800 Subject: [PATCH 1/2] chore: fix typos (#1451) --- evm/src/extension_tower.rs | 2 +- evm/src/keccak_sponge/columns.rs | 2 +- evm/src/memory/segments.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/evm/src/extension_tower.rs b/evm/src/extension_tower.rs index 4e5f54e67b..da7cca554e 100644 --- a/evm/src/extension_tower.rs +++ b/evm/src/extension_tower.rs @@ -1068,7 +1068,7 @@ where /// (Prod_{i=1}^11 x_i) / phi /// The 6th Frob map is nontrivial but leaves Fp6 fixed and hence must be the conjugate: /// x_6 = (a + bz)_6 = a - bz = x.conj() - /// Letting prod_17 = x_1 * x_7, the remaining factors in the numerator can be expresed as: + /// Letting prod_17 = x_1 * x_7, the remaining factors in the numerator can be expressed as: /// [(prod_17) * (prod_17)_2] * (prod_17)_4 * [(prod_17) * (prod_17)_2]_1 /// By Galois theory, both the following are in Fp2 and are complex conjugates /// prod_odds, prod_evens diff --git a/evm/src/keccak_sponge/columns.rs b/evm/src/keccak_sponge/columns.rs index 7ba0cf4559..bcd34b9c7f 100644 --- a/evm/src/keccak_sponge/columns.rs +++ b/evm/src/keccak_sponge/columns.rs @@ -32,7 +32,7 @@ pub(crate) struct KeccakSpongeColumnsView { /// not a padding byte; 0 otherwise. pub is_full_input_block: T, - /// The context of the base addresss at which we will read the input block. + /// The context of the base address at which we will read the input block. pub context: T, /// The segment of the base address at which we will read the input block. pub segment: T, diff --git a/evm/src/memory/segments.rs b/evm/src/memory/segments.rs index d38b2e5deb..f3de1a215c 100644 --- a/evm/src/memory/segments.rs +++ b/evm/src/memory/segments.rs @@ -3,7 +3,7 @@ use num::traits::AsPrimitive; pub(crate) const SEGMENT_SCALING_FACTOR: usize = 32; /// This contains all the existing memory segments. The values in the enum are shifted by 32 bits -/// to allow for convenient address components (context / segement / virtual) bundling in the kernel. +/// to allow for convenient address components (context / segment / virtual) bundling in the kernel. #[allow(dead_code)] #[allow(clippy::enum_clike_unportable_variant)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, Debug)] From bd02117cdcf56ca09c4ef9bd3978ca3b7073616e Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Tue, 9 Jan 2024 11:15:53 +0100 Subject: [PATCH 2/2] Fix `after_mpt_delete_extension_branch` (#1449) * Fix after_mpt_delete_extension_branch * Rename test * PR feedback --- .../asm/mpt/delete/delete_extension.asm | 14 ++------- evm/src/cpu/kernel/tests/mpt/delete.rs | 29 ++++++++++++++++++- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/evm/src/cpu/kernel/asm/mpt/delete/delete_extension.asm b/evm/src/cpu/kernel/asm/mpt/delete/delete_extension.asm index 149b971d76..0627fcba6a 100644 --- a/evm/src/cpu/kernel/asm/mpt/delete/delete_extension.asm +++ b/evm/src/cpu/kernel/asm/mpt/delete/delete_extension.asm @@ -37,18 +37,10 @@ after_mpt_delete_extension_branch: // stack: child_type, updated_child_node_ptr, node_payload_ptr, node_len, node_key, retdest POP // stack: updated_child_node_ptr, node_payload_ptr, node_len, node_key, retdest - SWAP1 - // stack: extension_ptr, updated_child_node_ptr, node_len, node_key, retdest - PUSH @MPT_NODE_EXTENSION DUP2 %mstore_trie_data - // stack: extension_ptr, updated_child_node_ptr, node_len, node_key, retdest - DUP3 DUP2 %mstore_trie_data // Append node_len to our node - // stack: extension_ptr, updated_child_node_ptr, node_len, node_key, retdest - DUP4 DUP2 %mstore_trie_data // Append node_key to our node - // stack: extension_ptr, updated_child_node_ptr, node_len, node_key, retdest - SWAP1 DUP2 %mstore_trie_data // Append updated_child_node_ptr to our node - // stack: extension_ptr, node_len, node_key, retdest + DUP2 %add_const(2) %mstore_trie_data + // stack: node_payload_ptr, node_len, node_key, retdest + %decrement %stack (extension_ptr, node_len, node_key, retdest) -> (retdest, extension_ptr) - // stack: extension_ptr, retdest JUMP after_mpt_delete_extension_extension: diff --git a/evm/src/cpu/kernel/tests/mpt/delete.rs b/evm/src/cpu/kernel/tests/mpt/delete.rs index acb75b7b21..38342dc99c 100644 --- a/evm/src/cpu/kernel/tests/mpt/delete.rs +++ b/evm/src/cpu/kernel/tests/mpt/delete.rs @@ -1,7 +1,8 @@ use anyhow::{anyhow, Result}; use eth_trie_utils::nibbles::Nibbles; use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie}; -use ethereum_types::{BigEndianHash, H256}; +use ethereum_types::{BigEndianHash, H256, U512}; +use rand::random; use crate::cpu::kernel::aggregator::KERNEL; use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; @@ -48,6 +49,32 @@ fn mpt_delete_branch_into_hash() -> Result<()> { test_state_trie(state_trie, nibbles_64(0xADE), test_account_2()) } +#[test] +fn test_after_mpt_delete_extension_branch() -> Result<()> { + let hash = Node::Hash(H256::random()); + let branch = Node::Branch { + children: std::array::from_fn(|i| { + if i == 0 { + Node::Empty.into() + } else { + hash.clone().into() + } + }), + value: vec![], + }; + let nibbles = Nibbles::from_bytes_be(&random::<[u8; 5]>()).unwrap(); + let state_trie = Node::Extension { + nibbles, + child: branch.into(), + } + .into(); + let key = nibbles.merge_nibbles(&Nibbles { + packed: U512::zero(), + count: 64 - nibbles.count, + }); + test_state_trie(state_trie, key, test_account_2()) +} + /// Note: The account's storage_root is ignored, as we can't insert a new storage_root without the /// accompanying trie data. An empty trie's storage_root is used instead. fn test_state_trie(