Begin MPT insert

This commit is contained in:
Daniel Lubarov 2022-10-08 13:23:00 -07:00
parent 39fc7a2a9e
commit 817156cd47
4 changed files with 55 additions and 4 deletions

View File

@ -39,6 +39,7 @@ pub(crate) fn combined_kernel() -> Kernel {
include_str!("asm/memory/metadata.asm"),
include_str!("asm/memory/packing.asm"),
include_str!("asm/memory/txn_fields.asm"),
include_str!("asm/mpt/delete.asm"),
include_str!("asm/mpt/hash.asm"),
include_str!("asm/mpt/hash_trie_specific.asm"),
include_str!("asm/mpt/hex_prefix.asm"),

View File

@ -0,0 +1,6 @@
// Return a copy of the given node with the given key deleted.
//
// Pre stack: node_ptr, num_nibbles, key, retdest
// Post stack: updated_node_ptr
global mpt_delete:
PANIC // TODO

View File

@ -39,7 +39,7 @@ global mpt_read:
DUP1 %eq_const(@MPT_NODE_EXTENSION) %jumpi(mpt_read_extension)
DUP1 %eq_const(@MPT_NODE_LEAF) %jumpi(mpt_read_leaf)
// There's still the MPT_NODE_HASH case, but if we hit a digest node,
// There's still the MPT_NODE_HASH case, but if we hit a hash node,
// it means the prover failed to provide necessary Merkle data, so panic.
PANIC

View File

@ -1,3 +1,47 @@
global mpt_write:
// stack: node_ptr, num_nibbles, key, retdest
// TODO
// TODO: Need a special case for deleting, if value = ''.
// Or canonicalize once, before final hashing, to remove empty leaves etc.
// Return a copy of the given node, with the given key set to the given value.
//
// Pre stack: node_ptr, num_nibbles, key, value_ptr, retdest
// Post stack: updated_node_ptr
global mpt_insert:
// stack: node_ptr, num_nibbles, key, value_ptr, retdest
DUP1 %mload_trie_data
// stack: node_type, node_ptr, num_nibbles, key, value_ptr, retdest
// Increment node_ptr, so it points to the node payload instead of its type.
SWAP1 %increment SWAP1
// stack: node_type, node_payload_ptr, num_nibbles, key, value_ptr, retdest
DUP1 %eq_const(@MPT_NODE_EMPTY) %jumpi(mpt_insert_empty)
DUP1 %eq_const(@MPT_NODE_BRANCH) %jumpi(mpt_insert_branch)
DUP1 %eq_const(@MPT_NODE_EXTENSION) %jumpi(mpt_insert_extension)
DUP1 %eq_const(@MPT_NODE_LEAF) %jumpi(mpt_insert_leaf)
// There's still the MPT_NODE_HASH case, but if we hit a hash node,
// it means the prover failed to provide necessary Merkle data, so panic.
PANIC
mpt_insert_empty:
// stack: node_type, node_payload_ptr, num_nibbles, key, value_ptr, retdest
POP
// stack: node_payload_ptr, num_nibbles, key, value_ptr, retdest
PANIC // TODO
mpt_insert_branch:
// stack: node_type, node_payload_ptr, num_nibbles, key, value_ptr, retdest
POP
// stack: node_payload_ptr, num_nibbles, key, value_ptr, retdest
PANIC // TODO
mpt_insert_extension:
// stack: node_type, node_payload_ptr, num_nibbles, key, value_ptr, retdest
POP
// stack: node_payload_ptr, num_nibbles, key, value_ptr, retdest
PANIC // TODO
mpt_insert_leaf:
// stack: node_type, node_payload_ptr, num_nibbles, key, value_ptr, retdest
POP
// stack: node_payload_ptr, num_nibbles, key, value_ptr, retdest
PANIC // TODO