From 46d053fdb392d6be076bf815c659d62afcc7765d Mon Sep 17 00:00:00 2001 From: Marco Stronati Date: Wed, 6 Jun 2018 23:53:45 +0200 Subject: [PATCH] Alpha: add Seed_repr.deterministic_seed --- src/proto_alpha/lib_protocol/src/seed_repr.ml | 8 ++++---- src/proto_alpha/lib_protocol/src/seed_repr.mli | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/src/seed_repr.ml b/src/proto_alpha/lib_protocol/src/seed_repr.ml index 4c433d6d5..674658216 100644 --- a/src/proto_alpha/lib_protocol/src/seed_repr.ml +++ b/src/proto_alpha/lib_protocol/src/seed_repr.ml @@ -91,12 +91,13 @@ let check_hash nonce hash = let nonce_hash_key_part = Nonce_hash.to_path -let initial_nonce_0 = - MBytes.of_string (String.make Constants_repr.nonce_length '\000') +let initial_nonce_0 = zero_bytes let initial_nonce_hash_0 = hash initial_nonce_0 +let deterministic_seed seed = nonce seed zero_bytes + let initial_seeds n = let rec loop acc elt i = if Compare.Int.(i = 1) then @@ -104,7 +105,6 @@ let initial_seeds n = else loop (elt :: acc) - (nonce elt - (MBytes.of_string (String.make Constants_repr.nonce_length '\000'))) + (deterministic_seed elt) (i-1) in loop [] (B (State_hash.hash_bytes [])) n diff --git a/src/proto_alpha/lib_protocol/src/seed_repr.mli b/src/proto_alpha/lib_protocol/src/seed_repr.mli index 4d7b8e91b..70001747c 100644 --- a/src/proto_alpha/lib_protocol/src/seed_repr.mli +++ b/src/proto_alpha/lib_protocol/src/seed_repr.mli @@ -44,6 +44,9 @@ val take_int32 : sequence -> int32 -> int32 * sequence val empty : seed +(** Returns a new seed by hashing the one passed with a constant. *) +val deterministic_seed : seed -> seed + (** [intial_seeds n] generates the first [n] seeds for which there are no nonces. The first seed is a constant value. The kth seed is the hash of seed (k-1) concatenated with a constant. *)