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

fix: changes made for Commonprefix patch #675

Merged
merged 4 commits into from
Sep 4, 2024
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
17 changes: 17 additions & 0 deletions plonk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Breaking Changes

### Non-breaking Changes

## 0.5.1 (2024-09-04)

### Breaking Changes

- [#648](https://github.com/EspressoSystems/jellyfish/pull/648) Refactored `trait Transcript`; Updated `SolidityTranscript` to use `state`-based logic correctly

### Non-breaking Changes

- [#647](https://github.com/EspressoSystems/jellyfish/pull/647) Append G2 points from SRS to `Transcript`


## 0.5.0 (2024-07-02)

### Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion plonk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "jf-plonk"
description = "TurboPlonk and UntraPlonk implementation."
version = "0.5.0"
version = "0.5.1"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
12 changes: 6 additions & 6 deletions plonk/src/circuit/plonk_verifier/gadgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,25 +229,25 @@ where
transcript_var.append_commitments_vars(b"witness_poly_comms", wires_poly_comms)?;
}

let beta = transcript_var.get_and_append_challenge_var::<E>(b"beta", circuit)?;
let gamma = transcript_var.get_and_append_challenge_var::<E>(b"gamma", circuit)?;
let beta = transcript_var.get_challenge_var::<E>(b"beta", circuit)?;
let gamma = transcript_var.get_challenge_var::<E>(b"gamma", circuit)?;
for prod_perm_poly_comm in batch_proof.prod_perm_poly_comms_vec.iter() {
transcript_var.append_commitment_var(b"perm_poly_comms", prod_perm_poly_comm)?;
}

let alpha = transcript_var.get_and_append_challenge_var::<E>(b"alpha", circuit)?;
let alpha = transcript_var.get_challenge_var::<E>(b"alpha", circuit)?;
transcript_var
.append_commitments_vars(b"quot_poly_comms", &batch_proof.split_quot_poly_comms)?;
let zeta = transcript_var.get_and_append_challenge_var::<E>(b"zeta", circuit)?;
let zeta = transcript_var.get_challenge_var::<E>(b"zeta", circuit)?;
for poly_evals in batch_proof.poly_evals_vec.iter() {
transcript_var.append_proof_evaluations_vars(circuit, poly_evals)?;
}

let v = transcript_var.get_and_append_challenge_var::<E>(b"v", circuit)?;
let v = transcript_var.get_challenge_var::<E>(b"v", circuit)?;
transcript_var.append_commitment_var(b"open_proof", &batch_proof.opening_proof)?;
transcript_var
.append_commitment_var(b"shifted_open_proof", &batch_proof.shifted_opening_proof)?;
let u = transcript_var.get_and_append_challenge_var::<E>(b"u", circuit)?;
let u = transcript_var.get_challenge_var::<E>(b"u", circuit)?;

// convert challenge vars into FpElemVars
let challenge_var = ChallengesVar {
Expand Down
29 changes: 10 additions & 19 deletions plonk/src/circuit/transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,6 @@ where
Ok(())
}

// Append a challenge variable to the transcript.
// For efficiency purpose, label is not used for rescue FS.
pub(crate) fn append_challenge_var(
&mut self,
_label: &'static [u8],
challenge_var: &Variable,
) -> Result<(), CircuitError> {
self.append_variable(_label, challenge_var)
}

// Append the proof evaluation to the transcript
pub(crate) fn append_proof_evaluations_vars(
&mut self,
Expand All @@ -171,7 +161,9 @@ where
// For efficiency purpose, label is not used for rescue FS.
// Note that this function currently only supports bls12-377
// curve due to its decomposition method.
pub(crate) fn get_and_append_challenge_var<E>(
//
// `_label` is omitted for efficiency.
pub(crate) fn get_challenge_var<E>(
&mut self,
_label: &'static [u8],
circuit: &mut PlonkCircuit<F>,
Expand All @@ -193,7 +185,7 @@ where
// This algorithm takes in 3 steps
// 1. state: [F: STATE_SIZE] = hash(state|transcript)
// 2. challenge = state[0] in Fr
// 3. transcript = vec![challenge]
// 3. transcript = vec![]
// ==================================

// step 1. state: [F: STATE_SIZE] = hash(state|transcript)
Expand All @@ -210,7 +202,6 @@ where
// finish and update the states
self.state_var.copy_from_slice(&res_var[0..STATE_SIZE]);
self.transcript_var = Vec::new();
self.append_challenge_var(_label, &challenge_var)?;

Ok(challenge_var)
}
Expand Down Expand Up @@ -267,10 +258,10 @@ mod tests {
.unwrap();
}

let challenge = transcript.get_and_append_challenge::<E>(label).unwrap();
let challenge = transcript.get_challenge::<E>(label).unwrap();

let challenge_var = transcript_var
.get_and_append_challenge_var::<E>(label, &mut circuit)
.get_challenge_var::<E>(label, &mut circuit)
.unwrap();

assert_eq!(
Expand Down Expand Up @@ -329,10 +320,10 @@ mod tests {
.append_vk_and_pub_input_vars::<E>(&mut circuit, &dummy_vk_var, &[])
.unwrap();

let challenge = transcript.get_and_append_challenge::<E>(label).unwrap();
let challenge = transcript.get_challenge::<E>(label).unwrap();

let challenge_var = transcript_var
.get_and_append_challenge_var::<E>(label, &mut circuit)
.get_challenge_var::<E>(label, &mut circuit)
.unwrap();

assert_eq!(
Expand Down Expand Up @@ -398,10 +389,10 @@ mod tests {
.append_vk_and_pub_input_vars::<E>(&mut circuit, &vk_var, &input_fp_elem_vars)
.unwrap();

let challenge = transcript.get_and_append_challenge::<E>(label).unwrap();
let challenge = transcript.get_challenge::<E>(label).unwrap();

let challenge_var = transcript_var
.get_and_append_challenge_var::<E>(label, &mut circuit)
.get_challenge_var::<E>(label, &mut circuit)
.unwrap();

assert_eq!(
Expand Down
3 changes: 3 additions & 0 deletions plonk/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ pub(crate) const EXTRA_TRANSCRIPT_MSG_LABEL: &[u8] = b"extra info";
pub(crate) const fn domain_size_ratio(n: usize, num_wire_types: usize) -> usize {
(num_wire_types * (n + 1) + 2) / n + 1
}

/// Keccak-256 have a 32 byte state size.
pub const KECCAK256_STATE_SIZE: usize = 32;
12 changes: 6 additions & 6 deletions plonk/src/proof_system/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ where
// Plookup: compute and interpolate the sorted concatenation of the (merged)
// lookup table and the (merged) witness values
if circuits.iter().any(|c| C::support_lookup(c)) {
challenges.tau = Some(transcript.get_and_append_challenge::<E>(b"tau")?);
challenges.tau = Some(transcript.get_challenge::<E>(b"tau")?);
} else {
challenges.tau = None;
}
Expand Down Expand Up @@ -284,8 +284,8 @@ where
}

// Round 2
challenges.beta = transcript.get_and_append_challenge::<E>(b"beta")?;
challenges.gamma = transcript.get_and_append_challenge::<E>(b"gamma")?;
challenges.beta = transcript.get_challenge::<E>(b"beta")?;
challenges.gamma = transcript.get_challenge::<E>(b"gamma")?;
let mut prod_perm_poly_comms_vec = vec![];
for i in 0..circuits.len() {
let (prod_perm_poly_comm, prod_perm_poly) =
Expand Down Expand Up @@ -318,7 +318,7 @@ where
}

// Round 3
challenges.alpha = transcript.get_and_append_challenge::<E>(b"alpha")?;
challenges.alpha = transcript.get_challenge::<E>(b"alpha")?;
let (split_quot_poly_comms, split_quot_polys) = prover.run_3rd_round(
prng,
&prove_keys[0].commit_key,
Expand All @@ -330,7 +330,7 @@ where
transcript.append_commitments(b"quot_poly_comms", &split_quot_poly_comms)?;

// Round 4
challenges.zeta = transcript.get_and_append_challenge::<E>(b"zeta")?;
challenges.zeta = transcript.get_challenge::<E>(b"zeta")?;
let mut poly_evals_vec = vec![];
for i in 0..circuits.len() {
let poly_evals = prover.compute_evaluations(
Expand Down Expand Up @@ -389,7 +389,7 @@ where
}

// Round 5
challenges.v = transcript.get_and_append_challenge::<E>(b"v")?;
challenges.v = transcript.get_challenge::<E>(b"v")?;
let (opening_proof, shifted_opening_proof) = prover.compute_opening_proofs(
&prove_keys[0].commit_key,
prove_keys,
Expand Down
18 changes: 9 additions & 9 deletions plonk/src/proof_system/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ where
// protocol transcript. This approach is more secure as `r` depends not only
// on the proofs, but also the list of public inputs and verifying keys.
for pcs_info in pcs_infos {
transcript.append_challenge::<E>(b"u", &pcs_info.u)?;
transcript.append_field_elem::<E>(b"u", &pcs_info.u)?;
}
transcript.get_and_append_challenge::<E>(b"r")?
transcript.get_challenge::<E>(b"r")?
};

// Compute A := A0 + r * A1 + ... + r^{m-1} * Am
Expand Down Expand Up @@ -288,7 +288,7 @@ where
transcript.append_commitments(b"witness_poly_comms", wires_poly_comms)?;
}
let tau = if verify_keys.iter().any(|vk| vk.plookup_vk.is_some()) {
Some(transcript.get_and_append_challenge::<E>(b"tau")?)
Some(transcript.get_challenge::<E>(b"tau")?)
} else {
None
};
Expand All @@ -299,8 +299,8 @@ where
}
}

let beta = transcript.get_and_append_challenge::<E>(b"beta")?;
let gamma = transcript.get_and_append_challenge::<E>(b"gamma")?;
let beta = transcript.get_challenge::<E>(b"beta")?;
let gamma = transcript.get_challenge::<E>(b"gamma")?;
for prod_perm_poly_comm in batch_proof.prod_perm_poly_comms_vec.iter() {
transcript.append_commitment(b"perm_poly_comms", prod_perm_poly_comm)?;
}
Expand All @@ -311,9 +311,9 @@ where
}
}

let alpha = transcript.get_and_append_challenge::<E>(b"alpha")?;
let alpha = transcript.get_challenge::<E>(b"alpha")?;
transcript.append_commitments(b"quot_poly_comms", &batch_proof.split_quot_poly_comms)?;
let zeta = transcript.get_and_append_challenge::<E>(b"zeta")?;
let zeta = transcript.get_challenge::<E>(b"zeta")?;
for poly_evals in batch_proof.poly_evals_vec.iter() {
transcript.append_proof_evaluations::<E>(poly_evals)?;
}
Expand All @@ -323,10 +323,10 @@ where
}
}

let v = transcript.get_and_append_challenge::<E>(b"v")?;
let v = transcript.get_challenge::<E>(b"v")?;
transcript.append_commitment(b"open_proof", &batch_proof.opening_proof)?;
transcript.append_commitment(b"shifted_open_proof", &batch_proof.shifted_opening_proof)?;
let u = transcript.get_and_append_challenge::<E>(b"u")?;
let u = transcript.get_challenge::<E>(b"u")?;
Ok(Challenges {
tau,
alpha,
Expand Down
9 changes: 5 additions & 4 deletions plonk/src/testing_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#![allow(missing_docs)]

use crate::{
constants::KECCAK256_STATE_SIZE,
errors::PlonkError,
lagrange::LagrangeCoeffs,
proof_system::{
Expand Down Expand Up @@ -379,12 +380,12 @@ where
/// exposing the internal states for testing purposes
impl SolidityTranscript {
/// Create a new transcript from specific internal states.
pub fn from_internal(transcript: Vec<u8>) -> Self {
Self { transcript }
pub fn from_internal(state: [u8; KECCAK256_STATE_SIZE], transcript: Vec<u8>) -> Self {
Self { state, transcript }
}

/// Returns the internal states
pub fn internal(&self) -> Vec<u8> {
self.transcript.clone()
pub fn internal(&self) -> ([u8; KECCAK256_STATE_SIZE], Vec<u8>) {
(self.state.clone(), self.transcript.clone())
}
}
Loading
Loading