Skip to content

Commit

Permalink
add test for the correctness of hashing symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Aug 29, 2023
1 parent f4f7613 commit 47e9bb8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2244,6 +2244,31 @@ pub mod test {
store.cdr(&opaque_cons).unwrap();
}

#[test]
fn symbol_hashing() {
let s = &mut Store::<Fr>::default();
let foo_ptr = s.intern_string("foo");
let bar_ptr = s.intern_string("bar");
let foo_bar_ptr = s.intern_symbol(&Symbol::sym_from_vec(vec!["foo".into(), "bar".into()]));

let foo_z_ptr = s.hash_expr(&foo_ptr).unwrap();
let bar_z_ptr = s.hash_expr(&bar_ptr).unwrap();
let foo_bar_hash = s.hash_expr(&foo_bar_ptr).unwrap().1;

let foo_bar_hash_manual = s.poseidon_cache.hash4(&[
bar_z_ptr.0.to_field(),
bar_z_ptr.1,
ExprTag::Sym.to_field(),
s.poseidon_cache.hash4(&[
foo_z_ptr.0.to_field(),
foo_z_ptr.1,
ExprTag::Sym.to_field(),
Fr::ZERO,
]),
]);
assert_eq!(foo_bar_hash, foo_bar_hash_manual);
}

#[test]
fn sym_and_key_hashes() {
let s = &mut Store::<Fr>::default();
Expand Down

0 comments on commit 47e9bb8

Please sign in to comment.