-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce StateCommitment type
- Loading branch information
Showing
18 changed files
with
120 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use alloy_primitives::B256; | ||
use revm_primitives::keccak256; | ||
|
||
/// Trait for hashing keys in state. | ||
pub trait KeyHasher: Default + Clone + Send + Sync + 'static { | ||
/// Hashes the given bytes into a 256-bit hash. | ||
fn hash_key<T: AsRef<[u8]>>(bytes: T) -> B256; | ||
} | ||
|
||
/// A key hasher that uses the Keccak-256 hash function. | ||
#[derive(Clone, Debug, Default)] | ||
pub struct KeccakKeyHasher; | ||
|
||
impl KeyHasher for KeccakKeyHasher { | ||
fn hash_key<T: AsRef<[u8]>>(bytes: T) -> B256 { | ||
keccak256(bytes) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::{ | ||
DatabaseHashedCursorFactory, DatabaseProof, DatabaseStateRoot, DatabaseStorageRoot, | ||
DatabaseTrieCursorFactory, DatabaseTrieWitness, | ||
}; | ||
use reth_db::transaction::DbTx; | ||
use reth_trie::{ | ||
proof::Proof, witness::TrieWitness, KeccakKeyHasher, KeyHasher, StateRoot, StorageRoot, | ||
}; | ||
|
||
/// The `StateCommitment` trait provides associated types for state commitment operations. | ||
pub trait StateCommitment: std::fmt::Debug + Send + Sync + Unpin + 'static { | ||
/// The state root type. | ||
type StateRoot<'a, TX: DbTx + 'a>: DatabaseStateRoot<'a, TX>; | ||
/// The storage root type. | ||
type StorageRoot<'a, TX: DbTx + 'a>: DatabaseStorageRoot<'a, TX>; | ||
/// The state proof type. | ||
type StateProof<'a, TX: DbTx + 'a>: DatabaseProof<'a, TX>; | ||
/// The state witness type. | ||
type StateWitness<'a, TX: DbTx + 'a>: DatabaseTrieWitness<'a, TX>; | ||
/// The key hasher type. | ||
type KeyHasher: KeyHasher; | ||
} | ||
|
||
/// The state commitment type for Ethereum's Merkle Patricia Trie. | ||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub struct MerklePatriciaTrie; | ||
|
||
impl StateCommitment for MerklePatriciaTrie { | ||
type StateRoot<'a, TX: DbTx + 'a> = | ||
StateRoot<DatabaseTrieCursorFactory<'a, TX>, DatabaseHashedCursorFactory<'a, TX>>; | ||
type StorageRoot<'a, TX: DbTx + 'a> = | ||
StorageRoot<DatabaseTrieCursorFactory<'a, TX>, DatabaseHashedCursorFactory<'a, TX>>; | ||
type StateProof<'a, TX: DbTx + 'a> = | ||
Proof<DatabaseTrieCursorFactory<'a, TX>, DatabaseHashedCursorFactory<'a, TX>>; | ||
type StateWitness<'a, TX: DbTx + 'a> = | ||
TrieWitness<DatabaseTrieCursorFactory<'a, TX>, DatabaseHashedCursorFactory<'a, TX>>; | ||
type KeyHasher = KeccakKeyHasher; | ||
} |
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