Skip to content

Commit 6db3c38

Browse files
committed
tests: add tests for random g1 and g2
1 parent 29b75e6 commit 6db3c38

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adapters/sp1/groth16-verifier/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ hex.workspace = true
2626
zkaleido.workspace = true
2727
serde_json = "1.0.140"
2828
bincode.workspace = true
29+
rand = "0.8.3"

adapters/sp1/groth16-verifier/src/verifier.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ impl SP1Groth16Verifier {
131131

132132
#[cfg(test)]
133133
mod tests {
134-
use bn::{AffineG1, AffineG2, Fq, Fq2, G1, G2};
134+
use bn::{AffineG1, AffineG2, Fq, Fq2, Group, G1, G2};
135+
use rand::thread_rng;
135136
use sp1_verifier::GROTH16_VK_BYTES;
136137
use zkaleido::ProofReceipt;
137138

@@ -163,7 +164,9 @@ mod tests {
163164
let vk_alpha = verifier.vk.g1.alpha.0;
164165
let alpha_x = vk_alpha.x();
165166
let alpha_y = vk_alpha.y();
166-
let invalid_alpha_x = alpha_x + Fq::one();
167+
168+
let mut rng = thread_rng();
169+
let invalid_alpha_x = alpha_x + Fq::random(&mut rng);
167170

168171
let res = AffineG1::new(alpha_x, alpha_y);
169172
assert!(res.is_ok());
@@ -180,6 +183,14 @@ mod tests {
180183
receipt.public_values().as_bytes(),
181184
);
182185
assert!(res.is_err());
186+
187+
let random_alpha = AffineG1::from_jacobian(G1::random(&mut rng)).unwrap();
188+
verifier.vk.g1.alpha.0 = random_alpha;
189+
let res = verifier.verify(
190+
receipt.proof().as_bytes(),
191+
receipt.public_values().as_bytes(),
192+
);
193+
assert!(res.is_err());
183194
}
184195

185196
#[test]
@@ -205,5 +216,14 @@ mod tests {
205216
receipt.public_values().as_bytes(),
206217
);
207218
assert!(res.is_err());
219+
220+
let mut rng = thread_rng();
221+
let random_gamma = AffineG2::from_jacobian(G2::random(&mut rng)).unwrap();
222+
verifier.vk.g2.gamma.0 = random_gamma;
223+
let res = verifier.verify(
224+
receipt.proof().as_bytes(),
225+
receipt.public_values().as_bytes(),
226+
);
227+
assert!(res.is_err());
208228
}
209229
}

0 commit comments

Comments
 (0)