From 55df45c358a70dfc2f03197d9256b685271ec088 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Thu, 3 Oct 2024 06:25:25 +0200 Subject: [PATCH 1/2] DAL/Crypto: export verify_shard in VERIFIER --- src/lib_crypto_dal/cryptobox.mli | 66 +++++++++++++++------------- src/lib_crypto_dal/cryptobox_intf.ml | 25 +++++++++++ 2 files changed, 61 insertions(+), 30 deletions(-) diff --git a/src/lib_crypto_dal/cryptobox.mli b/src/lib_crypto_dal/cryptobox.mli index 17f594747de4..34f1bb8e5527 100644 --- a/src/lib_crypto_dal/cryptobox.mli +++ b/src/lib_crypto_dal/cryptobox.mli @@ -60,7 +60,7 @@ open Cryptobox_intf code: we've chosen and implemented a technique to produce the proofs in time [O(n log n)] (see {{: https://eprint.iacr.org/2023/033.pdf}Fast amortized KZG proofs}). - + More diverse details about the formalization are provided here : https://hackmd.io/36XUZUo7QqK5Ub6GvZmgOg *) @@ -114,35 +114,12 @@ type error += Failed_to_load_trusted_setup of string (** [Invalid_precomputation_hash], thrown by {!load_precompute_shards_proofs}. *) type error += Invalid_precomputation_hash of (string, string) error_container -module Verifier : - VERIFIER - with type t = t - and type commitment = commitment - and type commitment_proof = commitment_proof - and type page_proof = page_proof - and type ('a, 'b) error_container = ('a, 'b) error_container - -include - VERIFIER - with type t := t - and type parameters := Dal_config.parameters - and type commitment := commitment - and type commitment_proof := commitment_proof - and type page_proof := page_proof - and type ('a, 'b) error_container := ('a, 'b) error_container - (** The primitives exposed in this modules require some preprocessing. This preprocessing generates data from an unknown secret. For the security of those primitives, it is important that the secret is unknown. *) type initialisation_parameters -module Commitment : sig - include COMMITMENT with type t = commitment - - val rpc_arg : commitment Resto.Arg.t -end - (** A slot is a byte sequence corresponding to some data. *) type slot = bytes @@ -224,13 +201,45 @@ val string_of_commit_error : (** A portion of the data represented by a polynomial. *) type share -(** Encoding of a share. *) -val share_encoding : share Data_encoding.t - (** A shard is share with its index (see {!val:shards_from_polynomial}). *) type shard = {index : int; share : share} +(** A proof that a shard belongs to some commitment. *) +type shard_proof + +module Verifier : + VERIFIER + with type t = t + and type commitment = commitment + and type commitment_proof = commitment_proof + and type page_proof = page_proof + and type ('a, 'b) error_container = ('a, 'b) error_container + and type share = share + and type shard = shard + and type shard_proof = shard_proof + +include + VERIFIER + with type t := t + and type parameters := Dal_config.parameters + and type commitment := commitment + and type commitment_proof := commitment_proof + and type page_proof := page_proof + and type ('a, 'b) error_container := ('a, 'b) error_container + and type share := share + and type shard := shard + and type shard_proof := shard_proof + +module Commitment : sig + include COMMITMENT with type t = commitment + + val rpc_arg : commitment Resto.Arg.t +end + +(** Encoding of a share. *) +val share_encoding : share Data_encoding.t + (** An encoding of a share. *) val shard_encoding : shard Data_encoding.t @@ -278,9 +287,6 @@ val polynomial_from_shards : The shards in the returned sequence have increasing indexes. *) val shards_from_polynomial : t -> polynomial -> shard Seq.t -(** A proof that a shard belongs to some commitment. *) -type shard_proof - (** An encoding of a shard proof. *) val shard_proof_encoding : shard_proof Data_encoding.t diff --git a/src/lib_crypto_dal/cryptobox_intf.ml b/src/lib_crypto_dal/cryptobox_intf.ml index 46338cc16567..2248a25e7053 100644 --- a/src/lib_crypto_dal/cryptobox_intf.ml +++ b/src/lib_crypto_dal/cryptobox_intf.ml @@ -147,4 +147,29 @@ module type VERIFIER = sig | `Page_length_mismatch | `Page_index_out_of_range ] ) Result.t + + type share + + val share_encoding : share Data_encoding.t + + type shard = {index : int; share : share} + + val shard_encoding : shard Data_encoding.t + + type shard_proof + + val shard_proof_encoding : shard_proof Data_encoding.t + + val verify_shard : + t -> + commitment -> + shard -> + shard_proof -> + ( unit, + [> `Invalid_degree_strictly_less_than_expected of + (int, int) error_container + | `Invalid_shard + | `Shard_length_mismatch + | `Shard_index_out_of_range of string ] ) + Result.t end -- GitLab From 13252f7128a8b0c94b950afe0bc49c9ded406c84 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Tue, 19 Nov 2024 15:41:10 +0100 Subject: [PATCH 2/2] Env/DAL: export shard_proof and verify_shard --- .../environment_V14.ml | 4 +++ .../environment_V14.mli | 4 +++ src/lib_protocol_environment/sigs/v14.ml | 26 +++++++++++++++++++ src/lib_protocol_environment/sigs/v14/dal.mli | 26 +++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/src/lib_protocol_environment/environment_V14.ml b/src/lib_protocol_environment/environment_V14.ml index 39dc9de68f3b..a945f1245d12 100644 --- a/src/lib_protocol_environment/environment_V14.ml +++ b/src/lib_protocol_environment/environment_V14.ml @@ -114,6 +114,10 @@ module type T = sig and type Dal.commitment_proof = Tezos_crypto_dal.Cryptobox.Verifier.commitment_proof and type Dal.page_proof = Tezos_crypto_dal.Cryptobox.Verifier.page_proof + and type Dal.share = Tezos_crypto_dal.Cryptobox.Verifier.share + and type Dal.shard = Tezos_crypto_dal.Cryptobox.Verifier.shard + and type Dal.shard_proof = + Tezos_crypto_dal.Cryptobox.Verifier.shard_proof and type Bounded.Non_negative_int32.t = Tezos_base.Bounded.Non_negative_int32.t and type Wasm_2_0_0.version = Tezos_scoru_wasm.Wasm_pvm_state.version diff --git a/src/lib_protocol_environment/environment_V14.mli b/src/lib_protocol_environment/environment_V14.mli index 43977a828e53..ad0ca9325de3 100644 --- a/src/lib_protocol_environment/environment_V14.mli +++ b/src/lib_protocol_environment/environment_V14.mli @@ -114,6 +114,10 @@ module type T = sig and type Dal.commitment_proof = Tezos_crypto_dal.Cryptobox.Verifier.commitment_proof and type Dal.page_proof = Tezos_crypto_dal.Cryptobox.Verifier.page_proof + and type Dal.share = Tezos_crypto_dal.Cryptobox.Verifier.share + and type Dal.shard = Tezos_crypto_dal.Cryptobox.Verifier.shard + and type Dal.shard_proof = + Tezos_crypto_dal.Cryptobox.Verifier.shard_proof and type Bounded.Non_negative_int32.t = Tezos_base.Bounded.Non_negative_int32.t and type Wasm_2_0_0.version = Tezos_scoru_wasm.Wasm_pvm_state.version diff --git a/src/lib_protocol_environment/sigs/v14.ml b/src/lib_protocol_environment/sigs/v14.ml index 02dc213a40f4..1a0c58043a1a 100644 --- a/src/lib_protocol_environment/sigs/v14.ml +++ b/src/lib_protocol_environment/sigs/v14.ml @@ -12360,6 +12360,32 @@ val verify_page : page -> page_proof -> (bool, [> `Segment_index_out_of_range | `Page_length_mismatch]) Result.t + +type share + +val share_encoding : share Data_encoding.t + +type shard = {index : int; share : share} + +val shard_encoding : shard Data_encoding.t + +type shard_proof + +val shard_proof_encoding : shard_proof Data_encoding.t + +type ('a, 'b) error_container + +val verify_shard : + t -> + commitment -> + shard -> + shard_proof -> + ( unit, + [> `Invalid_degree_strictly_less_than_expected of (int, int) error_container + | `Invalid_shard + | `Shard_length_mismatch + | `Shard_index_out_of_range of string ] ) + Result.t end # 138 "v14.in.ml" diff --git a/src/lib_protocol_environment/sigs/v14/dal.mli b/src/lib_protocol_environment/sigs/v14/dal.mli index 649ec4b84938..77014baac50c 100644 --- a/src/lib_protocol_environment/sigs/v14/dal.mli +++ b/src/lib_protocol_environment/sigs/v14/dal.mli @@ -115,3 +115,29 @@ val verify_page : page -> page_proof -> (bool, [> `Segment_index_out_of_range | `Page_length_mismatch]) Result.t + +type share + +val share_encoding : share Data_encoding.t + +type shard = {index : int; share : share} + +val shard_encoding : shard Data_encoding.t + +type shard_proof + +val shard_proof_encoding : shard_proof Data_encoding.t + +type ('a, 'b) error_container + +val verify_shard : + t -> + commitment -> + shard -> + shard_proof -> + ( unit, + [> `Invalid_degree_strictly_less_than_expected of (int, int) error_container + | `Invalid_shard + | `Shard_length_mismatch + | `Shard_index_out_of_range of string ] ) + Result.t -- GitLab