Skip to content
Closed
Changes from 3 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
58 changes: 58 additions & 0 deletions spartan/src/crr1csproof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,14 @@
instance: &CRR1CSInstance<G, PC>,
witness: CRR1CSWitness<G::ScalarField>,
key: &CRR1CSKey<G, PC>,
transcript: &mut Transcript,

Check warning on line 256 in spartan/src/crr1csproof.rs

View workflow job for this annotation

GitHub Actions / check-fmt

Diff in /home/runner/work/nexus-zkvm/nexus-zkvm/spartan/src/crr1csproof.rs
) -> (CRR1CSProof<G, PC>, Vec<G::ScalarField>, Vec<G::ScalarField>) {
let timer_prove = Timer::new("CRR1CSProof::prove");

// Check if witness size is a power of two
let witness_size = witness.W.len();

Check failure on line 261 in spartan/src/crr1csproof.rs

View workflow job for this annotation

GitHub Actions / cargo-clippy

no method named `len` found for struct `Assignment` in the current scope

Check failure on line 261 in spartan/src/crr1csproof.rs

View workflow job for this annotation

GitHub Actions / check-build

no method named `len` found for struct `Assignment` in the current scope
assert!(witness_size.is_power_of_two(), "Witness size must be a power of two");

<Transcript as ProofTranscript<G>>::append_protocol_name(
transcript,
CRR1CSProof::<G, PC>::protocol_name(),
Expand All @@ -272,9 +277,14 @@
let CRR1CSWitness { W: _vars, E } = witness;

let (inst, input, vars) = (&_inst, _input.assignment.as_slice(), _vars.assignment);

Check warning on line 280 in spartan/src/crr1csproof.rs

View workflow job for this annotation

GitHub Actions / check-fmt

Diff in /home/runner/work/nexus-zkvm/nexus-zkvm/spartan/src/crr1csproof.rs
// we currently require the number of |inputs| + 1 to be at most number of vars
assert!(input.len() < vars.len());

// Check if E vector size is power of two and matches witness size
assert!(E.len().is_power_of_two(), "Error vector size must be a power of two");
assert_eq!(witness_size, E.len(), "Witness and error vector sizes must match");

<Transcript as ProofTranscript<G>>::append_scalars(transcript, b"input", input);
<Transcript as ProofTranscript<G>>::append_scalar(transcript, b"u", u);
comm_W.append_to_transcript(b"comm_W", transcript);
Expand Down Expand Up @@ -676,4 +686,52 @@
)
.is_ok());
}

#[test]
#[should_panic(expected = "Witness size must be a power of two")]
fn test_witness_size_not_power_of_two() {
let num_vars = 1024;
let num_cons = 1024;
let num_inputs = 10;

Check warning on line 695 in spartan/src/crr1csproof.rs

View workflow job for this annotation

GitHub Actions / check-fmt

Diff in /home/runner/work/nexus-zkvm/nexus-zkvm/spartan/src/crr1csproof.rs
let (shape, instance, mut witness, gens) =
produce_synthetic_crr1cs::<G1Projective, Hyrax<G1Projective>>(num_cons, num_vars, num_inputs);

// Modify witness to have non-power-of-two size
witness.W = vec![Fr::zero(); 1023]; // Not a power of two

let mut prover_transcript = Transcript::new(b"example");

// This should panic because witness size is not power of two
let _ = CRR1CSProof::prove(
&shape,
&instance,
witness,
&gens.gens_r1cs_sat,
&mut prover_transcript,
);
}

#[test]
#[should_panic(expected = "Error vector size must be a power of two")]
fn test_error_vector_size_not_power_of_two() {
let num_vars = 1024;
let num_cons = 1024;
let num_inputs = 10;

Check warning on line 719 in spartan/src/crr1csproof.rs

View workflow job for this annotation

GitHub Actions / check-fmt

Diff in /home/runner/work/nexus-zkvm/nexus-zkvm/spartan/src/crr1csproof.rs
let (shape, instance, mut witness, gens) =
produce_synthetic_crr1cs::<G1Projective, Hyrax<G1Projective>>(num_cons, num_vars, num_inputs);

// Modify error vector to have non-power-of-two size
witness.E = vec![Fr::zero(); 1023]; // Not a power of two

let mut prover_transcript = Transcript::new(b"example");

// This should panic because error vector size is not power of two
let _ = CRR1CSProof::prove(
&shape,
&instance,
witness,
&gens.gens_r1cs_sat,
&mut prover_transcript,
);
}
}
Loading