From e3c58244d609df4ad58768f6664f394b407b78ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Thu, 28 Jul 2022 16:01:15 +0200 Subject: [PATCH] DAL: rename shards_amount -> number_of_shards --- src/bin_dal_node/cryptobox.ml | 4 +-- src/bin_dal_node/slot_manager.ml | 3 +- src/lib_crypto_dal/dal_cryptobox.ml | 30 +++++++++---------- src/lib_crypto_dal/dal_cryptobox_intf.ml | 2 +- src/lib_crypto_dal/test/test_dal_cryptobox.ml | 8 ++--- src/lib_protocol_environment/sigs/v7.ml | 2 +- src/lib_protocol_environment/sigs/v7/dal.mli | 2 +- tezt/lib_tezos/rollup.ml | 6 +--- 8 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/bin_dal_node/cryptobox.ml b/src/bin_dal_node/cryptobox.ml index a01b74b51d8d..a1770b7bbcb7 100644 --- a/src/bin_dal_node/cryptobox.ml +++ b/src/bin_dal_node/cryptobox.ml @@ -31,7 +31,7 @@ module Constants = struct let slot_size = 1048576 (* 1Mb *) - let shards_amount = 2048 + let number_of_shards = 2048 let trusted_setup_logarithm_size = 21 end @@ -46,4 +46,4 @@ let slot_header_encoding = Commitment.encoding let init () = let open Constants in - make ~redundancy_factor ~segment_size ~slot_size ~shards_amount + make ~redundancy_factor ~segment_size ~slot_size ~number_of_shards diff --git a/src/bin_dal_node/slot_manager.ml b/src/bin_dal_node/slot_manager.ml index ca14e0066e6a..45b648dd17cf 100644 --- a/src/bin_dal_node/slot_manager.ml +++ b/src/bin_dal_node/slot_manager.ml @@ -149,7 +149,8 @@ let get_shard store slot_header shard_id = let check_shards shards = let open Result_syntax in if shards = [] then fail [Slot_not_found] - else if Compare.List_length_with.(shards = Cryptobox.Constants.shards_amount) + else if + Compare.List_length_with.(shards = Cryptobox.Constants.number_of_shards) then Ok () else fail [Missing_shards] diff --git a/src/lib_crypto_dal/dal_cryptobox.ml b/src/lib_crypto_dal/dal_cryptobox.ml index 492b82225c8a..94a8725710b7 100644 --- a/src/lib_crypto_dal/dal_cryptobox.ml +++ b/src/lib_crypto_dal/dal_cryptobox.ml @@ -231,7 +231,7 @@ module Inner = struct redundancy_factor : int; slot_size : int; segment_size : int; - shards_amount : int; + number_of_shards : int; k : int; n : int; (* k and n are the parameters of the erasure code. *) @@ -273,15 +273,15 @@ module Inner = struct (* n must be at most 2^32, the biggest subgroup of 2^i roots of unity in the multiplicative group of Fr, because the FFTs operate on such groups. *) invalid_arg "Wrong computed size for n" - else if not (is_pow_of_two t.shards_amount && t.n > t.shards_amount) then - invalid_arg "Shards not containing at least two elements" + else if not (is_pow_of_two t.number_of_shards && t.n > t.number_of_shards) + then invalid_arg "Shards not containing at least two elements" else () (* Shards must contain at least two elements. *) - let make ~redundancy_factor ~slot_size ~segment_size ~shards_amount = + let make ~redundancy_factor ~slot_size ~segment_size ~number_of_shards = let k = 1 lsl Z.(log2up (of_int slot_size / of_int scalar_bytes_amount)) in let n = redundancy_factor * k in - let shard_size = n / shards_amount in + let shard_size = n / number_of_shards in let evaluations_log = Z.(log2 (of_int n)) in let evaluations_per_proof_log = Z.(log2 (of_int shard_size)) in let t = @@ -289,7 +289,7 @@ module Inner = struct redundancy_factor; slot_size; segment_size; - shards_amount; + number_of_shards; k; n; domain_k = make_domain k; @@ -592,14 +592,14 @@ module Inner = struct amortized. *) let shards_from_polynomial t p = let codeword = encode t p in - let len_shard = t.n / t.shards_amount in + let len_shard = t.n / t.number_of_shards in let rec loop i map = match i with - | i when i = t.shards_amount -> map + | i when i = t.number_of_shards -> map | _ -> let shard = Array.init len_shard (fun _ -> Scalar.(copy zero)) in for j = 0 to len_shard - 1 do - shard.(j) <- codeword.((t.shards_amount * j) + i) + shard.(j) <- codeword.((t.number_of_shards * j) + i) done ; loop (i + 1) (IntMap.add i shard map) in @@ -621,7 +621,7 @@ module Inner = struct | j when j = Array.length arr -> Ok () | _ -> ( let c_i = arr.(j) in - let z_i = (t.shards_amount * j) + z_i in + let z_i = (t.number_of_shards * j) + z_i in let x_i = Scalar.pow w (Z.of_int z_i) in let tmp = Evaluations.get eval_a' z_i in Scalar.mul_inplace tmp tmp x_i ; @@ -648,14 +648,14 @@ module Inner = struct else (* 1. Computing A(x) = prod_{i=0}^{k-1} (x - w^{z_i}). Let w be a primitive nth root of unity and - Ω_0 = {w^{shards_amount j}}_{j=0 to (n/shards_amount)-1} - be the (n/shards_amount)-th roots of unity and Ω_i = w^i Ω_0. + Ω_0 = {w^{number_of_shards j}}_{j=0 to (n/number_of_shards)-1} + be the (n/number_of_shards)-th roots of unity and Ω_i = w^i Ω_0. Together, the Ω_i's form a partition of the subgroup of the n-th roots - of unity: 𝕌_n = disjoint union_{i ∈ {0, ..., shards_amount-1}} Ω_i. + of unity: 𝕌_n = disjoint union_{i ∈ {0, ..., number_of_shards-1}} Ω_i. Let Z_j := Prod_{w ∈ Ω_j} (x − w). For a random set of shards - S⊆{0, ..., shards_amount-1} of length k/shard_size, we reorganize the + S⊆{0, ..., number_of_shards-1} of length k/shard_size, we reorganize the product A(x) = Prod_{i=0}^{k-1} (x − w^{z_i}) into A(x) = Prod_{j ∈ S} Z_j. @@ -667,7 +667,7 @@ module Inner = struct when using other ways of grouping the z_i's into shards. This also reduces the depth of the recursion tree of the poly_mul - function from log(k) to log(shards_amounts), so that the decoding time + function from log(k) to log(number_of_shards), so that the decoding time reduces from O(k*log^2(k) + n*log(n)) to O(n*log(n)). *) let factors = IntMap.bindings shards diff --git a/src/lib_crypto_dal/dal_cryptobox_intf.ml b/src/lib_crypto_dal/dal_cryptobox_intf.ml index 0b4f33b3c19f..73005e70edd1 100644 --- a/src/lib_crypto_dal/dal_cryptobox_intf.ml +++ b/src/lib_crypto_dal/dal_cryptobox_intf.ml @@ -54,7 +54,7 @@ module type VERIFIER = sig redundancy_factor:int -> slot_size:int -> segment_size:int -> - shards_amount:int -> + number_of_shards:int -> t (** A trusted setup. Namely Structured Reference String. diff --git a/src/lib_crypto_dal/test/test_dal_cryptobox.ml b/src/lib_crypto_dal/test/test_dal_cryptobox.ml index 05f2084fe706..e08a177d1d8b 100644 --- a/src/lib_crypto_dal/test/test_dal_cryptobox.ml +++ b/src/lib_crypto_dal/test/test_dal_cryptobox.ml @@ -25,7 +25,7 @@ module Test = struct (* Encoding and decoding of Reed-Solomon codes on the erasure channel. *) let bench_DAL_crypto_params () = (* We take mainnet parameters we divide by [16] to speed up the test. *) - let shards_amount = 2048 / 16 in + let number_of_shards = 2048 / 16 in let slot_size = 1048576 / 16 in let segment_size = 4096 / 16 in let msg_size = slot_size in @@ -41,7 +41,7 @@ module Test = struct ~redundancy_factor ~slot_size ~segment_size - ~shards_amount + ~number_of_shards in let trusted_setup = Dal_cryptobox.srs t @@ -67,8 +67,8 @@ module Test = struct (* Only take half of the buckets *) let c_indices = random_indices - (shards_amount - 1) - (shards_amount / redundancy_factor) + (number_of_shards - 1) + (number_of_shards / redundancy_factor) |> Array.of_list in diff --git a/src/lib_protocol_environment/sigs/v7.ml b/src/lib_protocol_environment/sigs/v7.ml index 70404eb979ff..7117c2904784 100644 --- a/src/lib_protocol_environment/sigs/v7.ml +++ b/src/lib_protocol_environment/sigs/v7.ml @@ -11308,7 +11308,7 @@ val make : redundancy_factor:int -> slot_size:int -> segment_size:int -> - shards_amount:int -> + number_of_shards:int -> t (** A trusted setup. Namely Structured Reference String. diff --git a/src/lib_protocol_environment/sigs/v7/dal.mli b/src/lib_protocol_environment/sigs/v7/dal.mli index ca5a8a9ed6b1..008cc82a163c 100644 --- a/src/lib_protocol_environment/sigs/v7/dal.mli +++ b/src/lib_protocol_environment/sigs/v7/dal.mli @@ -32,7 +32,7 @@ val make : redundancy_factor:int -> slot_size:int -> segment_size:int -> - shards_amount:int -> + number_of_shards:int -> t (** A trusted setup. Namely Structured Reference String. diff --git a/tezt/lib_tezos/rollup.ml b/tezt/lib_tezos/rollup.ml index 0dff4343aef7..2274ef57b47a 100644 --- a/tezt/lib_tezos/rollup.ml +++ b/tezt/lib_tezos/rollup.ml @@ -534,11 +534,7 @@ module Dal = struct 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 + Cryptobox.make ~redundancy_factor ~slot_size ~segment_size ~number_of_shards let load_srs ?(unsafe = false) t = if unsafe then Cryptobox.srs t -- GitLab