Skip to content

Commit

Permalink
TMP
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare committed Jul 5, 2024
1 parent 582cd68 commit 50f759b
Show file tree
Hide file tree
Showing 8 changed files with 10,662 additions and 48 deletions.
2 changes: 0 additions & 2 deletions evm_arithmetization/src/generation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,6 @@ fn simulate_cpu<F: Field>(
}
}

log::info!("CPU trace padded to {} cycles", state.traces.clock());

Ok((final_registers, mem_after))
}

Expand Down
2 changes: 0 additions & 2 deletions evm_arithmetization/src/generation/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ pub(crate) trait State<F: Field> {
debug_assert!(self.get_clock() - final_clock == NUM_EXTRA_CYCLES_AFTER - 1);
}
let final_mem = self.get_active_memory();
#[cfg(not(test))]
self.log_info(format!("CPU halted after {} cycles", self.get_clock()));
return Ok((final_registers, final_mem));
}
}
Expand Down
10 changes: 1 addition & 9 deletions evm_arithmetization/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,15 +686,7 @@ pub mod testing {

let mut proofs = Vec::with_capacity(data.len());
for mut d in data {
let proof = prove(
all_stark,
config,
inputs.clone(),
&mut d,
timing,
abort_signal.clone(),
)?;
proofs.push(proof);
let proof = generate_traces::<F, D>(all_stark, &inputs, config, &mut d, timing)?;
}

Ok(proofs)
Expand Down
41 changes: 6 additions & 35 deletions evm_arithmetization/src/witness/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,41 +141,12 @@ impl<T: Copy> Traces<T> {
keccak_sponge_ops,
} = self;

let arithmetic_trace = timed!(
timing,
"generate arithmetic trace",
all_stark.arithmetic_stark.generate_trace(arithmetic_ops)
);
let byte_packing_trace = timed!(
timing,
"generate byte packing trace",
all_stark
.byte_packing_stark
.generate_trace(byte_packing_ops, cap_elements, timing)
);
let cpu_rows = cpu.into_iter().map(|x| x.into()).collect();
let cpu_trace = trace_rows_to_poly_values(cpu_rows);
let keccak_trace = timed!(
timing,
"generate Keccak trace",
all_stark
.keccak_stark
.generate_trace(keccak_inputs, cap_elements, timing)
);
let keccak_sponge_trace = timed!(
timing,
"generate Keccak sponge trace",
all_stark
.keccak_sponge_stark
.generate_trace(keccak_sponge_ops, cap_elements, timing)
);
let logic_trace = timed!(
timing,
"generate logic trace",
all_stark
.logic_stark
.generate_trace(logic_ops, cap_elements, timing)
);
let arithmetic_trace = vec![];
let byte_packing_trace = vec![];
let cpu_trace = vec![];
let keccak_trace = vec![];
let keccak_sponge_trace = vec![];
let logic_trace = vec![];
let (memory_trace, final_values, unpadded_memory_length) = timed!(
timing,
"generate memory trace",
Expand Down
12 changes: 12 additions & 0 deletions evm_arithmetization/src/witness/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ pub(crate) const fn might_overflow_op(op: Operation) -> bool {
}

pub(crate) fn log_kernel_instruction<F: Field, S: State<F>>(state: &mut S, op: Operation) {
let pc = state.get_registers().program_counter;
let is_interesting_offset = KERNEL
.offset_label(pc)
.filter(|label| label == "check_state_trie")
.is_some();
if is_interesting_offset {
state.log(
log::Level::Info,
format!("Hashing trie at cycle {:?}", state.get_clock(),),
);
}

// The logic below is a bit costly, so skip it if debug logs aren't enabled.
if !log_enabled!(log::Level::Debug) {
return;
Expand Down
1,575 changes: 1,575 additions & 0 deletions trace_decoder/tests/test.json

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions trace_decoder/tests/test_parsing_and_proving.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//! This test aims at ensuring that the decoder can properly parse a block trace
//! received from Jerigon into zkEVM `GenerationInputs`, which the prover can
//! then pick to prove each transaction in the block independently.
//!
//! This test only `simulates` the zkEVM CPU, i.e. does not generate STARK
//! traces nor generates proofs, as its purpose is to be runnable easily in the
//! CI even in `debug` mode.
use evm_arithmetization::{prover::testing::prove_all_segments, AllStark, StarkConfig};
use plonky2::{
field::goldilocks_field::GoldilocksField, plonk::config::PoseidonGoldilocksConfig,
util::timing::TimingTree,
};
use pretty_env_logger::env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV};
use serde::{Deserialize, Serialize};
use trace_decoder::{
processed_block_trace::ProcessingMeta,
trace_protocol::BlockTrace,
types::{CodeHash, OtherBlockData},
};

fn resolve_code_hash_fn(_: &CodeHash) -> Vec<u8> {
todo!()
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ProverInput {
pub block_trace: BlockTrace,
pub other_data: OtherBlockData,
}

type F = GoldilocksField;
type C = PoseidonGoldilocksConfig;

fn test_block(path: &str) {
init_logger();

let bytes = std::fs::read(path).unwrap();
let prover_inputs: Vec<ProverInput> = serde_json::from_slice(&bytes).unwrap();

for prover_input in prover_inputs.into_iter() {
let tx_inputs = prover_input
.block_trace
.into_txn_proof_gen_ir(
&ProcessingMeta::new(resolve_code_hash_fn),
prover_input.other_data.clone(),
50,
)
.unwrap();

let _ = tx_inputs
.into_iter()
.take(3)
.map(|tx_input| {
println!("");
let mut timing = TimingTree::new("prove", log::Level::Info);
prove_all_segments::<F, C, 2>(
&AllStark::default(),
&StarkConfig::default(),
tx_input,
20,
&mut timing,
None,
)
.unwrap();
})
.collect::<Vec<_>>();
}
}

/// Tests an empty block with withdrawals: <https://etherscan.io/block/19840104>.
#[test]
fn test_block_19840104() {
test_block("tests/tmp.json")
}

fn init_logger() {
let _ = try_init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
}
8,989 changes: 8,989 additions & 0 deletions trace_decoder/tests/tmp.json

Large diffs are not rendered by default.

0 comments on commit 50f759b

Please sign in to comment.