From 4242ca7197a480cb02d8decf8e71d2d4a130d533 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Tue, 23 May 2023 09:00:48 +0200 Subject: [PATCH 1/4] soru/helpers: use common sig for pvm --- .../lib_sc_rollup/context_helpers.ml | 26 +++++++++++++++ .../lib_sc_rollup/context_helpers.mli | 32 +++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_sc_rollup/context_helpers.ml b/src/proto_alpha/lib_sc_rollup/context_helpers.ml index 2ab44f26d043..febdce584310 100644 --- a/src/proto_alpha/lib_sc_rollup/context_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup/context_helpers.ml @@ -22,6 +22,32 @@ (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) +open Protocol.Alpha_context + +module type P = sig + module Tree : + Tezos_context_sigs.Context.TREE + with type key = string list + and type value = bytes + + type tree = Tree.tree + + val hash_tree : tree -> Sc_rollup.State_hash.t + + type proof + + val proof_encoding : proof Data_encoding.t + + val proof_before : proof -> Sc_rollup.State_hash.t + + val proof_after : proof -> Sc_rollup.State_hash.t + + val verify_proof : + proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t + + val produce_proof : + Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t +end module In_memory = struct open Tezos_context_memory diff --git a/src/proto_alpha/lib_sc_rollup/context_helpers.mli b/src/proto_alpha/lib_sc_rollup/context_helpers.mli index 35ba7e64cf5a..a7611201c86d 100644 --- a/src/proto_alpha/lib_sc_rollup/context_helpers.mli +++ b/src/proto_alpha/lib_sc_rollup/context_helpers.mli @@ -22,6 +22,32 @@ (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) +open Protocol.Alpha_context + +module type P = sig + module Tree : + Tezos_context_sigs.Context.TREE + with type key = string list + and type value = bytes + + type tree = Tree.tree + + val hash_tree : tree -> Sc_rollup.State_hash.t + + type proof + + val proof_encoding : proof Data_encoding.t + + val proof_before : proof -> Sc_rollup.State_hash.t + + val proof_after : proof -> Sc_rollup.State_hash.t + + val verify_proof : + proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t + + val produce_proof : + Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t +end (** [In_memory] is a context that can be used to instantiate an Arith or Wasm PVM. It's signature is @@ -29,8 +55,10 @@ {!Protocol.Alpha_context.Sc_rollup.Wasm_2_0_0PVM.P} *) module In_memory : sig include - Protocol.Alpha_context.Sc_rollup.ArithPVM.P - with type proof = + P + with type Tree.tree = Tezos_context_memory.Context_binary.tree + and type Tree.t = Tezos_context_memory.Context_binary.t + and type proof = Tezos_context_memory.Context.Proof.tree Tezos_context_memory.Context.Proof.t -- GitLab From 2dea61bf90e698b05c22f86eb5a9947bddd1045b Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Tue, 23 May 2023 09:04:42 +0200 Subject: [PATCH 2/4] soru/helpers: use Context_binary for types --- src/proto_alpha/lib_sc_rollup/context_helpers.ml | 8 +++++--- src/proto_alpha/lib_sc_rollup/pvm_in_memory.ml | 8 ++++---- src/proto_alpha/lib_sc_rollup/pvm_in_memory.mli | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_sc_rollup/context_helpers.ml b/src/proto_alpha/lib_sc_rollup/context_helpers.ml index febdce584310..a0ff2c67dde4 100644 --- a/src/proto_alpha/lib_sc_rollup/context_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup/context_helpers.ml @@ -66,7 +66,7 @@ module In_memory = struct type tree = Tree.tree - type proof = Context.Proof.tree Context.Proof.t + type proof = Context_binary.Proof.tree Context_binary.Proof.t let hash_tree _ = assert false @@ -91,9 +91,11 @@ module In_memory = struct Protocol.Alpha_context.Sc_rollup.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_binary.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_binary.Proof.after let proof_encoding = Tezos_context_merkle_proof_encoding.Merkle_proof_encoding.V2.Tree2 diff --git a/src/proto_alpha/lib_sc_rollup/pvm_in_memory.ml b/src/proto_alpha/lib_sc_rollup/pvm_in_memory.ml index eedebb959617..e626aa543a96 100644 --- a/src/proto_alpha/lib_sc_rollup/pvm_in_memory.ml +++ b/src/proto_alpha/lib_sc_rollup/pvm_in_memory.ml @@ -27,11 +27,11 @@ open Protocol.Alpha_context module type S = Sc_rollup.PVM.S - with type context = Context_helpers.In_memory.Tree.t - and type state = Context_helpers.In_memory.tree + with type context = Tezos_context_memory.Context_binary.t + and type state = Tezos_context_memory.Context_binary.tree and type proof = - Tezos_context_memory.Context.Proof.tree - Tezos_context_memory.Context.Proof.t + Tezos_context_memory.Context_binary.Proof.tree + Tezos_context_memory.Context_binary.Proof.t module Arith : S = Sc_rollup.ArithPVM.Make (Context_helpers.In_memory) diff --git a/src/proto_alpha/lib_sc_rollup/pvm_in_memory.mli b/src/proto_alpha/lib_sc_rollup/pvm_in_memory.mli index 3871cb4c4a9f..c0ae57cf3e9f 100644 --- a/src/proto_alpha/lib_sc_rollup/pvm_in_memory.mli +++ b/src/proto_alpha/lib_sc_rollup/pvm_in_memory.mli @@ -27,11 +27,11 @@ open Protocol.Alpha_context module type S = Sc_rollup.PVM.S - with type context = Context_helpers.In_memory.Tree.t - and type state = Context_helpers.In_memory.tree + with type context = Tezos_context_memory.Context_binary.t + and type state = Tezos_context_memory.Context_binary.tree and type proof = - Tezos_context_memory.Context.Proof.tree - Tezos_context_memory.Context.Proof.t + Tezos_context_memory.Context_binary.Proof.tree + Tezos_context_memory.Context_binary.Proof.t (** [Arith]: Arith PVM with an in memory context {!Tezos_context_memory}. *) module Arith : S -- GitLab From 9c81d74a78ebea767a26f4074aee7084bf54bfd8 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Tue, 23 May 2023 15:33:32 +0200 Subject: [PATCH 3/4] backport: soru/helpers type rework --- .../lib_sc_rollup/context_helpers.ml | 50 ++++++++++++------- .../lib_sc_rollup/context_helpers.mli | 32 +++++++++++- .../lib_sc_rollup/pvm_in_memory.ml | 8 +-- .../lib_sc_rollup/pvm_in_memory.mli | 8 +-- .../lib_sc_rollup/context_helpers.ml | 42 ++++++++++------ .../lib_sc_rollup/context_helpers.mli | 32 +++++++++++- .../lib_sc_rollup/pvm_in_memory.ml | 8 +-- .../lib_sc_rollup/pvm_in_memory.mli | 8 +-- 8 files changed, 137 insertions(+), 51 deletions(-) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup/context_helpers.ml b/src/proto_016_PtMumbai/lib_sc_rollup/context_helpers.ml index 122bb2ca52fd..a0ff2c67dde4 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup/context_helpers.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup/context_helpers.ml @@ -22,6 +22,32 @@ (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) +open Protocol.Alpha_context + +module type P = sig + module Tree : + Tezos_context_sigs.Context.TREE + with type key = string list + and type value = bytes + + type tree = Tree.tree + + val hash_tree : tree -> Sc_rollup.State_hash.t + + type proof + + val proof_encoding : proof Data_encoding.t + + val proof_before : proof -> Sc_rollup.State_hash.t + + val proof_after : proof -> Sc_rollup.State_hash.t + + val verify_proof : + proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t + + val produce_proof : + Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t +end module In_memory = struct open Tezos_context_memory @@ -40,7 +66,7 @@ module In_memory = struct type tree = Tree.tree - type proof = Context.Proof.tree Context.Proof.t + type proof = Context_binary.Proof.tree Context_binary.Proof.t let hash_tree _ = assert false @@ -65,26 +91,16 @@ module In_memory = struct Protocol.Alpha_context.Sc_rollup.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_binary.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_binary.Proof.after let proof_encoding = Tezos_context_merkle_proof_encoding.Merkle_proof_encoding.V2.Tree2 .tree_proof_encoding - (* TODO: https://gitlab.com/tezos/tezos/-/issues/4386 - Extracted and adapted from {!Tezos_context_memory}. *) - let make_empty_context ?(root = "/tmp") () = - let open Lwt_syntax in - let context_promise = - let+ index = Tezos_context_memory.Context_binary.init root in - Tezos_context_memory.Context_binary.empty index - in - match Lwt.state context_promise with - | Lwt.Return result -> result - | Lwt.Fail exn -> raise exn - | Lwt.Sleep -> - (* The in-memory context should never block *) - assert false + let make_empty_context = + Tezos_context_memory.Context_binary.make_empty_context end diff --git a/src/proto_016_PtMumbai/lib_sc_rollup/context_helpers.mli b/src/proto_016_PtMumbai/lib_sc_rollup/context_helpers.mli index 35ba7e64cf5a..a7611201c86d 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup/context_helpers.mli +++ b/src/proto_016_PtMumbai/lib_sc_rollup/context_helpers.mli @@ -22,6 +22,32 @@ (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) +open Protocol.Alpha_context + +module type P = sig + module Tree : + Tezos_context_sigs.Context.TREE + with type key = string list + and type value = bytes + + type tree = Tree.tree + + val hash_tree : tree -> Sc_rollup.State_hash.t + + type proof + + val proof_encoding : proof Data_encoding.t + + val proof_before : proof -> Sc_rollup.State_hash.t + + val proof_after : proof -> Sc_rollup.State_hash.t + + val verify_proof : + proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t + + val produce_proof : + Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t +end (** [In_memory] is a context that can be used to instantiate an Arith or Wasm PVM. It's signature is @@ -29,8 +55,10 @@ {!Protocol.Alpha_context.Sc_rollup.Wasm_2_0_0PVM.P} *) module In_memory : sig include - Protocol.Alpha_context.Sc_rollup.ArithPVM.P - with type proof = + P + with type Tree.tree = Tezos_context_memory.Context_binary.tree + and type Tree.t = Tezos_context_memory.Context_binary.t + and type proof = Tezos_context_memory.Context.Proof.tree Tezos_context_memory.Context.Proof.t diff --git a/src/proto_016_PtMumbai/lib_sc_rollup/pvm_in_memory.ml b/src/proto_016_PtMumbai/lib_sc_rollup/pvm_in_memory.ml index eedebb959617..e626aa543a96 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup/pvm_in_memory.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup/pvm_in_memory.ml @@ -27,11 +27,11 @@ open Protocol.Alpha_context module type S = Sc_rollup.PVM.S - with type context = Context_helpers.In_memory.Tree.t - and type state = Context_helpers.In_memory.tree + with type context = Tezos_context_memory.Context_binary.t + and type state = Tezos_context_memory.Context_binary.tree and type proof = - Tezos_context_memory.Context.Proof.tree - Tezos_context_memory.Context.Proof.t + Tezos_context_memory.Context_binary.Proof.tree + Tezos_context_memory.Context_binary.Proof.t module Arith : S = Sc_rollup.ArithPVM.Make (Context_helpers.In_memory) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup/pvm_in_memory.mli b/src/proto_016_PtMumbai/lib_sc_rollup/pvm_in_memory.mli index 3871cb4c4a9f..c0ae57cf3e9f 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup/pvm_in_memory.mli +++ b/src/proto_016_PtMumbai/lib_sc_rollup/pvm_in_memory.mli @@ -27,11 +27,11 @@ open Protocol.Alpha_context module type S = Sc_rollup.PVM.S - with type context = Context_helpers.In_memory.Tree.t - and type state = Context_helpers.In_memory.tree + with type context = Tezos_context_memory.Context_binary.t + and type state = Tezos_context_memory.Context_binary.tree and type proof = - Tezos_context_memory.Context.Proof.tree - Tezos_context_memory.Context.Proof.t + Tezos_context_memory.Context_binary.Proof.tree + Tezos_context_memory.Context_binary.Proof.t (** [Arith]: Arith PVM with an in memory context {!Tezos_context_memory}. *) module Arith : S diff --git a/src/proto_017_PtNairob/lib_sc_rollup/context_helpers.ml b/src/proto_017_PtNairob/lib_sc_rollup/context_helpers.ml index 122bb2ca52fd..febdce584310 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup/context_helpers.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup/context_helpers.ml @@ -22,6 +22,32 @@ (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) +open Protocol.Alpha_context + +module type P = sig + module Tree : + Tezos_context_sigs.Context.TREE + with type key = string list + and type value = bytes + + type tree = Tree.tree + + val hash_tree : tree -> Sc_rollup.State_hash.t + + type proof + + val proof_encoding : proof Data_encoding.t + + val proof_before : proof -> Sc_rollup.State_hash.t + + val proof_after : proof -> Sc_rollup.State_hash.t + + val verify_proof : + proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t + + val produce_proof : + Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t +end module In_memory = struct open Tezos_context_memory @@ -73,18 +99,6 @@ module In_memory = struct Tezos_context_merkle_proof_encoding.Merkle_proof_encoding.V2.Tree2 .tree_proof_encoding - (* TODO: https://gitlab.com/tezos/tezos/-/issues/4386 - Extracted and adapted from {!Tezos_context_memory}. *) - let make_empty_context ?(root = "/tmp") () = - let open Lwt_syntax in - let context_promise = - let+ index = Tezos_context_memory.Context_binary.init root in - Tezos_context_memory.Context_binary.empty index - in - match Lwt.state context_promise with - | Lwt.Return result -> result - | Lwt.Fail exn -> raise exn - | Lwt.Sleep -> - (* The in-memory context should never block *) - assert false + let make_empty_context = + Tezos_context_memory.Context_binary.make_empty_context end diff --git a/src/proto_017_PtNairob/lib_sc_rollup/context_helpers.mli b/src/proto_017_PtNairob/lib_sc_rollup/context_helpers.mli index 35ba7e64cf5a..a7611201c86d 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup/context_helpers.mli +++ b/src/proto_017_PtNairob/lib_sc_rollup/context_helpers.mli @@ -22,6 +22,32 @@ (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) +open Protocol.Alpha_context + +module type P = sig + module Tree : + Tezos_context_sigs.Context.TREE + with type key = string list + and type value = bytes + + type tree = Tree.tree + + val hash_tree : tree -> Sc_rollup.State_hash.t + + type proof + + val proof_encoding : proof Data_encoding.t + + val proof_before : proof -> Sc_rollup.State_hash.t + + val proof_after : proof -> Sc_rollup.State_hash.t + + val verify_proof : + proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t + + val produce_proof : + Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t +end (** [In_memory] is a context that can be used to instantiate an Arith or Wasm PVM. It's signature is @@ -29,8 +55,10 @@ {!Protocol.Alpha_context.Sc_rollup.Wasm_2_0_0PVM.P} *) module In_memory : sig include - Protocol.Alpha_context.Sc_rollup.ArithPVM.P - with type proof = + P + with type Tree.tree = Tezos_context_memory.Context_binary.tree + and type Tree.t = Tezos_context_memory.Context_binary.t + and type proof = Tezos_context_memory.Context.Proof.tree Tezos_context_memory.Context.Proof.t diff --git a/src/proto_017_PtNairob/lib_sc_rollup/pvm_in_memory.ml b/src/proto_017_PtNairob/lib_sc_rollup/pvm_in_memory.ml index eedebb959617..e626aa543a96 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup/pvm_in_memory.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup/pvm_in_memory.ml @@ -27,11 +27,11 @@ open Protocol.Alpha_context module type S = Sc_rollup.PVM.S - with type context = Context_helpers.In_memory.Tree.t - and type state = Context_helpers.In_memory.tree + with type context = Tezos_context_memory.Context_binary.t + and type state = Tezos_context_memory.Context_binary.tree and type proof = - Tezos_context_memory.Context.Proof.tree - Tezos_context_memory.Context.Proof.t + Tezos_context_memory.Context_binary.Proof.tree + Tezos_context_memory.Context_binary.Proof.t module Arith : S = Sc_rollup.ArithPVM.Make (Context_helpers.In_memory) diff --git a/src/proto_017_PtNairob/lib_sc_rollup/pvm_in_memory.mli b/src/proto_017_PtNairob/lib_sc_rollup/pvm_in_memory.mli index 3871cb4c4a9f..c0ae57cf3e9f 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup/pvm_in_memory.mli +++ b/src/proto_017_PtNairob/lib_sc_rollup/pvm_in_memory.mli @@ -27,11 +27,11 @@ open Protocol.Alpha_context module type S = Sc_rollup.PVM.S - with type context = Context_helpers.In_memory.Tree.t - and type state = Context_helpers.In_memory.tree + with type context = Tezos_context_memory.Context_binary.t + and type state = Tezos_context_memory.Context_binary.tree and type proof = - Tezos_context_memory.Context.Proof.tree - Tezos_context_memory.Context.Proof.t + Tezos_context_memory.Context_binary.Proof.tree + Tezos_context_memory.Context_binary.Proof.t (** [Arith]: Arith PVM with an in memory context {!Tezos_context_memory}. *) module Arith : S -- GitLab From ea434b9152ee9ef06912f5ac91c7453a3d7f039f Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Wed, 24 May 2023 09:58:30 +0200 Subject: [PATCH 4/4] proto/soru: add generic pvm context sig --- .../tezos_scoru_wasm_regressions.ml | 2 +- .../lib_protocol/alpha_context.mli | 75 ++++++------------- .../lib_protocol/sc_rollup_PVM_sig.ml | 20 +++++ .../lib_protocol/sc_rollup_arith.ml | 26 +------ .../lib_protocol/sc_rollup_arith.mli | 24 +----- .../sc_rollup_machine_no_proofs.ml | 3 - .../lib_protocol/sc_rollup_wasm.ml | 24 +----- .../lib_protocol/sc_rollup_wasm.mli | 25 +------ .../lib_sc_rollup/context_helpers.ml | 28 ------- .../lib_sc_rollup/context_helpers.mli | 30 +------- 10 files changed, 54 insertions(+), 203 deletions(-) diff --git a/src/lib_scoru_wasm/regressions/tezos_scoru_wasm_regressions.ml b/src/lib_scoru_wasm/regressions/tezos_scoru_wasm_regressions.ml index 8528e7626f47..38e09eb382e4 100644 --- a/src/lib_scoru_wasm/regressions/tezos_scoru_wasm_regressions.ml +++ b/src/lib_scoru_wasm/regressions/tezos_scoru_wasm_regressions.ml @@ -53,7 +53,7 @@ module Prover = struct end module WASM_P : - Alpha_context.Sc_rollup.Wasm_2_0_0PVM.P + Alpha_context.Sc_rollup.Generic_pvm_context_sig with type Tree.t = Context_binary.t and type Tree.tree = Context_binary.tree and type Tree.key = string list diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 4357862cff42..935006bc2158 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3130,6 +3130,27 @@ module Sc_rollup : sig | Dissection_invalid_successive_states_shape end + module type Generic_pvm_context_sig = sig + module Tree : + Context.TREE with type key = string list and type value = bytes + + type tree = Tree.tree + + type proof + + val proof_encoding : proof Data_encoding.t + + val proof_before : proof -> Sc_rollup_repr.State_hash.t + + val proof_after : proof -> Sc_rollup_repr.State_hash.t + + val verify_proof : + proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t + + val produce_proof : + Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t + end + module PVM : sig type boot_sector = string @@ -3240,33 +3261,7 @@ module Sc_rollup : sig val genesis_state_hash_of : boot_sector:string -> Kind.t -> State_hash.t Lwt.t module ArithPVM : sig - module type P = sig - module Tree : - Context.TREE with type key = string list and type value = bytes - - type tree = Tree.tree - - val hash_tree : tree -> State_hash.t - - type proof - - val proof_encoding : proof Data_encoding.t - - val proof_before : proof -> State_hash.t - - val proof_after : proof -> State_hash.t - - val verify_proof : - proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t - - val produce_proof : - Tree.t -> - tree -> - (tree -> (tree * 'a) Lwt.t) -> - (proof * 'a) option Lwt.t - end - - module Make (C : P) : sig + module Make (C : Generic_pvm_context_sig) : sig include PVM.S with type context = C.Tree.t @@ -3310,33 +3305,9 @@ module Sc_rollup : sig val well_known_reveal_hash : Sc_rollup_reveal_hash.t - module type P = sig - module Tree : - Context.TREE with type key = string list and type value = bytes - - type tree = Tree.tree - - type proof - - val proof_encoding : proof Data_encoding.t - - val proof_before : proof -> State_hash.t - - val proof_after : proof -> State_hash.t - - val verify_proof : - proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t - - val produce_proof : - 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 - module Make (Wasm_backend : Make_wasm) (C : P) : sig + module Make (Wasm_backend : Make_wasm) (C : Generic_pvm_context_sig) : sig include PVM.S with type context = C.Tree.t diff --git a/src/proto_alpha/lib_protocol/sc_rollup_PVM_sig.ml b/src/proto_alpha/lib_protocol/sc_rollup_PVM_sig.ml index 296f0a41988b..bf4bdd7138b9 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_PVM_sig.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_PVM_sig.ml @@ -553,3 +553,23 @@ module type S = sig val insert_failure : state -> state Lwt.t end end + +module type Generic_pvm_context_sig = sig + module Tree : Context.TREE with type key = string list and type value = bytes + + type tree = Tree.tree + + type proof + + val proof_encoding : proof Data_encoding.t + + val proof_before : proof -> Sc_rollup_repr.State_hash.t + + val proof_after : proof -> Sc_rollup_repr.State_hash.t + + val verify_proof : + proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t + + val produce_proof : + Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t +end diff --git a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml index 5a2a9ee32fc9..287354f712d2 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml @@ -91,28 +91,6 @@ let () = (function Arith_proof_production_failed -> Some () | _ -> None) (fun () -> Arith_proof_production_failed) -module type P = sig - module Tree : Context.TREE with type key = string list and type value = bytes - - type tree = Tree.tree - - val hash_tree : tree -> State_hash.t - - type proof - - val proof_encoding : proof Data_encoding.t - - val proof_before : proof -> State_hash.t - - val proof_after : proof -> State_hash.t - - val verify_proof : - proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t - - val produce_proof : - Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t -end - module type S = sig include PS.S @@ -161,7 +139,7 @@ module type S = sig val get_is_stuck : state -> string option Lwt.t end -module Make (Context : P) : +module Make (Context : Sc_rollup_PVM_sig.Generic_pvm_context_sig) : S with type context = Context.Tree.t and type state = Context.tree @@ -1751,8 +1729,6 @@ module Protocol_implementation = Make (struct type tree = Context.tree - let hash_tree t = State_hash.context_hash_to_state_hash (Tree.hash t) - type proof = Context.Proof.tree Context.Proof.t let verify_proof p f = diff --git a/src/proto_alpha/lib_protocol/sc_rollup_arith.mli b/src/proto_alpha/lib_protocol/sc_rollup_arith.mli index 74e271408872..9bd8f8da76b2 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_arith.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_arith.mli @@ -165,29 +165,7 @@ module Protocol_implementation : tree structure). *) val reference_initial_state_hash : Sc_rollup_repr.State_hash.t -module type P = sig - module Tree : Context.TREE with type key = string list and type value = bytes - - type tree = Tree.tree - - val hash_tree : tree -> Sc_rollup_repr.State_hash.t - - type proof - - val proof_encoding : proof Data_encoding.t - - val proof_before : proof -> Sc_rollup_repr.State_hash.t - - val proof_after : proof -> Sc_rollup_repr.State_hash.t - - val verify_proof : - proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t - - val produce_proof : - Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t -end - -module Make (Context : P) : +module Make (Context : Sc_rollup_PVM_sig.Generic_pvm_context_sig) : S with type context = Context.Tree.t and type state = Context.tree 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 index 6885b4b381d0..c08158f9fb71 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_machine_no_proofs.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_machine_no_proofs.ml @@ -43,9 +43,6 @@ module Context_no_proofs = struct 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) -> . diff --git a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml index b17f75e4cc16..e7342c101df2 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml @@ -129,26 +129,6 @@ module V2_0_0 = struct module type Make_wasm = module type of Wasm_2_0_0.Make - module type P = sig - module Tree : TreeS - - type tree = Tree.tree - - type proof - - val proof_encoding : proof Data_encoding.t - - val proof_before : proof -> State_hash.t - - val proof_after : proof -> State_hash.t - - val verify_proof : - proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t - - val produce_proof : - Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t - end - module type S = sig include Sc_rollup_PVM_sig.S @@ -180,7 +160,9 @@ module V2_0_0 = struct 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) : + module Make + (Make_backend : Make_wasm) + (Context : Sc_rollup_PVM_sig.Generic_pvm_context_sig) : S with type context = Context.Tree.t and type state = Context.tree diff --git a/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli b/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli index 556c9cef0a97..11b9bb2ec318 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli @@ -64,31 +64,12 @@ module V2_0_0 : sig Raw_level_repr.t -> state -> Sc_rollup_PVM_sig.output list Lwt.t end - module type P = sig - module Tree : - Context.TREE with type key = string list and type value = bytes - - type tree = Tree.tree - - type proof - - val proof_encoding : proof Data_encoding.t - - val proof_before : proof -> Sc_rollup_repr.State_hash.t - - val proof_after : proof -> Sc_rollup_repr.State_hash.t - - val verify_proof : - proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t - - val produce_proof : - 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 (Lib_scoru_Wasm : Make_wasm) (Context : P) : + module Make + (Lib_scoru_Wasm : Make_wasm) + (Context : Sc_rollup_PVM_sig.Generic_pvm_context_sig) : S with type context = Context.Tree.t and type state = Context.tree diff --git a/src/proto_alpha/lib_sc_rollup/context_helpers.ml b/src/proto_alpha/lib_sc_rollup/context_helpers.ml index a0ff2c67dde4..af5e6a6d08f8 100644 --- a/src/proto_alpha/lib_sc_rollup/context_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup/context_helpers.ml @@ -22,32 +22,6 @@ (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) -open Protocol.Alpha_context - -module type P = sig - module Tree : - Tezos_context_sigs.Context.TREE - with type key = string list - and type value = bytes - - type tree = Tree.tree - - val hash_tree : tree -> Sc_rollup.State_hash.t - - type proof - - val proof_encoding : proof Data_encoding.t - - val proof_before : proof -> Sc_rollup.State_hash.t - - val proof_after : proof -> Sc_rollup.State_hash.t - - val verify_proof : - proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t - - val produce_proof : - Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t -end module In_memory = struct open Tezos_context_memory @@ -68,8 +42,6 @@ module In_memory = struct type proof = Context_binary.Proof.tree Context_binary.Proof.t - let hash_tree _ = assert false - let verify_proof p f = Lwt.map Result.to_option (Context_binary.verify_tree_proof p f) diff --git a/src/proto_alpha/lib_sc_rollup/context_helpers.mli b/src/proto_alpha/lib_sc_rollup/context_helpers.mli index a7611201c86d..fed32af2901e 100644 --- a/src/proto_alpha/lib_sc_rollup/context_helpers.mli +++ b/src/proto_alpha/lib_sc_rollup/context_helpers.mli @@ -24,38 +24,12 @@ (*****************************************************************************) open Protocol.Alpha_context -module type P = sig - module Tree : - Tezos_context_sigs.Context.TREE - with type key = string list - and type value = bytes - - type tree = Tree.tree - - val hash_tree : tree -> Sc_rollup.State_hash.t - - type proof - - val proof_encoding : proof Data_encoding.t - - val proof_before : proof -> Sc_rollup.State_hash.t - - val proof_after : proof -> Sc_rollup.State_hash.t - - val verify_proof : - proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t - - val produce_proof : - Tree.t -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t -end - (** [In_memory] is a context that can be used to instantiate an Arith or Wasm PVM. It's signature is - {!Protocol.Alpha_context.Sc_rollup.ArithPVM.P} = - {!Protocol.Alpha_context.Sc_rollup.Wasm_2_0_0PVM.P} *) + {!Protocol.Alpha_context.Sc_rollup.Generic_pvm_context_sig} *) module In_memory : sig include - P + Sc_rollup.Generic_pvm_context_sig with type Tree.tree = Tezos_context_memory.Context_binary.tree and type Tree.t = Tezos_context_memory.Context_binary.t and type proof = -- GitLab