Skip to content

Commit

Permalink
fails some addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
einar-polygon committed Jul 30, 2024
1 parent 8a81dde commit 18d5da4
Show file tree
Hide file tree
Showing 31 changed files with 451 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[build]
# https://github.com/rust-lang/rust/pull/124129
# https://github.com/dtolnay/linkme/pull/88
rustflags = ["-Z", "linker-features=-lld"]
rustflags = ["-C", "target-cpu=native", "-Z", "linker-features=-lld"]
74 changes: 74 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 27 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ criterion = "0.5.1"
dotenvy = "0.15.7"
either = "1.12.0"
enum-as-inner = "0.6.0"
enumn = "0.1.13"
env_logger = "0.11.3"
eth_trie = "0.4.0"
ethereum-types = "0.14.1"
Expand Down Expand Up @@ -94,7 +93,6 @@ ruint = "1.12.3"
serde = "1.0.203"
serde_json = "1.0.118"
serde_path_to_error = "0.1.16"
serde_with = "3.8.1"
sha2 = "0.10.8"
smt_trie = { path = "smt_trie", version = "0.1.0" }
static_assertions = "1.1.0"
Expand All @@ -110,6 +108,8 @@ u4 = "0.1.0"
uint = "0.9.5"
url = "2.5.2"
winnow = "0.6.13"
evm-disassembler = "0.5.0"
pretty_assertions = "1.4.0"

# zero-bin related dependencies
ops = { path = "zero_bin/ops" }
Expand All @@ -128,4 +128,29 @@ proc-macro2 = "1.0"
quote = "1.0"
syn = "2.0"
trybuild = "1.0"

zk_evm_proc_macro = { path = "proc_macro" }

[profile.release]
opt-level=3
debug=true
incremental=true
debug-assertions=true
lto=false
overflow-checks=false

[profile.test]
opt-level=3
debug=true
incremental=true
debug-assertions=true
lto=false
overflow-checks=false

[profile.dev]
opt-level=3
debug=true
incremental=true
debug-assertions=true
lto=false
overflow-checks=false
6 changes: 4 additions & 2 deletions evm_arithmetization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ anyhow = { workspace = true }
bytes = { workspace = true }
env_logger = { workspace = true }
ethereum-types = { workspace = true }
hex = { workspace = true, optional = true }
hex = { workspace = true }
hex-literal = { workspace = true }
itertools = { workspace = true }
keccak-hash = { workspace = true }
Expand All @@ -46,6 +46,8 @@ serde_json = { workspace = true }
# Local dependencies
mpt_trie = { workspace = true }
zk_evm_proc_macro = { workspace = true }
pretty_assertions = { workspace = true }
alloy.workspace = true

[dev-dependencies]
criterion = { workspace = true }
Expand All @@ -55,7 +57,7 @@ sha2 = { workspace = true }

[features]
default = ["parallel"]
asmtools = ["hex"]
#asmtools = ["hex"]
parallel = [
"plonky2/parallel",
"plonky2_maybe_rayon/parallel",
Expand Down
1 change: 1 addition & 0 deletions evm_arithmetization/benches/fibonacci_25m_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ fn prepare_setup() -> anyhow::Result<GenerationInputs> {
prev_hashes: vec![H256::default(); 256],
cur_hash: H256::default(),
},
jumpdest_table: Default::default(),
})
}

Expand Down
62 changes: 59 additions & 3 deletions evm_arithmetization/src/cpu/kernel/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ use core::cmp::Ordering;
use std::collections::{BTreeSet, HashMap};

use anyhow::anyhow;
use ethereum_types::{BigEndianHash, U256};
use ethereum_types::{BigEndianHash, U256, H256};
use log::Level;
use mpt_trie::partial_trie::PartialTrie;
use plonky2::field::types::Field;
//use alloy::primitives::Address;

