Skip to content

Commit

Permalink
Impled building account trie entries
Browse files Browse the repository at this point in the history
Cleaned up and finished account parsing

Initial (buggy!) impl of trie insertion

Initial work on trie tests

Filled in trie `todo!()`s

First trie test now passes

Leaf splitting now works

- Just realized that I'm reading the keys backwards, so I'll need to
  deal with that.
  • Loading branch information
BGluth committed Sep 12, 2022
0 parents commit c9eedc9
Show file tree
Hide file tree
Showing 8 changed files with 757 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Cargo.lock
/**/target
/target
**/*.rs.bk
*.iml
.idea/
.vscode
17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "zero_eth_trie_utils"
description = "Types and utility functions for building/working with partial Ethereum tries."
version = "0.1.0"
authors = ["Polygon Zero <[email protected]>"]
edition = "2021"

[dependencies]
anyhow = "1.0.64"
ethereum-types = "0.13.1"
itertools = "0.10.3"
log = "0.4.17"
num-traits = "0.2.15"
hex = "0.4.3"

[dev-dependencies]
pretty_env_logger = "0.4.0"
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
unstable_features = true
group_imports = "StdExternalCrate"
wrap_comments = true
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod partial_trie;
pub mod trie_builder;
mod types;
mod utils;
34 changes: 34 additions & 0 deletions src/partial_trie.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use ethereum_types::U256;

#[derive(Clone, Debug)]
/// A partial trie, or a sub-trie thereof. This mimics the structure of an Ethereum trie, except
/// with an additional `Hash` node type, representing a node whose data is not needed to process
/// our transaction.
pub enum PartialTrie {
/// An empty trie.
Empty,
/// The digest of trie whose data does not need to be stored.
Hash(U256),
/// A branch node, which consists of 16 children and an optional value.
Branch {
children: [Box<PartialTrie>; 16],
value: Option<U256>,
},
/// An extension node, which consists of a list of nibbles and a single child.
Extension {
nibbles: Nibbles,
child: Box<PartialTrie>,
},
/// A leaf node, which consists of a list of nibbles and a value.
Leaf { nibbles: Nibbles, value: Vec<u8> },
}

#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
/// A sequence of nibbles.
pub struct Nibbles {
/// The number of nibbles in this sequence.
pub count: usize,
/// A packed encoding of these nibbles. Only the first (least significant) `4 * count` bits are
/// used. The rest are unused and should be zero.
pub packed: U256,
}
Loading

0 comments on commit c9eedc9

Please sign in to comment.