From 2e848e0ef003fddd81d6d310a5a7930ca38aa5d3 Mon Sep 17 00:00:00 2001 From: Victor Dumitrescu Date: Wed, 15 Jun 2022 15:16:18 +0200 Subject: [PATCH 1/2] Opam: bump --- .gitlab/ci/templates.yml | 2 +- scripts/version.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab/ci/templates.yml b/.gitlab/ci/templates.yml index b5c0e61b4fb0..6d6428f28f3f 100644 --- a/.gitlab/ci/templates.yml +++ b/.gitlab/ci/templates.yml @@ -2,7 +2,7 @@ variables: # /!\ CI_REGISTRY is overriden to use a private Docker registry mirror in AWS ECR # in GitLab namespaces `nomadic-labs` and `tezos` ## This value MUST be the same as `opam_repository_tag` in `scripts/version.sh` - build_deps_image_version: 7b619e8f294911d4ee5930b3eb5c334dcf710e65 + build_deps_image_version: fba11a81e22ba2949ac9d7f5608966fdc5aa6712 build_deps_image_name: "${CI_REGISTRY}/tezos/opam-repository" GIT_STRATEGY: fetch GIT_DEPTH: "1" diff --git a/scripts/version.sh b/scripts/version.sh index c2688756e497..41a5d2e7b2a6 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -20,12 +20,12 @@ export recommended_node_version=14.12.0 ## full_opam_repository is a commit hash of the public OPAM repository, i.e. ## https://github.com/ocaml/opam-repository -export full_opam_repository_tag=e637ce47cd89e52fce3a0928ddbe3439c6616479 +export full_opam_repository_tag=bf63beadbea0c69b499037cd707fd607ed844f0d ## opam_repository is an additional, tezos-specific opam repository. ## This value MUST be the same as `build_deps_image_version` in `.gitlab/ci/templates.yml export opam_repository_url=https://gitlab.com/tezos/opam-repository -export opam_repository_tag=7b619e8f294911d4ee5930b3eb5c334dcf710e65 +export opam_repository_tag=fba11a81e22ba2949ac9d7f5608966fdc5aa6712 export opam_repository_git=$opam_repository_url.git export opam_repository=$opam_repository_git\#$opam_repository_tag -- GitLab From 4e928778b6b891d8547af70e2ef50078c07ed3d2 Mon Sep 17 00:00:00 2001 From: Antonio Locascio Date: Wed, 18 May 2022 14:10:49 +0200 Subject: [PATCH 2/2] Environment/ZKRU: expose PlonK --- manifest/main.ml | 4 + opam/tezos-protocol-environment.opam | 1 + src/lib_protocol_environment/dune | 1 + .../environment_V6.ml | 6 ++ .../environment_V6.mli | 5 ++ src/lib_protocol_environment/sigs/v6.dune.inc | 8 +- .../sigs/v6/plonk.mli | 79 +++++++++++++++++++ src/lib_protocol_environment/structs/dune | 3 +- .../tezos_protocol_environment_structs.ml | 1 + .../structs/v6_plonk.ml | 48 +++++++++++ 10 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 src/lib_protocol_environment/sigs/v6/plonk.mli create mode 100644 src/lib_protocol_environment/structs/v6_plonk.ml diff --git a/manifest/main.ml b/manifest/main.ml index 1d4507e35e51..29d565a10ddd 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -229,6 +229,8 @@ let ometrics = opam_only "ometrics" V.(at_least "0.2.1") let ppx_expect = inline_tests_backend (external_lib "ppx_expect" V.True) +let plonk = external_lib "tezos-plonk" V.(at_least "0.1.0") + let ptime = external_lib ~js_compatible:true "ptime" V.(at_least "1.0.0") let ppx_deriving = external_lib "ppx_deriving" V.True @@ -1771,6 +1773,7 @@ let tezos_protocol_environment_structs = tezos_scoru_wasm; data_encoding; bls12_381; + plonk; ] let tezos_protocol_environment = @@ -1795,6 +1798,7 @@ protocols.|} zarith; zarith_stubs_js; bls12_381; + plonk; ringo; ringo_lwt; tezos_base |> open_ ~m:"TzPervasives"; diff --git a/opam/tezos-protocol-environment.opam b/opam/tezos-protocol-environment.opam index 83bb185bf8b6..e444f8b44cd1 100644 --- a/opam/tezos-protocol-environment.opam +++ b/opam/tezos-protocol-environment.opam @@ -16,6 +16,7 @@ depends: [ "tezos-scoru-wasm" "data-encoding" { >= "0.5.3" & < "0.6" } "bls12-381" { >= "4.0.0" & < "4.1.0" } + "tezos-plonk" { >= "0.1.0" } "zarith" { >= "1.12" & < "1.13" } "zarith_stubs_js" "ringo" { >= "0.9" } diff --git a/src/lib_protocol_environment/dune b/src/lib_protocol_environment/dune index cd5be010896c..7f0f6b50e9ad 100644 --- a/src/lib_protocol_environment/dune +++ b/src/lib_protocol_environment/dune @@ -9,6 +9,7 @@ zarith zarith_stubs_js bls12-381 + tezos-plonk ringo ringo-lwt tezos-base diff --git a/src/lib_protocol_environment/environment_V6.ml b/src/lib_protocol_environment/environment_V6.ml index 652a3d263371..9239434a28d4 100644 --- a/src/lib_protocol_environment/environment_V6.ml +++ b/src/lib_protocol_environment/environment_V6.ml @@ -99,6 +99,11 @@ module type V6 = sig and type Bls_signature.pk = Bls12_381.Signature.MinPk.pk and type Bls_signature.signature = Bls12_381.Signature.MinPk.signature and type ('a, 'b) Either.t = ('a, 'b) Stdlib.Either.t + and type Bls12_381.Fr.t = Bls12_381.Fr.t + and type Plonk.transcript = Plonk.Main_protocol.transcript + and type Plonk.proof = Plonk.Main_protocol.proof + and type Plonk.verifier_public_parameters = + Plonk.Main_protocol.verifier_public_parameters type error += Ecoproto_error of Error_monad.error @@ -1457,4 +1462,5 @@ struct end module Equality_witness = Environment_context.Equality_witness + module Plonk = Tezos_protocol_environment_structs.V6.Plonk end diff --git a/src/lib_protocol_environment/environment_V6.mli b/src/lib_protocol_environment/environment_V6.mli index ffbaa058e155..a5e6a6c6ff3b 100644 --- a/src/lib_protocol_environment/environment_V6.mli +++ b/src/lib_protocol_environment/environment_V6.mli @@ -100,6 +100,11 @@ module type V6 = sig and type Bls_signature.pk = Bls12_381.Signature.MinPk.pk and type Bls_signature.signature = Bls12_381.Signature.MinPk.signature and type ('a, 'b) Either.t = ('a, 'b) Stdlib.Either.t + and type Bls12_381.Fr.t = Bls12_381.Fr.t + and type Plonk.transcript = Plonk.Main_protocol.transcript + and type Plonk.proof = Plonk.Main_protocol.proof + and type Plonk.verifier_public_parameters = + Plonk.Main_protocol.verifier_public_parameters (** An [Ecoproto_error e] is a shell error that carry a protocol error. diff --git a/src/lib_protocol_environment/sigs/v6.dune.inc b/src/lib_protocol_environment/sigs/v6.dune.inc index 33785133acf1..cb243adaa87a 100644 --- a/src/lib_protocol_environment/sigs/v6.dune.inc +++ b/src/lib_protocol_environment/sigs/v6.dune.inc @@ -77,8 +77,12 @@ v6/updater.mli v6/RPC_context.mli - ;; SCORU - v6/wasm_2_0_0.mli + ;; SCORU + v6/wasm_2_0_0.mli + + ;; ZKRU + v6/plonk.mli + ) (action (with-stdout-to %{targets} (chdir %{workspace_root}} (run %{libexec:tezos-protocol-environment:s_packer} "sigs" %{deps}))))) diff --git a/src/lib_protocol_environment/sigs/v6/plonk.mli b/src/lib_protocol_environment/sigs/v6/plonk.mli new file mode 100644 index 000000000000..678d012f584f --- /dev/null +++ b/src/lib_protocol_environment/sigs/v6/plonk.mli @@ -0,0 +1,79 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +type scalar := Bls12_381.Fr.t + +module Array : sig + val concat : 'a array list -> 'a array + + val length : 'a array -> int + + val to_list : 'a array -> 'a list +end + +type transcript + +type verifier_public_parameters + +type proof + +val verifier_public_parameters_encoding : + verifier_public_parameters Data_encoding.t + +val proof_encoding : proof Data_encoding.t + +val transcript_encoding : transcript Data_encoding.t + +val scalar_encoding : scalar Data_encoding.t + +(** Verifier function: checks proof + Inputs: + - transcript: transcript initialized with SRS + - public_parameters: output of setup + - public_inputs (scalar array): the first values of private_inputs that are public + - proof: output of prove + Outputs: + - bool +*) +val verify : + verifier_public_parameters * transcript -> + public_inputs:scalar array -> + proof -> + bool + +(** Verifier function: checks a bunch of proofs for several circuits + Inputs: + - transcript: transcript initialized with SRS + - public_parameters: output of setup_multi_circuits for the circuits being checked + - public_inputs: StringMap where the lists of public inputs are binded with the circuit to which they correspond + - proof: the unique proof that correspond to all inputs + Outputs: + - bool +*) +val verify_multi_circuits : + verifier_public_parameters * transcript -> + public_inputs:(string * scalar array list) list -> + proof -> + bool diff --git a/src/lib_protocol_environment/structs/dune b/src/lib_protocol_environment/structs/dune index d305f7eeed77..3613a738a540 100644 --- a/src/lib_protocol_environment/structs/dune +++ b/src/lib_protocol_environment/structs/dune @@ -11,4 +11,5 @@ tezos-lwt-result-stdlib tezos-scoru-wasm data-encoding - bls12-381)) + bls12-381 + tezos-plonk)) diff --git a/src/lib_protocol_environment/structs/tezos_protocol_environment_structs.ml b/src/lib_protocol_environment/structs/tezos_protocol_environment_structs.ml index ed2dd0570548..0a4c8a98291d 100644 --- a/src/lib_protocol_environment/structs/tezos_protocol_environment_structs.ml +++ b/src/lib_protocol_environment/structs/tezos_protocol_environment_structs.ml @@ -91,4 +91,5 @@ end module V6 = struct module Error_monad_infix_globals = V0_error_monad_infix_globals + module Plonk = V6_plonk end diff --git a/src/lib_protocol_environment/structs/v6_plonk.ml b/src/lib_protocol_environment/structs/v6_plonk.ml new file mode 100644 index 000000000000..4259eadc9fb9 --- /dev/null +++ b/src/lib_protocol_environment/structs/v6_plonk.ml @@ -0,0 +1,48 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +include Plonk.Main_protocol + +module Array = struct + let concat = Stdlib.Array.concat + + let length = Stdlib.Array.length + + let to_list = Stdlib.Array.to_list +end + +let verify pp ~public_inputs proof = + Result.fold ~ok:Fun.id ~error:(Fun.const false) + @@ Tezos_lwt_result_stdlib.Lwtreslib.Bare.Result.catch (fun () -> + fst @@ verify pp ~public_inputs proof) + +let verify_multi_circuits pp ~public_inputs proof = + Result.fold ~ok:Fun.id ~error:(Fun.const false) + @@ Tezos_lwt_result_stdlib.Lwtreslib.Bare.Result.catch (fun () -> + fst + @@ verify_multi_circuits + pp + ~public_inputs:(SMap.of_list public_inputs) + proof) -- GitLab