Skip to content

Commit 18d5da4

Browse files
committed
fails some addresses
1 parent 8a81dde commit 18d5da4

31 files changed

+451
-36
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[build]
22
# https://github.com/rust-lang/rust/pull/124129
33
# https://github.com/dtolnay/linkme/pull/88
4-
rustflags = ["-Z", "linker-features=-lld"]
4+
rustflags = ["-C", "target-cpu=native", "-Z", "linker-features=-lld"]

Cargo.lock

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ criterion = "0.5.1"
5555
dotenvy = "0.15.7"
5656
either = "1.12.0"
5757
enum-as-inner = "0.6.0"
58-
enumn = "0.1.13"
5958
env_logger = "0.11.3"
6059
eth_trie = "0.4.0"
6160
ethereum-types = "0.14.1"
@@ -94,7 +93,6 @@ ruint = "1.12.3"
9493
serde = "1.0.203"
9594
serde_json = "1.0.118"
9695
serde_path_to_error = "0.1.16"
97-
serde_with = "3.8.1"
9896
sha2 = "0.10.8"
9997
smt_trie = { path = "smt_trie", version = "0.1.0" }
10098
static_assertions = "1.1.0"
@@ -110,6 +108,8 @@ u4 = "0.1.0"
110108
uint = "0.9.5"
111109
url = "2.5.2"
112110
winnow = "0.6.13"
111+
evm-disassembler = "0.5.0"
112+
pretty_assertions = "1.4.0"
113113

114114
# zero-bin related dependencies
115115
ops = { path = "zero_bin/ops" }
@@ -128,4 +128,29 @@ proc-macro2 = "1.0"
128128
quote = "1.0"
129129
syn = "2.0"
130130
trybuild = "1.0"
131+
131132
zk_evm_proc_macro = { path = "proc_macro" }
133+
134+
[profile.release]
135+
opt-level=3
136+
debug=true
137+
incremental=true
138+
debug-assertions=true
139+
lto=false
140+
overflow-checks=false
141+
142+
[profile.test]
143+
opt-level=3
144+
debug=true
145+
incremental=true
146+
debug-assertions=true
147+
lto=false
148+
overflow-checks=false
149+
150+
[profile.dev]
151+
opt-level=3
152+
debug=true
153+
incremental=true
154+
debug-assertions=true
155+
lto=false
156+
overflow-checks=false

evm_arithmetization/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ anyhow = { workspace = true }
1919
bytes = { workspace = true }
2020
env_logger = { workspace = true }
2121
ethereum-types = { workspace = true }
22-
hex = { workspace = true, optional = true }
22+
hex = { workspace = true }
2323
hex-literal = { workspace = true }
2424
itertools = { workspace = true }
2525
keccak-hash = { workspace = true }
@@ -46,6 +46,8 @@ serde_json = { workspace = true }
4646
# Local dependencies
4747
mpt_trie = { workspace = true }
4848
zk_evm_proc_macro = { workspace = true }
49+
pretty_assertions = { workspace = true }
50+
alloy.workspace = true
4951

5052
[dev-dependencies]
5153
criterion = { workspace = true }
@@ -55,7 +57,7 @@ sha2 = { workspace = true }
5557

5658
[features]
5759
default = ["parallel"]
58-
asmtools = ["hex"]
60+
#asmtools = ["hex"]
5961
parallel = [
6062
"plonky2/parallel",
6163
"plonky2_maybe_rayon/parallel",

evm_arithmetization/benches/fibonacci_25m_gas.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ fn prepare_setup() -> anyhow::Result<GenerationInputs> {
173173
prev_hashes: vec![H256::default(); 256],
174174
cur_hash: H256::default(),
175175
},
176+
jumpdest_table: Default::default(),
176177
})
177178
}
178179

evm_arithmetization/src/cpu/kernel/interpreter.rs

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ use core::cmp::Ordering;
99
use std::collections::{BTreeSet, HashMap};
1010

1111
use anyhow::anyhow;
12-
use ethereum_types::{BigEndianHash, U256};
12+
use ethereum_types::{BigEndianHash, U256, H256};
1313
use log::Level;
1414
use mpt_trie::partial_trie::PartialTrie;
1515
use plonky2::field::types::Field;
16+
//use alloy::primitives::Address;
1617

