Module Tezos_raw_protocol_006_PsCARTHA__Seed_repr

Tezos Protocol Implementation - Random number generation

This is not expected to be a good cryptographic random number generator. In particular this is supposed to be used in situations where the seed is a globaly known information.

The only expected property is: It should be difficult to find a seed such that the generated sequence is a given one.

Random Generation

type t

The state of the random number generator

type seed

A random seed, to derive random sequences from

type sequence

A random sequence, to derive random values from

val initialize_new : seed -> Tezos_protocol_environment_006_PsCARTHA__Environment.MBytes.t list -> t

initialize_new state ident returns a new generator

val sequence : t -> int32 -> sequence

sequence state n prepares the n-th sequence of a state

val take : sequence -> Tezos_protocol_environment_006_PsCARTHA__Environment.MBytes.t * sequence

Generates the next random value in the sequence

val take_int32 : sequence -> int32 -> int32 * sequence

Generates the next random value as a bounded int32

Predefined seeds

val empty : seed
val deterministic_seed : seed -> seed

Returns a new seed by hashing the one passed with a constant.

val initial_seeds : int -> seed list

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.


type nonce

A nonce for adding entropy to the generator

val nonce : seed -> nonce -> seed

Add entropy to the seed generator

val make_nonce : Tezos_protocol_environment_006_PsCARTHA__Environment.MBytes.t -> nonce Tezos_protocol_environment_006_PsCARTHA__Environment.Error_monad.tzresult

Use a byte sequence as a nonce

val hash : nonce -> Tezos_raw_protocol_006_PsCARTHA.Nonce_hash.t

Compute the has of a nonce

val check_hash : nonce -> Tezos_raw_protocol_006_PsCARTHA.Nonce_hash.t -> bool

check_hash nonce hash is true if the nonce correspond to the hash

val nonce_hash_key_part : Tezos_raw_protocol_006_PsCARTHA.Nonce_hash.t -> string list -> string list

For using nonce hashes as keys in the hierarchical database

Predefined nonce

val initial_nonce_0 : nonce
val initial_nonce_hash_0 : Tezos_raw_protocol_006_PsCARTHA.Nonce_hash.t


val nonce_encoding : nonce Tezos_protocol_environment_006_PsCARTHA__Environment.Data_encoding.t
val seed_encoding : seed Tezos_protocol_environment_006_PsCARTHA__Environment.Data_encoding.t