diff --git a/evm_arithmetization/src/cpu/kernel/interpreter.rs b/evm_arithmetization/src/cpu/kernel/interpreter.rs index e7a139b7d..10af8d495 100644 --- a/evm_arithmetization/src/cpu/kernel/interpreter.rs +++ b/evm_arithmetization/src/cpu/kernel/interpreter.rs @@ -147,8 +147,7 @@ pub(crate) fn set_registers_and_run( ) }); - let result = interpreter.run()?; - Ok(result) + interpreter.run() } impl Interpreter { diff --git a/evm_arithmetization/src/generation/mod.rs b/evm_arithmetization/src/generation/mod.rs index dfc19f13a..9ebe0a975 100644 --- a/evm_arithmetization/src/generation/mod.rs +++ b/evm_arithmetization/src/generation/mod.rs @@ -235,21 +235,20 @@ impl GenerationInputs { } /// Post transaction execution tries retrieved from the prover's memory. -/// Used primarily as in the error returned in case of the failed execution, -/// for the purpose of error debugging. +/// Used primarily for error debugging in case of a failed execution. #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct DebugTrieOutputs { +pub struct DebugOutputTries { pub state_trie: HashedPartialTrie, pub transaction_trie: HashedPartialTrie, pub receipt_trie: HashedPartialTrie, } /// Wrapper around the error that happened in the simulation -/// with the additional collected post simulation tries +/// with the additional collected post-simulation tries. #[derive(Debug)] pub struct SimulationError { pub internal_error: anyhow::Error, - pub tries: Option, + pub tries: Option, } impl Display for SimulationError { @@ -631,7 +630,7 @@ fn simulate_cpu( /// they are represented in the prover's memory. pub(crate) fn collect_debug_tries( state: &GenerationState, -) -> anyhow::Result { +) -> anyhow::Result { let state_trie_ptr = u256_to_usize( state .memory @@ -652,8 +651,8 @@ pub(crate) fn collect_debug_tries( .read_global_metadata(GlobalMetadata::TransactionTrieRoot), ) .map_err(|_| anyhow!("transactions trie pointer is too large to fit in a usize."))?; - let transactions_trie = get_txn_trie::(&state.memory, txn_trie_ptr) - .map_err(|e| { + let transaction_trie = + get_txn_trie::(&state.memory, txn_trie_ptr).map_err(|e| { anyhow!( "unable to retrieve transaction trie for debugging purposes: {:?}", e @@ -666,7 +665,7 @@ pub(crate) fn collect_debug_tries( .read_global_metadata(GlobalMetadata::ReceiptTrieRoot), ) .map_err(|_| anyhow!("receipts trie pointer is too large to fit in a usize."))?; - let receipts_trie = get_receipt_trie::(&state.memory, receipt_trie_ptr) + let receipt_trie = get_receipt_trie::(&state.memory, receipt_trie_ptr) .map_err(|e| { anyhow!( "unable to retrieve receipt trie for debugging purposes: {:?}", @@ -674,9 +673,9 @@ pub(crate) fn collect_debug_tries( ) })?; - Ok(DebugTrieOutputs { + Ok(DebugOutputTries { state_trie, - transaction_trie: transactions_trie, - receipt_trie: receipts_trie, + transaction_trie, + receipt_trie, }) } diff --git a/evm_arithmetization/src/generation/segments.rs b/evm_arithmetization/src/generation/segments.rs index 3f3db9cb9..ac14c17be 100644 --- a/evm_arithmetization/src/generation/segments.rs +++ b/evm_arithmetization/src/generation/segments.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use crate::cpu::kernel::aggregator::KERNEL; use crate::cpu::kernel::interpreter::{set_registers_and_run, ExtraSegmentData, Interpreter}; use crate::generation::state::State; -use crate::generation::{collect_debug_tries, debug_inputs, DebugTrieOutputs, GenerationInputs}; +use crate::generation::{collect_debug_tries, debug_inputs, DebugOutputTries, GenerationInputs}; use crate::witness::memory::MemoryState; use crate::witness::state::RegistersState; use crate::AllData; @@ -93,7 +93,7 @@ pub struct SegmentError { pub message: String, pub block: u64, pub segment_index: usize, - pub tries: Option, + pub tries: Option, } impl SegmentDataIterator { @@ -138,8 +138,9 @@ impl SegmentDataIterator { // Run the interpreter to get `registers_after` and the partial data for the // next segment. - let run = set_registers_and_run(segment_data.registers_after, &mut self.interpreter); - if let Ok((updated_registers, mem_after)) = run { + let execution_result = + set_registers_and_run(segment_data.registers_after, &mut self.interpreter); + if let Ok((updated_registers, mem_after)) = execution_result { let partial_segment_data = Some(build_segment_data( segment_index + 1, Some(updated_registers), @@ -162,16 +163,15 @@ impl SegmentDataIterator { inputs.txn_number_before + inputs.txn_hashes.len() ), }; - let s = format!( - "Segment generation {:?} for block {:?} ({}) failed with error {:?}", - segment_index, - block, - txn_range, - run.unwrap_err() - ); - // In case of the error, return tries as part of the error for easier debugging + // In case of the error, return tries as part of the error for easier debugging. Err(SegmentError { - message: s, + message: format!( + "segment generation {:?} for block {:?} ({}) failed with error {:?}", + segment_index, + block, + txn_range, + execution_result.unwrap_err() + ), block: block.as_u64(), segment_index, tries: collect_debug_tries(self.interpreter.get_generation_state()).ok(), diff --git a/trace_decoder/src/core.rs b/trace_decoder/src/core.rs index 41e356bb7..d6058238a 100644 --- a/trace_decoder/src/core.rs +++ b/trace_decoder/src/core.rs @@ -30,7 +30,7 @@ use crate::{ /// TODO(0xaatif): document this after https://github.com/0xPolygonZero/zk_evm/issues/275 /// TODO: type parametrize observer depending on entrypoint. At the moment -/// `StateMpt` is hardcoded +/// `StateMpt` is hardcoded in this function. pub fn entrypoint( trace: BlockTrace, other: OtherBlockData, @@ -274,6 +274,7 @@ pub struct IntraBlockTries { pub receipt: ReceiptTrie, } +// TODO: we may want to refactor this many arguments. #[allow(clippy::too_many_arguments)] /// Does the main work mentioned in the [module documentation](super). fn middle( @@ -426,14 +427,6 @@ fn middle( if do_writes { acct.balance = balance.unwrap_or(acct.balance); - //******************************************************************* - // >>>>>>>>>>> DEBUG: Introduce error in the trie diff simulation - let addressdebug = "0x".to_string() + &hex::encode(addr.0); - if addressdebug.eq("0x71f755898886f79efa73334450f05a824faeae02") { - println!(">>>>>>>> I have found address and making a change txn index {txn_ix} address {addressdebug} making a balance from {} to {}!", acct.balance, acct.balance+U256::from(1)); - acct.balance += U256::from(1); - } - //******************************************************************* acct.nonce = nonce.unwrap_or(acct.nonce); acct.code_hash = code_usage .map(|it| match it { diff --git a/trace_decoder/src/observer.rs b/trace_decoder/src/observer.rs index d0a69b3c2..840435237 100644 --- a/trace_decoder/src/observer.rs +++ b/trace_decoder/src/observer.rs @@ -5,7 +5,7 @@ use crate::core::IntraBlockTries; /// Observer API for the trace decoder. pub trait Observer { /// Collect tries after the transaction/batch execution. - fn collect_tries(&mut self, block: u64, batch: u64, trie: IntraBlockTries); + fn collect_tries(&mut self, block: u64, batch: u64, tries: IntraBlockTries); } #[derive(Debug)] diff --git a/zero/src/bin/trie_diff.rs b/zero/src/bin/trie_diff.rs index 358d955da..803f4cc3a 100644 --- a/zero/src/bin/trie_diff.rs +++ b/zero/src/bin/trie_diff.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use anyhow::Result; use clap::{Parser, ValueHint}; -use evm_arithmetization::generation::DebugTrieOutputs; +use evm_arithmetization::generation::DebugOutputTries; use futures::{future, TryStreamExt}; use paladin::directive::{Directive, IndexedStream}; use paladin::runtime::Runtime; @@ -108,7 +108,7 @@ async fn main() -> Result<()> { zero::trie_diff::compare_tries( &block_prover_input, batch_index, - &DebugTrieOutputs { + &DebugOutputTries { state_trie: observer.data[prover_tries.batch_index] .tries .state diff --git a/zero/src/debug_utils.rs b/zero/src/debug_utils.rs index 7e8dbd842..9473989e6 100644 --- a/zero/src/debug_utils.rs +++ b/zero/src/debug_utils.rs @@ -3,7 +3,7 @@ use std::io::{self, Write}; use std::path::{Path, PathBuf}; use anyhow::Context; -use evm_arithmetization::generation::DebugTrieOutputs; +use evm_arithmetization::generation::DebugOutputTries; use serde::{Deserialize, Serialize}; const DEBUG_FOLDER: &str = "./debug"; @@ -89,7 +89,7 @@ pub struct ErrorTriesFile { pub error: String, pub block_number: u64, pub batch_index: usize, - pub tries: DebugTrieOutputs, + pub tries: DebugOutputTries, } pub fn generate_tries_debug_file_name(block_number: u64, batch_index: usize) -> String { @@ -100,7 +100,7 @@ pub fn save_tries_to_disk( err: &str, block_number: u64, batch_index: usize, - tries: &DebugTrieOutputs, + tries: &DebugOutputTries, ) -> anyhow::Result<()> { let output_dir = PathBuf::from(DEBUG_FOLDER); diff --git a/zero/src/trie_diff/mod.rs b/zero/src/trie_diff/mod.rs index 18ba2c115..39bd4a3c9 100644 --- a/zero/src/trie_diff/mod.rs +++ b/zero/src/trie_diff/mod.rs @@ -1,5 +1,5 @@ use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp}; -use evm_arithmetization::generation::DebugTrieOutputs; +use evm_arithmetization::generation::DebugOutputTries; use mpt_trie::debug_tools::diff::create_diff_between_tries; use mpt_trie::utils::TrieNodeType; use tracing::info; @@ -9,8 +9,8 @@ use crate::prover::BlockProverInput; pub fn compare_tries( block_prover_input: &BlockProverInput, batch_index: usize, - left: &DebugTrieOutputs, - right: &DebugTrieOutputs, + left: &DebugOutputTries, + right: &DebugOutputTries, ) -> anyhow::Result<()> { let block_number = block_prover_input .other_data