Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Fix after_mpt_delete_extension_branch (0xPolygonZero#1449)
Browse files Browse the repository at this point in the history
* Fix after_mpt_delete_extension_branch

* Rename test

* PR feedback
  • Loading branch information
wborgeaud authored Jan 9, 2024
1 parent dcbfef6 commit bd02117
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
14 changes: 3 additions & 11 deletions evm/src/cpu/kernel/asm/mpt/delete/delete_extension.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 28 additions & 1 deletion evm/src/cpu/kernel/tests/mpt/delete.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit bd02117

Please sign in to comment.