From a86a09b014e025f9631163688bc0591a63399c46 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Wed, 7 Sep 2022 09:07:44 +0200 Subject: [PATCH 1/3] proto/scoru: input must be defined before inbox In order to replace Sc_rollup_PVM_sem.input by input in the signature of function in `alpha_context.mli` I had to reorganized the order of the module. Now the `Message` and the type `input` are defined before `Inbox` and the function `produce_proof` and `verify_proof` can use the correct type I renamed `Message` to `Inbox_message` to not confuse it with `Outbox.Message` --- src/proto_alpha/bin_sc_rollup_node/context.ml | 1 + .../bin_sc_rollup_node/context.mli | 2 +- src/proto_alpha/bin_sc_rollup_node/inbox.ml | 8 +- .../bin_sc_rollup_node/interpreter.ml | 4 +- src/proto_alpha/bin_sc_rollup_node/store.ml | 4 +- src/proto_alpha/lib_protocol/alpha_context.ml | 2 +- .../lib_protocol/alpha_context.mli | 80 +++++++++---------- .../sc_rollup_management_protocol.ml | 4 +- .../sc_rollup_management_protocol.mli | 4 +- .../test/integration/test_sc_rollup_wasm.ml | 2 +- .../test/pbt/test_refutation_game.ml | 2 +- .../test_sc_rollup_management_protocol.ml | 10 +-- 12 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/proto_alpha/bin_sc_rollup_node/context.ml b/src/proto_alpha/bin_sc_rollup_node/context.ml index d1093b01c8b1..d4ff0301ba51 100644 --- a/src/proto_alpha/bin_sc_rollup_node/context.ml +++ b/src/proto_alpha/bin_sc_rollup_node/context.ml @@ -175,6 +175,7 @@ end module Inbox = struct include Sc_rollup.Inbox + module Message = Sc_rollup.Inbox_message include Sc_rollup.Inbox.Make_hashing_scheme (struct include diff --git a/src/proto_alpha/bin_sc_rollup_node/context.mli b/src/proto_alpha/bin_sc_rollup_node/context.mli index ae3cd8e94fd5..5e9aa163dd26 100644 --- a/src/proto_alpha/bin_sc_rollup_node/context.mli +++ b/src/proto_alpha/bin_sc_rollup_node/context.mli @@ -146,7 +146,7 @@ end module Inbox : sig type t = Sc_rollup.Inbox.t - module Message : module type of Sc_rollup.Inbox.Message + module Message : module type of Sc_rollup.Inbox_message val pp : Format.formatter -> t -> unit diff --git a/src/proto_alpha/bin_sc_rollup_node/inbox.ml b/src/proto_alpha/bin_sc_rollup_node/inbox.ml index 65eb6bd66be2..31f3f208cfe8 100644 --- a/src/proto_alpha/bin_sc_rollup_node/inbox.ml +++ b/src/proto_alpha/bin_sc_rollup_node/inbox.ml @@ -114,7 +114,7 @@ let get_messages Node_context.{l1_ctxt; rollup_address; _} head = when Sc_rollup.Address.(rollup = rollup_address) -> let messages = List.map - (fun message -> Sc_rollup.Inbox.Message.External message) + (fun message -> Sc_rollup.Inbox_message.External message) messages in List.rev_append messages accu @@ -137,8 +137,8 @@ let get_messages Node_context.{l1_ctxt; rollup_address; _} head = let+ payload = Environment.wrap_tzresult @@ Script_repr.force_decode parameters in - let message = Sc_rollup.Inbox.Message.{payload; sender; source} in - Sc_rollup.Inbox.Message.Internal message :: accu + let message = Sc_rollup.Inbox_message.{payload; sender; source} in + Sc_rollup.Inbox_message.Internal message :: accu | _ -> return accu in let*? messages = @@ -194,7 +194,7 @@ let process_head node_ctxt Layer1.(Head {level; hash = head_hash} as head) = lift @@ let*? level = Raw_level.of_int32 level in let*? messages = - List.map_e Sc_rollup.Inbox.Message.serialize messages + List.map_e Sc_rollup.Inbox_message.serialize messages in if messages = [] then return (history, inbox, ctxt) else diff --git a/src/proto_alpha/bin_sc_rollup_node/interpreter.ml b/src/proto_alpha/bin_sc_rollup_node/interpreter.ml index 6ebad14c0cb8..76e058a80523 100644 --- a/src/proto_alpha/bin_sc_rollup_node/interpreter.ml +++ b/src/proto_alpha/bin_sc_rollup_node/interpreter.ml @@ -106,7 +106,7 @@ module Make (PVM : Pvm.S) : S with module PVM = PVM = struct (** [mutate input] corrupts the payload of [input] for testing purposes. *) let mutate input = - let payload = Inbox.Message.unsafe_of_string "0xC4C4" in + let payload = Sc_rollup.Inbox_message.unsafe_of_string "0xC4C4" in {input with Sc_rollup.payload} (** [feed_input level message_index ~fuel ~failing_ticks state @@ -163,7 +163,7 @@ module Make (PVM : Pvm.S) : S with module PVM = PVM = struct List.fold_left_i_es (fun message_counter (state, fuel) message -> let*? payload = - Sc_rollup.Inbox.Message.( + Sc_rollup.Inbox_message.( message |> serialize |> Environment.wrap_tzresult) in let input = diff --git a/src/proto_alpha/bin_sc_rollup_node/store.ml b/src/proto_alpha/bin_sc_rollup_node/store.ml index 2aab02f4ac21..8670a2dfe964 100644 --- a/src/proto_alpha/bin_sc_rollup_node/store.ml +++ b/src/proto_alpha/bin_sc_rollup_node/store.ml @@ -293,10 +293,10 @@ module Messages = Make_append_only_map (struct let string_of_key = Block_hash.to_b58check - type value = Sc_rollup.Inbox.Message.t list + type value = Sc_rollup.Inbox_message.t list let value_encoding = - Data_encoding.(list @@ dynamic_size Sc_rollup.Inbox.Message.encoding) + Data_encoding.(list @@ dynamic_size Sc_rollup.Inbox_message.encoding) end) (** Inbox state for each block *) diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 43d36fd849f9..92decb272643 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -59,11 +59,11 @@ module Sc_rollup = struct include Sc_rollup_PVM_sig module ArithPVM = Sc_rollup_arith module Wasm_2_0_0PVM = Sc_rollup_wasm.V2_0_0 + module Inbox_message = Sc_rollup_inbox_message_repr module Inbox = struct include Sc_rollup_inbox_repr include Sc_rollup_inbox_storage - module Message = Sc_rollup_inbox_message_repr module Internal_for_tests = struct include Sc_rollup_inbox_repr.Internal_for_tests diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 988d6ad40990..8c625ea7e211 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2917,29 +2917,48 @@ module Sc_rollup : sig val hash_string : unreachable -> t end - module Inbox : sig - type t + (** See {!Sc_rollup_inbox_message_repr}. *) + module Inbox_message : sig + type internal_inbox_message = { + payload : Script.expr; + sender : Contract_hash.t; + source : public_key_hash; + } - (** See {!Sc_rollup_inbox_message_repr}. *) - module Message : sig - type internal_inbox_message = { - payload : Script.expr; - sender : Contract_hash.t; - source : public_key_hash; - } + type t = Internal of internal_inbox_message | External of string - type t = Internal of internal_inbox_message | External of string + type serialized = private string - type serialized = private string + val encoding : t Data_encoding.t - val encoding : t Data_encoding.t + val unsafe_of_string : string -> serialized - val unsafe_of_string : string -> serialized + val serialize : t -> serialized tzresult - val serialize : t -> serialized tzresult + val deserialize : serialized -> t tzresult + end - val deserialize : serialized -> t tzresult - end + type input = { + inbox_level : Raw_level.t; + message_counter : Z.t; + payload : Inbox_message.serialized; + } + + val input_equal : input -> input -> bool + + val input_encoding : input Data_encoding.t + + type input_request = + | No_input_required + | Initial + | First_after of Raw_level.t * Z.t + + val input_request_encoding : input_request Data_encoding.t + + val input_request_equal : input_request -> input_request -> bool + + module Inbox : sig + type t val pp : Format.formatter -> t -> unit @@ -2985,7 +3004,7 @@ module Sc_rollup : sig History.t -> t -> Raw_level.t -> - Message.serialized list -> + Inbox_message.serialized list -> tree option -> (tree * History.t * t) tzresult Lwt.t @@ -2993,7 +3012,7 @@ module Sc_rollup : sig inbox_context -> t -> Raw_level.t -> - Message.serialized list -> + Inbox_message.serialized list -> tree option -> (tree * t) tzresult Lwt.t @@ -3032,14 +3051,14 @@ module Sc_rollup : sig Raw_level.t * Z.t -> history_proof -> proof -> - Sc_rollup_PVM_sig.input option tzresult Lwt.t + input option tzresult Lwt.t val produce_proof : inbox_context -> History.t -> history_proof -> Raw_level.t * Z.t -> - (proof * Sc_rollup_PVM_sig.input option) tzresult Lwt.t + (proof * input option) tzresult Lwt.t val empty : inbox_context -> Sc_rollup_repr.t -> Raw_level.t -> t Lwt.t @@ -3105,25 +3124,6 @@ module Sc_rollup : sig val inbox : context -> rollup -> (t * context) tzresult Lwt.t end - type input = { - inbox_level : Raw_level.t; - message_counter : Z.t; - payload : Inbox.Message.serialized; - } - - val input_equal : input -> input -> bool - - val input_encoding : input Data_encoding.t - - type input_request = - | No_input_required - | Initial - | First_after of Raw_level.t * Z.t - - val input_request_encoding : input_request Data_encoding.t - - val input_request_equal : input_request -> input_request -> bool - module Outbox : sig (** See {!Sc_rollup_outbox_message_repr}. *) module Message : sig @@ -3457,7 +3457,7 @@ module Sc_rollup : sig Raw_level.t -> pvm_name:string -> t -> - (bool * Sc_rollup_PVM_sig.input option) tzresult Lwt.t + (bool * input option) tzresult Lwt.t val produce : (module PVM_with_context_and_state) -> Raw_level.t -> t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml index 0118f102407f..575a60114f3e 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml @@ -64,7 +64,7 @@ let make_internal_inbox_message ctxt ty ~payload ~sender ~source = payload in let payload = Micheline.strip_locations payload in - (Sc_rollup.Inbox.Message.Internal {payload; sender; source}, ctxt) + (Sc_rollup.Inbox_message.Internal {payload; sender; source}, ctxt) let transactions_batch_of_internal ctxt transactions = let open Lwt_tzresult_syntax in @@ -167,5 +167,5 @@ module Internal_for_tests = struct Sc_rollup.Outbox.Message.Internal_for_tests.serialize output_message_internal - let deserialize_inbox_message = Sc_rollup.Inbox.Message.deserialize + let deserialize_inbox_message = Sc_rollup.Inbox_message.deserialize end diff --git a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli index 688fd402cd86..817068a8a220 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli @@ -69,7 +69,7 @@ val make_internal_inbox_message : payload:'a -> sender:Contract_hash.t -> source:public_key_hash -> - (Sc_rollup.Inbox.Message.t * context) tzresult Lwt.t + (Sc_rollup.Inbox_message.t * context) tzresult Lwt.t (** [outbox_message_of_outbox_message_repr ctxt msg] returns a typed version of of the given outbox message [msg]. @@ -108,5 +108,5 @@ module Internal_for_tests : sig (** [deserialize_inbox_message bs] decodes an inbox message from the given data [bs]. *) val deserialize_inbox_message : - Sc_rollup.Inbox.Message.serialized -> Sc_rollup.Inbox.Message.t tzresult + Sc_rollup.Inbox_message.serialized -> Sc_rollup.Inbox_message.t tzresult end 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 02f3faa28eb1..a56433f603b7 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 @@ -237,7 +237,7 @@ let should_boot_complete_boot_sector boot_sector () = return_unit let arbitrary_input i payload = - match Sc_rollup.Inbox.Message.serialize (External payload) with + match Sc_rollup.Inbox_message.serialize (External payload) with | Ok payload -> Sc_rollup. { diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml b/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml index 795bc63b1510..d111bd459931 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_refutation_game.ml @@ -65,7 +65,7 @@ let number_of_ticks_of_int64_exn ?(__LOC__ = __LOC__) n = let make_external_inbox_message str = WithExceptions.Result.get_ok ~loc:__LOC__ - Inbox.Message.(External str |> serialize) + Inbox_message.(External str |> serialize) let game_status_of_refute_op_result = function | [ diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml index 5cd6c391bd54..186f88bb2f88 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml @@ -40,14 +40,14 @@ let check_encode_decode_inbox_message message = let open Lwt_result_syntax in let open Sc_rollup_management_protocol in let*? bytes = - Environment.wrap_tzresult @@ Sc_rollup.Inbox.Message.serialize message + Environment.wrap_tzresult @@ Sc_rollup.Inbox_message.serialize message in let*? message' = Environment.wrap_tzresult @@ Internal_for_tests.deserialize_inbox_message bytes in let*? bytes' = - Environment.wrap_tzresult @@ Sc_rollup.Inbox.Message.serialize message' + Environment.wrap_tzresult @@ Sc_rollup.Inbox_message.serialize message' in Assert.equal_string ~loc:__LOC__ (bytes :> string) (bytes' :> string) @@ -144,10 +144,10 @@ let test_encode_decode_internal_inbox_message () = let test_encode_decode_external_inbox_message () = let open Lwt_result_syntax in let assert_prefix message = - let inbox_message = Sc_rollup.Inbox.Message.External message in + let inbox_message = Sc_rollup.Inbox_message.External message in let*? real_encoding = Environment.wrap_tzresult - @@ Sc_rollup.Inbox.Message.serialize inbox_message + @@ Sc_rollup.Inbox_message.serialize inbox_message in let real_encoding = (real_encoding :> string) in (* The prefix consists of a tag (0 for internal, 1 for external). *) @@ -167,7 +167,7 @@ let test_encode_decode_external_inbox_message () = let* () = assert_prefix "0123456789" in let* () = assert_prefix (String.init 256 (Fun.const 'A')) in let assert_encoding_failure message = - let inbox_message = Sc_rollup.Inbox.Message.External message in + let inbox_message = Sc_rollup.Inbox_message.External message in let*! res = check_encode_decode_inbox_message inbox_message in assert_encoding_failure ~loc:__LOC__ res in -- GitLab From 25a6567e26e61e635ed6e84c02eccc988579c8f5 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Wed, 7 Sep 2022 09:23:08 +0200 Subject: [PATCH 2/3] proto/scoru: use Alpha_context type --- src/proto_alpha/lib_protocol/alpha_context.mli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 8c625ea7e211..77d6c31be56c 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3017,7 +3017,7 @@ module Sc_rollup : sig (tree * t) tzresult Lwt.t val get_message_payload : - tree -> Z.t -> Sc_rollup_inbox_message_repr.serialized option Lwt.t + tree -> Z.t -> Inbox_message.serialized option Lwt.t val form_history_proof : inbox_context -> -- GitLab From 59d9fde6b71116a782476bad159da8317aee6ec3 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Wed, 7 Sep 2022 09:56:36 +0200 Subject: [PATCH 3/3] proto/scoru: remove unnecessary comment --- src/proto_alpha/lib_protocol/alpha_context.mli | 1 - 1 file changed, 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 77d6c31be56c..48b4e04fb96b 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3062,7 +3062,6 @@ module Sc_rollup : sig val empty : inbox_context -> Sc_rollup_repr.t -> Raw_level.t -> t Lwt.t - (*xx*) module Internal_for_tests : sig val eq_tree : tree -> tree -> bool -- GitLab