@@ -2,9 +2,7 @@ use ff::Field;
22use group:: prime:: PrimeGroup ;
33use rand:: RngCore ;
44
5- use crate :: codec:: Shake128DuplexSponge ;
6- use crate :: fiat_shamir:: Nizk ;
7- use crate :: linear_relation:: { CanonicalLinearRelation , LinearRelation , Sum } ;
5+ use sigma_proofs:: linear_relation:: { CanonicalLinearRelation , LinearRelation , Sum } ;
86
97/// LinearMap for knowledge of a discrete logarithm relative to a fixed basepoint.
108#[ allow( non_snake_case) ]
@@ -351,7 +349,7 @@ pub fn weird_linear_combination<G: PrimeGroup, R: RngCore>(
351349 ( instance, witness)
352350}
353351
354- fn simple_subtractions < G : PrimeGroup , R : RngCore > (
352+ pub fn simple_subtractions < G : PrimeGroup , R : RngCore > (
355353 mut rng : & mut R ,
356354) -> ( CanonicalLinearRelation < G > , Vec < G :: Scalar > ) {
357355 let x = G :: Scalar :: random ( & mut rng) ;
@@ -370,7 +368,7 @@ fn simple_subtractions<G: PrimeGroup, R: RngCore>(
370368 ( instance, witness)
371369}
372370
373- fn subtractions_with_shift < G : PrimeGroup , R : RngCore > (
371+ pub fn subtractions_with_shift < G : PrimeGroup , R : RngCore > (
374372 rng : & mut R ,
375373) -> ( CanonicalLinearRelation < G > , Vec < G :: Scalar > ) {
376374 let B = G :: generator ( ) ;
@@ -390,7 +388,7 @@ fn subtractions_with_shift<G: PrimeGroup, R: RngCore>(
390388}
391389
392390#[ allow( non_snake_case) ]
393- fn cmz_wallet_spend_relation < G : PrimeGroup , R : RngCore > (
391+ pub fn cmz_wallet_spend_relation < G : PrimeGroup , R : RngCore > (
394392 mut rng : & mut R ,
395393) -> ( CanonicalLinearRelation < G > , Vec < G :: Scalar > ) {
396394 // Simulate the wallet spend relation from cmz
@@ -435,7 +433,7 @@ fn cmz_wallet_spend_relation<G: PrimeGroup, R: RngCore>(
435433 ( instance, witness)
436434}
437435
438- fn nested_affine_relation < G : PrimeGroup , R : RngCore > (
436+ pub fn nested_affine_relation < G : PrimeGroup , R : RngCore > (
439437 mut rng : & mut R ,
440438) -> ( CanonicalLinearRelation < G > , Vec < G :: Scalar > ) {
441439 let mut instance = LinearRelation :: < G > :: new ( ) ;
@@ -459,7 +457,7 @@ fn nested_affine_relation<G: PrimeGroup, R: RngCore>(
459457 ( instance, witness)
460458}
461459
462- fn pedersen_commitment_equality < G : PrimeGroup , R : RngCore > (
460+ pub fn pedersen_commitment_equality < G : PrimeGroup , R : RngCore > (
463461 rng : & mut R ,
464462) -> ( CanonicalLinearRelation < G > , Vec < G :: Scalar > ) {
465463 let mut instance = LinearRelation :: new ( ) ;
@@ -482,7 +480,7 @@ fn pedersen_commitment_equality<G: PrimeGroup, R: RngCore>(
482480 ( instance. canonical ( ) . unwrap ( ) , witness)
483481}
484482
485- fn elgamal_subtraction < G : PrimeGroup , R : RngCore > (
483+ pub fn elgamal_subtraction < G : PrimeGroup , R : RngCore > (
486484 rng : & mut R ,
487485) -> ( CanonicalLinearRelation < G > , Vec < G :: Scalar > ) {
488486 let mut instance = LinearRelation :: new ( ) ;
@@ -509,105 +507,3 @@ fn elgamal_subtraction<G: PrimeGroup, R: RngCore>(
509507
510508 ( instance. canonical ( ) . unwrap ( ) , witness)
511509}
512-
513- #[ test]
514- fn test_cmz_wallet_with_fee ( ) {
515- use group:: Group ;
516- type G = bls12_381:: G1Projective ;
517-
518- let mut rng = rand:: thread_rng ( ) ;
519-
520- // This version should fail with InvalidInstanceWitnessPair
521- // because it uses a scalar constant directly in the equation
522- let P_W = G :: random ( & mut rng) ;
523- let A = G :: random ( & mut rng) ;
524-
525- let n_balance = <G as Group >:: Scalar :: random ( & mut rng) ;
526- let i_price = <G as Group >:: Scalar :: random ( & mut rng) ;
527- let _fee = <G as Group >:: Scalar :: from ( 5u64 ) ;
528- let z_w_balance = <G as Group >:: Scalar :: random ( & mut rng) ;
529-
530- let mut relation = LinearRelation :: < G > :: new ( ) ;
531-
532- let var_n_balance = relation. allocate_scalar ( ) ;
533- let var_i_price = relation. allocate_scalar ( ) ;
534- let var_z_w_balance = relation. allocate_scalar ( ) ;
535-
536- let var_P_W = relation. allocate_element ( ) ;
537- let var_A = relation. allocate_element ( ) ;
538-
539- // This equation has a scalar constant (fee) which causes the error
540- let _var_C = relation. allocate_eq (
541- ( var_n_balance + var_i_price + <G as Group >:: Scalar :: from ( 5 ) ) * var_P_W
542- + var_z_w_balance * var_A,
543- ) ;
544-
545- relation. set_elements ( [ ( var_P_W, P_W ) , ( var_A, A ) ] ) ;
546- relation
547- . compute_image ( & [ n_balance, i_price, z_w_balance] )
548- . unwrap ( ) ;
549-
550- // Try to convert to CanonicalLinearRelation - this should fail
551- let nizk = relation. into_nizk ( b"session_identifier" ) . unwrap ( ) ;
552- let result = nizk. prove_batchable ( & vec ! [ n_balance, i_price, z_w_balance] , & mut rng) ;
553- assert ! ( result. is_ok( ) ) ;
554- let proof = result. unwrap ( ) ;
555- let verify_result = nizk. verify_batchable ( & proof) ;
556- assert ! ( verify_result. is_ok( ) ) ;
557- }
558-
559- /// Generic helper function to test both relation correctness and NIZK functionality
560- #[ test]
561- fn test_relations ( ) {
562- type G = bls12_381:: G1Projective ;
563-
564- let instance_generators: Vec < ( _ , & ' static dyn Fn ( & mut _) -> _ ) > = vec ! [
565- ( "dlog" , & discrete_logarithm) ,
566- ( "shifted_dlog" , & shifted_dlog) ,
567- ( "dleq" , & dleq) ,
568- ( "shifted_dleq" , & shifted_dleq) ,
569- ( "pedersen_commitment" , & pedersen_commitment) ,
570- ( "twisted_pedersen_commitment" , & twisted_pedersen_commitment) ,
571- ( "pedersen_commitment_dleq" , & pedersen_commitment_equality) ,
572- ( "bbs_blind_commitment" , & bbs_blind_commitment) ,
573- ( "test_range" , & test_range) ,
574- ( "weird_linear_combination" , & weird_linear_combination) ,
575- ( "simple_subtractions" , & simple_subtractions) ,
576- ( "subtractions_with_shift" , & subtractions_with_shift) ,
577- ( "cmz_wallet_spend_relation" , & cmz_wallet_spend_relation) ,
578- ( "nested_affine_relation" , & nested_affine_relation) ,
579- ( "elgamal_public_subtract" , & elgamal_subtraction) ,
580- ] ;
581-
582- for ( relation_name, relation_sampler) in instance_generators. iter ( ) {
583- let mut rng = rand:: thread_rng ( ) ;
584- let ( canonical_relation, witness) = relation_sampler ( & mut rng) ;
585-
586- // Test the NIZK protocol
587- let domain_sep = format ! ( "test-fiat-shamir-{relation_name}" )
588- . as_bytes ( )
589- . to_vec ( ) ;
590- let nizk = Nizk :: < CanonicalLinearRelation < G > , Shake128DuplexSponge < G > > :: new (
591- & domain_sep,
592- canonical_relation,
593- ) ;
594-
595- // Test both proof types
596- let proof_batchable = nizk
597- . prove_batchable ( & witness, & mut rng)
598- . unwrap_or_else ( |_| panic ! ( "Failed to create batchable proof for {relation_name}" ) ) ;
599- let proof_compact = nizk
600- . prove_compact ( & witness, & mut rng)
601- . unwrap_or_else ( |_| panic ! ( "Failed to create compact proof for {relation_name}" ) ) ;
602-
603- // Verify both proof types
604- assert ! (
605- nizk. verify_batchable( & proof_batchable) . is_ok( ) ,
606- "Batchable proof verification failed for {relation_name}"
607- ) ;
608- assert ! (
609- nizk. verify_compact( & proof_compact) . is_ok( ) ,
610- "Compact proof verification failed for {relation_name}"
611- ) ;
612- }
613- }
0 commit comments