diff --git a/src/lib_protocol_environment/environment_V6.ml b/src/lib_protocol_environment/environment_V6.ml index 8418e886045c6bb059bae24d27d4c355619cb402..f38743620f8c41fa2defe0136b385e951a57150b 100644 --- a/src/lib_protocol_environment/environment_V6.ml +++ b/src/lib_protocol_environment/environment_V6.ml @@ -1083,12 +1083,14 @@ struct Wasm.set_input_step {inbox_level; message_counter} payload tree let get_output {outbox_level; message_index} (tree : Tree.tree) = + let open Lwt_syntax in let outbox_level = Tezos_protocol_environment_structs.V6.Bounded.Int32 .non_negative_of_legacy_non_negative outbox_level in - Wasm.get_output {outbox_level; message_index} tree + let+ payload = Wasm.get_output {outbox_level; message_index} tree in + match payload with Some payload -> payload | None -> "" let convert_input : Tezos_scoru_wasm.Wasm_pvm_sig.input_info -> input = function diff --git a/src/lib_protocol_environment/environment_V7.ml b/src/lib_protocol_environment/environment_V7.ml index 77607a11bea7072858d6cf218755aff00486f2b1..c7ba16ff74016fc37c08c8d4982e8e434fdff2c1 100644 --- a/src/lib_protocol_environment/environment_V7.ml +++ b/src/lib_protocol_environment/environment_V7.ml @@ -1076,7 +1076,10 @@ struct let set_input_step input payload (tree : Tree.tree) = Wasm.set_input_step input payload tree - let get_output output (tree : Tree.tree) = Wasm.get_output output tree + let get_output output (tree : Tree.tree) = + let open Lwt_syntax in + let+ payload = Wasm.get_output output tree in + match payload with Some payload -> payload | None -> "" let get_info (tree : Tree.tree) = let open Lwt_syntax in diff --git a/src/lib_protocol_environment/sigs/v8.ml b/src/lib_protocol_environment/sigs/v8.ml index 77af7ea6c7d63ba56bfbab08814ebb445386ab08..b22d772383c902770b19cc121e4cdc844afc249a 100644 --- a/src/lib_protocol_environment/sigs/v8.ml +++ b/src/lib_protocol_environment/sigs/v8.ml @@ -11790,7 +11790,7 @@ module Make val reveal_step : bytes -> Tree.tree -> Tree.tree Lwt.t - val get_output : output -> Tree.tree -> string Lwt.t + val get_output : output -> Tree.tree -> string option Lwt.t val get_info : Tree.tree -> info Lwt.t end diff --git a/src/lib_protocol_environment/sigs/v8/wasm_2_0_0.mli b/src/lib_protocol_environment/sigs/v8/wasm_2_0_0.mli index f163b28c8d6b99dcb0a3c359696952d5fc4cdab1..6a460f5db68b60e7f4a4f422a7c579f290ed8548 100644 --- a/src/lib_protocol_environment/sigs/v8/wasm_2_0_0.mli +++ b/src/lib_protocol_environment/sigs/v8/wasm_2_0_0.mli @@ -52,7 +52,7 @@ module Make val reveal_step : bytes -> Tree.tree -> Tree.tree Lwt.t - val get_output : output -> Tree.tree -> string Lwt.t + val get_output : output -> Tree.tree -> string option Lwt.t val get_info : Tree.tree -> info Lwt.t end diff --git a/src/lib_scoru_wasm/test/test_get_set.ml b/src/lib_scoru_wasm/test/test_get_set.ml index 77668c47944e708ccdb18cdd6bf60dcf4f32853a..8a3df8641d353a235570c50189647f9066624725 100644 --- a/src/lib_scoru_wasm/test/test_get_set.ml +++ b/src/lib_scoru_wasm/test/test_get_set.ml @@ -236,10 +236,15 @@ let test_get_output () = Output_buffer.set_level output 0l ; let* () = Output_buffer.set_value output @@ Bytes.of_string "hello" in let buffers = Eval.{input = Input_buffer.alloc (); output} in - let* tree = Tree_encoding_runner.encode buffers_encoding buffers tree in + let* tree = + Tree_encoding_runner.encode + (Tezos_tree_encoding.option buffers_encoding) + (Some buffers) + tree + in let output_info = make_output_info ~outbox_level:0 ~message_index:0 in let* payload = Wasm.get_output output_info tree in - assert (payload = "hello") ; + assert (payload = Some "hello") ; Lwt_result_syntax.return_unit let tests = diff --git a/src/lib_scoru_wasm/wasm_pvm.ml b/src/lib_scoru_wasm/wasm_pvm.ml index fcf9b3d8f5d0575dc03dfa2633d4b3e004ea21a2..b22967a63005bda975db5a2dd07c86ab255a545d 100644 --- a/src/lib_scoru_wasm/wasm_pvm.ml +++ b/src/lib_scoru_wasm/wasm_pvm.ml @@ -544,11 +544,20 @@ struct let open Wasm_pvm_sig in let {outbox_level; message_index} = output_info in let outbox_level = Bounded.Non_negative_int32.to_value outbox_level in - let* {output; _} = - Tree_encoding_runner.decode durable_buffers_encoding tree + let* candidate = + Tree_encoding_runner.decode + (Tezos_tree_encoding.option durable_buffers_encoding) + tree in - let+ payload = Wasm.Output_buffer.get output outbox_level message_index in - Bytes.to_string payload + try + match candidate with + | Some {output; _} -> + let+ payload = + Wasm.Output_buffer.get output outbox_level message_index + in + Some (Bytes.to_string payload) + | None -> Lwt.return None + with _ -> Lwt.return None let get_info tree = let open Lwt_syntax in diff --git a/src/lib_scoru_wasm/wasm_pvm_sig.ml b/src/lib_scoru_wasm/wasm_pvm_sig.ml index b4e8daf86e3fcd3f6c207b5447540288e365f9ac..6ce6d328202e5a5b383a21b01feba83586b7519f 100644 --- a/src/lib_scoru_wasm/wasm_pvm_sig.ml +++ b/src/lib_scoru_wasm/wasm_pvm_sig.ml @@ -117,7 +117,7 @@ module type S = sig output. The result is meant to be deserialized using [Sc_rollup_PVM_sem.output_encoding]. If the output is missing, this function may raise an exception. *) - val get_output : output_info -> tree -> string Lwt.t + val get_output : output_info -> tree -> string option Lwt.t (** [get_info] provides a typed view of the current machine state. Should not raise. *) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml index 5afc97ac6e4f706c8b5278c7a480bdfefc56af9d..f6f9a3e79dc9ef4f6607fefc1707aa9e1206ea0b 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml @@ -405,7 +405,7 @@ module V2_0_0 = struct let state_of_output_proof s = s.output_proof_state let has_output : PS.output -> bool Monad.t = function - | {outbox_level; message_index; message} -> + | {outbox_level; message_index; message} -> ( let open Monad.Syntax in let* s = get in let* result = @@ -423,7 +423,11 @@ module V2_0_0 = struct Sc_rollup_outbox_message_repr.encoding message in - return @@ Compare.String.(result = message_encoded) + return + @@ + match result with + | Some result -> Compare.String.(result = message_encoded) + | None -> false) let verify_output_proof p = let open Lwt_syntax in