From 1e873392457ee7f941825d38de384f46925c2325 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 10 Oct 2023 07:06:28 +0100 Subject: [PATCH 1/5] Set the max_poly_size for the constraint system --- .../crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_index.rs | 3 ++- .../crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_index.rs b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_index.rs index abd43294f41..303d3d5979d 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_index.rs +++ b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_index.rs @@ -9,7 +9,7 @@ use kimchi::circuits::{constraints::ConstraintSystem, gate::CircuitGate}; use kimchi::{linearization::expr_linearization, prover_index::ProverIndex}; use mina_curves::pasta::{Fp, Pallas, Vesta, VestaParameters}; use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, sponge::DefaultFqSponge}; -use poly_commitment::evaluation_proof::OpeningProof; +use poly_commitment::{evaluation_proof::OpeningProof, SRS as _}; use serde::{Deserialize, Serialize}; use std::{ fs::{File, OpenOptions}, @@ -70,6 +70,7 @@ pub fn caml_pasta_fp_plonk_index_create( let cs = match ConstraintSystem::::create(gates) .public(public as usize) .prev_challenges(prev_challenges as usize) + .max_poly_size(Some(srs.0.max_poly_size())) .lookup(lookup_tables) .runtime(if runtime_tables.is_empty() { None diff --git a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs index 24317bfc561..5afb864d8c8 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs +++ b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs @@ -9,7 +9,7 @@ use kimchi::circuits::{constraints::ConstraintSystem, gate::CircuitGate}; use kimchi::{linearization::expr_linearization, prover_index::ProverIndex}; use mina_curves::pasta::{Fq, Pallas, PallasParameters, Vesta}; use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, sponge::DefaultFqSponge}; -use poly_commitment::evaluation_proof::OpeningProof; +use poly_commitment::{evaluation_proof::OpeningProof, SRS as _}; use serde::{Deserialize, Serialize}; use std::{ fs::{File, OpenOptions}, @@ -70,6 +70,7 @@ pub fn caml_pasta_fq_plonk_index_create( let cs = match ConstraintSystem::::create(gates) .public(public as usize) .prev_challenges(prev_challenges as usize) + .max_poly_size(Some(srs.0.max_poly_size())) .lookup(lookup_tables) .runtime(if runtime_tables.is_empty() { None From e95103ab28632c66d16bbe6d817bc140f951c2f7 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 10 Oct 2023 07:21:47 +0100 Subject: [PATCH 2/5] Propagate the useful error message from rust --- .../kimchi_bindings/stubs/src/pasta_fp_plonk_index.rs | 8 ++------ .../kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_index.rs b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_index.rs index 303d3d5979d..d81273d3e69 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_index.rs +++ b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_index.rs @@ -79,12 +79,8 @@ pub fn caml_pasta_fp_plonk_index_create( }) .build() { - Err(_) => { - return Err(ocaml::Error::failwith( - "caml_pasta_fp_plonk_index_create: could not create constraint system", - ) - .err() - .unwrap()) + Err(e) => { + return Err(e.into()) } Ok(cs) => cs, }; diff --git a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs index 5afb864d8c8..2ecc7db8ac0 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs +++ b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs @@ -79,12 +79,8 @@ pub fn caml_pasta_fq_plonk_index_create( }) .build() { - Err(_) => { - return Err(ocaml::Error::failwith( - "caml_pasta_fq_plonk_index_create: could not create constraint system", - ) - .err() - .unwrap()) + Err(e) => { + return Err(e.into()) } Ok(cs) => cs, }; From 9a0d0dc6d9055dc94b6565299c95e59d43aa6ce3 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 10 Oct 2023 07:35:00 +0100 Subject: [PATCH 3/5] Remove unnecessary max_poly_size from fq_plonk_index --- .../crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs index 2ecc7db8ac0..8a221f58fe4 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs +++ b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_index.rs @@ -9,7 +9,7 @@ use kimchi::circuits::{constraints::ConstraintSystem, gate::CircuitGate}; use kimchi::{linearization::expr_linearization, prover_index::ProverIndex}; use mina_curves::pasta::{Fq, Pallas, PallasParameters, Vesta}; use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, sponge::DefaultFqSponge}; -use poly_commitment::{evaluation_proof::OpeningProof, SRS as _}; +use poly_commitment::{evaluation_proof::OpeningProof}; use serde::{Deserialize, Serialize}; use std::{ fs::{File, OpenOptions}, @@ -70,7 +70,6 @@ pub fn caml_pasta_fq_plonk_index_create( let cs = match ConstraintSystem::::create(gates) .public(public as usize) .prev_challenges(prev_challenges as usize) - .max_poly_size(Some(srs.0.max_poly_size())) .lookup(lookup_tables) .runtime(if runtime_tables.is_empty() { None From 619adbcadce477aac6ed031c5cbfaca64dfec243 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 10 Oct 2023 07:55:03 +0100 Subject: [PATCH 4/5] Propagate step public input evals to the wrap proof --- src/lib/pickles/pickles.ml | 14 ++++++++------ src/lib/pickles/proof.ml | 2 +- src/lib/pickles/proof.mli | 2 +- src/lib/pickles/step.ml | 2 +- src/lib/pickles/wrap.ml | 32 ++++++++++++++++++-------------- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/lib/pickles/pickles.ml b/src/lib/pickles/pickles.ml index 8d5690b17ff..1ce46ea1819 100644 --- a/src/lib/pickles/pickles.ml +++ b/src/lib/pickles/pickles.ml @@ -1447,7 +1447,7 @@ module Make_str (_ : Wire_types.Concrete) = struct V.f Max_local_max_proofs_verifieds.length (M.f prev_messages_for_next_wrap_proof) in - O.create pairing_vk + O.create_with_public_evals pairing_vk Vector.( map2 (Vector.trim_front sgs lte) prev_challenges ~f:(fun commitment cs -> @@ -1520,7 +1520,7 @@ module Make_str (_ : Wire_types.Concrete) = struct let tick_combined_evals = Plonk_checks.evals_of_split_evals (module Tick.Field) - proof.openings.evals + proof.proof.openings.evals ~rounds:(Nat.to_int Tick.Rounds.n) ~zeta:As_field.zeta ~zetaw in @@ -1573,11 +1573,13 @@ module Make_str (_ : Wire_types.Concrete) = struct (* Note: We do not pad here. *) ~actual_proofs_verified: (Nat.Add.create actual_proofs_verified) - { evals = proof.openings.evals; public_input = x_hat } + { evals = proof.proof.openings.evals + ; public_input = x_hat + } ~r ~xi ~zeta ~zetaw ~old_bulletproof_challenges:prev_challenges ~env:tick_env ~domain:tick_domain - ~ft_eval1:proof.openings.ft_eval1 + ~ft_eval1:proof.proof.openings.ft_eval1 ~plonk:tick_plonk_minimal in let chal = Challenge.Constant.of_tick_field in @@ -1769,9 +1771,9 @@ module Make_str (_ : Wire_types.Concrete) = struct ; prev_evals = { Plonk_types.All_evals.evals = { public_input = x_hat - ; evals = proof.openings.evals + ; evals = proof.proof.openings.evals } - ; ft_eval1 = proof.openings.ft_eval1 + ; ft_eval1 = proof.proof.openings.ft_eval1 } } : _ P.Base.Wrap.t ) diff --git a/src/lib/pickles/proof.ml b/src/lib/pickles/proof.ml index d04f59f701a..2aefb7078a8 100644 --- a/src/lib/pickles/proof.ml +++ b/src/lib/pickles/proof.ml @@ -24,7 +24,7 @@ module Base = struct Types.Step.Statement.t ; index : int ; prev_evals : 'prev_evals - ; proof : Tick.Proof.t + ; proof : Tick.Proof.with_public_evals } end diff --git a/src/lib/pickles/proof.mli b/src/lib/pickles/proof.mli index 47e139becab..404e6058699 100644 --- a/src/lib/pickles/proof.mli +++ b/src/lib/pickles/proof.mli @@ -21,7 +21,7 @@ module Base : sig Import.Types.Step.Statement.t ; index : int ; prev_evals : 'prev_evals - ; proof : Backend.Tick.Proof.t + ; proof : Backend.Tick.Proof.with_public_evals } end diff --git a/src/lib/pickles/step.ml b/src/lib/pickles/step.ml index ed38eb776ab..2e0505ba018 100644 --- a/src/lib/pickles/step.ml +++ b/src/lib/pickles/step.ml @@ -880,7 +880,7 @@ struct } in [%log internal] "Pickles_step_proof_done" ; - ( { Proof.Base.Step.proof = next_proof.proof + ( { Proof.Base.Step.proof = next_proof ; statement = next_statement ; index = branch_data.index ; prev_evals = diff --git a/src/lib/pickles/wrap.ml b/src/lib/pickles/wrap.ml index 86137176902..59ec07e19f6 100644 --- a/src/lib/pickles/wrap.ml +++ b/src/lib/pickles/wrap.ml @@ -99,11 +99,12 @@ let deferred_values (type n) ~(sgs : (Backend.Tick.Curve.Affine.t, n) Vector.t) ~actual_feature_flags ~(prev_challenges : ((Backend.Tick.Field.t, _) Vector.t, n) Vector.t) ~(step_vk : Kimchi_bindings.Protocol.VerifierIndex.Fp.t) - ~(public_input : Backend.Tick.Field.t list) ~(proof : Backend.Tick.Proof.t) + ~(public_input : Backend.Tick.Field.t list) + ~(proof : Backend.Tick.Proof.with_public_evals) ~(actual_proofs_verified : n Nat.t) : deferred_values_and_hints = let module O = Tick.Oracles in let o = - O.create step_vk + O.create_with_public_evals step_vk Vector.( map2 sgs prev_challenges ~f:(fun commitment cs -> { Tick.Proof.Challenge_polynomial.commitment @@ -159,7 +160,7 @@ let deferred_values (type n) ~(sgs : (Backend.Tick.Curve.Affine.t, n) Vector.t) let tick_combined_evals = Plonk_checks.evals_of_split_evals (module Tick.Field) - proof.openings.evals ~rounds:(Nat.to_int Tick.Rounds.n) + proof.proof.openings.evals ~rounds:(Nat.to_int Tick.Rounds.n) ~zeta:As_field.zeta ~zetaw |> Plonk_types.Evals.to_in_circuit in @@ -236,10 +237,11 @@ let deferred_values (type n) ~(sgs : (Backend.Tick.Curve.Affine.t, n) Vector.t) As_field.( combined_inner_product (* Note: We do not pad here. *) ~actual_proofs_verified:(Nat.Add.create actual_proofs_verified) - { evals = proof.openings.evals; public_input = x_hat } + { evals = proof.proof.openings.evals; public_input = x_hat } ~r ~xi ~zeta ~zetaw ~old_bulletproof_challenges:prev_challenges ~env:tick_env ~domain:tick_domain - ~ft_eval1:proof.openings.ft_eval1 ~plonk:tick_plonk_minimal) + ~ft_eval1:proof.proof.openings.ft_eval1 + ~plonk:tick_plonk_minimal) ; branch_data = { proofs_verified = ( match actual_proofs_verified with @@ -332,7 +334,8 @@ let%test_module "gate finalization" = (feature_flags : Plonk_types.Features.options) (public_input : Pasta_bindings.Fp.t list) (vk : Kimchi_bindings.Protocol.VerifierIndex.Fp.t) - (proof : Backend.Tick.Proof.t) : Impls.Step.Boolean.value = + (proof : Backend.Tick.Proof.with_public_evals) : + Impls.Step.Boolean.value = (* Constants helper - takes an OCaml value and converts it to a snarky value, where all values here are constant literals. N.b. this should be encapsulated as Snarky internals, but it never got merged. *) @@ -418,8 +421,9 @@ let%test_module "gate finalization" = and evals = constant (Plonk_types.All_evals.typ (module Impls.Step) full_features) - { evals = { public_input = x_hat_evals; evals = proof.openings.evals } - ; ft_eval1 = proof.openings.ft_eval1 + { evals = + { public_input = x_hat_evals; evals = proof.proof.openings.evals } + ; ft_eval1 = proof.proof.openings.ft_eval1 } in @@ -499,7 +503,7 @@ let%test_module "gate finalization" = let runtest feature_flags = run_recursive_proof_test S.actual_feature_flags feature_flags - public_input vk proof.proof + public_input vk proof let%test "true -> yes" = runtest test_feature_flags_configs.true_is_yes @@ -734,9 +738,9 @@ let wrap in k (M.f messages_for_next_wrap_proof) | Messages -> - k proof.messages + k proof.proof.messages | Openings_proof -> - k proof.openings.proof + k proof.proof.openings.proof | Proof_state -> k prev_statement_with_hashes.proof_state | Which_branch -> @@ -802,7 +806,7 @@ let wrap let messages_for_next_wrap_proof : _ P.Base.Messages_for_next_proof_over_same_field.Wrap.t = { challenge_polynomial_commitment = - proof.openings.proof.challenge_polynomial_commitment + proof.proof.openings.proof.challenge_polynomial_commitment ; old_bulletproof_challenges = Vector.map prev_statement.proof_state.unfinalized_proofs ~f:(fun t -> t.deferred_values.bulletproof_challenges ) @@ -913,8 +917,8 @@ let wrap ~to_option:Opt.to_option_unsafe ; prev_evals = { Plonk_types.All_evals.evals = - { public_input = x_hat_evals; evals = proof.openings.evals } - ; ft_eval1 = proof.openings.ft_eval1 + { public_input = x_hat_evals; evals = proof.proof.openings.evals } + ; ft_eval1 = proof.proof.openings.ft_eval1 } } : _ P.Base.Wrap.t ) From bf2022ea05e5305042256b1906cab33136f4bfd7 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 10 Oct 2023 08:31:43 +0100 Subject: [PATCH 5/5] Bump proof-systems for chunking bugfix --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index 970c3ef8ef3..0467bcec007 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit 970c3ef8ef3b9a3f5d01aea51ed892ecd53b42b8 +Subproject commit 0467bcec00792b590239e15107718dabfc84d10a