diff --git a/.gitlab/ci/templates.yml b/.gitlab/ci/templates.yml index b5c0e61b4fb0197c54e53a98c97972370ebb9d7d..6d6428f28f3fbdaa3e4f86c44c7aa673efe00fdc 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/manifest/main.ml b/manifest/main.ml index 1d4507e35e511f981f73e90436d714781599b465..29d565a10ddd531dbed275af81a4342e9742c222 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 83bb185bf8b69b449c7686581b90b5cd293bf30f..e444f8b44cd19fd1e61ae50e6281964759771a0b 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/scripts/version.sh b/scripts/version.sh index c2688756e4971f166ca701c181a1a1fd4069abf7..41a5d2e7b2a6e96d54590e4e20df0c1e6e7478e3 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 diff --git a/src/lib_protocol_environment/dune b/src/lib_protocol_environment/dune index cd5be010896c06a4c6709b66dc393ea844fab0b9..7f0f6b50e9ad96b375dc723b4ed4110c13fdfebd 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 652a3d2633716cb9c42d210c6b442227c752b664..9239434a28d41b3aa4baf297f8a22889ceb06c0c 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 ffbaa058e155de1967f8c6a4e71ffdac2750eb5e..a5e6a6c6ff3b35f45cd8135502543050e0bf81b1 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 33785133acf167d76d6a2c42335aae429b7e8a39..cb243adaa87a7942a11b763b9ca5477fd11e6b81 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 0000000000000000000000000000000000000000..678d012f584f879142c4f276cf38300858d6f888 --- /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 d305f7eeed77b3566285aa4600c835769343eb87..3613a738a540b8a2d172f9ba8aed19042b8dbdc2 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 ed2dd05705484a64ee5b00bc3cc6dbfa8aa55e59..0a4c8a98291d13c1b8682ca181e1af07b9135435 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 0000000000000000000000000000000000000000..4259eadc9fb9e2f8e42459cc2c9e535c095d25cd --- /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)