Skip to content

Commit b24557c

Browse files
committed
test: add keys to the params
Signed-off-by: pedro bufulin <pedro@semiotic.ai>
1 parent f286cf4 commit b24557c

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

h2s2/src/ncs.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,24 +219,43 @@ mod tests {
219219
use once_cell::sync::Lazy;
220220

221221
static N: usize = 10; // Define the number of generators
222+
static PARAMS: Lazy<H2S2Parameters<Bn254>> = Lazy::new(|| {
223+
let mut rng = test_rng();
224+
225+
let mut params = NCS::<Bn254, Blake2b512>::setup(N).expect("Setup failed");
226+
227+
// Generate the secret and public keys using keygen
228+
let (pk, sk) = NCS::<Bn254, Blake2b512>::keygen(&params, &mut rng).expect("Keygen failed");
222229

223-
static PARAMS: Lazy<H2S2Parameters<Bn254>> =
224-
Lazy::new(|| NCS::<Bn254, Blake2b512>::setup(N).expect("Setup failed"));
230+
params.secret_key = Some(sk);
231+
params.public_key = pk;
232+
params
233+
});
225234

226235
#[test]
227-
fn test_setup() {
228-
let params = &*PARAMS;
236+
fn test_setup_and_keygen() {
237+
let mut rng = test_rng();
238+
let n = 10;
229239

230-
assert_eq!(params.g1_generators.len(), 11); // n + 1
231-
assert_eq!(params.max_lanes, 10);
240+
let params = NCS::<Bn254, Blake2b512>::setup(n).expect("Setup failed");
232241

233-
let expected_public_key = params.public_key;
234-
let calculated_public_key = params.g2_generator.mul(params.secret_key.unwrap());
242+
let (pk, sk) = NCS::<Bn254, Blake2b512>::keygen(&params, &mut rng).expect("Keygen failed");
235243

236244
assert_eq!(
237-
calculated_public_key, expected_public_key,
238-
"Public key and private key relation is invalid!"
245+
params.g1_generators.len(),
246+
n + 1,
247+
"Incorrect number of G1 generators"
239248
);
249+
assert_eq!(params.max_lanes, n, "Max lanes value mismatch");
250+
251+
// Verify the public key matches the secret key and G2 generator relationship
252+
let calculated_public_key = params.g2_generator.mul(sk);
253+
assert_eq!(
254+
calculated_public_key, pk,
255+
"Public key does not match the calculated value from secret key and G2 generator"
256+
);
257+
258+
println!("Setup and Keygen tests passed!");
240259
}
241260

242261
#[test]

0 commit comments

Comments
 (0)