From 0e24d8a58424a61e22b34cfad8ae76257cfb5587 Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Wed, 26 Jul 2023 14:36:30 +0200 Subject: [PATCH 1/2] WASM/Debugger: wrap inbox messages --- src/bin_wasm_debugger/messages.ml | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/bin_wasm_debugger/messages.ml b/src/bin_wasm_debugger/messages.ml index ea26d609f358..325e0e9e5fe9 100644 --- a/src/bin_wasm_debugger/messages.ml +++ b/src/bin_wasm_debugger/messages.ml @@ -44,7 +44,8 @@ let parsed_string_encoding = `Internal Transfer` and `External`. In the case of `Internal Transfer`, only the Micheline payload is mandatory, the other field are taken from the default one if they are missing. *) -let input_encoding default_sender default_source default_destination = +let input_encoding default_sender default_source default_destination : + [< `Inbox_message of Sc_rollup.Inbox_message.t] Data_encoding.encoding = let open Data_encoding in union [ @@ -63,23 +64,26 @@ let input_encoding default_sender default_source default_destination = Sc_rollup_repr.Address.encoding default_destination)) (function - | Sc_rollup.Inbox_message.( - Internal (Transfer {payload; sender; source; destination})) -> + | `Inbox_message + Sc_rollup.Inbox_message.( + Internal (Transfer {payload; sender; source; destination})) -> Some (payload, sender, source, destination) | _ -> None) (fun (payload, sender, source, destination) -> - Internal (Transfer {payload; sender; source; destination})); + `Inbox_message + (Internal (Transfer {payload; sender; source; destination}))); case (Tag 1) ~title:"External" (obj1 (req "external" string)) (function - | Sc_rollup.Inbox_message.External msg -> + | `Inbox_message (Sc_rollup.Inbox_message.External msg) -> let (`Hex msg) = Hex.of_string msg in Some msg - | Internal _ -> None) + | _ -> None) (fun msg -> - External (Hex.to_string (`Hex msg) |> Option.value ~default:"")); + `Inbox_message + (External (Hex.to_string (`Hex msg) |> Option.value ~default:""))); ] (* Represent a set of inboxes, i.e. a set of set of inputs. The position of an @@ -107,11 +111,12 @@ let parse_inboxes inputs Config.{sender; source; destination; _} = List.map_es (fun inputs -> List.map_es - (fun input -> - Protocol.Alpha_context.Sc_rollup.Inbox_message.( - serialize input - |> Result.map unsafe_to_string - |> Environment.wrap_tzresult |> Lwt.return)) + (function + | `Inbox_message input -> + Protocol.Alpha_context.Sc_rollup.Inbox_message.( + serialize input + |> Result.map unsafe_to_string + |> Environment.wrap_tzresult |> Lwt.return)) inputs) full_inputs | Error e -> Error_monad.failwith "%s" e -- GitLab From b4644caae09646950ca3cdb2b1c7b71f147615e9 Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Wed, 26 Jul 2023 14:41:18 +0200 Subject: [PATCH 2/2] WASM/Debbuger: allow serialized messages --- CHANGES.rst | 3 +++ src/bin_wasm_debugger/messages.ml | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index e84b9dd15d7c..726047763c39 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -348,6 +348,9 @@ Smart Rollup WASM Debugger - Added option ``--no-reboot`` to the ``profile`` command to profile a single ``kernel_run``. - Improved profiling output for consecutive kernel runs. +- Allow serialized messages in inputs: ``{ "serialized": "01..." }``, instead + of only external and internal transfers. This allows to inject arbitrary + messages in the rollup. (MR :gl:`!9613`) Data Availability Committee (DAC) ---------------------------------- diff --git a/src/bin_wasm_debugger/messages.ml b/src/bin_wasm_debugger/messages.ml index 325e0e9e5fe9..6c944837a154 100644 --- a/src/bin_wasm_debugger/messages.ml +++ b/src/bin_wasm_debugger/messages.ml @@ -43,9 +43,14 @@ let parsed_string_encoding = alternative encoding for {Sc_rollup_inbox_message_repr.t} that only encodes `Internal Transfer` and `External`. In the case of `Internal Transfer`, only the Micheline payload is mandatory, the other field are taken from the - default one if they are missing. *) + default one if they are missing. + + It can also take already serialized messages, if the input does not belong + to the two cases above. This allows to inject arbitrary messages in + the rollup. *) let input_encoding default_sender default_source default_destination : - [< `Inbox_message of Sc_rollup.Inbox_message.t] Data_encoding.encoding = + [< `Inbox_message of Sc_rollup.Inbox_message.t | `Serialized of string] + Data_encoding.encoding = let open Data_encoding in union [ @@ -84,6 +89,17 @@ let input_encoding default_sender default_source default_destination : (fun msg -> `Inbox_message (External (Hex.to_string (`Hex msg) |> Option.value ~default:""))); + case + (Tag 2) + ~title:"Serialized" + (obj1 (req "serialized" string)) + (function + | `Serialized msg -> + let (`Hex msg) = Hex.of_string msg in + Some msg + | _ -> None) + (fun msg -> + `Serialized (Hex.to_string (`Hex msg) |> Option.value ~default:"")); ] (* Represent a set of inboxes, i.e. a set of set of inputs. The position of an @@ -116,7 +132,8 @@ let parse_inboxes inputs Config.{sender; source; destination; _} = Protocol.Alpha_context.Sc_rollup.Inbox_message.( serialize input |> Result.map unsafe_to_string - |> Environment.wrap_tzresult |> Lwt.return)) + |> Environment.wrap_tzresult |> Lwt.return) + | `Serialized input -> Lwt.return_ok input) inputs) full_inputs | Error e -> Error_monad.failwith "%s" e -- GitLab