Skip to content

Commit df4953a

Browse files
authored
fix(l2): uncomment final state check and validate gas in sp1 and exec (#2558)
**Motivation** These were commented in #2291 (merged to main), probably for test/dev purposes, and left like that
1 parent 2d049b9 commit df4953a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

crates/l2/prover/src/backends/exec.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ethrex_blockchain::validate_block;
1+
use ethrex_blockchain::{validate_block, validate_gas_used};
22
use ethrex_l2::utils::prover::proving_systems::{ProofCalldata, ProverType};
33
use ethrex_l2_sdk::calldata::Value;
44
use ethrex_vm::Evm;
@@ -57,19 +57,19 @@ fn execution_program(input: ProgramInput) -> Result<ProgramOutput, Box<dyn std::
5757
let fork = db.chain_config.fork(block.header.timestamp);
5858

5959
let mut vm = Evm::from_execution_db(db.clone());
60-
let _result = vm.execute_block(&block)?;
61-
// let receipts = result.receipts;
60+
let result = vm.execute_block(&block)?;
61+
let receipts = result.receipts;
6262
let account_updates = vm.get_state_transitions(fork)?;
63-
// validate_gas_used(&receipts, &block.header)?;
63+
validate_gas_used(&receipts, &block.header)?;
6464

6565
// Update state trie
6666
update_tries(&mut state_trie, &mut storage_tries, &account_updates)?;
6767

6868
// Calculate final state root hash and check
6969
let final_state_hash = state_trie.hash_no_commit();
70-
// if final_state_hash != block.header.state_root {
71-
// return Err("invalid final state trie".to_string().into());
72-
// }
70+
if final_state_hash != block.header.state_root {
71+
return Err("invalid final state trie".to_string().into());
72+
}
7373

7474
Ok(ProgramOutput {
7575
initial_state_hash,

crates/l2/prover/zkvm/interface/sp1/src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ pub fn main() {
3636
let mut evm = Evm::from_execution_db(db.clone());
3737
let result = evm.execute_block(&block).expect("failed to execute block");
3838
let receipts = result.receipts;
39-
let account_updates = evm.get_state_transitions(fork).expect("failed to get state transitions");
40-
// validate_gas_used(&receipts, &block.header).expect("invalid gas used");
39+
let account_updates = evm
40+
.get_state_transitions(fork)
41+
.expect("failed to get state transitions");
42+
validate_gas_used(&receipts, &block.header).expect("invalid gas used");
4143

4244
// Output gas for measurement purposes
4345
let cumulative_gas_used = receipts
@@ -52,9 +54,9 @@ pub fn main() {
5254

5355
// Calculate final state root hash and check
5456
let final_state_hash = state_trie.hash_no_commit();
55-
// if final_state_hash != block.header.state_root {
56-
// panic!("invalid final state trie");
57-
// }
57+
if final_state_hash != block.header.state_root {
58+
panic!("invalid final state trie");
59+
}
5860

5961
sp1_zkvm::io::commit(&ProgramOutput {
6062
initial_state_hash,

0 commit comments

Comments
 (0)