-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: rust-reference-impls: Refactor reference impls into directory
- Loading branch information
Showing
7 changed files
with
101 additions
and
8 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
9 changes: 3 additions & 6 deletions
9
...eidon-reference-implementation/Cargo.toml → test/rust-reference-impls/Cargo.toml
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,10 +1,7 @@ | ||
[package] | ||
name = "poseidon-reference-implementation" | ||
version = "0.1.0" | ||
edition = "2021" | ||
[workspace] | ||
members = ["poseidon", "merkle"] | ||
|
||
[dependencies] | ||
[workspace.dependencies] | ||
renegade-constants = { package = "constants", git = "https://github.com/renegade-fi/renegade.git", default-features = false } | ||
renegade-crypto = { git = "https://github.com/renegade-fi/renegade.git" } | ||
|
||
num-bigint = "0.4" |
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,9 @@ | ||
[package] | ||
name = "merkle" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
renegade-constants.workspace = true | ||
renegade-crypto.workspace = true | ||
num-bigint.workspace = true |
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,42 @@ | ||
use renegade_constants::Scalar; | ||
use renegade_crypto::fields::scalar_to_biguint; | ||
use renegade_crypto::hash::Poseidon2Sponge; | ||
|
||
fn main() { | ||
let args: Vec<String> = std::env::args().collect(); | ||
if args.len() < 4 { | ||
eprintln!("Usage: {} <input> <idx> <sister_leaves>", args[0]); | ||
std::process::exit(1); | ||
} | ||
|
||
let input = Scalar::from_decimal_string(&args[1]).unwrap(); | ||
let idx = args[2].parse::<u64>().unwrap(); | ||
let sister_leaves: Vec<Scalar> = args[3] | ||
.trim_matches(|c| c == '[' || c == ']') | ||
.split(',') | ||
.map(|s| Scalar::from_decimal_string(s).unwrap()) | ||
.collect(); | ||
|
||
let result = hash_merkle(input, idx, &sister_leaves); | ||
let res_biguint = scalar_to_biguint(&result); | ||
let res_hex = format!("{res_biguint:x}"); | ||
println!("RES:0x{}", res_hex); | ||
} | ||
|
||
fn hash_merkle(input: Scalar, idx: u64, sister_leaves: &[Scalar]) -> Scalar { | ||
let mut current = input; | ||
let mut current_idx = idx; | ||
let mut sponge = Poseidon2Sponge::new(); | ||
|
||
for sister in sister_leaves { | ||
let inputs = if current_idx % 2 == 0 { | ||
[current.inner(), sister.inner()] | ||
} else { | ||
[sister.inner(), current.inner()] | ||
}; | ||
current = Scalar::new(sponge.hash(&inputs)); | ||
current_idx /= 2; | ||
} | ||
|
||
current | ||
} |
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,9 @@ | ||
[package] | ||
name = "poseidon" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
renegade-constants.workspace = true | ||
renegade-crypto.workspace = true | ||
num-bigint.workspace = true |
File renamed without changes.