Skip to content

Commit

Permalink
Merge pull request #158 from mempirate/feat/sha2-asm
Browse files Browse the repository at this point in the history
`sha2-asm` feature
  • Loading branch information
ralexstokes committed Sep 4, 2024
2 parents 9c19a3c + 327b863 commit 1df4cd9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions ssz-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exclude = ["tests/data"]
[features]
default = ["serde", "std"]
std = ["bitvec/default", "sha2/default", "alloy-primitives/default"]
sha2-asm = ["sha2/asm"]
serde = ["dep:serde", "alloy-primitives/serde"]

[dependencies]
Expand Down
28 changes: 28 additions & 0 deletions ssz-rs/src/merkleization/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,34 @@ pub(crate) mod tests {
assert!(result.is_ok());
}

#[test]
fn test_list_proving() {
let inner: Vec<List<u8, 1073741824>> = vec![
vec![0u8, 1u8, 2u8].try_into().unwrap(),
vec![3u8, 4u8, 5u8].try_into().unwrap(),
vec![6u8, 7u8, 8u8].try_into().unwrap(),
vec![9u8, 10u8, 11u8].try_into().unwrap(),
];

// Emulate a transactions tree
let outer: List<List<u8, 1073741824>, 1048576> = List::try_from(inner).unwrap();

let root = outer.hash_tree_root().unwrap();

let index = PathElement::from(1);

let start_proof = std::time::Instant::now();
let (proof, witness) = outer.prove(&[index]).unwrap();
println!("Generated proof in {:?}", start_proof.elapsed());

// Root and witness must be the same
assert_eq!(root, witness);

let start_verify = std::time::Instant::now();
assert!(proof.verify(witness).is_ok());
println!("Verified proof in {:?}", start_verify.elapsed());
}

#[test]
fn test_proving_primitives_fails_with_bad_path() {
let data = 8u8;
Expand Down

0 comments on commit 1df4cd9

Please sign in to comment.