From 18e1ec78d11cec04fe6f3e88b16e4a94850e413f Mon Sep 17 00:00:00 2001 From: Thomas Letan Date: Thu, 20 Oct 2022 10:04:26 +0200 Subject: [PATCH] WASM: Remove `rtype' from the input definition of the WASM PVM This is the leftover of a DAL design that is no longer planned, hence the removal. --- src/lib_scoru_wasm/host_funcs.ml | 18 ++++-------------- src/lib_scoru_wasm/host_funcs.mli | 17 ++++++++--------- .../test/helpers/ast_generators.ml | 3 +-- src/lib_scoru_wasm/test/test_init.ml | 2 +- src/lib_scoru_wasm/test/test_input.ml | 18 +----------------- src/lib_scoru_wasm/test/test_output.ml | 8 +------- src/lib_scoru_wasm/wasm_encoding.ml | 11 +++++------ src/lib_scoru_wasm/wasm_pvm.ml | 9 +-------- src/lib_webassembly/runtime/input_buffer.ml | 1 - src/lib_webassembly/runtime/input_buffer.mli | 7 +------ .../test/unit/test_sc_rollup_wasm.ml | 6 ++---- 11 files changed, 25 insertions(+), 75 deletions(-) diff --git a/src/lib_scoru_wasm/host_funcs.ml b/src/lib_scoru_wasm/host_funcs.ml index fd459ba2ffaa..4ea43f64d4be 100644 --- a/src/lib_scoru_wasm/host_funcs.ml +++ b/src/lib_scoru_wasm/host_funcs.ml @@ -109,13 +109,13 @@ let extract_error durable = function module Aux = struct let input_output_max_size = 4096 - let read_input ~input_buffer ~output_buffer ~memory ~rtype_offset - ~level_offset ~id_offset ~dst ~max_bytes = + let read_input ~input_buffer ~output_buffer ~memory ~level_offset ~id_offset + ~dst ~max_bytes = let open Lwt_result_syntax in let*! res = Lwt.catch (fun () -> - let*! {rtype; raw_level; message_counter; payload} = + let*! {raw_level; message_counter; payload} = Input_buffer.dequeue input_buffer in let input_size = Bytes.length payload in @@ -130,7 +130,6 @@ module Aux = struct let* () = Safe_access.store_bytes memory dst (Bytes.to_string payload) in - let* () = Safe_access.store_num memory rtype_offset 0l (I32 rtype) in let* () = Safe_access.store_num memory level_offset 0l (I32 raw_level) in @@ -334,14 +333,7 @@ let value i = Values.(Num (I32 i)) let read_input_type = let input_types = - Types. - [ - NumType I32Type; - NumType I32Type; - NumType I32Type; - NumType I32Type; - NumType I32Type; - ] + Types.[NumType I32Type; NumType I32Type; NumType I32Type; NumType I32Type] |> Vector.of_list in let output_types = Types.[NumType I32Type] |> Vector.of_list in @@ -355,7 +347,6 @@ let read_input = let open Lwt.Syntax in match inputs with | [ - Values.(Num (I32 rtype_offset)); Values.(Num (I32 level_offset)); Values.(Num (I32 id_offset)); Values.(Num (I32 dst)); @@ -367,7 +358,6 @@ let read_input = ~input_buffer ~output_buffer ~memory - ~rtype_offset ~level_offset ~id_offset ~dst diff --git a/src/lib_scoru_wasm/host_funcs.mli b/src/lib_scoru_wasm/host_funcs.mli index 8f99fedb92cf..f5eadcb3ae55 100644 --- a/src/lib_scoru_wasm/host_funcs.mli +++ b/src/lib_scoru_wasm/host_funcs.mli @@ -87,19 +87,18 @@ module Aux : sig num_bytes:int32 -> int32 Lwt.t - (** [aux_write_memory ~input_buffer ~module_inst ~rtype_offset - ~level_offset ~id_offset ~dst ~max_bytes] reads `input_buffer` - and writes its components to the memory of `module_inst` based - on the memory addreses offsets described. It also checks that - the input payload is no larger than `max_input` and crashes - with `input too large` otherwise. It returns the size of the - payload. Note also that, if the level increases this function also - updates the level of the output buffer and resets its id to zero.*) + (** [aux_write_memory ~input_buffer ~module_inst ~level_offset + ~id_offset ~dst ~max_bytes] reads `input_buffer` and writes its + components to the memory of `module_inst` based on the memory + addreses offsets described. It also checks that the input + payload is no larger than `max_input` and crashes with `input + too large` otherwise. It returns the size of the payload. Note + also that, if the level increases this function also updates + the level of the output buffer and resets its id to zero. *) val read_input : input_buffer:Tezos_webassembly_interpreter.Input_buffer.t -> output_buffer:Tezos_webassembly_interpreter.Output_buffer.t -> memory:Tezos_webassembly_interpreter.Instance.memory_inst -> - rtype_offset:int32 -> level_offset:int32 -> id_offset:int32 -> dst:int32 -> diff --git a/src/lib_scoru_wasm/test/helpers/ast_generators.ml b/src/lib_scoru_wasm/test/helpers/ast_generators.ml index 242849bc9eb7..5d98b500030d 100644 --- a/src/lib_scoru_wasm/test/helpers/ast_generators.ml +++ b/src/lib_scoru_wasm/test/helpers/ast_generators.ml @@ -629,11 +629,10 @@ and admin_instr_gen ~module_reg = let input_buffer_gen = let gen_message = - let* rtype = int32 in let* raw_level = int32 in let* message_counter = map Z.of_int small_nat in let+ payload = map Bytes.of_string (small_string ~gen:char) in - Input_buffer.{rtype; raw_level; message_counter; payload} + Input_buffer.{raw_level; message_counter; payload} in let* messages = vector_z_gen gen_message in let+ num_elements = small_nat in diff --git a/src/lib_scoru_wasm/test/test_init.ml b/src/lib_scoru_wasm/test/test_init.ml index e232b277d0f8..61810e6d5949 100644 --- a/src/lib_scoru_wasm/test/test_init.ml +++ b/src/lib_scoru_wasm/test/test_init.ml @@ -111,7 +111,7 @@ let test_imports () = {| (module (import "%s" "%s" - (func $%s (param i32 i32 i32 i32 i32) (result i32))) + (func $%s (param i32 i32 i32 i32) (result i32))) (memory 1) (export "mem"(memory 0)) (func (export "kernel_next") diff --git a/src/lib_scoru_wasm/test/test_input.ml b/src/lib_scoru_wasm/test/test_input.ml index 2756e9764fd3..3139945d61a2 100644 --- a/src/lib_scoru_wasm/test/test_input.ml +++ b/src/lib_scoru_wasm/test/test_input.ml @@ -43,7 +43,6 @@ let write_input () = Input_buffer.enqueue input { - rtype = 1l; raw_level = 2l; message_counter = Z.of_int 2; payload = Bytes.of_string "hello"; @@ -53,7 +52,6 @@ let write_input () = Input_buffer.enqueue input { - rtype = 1l; raw_level = 2l; message_counter = Z.of_int 3; payload = Bytes.of_string "hello"; @@ -66,7 +64,6 @@ let write_input () = Input_buffer.enqueue input { - rtype = 1l; raw_level = 2l; message_counter = Z.of_int 2; payload = Bytes.of_string "hello"; @@ -88,7 +85,6 @@ let read_input () = Input_buffer.enqueue input_buffer { - rtype = 1l; raw_level = 2l; message_counter = Z.of_int 2; payload = Bytes.of_string "hello"; @@ -100,7 +96,6 @@ let read_input () = ~input_buffer ~output_buffer ~memory - ~rtype_offset:0l ~level_offset:4l ~id_offset:10l ~dst:50l @@ -111,8 +106,6 @@ let read_input () = assert (output_id = Z.of_int (-1)) ; assert (Input_buffer.num_elements input_buffer = Z.zero) ; assert (result = 5l) ; - let* m = Memory.load_bytes memory 0l 1 in - assert (m = "\001") ; let* m = Memory.load_bytes memory 4l 1 in assert (m = "\002") ; let* m = Memory.load_bytes memory 10l 1 in @@ -133,7 +126,6 @@ let read_input_no_messages () = ~input_buffer ~output_buffer ~memory - ~rtype_offset:0l ~level_offset:4l ~id_offset:10l ~dst:50l @@ -153,7 +145,6 @@ let read_input_too_large () = Input_buffer.enqueue input_buffer { - rtype = 1l; raw_level = 2l; message_counter = Z.of_int 2; payload = Bytes.make 5000 '\000'; @@ -165,7 +156,6 @@ let read_input_too_large () = ~input_buffer ~output_buffer ~memory - ~rtype_offset:0l ~level_offset:4l ~id_offset:10l ~dst:50l @@ -182,7 +172,6 @@ let test_host_fun () = Input_buffer.enqueue input { - rtype = 1l; raw_level = 2l; message_counter = Z.of_int 2; payload = Bytes.of_string "hello"; @@ -196,10 +185,7 @@ let test_host_fun () = in let module_inst = {module_inst with memories} in let values = - Values. - [ - Num (I32 0l); Num (I32 4l); Num (I32 10l); Num (I32 50l); Num (I32 3600l); - ] + Values.[Num (I32 4l); Num (I32 10l); Num (I32 50l); Num (I32 3600l)] in let module_reg = Instance.ModuleMap.create () in @@ -218,8 +204,6 @@ let test_host_fun () = let* module_inst = Instance.resolve_module_ref module_reg module_key in let* memory = Lazy_vector.Int32Vector.get 0l module_inst.memories in assert (Input_buffer.num_elements input = Z.zero) ; - let* m = Memory.load_bytes memory 0l 1 in - assert (m = "\001") ; let* m = Memory.load_bytes memory 4l 1 in assert (m = "\002") ; let* m = Memory.load_bytes memory 10l 1 in diff --git a/src/lib_scoru_wasm/test/test_output.ml b/src/lib_scoru_wasm/test/test_output.ml index f7375f30a6d2..b592f6ee7879 100644 --- a/src/lib_scoru_wasm/test/test_output.ml +++ b/src/lib_scoru_wasm/test/test_output.ml @@ -46,7 +46,6 @@ let test_aux_write_output () = Input_buffer.enqueue input_buffer { - rtype = 1l; raw_level = 2l; message_counter = Z.of_int 2; payload = Bytes.of_string "hello"; @@ -58,7 +57,6 @@ let test_aux_write_output () = ~input_buffer ~output_buffer ~memory - ~rtype_offset:0l ~level_offset:4l ~id_offset:10l ~dst:50l @@ -86,7 +84,6 @@ let test_write_host_fun () = Input_buffer.enqueue input { - rtype = 1l; raw_level = 2l; message_counter = Z.of_int 2; payload = Bytes.of_string "hello"; @@ -100,10 +97,7 @@ let test_write_host_fun () = in let module_inst = {module_inst with memories} in let values = - Values. - [ - Num (I32 0l); Num (I32 4l); Num (I32 10l); Num (I32 50l); Num (I32 3600l); - ] + Values.[Num (I32 4l); Num (I32 10l); Num (I32 50l); Num (I32 3600l)] in let module_reg = Instance.ModuleMap.create () in diff --git a/src/lib_scoru_wasm/wasm_encoding.ml b/src/lib_scoru_wasm/wasm_encoding.ml index c62f96806bbe..963ddcc3db62 100644 --- a/src/lib_scoru_wasm/wasm_encoding.ml +++ b/src/lib_scoru_wasm/wasm_encoding.ml @@ -870,16 +870,15 @@ let admin_instr_encoding = let input_buffer_message_encoding = conv_lwt - (fun (rtype, raw_level, message_counter, payload) -> + (fun (raw_level, message_counter, payload) -> let open Lwt.Syntax in let+ payload = C.to_bytes payload in - Input_buffer.{rtype; raw_level; message_counter; payload}) - (fun Input_buffer.{rtype; raw_level; message_counter; payload} -> + Input_buffer.{raw_level; message_counter; payload}) + (fun Input_buffer.{raw_level; message_counter; payload} -> let payload = C.of_bytes payload in - Lwt.return (rtype, raw_level, message_counter, payload)) - (tup4 + Lwt.return (raw_level, message_counter, payload)) + (tup3 ~flatten:true - (value ["rtype"] Data_encoding.int32) (value ["raw-level"] Data_encoding.int32) (value ["message-counter"] Data_encoding.z) chunked_byte_vector) diff --git a/src/lib_scoru_wasm/wasm_pvm.ml b/src/lib_scoru_wasm/wasm_pvm.ml index 67bc64517127..289e533db6b5 100644 --- a/src/lib_scoru_wasm/wasm_pvm.ml +++ b/src/lib_scoru_wasm/wasm_pvm.ml @@ -464,14 +464,7 @@ let set_input_step input_info message pvm_state = Wasm.Input_buffer.( enqueue pvm_state.buffers.input - { - (* This is to distinguish (0) Inbox inputs from (1) - DAL/Slot_header inputs. *) - rtype = 0l; - raw_level; - message_counter; - payload = String.to_bytes message; - }) + {raw_level; message_counter; payload = String.to_bytes message}) in (* TODO: https://gitlab.com/tezos/tezos/-/issues/3157 The goal is to read a complete inbox. *) diff --git a/src/lib_webassembly/runtime/input_buffer.ml b/src/lib_webassembly/runtime/input_buffer.ml index 39ca0715afa7..2fbb73e47d7e 100644 --- a/src/lib_webassembly/runtime/input_buffer.ml +++ b/src/lib_webassembly/runtime/input_buffer.ml @@ -1,5 +1,4 @@ type message = { - rtype : int32; raw_level : int32; message_counter : Z.t; [@printer Z.pp_print] payload : bytes; diff --git a/src/lib_webassembly/runtime/input_buffer.mli b/src/lib_webassembly/runtime/input_buffer.mli index fa17ddefe4db..9880bf871323 100644 --- a/src/lib_webassembly/runtime/input_buffer.mli +++ b/src/lib_webassembly/runtime/input_buffer.mli @@ -1,12 +1,7 @@ (** This module implements a FIFO queue to model the input. The messages are queued in an input_buffer in their order of appearance in the inbox. *) -type message = { - rtype : int32; - raw_level : int32; - message_counter : Z.t; - payload : bytes; -} +type message = {raw_level : int32; message_counter : Z.t; payload : bytes} [@@deriving show] (** An element of type t will have a content which is a lazy_vector of messages diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml index 41bc79f67c51..26e41fc992bc 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_wasm.ml @@ -148,7 +148,6 @@ let make_transactions () = [write_output] host function and so it is used to test this function. *) let test_output () = let open Lwt_result_syntax in - let rtype_offset = 0 in let level_offset = 20 in let id_offset = 40 in let dst = 60 in @@ -159,12 +158,12 @@ let test_output () = (module (type (;0;) (func (param i32 i32 i32 i32 i32) (result i32))) (type $t0 (func (param i32 i32) (result i32))) - (type $t3 (func (param i32 i32 i32 i32 i32) (result i32))) + (type $t3 (func (param i32 i32 i32 i32) (result i32))) (import "rollup_safe_core" "read_input" (func $read_input (type $t3))) (import "rollup_safe_core" "write_output" (func $write_output (type $t0))) (func (export "kernel_next") (local $size i32) - (local.set $size (call $read_input (i32.const %d) + (local.set $size (call $read_input (i32.const %d) (i32.const %d) (i32.const %d) @@ -177,7 +176,6 @@ let test_output () = ) |} - rtype_offset level_offset id_offset dst -- GitLab