diff --git a/manifest/main.ml b/manifest/main.ml index 3ed9815da06aff91e1d3dadac4ca40f097ffee1b..2a15f8f3e0b7f957d3420e1451cf926263bf06e4 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -4624,6 +4624,7 @@ module Protocol = Protocol ringo; ringo_lwt; injector |> if_some |> open_; + octez_scoru_wasm; ] in let tx_rollup = diff --git a/opam/tezos-sc-rollup-node-013-PtJakart.opam b/opam/tezos-sc-rollup-node-013-PtJakart.opam index 9cb54d57fa596345a62d55a566620e2123518ee7..4ffc02327e1908f3e1d1401e1c0b08a9276695ea 100644 --- a/opam/tezos-sc-rollup-node-013-PtJakart.opam +++ b/opam/tezos-sc-rollup-node-013-PtJakart.opam @@ -31,6 +31,7 @@ depends: [ "ringo" { >= "0.9" } "ringo-lwt" { >= "0.9" } "tezos-injector-013-PtJakart" + "tezos-scoru-wasm" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-sc-rollup-node-014-PtKathma.opam b/opam/tezos-sc-rollup-node-014-PtKathma.opam index aefc968fd58295cf038508e869d5572a5cf0a8e2..c8a33144eb0ac3e0b7a2d128e9e666faab020a8b 100644 --- a/opam/tezos-sc-rollup-node-014-PtKathma.opam +++ b/opam/tezos-sc-rollup-node-014-PtKathma.opam @@ -31,6 +31,7 @@ depends: [ "ringo" { >= "0.9" } "ringo-lwt" { >= "0.9" } "tezos-injector-014-PtKathma" + "tezos-scoru-wasm" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-sc-rollup-node-alpha.opam b/opam/tezos-sc-rollup-node-alpha.opam index 8b6e5315770c236d09bef181db201678957dea4c..8e620ad04d7867d0b3543776864c4a9a0e5cbaf4 100644 --- a/opam/tezos-sc-rollup-node-alpha.opam +++ b/opam/tezos-sc-rollup-node-alpha.opam @@ -32,6 +32,7 @@ depends: [ "ringo" { >= "0.9" } "ringo-lwt" { >= "0.9" } "tezos-injector-alpha" + "tezos-scoru-wasm" ] build: [ ["rm" "-r" "vendors"] diff --git a/src/lib_protocol_environment/environment_V7.ml b/src/lib_protocol_environment/environment_V7.ml index d09bc8e95c85527c9149b71705d06fc04f79e645..2909cd7a88924d89d359b3e3e532e0144ee7f063 100644 --- a/src/lib_protocol_environment/environment_V7.ml +++ b/src/lib_protocol_environment/environment_V7.ml @@ -102,6 +102,13 @@ module type T = sig * Tezos_protocol_environment_structs.V7.Plonk.transcript and type Dal.parameters = Tezos_crypto_dal.Cryptobox.Verifier.parameters and type Dal.commitment = Tezos_crypto_dal.Cryptobox.Verifier.commitment + and type Bounded.Non_negative_int32.t = + Tezos_base.Bounded.Non_negative_int32.t + and type Wasm_2_0_0.input = Tezos_scoru_wasm.Wasm_pvm_sig.input_info + and type Wasm_2_0_0.output = Tezos_scoru_wasm.Wasm_pvm_sig.output_info + and type Wasm_2_0_0.input_request = + Tezos_scoru_wasm.Wasm_pvm_sig.input_request + and type Wasm_2_0_0.info = Tezos_scoru_wasm.Wasm_pvm_sig.info type error += Ecoproto_error of Error_monad.error diff --git a/src/lib_protocol_environment/environment_V7.mli b/src/lib_protocol_environment/environment_V7.mli index c629499392e2e3920bcb84e0855279b4217bc18b..ae4cbf1416643854a2f052762975396ba2855ed2 100644 --- a/src/lib_protocol_environment/environment_V7.mli +++ b/src/lib_protocol_environment/environment_V7.mli @@ -102,6 +102,13 @@ module type T = sig * Tezos_protocol_environment_structs.V7.Plonk.transcript and type Dal.parameters = Tezos_crypto_dal.Cryptobox.Verifier.parameters and type Dal.commitment = Tezos_crypto_dal.Cryptobox.Verifier.commitment + and type Bounded.Non_negative_int32.t = + Tezos_base.Bounded.Non_negative_int32.t + and type Wasm_2_0_0.input = Tezos_scoru_wasm.Wasm_pvm_sig.input_info + and type Wasm_2_0_0.output = Tezos_scoru_wasm.Wasm_pvm_sig.output_info + and type Wasm_2_0_0.input_request = + Tezos_scoru_wasm.Wasm_pvm_sig.input_request + and type Wasm_2_0_0.info = Tezos_scoru_wasm.Wasm_pvm_sig.info (** An [Ecoproto_error e] is a shell error that carry a protocol error. diff --git a/src/proto_013_PtJakart/bin_sc_rollup_node/dune b/src/proto_013_PtJakart/bin_sc_rollup_node/dune index 7f9be3976971cc6708f424eff2bcb25338458b15..124a1238172888acd33c0ec200b034412e8f14ce 100644 --- a/src/proto_013_PtJakart/bin_sc_rollup_node/dune +++ b/src/proto_013_PtJakart/bin_sc_rollup_node/dune @@ -31,7 +31,8 @@ irmin ringo ringo-lwt - tezos-injector-013-PtJakart) + tezos-injector-013-PtJakart + tezos-scoru-wasm) (link_flags (:standard) (:include %{workspace_root}/static-link-flags.sexp)) diff --git a/src/proto_014_PtKathma/bin_sc_rollup_node/dune b/src/proto_014_PtKathma/bin_sc_rollup_node/dune index 8a29a9f19848e6933da92867cce579b37c074d8c..d2e3f873d7ef0abf652e1cdf967dc47ec02651c2 100644 --- a/src/proto_014_PtKathma/bin_sc_rollup_node/dune +++ b/src/proto_014_PtKathma/bin_sc_rollup_node/dune @@ -31,7 +31,8 @@ irmin ringo ringo-lwt - tezos-injector-014-PtKathma) + tezos-injector-014-PtKathma + tezos-scoru-wasm) (link_flags (:standard) (:include %{workspace_root}/static-link-flags.sexp)) diff --git a/src/proto_alpha/bin_sc_rollup_node/dune b/src/proto_alpha/bin_sc_rollup_node/dune index 6e27d9926208d7b03ddef6e4bbdab3c55cde741a..72aa7d93598db95770bf48556e9a71a02225225a 100644 --- a/src/proto_alpha/bin_sc_rollup_node/dune +++ b/src/proto_alpha/bin_sc_rollup_node/dune @@ -32,7 +32,8 @@ irmin ringo ringo-lwt - tezos-injector-alpha) + tezos-injector-alpha + tezos-scoru-wasm) (link_flags (:standard) (:include %{workspace_root}/static-link-flags.sexp)) diff --git a/src/proto_alpha/bin_sc_rollup_node/wasm_2_0_0_pvm.ml b/src/proto_alpha/bin_sc_rollup_node/wasm_2_0_0_pvm.ml index 5de2060ce12fc5b45f9775ba4e4bfd11bbdcb9d2..74f0ac3018ca4f220aa0061394c65450e37e592f 100644 --- a/src/proto_alpha/bin_sc_rollup_node/wasm_2_0_0_pvm.ml +++ b/src/proto_alpha/bin_sc_rollup_node/wasm_2_0_0_pvm.ml @@ -44,8 +44,27 @@ module Wasm_2_0_0_proof_format = .tree_proof_encoding end) +module type TreeS = + Tezos_context_sigs.Context.TREE + with type key = string list + and type value = bytes + +module Make_backend (Tree : TreeS) = struct + type Lazy_containers.Lazy_map.tree += PVM_tree of Tree.tree + + include Tezos_scoru_wasm.Wasm_pvm.Make (struct + include Tree + + let select = function + | PVM_tree t -> t + | _ -> raise Tree_encoding.Incorrect_tree_type + + let wrap t = PVM_tree t + end) +end + module Impl : Pvm.S = struct - include Sc_rollup.Wasm_2_0_0PVM.Make (Wasm_2_0_0_proof_format) + include Sc_rollup.Wasm_2_0_0PVM.Make (Make_backend) (Wasm_2_0_0_proof_format) module State = Context.PVMState let string_of_status : status -> string = function diff --git a/src/proto_alpha/lib_client/client_proto_rollups.ml b/src/proto_alpha/lib_client/client_proto_rollups.ml index 3d931c35df9aca5b6a447865e6cab02f9abf7c23..f41391a9c48c2ae19edc0f15c846f2eda7ebe03f 100644 --- a/src/proto_alpha/lib_client/client_proto_rollups.ml +++ b/src/proto_alpha/lib_client/client_proto_rollups.ml @@ -144,7 +144,9 @@ module ScRollup = struct and type proof = Tezos_context_memory.Context.Proof.tree Tezos_context_memory.Context.Proof.t = - Sc_rollup.Wasm_2_0_0PVM.Make (In_memory_context) + Sc_rollup.Wasm_2_0_0PVM.Make + (Environment.Wasm_2_0_0.Make) + (In_memory_context) let origination_proof_exn ~boot_sector kind = let aux = function diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 0d05acff3f529eb1b580c2dd1076ff7f93cff883..f0905280e2c0e77ad04336a4423943d14fc99d81 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3379,7 +3379,9 @@ module Sc_rollup : sig (proof * 'a) option Lwt.t end - module Make (C : P) : sig + module type Make_wasm = module type of Wasm_2_0_0.Make + + module Make (Wasm_backend : Make_wasm) (C : P) : sig include PVM.S with type context = C.Tree.t diff --git a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml index 221d652ea465c3e5af1ed491551c35cf9f4e8dcd..acb3d0a5b758b86fc52a5ea39509cbcefce01f42 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml @@ -55,9 +55,13 @@ module V2_0_0 = struct open Sc_rollup_repr module PS = Sc_rollup_PVM_sig + module type TreeS = + Context.TREE with type key = string list and type value = bytes + + module type Make_wasm = module type of Wasm_2_0_0.Make + module type P = sig - module Tree : - Context.TREE with type key = string list and type value = bytes + module Tree : TreeS type tree = Tree.tree @@ -97,7 +101,12 @@ module V2_0_0 = struct val get_outbox : state -> Sc_rollup_PVM_sig.output list Lwt.t end - module Make (Context : P) : + (* [Make (Make_backend) (Context)] creates a PVM. + + The Make_backend is a functor that creates the backend of the PVM. + The Conext provides the tree and the proof types. + *) + module Make (Make_backend : Make_wasm) (Context : P) : S with type context = Context.Tree.t and type state = Context.tree @@ -169,11 +178,11 @@ module V2_0_0 = struct end end - module WASM_machine = Wasm_2_0_0.Make (Tree) - open State - type state = State.state + module WASM_machine = Make_backend (Tree) + open State + let pp _state = Lwt.return @@ fun fmt () -> Format.pp_print_string fmt "" @@ -426,38 +435,44 @@ module V2_0_0 = struct end end - module Protocol_implementation = Make (struct - module Tree = struct - include Context.Tree + module Protocol_implementation = + Make + (Wasm_2_0_0.Make) + (struct + module Tree = struct + include Context.Tree - type tree = Context.tree + type tree = Context.tree - type t = Context.t + type t = Context.t - type key = string list + type key = string list - type value = bytes - end + type value = bytes + end - type tree = Context.tree + type tree = Context.tree - type proof = Context.Proof.tree Context.Proof.t + type proof = Context.Proof.tree Context.Proof.t - let verify_proof p f = - Lwt.map Result.to_option (Context.verify_tree_proof p f) + let verify_proof p f = + Lwt.map Result.to_option (Context.verify_tree_proof p f) - let produce_proof _context _state _f = - (* Can't produce proof without full context*) - Lwt.return None + let produce_proof _context _state _f = + (* Can't produce proof without full context*) + Lwt.return None - let kinded_hash_to_state_hash = function - | `Value hash | `Node hash -> State_hash.context_hash_to_state_hash hash + let kinded_hash_to_state_hash = function + | `Value hash | `Node hash -> + State_hash.context_hash_to_state_hash hash - let proof_before proof = - kinded_hash_to_state_hash proof.Context.Proof.before + let proof_before proof = + kinded_hash_to_state_hash proof.Context.Proof.before - let proof_after proof = kinded_hash_to_state_hash proof.Context.Proof.after + let proof_after proof = + kinded_hash_to_state_hash proof.Context.Proof.after - let proof_encoding = Context.Proof_encoding.V2.Tree32.tree_proof_encoding - end) + let proof_encoding = + Context.Proof_encoding.V2.Tree32.tree_proof_encoding + end) end diff --git a/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli b/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli index 280ba1597f64c88407841029537d00f4483ec345..c33f80431f68559013eb5a17c873fa241692674e 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli @@ -83,8 +83,10 @@ module V2_0_0 : sig Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t end + module type Make_wasm = module type of Wasm_2_0_0.Make + (** Build a WebAssembly PVM using the given proof-supporting context. *) - module Make (Context : P) : + module Make (Lib_scoru_Wasm : Make_wasm) (Context : P) : S with type context = Context.Tree.t and type state = Context.tree diff --git a/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml index 2f3654bb104a214515e5f57751822aa8ec89cacf..d61dbaf3e935ef9bcbd36691a08d0080dbb6dfd8 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/sc_rollup_helpers.ml @@ -98,7 +98,7 @@ module Wasm_pvm : and type proof = Tezos_context_memory.Context.Proof.tree Tezos_context_memory.Context.Proof.t = - Sc_rollup.Wasm_2_0_0PVM.Make (In_memory_context) + Sc_rollup.Wasm_2_0_0PVM.Make (Environment.Wasm_2_0_0.Make) (In_memory_context) let origination_proof ~boot_sector = function | Sc_rollup.Kind.Example_arith -> diff --git a/src/proto_alpha/lib_protocol/test/integration/test_sc_rollup_wasm.ml b/src/proto_alpha/lib_protocol/test/integration/test_sc_rollup_wasm.ml index 2ad8c2112d2a59274509dd6d8239c5c97401ee73..cdf4309b4d086c0758e526804f0a3ec215aca1d8 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_sc_rollup_wasm.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_sc_rollup_wasm.ml @@ -108,7 +108,10 @@ end module Verifier = Alpha_context.Sc_rollup.Wasm_2_0_0PVM.Protocol_implementation -module Prover = Alpha_context.Sc_rollup.Wasm_2_0_0PVM.Make (WASM_P) +module Prover = + Alpha_context.Sc_rollup.Wasm_2_0_0PVM.Make + (Environment.Wasm_2_0_0.Make) + (WASM_P) (* Helpers *) (* FIXME: https://gitlab.com/tezos/tezos/-/issues/2198