Skip to content

Commit b87c00e

Browse files
committed
refactor: invalid instance/witness pair error
1 parent ee285bf commit b87c00e

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

src/composition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<G: Group + GroupEncoding> SigmaProtocol for Protocol<G> {
112112
}
113113
(Protocol::And(ps), ProtocolWitness::And(ws)) => {
114114
if ps.len() != ws.len() {
115-
return Err(Error::ProofSizeMismatch);
115+
return Err(Error::InvalidInstanceWitnessPair);
116116
}
117117
let mut commitments = Vec::with_capacity(ps.len());
118118
let mut prover_states = Vec::with_capacity(ps.len());
@@ -168,7 +168,7 @@ impl<G: Group + GroupEncoding> SigmaProtocol for Protocol<G> {
168168
}
169169
(Protocol::And(ps), ProtocolProverState::And(states)) => {
170170
if ps.len() != states.len() {
171-
return Err(Error::ProofSizeMismatch);
171+
return Err(Error::InvalidInstanceWitnessPair);
172172
}
173173
let mut responses = Vec::with_capacity(ps.len());
174174
for (i, p) in ps.iter().enumerate() {

src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ pub enum Error {
1515
/// Something is wrong with the proof, causing a verification failure.
1616
#[error("Verification failed.")]
1717
VerificationFailure,
18-
/// Indicates a mismatch in parameter sizes during batch verification.
19-
#[error("Mismatched parameter sizes for batch verification.")]
20-
ProofSizeMismatch,
18+
/// Indicates an invalid statement/witness pair
19+
#[error("Invalid instance/witness pair.")]
20+
InvalidInstanceWitnessPair,
2121
/// Uninitialized group element variable.
2222
#[error("Uninitialized group element variable: {var_debug}")]
2323
UnassignedGroupVar { var_debug: String },

src/schnorr_protocol.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,19 @@ where
6868
/// - The prover state (random nonces and witness) used to compute the response.
6969
///
7070
/// # Errors
71-
/// -[`Error::ProofSizeMismatch`] if the witness vector length is incorrect.
71+
/// -[`Error::InvalidInstanceWitnessPair`] if the witness vector length is incorrect.
7272
fn prover_commit(
7373
&self,
7474
witness: &Self::Witness,
7575
mut rng: &mut (impl RngCore + CryptoRng),
7676
) -> Result<(Self::Commitment, Self::ProverState), Error> {
7777
if witness.len() != self.witness_length() {
78-
return Err(Error::ProofSizeMismatch);
78+
return Err(Error::InvalidInstanceWitnessPair);
79+
}
80+
81+
// If the relation being proven is trivial, refuse to prove the statement.
82+
if self.0.image()?.iter().all(|&x| x == G::identity()) {
83+
return Err(Error::InvalidInstanceWitnessPair)
7984
}
8085

8186
let nonces: Vec<G::Scalar> = (0..self.witness_length())
@@ -96,7 +101,7 @@ where
96101
/// - A vector of scalars forming the prover's response.
97102
///
98103
/// # Errors
99-
/// - Returns [`Error::ProofSizeMismatch`] if the prover state vectors have incorrect lengths.
104+
/// - Returns [`Error::InvalidInstanceWitnessPair`] if the prover state vectors have incorrect lengths.
100105
fn prover_response(
101106
&self,
102107
prover_state: Self::ProverState,
@@ -105,7 +110,7 @@ where
105110
let (nonces, witness) = prover_state;
106111

107112
if nonces.len() != self.witness_length() || witness.len() != self.witness_length() {
108-
return Err(Error::ProofSizeMismatch);
113+
return Err(Error::InvalidInstanceWitnessPair);
109114
}
110115

111116
let responses = nonces
@@ -125,20 +130,20 @@ where
125130
/// # Returns
126131
/// - `Ok(())` if the proof is valid.
127132
/// - `Err(Error::VerificationFailure)` if the proof is invalid.
128-
/// - `Err(Error::ProofSizeMismatch)` if the lengths of commitment or response do not match the expected counts.
133+
/// - `Err(Error::InvalidInstanceWitnessPair)` if the lengths of commitment or response do not match the expected counts.
129134
///
130135
/// # Errors
131136
/// -[`Error::VerificationFailure`] if the computed relation
132137
/// does not hold for the provided challenge and response, indicating proof invalidity.
133-
/// -[`Error::ProofSizeMismatch`] if the commitment or response length is incorrect.
138+
/// -[`Error::InvalidInstanceWitnessPair`] if the commitment or response length is incorrect.
134139
fn verifier(
135140
&self,
136141
commitment: &Self::Commitment,
137142
challenge: &Self::Challenge,
138143
response: &Self::Response,
139144
) -> Result<(), Error> {
140145
if commitment.len() != self.commitment_length() || response.len() != self.witness_length() {
141-
return Err(Error::ProofSizeMismatch);
146+
return Err(Error::InvalidInstanceWitnessPair);
142147
}
143148

144149
let lhs = self.0.linear_map.evaluate(response)?;
@@ -307,14 +312,14 @@ where
307312
/// - A vector of group elements representing the simulated commitment (one per linear constraint).
308313
///
309314
/// # Errors
310-
/// - [`Error::ProofSizeMismatch`] if the response length does not match the expected number of scalars.
315+
/// - [`Error::InvalidInstanceWitnessPair`] if the response length does not match the expected number of scalars.
311316
fn simulate_commitment(
312317
&self,
313318
challenge: &Self::Challenge,
314319
response: &Self::Response,
315320
) -> Result<Self::Commitment, Error> {
316321
if response.len() != self.witness_length() {
317-
return Err(Error::ProofSizeMismatch);
322+
return Err(Error::InvalidInstanceWitnessPair);
318323
}
319324

320325
let response_image = self.0.linear_map.evaluate(response)?;

src/tests/spec/custom_schnorr_protocol.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
rng: &mut (impl Rng + CryptoRng),
3434
) -> Result<(Self::Commitment, Self::ProverState), Error> {
3535
if witness.len() != self.witness_len() {
36-
return Err(Error::ProofSizeMismatch);
36+
return Err(Error::InvalidInstanceWitnessPair);
3737
}
3838

3939
let mut nonces: Vec<G::Scalar> = Vec::new();
@@ -51,7 +51,7 @@ where
5151
challenge: &Self::Challenge,
5252
) -> Result<Self::Response, Error> {
5353
if state.0.len() != self.witness_len() || state.1.len() != self.witness_len() {
54-
return Err(Error::ProofSizeMismatch);
54+
return Err(Error::InvalidInstanceWitnessPair);
5555
}
5656

5757
let mut responses = Vec::new();
@@ -129,7 +129,7 @@ impl<G: SRandom + GroupEncoding> SigmaProtocolSimulator for SchnorrProtocolCusto
129129
response: &Self::Response,
130130
) -> Result<Self::Commitment, Error> {
131131
if response.len() != self.0.linear_map.num_scalars {
132-
return Err(Error::ProofSizeMismatch);
132+
return Err(Error::InvalidInstanceWitnessPair);
133133
}
134134

135135
let response_image = self.0.linear_map.evaluate(response)?;

0 commit comments

Comments
 (0)