diff --git a/curdleproofs/curdleproofs/curdleproofs.py b/curdleproofs/curdleproofs/curdleproofs.py index 3fed107..fa8a359 100644 --- a/curdleproofs/curdleproofs/curdleproofs.py +++ b/curdleproofs/curdleproofs/curdleproofs.py @@ -87,7 +87,7 @@ def new( compute_MSM(crs.vec_H, vec_r_a_prime), ) - (same_perm_proof, err) = SamePermutationProof.new( + same_perm_proof = SamePermutationProof.new( crs_G_vec=crs.vec_G, crs_H_vec=crs.vec_H, crs_U=crs.H, @@ -100,9 +100,6 @@ def new( transcript=transcript, ) - if same_perm_proof is None: - raise Exception(err) - r_t = Fr(random.randint(1, Fr.field_modulus)) r_u = Fr(random.randint(1, Fr.field_modulus)) R = compute_MSM(vec_R, vec_a) @@ -181,14 +178,14 @@ def verify( vec_T: List[PointProjective], vec_U: List[PointProjective], M: PointProjective, - ) -> Tuple[bool, str]: + ): ell = len(vec_R) transcript = CurdleproofsTranscript(b"curdleproofs") msm_accumulator = MSMAccumulator() if is_inf(vec_T[0]): - return False, "vec_T[0] is infinity" + raise Exception("vec_T[0] is infinity") transcript.append_list( b"curdleproofs_step1", points_projective_to_bytes(vec_R + vec_S + vec_T + vec_U) @@ -259,12 +256,7 @@ def verify( self.S, vec_S, vec_a ) - msm_verify = msm_accumulator.verify() - - if not msm_verify: - return False, "MSM check failed" - - return True, "" + msm_accumulator.verify() def to_json(self): return { diff --git a/curdleproofs/curdleproofs/grand_prod.py b/curdleproofs/curdleproofs/grand_prod.py index 56baba7..162c8f4 100644 --- a/curdleproofs/curdleproofs/grand_prod.py +++ b/curdleproofs/curdleproofs/grand_prod.py @@ -11,7 +11,7 @@ fr_to_bytes, ) from curdleproofs.curdleproofs_transcript import CurdleproofsTranscript -from typing import List, Optional, Tuple, TypeVar, Type +from typing import List, TypeVar, Type from curdleproofs.util import ( PointProjective, Fr, @@ -45,7 +45,7 @@ def new( vec_b: List[Fr], vec_b_blinders: List[Fr], transcript: CurdleproofsTranscript, - ) -> Tuple[Optional[T_GrandProductProof], Optional[str]]: + ) -> T_GrandProductProof: n_blinders = len(vec_b_blinders) ell = len(crs_G_vec) @@ -115,7 +115,7 @@ def new( assert eq(compute_MSM(vec_G, vec_c), C) assert eq(compute_MSM(vec_G_prime, vec_d), D) - (ipa_proof, err) = IPA.new( + ipa_proof = IPA.new( crs_G_vec=vec_G, crs_G_prime_vec=vec_G_prime, crs_H=crs_U, @@ -127,10 +127,7 @@ def new( transcript=transcript, ) - if ipa_proof is None: - return None, err - - return cls(C, r_p, ipa_proof), None + return cls(C, r_p, ipa_proof) def verify( self, @@ -144,7 +141,7 @@ def verify( n_blinders: int, transcript: CurdleproofsTranscript, msm_accumulator: MSMAccumulator, - ) -> Tuple[bool, str]: + ): ell = len(crs_G_vec) # Step 1 @@ -182,7 +179,7 @@ def verify( self.r_p * (beta ** (ell + 1)) + gprod_result * (beta**ell) - Fr.one() ) - (ipa_result, err) = self.ipa_proof.verify( + self.ipa_proof.verify( crs_G_vec=vec_G, crs_H=crs_U, C=self.C, @@ -193,11 +190,6 @@ def verify( msm_accumulator=msm_accumulator, ) - if not ipa_result: - return False, err - - return True, "" - def to_json(self): return { "C": point_projective_to_json(self.C), diff --git a/curdleproofs/curdleproofs/ipa.py b/curdleproofs/curdleproofs/ipa.py index be346be..af505ef 100644 --- a/curdleproofs/curdleproofs/ipa.py +++ b/curdleproofs/curdleproofs/ipa.py @@ -12,7 +12,7 @@ log2_int, ) from curdleproofs.curdleproofs_transcript import CurdleproofsTranscript -from typing import List, Optional, Tuple, Type, TypeVar +from typing import List, Tuple, Type, TypeVar from curdleproofs.util import ( PointProjective, Fr, @@ -89,13 +89,13 @@ def new( vec_c: List[Fr], vec_d: List[Fr], transcript: CurdleproofsTranscript, - ) -> Tuple[Optional[T_IPA], Optional[str]]: + ) -> T_IPA: n = len(vec_c) lg_n = int(log2(n)) if n != 2**lg_n: - return (None, "n != 2 ** lg_n, not a power of 2") + raise Exception("n != 2 ** lg_n, not a power of 2") if n != len(vec_d): - return (None, "len(vec_c) != len(vec_d)") + raise Exception("len(vec_c) != len(vec_d)") (vec_r_c, vec_r_d) = generate_ipa_blinders(vec_c, vec_d) @@ -155,19 +155,16 @@ def new( crs_G_vec = G_L crs_G_prime_vec = G_prime_L - return ( - cls(B_c, B_d, vec_L_C, vec_R_C, vec_L_D, vec_R_D, vec_c[0], vec_d[0]), - None, - ) + return cls(B_c, B_d, vec_L_C, vec_R_C, vec_L_D, vec_R_D, vec_c[0], vec_d[0]) def verification_scalars( self, n: int, transcript: CurdleproofsTranscript - ) -> Tuple[Tuple[List[Fr], List[Fr], List[Fr], List[Fr]], Optional[str]]: + ) -> Tuple[List[Fr], List[Fr], List[Fr], List[Fr]]: lg_n = len(self.vec_L_C) if lg_n >= 32: - return (([], [], [], []), "vec_L_C too large") + raise Exception("vec_L_C too large") elif n != 2**lg_n: - return (([], [], [], []), "n != 2 ** lg_n") + raise Exception("n != 2 ** lg_n") verification_scalars_bitstring = get_verification_scalars_bitstring(n, lg_n) @@ -191,7 +188,7 @@ def verification_scalars( vec_s_inv = [invert(s) for s in vec_s] - return ((challenges, challenges_inv, vec_s, vec_s_inv), None) + return (challenges, challenges_inv, vec_s, vec_s_inv) def verify( self, @@ -203,7 +200,7 @@ def verify( vec_u: List[Fr], transcript: CurdleproofsTranscript, msm_accumulator: MSMAccumulator, - ) -> Tuple[bool, str]: + ): n = len(crs_G_vec) # assert(((n != 0) and (n & (n-1) == 0)), "n must be a power of 2") @@ -217,11 +214,9 @@ def verify( alpha = transcript.get_and_append_challenge(b"ipa_alpha") beta = transcript.get_and_append_challenge(b"ipa_beta") - ((vec_gamma, vec_gamma_inv, vec_s, vec_s_inv), err) = self.verification_scalars( + (vec_gamma, vec_gamma_inv, vec_s, vec_s_inv) = self.verification_scalars( n, transcript ) - if err is not None: - return (False, err) vec_c_times_s = [self.c_final * s for s in vec_s] vec_rhs_scalars = vec_c_times_s + [self.c_final * self.d_final * beta] @@ -251,8 +246,6 @@ def verify( ) msm_accumulator.accumulate_check(point_lhs, crs_G_vec, vec_d_div_s) - return (True, "") - def to_json(self): return { "B_c": point_projective_to_json(self.B_c), diff --git a/curdleproofs/curdleproofs/msm_accumulator.py b/curdleproofs/curdleproofs/msm_accumulator.py index 002e15c..268804c 100644 --- a/curdleproofs/curdleproofs/msm_accumulator.py +++ b/curdleproofs/curdleproofs/msm_accumulator.py @@ -66,7 +66,7 @@ def accumulate_check( base_affine_int ] + random_factor * Fr(scalar) - def verify(self) -> bool: + def verify(self): bases: List[Tuple[int, int]] scalars: List[Fr] bases, scalars = map(list, zip(*self.base_scalar_map.items())) # type: ignore @@ -75,4 +75,4 @@ def verify(self) -> bool: list(map(int, scalars)), ) # print("bases", bases, "scalars", scalars, "computed", normalize(computed), "expected", normalize(self.A_c), "eq", eq(computed, self.A_c)) - return eq(computed, self.A_c) + assert eq(computed, self.A_c) diff --git a/curdleproofs/curdleproofs/opening.py b/curdleproofs/curdleproofs/opening.py index 7a979a7..1e2d670 100644 --- a/curdleproofs/curdleproofs/opening.py +++ b/curdleproofs/curdleproofs/opening.py @@ -67,7 +67,7 @@ def verify( k_r_G: PointProjective, r_G: PointProjective, k_G: PointProjective, - ) -> bool: + ): transcript.append_list( b"tracker_opening_proof", points_projective_to_bytes([k_G, G1, k_r_G, r_G, self.A, self.B]), @@ -79,7 +79,7 @@ def verify( Aprime = add(multiply(G1, int(self.s)), multiply(k_G, int(challenge))) Bprime = add(multiply(r_G, int(self.s)), multiply(k_r_G, int(challenge))) - return eq(Aprime, self.A) and eq(Bprime, self.B) + assert eq(Aprime, self.A) and eq(Bprime, self.B) def to_json(self): return { diff --git a/curdleproofs/curdleproofs/same_msm.py b/curdleproofs/curdleproofs/same_msm.py index 199403d..6c85ff6 100644 --- a/curdleproofs/curdleproofs/same_msm.py +++ b/curdleproofs/curdleproofs/same_msm.py @@ -14,7 +14,7 @@ log2_int, ) from curdleproofs.curdleproofs_transcript import CurdleproofsTranscript -from typing import List, Optional, Tuple, Type, TypeVar +from typing import List, Tuple, Type, TypeVar from curdleproofs.util import PointProjective, Fr, invert from curdleproofs.msm_accumulator import MSMAccumulator, compute_MSM from py_ecc.optimized_bls12_381.optimized_curve import ( @@ -148,12 +148,12 @@ def new( def verification_scalars( self, n: int, transcript: CurdleproofsTranscript - ) -> Tuple[Optional[Tuple[List[Fr], List[Fr], List[Fr]]], str]: + ) -> Tuple[List[Fr], List[Fr], List[Fr]]: lg_n = len(self.vec_L_A) if lg_n >= 32: - return None, "lg_n >= 32" + raise Exception("lg_n >= 32") if 2**lg_n != n: - return None, "2**lg_n != n" + raise Exception("2**lg_n != n") bitstring = get_verification_scalars_bitstring(n, lg_n) @@ -182,7 +182,7 @@ def verification_scalars( for j in bitstring[i]: vec_s[i] *= challenges[j] - return (challenges, challenges_inv, vec_s), "" + return (challenges, challenges_inv, vec_s) def verify( self, @@ -194,7 +194,7 @@ def verify( vec_U: List[PointProjective], transcript: CurdleproofsTranscript, msm_accumulator: MSMAccumulator, - ) -> Tuple[bool, str]: + ): n = len(vec_T) transcript.append_list( @@ -209,10 +209,7 @@ def verify( ) alpha = transcript.get_and_append_challenge(b"same_msm_alpha") - (ret, err) = self.verification_scalars(n, transcript) - - if ret is None: - return False, err + ret = self.verification_scalars(n, transcript) vec_gamma, vec_gamma_inv, vec_s = ret @@ -240,8 +237,6 @@ def verify( ) msm_accumulator.accumulate_check(point_lhs, vec_U, vec_x_times_s) - return True, "" - def to_json(self): return { "B_a": point_projective_to_json(self.B_a), diff --git a/curdleproofs/curdleproofs/same_perm.py b/curdleproofs/curdleproofs/same_perm.py index af166e4..548f9d5 100644 --- a/curdleproofs/curdleproofs/same_perm.py +++ b/curdleproofs/curdleproofs/same_perm.py @@ -1,7 +1,7 @@ from functools import reduce from curdleproofs.grand_prod import GrandProductProof from curdleproofs.curdleproofs_transcript import CurdleproofsTranscript -from typing import List, Optional, Tuple, Type, TypeVar +from typing import List, Type, TypeVar from curdleproofs.util import ( PointProjective, Fr, @@ -42,7 +42,7 @@ def new( vec_a_blinders: List[Fr], vec_m_blinders: List[Fr], transcript: CurdleproofsTranscript, - ) -> Tuple[Optional[T_SAME_PERM_PROOF], str]: + ) -> T_SAME_PERM_PROOF: n_blinders = len(vec_a_blinders) ell = len(crs_G_vec) @@ -66,7 +66,7 @@ def new( vec_a_blinders[i] + alpha * vec_m_blinders[i] for i in range(0, n_blinders) ] - (grand_product_proof, err) = GrandProductProof.new( + grand_product_proof = GrandProductProof.new( crs_G_vec=crs_G_vec, crs_H_vec=crs_H_vec, crs_U=crs_U, @@ -77,10 +77,7 @@ def new( transcript=transcript, ) - if grand_product_proof is None: - return (None, err or "") - - return cls(B, grand_product_proof), "" + return cls(B, grand_product_proof) def verify( self, @@ -95,7 +92,7 @@ def verify( n_blinders: int, transcript: CurdleproofsTranscript, msm_accumulator: MSMAccumulator, - ) -> Tuple[bool, str]: + ): ell = len(crs_G_vec) # Step 1 @@ -117,7 +114,7 @@ def verify( vec_beta_repeated, ) - (grand_prod_verify, err) = self.grand_prod_proof.verify( + self.grand_prod_proof.verify( crs_G_vec=crs_G_vec, crs_H_vec=crs_H_vec, crs_U=crs_U, @@ -130,11 +127,6 @@ def verify( msm_accumulator=msm_accumulator, ) - if not grand_prod_verify: - return (False, err) - - return (True, "") - def to_json(self): return { "B": point_projective_to_json(self.B), diff --git a/curdleproofs/curdleproofs/same_scalar.py b/curdleproofs/curdleproofs/same_scalar.py index de87b3f..37c6bb4 100644 --- a/curdleproofs/curdleproofs/same_scalar.py +++ b/curdleproofs/curdleproofs/same_scalar.py @@ -2,7 +2,7 @@ from curdleproofs.commitment import GroupCommitment from curdleproofs.util import field_from_json, field_to_json, points_projective_to_bytes from curdleproofs.curdleproofs_transcript import CurdleproofsTranscript -from typing import Tuple, Type, TypeVar +from typing import Type, TypeVar from curdleproofs.util import ( PointProjective, Fr, @@ -81,7 +81,7 @@ def verify( cm_T: GroupCommitment, cm_U: GroupCommitment, transcript: CurdleproofsTranscript, - ) -> Tuple[bool, str]: + ): transcript.append_list( b"sameexp_points", points_projective_to_bytes( @@ -111,10 +111,7 @@ def verify( computed_1 = self.cm_A + (cm_T * alpha) computed_2 = self.cm_B + (cm_U * alpha) - if expected_1 == computed_1 and expected_2 == computed_2: - return (True, "") - else: - return (False, "Failure") + assert expected_1 == computed_1 and expected_2 == computed_2 def to_json(self): return { diff --git a/curdleproofs/curdleproofs/test_curdleproofs.py b/curdleproofs/curdleproofs/test_curdleproofs.py index b2e3d83..6ddc1f5 100644 --- a/curdleproofs/curdleproofs/test_curdleproofs.py +++ b/curdleproofs/curdleproofs/test_curdleproofs.py @@ -1,6 +1,7 @@ from functools import reduce import operator import random +import pytest from curdleproofs.crs import CurdleproofsCrs from curdleproofs.grand_prod import GrandProductProof from curdleproofs.opening import TrackerOpeningProof @@ -61,7 +62,7 @@ def test_ipa(): B = compute_MSM(crs_G_vec, vec_b) C = compute_MSM(crs_G_prime_vec, vec_c) - (proof, err) = IPA.new( + proof = IPA.new( crs_G_vec=crs_G_vec, crs_G_prime_vec=crs_G_prime_vec, crs_H=crs_H, @@ -83,12 +84,11 @@ def test_ipa(): "crs len", len(crs_G_vec), ) - print("err: ", err) transcript_verifier = CurdleproofsTranscript(b"curdleproofs") msm_accumulator = MSMAccumulator() - (result, err) = proof.verify( + proof.verify( crs_G_vec=crs_G_vec, crs_H=crs_H, C=B, @@ -98,30 +98,23 @@ def test_ipa(): transcript=transcript_verifier, msm_accumulator=msm_accumulator, ) - msm_verify = msm_accumulator.verify() - - print("result: ", result) - print("msm_verify: ", msm_verify) - print("err: ", err) - assert result and msm_verify + msm_accumulator.verify() transcript_wrong = CurdleproofsTranscript(b"curdleproofs") msm_accumulator_wrong = MSMAccumulator() - (result_wrong, err_wrong) = proof.verify( - crs_G_vec=crs_G_vec, - crs_H=crs_H, - C=B, - D=C, - inner_prod=z + Fr.one(), - vec_u=vec_u, - transcript=transcript_wrong, - msm_accumulator=msm_accumulator_wrong, - ) - msm_wrong_verify = msm_accumulator_wrong.verify() - print("result_wrong: ", result_wrong) - print("msm_wrong_verify: ", msm_wrong_verify) - print("err_wrong: ", err_wrong) - assert not (result_wrong and msm_wrong_verify) + + with pytest.raises(AssertionError): + proof.verify( + crs_G_vec=crs_G_vec, + crs_H=crs_H, + C=B, + D=C, + inner_prod=z + Fr.one(), + vec_u=vec_u, + transcript=transcript_wrong, + msm_accumulator=msm_accumulator_wrong, + ) + msm_accumulator_wrong.verify() def test_gprod(): @@ -144,7 +137,7 @@ def test_gprod(): B = add(compute_MSM(crs_G_vec, vec_b), compute_MSM(crs_H_vec, vec_b_blinders)) - (gprod_proof, err) = GrandProductProof.new( + gprod_proof = GrandProductProof.new( crs_G_vec=crs_G_vec, crs_H_vec=crs_H_vec, crs_U=crs_U, @@ -156,12 +149,11 @@ def test_gprod(): ) print("Prover result: ", gprod_proof) - print("Prover error:", err) transcript_verifier = CurdleproofsTranscript(b"curdleproofs") msm_accumulator = MSMAccumulator() - (result, err) = gprod_proof.verify( + gprod_proof.verify( crs_G_vec=crs_G_vec, crs_H_vec=crs_H_vec, crs_U=crs_U, @@ -174,58 +166,45 @@ def test_gprod(): msm_accumulator=msm_accumulator, ) - msm_verify = msm_accumulator.verify() - - print("Result: ", result) - print("MSM verify: ", msm_verify) - print("Error: ", err) - assert result and msm_verify + msm_accumulator.verify() # Wrong test transcript_verifier = CurdleproofsTranscript(b"curdleproofs") msm_accumulator = MSMAccumulator() - (result, err) = gprod_proof.verify( - crs_G_vec=crs_G_vec, - crs_H_vec=crs_H_vec, - crs_U=crs_U, - crs_G_sum=crs_G_sum, - crs_H_sum=crs_H_sum, - B=B, - gprod_result=gprod_result + Fr.one(), - n_blinders=n_blinders, - transcript=transcript_verifier, - msm_accumulator=msm_accumulator, - ) - - msm_verify = msm_accumulator.verify() - - print("Wrong Result: ", result) - print("Wrong MSM verify: ", msm_verify) - print("Wrong Error: ", err) - assert not (result and msm_verify) + with pytest.raises(AssertionError): + gprod_proof.verify( + crs_G_vec=crs_G_vec, + crs_H_vec=crs_H_vec, + crs_U=crs_U, + crs_G_sum=crs_G_sum, + crs_H_sum=crs_H_sum, + B=B, + gprod_result=gprod_result + Fr.one(), + n_blinders=n_blinders, + transcript=transcript_verifier, + msm_accumulator=msm_accumulator, + ) + + msm_accumulator.verify() # Wrong test transcript_verifier = CurdleproofsTranscript(b"curdleproofs") msm_accumulator = MSMAccumulator() - (result, err) = gprod_proof.verify( - crs_G_vec=crs_G_vec, - crs_H_vec=crs_H_vec, - crs_U=crs_U, - crs_G_sum=crs_G_sum, - crs_H_sum=crs_H_sum, - B=multiply(B, 3), - gprod_result=gprod_result, - n_blinders=n_blinders, - transcript=transcript_verifier, - msm_accumulator=msm_accumulator, - ) - - msm_verify = msm_accumulator.verify() - - print("Wrong Result: ", result) - print("Wrong MSM verify: ", msm_verify) - print("Wrong Error: ", err) - assert not (result and msm_verify) + with pytest.raises(AssertionError): + gprod_proof.verify( + crs_G_vec=crs_G_vec, + crs_H_vec=crs_H_vec, + crs_U=crs_U, + crs_G_sum=crs_G_sum, + crs_H_sum=crs_H_sum, + B=multiply(B, 3), + gprod_result=gprod_result, + n_blinders=n_blinders, + transcript=transcript_verifier, + msm_accumulator=msm_accumulator, + ) + + msm_accumulator.verify() def test_same_permutation_proof(): @@ -256,7 +235,7 @@ def test_same_permutation_proof(): ) M = add(compute_MSM(crs_G_vec, permutation), compute_MSM(crs_H_vec, vec_m_blinders)) - (same_perm_proof, err) = SamePermutationProof.new( + same_perm_proof = SamePermutationProof.new( crs_G_vec=crs_G_vec, crs_H_vec=crs_H_vec, crs_U=crs_U, @@ -270,12 +249,11 @@ def test_same_permutation_proof(): ) print("Proof: ", same_perm_proof) - print("Error: ", err) transcript_verifier = CurdleproofsTranscript(b"curdleproofs") msm_accumulator = MSMAccumulator() - (verify, err) = same_perm_proof.verify( + same_perm_proof.verify( crs_G_vec=crs_G_vec, crs_H_vec=crs_H_vec, crs_U=crs_U, @@ -289,12 +267,7 @@ def test_same_permutation_proof(): msm_accumulator=msm_accumulator, ) - msm_verify = msm_accumulator.verify() - - print("Verify: ", verify) - print("Error: ", err) - print("MSM verify: ", msm_verify) - assert verify and msm_verify + msm_accumulator.verify() def test_same_msm(): @@ -327,7 +300,7 @@ def test_same_msm(): transcript_verifier = CurdleproofsTranscript(b"curdleproofs") msm_accumulator = MSMAccumulator() - (result, err) = proof.verify( + proof.verify( crs_G_vec=crs_G_vec, A=A, Z_t=Z_t, @@ -338,11 +311,7 @@ def test_same_msm(): msm_accumulator=msm_accumulator, ) - msm_verify = msm_accumulator.verify() - print("Result", result) - print("MSM verify", msm_verify) - print("Error", err) - assert result and msm_verify + msm_accumulator.verify() def test_same_scalar_arg(): @@ -379,7 +348,7 @@ def test_same_scalar_arg(): print("proof", proof) transcript_verifier = CurdleproofsTranscript(b"curdleproofs") - (res, err) = proof.verify( + proof.verify( crs_G_t=crs_G_t, crs_G_u=crs_G_u, crs_H=crs_H, @@ -389,9 +358,6 @@ def test_same_scalar_arg(): cm_U=cm_U, transcript=transcript_verifier, ) - print("res", res) - print("err", err) - assert res def test_group_commit(): @@ -444,10 +410,7 @@ def test_shuffle_argument(): # for i in range(50): # print("iter ", i) - verify, err = shuffle_proof.verify(crs, vec_R, vec_S, vec_T, vec_U, M) - print("verify", verify) - print("err", err) - assert verify + shuffle_proof.verify(crs, vec_R, vec_S, vec_T, vec_U, M) def test_bad_shuffle_argument(): @@ -481,43 +444,34 @@ def test_bad_shuffle_argument(): print("shuffle proof", shuffle_proof) - verify, err = shuffle_proof.verify(crs, vec_S, vec_R, vec_T, vec_U, M) - print("false verify", verify) - print("err", err) - assert not verify + with pytest.raises(AssertionError): + shuffle_proof.verify(crs, vec_S, vec_R, vec_T, vec_U, M) another_permutation = list(range(ell)) random.shuffle(another_permutation) - verify, err = shuffle_proof.verify( - crs, - vec_R, - vec_S, - get_permutation(vec_T, another_permutation), - get_permutation(vec_U, another_permutation), - M, - ) - print("false verify also", verify) - print("err", err) - assert not verify + with pytest.raises(AssertionError): + shuffle_proof.verify( + crs, + vec_R, + vec_S, + get_permutation(vec_T, another_permutation), + get_permutation(vec_U, another_permutation), + M, + ) - verify, err = shuffle_proof.verify( - crs, vec_R, vec_S, vec_T, vec_U, multiply(M, int(k)) - ) - print("false verify also also", verify) - print("err", err) - assert not verify + shuffle_proof.verify( + crs, vec_R, vec_S, vec_T, vec_U, multiply(M, int(k)) + ) another_k = Fr(random.randint(1, Fr.field_modulus)) another_vec_T = [multiply(affine_to_projective(T), int(another_k)) for T in vec_T] another_vec_U = [multiply(affine_to_projective(U), int(another_k)) for U in vec_U] - verify, err = shuffle_proof.verify( - crs, vec_R, vec_S, another_vec_T, another_vec_U, M - ) - print("false verify also also also", verify) - print("err", err) - assert not verify + with pytest.raises(AssertionError): + shuffle_proof.verify( + crs, vec_R, vec_S, another_vec_T, another_vec_U, M + ) def test_serde(): @@ -573,7 +527,7 @@ def test_serde(): # for i in range(50): # print("iter ", i) - verify, err = deser_shuffle_proof.verify( + deser_shuffle_proof.verify( deser_crs, deser_verifier_input.vec_R, deser_verifier_input.vec_S, @@ -581,9 +535,6 @@ def test_serde(): deser_verifier_input.vec_U, deser_verifier_input.M, ) - print("verify", verify) - print("err", err) - assert verify def test_tracker_opening_proof(): @@ -606,7 +557,7 @@ def test_tracker_opening_proof(): deser_proof = TrackerOpeningProof.from_json(json_str_proof) transcript_verifier = CurdleproofsTranscript(b"whisk_opening_proof") - assert deser_proof.verify(transcript_verifier, k_r_G, r_G, k_G) + deser_proof.verify(transcript_verifier, k_r_G, r_G, k_G) def test_whisk_interface_tracker_opening_proof(): @@ -616,7 +567,7 @@ def test_whisk_interface_tracker_opening_proof(): tracker_proof = GenerateWhiskTrackerProof(tracker, k) - assert IsValidWhiskOpeningProof(tracker, k_commitment, tracker_proof) + IsValidWhiskOpeningProof(tracker, k_commitment, tracker_proof) def test_whisk_interface_shuffle_proof(): @@ -625,7 +576,7 @@ def test_whisk_interface_shuffle_proof(): crs = generate_random_crs(ell) pre_trackers = generate_random_trackers(ell) post_trackers, shuffle_proof = GenerateWhiskShuffleProof(crs, pre_trackers) - assert IsValidWhiskShuffleProof(crs, pre_trackers, post_trackers, shuffle_proof) + IsValidWhiskShuffleProof(crs, pre_trackers, post_trackers, shuffle_proof) def generate_random_k() -> Fr: diff --git a/curdleproofs/curdleproofs/whisk_interface.py b/curdleproofs/curdleproofs/whisk_interface.py index f313607..8fe6ad4 100644 --- a/curdleproofs/curdleproofs/whisk_interface.py +++ b/curdleproofs/curdleproofs/whisk_interface.py @@ -75,7 +75,7 @@ def IsValidWhiskShuffleProof( pre_shuffle_trackers: Sequence[WhiskTracker], post_shuffle_trackers: Sequence[WhiskTracker], whisk_shuffle_proof_bytes: WhiskShuffleProofBytes, -) -> Tuple[bool, str]: +): """ Verify `post_shuffle_trackers` is a permutation of `pre_shuffle_trackers`. """