Skip to content

Commit

Permalink
Add serialisation, types and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ax0 committed Dec 2, 2024
1 parent f59c940 commit 97c04b2
Show file tree
Hide file tree
Showing 10 changed files with 1,103 additions and 666 deletions.
880 changes: 562 additions & 318 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions parcnet-pod/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ path = "src/lib.rs"
ark-bn254 = "0.4.0"
ark-ff = "0.4.0"
ark-std = "0.4.0"
babyjubjub-ark = { git = "https://github.com/ax0/babyjubjub-ark", version = "0.0.1" }
babyjubjub-ark = { git = "https://github.com/ax0/babyjubjub-ark" }
base64 = "0.22.1"
ff = { package = "ff_ce", version = "0.11", features = ["derive"] }
hex = "0.4.3"
indexmap = { version = "2.5.0", features = ["serde"] }
indexmap = { version = "2.5.0", features = ["rayon", "serde"] }
lazy_static = "1.5.0"
num-bigint = { version = "0.4.6", features = ["serde"] }
num-traits = "0.2.19"
poseidon-ark = { git = "https://github.com/arnaucube/poseidon-ark", version = "0.0.1" }
poseidon-rs = "0.0.10"
rand = "0.8.5"
rayon = "1.10.0"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = { version = "1.0.128", features = ["preserve_order"] }
serde_with = { version = "3.11.0", features = ["hex"] }
sha2 = "0.10.8"
thiserror = "1.0.64"
time = {version = "0.3.36", features = ["macros", "serde"]}
url = "2.5.2"
urlencoding = "2.1.3"
uuid = { version = "1.10.0", features = ["v4", "serde"] }
Expand Down
6 changes: 3 additions & 3 deletions parcnet-pod/benches/pod_benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ark_bn254::Fr as Fq;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use num_bigint::BigInt;
use parcnet_pod::pod::pod_impl::{create_pod, PodValue};
use parcnet_pod::pod::{create_pod, value::PodValue};

fn benchmark_create_pod(c: &mut Criterion) {
let private_key = vec![0u8; 32];
Expand Down Expand Up @@ -68,7 +68,7 @@ fn benchmark_create_pod(c: &mut Criterion) {
("element".to_string(), PodValue::String("holy".to_string())),
(
"cryptoHash".to_string(),
PodValue::Cryptographic(BigInt::from(1234567890)),
PodValue::Cryptographic(Fq::from(1234567890)),
),
]),
)
Expand Down
6 changes: 3 additions & 3 deletions parcnet-pod/src/crypto/lean_imt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ pub fn lean_poseidon_imt(inputs: &[Fq]) -> Result<Fq, &'static str> {
let mut new_items = Vec::new();
for chunk in items.chunks(2) {
if chunk.len() == 2 {
let hash = poseidon.hash(vec![chunk[0].clone(), chunk[1].clone()]).map_err(|_| "Error hashing")?;
let hash = poseidon.hash(vec![chunk[0], chunk[1]]).map_err(|_| "Error hashing")?;
new_items.push(hash);
} else {
new_items.push(chunk[0].clone());
new_items.push(chunk[0]);
}
}
items = new_items;
Expand All @@ -36,7 +36,7 @@ mod tests {

#[test]
fn test_lean_imt() -> Result<(), Error> {
let inputs = ["1", "2", "3", "4", "5"].into_iter().map(|s| Fq::from_str(s)).collect::<Result<Vec<_>, ()>>().map_err(|_| "Error converting strings to fields.")?;
let inputs = ["1", "2", "3", "4", "5"].into_iter().map(Fq::from_str).collect::<Result<Vec<_>, ()>>().map_err(|_| "Error converting strings to fields.")?;

let result = lean_poseidon_imt(&inputs);
assert!(result.is_ok());
Expand Down
2 changes: 1 addition & 1 deletion parcnet-pod/src/pod/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ macro_rules! pod_entries {
($($key:expr => $value:expr),* $(,)?) => {{
vec![
$(
(String::from($key), $crate::pod::pod_impl::PodValue::from($value)),
(String::from($key), $crate::pod::PodValue::from($value)),
)*
]
}};
Expand Down
Loading

0 comments on commit 97c04b2

Please sign in to comment.