diff --git a/.gitlab/ci/opam-ci.yml b/.gitlab/ci/opam-ci.yml index cd86670dbc6cc8e98324aa8249e4844c6a903c0c..27805a34a7823038258739e114803d853fe7f2ff 100644 --- a/.gitlab/ci/opam-ci.yml +++ b/.gitlab/ci/opam-ci.yml @@ -689,10 +689,17 @@ opam:tezos-context-ops: opam:tezos-crypto: extends: - .opam_template - - .rules_template__trigger_opam_batch_6 + - .rules_template__trigger_opam_batch_7 variables: package: tezos-crypto +opam:tezos-crypto-dal: + extends: + - .opam_template + - .rules_template__trigger_opam_batch_6 + variables: + package: tezos-crypto-dal + opam:tezos-dal-alpha: extends: - .opam_template diff --git a/dune-project b/dune-project index 728b1041f417e521d0de52e128a699cfc0882bdb..48a349b6356871491524efdfddf587c27d5c5a95 100644 --- a/dune-project +++ b/dune-project @@ -66,6 +66,7 @@ (package (name tezos-context)) (package (name tezos-context-ops)) (package (name tezos-crypto)) +(package (name tezos-crypto-dal)) (package (name tezos-dal-alpha)) (package (name tezos-dal-node)) (package (name tezos-embedded-protocol-000-Ps9mPmXa)) diff --git a/manifest/main.ml b/manifest/main.ml index c0c6e7ad21166615e0914e85f475224658ca3e28..890be06c7b03e42867ea9946d3a7c0d16510d5d3 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -823,6 +823,38 @@ let _octez_crypto_tests_unix = octez_test_helpers; ] +let octez_crypto_dal = + public_lib + "tezos-crypto-dal" + ~path:"src/lib_crypto_dal" + ~synopsis:"DAL cryptographic primitives" + ~opam:"tezos-crypto-dal" + ~deps: + [ + octez_stdlib |> open_; + octez_error_monad |> open_; + data_encoding |> open_; + octez_crypto; + bls12_381_polynomial; + ] + +let _octez_crypto_dal_tests = + tests + ["test_dal_cryptobox"] + ~path:"src/lib_crypto_dal/test" + ~opam:"tezos-crypto-dal" + ~dep_files:["shard_proofs_precomp"] + ~deps: + [ + octez_stdlib |> open_; + octez_crypto_dal |> open_; + octez_error_monad |> open_; + data_encoding |> open_; + alcotest; + qcheck_alcotest; + bls12_381_polynomial; + ] + let octez_event_logging = public_lib "tezos-event-logging" @@ -1784,6 +1816,7 @@ protocols.|} zarith_stubs_js; bls12_381; plonk; + octez_crypto_dal; vdf; ringo; ringo_lwt; @@ -2841,6 +2874,7 @@ let tezt_tezos = tezt_performance_regression |> open_; uri; hex; + octez_crypto_dal; octez_base; octez_base_unix; cohttp_lwt_unix; @@ -5127,36 +5161,6 @@ let _octez_codec = ]) ~linkall:true -let octez_crypto_dal = - public_lib - "tezos-crypto.dal" - ~path:"src/lib_crypto/dal" - ~opam:"tezos-crypto" - ~deps: - [ - octez_stdlib |> open_; - octez_error_monad |> open_; - data_encoding |> open_; - bls12_381_polynomial; - ] - -let _octez_crypto_dal_tests = - tests - ["test_dal_cryptobox"] - ~path:"src/lib_crypto/dal/test" - ~opam:"tezos-crypto" - ~dep_files:["shard_proofs_precomp"] - ~deps: - [ - octez_stdlib |> open_; - octez_crypto_dal |> open_; - octez_error_monad |> open_; - data_encoding |> open_; - alcotest; - qcheck_alcotest; - bls12_381_polynomial; - ] - let _octez_proxy_server = public_exe "tezos-proxy-server" @@ -5393,6 +5397,7 @@ let () = bls12_381; tezt_tezos |> open_ |> open_ ~m:"Runnable.Syntax"; data_encoding; + octez_crypto_dal; octez_base; octez_base_unix; octez_stdlib_unix; diff --git a/opam/tezos-crypto-dal.opam b/opam/tezos-crypto-dal.opam new file mode 100644 index 0000000000000000000000000000000000000000..7ea531f131fa91ee3ada205f52facecc3b16ea02 --- /dev/null +++ b/opam/tezos-crypto-dal.opam @@ -0,0 +1,25 @@ +# This file was automatically generated, do not edit. +# Edit file manifest/main.ml instead. +opam-version: "2.0" +maintainer: "contact@tezos.com" +authors: ["Tezos devteam"] +homepage: "https://www.tezos.com/" +bug-reports: "https://gitlab.com/tezos/tezos/issues" +dev-repo: "git+https://gitlab.com/tezos/tezos.git" +license: "MIT" +depends: [ + "dune" { >= "3.0" } + "tezos-stdlib" + "tezos-error-monad" + "data-encoding" { >= "0.6" & < "0.7" } + "tezos-crypto" + "tezos-bls12-381-polynomial" { >= "0.1.0" } + "alcotest" { with-test & >= "1.5.0" } + "qcheck-alcotest" { with-test & >= "0.18" } +] +build: [ + ["rm" "-r" "vendors"] + ["dune" "build" "-p" name "-j" jobs] + ["dune" "runtest" "-p" name "-j" jobs] {with-test} +] +synopsis: "DAL cryptographic primitives" diff --git a/opam/tezos-crypto.opam b/opam/tezos-crypto.opam index 70f7f41fc38cb75fe3fd6f2db8ba34d76c8ff95a..6cf18d6e0671169b9a57a2c8a65032c8f270a2dd 100644 --- a/opam/tezos-crypto.opam +++ b/opam/tezos-crypto.opam @@ -25,7 +25,6 @@ depends: [ "qcheck-alcotest" { with-test & >= "0.18" } "tezos-test-helpers" {with-test} "alcotest-lwt" { with-test & >= "1.5.0" } - "tezos-bls12-381-polynomial" { >= "0.1.0" } ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-dal-node.opam b/opam/tezos-dal-node.opam index 429ae43c0e999ba0a0a23f875ecbc1b9115b4f5f..a3d2f19795350de6c3d4b43fc3a031393f27fef4 100644 --- a/opam/tezos-dal-node.opam +++ b/opam/tezos-dal-node.opam @@ -18,7 +18,7 @@ depends: [ "tezos-rpc-http-client-unix" "tezos-stdlib-unix" "tezos-stdlib" - "tezos-crypto" + "tezos-crypto-dal" "irmin-pack" { >= "3.3.1" & < "3.4.0" } "irmin" { >= "3.3.2" & < "3.4.0" } ] diff --git a/opam/tezos-protocol-environment.opam b/opam/tezos-protocol-environment.opam index b1fe49eda5443e4b007761859af91c8d4de1cd6c..43a55f3f61059923937eb90a65498b008a5ba11d 100644 --- a/opam/tezos-protocol-environment.opam +++ b/opam/tezos-protocol-environment.opam @@ -19,6 +19,7 @@ depends: [ "tezos-plonk" { >= "0.1.0" } "zarith" { >= "1.12" & < "1.13" } "zarith_stubs_js" + "tezos-crypto-dal" "class_group_vdf" { >= "0.0.4" } "ringo" { >= "0.9" } "ringo-lwt" { >= "0.9" } diff --git a/opam/tezt-tezos.opam b/opam/tezt-tezos.opam index 89923cce247731287496479f2f717ec19261b581..ba05704ff23e968da25385fc3406dbfafe4f032d 100644 --- a/opam/tezt-tezos.opam +++ b/opam/tezt-tezos.opam @@ -13,6 +13,7 @@ depends: [ "tezt-performance-regression" "uri" { >= "2.2.0" } "hex" { >= "1.3.0" } + "tezos-crypto-dal" "tezos-base" "cohttp-lwt-unix" { >= "2.2.0" } ] diff --git a/src/bin_dal_node/cryptobox.ml b/src/bin_dal_node/cryptobox.ml index 033463498769ddc32483c3f896b6d3360839b748..a01b74b51d8d0b955e9ecffbd7b6d4977528eb3f 100644 --- a/src/bin_dal_node/cryptobox.ml +++ b/src/bin_dal_node/cryptobox.ml @@ -42,7 +42,7 @@ type slot = bytes type slot_header = commitment -let slot_header_encoding = commitment_encoding +let slot_header_encoding = Commitment.encoding let init () = let open Constants in diff --git a/src/bin_dal_node/dune b/src/bin_dal_node/dune index 6bbb7041e362e81d8dcb7cf0638e899b7cca5d6a..1578f7fff3aadbe5231b9ce74c5dd6204467a84f 100644 --- a/src/bin_dal_node/dune +++ b/src/bin_dal_node/dune @@ -17,7 +17,7 @@ tezos-rpc-http-client-unix tezos-stdlib-unix tezos-stdlib - tezos-crypto.dal + tezos-crypto-dal irmin-pack irmin-pack.unix irmin) diff --git a/src/bin_dal_node/services.ml b/src/bin_dal_node/services.ml index f7ebda6dc9334363ef5a0950bf2245951015d9cf..4ef79c77c6a1eacb84d4d31fa303bcfab2d87ad5 100644 --- a/src/bin_dal_node/services.ml +++ b/src/bin_dal_node/services.ml @@ -49,8 +49,7 @@ let slot () = ~description:"Show content of a slot" ~query:slot_query ~output:Data_encoding.string - RPC_path.( - open_root / "slot" / "content" /: Slot_manager.Slot_header.rpc_arg) + RPC_path.(open_root / "slot" / "content" /: Cryptobox.Commitment.rpc_arg) let shard () = let shard_arg = RPC_arg.int in @@ -58,15 +57,14 @@ let shard () = ~description:"Fetch shard as bytes" ~query:RPC_query.empty ~output:Cryptobox.shard_encoding - RPC_path.( - open_root / "shard" /: Slot_manager.Slot_header.rpc_arg /: shard_arg) + RPC_path.(open_root / "shard" /: Cryptobox.Commitment.rpc_arg /: shard_arg) let handle_split_slot dal_constants srs store fill slot = let open Lwt_result_syntax in let slot = String.to_bytes slot in let slot = if fill then Slot_manager.Utils.fill_x00 slot else slot in let+ commitment = Slot_manager.split_and_store dal_constants srs store slot in - Slot_manager.Slot_header.to_b58check commitment + Cryptobox.Commitment.to_b58check commitment let handle_slot dal_constants store (_, commitment) trim () = let open Lwt_result_syntax in diff --git a/src/bin_dal_node/slot_manager.ml b/src/bin_dal_node/slot_manager.ml index a05dd2d21fad53321e9d1c69c56e2e29d9f29e42..ca14e0066e6a1de75131588e624d9b5b9eb80f47 100644 --- a/src/bin_dal_node/slot_manager.ml +++ b/src/bin_dal_node/slot_manager.ml @@ -94,48 +94,6 @@ let wrap_encoding_error = let encode enc v = Data_encoding.Binary.to_string enc v |> wrap_encoding_error -module Slot_header = struct - type t = Cryptobox.commitment - - type Base58.data += Data of t - - let to_string commitment = - Cryptobox.commitment_to_bytes commitment |> Bytes.to_string - - let of_string_opt str = - Cryptobox.commitment_of_bytes_opt (String.to_bytes str) - - let b58check_encoding = - Base58.register_encoding - ~prefix:Base58.Prefix.slot_header - ~length:Cryptobox.commitment_size - ~to_raw:to_string - ~of_raw:of_string_opt - ~wrap:(fun x -> Data x) - - let name = "slot_header_encoding" - - let to_b58check c = Base58.simple_encode b58check_encoding c - - let of_b58check_opt b = Base58.simple_decode b58check_encoding b - - let rpc_arg = - RPC_arg.make - ~name - ~descr:(Format.asprintf "%s (Base58Check-encoded)" name) - ~destruct:(fun s -> - match of_b58check_opt s with - | None -> - Error - (Format.asprintf - "failed to decode Base58Check-encoded data (%s): %S" - name - s) - | Some v -> Ok v) - ~construct:to_b58check - () -end - let share_path slot_header shard_id = [slot_header; string_of_int shard_id] let decode_share s = @@ -145,7 +103,7 @@ let decode_share s = let save store slot_header shards = let open Lwt_result_syntax in - let slot_header = Slot_header.to_b58check slot_header in + let slot_header = Cryptobox.Commitment.to_b58check slot_header in Cryptobox.IntMap.iter_es (fun i share -> let path = share_path slot_header i in @@ -197,7 +155,7 @@ let check_shards shards = let get_slot cb_constants store slot_header = let open Lwt_result_syntax in - let slot_header = Slot_header.to_b58check slot_header in + let slot_header = Cryptobox.Commitment.to_b58check slot_header in let*! shards = Store.list store [slot_header] in let*? () = check_shards shards in let* shards = diff --git a/src/bin_dal_node/slot_manager.mli b/src/bin_dal_node/slot_manager.mli index c7d9b13031290a5d94552f97dabd0ae3df59df4b..24deff4058bb7cedc8ae521663ece2eea7c3bb39 100644 --- a/src/bin_dal_node/slot_manager.mli +++ b/src/bin_dal_node/slot_manager.mli @@ -53,16 +53,6 @@ val get_slot : Cryptobox.slot_header -> Cryptobox.slot tzresult Lwt.t -module Slot_header : sig - type t = Cryptobox.commitment - - val to_b58check : t -> string - - val of_b58check_opt : string -> t option - - val rpc_arg : t RPC_arg.t -end - module Utils : sig (** [trim_x00 b] removes trailing '\000' at the end of a [b] and returns a new [bytes]. This function in needed to debug the fetching a slot and remove diff --git a/src/lib_crypto/dal/dal_cryptobox.ml b/src/lib_crypto_dal/dal_cryptobox.ml similarity index 95% rename from src/lib_crypto/dal/dal_cryptobox.ml rename to src/lib_crypto_dal/dal_cryptobox.ml index d9b70d27b60f5e89b5448312f3ec51ffc6bdc338..492b82225c8a3f5038dc784591a052cb6dd48f9f 100644 --- a/src/lib_crypto/dal/dal_cryptobox.ml +++ b/src/lib_crypto_dal/dal_cryptobox.ml @@ -25,6 +25,7 @@ open Error_monad include Dal_cryptobox_intf +module Base58 = Tezos_crypto.Base58 type error += | Failed_to_load_trusted_setup of string @@ -120,15 +121,6 @@ module Inner = struct Bls12_381.G1.of_compressed_bytes_exn bytes - let commitment_to_bytes = Bls12_381.G1.to_compressed_bytes - - let commitment_of_bytes_opt = Bls12_381.G1.of_compressed_bytes_opt - - (* We divide by two because we use the compressed representation. *) - let commitment_size = Bls12_381.G1.size_in_bytes / 2 - - let commitment_encoding = g1_encoding - let _proof_shards_encoding = g1_encoding let commitment_proof_encoding = g1_encoding @@ -157,6 +149,74 @@ module Inner = struct include Encoding + module Commitment = struct + type t = commitment + + type Base58.data += Data of t + + let zero = Bls12_381.G1.zero + + let commitment_to_bytes = Bls12_381.G1.to_compressed_bytes + + let commitment_of_bytes_opt = Bls12_381.G1.of_compressed_bytes_opt + + let commitment_of_bytes_exn bytes = + match Bls12_381.G1.of_compressed_bytes_opt bytes with + | None -> + Format.kasprintf Stdlib.failwith "Unexpected data (DAL commitment)" + | Some commitment -> commitment + + (* We divide by two because we use the compressed representation. *) + let commitment_size = Bls12_381.G1.size_in_bytes / 2 + + let to_string commitment = commitment_to_bytes commitment |> Bytes.to_string + + let of_string_opt str = commitment_of_bytes_opt (String.to_bytes str) + + let b58check_encoding = + Base58.register_encoding + ~prefix:Base58.Prefix.slot_header + ~length:commitment_size + ~to_raw:to_string + ~of_raw:of_string_opt + ~wrap:(fun x -> Data x) + + let raw_encoding = + let open Data_encoding in + conv + commitment_to_bytes + commitment_of_bytes_exn + (Fixed.bytes commitment_size) + + include Tezos_crypto.Helpers.Make (struct + type t = commitment + + let name = "DAL_commitment" + + let title = "Commitment representation for the DAL" + + let b58check_encoding = b58check_encoding + + let raw_encoding = raw_encoding + + let compare = compare + + let equal = ( = ) + + let hash _ = + (* The commitment is not hashed. This is ensured by the + function exposed. We only need the Base58 encoding and the + rpc_arg. *) + assert false + + let seeded_hash _ _ = + (* Same argument. *) + assert false + end) + end + + include Commitment + (* Number of bytes fitting in a Scalar.t. Since scalars are integer modulo r~2^255, we restrict ourselves to 248-bit integers (31 bytes). *) let scalar_bytes_amount = Scalar.size_in_bytes - 1 diff --git a/src/lib_crypto/dal/dal_cryptobox.mli b/src/lib_crypto_dal/dal_cryptobox.mli similarity index 96% rename from src/lib_crypto/dal/dal_cryptobox.mli rename to src/lib_crypto_dal/dal_cryptobox.mli index c3ad1746cb5a51f789e465e24c28f2b743832478..0d80fb5bcf4a1b5213b5567c583fb2a41c81072c 100644 --- a/src/lib_crypto/dal/dal_cryptobox.mli +++ b/src/lib_crypto_dal/dal_cryptobox.mli @@ -29,15 +29,6 @@ open Dal_cryptobox_intf by this module. *) type t -(** [make] precomputes the set of values needed by cryptographic primitives - defined in this module and store them in a value of type [t] *) -val make : - redundancy_factor:int -> - slot_size:int -> - segment_size:int -> - shards_amount:int -> - t - (** A trusted setup. *) type srs @@ -65,6 +56,17 @@ module Verifier : VERIFIER include VERIFIER with type srs := srs and type t := t +(** FIXME https://gitlab.com/tezos/tezos/-/issues/3390 + + This is unsafe but can be used for testing. *) +val srs : t -> srs + +module Commitment : sig + include Dal_cryptobox_intf.COMMITMENT with type t = commitment + + val rpc_arg : commitment Resto.Arg.t +end + module IntMap : Tezos_error_monad.TzLwtreslib.Map.S with type key = int (** A slot is just some data represented as bytes. *) diff --git a/src/lib_crypto/dal/dal_cryptobox_intf.ml b/src/lib_crypto_dal/dal_cryptobox_intf.ml similarity index 76% rename from src/lib_crypto/dal/dal_cryptobox_intf.ml rename to src/lib_crypto_dal/dal_cryptobox_intf.ml index 61ab4de7bf79a5dd419515686027e1765c877598..0b4f33b3c19f374cc056bb2b81e14c81b2fd88be 100644 --- a/src/lib_crypto/dal/dal_cryptobox_intf.ml +++ b/src/lib_crypto_dal/dal_cryptobox_intf.ml @@ -23,21 +23,52 @@ (* *) (*****************************************************************************) +module type COMMITMENT = sig + (** Commitment to a polynomial. *) + type t + + (** An encoding for a commitment. *) + val encoding : t Data_encoding.t + + (** [commitment_to_b58check commitment] returns a b58 representation + of [commitment]. *) + val to_b58check : t -> string + + (** [commitment_of_b58check_opt bytes] computes a commitment from + its b58 representation. Returns [None] if it is not a valid + representation. *) + val of_b58check_opt : string -> t option + + val pp : Format.formatter -> t -> unit + + val zero : t +end + module type VERIFIER = sig (** A precomputed set of constants *) type t - (** A trusted setup. *) - type srs + (** [make] precomputes the set of values needed by cryptographic primitives + defined in this module and store them in a value of type [t] *) + val make : + redundancy_factor:int -> + slot_size:int -> + segment_size:int -> + shards_amount:int -> + t - (** FIXME https://gitlab.com/tezos/tezos/-/issues/3390 + (** A trusted setup. Namely Structured Reference String. - This is unsafe but can be used for testing. *) - val srs : t -> srs + Those are data necessary to make the cryptographic primitives + secured. In particular, to prevent an attacker to forge two + polynomials with the same commitment. *) + type srs (** [load_srs ()] loads a trusted [srs]. If the [srs] is already loaded, it is given directly. Otherwise, the trusted [srs] is - read from some files. The [srs] depends on the [slot_size] + read from two dedicated files. The function assumes those files + are located in some predetermined directories + UNIX-compatible. The [srs] depends on the [slot_size] parameters. Loading the first time an srs is consequently costly while the other times would be cheap. @@ -49,20 +80,7 @@ module type VERIFIER = sig (** Commitment to a polynomial. *) type commitment - (** An encoding for a commitment. *) - val commitment_encoding : commitment Data_encoding.t - - (** [commitment_to_bytes commitment] returns a byte representation - of [commitment]. *) - val commitment_to_bytes : commitment -> Bytes.t - - (** [commitment_size] is the size in bytes of the commitment. *) - val commitment_size : int - - (** [commitment_of_bytes_opt bytes] computes a commitment from its - bytes representation. Returns [None] if [bytes] is not a valid - representation. *) - val commitment_of_bytes_opt : Bytes.t -> commitment option + module Commitment : COMMITMENT with type t := commitment (** A proof that the polynomial associated to some commitment is bounded by a constant. *) diff --git a/src/lib_crypto/dal/dune b/src/lib_crypto_dal/dune similarity index 88% rename from src/lib_crypto/dal/dune rename to src/lib_crypto_dal/dune index 91de7f5e966c00b9a973d288720b034eec41c07e..b1b79cd046c1a79c36c190d1a82dd169e468c8ac 100644 --- a/src/lib_crypto/dal/dune +++ b/src/lib_crypto_dal/dune @@ -3,12 +3,13 @@ (library (name tezos_crypto_dal) - (public_name tezos-crypto.dal) + (public_name tezos-crypto-dal) (instrumentation (backend bisect_ppx)) (libraries tezos-stdlib tezos-error-monad data-encoding + tezos-crypto tezos-bls12-381-polynomial) (flags (:standard) diff --git a/src/lib_crypto/dal/kate_amortized.ml b/src/lib_crypto_dal/kate_amortized.ml similarity index 100% rename from src/lib_crypto/dal/kate_amortized.ml rename to src/lib_crypto_dal/kate_amortized.ml diff --git a/src/lib_crypto/dal/test/dune b/src/lib_crypto_dal/test/dune similarity index 90% rename from src/lib_crypto/dal/test/dune rename to src/lib_crypto_dal/test/dune index 83857604de0b99906297deabb464039ada9cbbbf..fd5b8f4bb98898dce93de3d610cadf9e5d581b6f 100644 --- a/src/lib_crypto/dal/test/dune +++ b/src/lib_crypto_dal/test/dune @@ -5,7 +5,7 @@ (name test_dal_cryptobox) (libraries tezos-stdlib - tezos-crypto.dal + tezos-crypto-dal tezos-error-monad data-encoding alcotest @@ -20,6 +20,6 @@ (rule (alias runtest) - (package tezos-crypto) + (package tezos-crypto-dal) (deps shard_proofs_precomp) (action (run %{dep:./test_dal_cryptobox.exe}))) diff --git a/src/lib_crypto/dal/test/shard_proofs_precomp b/src/lib_crypto_dal/test/shard_proofs_precomp similarity index 100% rename from src/lib_crypto/dal/test/shard_proofs_precomp rename to src/lib_crypto_dal/test/shard_proofs_precomp diff --git a/src/lib_crypto/dal/test/test_dal_cryptobox.ml b/src/lib_crypto_dal/test/test_dal_cryptobox.ml similarity index 100% rename from src/lib_crypto/dal/test/test_dal_cryptobox.ml rename to src/lib_crypto_dal/test/test_dal_cryptobox.ml diff --git a/src/lib_protocol_environment/dune b/src/lib_protocol_environment/dune index 8f30295b46a24559d5a9acb7b3b03cbd057ca777..b93e69c7d692617445e32a25fefa8e61d57faed1 100644 --- a/src/lib_protocol_environment/dune +++ b/src/lib_protocol_environment/dune @@ -10,6 +10,7 @@ zarith_stubs_js bls12-381 tezos-plonk + tezos-crypto-dal class_group_vdf ringo ringo-lwt diff --git a/src/lib_protocol_environment/environment_V7.ml b/src/lib_protocol_environment/environment_V7.ml index f98b919860b5c3a220b477d1dbb1a78b81c0c3b0..1ed55aee89857a2c7b721496dae95b339c9bc73b 100644 --- a/src/lib_protocol_environment/environment_V7.ml +++ b/src/lib_protocol_environment/environment_V7.ml @@ -1460,4 +1460,5 @@ struct module Equality_witness = Environment_context.Equality_witness module Plonk = Tezos_protocol_environment_structs.V7.Plonk + module Dal = Tezos_crypto_dal.Dal_cryptobox.Verifier end diff --git a/src/lib_protocol_environment/sigs/v7.in.ml b/src/lib_protocol_environment/sigs/v7.in.ml index 17570eac5032b2fab0bb05369ec232f21a0aa58b..2e0def89bbb48346bfa1f1e5cafb1521021d9397 100644 --- a/src/lib_protocol_environment/sigs/v7.in.ml +++ b/src/lib_protocol_environment/sigs/v7.in.ml @@ -130,4 +130,6 @@ module type T = sig module Wasm_2_0_0 : [%sig "v7/wasm_2_0_0.mli"] module Plonk : [%sig "v7/plonk.mli"] + + module Dal : [%sig "v7/dal.mli"] end diff --git a/src/lib_protocol_environment/sigs/v7.ml b/src/lib_protocol_environment/sigs/v7.ml index b970937ad1be8fc60d20c9c756b32751fef4e7e8..6f7caded07fb914604515026a4b227dc8ff030a9 100644 --- a/src/lib_protocol_environment/sigs/v7.ml +++ b/src/lib_protocol_environment/sigs/v7.ml @@ -11271,4 +11271,129 @@ val verify_multi_circuits : end # 132 "v7.in.ml" + + module Dal : sig +# 1 "v7/dal.mli" +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(** A precomputed set of constants *) +type t + +(** [make] precomputes the set of values needed by cryptographic primitives + defined in this module and store them in a value of type [t] *) +val make : + redundancy_factor:int -> + slot_size:int -> + segment_size:int -> + shards_amount:int -> + t + +(** A trusted setup. Namely Structured Reference String. + + Those are data necessary to make the cryptographic primitives + secured. In particular, to prevent an attacker to forge two + polynomials with the same commitment. *) +type srs + +(** [load_srs ()] loads a trusted [srs]. If the [srs] is already + loaded, it is given directly. Otherwise, the trusted [srs] is read + from two dedicated files. The function assumes those files are + located in some predetermined directories UNIX-compatible. The + [srs] depends on the [slot_size] parameters. Loading the first time + an srs is consequently costly while the other times would be cheap. + + We assume the [srs] won't change many times. The shell ensures + that a bounded and small number of [srs] can be loaded at the same + time. *) +val load_srs : t -> srs Error_monad.shell_tzresult + +(** Commitment to a polynomial. *) +type commitment + +module Commitment : sig + (** An encoding for a commitment. *) + val encoding : commitment Data_encoding.t + + (** [commitment_to_b58check commitment] returns a b58 representation + of [commitment]. *) + val to_b58check : commitment -> string + + (** [commitment_of_b58check_opt bytes] computes a commitment from + its b58 representation. Returns [None] if it is not a valid + representation. *) + val of_b58check_opt : string -> commitment option + + val zero : commitment + + val pp : Format.formatter -> commitment -> unit +end + +(** A proof that the polynomial associated to some commitment is + bounded by a constant. *) +type commitment_proof + +(** An encoding for the proof of a commitment. *) +val commitment_proof_encoding : commitment_proof Data_encoding.t + +(** [verify_commitment srs commitment proof] checks whether + [commitment] is a valid [commitment]. In particular, it check + that the size of the data committed via [commitment] do not + exceed [C.slot_size]. The verification time is constant. *) +val verify_commitment : + srs -> + commitment -> + commitment_proof -> + (bool, [> `Degree_exceeds_srs_length of string]) Result.t + +(** The original slot can be split into a list of segments of size + [segment_size]. A segment is consequently encoded as a pair of an + [index] and the content of this segment. *) +type segment = {index : int; content : bytes} + +(** A proof that the evaluation of points of a polynomial is part of + a commitment. *) +type segment_proof + +(** An encoding for the proof of a segment. *) +val segment_proof_encoding : segment_proof Data_encoding.t + +(** [verify_segment t commitment segment segment_proof] returns [Ok + true] if the [proof] certifies that the [slot_segment] is indeed + included in the slot committed with commitment + [comitment]. Returns [Ok false] otherwise. + + Fails if the index of the segment is out of range. *) +val verify_segment : + t -> + srs -> + commitment -> + segment -> + segment_proof -> + (bool, [> `Slot_segment_index_out_of_range]) Result.t +end +# 134 "v7.in.ml" + end diff --git a/src/lib_protocol_environment/sigs/v7/dal.mli b/src/lib_protocol_environment/sigs/v7/dal.mli new file mode 100644 index 0000000000000000000000000000000000000000..ca5a8a9ed6b126a7162f8648c768df9e3b19c7b7 --- /dev/null +++ b/src/lib_protocol_environment/sigs/v7/dal.mli @@ -0,0 +1,119 @@ +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(** A precomputed set of constants *) +type t + +(** [make] precomputes the set of values needed by cryptographic primitives + defined in this module and store them in a value of type [t] *) +val make : + redundancy_factor:int -> + slot_size:int -> + segment_size:int -> + shards_amount:int -> + t + +(** A trusted setup. Namely Structured Reference String. + + Those are data necessary to make the cryptographic primitives + secured. In particular, to prevent an attacker to forge two + polynomials with the same commitment. *) +type srs + +(** [load_srs ()] loads a trusted [srs]. If the [srs] is already + loaded, it is given directly. Otherwise, the trusted [srs] is read + from two dedicated files. The function assumes those files are + located in some predetermined directories UNIX-compatible. The + [srs] depends on the [slot_size] parameters. Loading the first time + an srs is consequently costly while the other times would be cheap. + + We assume the [srs] won't change many times. The shell ensures + that a bounded and small number of [srs] can be loaded at the same + time. *) +val load_srs : t -> srs Error_monad.shell_tzresult + +(** Commitment to a polynomial. *) +type commitment + +module Commitment : sig + (** An encoding for a commitment. *) + val encoding : commitment Data_encoding.t + + (** [commitment_to_b58check commitment] returns a b58 representation + of [commitment]. *) + val to_b58check : commitment -> string + + (** [commitment_of_b58check_opt bytes] computes a commitment from + its b58 representation. Returns [None] if it is not a valid + representation. *) + val of_b58check_opt : string -> commitment option + + val zero : commitment + + val pp : Format.formatter -> commitment -> unit +end + +(** A proof that the polynomial associated to some commitment is + bounded by a constant. *) +type commitment_proof + +(** An encoding for the proof of a commitment. *) +val commitment_proof_encoding : commitment_proof Data_encoding.t + +(** [verify_commitment srs commitment proof] checks whether + [commitment] is a valid [commitment]. In particular, it check + that the size of the data committed via [commitment] do not + exceed [C.slot_size]. The verification time is constant. *) +val verify_commitment : + srs -> + commitment -> + commitment_proof -> + (bool, [> `Degree_exceeds_srs_length of string]) Result.t + +(** The original slot can be split into a list of segments of size + [segment_size]. A segment is consequently encoded as a pair of an + [index] and the content of this segment. *) +type segment = {index : int; content : bytes} + +(** A proof that the evaluation of points of a polynomial is part of + a commitment. *) +type segment_proof + +(** An encoding for the proof of a segment. *) +val segment_proof_encoding : segment_proof Data_encoding.t + +(** [verify_segment t commitment segment segment_proof] returns [Ok + true] if the [proof] certifies that the [slot_segment] is indeed + included in the slot committed with commitment + [comitment]. Returns [Ok false] otherwise. + + Fails if the index of the segment is out of range. *) +val verify_segment : + t -> + srs -> + commitment -> + segment -> + segment_proof -> + (bool, [> `Slot_segment_index_out_of_range]) Result.t diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 6b39500e98bd2732ff6c13863e339e62412e0307..b33e89d3b4c064f67b52638cb57552fce9ae713c 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -66,6 +66,9 @@ let default_dal = number_of_shards = 2048; endorsement_lag = 1; availability_threshold = 50; + slot_size = 1 lsl 20; + redundancy_factor = 16; + segment_size = 4096; } let constants_mainnet = @@ -232,6 +235,9 @@ let default_dal_sandbox = number_of_shards = 256; endorsement_lag = 1; availability_threshold = 50; + slot_size = 1 lsl 16; + redundancy_factor = 4; + segment_size = 4096; } let constants_sandbox = diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 296da2ae1cd3fcebccbd5c73e8592858ee306c1e..bc6330b10b0e854193870a05d16ea7d362486860 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -775,6 +775,9 @@ module Constants : sig number_of_shards : int; endorsement_lag : int; availability_threshold : int; + slot_size : int; + redundancy_factor : int; + segment_size : int; } val dal_encoding : dal Data_encoding.t @@ -2682,11 +2685,9 @@ module Dal : sig module Slot : sig type header - type t = private { - level : Raw_level.t; - index : Slot_index.t; - header : header; - } + type t = {level : Raw_level.t; index : Slot_index.t; header : header} + + val zero : header val encoding : t Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index 5a5515761ba283c88ae4097d840058ad28bbddb3..e955a60bfcc85cccbf1f69a287f35efc1f1377f2 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -31,6 +31,9 @@ type dal = { number_of_shards : int; endorsement_lag : int; availability_threshold : int; + slot_size : int; + redundancy_factor : int; + segment_size : int; } let dal_encoding = @@ -42,30 +45,45 @@ let dal_encoding = number_of_shards; endorsement_lag; availability_threshold; + slot_size; + redundancy_factor; + segment_size; } -> ( feature_enable, number_of_slots, number_of_shards, endorsement_lag, - availability_threshold )) + availability_threshold, + slot_size, + redundancy_factor, + segment_size )) (fun ( feature_enable, number_of_slots, number_of_shards, endorsement_lag, - availability_threshold ) -> + availability_threshold, + slot_size, + redundancy_factor, + segment_size ) -> { feature_enable; number_of_slots; number_of_shards; endorsement_lag; availability_threshold; + slot_size; + redundancy_factor; + segment_size; }) - (obj5 + (obj8 (req "feature_enable" Data_encoding.bool) (req "number_of_slots" Data_encoding.int16) (req "number_of_shards" Data_encoding.int16) (req "endorsement_lag" Data_encoding.int16) - (req "availability_threshold" Data_encoding.int16)) + (req "availability_threshold" Data_encoding.int16) + (req "slot_size" Data_encoding.int31) + (req "redundancy_factor" Data_encoding.uint8) + (req "segment_size" Data_encoding.uint16)) (* The encoded representation of this type is stored in the context as bytes. Changing the encoding, or the value of these constants from diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli index 22d62377f6d4dd00ec301a4c918a7df0b524d7a1..e83485d4a1c316e4d6680febcac796fa50c5d3a5 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -31,6 +31,9 @@ type dal = { number_of_shards : int; endorsement_lag : int; availability_threshold : int; + slot_size : int; + redundancy_factor : int; + segment_size : int; } val dal_encoding : dal Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index da9fece78099ed26694c0663ca6a5740be9736ac..4cbcbf56a6da534807f877235406c65d2f8b1124 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -24,15 +24,16 @@ (*****************************************************************************) module Header = struct - (* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3101 + (* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3389 - Datatype is mocked for the moment while the cryptography is not - provided by the environment. *) - type t = int + It is not clear whether the size of the slot associated to the + commitment should be given here. *) + type t = Dal.commitment - let encoding = Data_encoding.int31 + let encoding = Dal.Commitment.encoding - let pp = Format.pp_print_int + let pp ppf commitment = + Format.fprintf ppf "%s" (Dal.Commitment.to_b58check commitment) end module Index = struct @@ -58,12 +59,12 @@ end type header = Header.t +let zero = Dal.Commitment.zero + type t = {level : Raw_level_repr.t; index : Index.t; header : header} type slot = t -let make ~level ~index ~header = {level; index; header} - let encoding = let open Data_encoding in conv diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index 664eb4149579bb38bb7b6838c4be91501becf880..9d8ce16eed6e0ef86d6ca635e158c8cb1302f0ef 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -84,17 +84,15 @@ end type header = Header.t -type t = private {level : Raw_level_repr.t; index : Index.t; header : header} +type t = {level : Raw_level_repr.t; index : Index.t; header : header} type slot = t -(** [make ~level ~index ~header] builds a slot. *) - -val make : level:Raw_level_repr.t -> index:Index.t -> header:header -> t - (** The encoding ensures the slot is always a non-negative number. *) val encoding : t Data_encoding.t +val zero : header + val pp : Format.formatter -> t -> unit (** Only one slot header is accepted per slot index. If two slots diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index cacaabe67a059f77f539fcb8b0b1ac0f07ef803d..93d9820d163de289775f851bd83de8b78427906c 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -922,6 +922,9 @@ let prepare_first_block ~level ~timestamp ctxt = number_of_shards = 2048; endorsement_lag = 1; availability_threshold = 50; + slot_size = 1 lsl 20; + redundancy_factor = 16; + segment_size = 4096; } in let sc_rollup = diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml index e0b7f60c03abd2a0cc78bada8b0b595896ad0446..3801665430fb158635e024521b47414af282a34f 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml @@ -961,22 +961,10 @@ let mk_sc_rollup_return_bond (oinfos : operation_req) (infos : infos) = sc_rollup let mk_dal_publish_slot_header (oinfos : operation_req) (infos : infos) = - let open Lwt_result_syntax in - let level = 0 in - let index = 0 in - let header = 0 in - let json_slot = - Data_encoding.Json.from_string - (Format.asprintf - {|{"level":%d,"index":%d,"header":%d}|} - level - index - header) - in - let* json_slot = - match json_slot with Error s -> failwith "%s" s | Ok slot -> return slot - in - let slot = Data_encoding.Json.destruct Dal.Slot.encoding json_slot in + let level = Alpha_context.Raw_level.of_int32_exn Int32.zero in + let index = Alpha_context.Dal.Slot_index.zero in + let header = Alpha_context.Dal.Slot.zero in + let slot = Alpha_context.Dal.Slot.{level; index; header} in Op.dal_publish_slot_header ?fee:oinfos.fee ?gas_limit:oinfos.gas_limit diff --git a/tezt/lib_tezos/dune b/tezt/lib_tezos/dune index df971cd47313210e3be068969604f55c7dfdc518..ce24851c8daf30ec88033bfe810ea87d5bc3f518 100644 --- a/tezt/lib_tezos/dune +++ b/tezt/lib_tezos/dune @@ -9,6 +9,7 @@ tezt-performance-regression uri hex + tezos-crypto-dal tezos-base tezos-base.unix cohttp-lwt-unix) diff --git a/tezt/lib_tezos/operation_core.ml b/tezt/lib_tezos/operation_core.ml index 0e098bfaa6fe1726153b65e5ea16c7f429a79fc9..528b838d2a09f31a5bcd38dc72d61f8ea75e7213 100644 --- a/tezt/lib_tezos/operation_core.ml +++ b/tezt/lib_tezos/operation_core.ml @@ -270,6 +270,11 @@ module Manager = struct let json_of_int n = float_of_int n |> Ezjsonm.float + let json_of_commitment commitment = + Data_encoding.Json.construct + Tezos_crypto_dal.Dal_cryptobox.Commitment.encoding + commitment + let get_next_counter ?(source = Constant.bootstrap1) client = let*! json = RPC.Contracts.get_counter @@ -331,7 +336,11 @@ module Manager = struct type payload = | Reveal of Account.key | Transfer of {amount : int; dest : Account.key} - | Dal_publish_slot_header of {level : int; index : int; header : int} + | Dal_publish_slot_header of { + level : int; + index : int; + header : Tezos_crypto_dal.Dal_cryptobox.commitment; + } | Sc_rollup_dal_slot_subscribe of {rollup : string; slot_index : int} | Delegation of {delegate : Account.key} | Sc_rollup_refute of { @@ -381,7 +390,7 @@ module Manager = struct [ ("index", json_of_int index); ("level", json_of_int level); - ("header", json_of_int header); + ("header", json_of_commitment header); ] in [("kind", `String "dal_publish_slot_header"); ("slot", slot)] diff --git a/tezt/lib_tezos/operation_core.mli b/tezt/lib_tezos/operation_core.mli index d8c0a0361eff0af7f50d9e6db7f15ce394f51587..fc90f67e9c26ddf6077cad04f20d0a10e74e4365 100644 --- a/tezt/lib_tezos/operation_core.mli +++ b/tezt/lib_tezos/operation_core.mli @@ -283,7 +283,11 @@ module Manager : sig (** [dal_publish_slot_header ~level ~index ~header] builds an operation for the data-availability layer that publishes a slot. *) - val dal_publish_slot_header : level:int -> index:int -> header:int -> payload + val dal_publish_slot_header : + level:int -> + index:int -> + header:Tezos_crypto_dal.Dal_cryptobox.commitment -> + payload (** [sc_rollup_dal_slot_subscribe ~rollup ~slot_index] builds an operation for the sc rollup [rollup] to subscribe to the data diff --git a/tezt/lib_tezos/rollup.ml b/tezt/lib_tezos/rollup.ml index 9fb2c79f3e59cb213ab04642e9a5afb91bf682f9..0dff4343aef7e532b17fa14ce82ea5170a46da08 100644 --- a/tezt/lib_tezos/rollup.ml +++ b/tezt/lib_tezos/rollup.ml @@ -506,8 +506,76 @@ end module Dal = struct module Parameters = struct + type t = { + number_of_shards : int; + redundancy_factor : int; + slot_size : int; + segment_size : int; + } + let parameter_file protocol = let args = [(["dal_parametric"; "feature_enable"], Some "true")] in Protocol.write_parameter_file ~base:(Either.right (protocol, None)) args + + let from_client client = + let* json = + RPC_legacy.get_constants client + |> Lwt.map (fun json -> JSON.(json |-> "dal_parametric")) + in + let number_of_shards = JSON.(json |-> "number_of_shards" |> as_int) in + let redundancy_factor = JSON.(json |-> "redundancy_factor" |> as_int) in + let slot_size = JSON.(json |-> "slot_size" |> as_int) in + let segment_size = JSON.(json |-> "segment_size" |> as_int) in + return {number_of_shards; redundancy_factor; slot_size; segment_size} + end + + module Cryptobox = Tezos_crypto_dal.Dal_cryptobox + + let make + Parameters.{redundancy_factor; number_of_shards; slot_size; segment_size} + = + Cryptobox.make + ~redundancy_factor + ~slot_size + ~segment_size + ~shards_amount:number_of_shards + + let load_srs ?(unsafe = false) t = + if unsafe then Cryptobox.srs t + else + match Cryptobox.load_srs t with + | Ok srs -> srs + | Error err -> + Test.fail + "Rollup.Dal.load_srs failed: %a" + Tezos_base.TzPervasives.Error_monad.pp_print_trace + err + + module Commitment = struct + let pad n message = + let prefix = String.make n '\000' in + prefix ^ message + + let dummy_commitment + ?(on_error = + fun str -> Test.fail "Rollup.Dal.dummy_commitment failed: %s" str) + parameters t message = + let padding_length = + parameters.Parameters.slot_size - String.length message + in + let padded_message = + if padding_length > 0 then pad padding_length message else message + in + let slot = String.to_bytes padded_message in + (* FIXME + + Use a real srs here. *) + let srs = load_srs ~unsafe:true t in + match Cryptobox.polynomial_from_slot t slot with + | Ok r -> ( + match Cryptobox.commit srs r with + | Ok r -> r + | Error (`Degree_exceeds_srs_length str) -> on_error str) + | Error (`Slot_wrong_size str) -> on_error str end end diff --git a/tezt/lib_tezos/rollup.mli b/tezt/lib_tezos/rollup.mli index 31972dbb855b3cdedc46f49771a8846ae84ad161..db95d5c9fb1fdc2f9ddca46ad7b5807862cb655b 100644 --- a/tezt/lib_tezos/rollup.mli +++ b/tezt/lib_tezos/rollup.mli @@ -216,6 +216,28 @@ end module Dal : sig module Parameters : sig + type t = { + number_of_shards : int; + redundancy_factor : int; + slot_size : int; + segment_size : int; + } + val parameter_file : Protocol.t -> string Lwt.t + + val from_client : Client.t -> t Lwt.t + end + + module Cryptobox = Tezos_crypto_dal.Dal_cryptobox + + val make : Parameters.t -> Cryptobox.t + + module Commitment : sig + val dummy_commitment : + ?on_error:(string -> Cryptobox.commitment) -> + Parameters.t -> + Cryptobox.t -> + string -> + Cryptobox.commitment end end diff --git a/tezt/tests/dal.ml b/tezt/tests/dal.ml index f1be5cefcdc99909194b4391da5ddc44c74d2a5c..08d007ce4ff56daac19187868579db49259a1ce3 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -159,6 +159,11 @@ let test_feature_flag _protocol _sc_rollup_node sc_rollup_address node client = JSON.( protocol_parameters |-> "dal_parametric" |-> "number_of_slots" |> as_int) in + let* parameters = Rollup.Dal.Parameters.from_client client in + let cryptobox = Rollup.Dal.make parameters in + let header = + Rollup.Dal.Commitment.dummy_commitment parameters cryptobox "coucou" + in Check.( (feature_flag = false) bool @@ -175,7 +180,7 @@ let test_feature_flag _protocol _sc_rollup_node sc_rollup_address node client = Operation.Manager.( inject ~force:true - [make @@ dal_publish_slot_header ~index:0 ~level:1 ~header:0] + [make @@ dal_publish_slot_header ~index:0 ~level:1 ~header] client) in let* (`OpHash oph3) = @@ -195,9 +200,11 @@ let test_feature_flag _protocol _sc_rollup_node sc_rollup_address node client = open Tezt_tezos.Rollup.Dal -let publish_slot ~source ?fee ~index node client = +let publish_slot ~source ?fee ~index ~message parameters cryptobox node client = let level = Node.get_level node in - let header = 0 in + let header = + Rollup.Dal.Commitment.dummy_commitment parameters cryptobox message + in Operation.Manager.( inject [make ~source ?fee @@ dal_publish_slot_header ~index ~level ~header] @@ -259,17 +266,51 @@ let test_slot_management_logic = let* node, client = Client.init_with_protocol ~parameter_file `Client ~protocol () in + let* parameters = Rollup.Dal.Parameters.from_client client in + let cryptobox = Rollup.Dal.make parameters in let* (`OpHash oph1) = - publish_slot ~source:Constant.bootstrap1 ~fee:1_000 ~index:0 node client + publish_slot + ~source:Constant.bootstrap1 + ~fee:1_000 + ~index:0 + ~message:"a" + parameters + cryptobox + node + client in let* (`OpHash oph2) = - publish_slot ~source:Constant.bootstrap2 ~fee:1_500 ~index:1 node client + publish_slot + ~source:Constant.bootstrap2 + ~fee:1_500 + ~index:1 + ~message:"b" + parameters + cryptobox + node + client in let* (`OpHash oph3) = - publish_slot ~source:Constant.bootstrap3 ~fee:2_000 ~index:0 node client + publish_slot + ~source:Constant.bootstrap3 + ~fee:2_000 + ~index:0 + ~message:"c" + parameters + cryptobox + node + client in let* (`OpHash oph4) = - publish_slot ~source:Constant.bootstrap4 ~fee:1_200 ~index:1 node client + publish_slot + ~source:Constant.bootstrap4 + ~fee:1_200 + ~index:1 + ~message:"d" + parameters + cryptobox + node + client in let* mempool = Mempool.get_mempool client in let expected_mempool = diff --git a/tezt/tests/dune b/tezt/tests/dune index 12a7af8b092c8906cb0e90662b8dc9deaa155de6..4048aa23e61bd0fb8ed86441be3a024303a9c9f9 100644 --- a/tezt/tests/dune +++ b/tezt/tests/dune @@ -9,6 +9,7 @@ bls12-381 tezt-tezos data-encoding + tezos-crypto-dal tezos-base tezos-base.unix tezos-stdlib-unix diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out index be3cdd737a287c3568da778b221ebb5de2c51950..499600fef375261673b94125744e44cc1e919049 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out @@ -46,8 +46,9 @@ "dal_parametric": { "feature_enable": false, "number_of_slots": 16, "number_of_shards": 256, "endorsement_lag": 1, - "availability_threshold": 50 }, "sc_rollup_enable": false, - "sc_rollup_origination_size": 6314, + "availability_threshold": 50, "slot_size": 65536, + "redundancy_factor": 4, "segment_size": 4096 }, + "sc_rollup_enable": false, "sc_rollup_origination_size": 6314, "sc_rollup_challenge_window_in_blocks": 20160, "sc_rollup_max_number_of_messages_per_commitment_period": 32765, "sc_rollup_stake_amount": "10000000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out index 7721a40b8d0320654fcd561049d7921693b98f16..e662fd0afde5adfc897931d7f8fa81c14d50f3c6 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out @@ -46,8 +46,9 @@ "dal_parametric": { "feature_enable": false, "number_of_slots": 16, "number_of_shards": 256, "endorsement_lag": 1, - "availability_threshold": 50 }, "sc_rollup_enable": false, - "sc_rollup_origination_size": 6314, + "availability_threshold": 50, "slot_size": 65536, + "redundancy_factor": 4, "segment_size": 4096 }, + "sc_rollup_enable": false, "sc_rollup_origination_size": 6314, "sc_rollup_challenge_window_in_blocks": 20160, "sc_rollup_max_number_of_messages_per_commitment_period": 32765, "sc_rollup_stake_amount": "10000000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out index f983510561bdd9a4be9f44cddedfdf25f29e31cd..4dda12289635c2c2589dd4dceec15b198ee46e6b 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out @@ -46,8 +46,9 @@ "dal_parametric": { "feature_enable": false, "number_of_slots": 16, "number_of_shards": 256, "endorsement_lag": 1, - "availability_threshold": 50 }, "sc_rollup_enable": false, - "sc_rollup_origination_size": 6314, + "availability_threshold": 50, "slot_size": 65536, + "redundancy_factor": 4, "segment_size": 4096 }, + "sc_rollup_enable": false, "sc_rollup_origination_size": 6314, "sc_rollup_challenge_window_in_blocks": 20160, "sc_rollup_max_number_of_messages_per_commitment_period": 32765, "sc_rollup_stake_amount": "10000000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out index ff2d2c09aff49ebc8efc7787e7d931e93a282126..20dee1b887f0f80771cfbee663b6ee994503f70d 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out @@ -46,8 +46,9 @@ "dal_parametric": { "feature_enable": false, "number_of_slots": 16, "number_of_shards": 256, "endorsement_lag": 1, - "availability_threshold": 50 }, "sc_rollup_enable": false, - "sc_rollup_origination_size": 6314, + "availability_threshold": 50, "slot_size": 65536, + "redundancy_factor": 4, "segment_size": 4096 }, + "sc_rollup_enable": false, "sc_rollup_origination_size": 6314, "sc_rollup_challenge_window_in_blocks": 20160, "sc_rollup_max_number_of_messages_per_commitment_period": 32765, "sc_rollup_stake_amount": "10000000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out index ff2d2c09aff49ebc8efc7787e7d931e93a282126..20dee1b887f0f80771cfbee663b6ee994503f70d 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out @@ -46,8 +46,9 @@ "dal_parametric": { "feature_enable": false, "number_of_slots": 16, "number_of_shards": 256, "endorsement_lag": 1, - "availability_threshold": 50 }, "sc_rollup_enable": false, - "sc_rollup_origination_size": 6314, + "availability_threshold": 50, "slot_size": 65536, + "redundancy_factor": 4, "segment_size": 4096 }, + "sc_rollup_enable": false, "sc_rollup_origination_size": 6314, "sc_rollup_challenge_window_in_blocks": 20160, "sc_rollup_max_number_of_messages_per_commitment_period": 32765, "sc_rollup_stake_amount": "10000000000", diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- observing the correct handling of commitments in the rollup node (no_comm.out b/tezt/tests/expected/sc_rollup.ml/Alpha- observing the correct handling of commitments in the rollup node (no_comm.out index 47f4ce5a062b4b236eea04ae42a155e88ab0c0dc..35ebefbdf5520c31ed9ddb87d774e7692c0ecf90 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- observing the correct handling of commitments in the rollup node (no_comm.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- observing the correct handling of commitments in the rollup node (no_comm.out @@ -102,8 +102,9 @@ This sequence of operations was run: "dal_parametric": { "feature_enable": false, "number_of_slots": 16, "number_of_shards": 256, "endorsement_lag": 1, - "availability_threshold": 50 }, "sc_rollup_enable": true, - "sc_rollup_origination_size": 6314, + "availability_threshold": 50, "slot_size": 65536, + "redundancy_factor": 4, "segment_size": 4096 }, + "sc_rollup_enable": true, "sc_rollup_origination_size": 6314, "sc_rollup_challenge_window_in_blocks": 1, "sc_rollup_max_number_of_messages_per_commitment_period": 32765, "sc_rollup_stake_amount": "10000000000", @@ -209,8 +210,9 @@ This sequence of operations was run: "dal_parametric": { "feature_enable": false, "number_of_slots": 16, "number_of_shards": 256, "endorsement_lag": 1, - "availability_threshold": 50 }, "sc_rollup_enable": true, - "sc_rollup_origination_size": 6314, + "availability_threshold": 50, "slot_size": 65536, + "redundancy_factor": 4, "segment_size": 4096 }, + "sc_rollup_enable": true, "sc_rollup_origination_size": 6314, "sc_rollup_challenge_window_in_blocks": 1, "sc_rollup_max_number_of_messages_per_commitment_period": 32765, "sc_rollup_stake_amount": "10000000000",