From c000b5a55d7bccdeed29da60559533114279aa77 Mon Sep 17 00:00:00 2001 From: Einar Rasmussen Date: Thu, 19 Sep 2024 22:46:57 +0200 Subject: [PATCH] remove redtape for JUMP/I --- .../src/cpu/kernel/tests/mod.rs | 2 +- .../src/generation/prover_input.rs | 6 +- scripts/prove_stdio.sh | 2 +- scripts/test_jerigon.sh | 5 +- zero/src/rpc/jerigon.rs | 11 ++-- zero/src/rpc/jumpdest.rs | 58 ++++++++++--------- zero/src/rpc/native/txn.rs | 2 +- 7 files changed, 45 insertions(+), 41 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/tests/mod.rs b/evm_arithmetization/src/cpu/kernel/tests/mod.rs index aae20ae78..f4fb947e6 100644 --- a/evm_arithmetization/src/cpu/kernel/tests/mod.rs +++ b/evm_arithmetization/src/cpu/kernel/tests/mod.rs @@ -26,9 +26,9 @@ mod signed_syscalls; mod transaction_parsing; mod transient_storage; -use ::core::iter::Iterator as _; use std::{ops::Range, str::FromStr}; +use ::core::iter::Iterator as _; use anyhow::Result; use ethereum_types::U256; use plonky2::hash::hash_types::RichField; diff --git a/evm_arithmetization/src/generation/prover_input.rs b/evm_arithmetization/src/generation/prover_input.rs index e2ea4b179..c561504df 100644 --- a/evm_arithmetization/src/generation/prover_input.rs +++ b/evm_arithmetization/src/generation/prover_input.rs @@ -790,10 +790,10 @@ impl GenerationState { assert_eq!(rw, &sw); } - info!("SIMW {:#?}", sim); - info!("RPCW {:#?}", rpc); + info!("SIM {:#?}", sim); + info!("RPC {:#?}", rpc); - self.jumpdest_table = sim;// = if rpc.is_some() { rpc } else { sim }; + self.jumpdest_table = if rpc.is_some() { rpc } else { sim }; Ok(()) } diff --git a/scripts/prove_stdio.sh b/scripts/prove_stdio.sh index 80515c9e1..dc59806b9 100755 --- a/scripts/prove_stdio.sh +++ b/scripts/prove_stdio.sh @@ -40,7 +40,7 @@ export RAYON_NUM_THREADS=$num_procs #export RUST_LOG=trace # Script users are running locally, and might benefit from extra perf. # See also .cargo/config.toml. -export RUSTFLAGS='-C target-cpu=native -Zlinker-features=-lld' +export RUSTFLAGS='-C target-cpu=native -Z linker-features=-lld' INPUT_FILE=$1 TEST_ONLY=$2 diff --git a/scripts/test_jerigon.sh b/scripts/test_jerigon.sh index 240148594..baee31ea7 100755 --- a/scripts/test_jerigon.sh +++ b/scripts/test_jerigon.sh @@ -13,8 +13,7 @@ mkdir -p witnesses export RAYON_NUM_THREADS=4 export TOKIO_WORKER_THREADS=1 export RUST_BACKTRACE=full -export RUST_LOG=rpc=trace,evm_arithmetization::generation::prover_input=trace -export 'RUSTFLAGS=-C target-cpu=native -Zlinker-features=-lld' +export RUSTFLAGS='-C target-cpu=native -Zlinker-features=-lld' export RUST_MIN_STACK=67108864 GITHASH=`git rev-parse --short HEAD` @@ -142,10 +141,10 @@ ROUND2=" 665 667 670 -444 " NOWSUCCESS=" +444 4 5 28 diff --git a/zero/src/rpc/jerigon.rs b/zero/src/rpc/jerigon.rs index 9a9946a23..ab8cf8d37 100644 --- a/zero/src/rpc/jerigon.rs +++ b/zero/src/rpc/jerigon.rs @@ -16,9 +16,12 @@ use serde_json::json; use trace_decoder::{ BlockTrace, BlockTraceTriePreImages, CombinedPreImages, TxnInfo, TxnMeta, TxnTrace, }; -use tracing::debug; +use tracing::info; -use super::{fetch_other_block_data, jumpdest::{self, get_normalized_structlog}}; +use super::{ + fetch_other_block_data, + jumpdest::{self, get_normalized_structlog}, +}; use crate::prover::BlockProverInput; use crate::provider::CachedProvider; /// Transaction traces retrieved from Erigon zeroTracer. @@ -167,14 +170,14 @@ where let jumpdest_table: Option = structlog_opt.and_then(|struct_log| { jumpdest::generate_jumpdest_table(tx, &struct_log, &tx_traces).map_or_else( |error| { - debug!( + info!( "{:#?}: JumpDestTable generation failed with reason: {}", tx.hash, error ); None }, |jdt| { - debug!( + info!( "{:#?}: JumpDestTable generation succeeded with result: {}", tx.hash, jdt ); diff --git a/zero/src/rpc/jumpdest.rs b/zero/src/rpc/jumpdest.rs index 4861aeeca..533a9229b 100644 --- a/zero/src/rpc/jumpdest.rs +++ b/zero/src/rpc/jumpdest.rs @@ -143,7 +143,7 @@ pub(crate) fn generate_jumpdest_table( // `None` encodes that previous `entry` was not a JUMP or JUMPI with true // condition, `Some(jump_target)` encodes we came from a JUMP or JUMPI with // true condition and target `jump_target`. - let mut prev_jump = None; + let mut prev_jump: Option = None; // Call depth of the previous `entry`. We initialize to 0 as this compares // smaller to 1. @@ -167,14 +167,14 @@ pub(crate) fn generate_jumpdest_table( ensure!(call_stack.is_empty().not(), "Call stack was empty."); let (code_hash, ctx) = call_stack.last().unwrap(); - // trace!("TX: {:?}", tx.hash); - // trace!("STEP: {:?}", step); - // trace!("STEPS: {:?}", struct_log.len()); - // trace!("OPCODE: {}", entry.op.as_str()); - // trace!("CODE: {:?}", code_hash); - // trace!("CTX: {:?}", ctx); - // trace!("CURR_DEPTH: {:?}", curr_depth); - // trace!("{:#?}\n", entry); + trace!("TX: {:?}", tx.hash); + trace!("STEP: {:?}", step); + trace!("STEPS: {:?}", struct_log.len()); + trace!("OPCODE: {}", entry.op.as_str()); + trace!("CODE: {:?}", code_hash); + trace!("CTX: {:?}", ctx); + trace!("CURR_DEPTH: {:?}", curr_depth); + trace!("{:#?}\n", entry); match op { "CALL" | "CALLCODE" | "DELEGATECALL" | "STATICCALL" => { @@ -226,7 +226,7 @@ pub(crate) fn generate_jumpdest_table( let operands = 3; ensure!( evm_stack.len() >= operands, - "Opcode {op} expected {operands} operands at the EVM stack, but only {} were found.", + "Opcode {op} expected {operands} operands at the EVM stack, but only {} were found.", evm_stack.len() ); let [_value, _offset, _size, ..] = evm_stack[..] else { @@ -301,18 +301,18 @@ pub(crate) fn generate_jumpdest_table( "Opcode {op} expected {operands} operands at the EVM stack, but only {} were found.", evm_stack.len() ); - let [counter, ..] = evm_stack[..] else { + let [jump_target, ..] = evm_stack[..] else { unreachable!() }; - ensure!( - *counter <= U256::from(u64::MAX), - "Operand for {op} caused overflow: counter: {} is larger than u64::MAX {}", - *counter, - u64::MAX - ); - let jump_target: u64 = counter.to(); - - prev_jump = Some(jump_target); + // ensure!( + // *counter <= U256::from(u64::MAX), + // "Operand for {op} caused overflow: counter: {} is larger than u64::MAX + // {}", *counter, + // u64::MAX + // ); + // let jump_target: u64 = counter.to(); + + prev_jump = Some(*jump_target); } "JUMPI" => { ensure!(entry.stack.as_ref().is_some(), "No evm stack found."); @@ -324,25 +324,27 @@ pub(crate) fn generate_jumpdest_table( "Opcode {op} expected {operands} operands at the EVM stack, but only {} were found.", evm_stack.len() ); - let [counter, condition, ..] = evm_stack[..] else { + let [jump_target, condition, ..] = evm_stack[..] else { unreachable!() }; - ensure!( - *counter <= U256::from(u64::MAX), - "Operand for {op} caused overflow." - ); - let jump_target: u64 = counter.to(); + // ensure!( + // *counter <= U256::from(u64::MAX), + // "Operand for {op} caused overflow: counter: {} is larger than u64::MAX + // {}", *counter, + // u64::MAX + // ); + // let jump_target: u64 = counter.to(); let jump_condition = condition.is_zero().not(); prev_jump = if jump_condition { - Some(jump_target) + Some(*jump_target) } else { None }; } "JUMPDEST" => { let jumped_here = if let Some(jmp_target) = prev_jump { - jmp_target == entry.pc + jmp_target == U256::from(entry.pc) } else { false }; diff --git a/zero/src/rpc/native/txn.rs b/zero/src/rpc/native/txn.rs index fdfdf23f5..1305f9010 100644 --- a/zero/src/rpc/native/txn.rs +++ b/zero/src/rpc/native/txn.rs @@ -1,6 +1,5 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; -use crate::rpc::Compat; use __compat_primitive_types::{H256, U256}; use alloy::{ primitives::{keccak256, Address, B256}, @@ -26,6 +25,7 @@ use trace_decoder::{ContractCodeUsage, TxnInfo, TxnMeta, TxnTrace}; use tracing::debug; use crate::rpc::jumpdest::{self, get_normalized_structlog}; +use crate::rpc::Compat; /// Processes the transactions in the given block and updates the code db. pub async fn process_transactions(