diff --git a/src/lib_protocol_environment/sigs/v8.ml b/src/lib_protocol_environment/sigs/v8.ml index 442d10addfb4dfe7ccc87bd3a254471e3c7cbc96..3c6ecc5f8178139a9415b9d6bcc08c50088428b5 100644 --- a/src/lib_protocol_environment/sigs/v8.ml +++ b/src/lib_protocol_environment/sigs/v8.ml @@ -12070,7 +12070,8 @@ type info = { module Make (Tree : Context.TREE with type key = string list and type value = bytes) : sig - val install_boot_sector : string -> Tree.tree -> Tree.tree Lwt.t + val install_boot_sector : + ticks_per_snapshot:Z.t -> string -> Tree.tree -> Tree.tree Lwt.t val compute_step : Tree.tree -> Tree.tree Lwt.t diff --git a/src/lib_protocol_environment/sigs/v8/wasm_2_0_0.mli b/src/lib_protocol_environment/sigs/v8/wasm_2_0_0.mli index 1a7dfd7ef23ed42d0e089549aacb519d90c48286..c696ead44f0e78028695e828278ff699fec2bddf 100644 --- a/src/lib_protocol_environment/sigs/v8/wasm_2_0_0.mli +++ b/src/lib_protocol_environment/sigs/v8/wasm_2_0_0.mli @@ -46,7 +46,8 @@ type info = { module Make (Tree : Context.TREE with type key = string list and type value = bytes) : sig - val install_boot_sector : string -> Tree.tree -> Tree.tree Lwt.t + val install_boot_sector : + ticks_per_snapshot:Z.t -> string -> Tree.tree -> Tree.tree Lwt.t val compute_step : Tree.tree -> Tree.tree Lwt.t diff --git a/src/lib_scoru_wasm/constants.ml b/src/lib_scoru_wasm/constants.ml index 693e07c48b177ce51dbd9ad4ea9e97cd69bcc899..16b0c0991eabedb936e05cebafbea6dfa60c2a30 100644 --- a/src/lib_scoru_wasm/constants.ml +++ b/src/lib_scoru_wasm/constants.ml @@ -35,18 +35,6 @@ let wasm_entrypoint = "kernel_run" WASM kernel. *) let wasm_host_funcs_virual_module = "smart_rollup_core" -(* Number of ticks between snapshotable states, - should be chosen low enough to maintain refutability. - - Depends on - - speed (tick/s) of node in slow mode (from benchmark, 6000000 tick/s) - - the number of ticks in a commitment (Int64.max_int, - as per Number_of_ticks.max_value) - - see #3590 for more pointers -*) -let wasm_max_tick = Z.of_int 11_000_000_000 - (* TODO: https://gitlab.com/tezos/tezos/-/issues/3157 Find an appropriate number of reboots per inputs. *) diff --git a/src/lib_scoru_wasm/test/helpers/wasm_utils.ml b/src/lib_scoru_wasm/test/helpers/wasm_utils.ml index 2dee3d875d5e3080da544efb9e3cd59bbd6681ba..9f1dffe616a37c12ff09ec5bc958a0ef7d49810a 100644 --- a/src/lib_scoru_wasm/test/helpers/wasm_utils.ml +++ b/src/lib_scoru_wasm/test/helpers/wasm_utils.ml @@ -49,8 +49,9 @@ let initial_tree ?(max_tick = default_max_tick) let max_tick_Z = Z.of_int64 max_tick in let* tree = empty_tree () in let* boot_sector = if from_binary then Lwt.return code else wat2wasm code in - let* tree = Wasm.install_boot_sector boot_sector tree in - let* tree = Wasm.Internal_for_tests.set_max_nb_ticks max_tick_Z tree in + let* tree = + Wasm.install_boot_sector ~ticks_per_snapshot:max_tick_Z boot_sector tree + in Wasm.Internal_for_tests.set_maximum_reboots_per_input max_reboots tree module Builtins = struct diff --git a/src/lib_scoru_wasm/wasm_pvm.ml b/src/lib_scoru_wasm/wasm_pvm.ml index 3c0d264605d6ca5dd6a1880c0f5552782ddab6b0..d78e6262d37b3d578fa4ba914b3cdee5338cdee5 100644 --- a/src/lib_scoru_wasm/wasm_pvm.ml +++ b/src/lib_scoru_wasm/wasm_pvm.ml @@ -170,10 +170,7 @@ let pvm_state_encoding = (option durable_buffers_encoding) (scope ["wasm"] tick_state_encoding) (value ~default:Z.zero ["pvm"; "last_top_level_call"] Data_encoding.n) - (value - ~default:Constants.wasm_max_tick - ["pvm"; "max_nb_ticks"] - Data_encoding.n) + (value ["pvm"; "max_nb_ticks"] Data_encoding.n) (value ~default:Constants.maximum_reboots_per_input ["pvm"; "maximum_reboots_per_input"] @@ -207,7 +204,7 @@ module Make_pvm (Wasm_vm : Wasm_vm_sig.S) (T : Tezos_tree_encoding.TREE) : let* tree = T.remove tree ["wasm"] in Tree_encoding_runner.encode pvm_state_encoding pvm_state tree - let install_boot_sector bs tree = + let install_boot_sector ~ticks_per_snapshot bs tree = (* TODO: https://gitlab.com/tezos/tezos/-/issues/4240 We cannot manipulate the durable storage at this point, because the `durable` directory is empty. *) @@ -215,7 +212,7 @@ module Make_pvm (Wasm_vm : Wasm_vm_sig.S) (T : Tezos_tree_encoding.TREE) : let bs = Tezos_lazy_containers.Chunked_byte_vector.of_string bs in Tree_encoding_runner.encode Tezos_tree_encoding.( - tup2 + tup3 ~flatten:true (* We set the reboot flag in the durable storage to allow a reboot to the evaluation phase once the collection of the @@ -226,8 +223,9 @@ module Make_pvm (Wasm_vm : Wasm_vm_sig.S) (T : Tezos_tree_encoding.TREE) : (scope ["durable"; "kernel"; "env"; "reboot"; "_"] chunked_byte_vector) - (scope ["durable"; "kernel"; "boot.wasm"; "_"] chunked_byte_vector)) - (reboot_flag, bs) + (scope ["durable"; "kernel"; "boot.wasm"; "_"] chunked_byte_vector) + (value ["pvm"; "max_nb_ticks"] Data_encoding.n)) + (reboot_flag, bs, ticks_per_snapshot) tree let compute_step_many ?builtins ?stop_at_snapshot ~max_steps tree = diff --git a/src/lib_scoru_wasm/wasm_pvm_sig.ml b/src/lib_scoru_wasm/wasm_pvm_sig.ml index 21623ab7121c9f3dd326ecac336965582ee6b14e..a2fe3a864bae7ccee63ec2fe483925d2f00ec473 100644 --- a/src/lib_scoru_wasm/wasm_pvm_sig.ml +++ b/src/lib_scoru_wasm/wasm_pvm_sig.ml @@ -60,10 +60,11 @@ module type S = sig include Wasm_vm_sig.Generic with type state := tree - (** [install_boot_sector payload tree] installs the [payload] passed - as an argument in [tree] so that it is interpreted as the kernel - to be used by the PVM. *) - val install_boot_sector : string -> tree -> tree Lwt.t + (** [install_boot_sector ~ticks_per_snapshot payload tree] installs + the [payload] passed as an argument in [tree] so that it is + interpreted as the kernel to be used by the PVM. *) + val install_boot_sector : + ticks_per_snapshot:Z.t -> string -> tree -> tree Lwt.t (** [get_output output state] returns the payload associated with the given output. The result is meant to be deserialized using diff --git a/src/proto_alpha/bin_wasm_repl/main_wasm_repl_alpha.ml b/src/proto_alpha/bin_wasm_repl/main_wasm_repl_alpha.ml index 9d0b9c72c5d88c20c04c6263dd3871bf4d7985dc..9215a094fc59cbfd07adf4f7fde4c3ae42ded62f 100644 --- a/src/proto_alpha/bin_wasm_repl/main_wasm_repl_alpha.ml +++ b/src/proto_alpha/bin_wasm_repl/main_wasm_repl_alpha.ml @@ -57,6 +57,7 @@ let link module_ = installation into a tree for the PVM interpreter. *) let handle_module binary name module_ = let open Lwt_result_syntax in + let open Protocol.Alpha_context.Sc_rollup in let* ast = Repl_helpers.trap_exn (fun () -> if binary then parse_binary_module name module_ @@ -67,7 +68,7 @@ let handle_module binary name module_ = let* _ = link ast in let*! tree = initial_tree - ~max_tick:(Z.to_int64 Tezos_scoru_wasm.Constants.wasm_max_tick) + ~max_tick:(Z.to_int64 Wasm_2_0_0PVM.ticks_per_snapshot) ~from_binary:binary module_ in diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 63068a8cc2f60875600cab287a6bd695ff79b9e9..5a7cb2bc2603872c141842854a55c07f296b193d 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3632,6 +3632,8 @@ module Sc_rollup : sig end module Wasm_2_0_0PVM : sig + val ticks_per_snapshot : Z.t + module type P = sig module Tree : Context.TREE with type key = string list and type value = bytes diff --git a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml index 812bd9a685254132b7e22bd0937c8347dfcc6049..fb5b07f5507934fdaf69937f3556e614cbe261e0 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_wasm.ml @@ -66,6 +66,8 @@ let () = (fun () -> WASM_proof_production_failed) module V2_0_0 = struct + let ticks_per_snapshot = Z.of_int64 11_000_000_000L + (* This is the state hash of reference that both the prover of the node and the verifier of the protocol {!Protocol_implementation} @@ -242,7 +244,7 @@ module V2_0_0 = struct Lwt.return state let install_boot_sector state boot_sector = - WASM_machine.install_boot_sector boot_sector state + WASM_machine.install_boot_sector ~ticks_per_snapshot boot_sector state let state_hash state = let context_hash = Tree.hash state in diff --git a/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli b/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli index 3d42188d8863f4bd219a346eaa86cf3eddfffa12..35f7ef51753efd072dc4d7eb4fa6d42169306676 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_wasm.mli @@ -109,4 +109,19 @@ module V2_0_0 : sig have to agree on (if they do, it means they are using the same tree structure). *) val reference_initial_state_hash : Sc_rollup_repr.State_hash.t + + (** Number of ticks between snapshotable states, chosen low enough + to maintain refutability. + + {b Warning:} This value is used to specialize the dissection + predicate of the WASM PVM. Do not change it without a migration + plan for already originated smart rollups. + + Depends on + - speed (tick/s) of node in slow mode (from benchmark, 6000000 tick/s) + - the number of ticks in a commitment ({!Int64.max_int}, + as per Number_of_ticks.max_value) + + see #3590 for more pointers *) + val ticks_per_snapshot : Z.t end 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 187b2a935c9bf1da042f7d75a6add5de085ec14d..82a7afc1f409eeb96efb24ceec6982a1e9f0cf65 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 @@ -233,7 +233,12 @@ let test_output () = match parsed.it with Script.Textual m -> m | _ -> assert false in let*! boot_sector = Encode.encode parsed in - let*! tree = Wasm.install_boot_sector boot_sector empty_tree in + let*! tree = + Wasm.install_boot_sector + ~ticks_per_snapshot:Sc_rollup_wasm.V2_0_0.ticks_per_snapshot + boot_sector + empty_tree + in let*! tree = Wasm.Internal_for_tests.set_max_nb_ticks (Z.of_int64 50_000_000L) tree in