Skip to content

Commit

Permalink
Use a transcript RNG for prover nonces (#15)
Browse files Browse the repository at this point in the history
As noted in #14, nonces required for proof generation are produced using an externally-provided random number generator. This PR builds a Merlin-based `TranscriptRng` that uses the transcript state, witness data, and external random number generator to produce nonces. This provides a much more robust design for nonce construction.

Closes #14.
  • Loading branch information
AaronFeickert authored Jan 5, 2024
1 parent d0d4ae9 commit 6ec58d1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,19 @@ impl Proof {
transcript.append_message("M".as_bytes(), statement.get_input_set().get_hash());
transcript.append_message("J".as_bytes(), J.compress().as_bytes());

// Construct a random number generator at the current transcript state
let mut transcript_rng = transcript
.build_rng()
.rekey_with_witness_bytes("l".as_bytes(), &l.to_le_bytes())
.rekey_with_witness_bytes("r".as_bytes(), r.as_bytes())
.finalize(rng);

// Compute the `A` matrix commitment
let r_A = Scalar::random(rng);
let r_A = Scalar::random(&mut transcript_rng);
let mut a = (0..params.get_m())
.map(|_| {
(0..params.get_n())
.map(|_| Scalar::random(rng))
.map(|_| Scalar::random(&mut transcript_rng))
.collect::<Vec<Scalar>>()
})
.collect::<Vec<Vec<Scalar>>>();
Expand All @@ -148,7 +155,7 @@ impl Proof {
.map_err(|_| ProofError::InvalidParameter)?;

// Compute the `B` matrix commitment
let r_B = Scalar::random(rng);
let r_B = Scalar::random(&mut transcript_rng);
let l_decomposed = params.decompose(l).map_err(|_| ProofError::InvalidParameter)?;
let sigma = (0..params.get_m())
.map(|j| {
Expand All @@ -163,7 +170,7 @@ impl Proof {

// Compute the `C` matrix commitment
let two = Scalar::from(2u32);
let r_C = Scalar::random(rng);
let r_C = Scalar::random(&mut transcript_rng);
let a_sigma = (0..params.get_m())
.map(|j| {
(0..params.get_n())
Expand All @@ -176,7 +183,7 @@ impl Proof {
.map_err(|_| ProofError::InvalidParameter)?;

// Compute the `D` matrix commitment
let r_D = Scalar::random(rng);
let r_D = Scalar::random(&mut transcript_rng);
let a_square = (0..params.get_m())
.map(|j| {
(0..params.get_n())
Expand All @@ -191,7 +198,7 @@ impl Proof {
// Random masks
let rho = Zeroizing::new(
(0..params.get_m())
.map(|_| Scalar::random(rng))
.map(|_| Scalar::random(&mut transcript_rng))
.collect::<Vec<Scalar>>(),
);

Expand Down

0 comments on commit 6ec58d1

Please sign in to comment.