diff --git a/.gitignore b/.gitignore index 80b7569..a40a028 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,9 @@ debug/ target/ -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +# Remove Cargo.lock from gitignore if creating an executable, leave it for +# libraries. More information at +# Cargo.lock # These are backup files generated by rustfmt @@ -34,3 +35,5 @@ Sessionx.vim tags # Persistent undo [._]*.un~ +#______________________ +commit_message_draft.md diff --git a/rust-arkworks/src/lib.rs b/rust-arkworks/src/lib.rs index 15f32dd..ec1acc9 100644 --- a/rust-arkworks/src/lib.rs +++ b/rust-arkworks/src/lib.rs @@ -14,7 +14,8 @@ pub mod sig { }; use ark_std::{marker::PhantomData, rand::Rng, UniformRand}; use secp256k1::sec1::Sec1EncodePoint; - use sha2::{Digest, Sha512}; + use sha2::digest::Output; + use sha2::{Digest, Sha256}; pub enum PlumeVersion { V1, @@ -48,7 +49,6 @@ pub mod sig { Ok(hash_to_curve::hash_to_curve::(message, pk)) } - // TODO [replace SHA-512](https://github.com/plume-sig/zk-nullifier-sig/issues/39#issuecomment-1732497672) fn compute_c_v1( g: &GroupAffine

, pk: &GroupAffine

, @@ -56,8 +56,7 @@ pub mod sig { nul: &GroupAffine

, g_r: &GroupAffine

, z: &GroupAffine

, - // should be `Output` when tests are fixed - ) -> Vec { + ) -> Output { // Compute c = sha512([g, pk, h, nul, g^r, z]) let g_bytes = affine_to_bytes::

(g); let pk_bytes = affine_to_bytes::

(pk); @@ -68,18 +67,14 @@ pub mod sig { let c_preimage_vec = [g_bytes, pk_bytes, h_bytes, nul_bytes, g_r_bytes, z_bytes].concat(); - let mut sha512_hasher = Sha512::new(); - sha512_hasher.update(c_preimage_vec.as_slice()); - sha512_hasher.finalize()[0..32].to_owned() + Sha256::digest(c_preimage_vec.as_slice()) } - // TODO [replace SHA-512](https://github.com/plume-sig/zk-nullifier-sig/issues/39#issuecomment-1732497672) fn compute_c_v2( nul: &GroupAffine

, g_r: &GroupAffine

, z: &GroupAffine

, - // should be `Output` when tests are fixed - ) -> Vec { + ) -> Output { // Compute c = sha512([nul, g^r, z]) let nul_bytes = affine_to_bytes::

(nul); let g_r_bytes = affine_to_bytes::

(g_r); @@ -87,9 +82,7 @@ pub mod sig { let c_preimage_vec = [nul_bytes, g_r_bytes, z_bytes].concat(); - let mut sha512_hasher = Sha512::new(); - sha512_hasher.update(c_preimage_vec.as_slice()); - sha512_hasher.finalize()[0..32].to_owned() + Sha256::digest(c_preimage_vec.as_slice()) } pub trait VerifiableUnpredictableFunction { diff --git a/rust-arkworks/src/tests.rs b/rust-arkworks/src/tests.rs index 759f7f6..4e33bf1 100644 --- a/rust-arkworks/src/tests.rs +++ b/rust-arkworks/src/tests.rs @@ -231,8 +231,8 @@ pub fn test_against_zk_nullifier_sig_c_and_s() { PlumeVersion::V1 ).unwrap(); - assert_eq!(coord_to_hex(sig.c.into()), "00000000000000007da1ad3f63c6180beefd0d6a8e3c87620b54f1b1d2c8287d104da9e53b6b5524"); - assert_eq!(coord_to_hex(sig.s.into()), "0000000000000000638330fea277e97ad407b32c9dc4d522454f5483abd903e6710a59d14f6fbdf2"); + assert_eq!(coord_to_hex(sig.c.into()), "0000000000000000c6a7fc2c926ddbaf20731a479fb6566f2daa5514baae5223fe3b32edbce83254"); + assert_eq!(coord_to_hex(sig.s.into()), "0000000000000000e69f027d84cb6fe5f761e333d12e975fb190d163e8ea132d7de0bd6079ba28ca"); let sig = Scheme::sign_with_r( &pp, @@ -242,7 +242,7 @@ pub fn test_against_zk_nullifier_sig_c_and_s() { PlumeVersion::V2 ).unwrap(); - assert_eq!(coord_to_hex(sig.c.into()), "0000000000000000d898f5fa7e4af2d694cb948cfe3226aebd602852beb7b32f5e9225a10c2bc925"); - assert_eq!(coord_to_hex(sig.s.into()), "00000000000000009231fa7cc28765f013def6b24310f09c8c25cb276b461d22162da027c90e348c"); + assert_eq!(coord_to_hex(sig.c.into()), "00000000000000003dbfb717705010d4f44a70720c95e74b475bd3a783ab0b9e8a6b3b363434eb96"); + assert_eq!(coord_to_hex(sig.s.into()), "0000000000000000528e8fbb6452f82200797b1a73b2947a92524bd611085a920f1177cb8098136b"); }