diff --git a/manifest/main.ml b/manifest/main.ml index f7ff3362ff0be40d12ad95984051ae737cd7abbb..68b0d9a3b528ae756728a1c22a3603cf67c461d0 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -1814,6 +1814,7 @@ protocols.|} ringo; ringo_lwt; tezos_base |> open_ ~m:"TzPervasives"; + tezos_crypto_dal; tezos_sapling; tezos_protocol_environment_sigs; tezos_protocol_environment_structs; diff --git a/src/lib_protocol_environment/dune b/src/lib_protocol_environment/dune index 7f0f6b50e9ad96b375dc723b4ed4110c13fdfebd..e29cba5be4f4c11e532c53596844f4050f0afc06 100644 --- a/src/lib_protocol_environment/dune +++ b/src/lib_protocol_environment/dune @@ -13,6 +13,7 @@ ringo ringo-lwt tezos-base + tezos-crypto.dal tezos-sapling tezos-protocol-environment.sigs tezos-protocol-environment.structs diff --git a/src/lib_protocol_environment/environment_V6.ml b/src/lib_protocol_environment/environment_V6.ml index 9239434a28d41b3aa4baf297f8a22889ceb06c0c..b0ef8a6c22f82911827c34ab2bf7cee705e667aa 100644 --- a/src/lib_protocol_environment/environment_V6.ml +++ b/src/lib_protocol_environment/environment_V6.ml @@ -2,7 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) -(* Copyright (c) 2020 Nomadic Labs. *) +(* Copyright (c) 2020-2022 Nomadic Labs. *) (* Copyright (c) 2020 Metastate AG *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) @@ -279,6 +279,49 @@ struct let aggregate_verify = Aug.aggregate_verify end + module Dal_cryptobox = struct + include Tezos_crypto_dal + + module type S = sig + (** Commitment to a polynomial. *) + type commitment + + (** Proof of degree. *) + type proof_degree + + (** Proof of evaluation at multiple points. *) + type proof_multi + + module Encoding : sig + val commitment_encoding : commitment Data_encoding.t + + val proof_degree_encoding : proof_degree Data_encoding.t + + val proof_multi_encoding : proof_multi Data_encoding.t + end + + (** Length of the erasure-encoded slot in terms of scalar elements. *) + val erasure_encoding_length : int + + (** [verify_degree commitment proof n] returns true if and only if the + committed polynomial has degree less than [n]. *) + val verify_degree : + commitment -> + proof_degree -> + int -> + (bool, [> `Degree_exceeds_srs_length of string]) Result.t + + (** [verify_slot_segment cm ~slot_segment ~offset proof] returns true if the + [slot_segment] is correct. *) + val verify_slot_segment : + commitment -> slot_segment:bytes -> offset:int -> proof_multi -> bool + end + + module type Constants = Dal_cryptobox.Params_sig + + module Make (C : Constants) = Dal_cryptobox.Make (C) + end + module Ed25519 = Ed25519 module Secp256k1 = Secp256k1 module P256 = P256 diff --git a/src/lib_protocol_environment/environment_V6.mli b/src/lib_protocol_environment/environment_V6.mli index a5e6a6c6ff3b35f45cd8135502543050e0bf81b1..30d2c2a2f6eb47618eb54040f0d5388c8e9cf0bf 100644 --- a/src/lib_protocol_environment/environment_V6.mli +++ b/src/lib_protocol_environment/environment_V6.mli @@ -2,7 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) -(* Copyright (c) 2021 Nomadic Labs. *) +(* Copyright (c) 2021-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"),*) diff --git a/src/lib_protocol_environment/sigs/v6.in.ml b/src/lib_protocol_environment/sigs/v6.in.ml index 8bca0a4fdd42da7c12159b19ac5f2f4510279f8d..4026009ca937e99aefa5f48ea51d5102d175178c 100644 --- a/src/lib_protocol_environment/sigs/v6.in.ml +++ b/src/lib_protocol_environment/sigs/v6.in.ml @@ -131,4 +131,6 @@ module type T = sig module Wasm_2_0_0 : [%sig "v6/wasm_2_0_0.mli"] [@@coq_plain_module] module Plonk : [%sig "v6/plonk.mli"] [@@coq_plain_module] + + module Dal_cryptobox : [%sig "v6/dal_cryptobox.mli"] [@@coq_plain_module] end diff --git a/src/lib_protocol_environment/sigs/v6/dal_cryptobox.mli b/src/lib_protocol_environment/sigs/v6/dal_cryptobox.mli new file mode 100644 index 0000000000000000000000000000000000000000..f399b0aa0f26a395f416efee44c4d8d89ad77c55 --- /dev/null +++ b/src/lib_protocol_environment/sigs/v6/dal_cryptobox.mli @@ -0,0 +1,77 @@ +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(** The cryptographic primitives for the data availability layer (DAL). *) +module type S = sig + (** Commitment to a polynomial. *) + type commitment + + (** Proof of degree. *) + type proof_degree + + (** Proof of evaluation at multiple points. *) + type proof_multi + + module Encoding : sig + val commitment_encoding : commitment Data_encoding.t + + val proof_degree_encoding : proof_degree Data_encoding.t + + val proof_multi_encoding : proof_multi Data_encoding.t + end + + (** Length of the erasure-encoded slot in terms of scalar elements. *) + val erasure_encoding_length : int + + (** [verify_degree commitment proof n] returns true if and only if the + committed polynomial has degree less than [n]. *) + val verify_degree : + commitment -> + proof_degree -> + int -> + (bool, [> `Degree_exceeds_srs_length of string]) Result.t + + (** [verify_slot_segment cm ~slot_segment ~offset proof] returns true if the + [slot_segment] is correct. *) + val verify_slot_segment : + commitment -> slot_segment:bytes -> offset:int -> proof_multi -> bool +end + +(** Parameters of the DAL relevant to the cryptographic primitives. *) +module type Constants = sig + (** Redundancy factor of the erasure code. *) + val redundancy_factor : int + + (** Size in bytes of a slot. *) + val slot_size : int + + (** Size in bytes of a slot segment. *) + val slot_segment_size : int + + (** Each erasure-encoded slot splits evenly into the given amount of shards. *) + val shards_amount : int +end + +module Make : functor (C : Constants) -> S