-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat(l2): prove block validation (#973)
**Motivation** the block execution program is missing many validation steps, this PR adds them. **Description** - adds validation steps to zkVM program
- Loading branch information
Showing
5 changed files
with
47 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,39 @@ | ||
use ethereum_rust_rlp::decode::RLPDecode; | ||
use ethereum_rust_rlp::{decode::RLPDecode, error::RLPDecodeError}; | ||
use risc0_zkvm::guest::env; | ||
|
||
use ethereum_rust_core::types::Block; | ||
use ethereum_rust_vm::{execute_block, execution_db::ExecutionDB, EvmState}; | ||
use ethereum_rust_blockchain::{validate_block, validate_gas_used}; | ||
use ethereum_rust_core::types::{Block, BlockHeader}; | ||
use ethereum_rust_vm::{execute_block, execution_db::ExecutionDB, get_state_transitions, EvmState}; | ||
|
||
fn main() { | ||
// Read inputs | ||
let (block, execution_db, parent_header) = read_inputs().expect("failed to read inputs"); | ||
let mut state = EvmState::from_exec_db(execution_db.clone()); | ||
|
||
// Validate the block pre-execution | ||
validate_block(&block, &parent_header, &state).expect("invalid block"); | ||
|
||
let receipts = execute_block(&block, &mut state).unwrap(); | ||
|
||
validate_gas_used(&receipts, &block.header).expect("invalid gas used"); | ||
|
||
let _account_updates = get_state_transitions(&mut state); | ||
|
||
// TODO: compute new state root from account updates and check it matches with the block's | ||
// header one. | ||
} | ||
|
||
fn read_inputs() -> Result<(Block, ExecutionDB, BlockHeader), RLPDecodeError> { | ||
let head_block_bytes = env::read::<Vec<u8>>(); | ||
let execution_db = env::read::<ExecutionDB>(); | ||
let parent_header_bytes = env::read::<Vec<u8>>(); | ||
|
||
let block = Block::decode(&head_block_bytes).unwrap(); | ||
let block = Block::decode(&head_block_bytes)?; | ||
let parent_header = BlockHeader::decode(&parent_header_bytes)?; | ||
|
||
// Make inputs public | ||
// make inputs public | ||
env::commit(&block); | ||
env::commit(&execution_db); | ||
env::commit(&parent_header); | ||
|
||
// Execute block | ||
let mut state = EvmState::from_exec_db(execution_db); | ||
let block_receipts = execute_block(&block, &mut state).unwrap(); | ||
env::commit(&block_receipts); | ||
Ok((block, execution_db, parent_header)) | ||
} |