Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve #39 #42

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html>
Cargo.lock

# These are backup files generated by rustfmt
Expand Down Expand Up @@ -34,3 +35,5 @@ Sessionx.vim
tags
# Persistent undo
[._]*.un~
#______________________
commit_message_draft.md
19 changes: 6 additions & 13 deletions rust-arkworks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,16 +49,14 @@ pub mod sig {
Ok(hash_to_curve::hash_to_curve::<Fq, P>(message, pk))
}

// TODO [replace SHA-512](https://github.com/plume-sig/zk-nullifier-sig/issues/39#issuecomment-1732497672)
fn compute_c_v1<P: SWModelParameters>(
g: &GroupAffine<P>,
pk: &GroupAffine<P>,
h: &GroupAffine<P>,
nul: &GroupAffine<P>,
g_r: &GroupAffine<P>,
z: &GroupAffine<P>,
// should be `Output<Sha256>` when tests are fixed <https://github.com/plume-sig/zk-nullifier-sig/issues/39#issuecomment-1732538695>
) -> Vec<u8> {
) -> Output<Sha256> {
// Compute c = sha512([g, pk, h, nul, g^r, z])
let g_bytes = affine_to_bytes::<P>(g);
let pk_bytes = affine_to_bytes::<P>(pk);
Expand All @@ -68,28 +67,22 @@ 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<P: SWModelParameters>(
nul: &GroupAffine<P>,
g_r: &GroupAffine<P>,
z: &GroupAffine<P>,
// should be `Output<Sha256>` when tests are fixed <https://github.com/plume-sig/zk-nullifier-sig/issues/39#issuecomment-1732538695>
) -> Vec<u8> {
) -> Output<Sha256> {
// Compute c = sha512([nul, g^r, z])
let nul_bytes = affine_to_bytes::<P>(nul);
let g_r_bytes = affine_to_bytes::<P>(g_r);
let z_bytes = affine_to_bytes::<P>(z);

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 {
Expand Down
8 changes: 4 additions & 4 deletions rust-arkworks/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");

}