2022-09-29 23:09:32 -07:00
|
|
|
global main:
|
2022-11-09 10:47:15 +11:00
|
|
|
// First, initialise the shift table
|
|
|
|
|
%shift_table_init
|
2022-12-01 16:23:39 -08:00
|
|
|
|
2023-08-23 23:29:58 +01:00
|
|
|
// Initialize the block bloom filter
|
|
|
|
|
%initialize_block_bloom
|
|
|
|
|
|
2022-11-09 10:47:15 +11:00
|
|
|
// Second, load all MPT data from the prover.
|
2022-12-01 16:23:39 -08:00
|
|
|
PUSH hash_initial_tries
|
2022-09-30 13:04:16 -07:00
|
|
|
%jump(load_all_mpts)
|
|
|
|
|
|
2023-03-06 21:57:51 -08:00
|
|
|
global hash_initial_tries:
|
2023-08-09 10:15:13 +02:00
|
|
|
%mpt_hash_state_trie %mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_DIGEST_BEFORE) %assert_eq
|
|
|
|
|
%mpt_hash_txn_trie %mload_global_metadata(@GLOBAL_METADATA_TXN_TRIE_DIGEST_BEFORE) %assert_eq
|
|
|
|
|
%mpt_hash_receipt_trie %mload_global_metadata(@GLOBAL_METADATA_RECEIPT_TRIE_DIGEST_BEFORE) %assert_eq
|
2022-09-30 13:04:16 -07:00
|
|
|
|
2023-05-04 09:57:02 +02:00
|
|
|
global start_txns:
|
|
|
|
|
// stack: (empty)
|
2023-09-27 16:00:16 +02:00
|
|
|
// The special case of an empty trie (i.e. for the first transaction)
|
|
|
|
|
// is handled outside of the kernel.
|
2023-08-23 23:29:58 +01:00
|
|
|
%mload_global_metadata(@GLOBAL_METADATA_TXN_NUMBER_BEFORE)
|
2023-09-27 16:00:16 +02:00
|
|
|
// stack: txn_nb
|
2023-08-23 23:29:58 +01:00
|
|
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_GAS_USED_BEFORE)
|
2023-05-04 09:57:02 +02:00
|
|
|
// stack: init_used_gas, txn_nb
|
2023-09-27 16:00:16 +02:00
|
|
|
DUP2 %scalar_to_rlp
|
|
|
|
|
// stack: txn_counter, init_gas_used, txn_nb
|
|
|
|
|
DUP1 %num_bytes %mul_const(2)
|
|
|
|
|
// stack: num_nibbles, txn_counter, init_gas_used, txn_nb
|
|
|
|
|
SWAP2
|
|
|
|
|
// stack: init_gas_used, txn_counter, num_nibbles, txn_nb
|
2023-05-04 09:57:02 +02:00
|
|
|
|
|
|
|
|
txn_loop:
|
2022-09-29 23:09:32 -07:00
|
|
|
// If the prover has no more txns for us to process, halt.
|
|
|
|
|
PROVER_INPUT(end_of_txns)
|
2022-09-30 13:04:16 -07:00
|
|
|
%jumpi(hash_final_tries)
|
2022-09-29 23:09:32 -07:00
|
|
|
|
2022-09-30 13:04:16 -07:00
|
|
|
// Call route_txn. When we return, continue the txn loop.
|
2023-05-04 09:57:02 +02:00
|
|
|
PUSH txn_loop_after
|
2023-09-27 16:00:16 +02:00
|
|
|
// stack: retdest, prev_gas_used, txn_counter, num_nibbles, txn_nb
|
|
|
|
|
DUP4 DUP4 %increment_bounded_rlp
|
|
|
|
|
%stack (next_txn_counter, next_num_nibbles, retdest, prev_gas_used, txn_counter, num_nibbles) -> (txn_counter, num_nibbles, retdest, prev_gas_used, txn_counter, num_nibbles, next_txn_counter, next_num_nibbles)
|
2022-09-29 23:09:32 -07:00
|
|
|
%jump(route_txn)
|
2022-09-30 13:04:16 -07:00
|
|
|
|
2023-05-04 09:57:02 +02:00
|
|
|
global txn_loop_after:
|
2023-09-27 16:00:16 +02:00
|
|
|
// stack: success, leftover_gas, cur_cum_gas, prev_txn_counter, prev_num_nibbles, txn_counter, num_nibbles, txn_nb
|
2023-05-04 09:57:02 +02:00
|
|
|
%process_receipt
|
2023-09-27 16:00:16 +02:00
|
|
|
// stack: new_cum_gas, txn_counter, num_nibbles, txn_nb
|
|
|
|
|
SWAP3 %increment SWAP3
|
2023-05-04 09:57:02 +02:00
|
|
|
%jump(txn_loop)
|
|
|
|
|
|
2022-12-06 23:05:47 -08:00
|
|
|
global hash_final_tries:
|
2023-09-27 16:00:16 +02:00
|
|
|
// stack: cum_gas, txn_counter, num_nibbles, txn_nb
|
2023-08-23 23:29:58 +01:00
|
|
|
// Check that we end up with the correct `cum_gas`, `txn_nb` and bloom filter.
|
|
|
|
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_GAS_USED_AFTER) %assert_eq
|
2023-09-27 16:00:16 +02:00
|
|
|
DUP3 %mload_global_metadata(@GLOBAL_METADATA_TXN_NUMBER_AFTER) %assert_eq
|
|
|
|
|
%pop3
|
2023-08-23 23:29:58 +01:00
|
|
|
%check_metadata_block_bloom
|
2023-08-09 10:15:13 +02:00
|
|
|
%mpt_hash_state_trie %mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_DIGEST_AFTER) %assert_eq
|
|
|
|
|
%mpt_hash_txn_trie %mload_global_metadata(@GLOBAL_METADATA_TXN_TRIE_DIGEST_AFTER) %assert_eq
|
|
|
|
|
%mpt_hash_receipt_trie %mload_global_metadata(@GLOBAL_METADATA_RECEIPT_TRIE_DIGEST_AFTER) %assert_eq
|
2022-09-30 13:04:16 -07:00
|
|
|
%jump(halt)
|
2023-08-23 23:29:58 +01:00
|
|
|
|
|
|
|
|
initialize_block_bloom:
|
|
|
|
|
// stack: retdest
|
|
|
|
|
PUSH 0 PUSH 8 PUSH 0
|
|
|
|
|
|
|
|
|
|
initialize_bloom_loop:
|
|
|
|
|
// stack: i, len, offset, retdest
|
|
|
|
|
DUP2 DUP2 EQ %jumpi(initialize_bloom_loop_end)
|
|
|
|
|
PUSH 32 // Bloom word length
|
|
|
|
|
// stack: word_len, i, len, offset, retdest
|
|
|
|
|
// Load the next `block_bloom_before` word.
|
|
|
|
|
DUP2 %add_const(8) %mload_kernel(@SEGMENT_GLOBAL_BLOCK_BLOOM)
|
|
|
|
|
// stack: bloom_word, word_len, i, len, offset, retdest
|
|
|
|
|
DUP5 PUSH @SEGMENT_BLOCK_BLOOM PUSH 0 // Bloom word address in SEGMENT_BLOCK_BLOOM
|
|
|
|
|
%mstore_unpacking
|
|
|
|
|
// stack: new_offset, i, len, old_offset, retdest
|
|
|
|
|
SWAP3 POP %increment
|
|
|
|
|
// stack: i, len, new_offset, retdest
|
|
|
|
|
%jump(initialize_bloom_loop)
|
|
|
|
|
|
|
|
|
|
initialize_bloom_loop_end:
|
|
|
|
|
// stack: len, len, offset, retdest
|
|
|
|
|
%pop3
|
|
|
|
|
JUMP
|
|
|
|
|
|
|
|
|
|
%macro initialize_block_bloom
|
|
|
|
|
// stack: (empty)
|
|
|
|
|
PUSH %%after
|
|
|
|
|
%jump(initialize_block_bloom)
|
|
|
|
|
%%after:
|
|
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
check_metadata_block_bloom:
|
|
|
|
|
// stack: retdest
|
|
|
|
|
PUSH 0 PUSH 8 PUSH 0
|
|
|
|
|
|
|
|
|
|
check_bloom_loop:
|
|
|
|
|
// stack: i, len, offset, retdest
|
|
|
|
|
DUP2 DUP2 EQ %jumpi(check_bloom_loop_end)
|
|
|
|
|
PUSH 32 // Bloom word length
|
|
|
|
|
// stack: word_len, i, len, offset, retdest
|
|
|
|
|
DUP4 PUSH @SEGMENT_BLOCK_BLOOM PUSH 0
|
|
|
|
|
%mload_packing
|
|
|
|
|
// stack: bloom_word, i, len, offset, retdest
|
|
|
|
|
DUP2 %add_const(16) %mload_kernel(@SEGMENT_GLOBAL_BLOCK_BLOOM) %assert_eq
|
|
|
|
|
// stack: i, len, offset, retdest
|
|
|
|
|
%increment SWAP2 %add_const(32) SWAP2
|
|
|
|
|
// stack: i+1, len, new_offset, retdest
|
|
|
|
|
%jump(check_bloom_loop)
|
|
|
|
|
|
|
|
|
|
check_bloom_loop_end:
|
|
|
|
|
// stack: len, len, offset, retdest
|
|
|
|
|
%pop3
|
|
|
|
|
JUMP
|
|
|
|
|
|
|
|
|
|
%macro check_metadata_block_bloom
|
|
|
|
|
PUSH %%after
|
|
|
|
|
%jump(check_metadata_block_bloom)
|
|
|
|
|
%%after:
|
|
|
|
|
%endmacro
|