Skip to content

Commit

Permalink
fixed for risc0 guest
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Nov 19, 2024
1 parent cd96e43 commit 29a0d5b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["crates/*"]
members = ["crates/eth-rlp-types", "crates/eth-rlp-verify"]

resolver = "2"

Expand Down
1 change: 0 additions & 1 deletion crates/eth-rlp-verify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ rlp = "0.6"
ethereum-types = "0.15"
hex = "0.4"
eyre = "0.6"
thiserror = "2.0"


[lib]
Expand Down
28 changes: 8 additions & 20 deletions crates/eth-rlp-verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,30 @@ pub mod eras;
pub mod test_helpers;
pub mod traits;
use eth_rlp_types::BlockHeader as VerifiableBlockHeader;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum VerificationError {
#[error("Block {0} is invalid (hash: {1})")]
InvalidBlock(i64, String),
#[error("Block {0} parent hash mismatch. Expected: {1}, Got: {2}")]
ParentHashMismatch(i64, String, String),
}

pub fn are_blocks_and_chain_valid(block_headers: &[VerifiableBlockHeader]) -> eyre::Result<bool> {
pub fn are_blocks_and_chain_valid(block_headers: &[VerifiableBlockHeader]) -> bool {
for (i, block) in block_headers.iter().enumerate() {
let block_hash = block.block_hash.clone();
let parent_hash = block.parent_hash.clone().unwrap_or_default();
let block_number = block.number;

if !verify_block(block_number as u64, block.clone(), &block_hash) {
return Err(VerificationError::InvalidBlock(block_number, block_hash).into());
let is_valid = verify_block(block_number as u64, block.clone(), &block_hash);

if !is_valid {
return false;
}

if i > 0 {
if i != 0 {
let previous_block = &block_headers[i - 1];
let previous_block_hash = previous_block.block_hash.clone();

if parent_hash != previous_block_hash {
return Err(VerificationError::ParentHashMismatch(
block_number,
previous_block_hash,
parent_hash,
)
.into());
return false;
}
}
}

Ok(true)
true
}

/// Verifies the validity of an Ethereum block header based on the block number and expected hash.
Expand Down

0 comments on commit 29a0d5b

Please sign in to comment.