1718
use crate::byte_packing::byte_packing_stark::BytePackingOp;
1819
use crate::cpu::columns::CpuColumnsView;
1920
use crate::cpu::kernel::aggregator::KERNEL;
2021
use crate::cpu::kernel::constants::global_metadata::GlobalMetadata;
2122
use crate::generation::debug_inputs;
2223
use crate::generation::mpt::load_all_mpts;
24+
use crate::generation::prover_input::{get_proofs_and_jumpdests, JumpDestTableProcessed, JumpDestTableRaw};
2325
use crate::generation::rlp::all_rlp_prover_inputs_reversed;
2426
use crate::generation::state::{
2527
all_withdrawals_prover_inputs_reversed, GenerationState, GenerationStateCheckpoint,
@@ -62,10 +64,11 @@ pub(crate) struct Interpreter<F: Field> {
6264

6365
/// Simulates the CPU execution from `state` until the program counter reaches
6466
/// `final_label` in the current context.
67+
/// TODO: main fun
6568
pub(crate) fn simulate_cpu_and_get_user_jumps<F: Field>(
6669
final_label: &str,
6770
state: &GenerationState<F>,
68-
) -> Option<HashMap<usize, Vec<usize>>> {
71+
) -> Option<HashMap<usize,Vec<usize>>> {
6972
match state.jumpdest_table {
7073
Some(_) => None,
7174
None => {
@@ -90,6 +93,58 @@ pub(crate) fn simulate_cpu_and_get_user_jumps<F: Field>(
9093
}
9194
}
9295

96+
// todo: remove. for easy comparison only
97+
#[deprecated(note = "use rpc to get jumpdests instead")]
98+
pub(crate) fn simulate_cpu_and_get_user_jumps_rpc<F: Field>(
99+
final_label: &str,
100+
state: &GenerationState<F>,
101+
) -> Option<JumpDestTableProcessed> {
102+
match state.jumpdest_table {
103+
Some(_) => None,
104+
None => {
105+
let halt_pc = KERNEL.global_labels[final_label];
106+
let initial_context = state.registers.context;
107+
let mut interpreter =
108+
Interpreter::new_with_state_and_halt_condition(state, halt_pc, initial_context);
109+
110+
log::debug!("Simulating CPU for jumpdest analysis.");
111+
112+
let _ = interpreter.run();
113+
114+
log::trace!("jumpdest table = {:?}", interpreter.jumpdest_table);
115+
116+
//debug_assert_eq!(&interpreter.jumpdest_table, &state.inputs.jumpdest_table);
117+
let jumpdest_table = set_jumpdest_analysis_inputs_rpc(&state.inputs.jumpdest_table, &state.inputs.contract_code);
118+
119+
Some(jumpdest_table)
120+
}
121+
}
122+
}
123+
124+
/// Given a HashMap containing the contexts and the jumpdest addresses, compute
125+
/// their respective proofs, by calling `get_proofs_and_jumpdests`
126+
pub(crate) fn set_jumpdest_analysis_inputs_rpc(
127+
jumpdest_table_rpc: &JumpDestTableRaw,
128+
codes: &HashMap<H256, Vec<u8>>,
129+
) -> JumpDestTableProcessed {
130+
JumpDestTableProcessed(jumpdest_table_rpc.0.iter().flat_map(|(code_address, ctx_table)| {
131+
ctx_table.0.iter().map(|(&ctx, jumpdest_table)| {
132+
let code = &codes[code_address];
133+
if let Some(&largest_address) = jumpdest_table.last() {
134+
// maybe just serialize it as BTreeSet and avoid conversion
135+
// this is consistent with:
136+
// https://doc.rust-lang.org/std/collections/struct.BTreeSet.html#method.last
137+
// let jdt: BTreeSet<usize> = jumpdest_table.into_iter().collect();
138+
let proofs = get_proofs_and_jumpdests(code, largest_address, jumpdest_table.clone());
139+
(ctx, proofs)
140+
} else {
141+
(ctx, vec![])
142+
}
143+
}).collect::<HashMap<usize,Vec<_>>>()
144+
}).collect())
145+
}
146+
147+
93148
impl<F: Field> Interpreter<F> {
94149
/// Returns an instance of `Interpreter` given `GenerationInputs`, and
95150
/// assuming we are initializing with the `KERNEL` code.
@@ -350,6 +405,7 @@ impl<F: Field> Interpreter<F> {
350405
}
351406

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

509-
let op = decode(registers, opcode)?;
565+
let op: Operation = decode(registers, opcode)?;
510566

511567
fill_op_flag(op, &mut row);
512568

evm_arithmetization/src/cpu/kernel/tests/add11.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ fn test_add11_yml() {
152152
prev_hashes: vec![H256::default(); 256],
153153
cur_hash: H256::default(),
154154
},
155+
jumpdest_table: Default::default(),
155156
};
156157

157158
let initial_stack = vec![];
@@ -293,6 +294,7 @@ fn test_add11_yml_with_exception() {
293294
prev_hashes: vec![H256::default(); 256],
294295
cur_hash: H256::default(),
295296
},
297+
jumpdest_table: Default::default(),
296298
};
297299

298300
let initial_stack = vec![];

evm_arithmetization/src/cpu/kernel/tests/core/jumpdest_analysis.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,13 @@ fn test_verify_non_jumpdest() -> Result<()> {
210210
}
211211
Ok(())
212212
}
213+
214+
#[test]
215+
fn compare_jumpdest_tables() -> Result<()> {
216+
let jumpdest_tbl_sim = todo!();
217+
let jumpdest_tbl_rpc = todo!();
218+
219+
assert_eq!(jumpdest_tbl_sim, jumpdest_tbl_rpc);
220+
221+
Ok(())
222+
}

0 commit comments

Comments
 (0)