mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-10 17:53:06 +00:00
Merge pull request #918 from mir-protocol/fix_read_ext
Fix reads from not-found ext nodes
This commit is contained in:
commit
de246e227d
@ -23,18 +23,6 @@ global transfer_eth_failure:
|
||||
%%after:
|
||||
%endmacro
|
||||
|
||||
// Pre stack: should_transfer, from, to, amount
|
||||
// Post stack: (empty)
|
||||
%macro maybe_transfer_eth
|
||||
%jumpi(%%transfer)
|
||||
// We're skipping the transfer, so just pop the arguments and return.
|
||||
%pop3
|
||||
%jump(%%after)
|
||||
%%transfer:
|
||||
%transfer_eth
|
||||
%%after:
|
||||
%endmacro
|
||||
|
||||
// Returns 0 on success, or 1 if addr has insufficient balance. Panics if addr isn't found in the trie.
|
||||
// Pre stack: addr, amount, retdest
|
||||
// Post stack: status (0 indicates success)
|
||||
|
||||
@ -23,6 +23,7 @@ global mpt_read_state_trie:
|
||||
// - the virtual address of the trie to search in
|
||||
// - the number of nibbles in the key (should start at 64)
|
||||
// - the key, as a U256
|
||||
// - return destination
|
||||
//
|
||||
// This function returns a pointer to the value, or 0 if the key is not found.
|
||||
global mpt_read:
|
||||
@ -43,13 +44,13 @@ global mpt_read:
|
||||
// it means the prover failed to provide necessary Merkle data, so panic.
|
||||
PANIC
|
||||
|
||||
mpt_read_empty:
|
||||
global mpt_read_empty:
|
||||
// Return 0 to indicate that the value was not found.
|
||||
%stack (node_type, node_payload_ptr, num_nibbles, key, retdest)
|
||||
-> (retdest, 0)
|
||||
JUMP
|
||||
|
||||
mpt_read_branch:
|
||||
global mpt_read_branch:
|
||||
// stack: node_type, node_payload_ptr, num_nibbles, key, retdest
|
||||
POP
|
||||
// stack: node_payload_ptr, num_nibbles, key, retdest
|
||||
@ -71,7 +72,7 @@ mpt_read_branch:
|
||||
// stack: child_ptr, num_nibbles, key, retdest
|
||||
%jump(mpt_read) // recurse
|
||||
|
||||
mpt_read_branch_end_of_key:
|
||||
global mpt_read_branch_end_of_key:
|
||||
%stack (node_payload_ptr, num_nibbles, key, retdest) -> (node_payload_ptr, retdest)
|
||||
// stack: node_payload_ptr, retdest
|
||||
%add_const(16) // skip over the 16 child nodes
|
||||
@ -81,7 +82,7 @@ mpt_read_branch_end_of_key:
|
||||
SWAP1
|
||||
JUMP
|
||||
|
||||
mpt_read_extension:
|
||||
global mpt_read_extension:
|
||||
// stack: node_type, node_payload_ptr, num_nibbles, key, retdest
|
||||
%stack (node_type, node_payload_ptr, num_nibbles, key)
|
||||
-> (num_nibbles, key, node_payload_ptr)
|
||||
@ -100,8 +101,9 @@ mpt_read_extension:
|
||||
// stack: node_key, key_part, key_part, future_nibbles, key, node_payload_ptr, retdest
|
||||
EQ // does the first part of our key match the node's key?
|
||||
%jumpi(mpt_read_extension_found)
|
||||
global mpt_read_extension_not_found:
|
||||
// Not found; return 0.
|
||||
%stack (key_part, future_nibbles, node_payload_ptr, retdest) -> (retdest, 0)
|
||||
%stack (key_part, future_nibbles, key, node_payload_ptr, retdest) -> (retdest, 0)
|
||||
JUMP
|
||||
mpt_read_extension_found:
|
||||
// stack: key_part, future_nibbles, key, node_payload_ptr, retdest
|
||||
@ -135,6 +137,7 @@ mpt_read_leaf:
|
||||
AND
|
||||
// stack: keys_match && num_nibbles_match, node_payload_ptr, retdest
|
||||
%jumpi(mpt_read_leaf_found)
|
||||
global mpt_read_leaf_not_found:
|
||||
// Not found; return 0.
|
||||
%stack (node_payload_ptr, retdest) -> (retdest, 0)
|
||||
JUMP
|
||||
|
||||
@ -99,7 +99,8 @@ impl<F: Field> GenerationState<F> {
|
||||
}
|
||||
|
||||
pub(crate) fn stack(&self) -> Vec<U256> {
|
||||
(0..self.registers.stack_len)
|
||||
const MAX_TO_SHOW: usize = 10;
|
||||
(0..self.registers.stack_len.min(MAX_TO_SHOW))
|
||||
.map(|i| stack_peek(self, i).unwrap())
|
||||
.collect()
|
||||
}
|
||||
|
||||
@ -589,7 +589,7 @@ pub(crate) fn generate_exit_kernel<F: Field>(
|
||||
state.registers.gas_used = gas_used_val;
|
||||
log::debug!(
|
||||
"Exiting to {}, is_kernel={}",
|
||||
KERNEL.offset_name(program_counter),
|
||||
program_counter,
|
||||
is_kernel_mode
|
||||
);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user