package tezos-protocol-014-PtKathma
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=7062cd57addd452852598a2214ade393130efa087b99068d53713bdf912b3680
sha512=08e4091144a03ce3c107fb91a66501bd8b65ca3278917c455a2eaac6df3e108ade63f6ab8340a4bb152d60f404326e464d0ec95d26cafe8e82f870465d24a5fc
doc/tezos-protocol-014-PtKathma.raw/Tezos_raw_protocol_014_PtKathma/Sc_rollup_arith/ProtocolImplementation/index.html
Module Sc_rollup_arith.ProtocolImplementation
Source
include Sc_rollup_PVM_sem.S
with type context = Tezos_protocol_environment_014_PtKathma.Context.t
The state of the PVM denotes a state of the rollup.
We classify states into two categories: "internal states" do not require any external information to be executed while "input states" are waiting for some information from the inbox to be executable.
A state is initialized in a given context. A context
represents the executable environment needed by the state to exist. Typically, the rollup node storage can be part of this context to allow the PVM state to be persistent.
A hash
characterizes the contents of a state.
During interactive refutation games, a player may need to provide a proof that a given execution step is valid. The PVM implementation is responsible for ensuring that this proof type has the correct semantics:
A proof p
has four parameters:
start_hash := proof_start_state p
stop_hash := proof_stop_state p
input_requested := proof_input_requested p
input_given := proof_input_given p
The following predicate must hold of a valid proof:
exists start_state, stop_state. (state_hash start_state == start_hash) AND (Option.map state_hash stop_state == stop_hash) AND (is_input_state start_state == input_requested) AND (match (input_given, input_requested) with | (None, No_input_required) -> eval start_state == stop_state | (None, Initial) -> stop_state == None | (None, First_after (l, n)) -> stop_state == None | (Some input, No_input_required) -> true | (Some input, Initial) -> set_input input_given start_state == stop_state | (Some input, First_after (l, n)) -> set_input input_given start_state == stop_state)
In natural language---the two hash parameters start_hash
and stop_hash
must have actual state
values (or possibly None
in the case of stop_hash
) of which they are the hashes. The input_requested
parameter must be the correct request from the start_hash
, given according to is_input_state
. Finally there are four possibilities of input_requested
and input_given
.
- if no input is required, or given, the proof is a simple
eval
step ; - if input was required but not given, the
stop_hash
must beNone
(the machine is blocked) ; - if no input was required but some was given, this makes no sense and it doesn't matter if the proof is valid or invalid (this case will be ruled out by the inbox proof anyway) ;
- finally, if input was required and given, the proof is a
set_input
step.
proof
s are embedded in L1 refutation game operations using proof_encoding
. Given that the size of L1 operations are limited, it is of *critical* importance to make sure that no execution step of the PVM can generate proofs that do not fit in L1 operations when encoded. If such a proof existed, the rollup could get stuck.
proof_start_state proof
returns the initial state hash of the proof
execution step.
proof_stop_state proof
returns the final state hash of the proof
execution step.
proof_input_requested proof
returns the input_request
status of the start state of the proof, as given by is_input_state
. This must match with the inbox proof to complete a valid refutation game proof.
proof_input_given proof
returns the input
, if any, provided to the start state of the proof using the set_input
function. If None
, the proof is an eval
step instead, or the machine is blocked because the inbox is fully read. This must match with the inbox proof to complete a valid refutation game proof.
state_hash state
returns a compressed representation of state
.
initial_state context boot_sector
is the initial state of the PVM, which is a pure function of boot_sector
.
The context
argument is required for technical reasons and does not impact the result.
val is_input_state :
state ->
Sc_rollup_PVM_sem.input_request Tezos_protocol_environment_014_PtKathma.Lwt.t
is_input_state state
returns the input expectations of the state
---does it need input, and if so, how far through the inbox has it read so far?
val set_input :
Sc_rollup_PVM_sem.input ->
state ->
state Tezos_protocol_environment_014_PtKathma.Lwt.t
set_input (level, n, msg) state
sets msg
in state
as the next message to be processed. This input message is assumed to be the number n
in the inbox messages at the given level
. The input message must be the message next to the previous message processed by the rollup.
eval s0
returns a state s1
resulting from the execution of an atomic step of the rollup at state s0
.
This checks the proof. See the doc-string for the proof
type.
val produce_proof :
context ->
Sc_rollup_PVM_sem.input option ->
state ->
(proof, Tezos_protocol_environment_014_PtKathma.Error_monad.error)
Tezos_protocol_environment_014_PtKathma.Pervasives.result
Tezos_protocol_environment_014_PtKathma.Lwt.t
produce_proof ctxt input_given state
should return a proof
for the PVM step starting from state
, if possible. This may fail for a few reasons:
- the
input_given
doesn't match the expectations ofstate
; - the
context
for this instance of the PVM doesn't have access to enough of thestate
to build the proof.
The following type is inhabited by the proofs that a given output
is part of the outbox of a given state
.
val output_proof_encoding :
output_proof Tezos_protocol_environment_014_PtKathma.Data_encoding.t
output_proof_encoding
encoding value for output_proof
s.
output_of_output_proof proof
returns the output
that is referred to in proof
's statement.
state_of_output_proof proof
returns the state
hash that is referred to in proof
's statement.
verify_output_proof output_proof
returns true
iff proof
is a valid witness that its output
is part of its state
's outbox.
val produce_output_proof :
context ->
state ->
Sc_rollup_PVM_sem.output ->
(output_proof, Tezos_protocol_environment_014_PtKathma.Error_monad.error)
Tezos_protocol_environment_014_PtKathma.Pervasives.result
Tezos_protocol_environment_014_PtKathma.Lwt.t
produce_output_proof ctxt state output
returns a proof that witnesses the fact that output
is part of state
's outbox.
name
is "arith".
parse_boot_sector s
builds a boot sector from its human writable description.
val pp_boot_sector :
Tezos_protocol_environment_014_PtKathma.Format.formatter ->
string ->
unit
pp_boot_sector fmt s
prints a human readable representation of a boot sector.
val pp :
state ->
(Tezos_protocol_environment_014_PtKathma.Format.formatter ->
unit ->
unit)
Tezos_protocol_environment_014_PtKathma.Lwt.t
pp state
returns a pretty-printer valid for state
.
get_tick state
returns the current tick of state
.
The machine has three possible statuses:
get_status state
returns the machine status in state
.
type instruction =
| IPush : int -> instruction
| IAdd : instruction
| IStore : string -> instruction
The machine has only three instructions.
equal_instruction i1 i2
is true
iff i1
equals i2
.
val pp_instruction :
Tezos_protocol_environment_014_PtKathma.Format.formatter ->
instruction ->
unit
pp_instruction fmt i
shows a human readable representation of i
.
get_parsing_result state
is Some true
if the current message is syntactically correct, Some false
when it contains a syntax error, and None
when the machine is not in parsing state.
get_code state
returns the current code obtained by parsing the current input message.
get_stack state
returns the current stack.
get_var state x
returns the current value of variable x
. Returns None
if x
does not exist.
val get_evaluation_result :
state ->
bool option Tezos_protocol_environment_014_PtKathma.Lwt.t
get_evaluation_result state
returns Some true
if the current message evaluation succeeds, Some false
if it failed, and None
if the evaluation has not been done yet.
get_is_stuck state
returns Some err
if some internal error made the machine fail during the last evaluation step. None
if no internal error occurred. When a machine is stuck, it reboots, waiting for the next message to process.