package tezos-protocol-015-PtLimaPt

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

The following operations are subject to cross-validation between rollup nodes and the layer 1.

type tree

The type for the Merkle trees used in this module.

type inbox_context

The context used by the trees.

val hash_level_tree : tree -> Hash.t

Standard hashing function used for trees in this module.

Initialise a new level. new_level_tree ctxt level is a merkle tree with no messages yet, but has the level stored so we can check that in proofs.

add_messages ctxt history inbox level payloads level_tree inserts a list of payloads as new messages in the level_tree of the current level of the inbox. This function returns the new level tree as well as updated inbox and history.

If the inbox's level is older than level, the inbox is updated so that the level trees of the levels older than level are archived. To archive a level_tree for a given level, we push it at the end of the history and update the witness of this history in the inbox. The inbox's level tree for the current level is emptied to insert the payloads in a fresh level_tree for level.

This function fails if level is older than inbox's level.

add_messages_no_history ctxt inbox level payloads level_tree behaves as add_external_messages except that it does not remember the inbox history.

get_message_payload level_tree idx returns Some payload if the level_tree has more than idx messages, and payload is at position idx. Returns None otherwise.

form_history_proof ctxt history inbox level_tree creates the skip list structure that includes the current inbox level, while also updating the history and making sure the level_tree has been committed to the ctxt.

This is used in archive_if_needed to produce the old_levels_messages value for the next level of the inbox. It is also needed if you want to produce a fully-up-to-date skip list for proof production. Just taking the skip list stored in the inbox at old_levels_messages will not include the current level (and that current level could be quite far back in terms of blocks if the inbox hasn't been added to for a while).

val take_snapshot : t -> history_proof

This is similar to form_history_proof except that it is just to be used on the protocol side because it doesn't ensure the history is remembered or the trees are committed in the context. Used at the beginning of a refutation game to create the snapshot against which proofs in that game must be valid.

This will however produce a history_proof with exactly the same hash as the one produced by form_history_proof, run on a node with a complete inbox_context.

type inclusion_proof

Given a inbox A at some level L and another inbox B at some level L' >= L, an inclusion_proof guarantees that A is an older version of B.

To be more precise, an inclusion_proof guarantees that the previous levels level_trees of A are included in the previous levels level_trees of B. The current level_tree of A and B are not considered.

The size of this proof is O(log_basis (L' - L)).

val number_of_proof_steps : inclusion_proof -> int

number_of_proof_steps proof returns the length of proof.

val verify_inclusion_proof : inclusion_proof -> history_proof -> history_proof -> bool

verify_inclusion_proof proof a b returns true iff proof is a minimal and valid proof that a is included in b.

type proof

An inbox proof has three parameters:

  • the starting_point, of type Raw_level_repr.t * Z.t, specifying a location in the inbox ;
  • the message, of type Sc_rollup_PVM_sig.input option ;
  • and a reference snapshot inbox.

A valid inbox proof implies the following semantics: beginning at starting_point and reading forward through snapshot, the first message you reach will be message.

Usually this is fairly simple because there will actually be a message at the location specified by starting_point. But in some cases starting_point is past the last message within a level, and then the inbox proof must prove that and also provide another proof about the message at the beginning of the next non-empty level.

val to_serialized_proof : proof -> serialized_proof
val of_serialized_proof : serialized_proof -> proof option

See the docstring for the proof type for details of proof semantics.

verify_proof starting_point inbox proof will return the third parameter of the proof, message, iff the proof is valid.

produce_proof ctxt history inbox (level, counter) creates an inbox proof proving the first message after the index counter at location level. This will fail if the ctxt given doesn't have sufficient data (it needs to be run on an inbox_context with the full history).

empty ctxt level is an inbox started at some given level with no message at all.

module Internal_for_tests : sig ... end
OCaml

Innovation. Community. Security.