11// This crate collects all the underlying primitives used to implement RLN
22
33use ark_bn254:: Fr ;
4+ use ark_ff:: AdditiveGroup ;
45use ark_groth16:: { prepare_verifying_key, Groth16 , Proof as ArkProof , ProvingKey , VerifyingKey } ;
56use ark_relations:: r1cs:: ConstraintMatrices ;
67use ark_serialize:: { CanonicalDeserialize , CanonicalSerialize } ;
@@ -14,7 +15,7 @@ use std::time::Instant;
1415use tiny_keccak:: { Hasher as _, Keccak } ;
1516
1617use crate :: circuit:: { calculate_rln_witness, qap:: CircomReduction , Curve } ;
17- use crate :: error:: { ConversionError , ProofError , ProtocolError } ;
18+ use crate :: error:: { ComputeIdSecretError , ConversionError , ProofError , ProtocolError } ;
1819use crate :: hashers:: { hash_to_field, poseidon_hash} ;
1920use crate :: poseidon_tree:: * ;
2021use crate :: public:: RLN_IDENTIFIER ;
@@ -508,7 +509,7 @@ pub fn extended_seeded_keygen(signal: &[u8]) -> (Fr, Fr, Fr, Fr) {
508509 )
509510}
510511
511- pub fn compute_id_secret ( share1 : ( Fr , Fr ) , share2 : ( Fr , Fr ) ) -> Result < Fr , String > {
512+ pub fn compute_id_secret ( share1 : ( Fr , Fr ) , share2 : ( Fr , Fr ) ) -> Result < Fr , ComputeIdSecretError > {
512513 // Assuming a0 is the identity secret and a1 = poseidonHash([a0, external_nullifier]),
513514 // a (x,y) share satisfies the following relation
514515 // y = a_0 + x * a_1
@@ -518,11 +519,16 @@ pub fn compute_id_secret(share1: (Fr, Fr), share2: (Fr, Fr)) -> Result<Fr, Strin
518519 // If the two input shares were computed for the same external_nullifier and identity secret, we can recover the latter
519520 // y1 = a_0 + x1 * a_1
520521 // y2 = a_0 + x2 * a_1
521- let a_1 = ( y1 - y2) / ( x1 - x2) ;
522- let a_0 = y1 - x1 * a_1;
523522
524- // If shares come from the same polynomial, a0 is correctly recovered and a1 = poseidonHash([a0, external_nullifier])
525- Ok ( a_0)
523+ if ( x1 - x2) != Fr :: ZERO {
524+ let a_1 = ( y1 - y2) / ( x1 - x2) ;
525+ let a_0 = y1 - x1 * a_1;
526+
527+ // If shares come from the same polynomial, a0 is correctly recovered and a1 = poseidonHash([a0, external_nullifier])
528+ Ok ( a_0)
529+ } else {
530+ Err ( ComputeIdSecretError :: DivisionByZero )
531+ }
526532}
527533
528534///////////////////////////////////////////////////////
0 commit comments