diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 6706d13533204cfc68371cd10ccc12185464a571..bdb8f02055f6abb60b94412ba45ca8d4a0bd41d9 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -104,3 +104,7 @@ Internal - Refactoring : rewards computed as a relative portion of the total amount of tez rewarded per minute (about 85tez/min). (MR :gl:`!8657`) + +- Introduce the notion of rollups “machine” which can compute the semantics of + a given rollup, but cannot be used to generate or verify proof. (MR + :gl:`!8815`) diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 714005680da6207e51c64f618bd707130899397e..061a870e8d06df969659084c468617986b2a8558 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -65,6 +65,7 @@ "Sc_rollup_PVM_sig", "Sc_rollup_arith", "Sc_rollup_wasm", + "Sc_rollup_machine_no_proofs", "Sc_rollups", "Sc_rollup_data_version_sig", "Sc_rollup_inbox_repr", diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 70c8061a3a780c2695276ca6496fd34fe1970bba..c5d08b6e2a1df4cca9e08ac320d2a044778b7fb2 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -115,6 +115,9 @@ module Sc_rollup = struct module Refutation_storage = Sc_rollup_refutation_storage include Sc_rollup_storage + + module type MACHINE = Sc_rollup_machine_no_proofs.S + include Sc_rollups module Outbox = struct diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index ddbb4ac646924385727a1d68b7364b4780b49ac6..00d50cb4561703fde085811320d6f7ff412fea51 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3740,6 +3740,12 @@ module Sc_rollup : sig [@@unboxed] end + module type MACHINE = + PVM.S + with type context = Context_binary.t + and type state = Context_binary.tree + and type proof = Sc_rollup_machine_no_proofs.void + module Kind : sig type t = Example_arith | Wasm_2_0_0 @@ -3749,6 +3755,8 @@ module Sc_rollup : sig val pvm_of : t -> PVM.t + val no_proof_machine_of : t -> (module MACHINE) + val all : t list val of_string : string -> t option diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index 41b569a871a5623e7622de248dfa6fe3b48f4d32..5a4d9c5eb34e9df7c6c8c321bd50f918922ff89e 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -91,6 +91,7 @@ Sc_rollup_PVM_sig Sc_rollup_arith Sc_rollup_wasm + Sc_rollup_machine_no_proofs Sc_rollups Sc_rollup_data_version_sig Sc_rollup_inbox_repr @@ -370,6 +371,7 @@ sc_rollup_PVM_sig.ml sc_rollup_arith.ml sc_rollup_arith.mli sc_rollup_wasm.ml sc_rollup_wasm.mli + sc_rollup_machine_no_proofs.ml sc_rollup_machine_no_proofs.mli sc_rollups.ml sc_rollups.mli sc_rollup_data_version_sig.ml sc_rollup_inbox_repr.ml sc_rollup_inbox_repr.mli @@ -653,6 +655,7 @@ sc_rollup_PVM_sig.ml sc_rollup_arith.ml sc_rollup_arith.mli sc_rollup_wasm.ml sc_rollup_wasm.mli + sc_rollup_machine_no_proofs.ml sc_rollup_machine_no_proofs.mli sc_rollups.ml sc_rollups.mli sc_rollup_data_version_sig.ml sc_rollup_inbox_repr.ml sc_rollup_inbox_repr.mli @@ -920,6 +923,7 @@ sc_rollup_PVM_sig.ml sc_rollup_arith.ml sc_rollup_arith.mli sc_rollup_wasm.ml sc_rollup_wasm.mli + sc_rollup_machine_no_proofs.ml sc_rollup_machine_no_proofs.mli sc_rollups.ml sc_rollups.mli sc_rollup_data_version_sig.ml sc_rollup_inbox_repr.ml sc_rollup_inbox_repr.mli diff --git a/src/proto_alpha/lib_protocol/sc_rollup_machine_no_proofs.ml b/src/proto_alpha/lib_protocol/sc_rollup_machine_no_proofs.ml new file mode 100644 index 0000000000000000000000000000000000000000..6885b4b381d00b64e236402c072c6a57e541d5b4 --- /dev/null +++ b/src/proto_alpha/lib_protocol/sc_rollup_machine_no_proofs.ml @@ -0,0 +1,77 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +type void = | + +let void = + Data_encoding.( + conv_with_guard + (function (_ : void) -> .) + (fun _ -> Error "void has no inhabitant") + unit) + +type t = Context_binary.t + +type tree = Context_binary.tree + +let empty_tree () = Context_binary.(make_empty_context () |> Tree.empty) + +module Context_no_proofs = struct + module Tree = Context_binary.Tree + + type tree = Context_binary.tree + + let hash_tree tree = + Sc_rollup_repr.State_hash.context_hash_to_state_hash (Tree.hash tree) + + type proof = void + + let verify_proof = function (_ : proof) -> . + + let produce_proof _context _state _step = assert false + + let proof_before = function (_ : proof) -> . + + let proof_after = function (_ : proof) -> . + + let proof_encoding = void +end + +module type S = sig + val parse_boot_sector : string -> string option + + val pp_boot_sector : Format.formatter -> string -> unit + + include + Sc_rollup_PVM_sig.S + with type context = Context_no_proofs.Tree.t + and type state = Context_no_proofs.tree + and type proof = void +end + +module Arith : S = Sc_rollup_arith.Make (Context_no_proofs) + +module Wasm : S = + Sc_rollup_wasm.V2_0_0.Make (Wasm_2_0_0.Make) (Context_no_proofs) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_machine_no_proofs.mli b/src/proto_alpha/lib_protocol/sc_rollup_machine_no_proofs.mli new file mode 100644 index 0000000000000000000000000000000000000000..cfe1a7b708946d295fdcf3a2b44cd97d20299c92 --- /dev/null +++ b/src/proto_alpha/lib_protocol/sc_rollup_machine_no_proofs.mli @@ -0,0 +1,52 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** This module provides instantiation of both the WASM and Arith PVM which can + be used to perform rollup computations, {b but} cannot be used to compute + proofs. *) + +type void = | + +type t = Context_binary.t + +type tree = Context_binary.tree + +val empty_tree : unit -> tree + +module type S = sig + val parse_boot_sector : string -> string option + + val pp_boot_sector : Format.formatter -> string -> unit + + include + Sc_rollup_PVM_sig.S + with type context = t + and type state = tree + and type proof = void +end + +module Arith : S + +module Wasm : S diff --git a/src/proto_alpha/lib_protocol/sc_rollups.ml b/src/proto_alpha/lib_protocol/sc_rollups.ml index de63308c734617ed16e02b6392db8d8b63bd6122..09d8e122e5920dc92c4ebc36485ede5354e40973 100644 --- a/src/proto_alpha/lib_protocol/sc_rollups.ml +++ b/src/proto_alpha/lib_protocol/sc_rollups.ml @@ -87,4 +87,9 @@ module Kind = struct let pvm_of = function | Example_arith -> example_arith_pvm | Wasm_2_0_0 -> wasm_2_0_0_pvm + + let no_proof_machine_of : t -> (module Sc_rollup_machine_no_proofs.S) = + function + | Example_arith -> (module Sc_rollup_machine_no_proofs.Arith) + | Wasm_2_0_0 -> (module Sc_rollup_machine_no_proofs.Wasm) end diff --git a/src/proto_alpha/lib_protocol/sc_rollups.mli b/src/proto_alpha/lib_protocol/sc_rollups.mli index 5fa3b57695aaf41f55f3fb0d802882aa3e4b31f3..6c1f9a2698bf9939546cae121193679b1db8e060 100644 --- a/src/proto_alpha/lib_protocol/sc_rollups.mli +++ b/src/proto_alpha/lib_protocol/sc_rollups.mli @@ -64,6 +64,11 @@ module Kind : sig (** [pvm_of kind] returns the [PVM] of the given [kind]. *) val pvm_of : t -> PVM.t + (** [no_proof_machine_of kind] returns a machine of a given [kind] capable of + computing a rollup semantics, but incapable of doing any proof-related + computations. *) + val no_proof_machine_of : t -> (module Sc_rollup_machine_no_proofs.S) + (** [all] returns all implemented PVM. *) val all : t list diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml index 644eaa6393bfe82b6a44863b204849a4492dedbc..c425b509d462683515b7426dccf5d8159f83bf99 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml @@ -105,6 +105,21 @@ let test_initial_state_hash_wasm_pvm () = Sc_rollup.State_hash.pp hash +let test_initial_state_hash_wasm_machine () = + let open Lwt_result_syntax in + let open Sc_rollup_machine_no_proofs in + let*! state = Wasm.initial_state ~empty:(empty_tree ()) in + let*! hash = Wasm.state_hash state in + let expected = Sc_rollup_wasm.V2_0_0.reference_initial_state_hash in + if Sc_rollup_repr.State_hash.(hash = expected) then return_unit + else + failwith + "incorrect hash, expected %a, got %a" + Sc_rollup_repr.State_hash.pp + expected + Sc_rollup_repr.State_hash.pp + hash + let test_metadata_size () = let address = Sc_rollup_repr.Address.of_bytes_exn (Bytes.make 20 '\000') in let metadata = @@ -344,6 +359,10 @@ let tests = "initial state hash for Wasm" `Quick test_initial_state_hash_wasm_pvm; + Tztest.tztest + "initial state hash for Wasm machine" + `Quick + test_initial_state_hash_wasm_machine; Tztest.tztest "size of a rollup metadata" `Quick test_metadata_size; Tztest.tztest "l1 input kind" `Quick test_l1_input_kind; Tztest.tztest "output proofs" `Quick test_output;