use crate::byte_packing::byte_packing_stark::BytePackingOp;
use crate::cpu::columns::CpuColumnsView;
use crate::cpu::kernel::aggregator::KERNEL;
use crate::cpu::kernel::constants::global_metadata::GlobalMetadata;
use crate::generation::debug_inputs;
use crate::generation::mpt::load_all_mpts;
use crate::generation::prover_input::{get_proofs_and_jumpdests, JumpDestTableProcessed, JumpDestTableRaw};
use crate::generation::rlp::all_rlp_prover_inputs_reversed;
use crate::generation::state::{
all_withdrawals_prover_inputs_reversed, GenerationState, GenerationStateCheckpoint,
Expand Down Expand Up @@ -62,10 +64,11 @@ pub(crate) struct Interpreter<F: Field> {

/// Simulates the CPU execution from `state` until the program counter reaches
/// `final_label` in the current context.
/// TODO: main fun
pub(crate) fn simulate_cpu_and_get_user_jumps<F: Field>(
final_label: &str,
state: &GenerationState<F>,
) -> Option<HashMap<usize, Vec<usize>>> {
) -> Option<HashMap<usize,Vec<usize>>> {
match state.jumpdest_table {
Some(_) => None,
None => {
Expand All @@ -90,6 +93,58 @@ pub(crate) fn simulate_cpu_and_get_user_jumps<F: Field>(
}
}

// todo: remove. for easy comparison only
#[deprecated(note = "use rpc to get jumpdests instead")]
pub(crate) fn simulate_cpu_and_get_user_jumps_rpc<F: Field>(
final_label: &str,
state: &GenerationState<F>,
) -> Option<JumpDestTableProcessed> {
match state.jumpdest_table {
Some(_) => None,
None => {
let halt_pc = KERNEL.global_labels[final_label];
let initial_context = state.registers.context;
let mut interpreter =
Interpreter::new_with_state_and_halt_condition(state, halt_pc, initial_context);

log::debug!("Simulating CPU for jumpdest analysis.");

let _ = interpreter.run();

log::trace!("jumpdest table = {:?}", interpreter.jumpdest_table);

//debug_assert_eq!(&interpreter.jumpdest_table, &state.inputs.jumpdest_table);
let jumpdest_table = set_jumpdest_analysis_inputs_rpc(&state.inputs.jumpdest_table, &state.inputs.contract_code);

Some(jumpdest_table)
}
}
}

/// Given a HashMap containing the contexts and the jumpdest addresses, compute
/// their respective proofs, by calling `get_proofs_and_jumpdests`
pub(crate) fn set_jumpdest_analysis_inputs_rpc(
jumpdest_table_rpc: &JumpDestTableRaw,
codes: &HashMap<H256, Vec<u8>>,
) -> JumpDestTableProcessed {
JumpDestTableProcessed(jumpdest_table_rpc.0.iter().flat_map(|(code_address, ctx_table)| {
ctx_table.0.iter().map(|(&ctx, jumpdest_table)| {
let code = &codes[code_address];
if let Some(&largest_address) = jumpdest_table.last() {
// maybe just serialize it as BTreeSet and avoid conversion
// this is consistent with:
// https://doc.rust-lang.org/std/collections/struct.BTreeSet.html#method.last
// let jdt: BTreeSet<usize> = jumpdest_table.into_iter().collect();
let proofs = get_proofs_and_jumpdests(code, largest_address, jumpdest_table.clone());
(ctx, proofs)
} else {
(ctx, vec![])
}
}).collect::<HashMap<usize,Vec<_>>>()
}).collect())
}


impl<F: Field> Interpreter<F> {
/// Returns an instance of `Interpreter` given `GenerationInputs`, and
/// assuming we are initializing with the `KERNEL` code.
Expand Down Expand Up @@ -350,6 +405,7 @@ impl<F: Field> Interpreter<F> {
}

pub(crate) fn add_jumpdest_offset(&mut self, offset: usize) {
println!("SIM: ({:?}, {:?})", &self.generation_state.registers.context, offset);
if let Some(jumpdest_table) = self
.jumpdest_table
.get_mut(&self.generation_state.registers.context)
Expand Down Expand Up @@ -506,7 +562,7 @@ impl<F: Field> State<F> for Interpreter<F> {
let registers = self.generation_state.registers;
let (mut row, opcode) = self.base_row();

let op = decode(registers, opcode)?;
let op: Operation = decode(registers, opcode)?;

fill_op_flag(op, &mut row);

Expand Down
2 changes: 2 additions & 0 deletions evm_arithmetization/src/cpu/kernel/tests/add11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ fn test_add11_yml() {
prev_hashes: vec![H256::default(); 256],
cur_hash: H256::default(),
},
jumpdest_table: Default::default(),
};

let initial_stack = vec![];
Expand Down Expand Up @@ -293,6 +294,7 @@ fn test_add11_yml_with_exception() {
prev_hashes: vec![H256::default(); 256],
cur_hash: H256::default(),
},
jumpdest_table: Default::default(),
};

let initial_stack = vec![];
Expand Down
10 changes: 10 additions & 0 deletions evm_arithmetization/src/cpu/kernel/tests/core/jumpdest_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,13 @@ fn test_verify_non_jumpdest() -> Result<()> {
}
Ok(())
}

#[test]
fn compare_jumpdest_tables() -> Result<()> {
let jumpdest_tbl_sim = todo!();
let jumpdest_tbl_rpc = todo!();

assert_eq!(jumpdest_tbl_sim, jumpdest_tbl_rpc);

Ok(())
}
Loading

0 comments on commit 18d5da4

Please sign in to comment.