diff --git a/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml b/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml index 5be7b9fbcd222a6ce24c7ac20ef0f4fb42cbcbd1..983c1ef176cc61958cd2f5c4791ca64bde89424b 100644 --- a/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml +++ b/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml @@ -196,6 +196,25 @@ module Block_directory = Make_directory (struct (Node_context.readonly node_ctxt, block) end) +module Outbox_directory = Make_directory (struct + include Sc_rollup_services.Global.Block.Outbox + + type context = + Node_context.ro * Tezos_crypto.Block_hash.t * Alpha_context.Raw_level.t + + let context_of_prefix node_ctxt (((), block), level) = + let open Lwt_result_syntax in + let+ block = + match block with + | `Head -> get_head node_ctxt.Node_context.store + | `Hash b -> return b + | `Level l -> State.hash_of_level node_ctxt.store l >>= return + | `Finalized -> get_finalized node_ctxt.Node_context.store + | `Cemented -> get_last_cemented node_ctxt.Node_context.store + in + (Node_context.readonly node_ctxt, block, level) +end) + module Common = struct let () = Block_directory.register0 Sc_rollup_services.Global.Block.num_messages @@ -283,7 +302,7 @@ module Make (Simulation : Simulation.S) (Batcher : Batcher.S) = struct Simulation.end_simulation node_ctxt sim in let num_ticks = Z.(num_ticks_0 + num_ticks_end) in - let*! outbox = PVM.get_outbox state in + let*! outbox = PVM.get_outbox inbox_level state in let output = List.filter (fun Sc_rollup.{outbox_level; _} -> outbox_level = inbox_level) @@ -387,11 +406,11 @@ module Make (Simulation : Simulation.S) (Batcher : Batcher.S) = struct get_dal_slot_page node_ctxt.store block index page let () = - Block_directory.register0 Sc_rollup_services.Global.Block.outbox - @@ fun (node_ctxt, block) () () -> + Outbox_directory.register0 Sc_rollup_services.Global.Block.Outbox.messages + @@ fun (node_ctxt, block, outbox_level) () () -> let open Lwt_result_syntax in let* state = get_state node_ctxt block in - let*! outbox = PVM.get_outbox state in + let*! outbox = PVM.get_outbox outbox_level state in return outbox let () = @@ -534,6 +553,7 @@ module Make (Simulation : Simulation.S) (Batcher : Batcher.S) = struct Local_directory.build_directory; Block_directory.build_directory; Proof_helpers_directory.build_directory; + Outbox_directory.build_directory; ] let start node_ctxt configuration = diff --git a/src/proto_alpha/bin_sc_rollup_node/pvm.ml b/src/proto_alpha/bin_sc_rollup_node/pvm.ml index 37a10fcf32292e5d64a7e0501119a573b6bbf1f2..566c49e1d52e682121787fdfd85cd50142983f74 100644 --- a/src/proto_alpha/bin_sc_rollup_node/pvm.ml +++ b/src/proto_alpha/bin_sc_rollup_node/pvm.ml @@ -49,9 +49,9 @@ module type S = sig (** [string_of_status status] returns a string representation of [status]. *) val string_of_status : status -> string - (** [get_outbox state] returns a list of outputs available in the - outbox of [state]. *) - val get_outbox : state -> Sc_rollup.output list Lwt.t + (** [get_outbox outbox_level state] returns a list of outputs + available in the outbox of [state] at a given [outbox_level]. *) + val get_outbox : Raw_level.t -> state -> Sc_rollup.output list Lwt.t (** [eval_many ~max_steps s0] returns a state [s1] resulting from the execution of up to [~max_steps] steps of the rollup at state [s0]. *) diff --git a/src/proto_alpha/lib_client/client_proto_args.ml b/src/proto_alpha/lib_client/client_proto_args.ml index a6922ece79681bde3f658d642516711bee6e886f..e5077349701f20016f6147ae7b4d8d62410cccbf 100644 --- a/src/proto_alpha/lib_client/client_proto_args.ml +++ b/src/proto_alpha/lib_client/client_proto_args.ml @@ -935,7 +935,18 @@ module Sc_rollup_params = struct let messages_parameter = let open Lwt_result_syntax in let from_json text = - try return (`Json (Ezjsonm.from_string text)) + try + match Ezjsonm.from_string text with + | `A messages -> return (`Json (`A (`String "raw" :: messages))) + | _ -> failwith "Expecting a list of string" + with Ezjsonm.Parse_error _ -> + failwith "Given text is not valid JSON: '%s'" text + in + let from_json_hex text = + try + match Ezjsonm.from_string text with + | `A messages -> return (`Json (`A (`String "hex" :: messages))) + | _ -> failwith "Expecting a list of hex-encoded string" with Ezjsonm.Parse_error _ -> failwith "Given text is not valid JSON: '%s'" text in @@ -951,6 +962,7 @@ module Sc_rollup_params = struct Client_aliases.parse_alternatives [ ("text", from_json); + ("hex", from_json_hex); ("file", from_json_file cctxt); ("bin", from_bin_file cctxt); ] diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index a61dcada6518ec81fae05932d77c49b95d0ddcc4..93caa1e848d7dc55622c8c5a34e19796ccedd95a 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -3092,7 +3092,8 @@ let commands_rw () = ~name:"messages" ~desc: "The message(s) to be sent to the rollup (syntax: \ - bin:|text:|text:|hex:|file:)." Sc_rollup_params.messages_parameter @@ prefixes ["from"] @@ -3119,7 +3120,21 @@ let commands_rw () = | exception _ -> failwith "Could not read list of messages (expected list of bytes)" - | messages -> return messages) + | "raw" :: messages -> return messages + | "hex" :: messages -> + let* messages = + List.map_es + (fun message -> + match Hex.to_string (`Hex message) with + | None -> + failwith + "'%s' is not a valid hex encoded message" + message + | Some msg -> return [msg]) + messages + in + return @@ List.flatten messages + | _messages -> assert false) in let* _, src_pk, src_sk = Client_keys.get_key cctxt source in let* _res = diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 6f0c6573d7bd60f939b4c806f7c537c3e93ac01a..7b43a2d5907aa9f01847cb102d2b9bc0f2c4a4ea 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3661,7 +3661,7 @@ module Sc_rollup : sig val get_status : state -> status Lwt.t - val get_outbox : state -> output list Lwt.t + val get_outbox : Raw_level.t -> state -> output list Lwt.t end val reference_initial_state_hash : State_hash.t @@ -3716,7 +3716,7 @@ module Sc_rollup : sig val get_status : state -> status Lwt.t - val get_outbox : state -> output list Lwt.t + val get_outbox : Raw_level.t -> state -> output list Lwt.t val produce_proof : context -> input option -> state -> proof tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml index 6be368695bad1194cd1db5a1080de99acd23501c..3d49179e2c3803231db64faa3d568468a6545900 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_arith.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_arith.ml @@ -136,7 +136,8 @@ module type S = sig val get_status : state -> status Lwt.t - val get_outbox : state -> Sc_rollup_PVM_sig.output list Lwt.t + val get_outbox : + Raw_level_repr.t -> state -> Sc_rollup_PVM_sig.output list Lwt.t type instruction = | IPush : int -> instruction @@ -914,10 +915,14 @@ module Make (Context : P) : let get_status = result_of ~default:Waiting_for_input_message @@ Status.get - let get_outbox state = + let get_outbox outbox_level state = let open Lwt_syntax in let+ entries = result_of ~default:[] Output.entries state in - List.map snd entries + List.filter_map + (fun (_, msg) -> + if Raw_level_repr.(msg.PS.outbox_level = outbox_level) then Some msg + else None) + entries let get_code = result_of ~default:[] @@ Code.to_list @@ -952,7 +957,9 @@ module Make (Context : P) : match metadata with | Some {address; _} when Address.(destination = address) -> ( match Micheline.root payload with - | String (_, payload) -> return (Some payload) + | Bytes (_, payload) -> + let payload = Bytes.to_string payload in + return (Some payload) | _ -> return None) | _ -> return None) | Ok (Internal Start_of_level) -> diff --git a/src/proto_alpha/lib_protocol/sc_rollup_arith.mli b/src/proto_alpha/lib_protocol/sc_rollup_arith.mli index 4b8ba4520ab763dc4ae846ba645cbc203c63f723..0983dd3a9587cc9007493327f58b0e8f4eb37ef6 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_arith.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_arith.mli @@ -102,8 +102,10 @@ module type S = sig (** [get_status state] returns the machine status in [state]. *) val get_status : state -> status Lwt.t - (** [get_outbox state] returns the outbox in [state]. *) - val get_outbox : state -> Sc_rollup_PVM_sig.output list Lwt.t + (** [get_outbox outbox_level state] returns the outbox in [state] + for a given [outbox_level]. *) + val get_outbox : + Raw_level_repr.t -> state -> Sc_rollup_PVM_sig.output list Lwt.t (** The machine has only three instructions. *) type instruction = diff --git a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml index a8c4184ee4945cb6c072f6ecdb9ea7a91501ab1e..ab131be41395ea30e9117862ca380bedc00a633e 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml @@ -24,6 +24,47 @@ (* *) (*****************************************************************************) +type error += WASM_proof_verification_failed + +type error += WASM_proof_production_failed + +type error += WASM_output_proof_production_failed + +type error += WASM_invalid_claim_about_outbox + +let () = + let open Data_encoding in + let msg = "Invalid claim about outbox" in + register_error_kind + `Permanent + ~id:"sc_rollup_wasm_invalid_claim_about_outbox" + ~title:msg + ~pp:(fun fmt () -> Format.pp_print_string fmt msg) + ~description:msg + unit + (function WASM_invalid_claim_about_outbox -> Some () | _ -> None) + (fun () -> WASM_invalid_claim_about_outbox) ; + let msg = "Output proof production failed" in + register_error_kind + `Permanent + ~id:"sc_rollup_wasm_output_proof_production_failed" + ~title:msg + ~pp:(fun fmt () -> Format.fprintf fmt "%s" msg) + ~description:msg + unit + (function WASM_output_proof_production_failed -> Some () | _ -> None) + (fun () -> WASM_output_proof_production_failed) ; + let msg = "Proof production failed" in + register_error_kind + `Permanent + ~id:"sc_rollup_wasm_proof_production_failed" + ~title:msg + ~pp:(fun fmt () -> Format.fprintf fmt "%s" msg) + ~description:msg + unit + (function WASM_proof_production_failed -> Some () | _ -> None) + (fun () -> WASM_proof_production_failed) + module V2_0_0 = struct (* This is the state hash of reference that both the prover of the @@ -101,7 +142,8 @@ module V2_0_0 = struct (** [get_status state] gives you the current execution status for the PVM. *) val get_status : state -> status Lwt.t - val get_outbox : state -> Sc_rollup_PVM_sig.output list Lwt.t + val get_outbox : + Raw_level_repr.t -> state -> Sc_rollup_PVM_sig.output list Lwt.t end (* [Make (Make_backend) (Context)] creates a PVM. @@ -276,10 +318,37 @@ module V2_0_0 = struct let get_status : state -> status Lwt.t = result_of get_status - let get_outbox _state = - (* FIXME: https://gitlab.com/tezos/tezos/-/issues/3790 *) + let get_outbox outbox_level state = + let outbox_level_int32 = + Raw_level_repr.to_int32_non_negative outbox_level + in let open Lwt_syntax in - return [] + let rec aux outbox message_index = + let output = + Wasm_2_0_0.{outbox_level = outbox_level_int32; message_index} + in + let* res = WASM_machine.get_output output state in + match res with + | None -> return (List.rev outbox) + | Some msg -> ( + let serialized = + Sc_rollup_outbox_message_repr.unsafe_of_string msg + in + match Sc_rollup_outbox_message_repr.deserialize serialized with + | Error _ -> + (* The [write_output] host function does not guarantee that the contents + of the returned output is a valid encoding of an outbox message. + We choose to ignore such messages. An alternative choice would be to + craft an output with a payload witnessing the illformedness of the + output produced by the kernel. *) + (aux [@ocaml.tailcall]) outbox (Z.succ message_index) + | Ok message -> + let output = PS.{outbox_level; message_index; message} in + (aux [@ocaml.tailcall]) + (output :: outbox) + (Z.succ message_index)) + in + aux [] Z.zero let set_input_state input = let open Monad.Syntax in @@ -340,8 +409,6 @@ module V2_0_0 = struct in return (state, request) - type error += WASM_proof_verification_failed - let verify_proof input_given proof = let open Lwt_result_syntax in let*! result = Context.verify_proof proof (step_transition input_given) in @@ -349,8 +416,6 @@ module V2_0_0 = struct | None -> tzfail WASM_proof_verification_failed | Some (_state, request) -> return request - type error += WASM_proof_production_failed - let produce_proof context input_given state = let open Lwt_result_syntax in let*! result = @@ -438,10 +503,6 @@ module V2_0_0 = struct let* result = Context.verify_proof p.output_proof transition in match result with None -> return false | Some _ -> return true - type error += Wasm_output_proof_production_failed - - type error += Wasm_invalid_claim_about_outbox - let produce_output_proof context state output_proof_output = let open Lwt_result_syntax in let*! output_proof_state = state_hash state in @@ -453,8 +514,8 @@ module V2_0_0 = struct match result with | Some (output_proof, true) -> return {output_proof; output_proof_state; output_proof_output} - | Some (_, false) -> fail Wasm_invalid_claim_about_outbox - | None -> fail Wasm_output_proof_production_failed + | Some (_, false) -> fail WASM_invalid_claim_about_outbox + | None -> fail WASM_output_proof_production_failed module Internal_for_tests = struct let insert_failure state = diff --git a/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli b/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli index 20268f7c386b97682631166017030181f9e6ce64..3d42188d8863f4bd219a346eaa86cf3eddfffa12 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli @@ -61,8 +61,10 @@ module V2_0_0 : sig (** [get_status state] gives you the current execution status for the PVM. *) val get_status : state -> status Lwt.t - (** [get_outbox state] returns the outbox in [state]. *) - val get_outbox : state -> Sc_rollup_PVM_sig.output list Lwt.t + (** [get_outbox outbox_level state] returns the outbox in [state] + for a given [outbox_level]. *) + val get_outbox : + Raw_level_repr.t -> state -> Sc_rollup_PVM_sig.output list Lwt.t end module type P = sig diff --git a/src/proto_alpha/lib_protocol/test/integration/wasm_kernel/README.md b/src/proto_alpha/lib_protocol/test/integration/wasm_kernel/README.md index d0ab49dbdac4a78f0d395a02e03c322d3e741cfb..330c9678f645a593655caeefdfeec90a59611e77 100644 --- a/src/proto_alpha/lib_protocol/test/integration/wasm_kernel/README.md +++ b/src/proto_alpha/lib_protocol/test/integration/wasm_kernel/README.md @@ -41,3 +41,11 @@ cp target/wasm32-unknown-unknown/release/test_kernel.wasm computation_kernel.was wasm-strip computation_kernel.wasm ``` +# echo.wasm + +`echo.wasm` is the result of `wat2wasm echo.wast`. + +This simple kernel writes the external messages it receives in its outbox. + +To achieve that, it needs to take the encoding of the inputs into +account to extract the payload to push into the outbox. diff --git a/src/proto_alpha/lib_protocol/test/integration/wasm_kernel/echo.wasm b/src/proto_alpha/lib_protocol/test/integration/wasm_kernel/echo.wasm new file mode 100644 index 0000000000000000000000000000000000000000..be9e1532645971b3d674034c3013149d4a632836 Binary files /dev/null and b/src/proto_alpha/lib_protocol/test/integration/wasm_kernel/echo.wasm differ diff --git a/src/proto_alpha/lib_protocol/test/integration/wasm_kernel/echo.wast b/src/proto_alpha/lib_protocol/test/integration/wasm_kernel/echo.wast new file mode 100644 index 0000000000000000000000000000000000000000..2d1bc46bd889c07aa230583cf3686c5f8b13e2a7 --- /dev/null +++ b/src/proto_alpha/lib_protocol/test/integration/wasm_kernel/echo.wast @@ -0,0 +1,104 @@ +(module + + (type $read_t (func (param i32 i32 i32 i32) (result i32))) + (type $write_t (func (param i32 i32) (result i32))) + (type $store_w_t (func (param i32 i32 i32 i32 i32) (result i32))) + + (import "rollup_safe_core" "read_input" (func $read_input (type $read_t))) + (import "rollup_safe_core" "write_output" (func $write_output (type $write_t))) + (import "rollup_safe_core" "store_write" + (func $store_write (type $store_w_t))) + + (data (i32.const 100) "/kernel/env/reboot") + (data (i32.const 120) "\00\01") ;;Start_of_level + (data (i32.const 122) "\00\02") ;;End_of_level + (data (i32.const 124) "\00\00") ;;Internal Transfer + (data (i32.const 126) "\01") ;;External + + (memory 1) + (export "mem" (memory 0)) + + (func $set_reboot_flag (param $input_offset i32) ;;location of input + (local $eol i32) + (local $input_header i32) + + (local.set $eol (i32.load16_u (i32.const 122))) + (local.set $input_header + (i32.load16_u (local.get $input_offset))) + (i32.ne (local.get $eol) (local.get $input_header)) + (if (then + (call $store_write + (i32.const 100) ;; offset + (i32.const 18) ;; key size + (i32.const 0) ;; offset in the durable storage page + (i32.const 100) ;; offset in memory for the value (placeholder here) + (i32.const 0)) ;; size of the value in memory (placeholder here) + (drop))) + ) + + ;; Internal message representation + ;; (see Data_encoding.Binary.describe Sc_rollup_inbox_message_repr.encoding): + ;; - Tag (1B) `t1` + ;; - Tag (1B) `t2` + ;; - Payload (variable) `payload`, expected as a Byte + ;; + Tag (1B) `tb` + ;; + Size (4B) `size_b` + ;; + bytes (variable) + ;; - Sender (20B) `sender` + ;; - Source (21B) `source` + ;; - Destination (20B) `destination` + ;; + ;; payload = len - (t1 + t2 + tb + size_b + sender + source + destination) + ;; ==> payload = len - (1 + 1 + 1 + 4 + 20 + 21 + 20) + ;; ==> payload = len - 68 + ;; and starts at offset 7 from the input + + (func $internal_payload_size (param $input_size i32) (result i32) + (i32.sub (local.get $input_size) (i32.const 68))) ;; tag + + (func $write_message (param $input_offset i32) (param $size i32) + (local $internal i32) + (local $external i32) + (local $input_header i32) + (local $payload_size i32) + + (local.set $internal (i32.load16_u (i32.const 124))) + (local.set $external (i32.load8_u (i32.const 126))) + (local.set $input_header + (i32.load16_u (local.get $input_offset))) + (local.set $payload_size + (call $internal_payload_size (local.get $size))) + + (if + (i32.eq (local.get $input_header) (local.get $internal)) + (then + (call $write_output ;;See comment for the internal message representation + (i32.add (local.get $input_offset) (i32.const 7)) + (local.get $payload_size)) + (drop)) + (else + (if + (i32.eq (local.get $input_header) (local.get $external)) + (then + (call $write_output + (i32.add (local.get $input_offset) (i32.const 1)) ;;Remove the header + (i32.sub (local.get $size) (i32.const 1))) ;;Size without the header + (drop)) + ) + ) + ) + ) + + (func (export "kernel_next") + (local $size i32) + (local.set $size (call $read_input + (i32.const 220) ;; level_offset + (i32.const 240) ;; id_offset + (i32.const 260) ;; dst + (i32.const 3600))) ;; max_bytes + + (call $write_message (i32.const 260) + (local.get $size)) + (call $set_reboot_flag (i32.const 260)) + ) +) diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_arith.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_arith.ml index 97102e99436b98884f6a8f731df6df6ca7961f1d..0da9f177af538bc1bf83e72d606ce6db212b8860 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_arith.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_arith.ml @@ -455,12 +455,12 @@ let dummy_internal_transfer address = (Tezos_crypto.Signature.Public_key_hash.of_b58check "tz1RjtZUVeLhADFHDL8UwDZA6vjWWhojpu5w") in - let*? payload = Environment.wrap_tzresult (Script_string.of_string "foo") in + let payload = Bytes.of_string "foo" in let* payload, _ctxt = Script_ir_translator.unparse_data ctxt Script_ir_unparser.Optimized - String_t + Bytes_t payload >|= Environment.wrap_tzresult in diff --git a/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml b/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml index 660d1a615e87bd592e0401813b21518bf7731e10..24199a2293dfa481632bf4918af29864e8468bb6 100644 --- a/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml +++ b/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml @@ -475,10 +475,25 @@ module Global = struct ~output:Data_encoding.string (path / "status") + let outbox_level_query = + let open Tezos_rpc.Query in + query (fun outbox_level -> + let req name f = function + | None -> + raise + (Invalid + (Format.sprintf "Query parameter %s is required" name)) + | Some arg -> f arg + in + req "outbox_level" Raw_level.of_int32_exn outbox_level) + |+ opt_field "outbox_level" Tezos_rpc.Arg.int32 (fun o -> + Some (Raw_level.to_int32 o)) + |> seal + let outbox = Tezos_rpc.Service.get_service - ~description:"Outbox at block" - ~query:Tezos_rpc.Query.empty + ~description:"Outbox at block for a given outbox level" + ~query:outbox_level_query ~output:Data_encoding.(list Sc_rollup.output_encoding) (path / "outbox") @@ -550,6 +565,33 @@ module Global = struct (req "result" string) (opt "contents" Dal.Page.content_encoding)) (path / "dal" / "slot_page") + + module Outbox = struct + let level_param = + let destruct s = + match Int32.of_string_opt s with + | None -> Error "Invalid level" + | Some l -> ( + match Raw_level.of_int32 l with + | Error _ -> Error "Invalid level" + | Ok l -> Ok l) + in + let construct = Format.asprintf "%a" Raw_level.pp in + Tezos_rpc.Arg.make ~name:"level" ~construct ~destruct () + + include Make_services (struct + type nonrec prefix = prefix * Raw_level.t + + let prefix = prefix / "outbox" /: level_param + end) + + let messages = + Tezos_rpc.Service.get_service + ~description:"Outbox at block for a given outbox level" + ~query:Tezos_rpc.Query.empty + ~output:Data_encoding.(list Sc_rollup.output_encoding) + (path / "messages") + end end end diff --git a/tezt/lib_tezos/sc_rollup_client.ml b/tezt/lib_tezos/sc_rollup_client.ml index f8ef977e0d00bdfe1ebd3bc0e0ec481681903f62..c0b29db1a530a1d58587b328289db50b3c752ec3 100644 --- a/tezt/lib_tezos/sc_rollup_client.ml +++ b/tezt/lib_tezos/sc_rollup_client.ml @@ -182,6 +182,21 @@ let outbox_proof_single ?hooks ?expected_error ?entrypoint sc_client ~outbox_level [{destination; entrypoint; parameters}] +let encode_batch ?hooks ?expected_error sc_client batch = + let runnable = + spawn_command + ?hooks + sc_client + ["encode"; "outbox"; "message"; string_of_batch batch] + in + match expected_error with + | None -> + let* answer = Process.check_and_read_stdout runnable.value in + return (Some (String.trim answer)) + | Some msg -> + let* () = Process.check_error ~msg runnable.value in + return None + let rpc_get ?hooks sc_client path = spawn_command ?hooks sc_client ["rpc"; "get"; Client.string_of_path path] |> Runnable.map @@ fun output -> @@ -195,6 +210,18 @@ let rpc_post ?hooks sc_client path data = |> Runnable.map @@ fun output -> JSON.parse ~origin:(Client.string_of_path path ^ " response") output +let rpc_get_rich ?hooks sc_client path parameters = + let parameters = + if parameters = [] then "" + else + "?" ^ String.concat "&" + @@ List.map (fun (k, v) -> Format.asprintf "%s=%s" k v) parameters + in + let uri = Client.string_of_path path ^ parameters in + let runnable = spawn_command ?hooks sc_client ["rpc"; "get"; uri] in + let* output = Process.check_and_read_stdout runnable.value in + return (JSON.parse ~origin:(Client.string_of_path path ^ " response") output) + let ticks ?hooks ?(block = "head") sc_client = let res = rpc_get ?hooks sc_client ["global"; "block"; block; "ticks"] in Runnable.map JSON.as_int res @@ -211,8 +238,11 @@ let status ?hooks ?(block = "head") sc_client = rpc_get ?hooks sc_client ["global"; "block"; block; "status"] |> Runnable.map JSON.as_string -let outbox ?hooks ?(block = "cemented") sc_client = - rpc_get ?hooks sc_client ["global"; "block"; block; "outbox"] +let outbox ?hooks ?(block = "cemented") ~outbox_level sc_client = + rpc_get + ?hooks + sc_client + ["global"; "block"; block; "outbox"; string_of_int outbox_level; "messages"] let last_stored_commitment ?hooks sc_client = rpc_get ?hooks sc_client ["global"; "last_stored_commitment"] diff --git a/tezt/lib_tezos/sc_rollup_client.mli b/tezt/lib_tezos/sc_rollup_client.mli index 3cb0fd6372b153c10ab63b0c4dca941252c08705..aab60c108833d8daf67910b233316a0c53473503 100644 --- a/tezt/lib_tezos/sc_rollup_client.mli +++ b/tezt/lib_tezos/sc_rollup_client.mli @@ -67,6 +67,15 @@ val rpc_get : val rpc_post : ?hooks:Process.hooks -> t -> Client.path -> JSON.t -> JSON.t Runnable.process +(** [rpc_get_rich client path parameters] issues a GET request for [path] + passing [parameters]. *) +val rpc_get_rich : + ?hooks:Process.hooks -> + t -> + Client.path -> + (string * string) list -> + JSON.t Lwt.t + (** [total_ticks ?block client] gets the total number of ticks for the PVM. *) val total_ticks : ?hooks:Process.hooks -> ?block:string -> t -> int Runnable.process @@ -94,11 +103,15 @@ val state_value : val status : ?hooks:Process.hooks -> ?block:string -> t -> string Runnable.process -(** [outbox ?block client] gets the rollup outbox for the [block] (default - ["cemented"] which is the block corresponding to the last cemented - level). *) +(** [outbox ?block outbox_level client] gets the rollup outbox of + [outbox_level] as known to the [block] (default ["cemented"] which + is the block corresponding to the last cemented level). *) val outbox : - ?hooks:Process.hooks -> ?block:string -> t -> JSON.t Runnable.process + ?hooks:Process.hooks -> + ?block:string -> + outbox_level:int -> + t -> + JSON.t Runnable.process type outbox_proof = {commitment_hash : string; proof : string} @@ -134,6 +147,15 @@ val outbox_proof_batch : transaction list -> outbox_proof option Lwt.t +(** [encode_batch batch] returns the encoding of a [batch] of output + transactions. *) +val encode_batch : + ?hooks:Process.hooks -> + ?expected_error:Base.rex -> + t -> + transaction list -> + string option Lwt.t + (** [commitment_from_json] parses a commitment from its JSON representation. *) val commitment_from_json : JSON.t -> commitment option diff --git a/tezt/tests/contracts/proto_alpha/sc_rollup_forward.tz b/tezt/tests/contracts/proto_alpha/sc_rollup_forward.tz index 22789dbc3e169adcf7e458b843b505b2761ed75f..0632b96496dea168bb7afa16781f43a6ddc0728a 100644 --- a/tezt/tests/contracts/proto_alpha/sc_rollup_forward.tz +++ b/tezt/tests/contracts/proto_alpha/sc_rollup_forward.tz @@ -1,12 +1,12 @@ -parameter (pair address string) ; +parameter (pair address bytes) ; storage unit ; code { UNPAIR ; DIP { NIL operation }; UNPAIR ; - CONTRACT string ; + CONTRACT bytes ; ASSERT_SOME; SWAP; DIP { PUSH mutez 0 }; TRANSFER_TOKENS; CONS; - PAIR; } \ No newline at end of file + PAIR; } diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - RPC API should work and be stable.out b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - RPC API should work and be stable.out index 19c81ec26a6de326ec852630ba04f191fbd7f7c7..3a809380d2d7d6bbbaeb9ac29636d8302b6bbc6b 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - RPC API should work and be stable.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - RPC API should work and be stable.out @@ -252,7 +252,7 @@ This sequence of operations was run: ./octez-sc-rollup-client-alpha rpc get /global/block/head/state_hash "[SC_ROLLUP_PVM_STATE_HASH]" -./octez-sc-rollup-client-alpha rpc get /global/block/head/outbox +./octez-sc-rollup-client-alpha rpc get /global/block/cemented/outbox/16/messages [] ./octez-sc-rollup-client-alpha rpc get /global/tezos_head diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - node advances PVM state with messages (external).out b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - node advances PVM state with messages (external).out index 42770921f21dd8129bc0fc49d6a4615562d6a06e..c0e4e9c45815039041fd2d45cdbbbb9d97d6b589 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - node advances PVM state with messages (external).out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - node advances PVM state with messages (external).out @@ -1,5 +1,5 @@ -./octez-client --wait none originate sc rollup from bootstrap1 of kind arith of type string booting with --burn-cap 9999999 +./octez-client --wait none originate sc rollup from bootstrap1 of kind arith of type bytes booting with --burn-cap 9999999 Node is bootstrapped. Estimated gas: 2709.909 units (will add 100 for safety) Estimated storage: 6520 bytes added (will add 20 for safety) @@ -21,7 +21,7 @@ This sequence of operations was run: payload fees(the block proposer) ....... +ꜩ0.000629 Smart contract rollup origination: Kind: arith - Parameter type: string + Parameter type: bytes Boot sector Blake2B hash: '0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8' This smart contract rollup origination was successfully applied Consumed gas: 2709.909 diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - node advances PVM state with messages (internal).out b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - node advances PVM state with messages (internal).out index f3b2ada5f2f569e017ebc4715329d1116173a22c..a4a12ac667a705262d169afd9177a12e4a4aee6f 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - node advances PVM state with messages (internal).out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - node advances PVM state with messages (internal).out @@ -1,5 +1,5 @@ -./octez-client --wait none originate sc rollup from bootstrap1 of kind arith of type string booting with --burn-cap 9999999 +./octez-client --wait none originate sc rollup from bootstrap1 of kind arith of type bytes booting with --burn-cap 9999999 Node is bootstrapped. Estimated gas: 2709.909 units (will add 100 for safety) Estimated storage: 6520 bytes added (will add 20 for safety) @@ -21,7 +21,7 @@ This sequence of operations was run: payload fees(the block proposer) ....... +ꜩ0.000629 Smart contract rollup origination: Kind: arith - Parameter type: string + Parameter type: bytes Boot sector Blake2B hash: '0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8' This smart contract rollup origination was successfully applied Consumed gas: 2709.909 diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - an outbox message should be executable (entrypoint- -aux- earline.out b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -aux- earliness- 0- external).out similarity index 84% rename from tezt/tests/expected/sc_rollup.ml/Alpha- arith - an outbox message should be executable (entrypoint- -aux- earline.out rename to tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -aux- earliness- 0- external).out index fc58697391a61b971f6fc59f579fb49865e701e8..19cb7bcf47c59816f6534812e22c3b1eaa7d66c0 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - an outbox message should be executable (entrypoint- -aux- earline.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -aux- earliness- 0- external).out @@ -1,5 +1,5 @@ -./octez-client --wait none originate sc rollup from bootstrap1 of kind arith of type string booting with --burn-cap 9999999 +./octez-client --wait none originate sc rollup from bootstrap1 of kind arith of type bytes booting with --burn-cap 9999999 Node is bootstrapped. Estimated gas: 2709.909 units (will add 100 for safety) Estimated storage: 6520 bytes added (will add 20 for safety) @@ -21,7 +21,7 @@ This sequence of operations was run: payload fees(the block proposer) ....... +ꜩ0.000629 Smart contract rollup origination: Kind: arith - Parameter type: string + Parameter type: bytes Boot sector Blake2B hash: '0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8' This smart contract rollup origination was successfully applied Consumed gas: 2709.909 @@ -33,7 +33,7 @@ This sequence of operations was run: storage fees ........................... +ꜩ1.63 -./octez-client --wait none send sc rollup message 'text:["37 [CONTRACT_HASH]%aux"]' from bootstrap2 +./octez-client --wait none send sc rollup message 'hex:["3337204b543153364537793463703851657451516a555467784d646f6d706a4b66386f7377675525617578"]' from bootstrap2 Node is bootstrapped. Estimated gas: 1001.191 units (will add 100 for safety) Estimated storage: no bytes added @@ -56,16 +56,17 @@ This sequence of operations was run: Smart contract rollup messages submission This smart contract rollup messages submission was successfully applied Consumed gas: 1001.191 - Resulting inbox state: { level = 4 + Resulting inbox state: { level = 5 current messages hash = hash: [SC_ROLLUP_INBOX_HASH] - level: 4 nb_messages_in_commitment_period = 8 + level: 5 nb_messages_in_commitment_period = 10 message_counter = 2 old_levels_messages = content = hash: [SC_ROLLUP_INBOX_HASH] - level: 3 - index = 3 + level: 4 + index = 4 back_pointers = [SC_ROLLUP_INBOX_HASH] [SC_ROLLUP_INBOX_HASH] + [SC_ROLLUP_INBOX_HASH] } diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - an outbox message should be executable (entrypoint- -aux- ea.out b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -aux- earliness- 0- internal).out similarity index 50% rename from tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - an outbox message should be executable (entrypoint- -aux- ea.out rename to tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -aux- earliness- 0- internal).out index 285f6c9a66cb9cf77d7b4140d00e23d00cde3185..b87702ade564fc9c3bc1e81324f35333d8bd506b 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - an outbox message should be executable (entrypoint- -aux- ea.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -aux- earliness- 0- internal).out @@ -1,5 +1,5 @@ -./octez-client --wait none originate sc rollup from bootstrap1 of kind wasm_2_0_0 of type string booting with 0061736d0100000001240660047f7f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060027f7f00600000025e0310726f6c6c75705f736166655f636f72650a726561645f696e707574000010726f6c6c75705f736166655f636f72650c77726974655f6f7574707574000110726f6c6c75705f736166655f636f72650b73746f72655f777269746500020304030304050503010001071502036d656d02000b6b65726e656c5f6e65787400050a76032a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b2801027f41fd002d0000210220002d0000210320032002460440200041016a200141016b10011a0b0b2001017f41dc0141f00141840241901c100021004184022000100441840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fd000b0101 --burn-cap 9999999 +./octez-client --wait none originate sc rollup from bootstrap1 of kind arith of type bytes booting with --burn-cap 9999999 Node is bootstrapped. Estimated gas: 2709.909 units (will add 100 for safety) Estimated storage: 6520 bytes added (will add 20 for safety) @@ -12,17 +12,17 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000989 + Fee to the baker: ꜩ0.000629 Expected counter: 1 Gas limit: 2810 Storage limit: 6540 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000989 - payload fees(the block proposer) ....... +ꜩ0.000989 + [PUBLIC_KEY_HASH] ... -ꜩ0.000629 + payload fees(the block proposer) ....... +ꜩ0.000629 Smart contract rollup origination: - Kind: wasm_2_0_0 - Parameter type: string - Boot sector Blake2B hash: 'cd21483a93a238aad0f696ca1a754735f4126d609308c93039463918ad37444b' + Kind: arith + Parameter type: bytes + Boot sector Blake2B hash: '0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8' This smart contract rollup origination was successfully applied Consumed gas: 2709.909 Storage size: 6520 bytes diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - an outbox message should be executable (entrypoint- -default- ear.out b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -default- earliness- 0- external.out similarity index 84% rename from tezt/tests/expected/sc_rollup.ml/Alpha- arith - an outbox message should be executable (entrypoint- -default- ear.out rename to tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -default- earliness- 0- external.out index c86304ed864d1edd7dc744c11a0d7d1c5fdbecfc..dacd1607b7aa4c171b12b6b107efa708003619c9 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- arith - an outbox message should be executable (entrypoint- -default- ear.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -default- earliness- 0- external.out @@ -1,5 +1,5 @@ -./octez-client --wait none originate sc rollup from bootstrap1 of kind arith of type string booting with --burn-cap 9999999 +./octez-client --wait none originate sc rollup from bootstrap1 of kind arith of type bytes booting with --burn-cap 9999999 Node is bootstrapped. Estimated gas: 2709.909 units (will add 100 for safety) Estimated storage: 6520 bytes added (will add 20 for safety) @@ -21,7 +21,7 @@ This sequence of operations was run: payload fees(the block proposer) ....... +ꜩ0.000629 Smart contract rollup origination: Kind: arith - Parameter type: string + Parameter type: bytes Boot sector Blake2B hash: '0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8' This smart contract rollup origination was successfully applied Consumed gas: 2709.909 @@ -33,7 +33,7 @@ This sequence of operations was run: storage fees ........................... +ꜩ1.63 -./octez-client --wait none send sc rollup message 'text:["37 [CONTRACT_HASH]"]' from bootstrap2 +./octez-client --wait none send sc rollup message 'hex:["3337204b543153364537793463703851657451516a555467784d646f6d706a4b66386f73776755"]' from bootstrap2 Node is bootstrapped. Estimated gas: 1001.123 units (will add 100 for safety) Estimated storage: no bytes added @@ -56,16 +56,17 @@ This sequence of operations was run: Smart contract rollup messages submission This smart contract rollup messages submission was successfully applied Consumed gas: 1001.123 - Resulting inbox state: { level = 4 + Resulting inbox state: { level = 5 current messages hash = hash: [SC_ROLLUP_INBOX_HASH] - level: 4 nb_messages_in_commitment_period = 8 + level: 5 nb_messages_in_commitment_period = 10 message_counter = 2 old_levels_messages = content = hash: [SC_ROLLUP_INBOX_HASH] - level: 3 - index = 3 + level: 4 + index = 4 back_pointers = [SC_ROLLUP_INBOX_HASH] [SC_ROLLUP_INBOX_HASH] + [SC_ROLLUP_INBOX_HASH] } diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - an outbox message should be executable (entrypoint- -default.out b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -default- earliness- 0- internal.out similarity index 50% rename from tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - an outbox message should be executable (entrypoint- -default.out rename to tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -default- earliness- 0- internal.out index 285f6c9a66cb9cf77d7b4140d00e23d00cde3185..b87702ade564fc9c3bc1e81324f35333d8bd506b 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - an outbox message should be executable (entrypoint- -default.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- arith - trigger exec output (entrypoint- -default- earliness- 0- internal.out @@ -1,5 +1,5 @@ -./octez-client --wait none originate sc rollup from bootstrap1 of kind wasm_2_0_0 of type string booting with 0061736d0100000001240660047f7f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060027f7f00600000025e0310726f6c6c75705f736166655f636f72650a726561645f696e707574000010726f6c6c75705f736166655f636f72650c77726974655f6f7574707574000110726f6c6c75705f736166655f636f72650b73746f72655f777269746500020304030304050503010001071502036d656d02000b6b65726e656c5f6e65787400050a76032a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b2801027f41fd002d0000210220002d0000210320032002460440200041016a200141016b10011a0b0b2001017f41dc0141f00141840241901c100021004184022000100441840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fd000b0101 --burn-cap 9999999 +./octez-client --wait none originate sc rollup from bootstrap1 of kind arith of type bytes booting with --burn-cap 9999999 Node is bootstrapped. Estimated gas: 2709.909 units (will add 100 for safety) Estimated storage: 6520 bytes added (will add 20 for safety) @@ -12,17 +12,17 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000989 + Fee to the baker: ꜩ0.000629 Expected counter: 1 Gas limit: 2810 Storage limit: 6540 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000989 - payload fees(the block proposer) ....... +ꜩ0.000989 + [PUBLIC_KEY_HASH] ... -ꜩ0.000629 + payload fees(the block proposer) ....... +ꜩ0.000629 Smart contract rollup origination: - Kind: wasm_2_0_0 - Parameter type: string - Boot sector Blake2B hash: 'cd21483a93a238aad0f696ca1a754735f4126d609308c93039463918ad37444b' + Kind: arith + Parameter type: bytes + Boot sector Blake2B hash: '0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8' This smart contract rollup origination was successfully applied Consumed gas: 2709.909 Storage size: 6520 bytes diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - RPC API should work and be stable.out b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - RPC API should work and be stable.out index 8a7d62d6b6c204ebf9343b793a2039ea294497f9..1045150497fd0b291ff9ee15f862ebe758a3a3fc 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - RPC API should work and be stable.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - RPC API should work and be stable.out @@ -252,7 +252,7 @@ This sequence of operations was run: ./octez-sc-rollup-client-alpha rpc get /global/block/head/state_hash "[SC_ROLLUP_PVM_STATE_HASH]" -./octez-sc-rollup-client-alpha rpc get /global/block/head/outbox +./octez-sc-rollup-client-alpha rpc get /global/block/cemented/outbox/16/messages [] ./octez-sc-rollup-client-alpha rpc get /global/tezos_head diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - node advances PVM state with messages (external).out b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - node advances PVM state with messages (external).out index 4bc3a63698e86e8452c39b9b70f88c42551b6b3e..efd8743af2683ef1572b0f355942c045f8bc819b 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - node advances PVM state with messages (external).out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - node advances PVM state with messages (external).out @@ -1,5 +1,5 @@ -./octez-client --wait none originate sc rollup from bootstrap1 of kind wasm_2_0_0 of type string booting with 0061736d0100000001240660047f7f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060027f7f00600000025e0310726f6c6c75705f736166655f636f72650a726561645f696e707574000010726f6c6c75705f736166655f636f72650c77726974655f6f7574707574000110726f6c6c75705f736166655f636f72650b73746f72655f777269746500020304030304050503010001071502036d656d02000b6b65726e656c5f6e65787400050a76032a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b2801027f41fd002d0000210220002d0000210320032002460440200041016a200141016b10011a0b0b2001017f41dc0141f00141840241901c100021004184022000100441840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fd000b0101 --burn-cap 9999999 +./octez-client --wait none originate sc rollup from bootstrap1 of kind wasm_2_0_0 of type bytes booting with 0061736d0100000001240660047f7f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060027f7f00600000025e0310726f6c6c75705f736166655f636f72650a726561645f696e707574000010726f6c6c75705f736166655f636f72650c77726974655f6f7574707574000110726f6c6c75705f736166655f636f72650b73746f72655f777269746500020304030304050503010001071502036d656d02000b6b65726e656c5f6e65787400050a76032a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b2801027f41fd002d0000210220002d0000210320032002460440200041016a200141016b10011a0b0b2001017f41dc0141f00141840241901c100021004184022000100441840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fd000b0101 --burn-cap 9999999 Node is bootstrapped. Estimated gas: 2709.909 units (will add 100 for safety) Estimated storage: 6520 bytes added (will add 20 for safety) @@ -21,7 +21,7 @@ This sequence of operations was run: payload fees(the block proposer) ....... +ꜩ0.000989 Smart contract rollup origination: Kind: wasm_2_0_0 - Parameter type: string + Parameter type: bytes Boot sector Blake2B hash: 'cd21483a93a238aad0f696ca1a754735f4126d609308c93039463918ad37444b' This smart contract rollup origination was successfully applied Consumed gas: 2709.909 diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - node advances PVM state with messages (internal).out b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - node advances PVM state with messages (internal).out index 1da514f54b1ad9783e8934942b423f11739bec2d..ece9c04b72c7c68511190deafc7096d82641485d 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - node advances PVM state with messages (internal).out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - node advances PVM state with messages (internal).out @@ -1,5 +1,5 @@ -./octez-client --wait none originate sc rollup from bootstrap1 of kind wasm_2_0_0 of type string booting with 0061736d0100000001240660047f7f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060027f7f00600000025e0310726f6c6c75705f736166655f636f72650a726561645f696e707574000010726f6c6c75705f736166655f636f72650c77726974655f6f7574707574000110726f6c6c75705f736166655f636f72650b73746f72655f777269746500020304030304050503010001071502036d656d02000b6b65726e656c5f6e65787400050a76032a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b2801027f41fd002d0000210220002d0000210320032002460440200041016a200141016b10011a0b0b2001017f41dc0141f00141840241901c100021004184022000100441840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fd000b0101 --burn-cap 9999999 +./octez-client --wait none originate sc rollup from bootstrap1 of kind wasm_2_0_0 of type bytes booting with 0061736d0100000001240660047f7f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060027f7f00600000025e0310726f6c6c75705f736166655f636f72650a726561645f696e707574000010726f6c6c75705f736166655f636f72650c77726974655f6f7574707574000110726f6c6c75705f736166655f636f72650b73746f72655f777269746500020304030304050503010001071502036d656d02000b6b65726e656c5f6e65787400050a76032a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b2801027f41fd002d0000210220002d0000210320032002460440200041016a200141016b10011a0b0b2001017f41dc0141f00141840241901c100021004184022000100441840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fd000b0101 --burn-cap 9999999 Node is bootstrapped. Estimated gas: 2709.909 units (will add 100 for safety) Estimated storage: 6520 bytes added (will add 20 for safety) @@ -21,7 +21,7 @@ This sequence of operations was run: payload fees(the block proposer) ....... +ꜩ0.000989 Smart contract rollup origination: Kind: wasm_2_0_0 - Parameter type: string + Parameter type: bytes Boot sector Blake2B hash: 'cd21483a93a238aad0f696ca1a754735f4126d609308c93039463918ad37444b' This smart contract rollup origination was successfully applied Consumed gas: 2709.909 diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -aux- earliness- 0- externa.out b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -aux- earliness- 0- externa.out new file mode 100644 index 0000000000000000000000000000000000000000..705d240a68281e4aaac920bcb395c354572c5d19 --- /dev/null +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -aux- earliness- 0- externa.out @@ -0,0 +1,72 @@ + +./octez-client --wait none originate sc rollup from bootstrap1 of kind wasm_2_0_0 of type bytes booting with 0061736d0100000001290760047f7f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060017f017f60027f7f00600000025e0310726f6c6c75705f736166655f636f72650a726561645f696e707574000010726f6c6c75705f736166655f636f72650c77726974655f6f7574707574000110726f6c6c75705f736166655f636f72650b73746f72655f77726974650002030504030405060503010001071502036d656d02000b6b65726e656c5f6e65787400060aa001042a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b0800200041c4006b0b4901047f41fc002f0100210241fe002d0000210320002f0100210420011004210520042002460440200041076a200510011a0520042003460440200041016a200141016b10011a0b0b0b2001017f41dc0141f00141840241901c100021004184022000100541840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fe000b0101 --burn-cap 9999999 +Node is bootstrapped. +Estimated gas: 2709.909 units (will add 100 for safety) +Estimated storage: 6520 bytes added (will add 20 for safety) +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.001038 + Expected counter: 1 + Gas limit: 2810 + Storage limit: 6540 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.001038 + payload fees(the block proposer) ....... +ꜩ0.001038 + Smart contract rollup origination: + Kind: wasm_2_0_0 + Parameter type: bytes + Boot sector Blake2B hash: '88a2a78ca83fb7dc5f9393763b7fcbf0c10e0a12da1fd446835a16dad2dabd86' + This smart contract rollup origination was successfully applied + Consumed gas: 2709.909 + Storage size: 6520 bytes + Address: [SC_ROLLUP_HASH] + Genesis commitment hash: [SC_ROLLUP_COMMITMENT_HASH] + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ1.63 + storage fees ........................... +ꜩ1.63 + + +./octez-client --wait none send sc rollup message 'hex:["000000001f002501c00c5e4e94a48a49e267873112bbe3cf3373be5b0000000003617578"]' from bootstrap2 +Node is bootstrapped. +Estimated gas: 1001.072 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000379 + Expected counter: 1 + Gas limit: 1102 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000379 + payload fees(the block proposer) ....... +ꜩ0.000379 + Smart contract rollup messages submission + This smart contract rollup messages submission was successfully applied + Consumed gas: 1001.072 + Resulting inbox state: { level = 5 + current messages hash = hash: [SC_ROLLUP_INBOX_HASH] + level: 5 nb_messages_in_commitment_period = 10 + message_counter = 2 + old_levels_messages = + content = hash: [SC_ROLLUP_INBOX_HASH] + level: 4 + index = 4 + back_pointers = [SC_ROLLUP_INBOX_HASH] + [SC_ROLLUP_INBOX_HASH] + [SC_ROLLUP_INBOX_HASH] + + } + diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -aux- earliness- 0- interna.out b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -aux- earliness- 0- interna.out new file mode 100644 index 0000000000000000000000000000000000000000..bf22b75c63edd9c0378d472aa5ff66905d81dba6 --- /dev/null +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -aux- earliness- 0- interna.out @@ -0,0 +1,34 @@ + +./octez-client --wait none originate sc rollup from bootstrap1 of kind wasm_2_0_0 of type bytes booting with 0061736d0100000001290760047f7f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060017f017f60027f7f00600000025e0310726f6c6c75705f736166655f636f72650a726561645f696e707574000010726f6c6c75705f736166655f636f72650c77726974655f6f7574707574000110726f6c6c75705f736166655f636f72650b73746f72655f77726974650002030504030405060503010001071502036d656d02000b6b65726e656c5f6e65787400060aa001042a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b0800200041c4006b0b4901047f41fc002f0100210241fe002d0000210320002f0100210420011004210520042002460440200041076a200510011a0520042003460440200041016a200141016b10011a0b0b0b2001017f41dc0141f00141840241901c100021004184022000100541840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fe000b0101 --burn-cap 9999999 +Node is bootstrapped. +Estimated gas: 2709.909 units (will add 100 for safety) +Estimated storage: 6520 bytes added (will add 20 for safety) +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.001038 + Expected counter: 1 + Gas limit: 2810 + Storage limit: 6540 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.001038 + payload fees(the block proposer) ....... +ꜩ0.001038 + Smart contract rollup origination: + Kind: wasm_2_0_0 + Parameter type: bytes + Boot sector Blake2B hash: '88a2a78ca83fb7dc5f9393763b7fcbf0c10e0a12da1fd446835a16dad2dabd86' + This smart contract rollup origination was successfully applied + Consumed gas: 2709.909 + Storage size: 6520 bytes + Address: [SC_ROLLUP_HASH] + Genesis commitment hash: [SC_ROLLUP_COMMITMENT_HASH] + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ1.63 + storage fees ........................... +ꜩ1.63 + diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -default- earliness- 0- ext.out b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -default- earliness- 0- ext.out new file mode 100644 index 0000000000000000000000000000000000000000..7b605460eaaca425cc94c39c198403421d84aa80 --- /dev/null +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -default- earliness- 0- ext.out @@ -0,0 +1,72 @@ + +./octez-client --wait none originate sc rollup from bootstrap1 of kind wasm_2_0_0 of type bytes booting with 0061736d0100000001290760047f7f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060017f017f60027f7f00600000025e0310726f6c6c75705f736166655f636f72650a726561645f696e707574000010726f6c6c75705f736166655f636f72650c77726974655f6f7574707574000110726f6c6c75705f736166655f636f72650b73746f72655f77726974650002030504030405060503010001071502036d656d02000b6b65726e656c5f6e65787400060aa001042a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b0800200041c4006b0b4901047f41fc002f0100210241fe002d0000210320002f0100210420011004210520042002460440200041076a200510011a0520042003460440200041016a200141016b10011a0b0b0b2001017f41dc0141f00141840241901c100021004184022000100541840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fe000b0101 --burn-cap 9999999 +Node is bootstrapped. +Estimated gas: 2709.909 units (will add 100 for safety) +Estimated storage: 6520 bytes added (will add 20 for safety) +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.001038 + Expected counter: 1 + Gas limit: 2810 + Storage limit: 6540 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.001038 + payload fees(the block proposer) ....... +ꜩ0.001038 + Smart contract rollup origination: + Kind: wasm_2_0_0 + Parameter type: bytes + Boot sector Blake2B hash: '88a2a78ca83fb7dc5f9393763b7fcbf0c10e0a12da1fd446835a16dad2dabd86' + This smart contract rollup origination was successfully applied + Consumed gas: 2709.909 + Storage size: 6520 bytes + Address: [SC_ROLLUP_HASH] + Genesis commitment hash: [SC_ROLLUP_COMMITMENT_HASH] + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ1.63 + storage fees ........................... +ꜩ1.63 + + +./octez-client --wait none send sc rollup message 'hex:["0000000023002501c00c5e4e94a48a49e267873112bbe3cf3373be5b000000000764656661756c74"]' from bootstrap2 +Node is bootstrapped. +Estimated gas: 1001.140 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000383 + Expected counter: 1 + Gas limit: 1102 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000383 + payload fees(the block proposer) ....... +ꜩ0.000383 + Smart contract rollup messages submission + This smart contract rollup messages submission was successfully applied + Consumed gas: 1001.140 + Resulting inbox state: { level = 5 + current messages hash = hash: [SC_ROLLUP_INBOX_HASH] + level: 5 nb_messages_in_commitment_period = 10 + message_counter = 2 + old_levels_messages = + content = hash: [SC_ROLLUP_INBOX_HASH] + level: 4 + index = 4 + back_pointers = [SC_ROLLUP_INBOX_HASH] + [SC_ROLLUP_INBOX_HASH] + [SC_ROLLUP_INBOX_HASH] + + } + diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -default- earliness- 0- int.out b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -default- earliness- 0- int.out new file mode 100644 index 0000000000000000000000000000000000000000..bf22b75c63edd9c0378d472aa5ff66905d81dba6 --- /dev/null +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- wasm_2_0_0 - trigger exec output (entrypoint- -default- earliness- 0- int.out @@ -0,0 +1,34 @@ + +./octez-client --wait none originate sc rollup from bootstrap1 of kind wasm_2_0_0 of type bytes booting with 0061736d0100000001290760047f7f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060017f017f60027f7f00600000025e0310726f6c6c75705f736166655f636f72650a726561645f696e707574000010726f6c6c75705f736166655f636f72650c77726974655f6f7574707574000110726f6c6c75705f736166655f636f72650b73746f72655f77726974650002030504030405060503010001071502036d656d02000b6b65726e656c5f6e65787400060aa001042a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b0800200041c4006b0b4901047f41fc002f0100210241fe002d0000210320002f0100210420011004210520042002460440200041076a200510011a0520042003460440200041016a200141016b10011a0b0b0b2001017f41dc0141f00141840241901c100021004184022000100541840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fe000b0101 --burn-cap 9999999 +Node is bootstrapped. +Estimated gas: 2709.909 units (will add 100 for safety) +Estimated storage: 6520 bytes added (will add 20 for safety) +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.001038 + Expected counter: 1 + Gas limit: 2810 + Storage limit: 6540 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.001038 + payload fees(the block proposer) ....... +ꜩ0.001038 + Smart contract rollup origination: + Kind: wasm_2_0_0 + Parameter type: bytes + Boot sector Blake2B hash: '88a2a78ca83fb7dc5f9393763b7fcbf0c10e0a12da1fd446835a16dad2dabd86' + This smart contract rollup origination was successfully applied + Consumed gas: 2709.909 + Storage size: 6520 bytes + Address: [SC_ROLLUP_HASH] + Genesis commitment hash: [SC_ROLLUP_COMMITMENT_HASH] + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ1.63 + storage fees ........................... +ꜩ1.63 + diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index 6f52454f41ec31e7f27a9d041948b28a76e4b510..0061a29f7d525e35b72ec7fdc6101b50b06801e3 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -246,10 +246,15 @@ let wait_for_conflict_detected sc_node = A rollup node has a configuration file that must be initialized. *) -let setup_rollup ~kind ?boot_sector ?(operator = Constant.bootstrap1.alias) - tezos_node tezos_client = +let setup_rollup ~kind ?boot_sector ?(parameters_ty = "string") + ?(operator = Constant.bootstrap1.alias) tezos_node tezos_client = let* sc_rollup = - originate_sc_rollup ~kind ?boot_sector ~src:operator tezos_client + originate_sc_rollup + ~kind + ?boot_sector + ~parameters_ty + ~src:operator + tezos_client in let sc_rollup_node = Sc_rollup_node.create @@ -286,8 +291,9 @@ let test_l1_scenario ?regression ~kind ?boot_sector ?commitment_period scenario sc_rollup tezos_node tezos_client let test_full_scenario ?regression ~kind ?boot_sector ?commitment_period - ?challenge_window ?timeout ?max_number_of_messages_per_commitment_period - {variant; tags; description} scenario = + ?(parameters_ty = "string") ?challenge_window ?timeout + ?max_number_of_messages_per_commitment_period {variant; tags; description} + scenario = let tags = kind :: "rollup_node" :: tags in register_test ?regression @@ -311,7 +317,7 @@ let test_full_scenario ?regression ~kind ?boot_sector ?commitment_period protocol in let* rollup_node, rollup_client, sc_rollup = - setup_rollup ~kind ?boot_sector tezos_node tezos_client + setup_rollup ~parameters_ty ~kind ?boot_sector tezos_node tezos_client in scenario rollup_node rollup_client sc_rollup tezos_node tezos_client @@ -678,8 +684,14 @@ let to_text_messages_arg msgs = let json = Ezjsonm.list Ezjsonm.string msgs in "text:" ^ Ezjsonm.to_string ~minify:true json -let send_text_messages ?src client msgs = - send_message ?src client (to_text_messages_arg msgs) +let to_hex_messages_arg msgs = + let json = Ezjsonm.list Ezjsonm.string msgs in + "hex:" ^ Ezjsonm.to_string ~minify:true json + +let send_text_messages ?(format = `Raw) ?src client msgs = + match format with + | `Raw -> send_message ?src client (to_text_messages_arg msgs) + | `Hex -> send_message ?src client (to_hex_messages_arg msgs) let parse_inbox json = let go () = @@ -908,14 +920,16 @@ let sc_rollup_node_simulate sc_rollup_node sc_rollup_client _sc_rollup node [msg1] in let* () = send_message client (to_text_messages_arg [msg1]) in - let* _ = - Sc_rollup_node.wait_for_level - ~timeout:3. - sc_rollup_node - (Node.get_level node) - in + let level = Node.get_level node in + let* _ = Sc_rollup_node.wait_for_level ~timeout:3. sc_rollup_node level in let*! real_state_hash = Sc_rollup_client.state_hash sc_rollup_client in - let*! real_outbox = Sc_rollup_client.outbox sc_rollup_client ~block:"head" in + let* real_outbox = + Runnable.run + @@ Sc_rollup_client.outbox + sc_rollup_client + ~outbox_level:level + ~block:"head" + in Check.((sim_result.state_hash = real_state_hash) string) ~error_msg:"Simulated resulting state hash is %L but should have been %R" ; Check.((JSON.encode sim_result.output = JSON.encode real_outbox) string) @@ -1152,6 +1166,7 @@ let test_rollup_node_advances_pvm_state ?regression ~title ?boot_sector description = title; } ?boot_sector + ~parameters_ty:"bytes" ~kind @@ fun sc_rollup_node sc_rollup_client sc_rollup _tezos_node client -> let* genesis_info = @@ -1200,17 +1215,18 @@ let test_rollup_node_advances_pvm_state ?regression ~title ?boot_sector send_message client (sf "[%S]" message) | Some forwarder -> (* Internal message through forwarder *) + let message = hex_encode message in let* () = Client.transfer client ~amount:Tez.zero ~giver:Constant.bootstrap1.alias ~receiver:forwarder - ~arg:(sf "Pair %S %S" sc_rollup message) + ~arg:(sf "Pair %S 0x%s" sc_rollup message) in Client.bake_for_and_wait client in - let* _ = + let* (_ : int) = Sc_rollup_node.wait_for_level ~timeout:30. sc_rollup_node (level + i) in @@ -3261,27 +3277,36 @@ let test_refutation_reward_and_punishment ~kind = The input depends on the PVM. *) -let test_outbox_message_generic ?regression ?expected_error ~skip ~earliness - ?entrypoint ~input_message ~expected_storage ~kind = +let test_outbox_message_generic ?regression ?expected_error ~earliness + ?entrypoint ?boot_sector ~input_message ~expected_storage ~kind + ~message_kind = let commitment_period = 2 and challenge_window = 5 in + let message_kind_s = + match message_kind with `Internal -> "internal" | `External -> "external" + in + let entrypoint_s = Option.value ~default:"default" entrypoint in test_full_scenario ?regression + ?boot_sector + ~parameters_ty:"bytes" ~kind ~commitment_period ~challenge_window { - tags = ["outbox"]; + tags = ["outbox"; message_kind_s; entrypoint_s]; variant = Some (Format.sprintf - "entrypoint: %%%s, earliness: %d" - (Option.value ~default:"default" entrypoint) - earliness); - description = "an outbox message should be executable"; + "entrypoint: %%%s, earliness: %d, %s" + entrypoint_s + earliness + message_kind_s); + description = "trigger exec output"; } @@ fun rollup_node sc_client sc_rollup _node client -> let* () = Sc_rollup_node.run rollup_node [] in let src = Constant.bootstrap1.public_key_hash in + let src2 = Constant.bootstrap2.public_key_hash in let originate_target_contract () = let prg = {| @@ -3320,30 +3345,118 @@ let test_outbox_message_generic ?regression ?expected_error ~skip ~earliness string ~error_msg:"Invalid contract storage: expecting '%R', got '%L'.") in - let perform_rollup_execution_and_cement address = - let* () = send_text_messages client [input_message address] in + let originate_source_contract () = + (* A script that receives bytes as a parameter and transfers them + to the rollup as is. The transfer will appear as an internal + message targetting this specific rollup in the rollups' + inbox. *) + let prg = + Format.asprintf + {| + { + parameter (bytes %%default); + storage (unit); + + code + { + CAR; + PUSH address "%s"; + CONTRACT bytes; + IF_NONE { PUSH string "Invalid address"; FAILWITH; } + { + PUSH mutez 0; + DIG 2; + TRANSFER_TOKENS; + NIL operation; + SWAP; + CONS; + PUSH unit Unit; + SWAP; + PAIR; + } + } + } |} + sc_rollup + in + let* address = + Client.originate_contract + ~alias:"source" + ~amount:(Tez.of_int 100) + ~burn_cap:(Tez.of_int 100) + ~src + ~prg + ~init:"Unit" + client + in + let* () = Client.bake_for_and_wait client in + return address + in + let perform_rollup_execution_and_cement source_address target_address = + let* payload = input_message sc_client target_address in + let* () = + match payload with + | `External payload -> send_text_messages ~format:`Hex client [payload] + | `Internal payload -> + let payload = "0x" ^ payload in + Client.transfer + ~amount:Tez.(of_int 100) + ~burn_cap:Tez.(of_int 100) + ~storage_limit:100000 + ~giver:"bootstrap1" + ~receiver:source_address + ~arg:payload + client + in let blocks_to_wait = 2 + (2 * commitment_period) + challenge_window - earliness in repeat blocks_to_wait @@ fun () -> Client.bake_for client in let trigger_outbox_message_execution address = - let*! outbox = Sc_rollup_client.outbox sc_client in - Log.info "Outbox is %s" (JSON.encode outbox) ; - let* answer = - let message_index = 0 in - let outbox_level = 4 in - let destination = address in - let parameters = "37" in - Sc_rollup_client.outbox_proof_single - sc_client - ?expected_error - ~message_index - ~outbox_level - ~destination - ?entrypoint - ~parameters + let outbox_level = 5 in + let destination = address in + let parameters = "37" in + let message_index = 0 in + let check_expected_outbox () = + let* outbox = + Runnable.run @@ Sc_rollup_client.outbox ~outbox_level sc_client + in + Log.info "Outbox is %s" (JSON.encode outbox) ; + + match expected_error with + | None -> + let expected = + JSON.parse ~origin:"trigger_outbox_message_execution" + @@ Printf.sprintf + {| + [ { "outbox_level": %d, "message_index": "%d", + "message": + { "transactions": + [ { "parameters": { "int": "%s" }, + "destination": "%s"%s } ] } } ] |} + outbox_level + message_index + parameters + address + (match entrypoint with + | None -> "" + | Some entrypoint -> + Format.asprintf {| , "entrypoint" : "%s" |} entrypoint) + in + assert (JSON.encode expected = JSON.encode outbox) ; + Sc_rollup_client.outbox_proof_single + sc_client + ?expected_error + ~message_index + ~outbox_level + ~destination + ?entrypoint + ~parameters + | Some _ -> + assert (JSON.encode outbox = "[]") ; + return None in + let* answer = check_expected_outbox () in match (answer, expected_error) with | Some _, Some _ -> assert false | None, None -> failwith "Unexpected error during proof generation" @@ -3353,43 +3466,64 @@ let test_outbox_message_generic ?regression ?expected_error ~skip ~earliness Client.Sc_rollup.execute_outbox_message ~burn_cap:(Tez.of_int 10) ~rollup:sc_rollup - ~src + ~src:src2 ~commitment_hash ~proof client in - Client.bake_for client - in - if skip then unit - else - let* target_contract_address = originate_target_contract () in - let* () = perform_rollup_execution_and_cement target_contract_address in - let* () = trigger_outbox_message_execution target_contract_address in - match expected_error with - | None -> - let* () = - check_contract_execution target_contract_address expected_storage - in - unit - | Some _ -> unit + Client.bake_for_and_wait client + in + let* target_contract_address = originate_target_contract () in + let* source_contract_address = originate_source_contract () in + let* () = + perform_rollup_execution_and_cement + source_contract_address + target_contract_address + in + let* () = Client.bake_for_and_wait client in + let* () = trigger_outbox_message_execution target_contract_address in + match expected_error with + | None -> + let* () = + check_contract_execution target_contract_address expected_storage + in + unit + | Some _ -> unit let test_outbox_message ?regression ?expected_error ~earliness ?entrypoint ~kind - = - let skip, input_message, expected_storage = + ~message_kind = + let wrap payload = + match message_kind with + | `Internal -> `Internal payload + | `External -> `External payload + in + let boot_sector, input_message, expected_storage = match kind with | "arith" -> - ( false, - (fun contract_address -> + let input_message _client contract_address = + let payload = Printf.sprintf "37 %s%s" contract_address - (match entrypoint with Some e -> "%" ^ e | None -> "")), - "37" ) + (match entrypoint with Some e -> "%" ^ e | None -> "") + in + let payload = hex_encode payload in + return @@ wrap payload + in + (None, input_message, "37") | "wasm_2_0_0" -> - (* FIXME: https://gitlab.com/tezos/tezos/-/issues/3790 - For the moment, the WASM PVM has no support for - output. Hence, the storage is unchanged.*) - (true, Fun.const "", "0") + let bootsector = read_kernel "echo" in + let input_message client contract_address = + let transaction = + Sc_rollup_client. + {destination = contract_address; entrypoint; parameters = "37"} + in + let* answer = Sc_rollup_client.encode_batch client [transaction] in + match answer with + | None -> failwith "Encoding of batch should not fail." + | Some answer -> return (wrap answer) + in + (Some bootsector, input_message, "37") | _ -> (* There is no other PVM in the protocol. *) assert false @@ -3397,11 +3531,12 @@ let test_outbox_message ?regression ?expected_error ~earliness ?entrypoint ~kind test_outbox_message_generic ?regression ?expected_error - ~skip ~earliness ?entrypoint + ?boot_sector ~input_message ~expected_storage + ~message_kind ~kind let test_rpcs ~kind = @@ -3485,11 +3620,12 @@ let test_rpcs ~kind = sc_client ["global"; "block"; "head"; "state_hash"] in - let*! _outbox = - Sc_rollup_client.rpc_get - ~hooks - sc_client - ["global"; "block"; "head"; "outbox"] + let* _outbox = + Runnable.run + @@ Sc_rollup_client.outbox + ~hooks + ~outbox_level:l2_finalied_block_level + sc_client in let*! _head = Sc_rollup_client.rpc_get ~hooks sc_client ["global"; "tezos_head"] @@ -3615,22 +3751,56 @@ let register ~kind ~protocols = test_reinject_failed_commitment protocols ~kind ; test_late_rollup_node protocols ~kind ; test_interrupt_rollup_node protocols ~kind ; - test_outbox_message ~regression:true ~earliness:0 protocols ~kind ; + test_outbox_message + ~regression:true + ~earliness:0 + ~message_kind:`Internal + ~kind + protocols ; + test_outbox_message + ~regression:true + ~earliness:0 + ~entrypoint:"aux" + ~message_kind:`Internal + protocols + ~kind ; + test_outbox_message + ~expected_error:(Base.rex ".*Invalid claim about outbox") + ~earliness:5 + ~message_kind:`Internal + protocols + ~kind ; + test_outbox_message + ~expected_error:(Base.rex ".*Invalid claim about outbox") + ~earliness:5 + ~entrypoint:"aux" + ~message_kind:`Internal + protocols + ~kind ; + test_outbox_message + ~regression:true + ~earliness:0 + ~message_kind:`External + protocols + ~kind ; test_outbox_message ~regression:true ~earliness:0 ~entrypoint:"aux" + ~message_kind:`External protocols ~kind ; test_outbox_message ~expected_error:(Base.rex ".*Invalid claim about outbox") ~earliness:5 + ~message_kind:`External protocols ~kind ; test_outbox_message ~expected_error:(Base.rex ".*Invalid claim about outbox") ~earliness:5 ~entrypoint:"aux" + ~message_kind:`External protocols ~kind