diff --git a/src/client/client.rs b/src/client/client.rs index 12e15a0..4af29c5 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use ethers::prelude::{Address, U256}; use eyre::Result; @@ -10,7 +8,7 @@ use crate::execution::ExecutionClient; pub struct Client { consensus: ConsensusClient, - execution: Arc, + execution: ExecutionClient, } impl Client { @@ -24,7 +22,7 @@ impl Client { Ok(Client { consensus, - execution: Arc::new(execution), + execution, }) } diff --git a/src/execution/evm.rs b/src/execution/evm.rs index 33c7add..e5e7acb 100644 --- a/src/execution/evm.rs +++ b/src/execution/evm.rs @@ -1,4 +1,4 @@ -use std::{str::FromStr, sync::Arc, thread}; +use std::{str::FromStr, thread}; use bytes::Bytes; use ethers::prelude::{Address, H160, H256, U256}; @@ -14,7 +14,7 @@ pub struct Evm { } impl Evm { - pub fn new(execution: Arc, payload: ExecutionPayload) -> Self { + pub fn new(execution: ExecutionClient, payload: ExecutionPayload) -> Self { let mut evm: EVM = EVM::new(); let db = ProofDB::new(execution, payload); evm.database(db); @@ -47,13 +47,13 @@ impl Evm { } struct ProofDB { - execution: Arc, + execution: ExecutionClient, payload: ExecutionPayload, error: Option, } impl ProofDB { - pub fn new(execution: Arc, payload: ExecutionPayload) -> Self { + pub fn new(execution: ExecutionClient, payload: ExecutionPayload) -> Self { ProofDB { execution, payload, diff --git a/src/execution/proof.rs b/src/execution/proof.rs index c979486..f38df2f 100644 --- a/src/execution/proof.rs +++ b/src/execution/proof.rs @@ -7,6 +7,7 @@ pub fn verify_proof(proof: &Vec>, root: &Vec, path: &Vec, value: let mut expected_hash = root.clone(); let mut path_offset = 0; + for (i, node) in proof.iter().enumerate() { if expected_hash != keccak256(node).to_vec() { return false; @@ -21,6 +22,13 @@ pub fn verify_proof(proof: &Vec>, root: &Vec, path: &Vec, value: path_offset += 1; } else if node_list.len() == 2 { if i == proof.len() - 1 { + + // exclusion proof + if &node_list[0][skip_length(&node_list[0])..] != &path[path_offset..] && value[0] == 0x80 { + return true + } + + // inclusion proof if &node_list[1] != value { return false; } @@ -35,6 +43,15 @@ pub fn verify_proof(proof: &Vec>, root: &Vec, path: &Vec, value: true } +fn skip_length(node: &Vec) -> usize { + let nibble = get_nibble(node, 0); + match nibble { + 2 => 2, + 3 => 1, + _ => 0, + } +} + fn get_nibble(path: &Vec, offset: usize) -> u8 { let byte = path[offset / 2]; if offset % 2 == 0 {