From c40c7470354130ea1f5957ab7fc897eed614a363 Mon Sep 17 00:00:00 2001 From: kilyig Date: Thu, 2 Feb 2023 01:02:11 -0500 Subject: [PATCH] hackathon attempt --- prover.py | 12 ++++++++++++ setup.py | 20 ++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/prover.py b/prover.py index 927fc66..ea84074 100644 --- a/prover.py +++ b/prover.py @@ -98,11 +98,22 @@ def round_1( # - A_values: witness[program.wires()[i].L] # - B_values: witness[program.wires()[i].R] # - C_values: witness[program.wires()[i].O] + filler = [Scalar(0) for i in range(self.group_order - len(program.wires()))] + + A_values = [Scalar(witness[program.wires()[i].L]) for i in range(len(program.wires()))] + filler + B_values = [Scalar(witness[program.wires()[i].R]) for i in range(len(program.wires()))] + filler + C_values = [Scalar(witness[program.wires()[i].O]) for i in range(len(program.wires()))] + filler # Construct A, B, C Lagrange interpolation polynomials for # A_values, B_values, C_values + self.A = Polynomial(A_values, Basis.LAGRANGE) + self.B = Polynomial(B_values, Basis.LAGRANGE) + self.C = Polynomial(C_values, Basis.LAGRANGE) # Compute a_1, b_1, c_1 commitments to A, B, C polynomials + a_1 = setup.commit(self.A) + b_1 = setup.commit(self.B) + c_1 = setup.commit(self.C) # Sanity check that witness fulfils gate constraints assert ( @@ -313,3 +324,4 @@ def expanded_evals_to_coeffs(self, x: Polynomial): def rlc(self, term_1, term_2): return term_1 + term_2 * self.beta + self.gamma + diff --git a/setup.py b/setup.py index bb2b5ef..a96e1d2 100644 --- a/setup.py +++ b/setup.py @@ -67,11 +67,27 @@ def commit(self, values: Polynomial) -> G1Point: assert values.basis == Basis.LAGRANGE # Run inverse FFT to convert values from Lagrange basis to monomial basis + monomial_version = values.ifft() # Optional: Check values size does not exceed maximum power setup can handle # Compute linear combination of setup with values - return NotImplemented + commitment = ec_lincomb(list(zip(self.powers_of_x, monomial_version.values))) + + return commitment # Generate the verification key for this program with the given setup def verification_key(self, pk: CommonPreprocessedInput) -> VerificationKey: # Create the appropriate VerificationKey object - return NotImplemented + return VerificationKey( + pk.group_order, + self.commit(pk.QM), + self.commit(pk.QL), + self.commit(pk.QR), + self.commit(pk.QO), + self.commit(pk.QC), + self.commit(pk.S1), + self.commit(pk.S2), + self.commit(pk.S3), + self.X2, + Scalar.root_of_unity(pk.group_order) + ) +