Skip to content

Commit

Permalink
remove redtape for JUMP/I
Browse files Browse the repository at this point in the history
  • Loading branch information
einar-polygon committed Sep 19, 2024
1 parent 184878d commit c000b5a
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 41 deletions.
2 changes: 1 addition & 1 deletion evm_arithmetization/src/cpu/kernel/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions evm_arithmetization/src/generation/prover_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,10 @@ impl<F: RichField> GenerationState<F> {
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(())
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/prove_stdio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions scripts/test_jerigon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -142,10 +141,10 @@ ROUND2="
665
667
670
444
"

NOWSUCCESS="
444
4
5
28
Expand Down
11 changes: 7 additions & 4 deletions zero/src/rpc/jerigon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -167,14 +170,14 @@ where
let jumpdest_table: Option<JumpDestTableWitness> = 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
);
Expand Down
58 changes: 30 additions & 28 deletions zero/src/rpc/jumpdest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<U256> = None;

// Call depth of the previous `entry`. We initialize to 0 as this compares
// smaller to 1.
Expand All @@ -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" => {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.");
Expand All @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion zero/src/rpc/native/txn.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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<ProviderT, TransportT>(
Expand Down

0 comments on commit c000b5a

Please sign in to comment.