Skip to content

Instantly share code, notes, and snippets.

@Michael-Qedit
Created November 23, 2021 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Michael-Qedit/899147e9716b305c93967d62c4c347b9 to your computer and use it in GitHub Desktop.
Save Michael-Qedit/899147e9716b305c93967d62c4c347b9 to your computer and use it in GitHub Desktop.
ZKHack - Puzzle 5 - Solution
#![allow(unused, unreachable_code)]
use ark_ed_on_bls12_381::Fr;
use ark_ff::{Field, UniformRand};
use strong_adaptivity::{Instance, Proof, data::puzzle_data, prove, Witness, ProofCommitment, ProofResponse};
use strong_adaptivity::verify;
use strong_adaptivity::PUZZLE_DESCRIPTION;
use prompt::{puzzle, welcome};
use rand::rngs::ThreadRng;
use std::ops::Div;
use strong_adaptivity::msg_equality_arg::utils::b2s_hash_to_field;
fn main() {
welcome();
puzzle(PUZZLE_DESCRIPTION);
let ck = puzzle_data();
let mut rng = ThreadRng::default();
let tmp_1 = Fr::rand(&mut rng);
let rho = Fr::rand(&mut rng);
let comm_rho = ck.commit_with_explicit_randomness(tmp_1, rho);
let tmp_2 = Fr::rand(&mut rng);
let tau = Fr::rand(&mut rng);
let comm_tau = ck.commit_with_explicit_randomness(tmp_2, tau);
let commitment = ProofCommitment {
comm_rho,
comm_tau,
};
let challenge = b2s_hash_to_field(&(ck, commitment));
let a_2 = Fr::rand(&mut rng);
let (comm_2, r_2) = ck.commit_with_rng(a_2, &mut rng);
let r_1 = Fr::rand(&mut rng);
let s = (tmp_2 + challenge*a_2);
let u = rho + challenge * r_1;
let t = tau + challenge * r_2;
let a_1 = (s - tmp_1) / challenge;
let comm_1 = ck.commit_with_explicit_randomness(a_1, r_1);
let (instance, witness, proof): (Instance, (Fr, Fr, Fr, Fr), Proof) = {
(
Instance {
comm_1,
comm_2
},
(a_1, r_1, a_2, r_2),
Proof {
commitment,
response: ProofResponse {
s,
u,
t
}
}
)
};
let (a_1, r_1, a_2, r_2) = witness;
assert!(verify(&ck, &instance, &proof));
// Check that commitments are correct
assert_eq!(ck.commit_with_explicit_randomness(a_1, r_1), instance.comm_1);
assert_eq!(ck.commit_with_explicit_randomness(a_2, r_2), instance.comm_2);
// Check that messages are unequal
assert_ne!(a_1, a_2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment