-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixing a bug that would use 256 siblings instead of 254 (#34)
* fix: fixing a bug that would use 256 siblings instead of 254 * bumping noirup in github actions * bumping noirup in github actions * constraining bignum to limbs of size u128
- Loading branch information
1 parent
ce5e584
commit 961eaf6
Showing
11 changed files
with
81 additions
and
118 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,67 +1,41 @@ | ||
use bignum::BigNum; | ||
use bignum::BigNumTrait; | ||
use bignum::fields::bn254Fq::BN254_Fq_Params; | ||
use std::hash::poseidon2::Poseidon2::hash; | ||
use trees::merkle::MerkleTree; | ||
|
||
type BN = BigNum<3, 254, BN254_Fq_Params>; | ||
|
||
fn hasher(input: [BN; 2]) -> BN { | ||
let limbs: [Field; 6] = | ||
let limbs: [u128; 6] = | ||
&[].append(input[0].get_limbs_slice()).append(input[1].get_limbs_slice()).as_array(); | ||
let hash_field = hash(limbs, 6); | ||
BigNum::from_slice([hash_field, 0x00, 0x00]) | ||
let hash_field = hash(limbs.map(|limb| limb as Field), 6); | ||
BigNum::from_slice([hash_field as u128, 0x00, 0x00]) | ||
} | ||
|
||
#[test] | ||
fn test_merkle_tree_add_bignum() { | ||
let old_root = BigNum::from_slice([ | ||
0x21447efbbddb57d6fc5ad24d906388492e82c44e5160425258dd4ea995e3a06e, | ||
0x00, | ||
0x00, | ||
]); | ||
let old_root = BigNum::from_slice([0x21447efbbddb57d6fc5ad24d90638849, 0x00, 0x00]); | ||
let mut mt = MerkleTree::from(old_root, hasher); | ||
|
||
let leaf = BigNum::from_slice([ | ||
0x2bc00d90b885b09d12764e764410f7f693f514f7f3ca14d916741ff3968b3079, | ||
0x00, | ||
0x00, | ||
]); | ||
let paths = [BigNum::from_slice([ | ||
0x21447efbbddb57d6fc5ad24d906388492e82c44e5160425258dd4ea995e3a06e, | ||
0x00, | ||
0x00, | ||
])]; | ||
let leaf = BigNum::from_slice([0x2bc00d90b885b09d12764e764410f7f6, 0x00, 0x00]); | ||
let paths = [BigNum::from_slice([0x21447efbbddb57d6fc5ad24d90638849, 0x00, 0x00])]; | ||
|
||
mt.add(leaf, 0x01, paths); | ||
} | ||
|
||
#[test] | ||
fn test_merkle_tree_add_really_bignum() { | ||
let old_root = BigNum::from_slice([ | ||
0x2494b80a540ec0a0124a9dba7d5922e3250507677700e9eb680e30a279a72742, | ||
0x00, | ||
0x00, | ||
]); | ||
let old_root = BigNum::from_slice([0x2494b80a540ec0a0124a9dba7d5922e, 0x00, 0x00]); | ||
let mut mt = MerkleTree::from(old_root, hasher); | ||
|
||
let leaf = BN::from_slice([ | ||
0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000, | ||
0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000, | ||
0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000, | ||
0x30644e72e131a029b85045b68181585, | ||
0x30644e72e131a029b85045b68181585, | ||
0x30644e72e131a029b85045b68181585, | ||
]); | ||
|
||
let paths = [BigNum::from_slice([ | ||
0x2494b80a540ec0a0124a9dba7d5922e3250507677700e9eb680e30a279a72742, | ||
0x00, | ||
0x00, | ||
])]; | ||
let paths = [BigNum::from_slice([0x2494b80a540ec0a0124a9dba7d5922e, 0x00, 0x00])]; | ||
mt.add(leaf, 0x01, paths); | ||
assert( | ||
mt.root | ||
== BN::from_slice([ | ||
0x1a9a6cfaea6bfb6f8dec45c5e333cf568d1f74a32acaca391e510a690b3767f9, | ||
0x00, | ||
0x00, | ||
]), | ||
); | ||
assert(mt.root == BN::from_slice([198795359253477292896825724889155436891, 0x00, 0x00])); | ||
} |
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
Oops, something went wrong.