From 679f3b781c970f57398e5354375bb0d2aa21646d Mon Sep 17 00:00:00 2001 From: atahanyild Date: Fri, 13 Dec 2024 12:38:51 +0300 Subject: [PATCH 1/3] fix: remove usage of primitive_types H256 and update error handling to use unionlabs H256 type --- lib/evm-storage-verifier/src/error.rs | 9 +++++---- lib/evm-storage-verifier/src/lib.rs | 1 - lib/evm-storage-verifier/src/rlp_node_codec.rs | 5 +++-- lib/unionlabs/src/hash.rs | 6 ++++++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/evm-storage-verifier/src/error.rs b/lib/evm-storage-verifier/src/error.rs index 977fe48b3c..e02df173f5 100644 --- a/lib/evm-storage-verifier/src/error.rs +++ b/lib/evm-storage-verifier/src/error.rs @@ -1,4 +1,5 @@ use trie_db::TrieError; +use unionlabs::hash::H256; #[derive(Debug, Clone, PartialEq, thiserror::Error)] pub enum Error { @@ -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 }, #[error("trie error ({0:?})")] - Trie(Box>), + Trie(Box>), #[error("rlp decoding failed: {0:?}")] RlpDecode(#[from] rlp::DecoderError), } -// NOTE: Implemented here instead of via #[from] since Box> doesn't implement core::error::Error -impl From>> for Error { - fn from(e: Box>) -> Self { +// NOTE: Implemented here instead of via #[from] since Box> doesn't implement core::error::Error +impl From>> for Error { + fn from(e: Box>) -> Self { Error::Trie(e) } } diff --git a/lib/evm-storage-verifier/src/lib.rs b/lib/evm-storage-verifier/src/lib.rs index 71dde6c051..d9384598f6 100644 --- a/lib/evm-storage-verifier/src/lib.rs +++ b/lib/evm-storage-verifier/src/lib.rs @@ -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::::new(&db, &root).build(); Ok(trie.get(&keccak_256(key.as_ref()))?) } diff --git a/lib/evm-storage-verifier/src/rlp_node_codec.rs b/lib/evm-storage-verifier/src/rlp_node_codec.rs index 6e119b003b..8befc2d755 100644 --- a/lib/evm-storage-verifier/src/rlp_node_codec.rs +++ b/lib/evm-storage-verifier/src/rlp_node_codec.rs @@ -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; @@ -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>( diff --git a/lib/unionlabs/src/hash.rs b/lib/unionlabs/src/hash.rs index d5853cc9f3..0f36d5b25b 100644 --- a/lib/unionlabs/src/hash.rs +++ b/lib/unionlabs/src/hash.rs @@ -252,6 +252,12 @@ pub mod hash_v2 { } } + impl AsMut<[u8]> for Hash { + fn as_mut(&mut self) -> &mut [u8] { + self.get_mut() + } + } + impl Clone for Hash { fn clone(&self) -> Self { *self From e8badc9e2d777ac843e60acc1c6a7f2a0bd19e46 Mon Sep 17 00:00:00 2001 From: atahanyild Date: Fri, 13 Dec 2024 17:32:00 +0300 Subject: [PATCH 2/3] fix(evm): remove unused import of primitive_types H256 in rlp_node_codec --- lib/evm-storage-verifier/src/rlp_node_codec.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/evm-storage-verifier/src/rlp_node_codec.rs b/lib/evm-storage-verifier/src/rlp_node_codec.rs index 8befc2d755..8f21efaf52 100644 --- a/lib/evm-storage-verifier/src/rlp_node_codec.rs +++ b/lib/evm-storage-verifier/src/rlp_node_codec.rs @@ -19,7 +19,6 @@ use std::{borrow::Borrow, marker::PhantomData, ops::Range}; use hash_db::Hasher; -// use primitive_types::H256; use rlp::{DecoderError, Prototype, Rlp, RlpStream}; use sha3::{Digest, Keccak256}; use trie_db::{ From b963386d7678be871312d23f54e3a7dd5efa41b4 Mon Sep 17 00:00:00 2001 From: atahanyild Date: Sat, 14 Dec 2024 01:44:52 +0300 Subject: [PATCH 3/3] added ref for movefmt in aptos.nix --- lib/aptos.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/aptos.nix b/lib/aptos.nix index 6abe2dfc11..1ef53d344d 100644 --- a/lib/aptos.nix +++ b/lib/aptos.nix @@ -97,6 +97,7 @@ _: { src = builtins.fetchGit { url = "https://github.com/movebit/movefmt"; + ref = "develop"; rev = version; };