mirror of
https://github.com/arnaucube/babyjubjub-ark.git
synced 2026-01-13 17:21:29 +01:00
Poseidon load static ref avoiding load each time
Benchmarks (On a Intel(R) Core(TM) i7-8705G CPU @ 3.10GHz, with 32 GB of RAM): - Old: ``` sign time: [953.50 us 953.73 us 953.98 us] verify time: [832.24 us 832.38 us 832.52 us] ``` - New: ``` sign time: [559.84 us 568.41 us 576.26 us] verify time: [376.59 us 376.68 us 376.78 us] ```
This commit is contained in:
@@ -20,7 +20,7 @@ generic-array = "0.13.2"
|
|||||||
tiny-keccak = "1.5"
|
tiny-keccak = "1.5"
|
||||||
rustc-hex = "1.0.0"
|
rustc-hex = "1.0.0"
|
||||||
mimc-rs = "0.0.2"
|
mimc-rs = "0.0.2"
|
||||||
poseidon-rs = "0.0.3"
|
poseidon-rs = "0.0.4"
|
||||||
arrayref = "0.3.5"
|
arrayref = "0.3.5"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ lazy_static! {
|
|||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
>> 3;
|
>> 3;
|
||||||
|
static ref poseidon: poseidon_rs::Poseidon = Poseidon::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -306,7 +307,6 @@ impl PrivateKey {
|
|||||||
let a = &self.public()?;
|
let a = &self.public()?;
|
||||||
|
|
||||||
let hm_input = vec![r8.x.clone(), r8.y.clone(), a.x.clone(), a.y.clone(), msgFr];
|
let hm_input = vec![r8.x.clone(), r8.y.clone(), a.x.clone(), a.y.clone(), msgFr];
|
||||||
let poseidon = Poseidon::new();
|
|
||||||
let hm = poseidon.hash(hm_input)?;
|
let hm = poseidon.hash(hm_input)?;
|
||||||
|
|
||||||
let mut s = &self.key << 3;
|
let mut s = &self.key << 3;
|
||||||
@@ -345,7 +345,6 @@ pub fn schnorr_hash(pk: &Point, msg: BigInt, c: &Point) -> Result<BigInt, String
|
|||||||
}
|
}
|
||||||
let msgFr: Fr = Fr::from_str(&msg.to_string()).unwrap();
|
let msgFr: Fr = Fr::from_str(&msg.to_string()).unwrap();
|
||||||
let hm_input = vec![pk.x.clone(), pk.y.clone(), c.x.clone(), c.y.clone(), msgFr];
|
let hm_input = vec![pk.x.clone(), pk.y.clone(), c.x.clone(), c.y.clone(), msgFr];
|
||||||
let poseidon = Poseidon::new();
|
|
||||||
let h = poseidon.hash(hm_input)?;
|
let h = poseidon.hash(hm_input)?;
|
||||||
println!("h {:?}", h.to_string());
|
println!("h {:?}", h.to_string());
|
||||||
let hB = BigInt::parse_bytes(to_hex(&h).as_bytes(), 16).unwrap();
|
let hB = BigInt::parse_bytes(to_hex(&h).as_bytes(), 16).unwrap();
|
||||||
@@ -387,7 +386,6 @@ pub fn verify(pk: Point, sig: Signature, msg: BigInt) -> bool {
|
|||||||
if msg > Q.clone() {
|
if msg > Q.clone() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let (_, msg_bytes) = msg.to_bytes_be();
|
|
||||||
let msgFr: Fr = Fr::from_str(&msg.to_string()).unwrap();
|
let msgFr: Fr = Fr::from_str(&msg.to_string()).unwrap();
|
||||||
let hm_input = vec![
|
let hm_input = vec![
|
||||||
sig.r_b8.x.clone(),
|
sig.r_b8.x.clone(),
|
||||||
@@ -396,7 +394,6 @@ pub fn verify(pk: Point, sig: Signature, msg: BigInt) -> bool {
|
|||||||
pk.y.clone(),
|
pk.y.clone(),
|
||||||
msgFr,
|
msgFr,
|
||||||
];
|
];
|
||||||
let poseidon = Poseidon::new();
|
|
||||||
let hm = match poseidon.hash(hm_input) {
|
let hm = match poseidon.hash(hm_input) {
|
||||||
Result::Err(_) => return false,
|
Result::Err(_) => return false,
|
||||||
Result::Ok(hm) => hm,
|
Result::Ok(hm) => hm,
|
||||||
|
|||||||
Reference in New Issue
Block a user