Skip to content

Commit 6236577

Browse files
committed
Execute before prove
1 parent 99425da commit 6236577

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

prover/Cargo.lock

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

prover/bin/server/src/queue.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ fn save_batch_header(blocks: &mut Vec<BlockTrace>, batch_index: u64) -> bool {
120120
let proof_dir = PROVER_PROOF_DIR.to_string() + format!("/batch_{}", batch_index).as_str();
121121
std::fs::create_dir_all(&proof_dir).expect("failed to create proof path");
122122
blocks.iter_mut().for_each(|blobk| blobk.flatten());
123+
let verify_result = EVMVerifier::verify(blocks);
123124

124-
if let Ok(batch_info) = EVMVerifier::verify(blocks) {
125+
if let Ok(batch_info) = verify_result {
125126
let blob_info = morph_executor_host::get_blob_info(blocks).unwrap();
126127
let (versioned_hash, _) = BlobVerifier::verify(&blob_info, blocks.len()).unwrap();
127128

@@ -137,7 +138,7 @@ fn save_batch_header(blocks: &mut Vec<BlockTrace>, batch_index: u64) -> bool {
137138
batch_file.write_all(&batch_header[..]).expect("failed to batch_header");
138139
true
139140
} else {
140-
let e = EVMVerifier::verify(blocks).unwrap_err();
141+
let e = verify_result.unwrap_err();
141142
let error_data = serde_json::json!({
142143
"error_code": "EVM_EXECUTE_NOT_EXPECTED",
143144
"error_msg": e.to_string()
@@ -209,3 +210,19 @@ fn save_trace(batch_index: u64, chunk_traces: &Vec<BlockTrace>) {
209210
serde_json::to_writer_pretty(writer, &chunk_traces).unwrap();
210211
log::info!("chunk_traces of batch_index = {:#?} saved", batch_index);
211212
}
213+
214+
#[test]
215+
fn test_save_execute() {
216+
let batch_index = 102u64;
217+
218+
let mut blocks = load_trace("../../testdata/viridian/eip7702_traces.json");
219+
println!("blocks.len(): {:?}", blocks.len());
220+
let traces = blocks.first_mut().unwrap();
221+
222+
if !save_batch_header(traces, batch_index) {
223+
save_trace(batch_index, traces);
224+
println!("save_batch_header error");
225+
} else {
226+
println!("save_batch_header success");
227+
}
228+
}

prover/crates/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tiny-keccak.workspace = true
2121

2222
sbv-primitives.workspace = true
2323
sbv-utils.workspace = true
24+
cfg-if = { workspace = true }
2425

2526
[dev-dependencies]
2627
ctor.workspace = true

prover/crates/core/src/database.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,17 @@ impl DatabaseRef for ReadOnlyDB {
193193
// then the upcoming trace contains code (meaning the code is used in this new block),
194194
// we can't directly update the CacheDB, so we offer the code by hash here.
195195
// However, if the code still cannot be found, this is an error.
196-
self.code_db.get(&hash).cloned().ok_or_else(|| {
197-
unreachable!(
198-
"Code is either loaded or not needed (like EXTCODESIZE), code hash: {:?}",
199-
hash
200-
);
201-
})
196+
// self.code_db.get(&hash).cloned().ok_or_else(|| {
197+
// unreachable!(
198+
// "Code is either loaded or not needed (like EXTCODESIZE), code hash: {:?}",
199+
// hash
200+
// );
201+
// })
202+
203+
Ok(self.code_db.get(&hash).cloned().unwrap_or_else(|| {
204+
println!("---------------->code_by_hash_ref error: {:?}", hash);
205+
Bytecode::default()
206+
}))
202207
}
203208

204209
/// Get storage value of address at index.

prover/crates/core/src/executor/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ impl EvmExecutor<'_> {
9292
};
9393

9494
for (idx, tx) in l2_trace.transactions().enumerate() {
95+
cfg_if::cfg_if! {
96+
if #[cfg(not(target_os = "zkvm"))] {
97+
println!("handle block: {:?}, handle tx: {:?}th", l2_trace.number(), idx);
98+
}
99+
}
100+
95101
cycle_tracker_start!("handle tx {}", idx);
96102

97103
dev_trace!("handle {idx}th tx");
@@ -277,9 +283,11 @@ impl EvmExecutor<'_> {
277283
poseidon_code_hash.0,
278284
];
279285
cycle_track!(
280-
zktrie
281-
.update_account(addr.as_slice(), &acc_data)
282-
.unwrap_or_else(|_| panic!("failed to update account: {}", addr)),
286+
zktrie.update_account(addr.as_slice(), &acc_data).unwrap_or_else(|e| println!(
287+
"---------------->failed to update account: {:?}, address: {:?}",
288+
addr,
289+
e.to_string()
290+
)),
283291
"Zktrie::update_account"
284292
);
285293

0 commit comments

Comments
 (0)