Skip to content

Commit

Permalink
fix: remove usage of primitive_types H256 and update error handling t…
Browse files Browse the repository at this point in the history
…o use unionlabs H256 type
  • Loading branch information
atahanyild committed Dec 13, 2024
1 parent d607730 commit 554f395
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/evm-storage-verifier/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use trie_db::TrieError;
use unionlabs::hash::H256;

#[derive(Debug, Clone, PartialEq, thiserror::Error)]
pub enum Error {
Expand All @@ -11,14 +12,14 @@ pub enum Error {
#[error("proof is invalid due to missing value: {v}", v = serde_utils::to_hex(value))]
ValueMissing { value: Vec<u8> },
#[error("trie error ({0:?})")]
Trie(Box<TrieError<primitive_types::H256, rlp::DecoderError>>),
Trie(Box<TrieError<H256, rlp::DecoderError>>),
#[error("rlp decoding failed: {0:?}")]
RlpDecode(#[from] rlp::DecoderError),
}

// NOTE: Implemented here instead of via #[from] since Box<TrieError<primitive_types::H256, rlp::DecoderError>> doesn't implement core::error::Error
impl From<Box<TrieError<primitive_types::H256, rlp::DecoderError>>> for Error {
fn from(e: Box<TrieError<primitive_types::H256, rlp::DecoderError>>) -> Self {
// NOTE: Implemented here instead of via #[from] since Box<TrieError<H256, rlp::DecoderError>> doesn't implement core::error::Error
impl From<Box<TrieError<H256, rlp::DecoderError>>> for Error {
fn from(e: Box<TrieError<H256, rlp::DecoderError>>) -> Self {
Error::Trie(e)
}
}
1 change: 0 additions & 1 deletion lib/evm-storage-verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ fn get_node(
db.insert(hash_db::EMPTY_PREFIX, n.as_ref());
});

let root: primitive_types::H256 = root.into();
let trie = TrieDBBuilder::<EthLayout>::new(&db, &root).build();
Ok(trie.get(&keccak_256(key.as_ref()))?)
}
5 changes: 3 additions & 2 deletions lib/evm-storage-verifier/src/rlp_node_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
use std::{borrow::Borrow, marker::PhantomData, ops::Range};

use hash_db::Hasher;
use primitive_types::H256;
// use primitive_types::H256;
use rlp::{DecoderError, Prototype, Rlp, RlpStream};
use sha3::{Digest, Keccak256};
use trie_db::{
node::{NibbleSlicePlan, NodeHandlePlan, NodePlan, Value, ValuePlan},
ChildReference, NodeCodec, TrieLayout,
};
use unionlabs::hash::H256;

#[derive(Default, Clone)]
pub struct EthLayout;
Expand Down Expand Up @@ -72,7 +73,7 @@ const HASHED_NULL_NODE_BYTES: [u8; 32] = [
0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e,
0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21,
];
const HASHED_NULL_NODE: H256 = H256(HASHED_NULL_NODE_BYTES);
const HASHED_NULL_NODE: H256 = H256::new(HASHED_NULL_NODE_BYTES);

/// Encode a partial value with an iterator as input.
fn encode_partial_from_iterator_iter<'a>(
Expand Down
6 changes: 6 additions & 0 deletions lib/unionlabs/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ pub mod hash_v2 {
}
}

impl<const BYTES: usize, E: Encoding> AsMut<[u8]> for Hash<BYTES, E> {
fn as_mut(&mut self) -> &mut [u8] {
self.get_mut()
}
}

impl<const BYTES: usize, E: Encoding> Clone for Hash<BYTES, E> {
fn clone(&self) -> Self {
*self
Expand Down

0 comments on commit 554f395

Please sign in to comment.