diff --git a/src/lib_scoru_wasm/fast/exec.ml b/src/lib_scoru_wasm/fast/exec.ml index 6d6e7dfa69e0cade416fbc414685374b42a55f9a..1d72df6e4e93bd0da79ec4ec979060a8bbe2c529 100644 --- a/src/lib_scoru_wasm/fast/exec.ml +++ b/src/lib_scoru_wasm/fast/exec.ml @@ -57,7 +57,7 @@ let load_kernel durable = let store = Lazy.force store in Module_cache.load_kernel store durable -let compute ~reveal_builtins ~write_debug durable buffers = +let compute ~version ~reveal_builtins ~write_debug durable buffers = let open Lwt.Syntax in let* module_ = load_kernel durable in @@ -67,7 +67,9 @@ let compute ~reveal_builtins ~write_debug durable buffers = in let host_state = Funcs.{retrieve_mem; buffers; durable} in - let host_funcs = Funcs.make ~reveal_builtins ~write_debug host_state in + let host_funcs = + Funcs.make ~version ~reveal_builtins ~write_debug host_state + in let with_durable f = let+ durable = f host_state.durable in diff --git a/src/lib_scoru_wasm/fast/exec.mli b/src/lib_scoru_wasm/fast/exec.mli index cf793f0d745f7e6d846c281a4e4ac1d6dac376e9..b7d7399d60af39ad588b960a98b0ee4ab01faa3e 100644 --- a/src/lib_scoru_wasm/fast/exec.mli +++ b/src/lib_scoru_wasm/fast/exec.mli @@ -28,6 +28,7 @@ open Tezos_webassembly_interpreter (** [compute durable buffers] applies one call to [kernel_run]. *) val compute : + version:Wasm_pvm_state.version -> reveal_builtins:Builtins.reveals -> write_debug:Builtins.write_debug -> Durable.t -> diff --git a/src/lib_scoru_wasm/fast/funcs.ml b/src/lib_scoru_wasm/fast/funcs.ml index 4de508b19fbb84257d063d4df5a7369fd2963fc9..a10b46c8ece865cbeecafa337da55d926edfda2a 100644 --- a/src/lib_scoru_wasm/fast/funcs.ml +++ b/src/lib_scoru_wasm/fast/funcs.ml @@ -38,7 +38,7 @@ type host_state = { mutable durable : Durable.t; } -let make ~reveal_builtins ~write_debug state = +let make ~version ~reveal_builtins ~write_debug state = let open Wasmer in let open Lwt.Syntax in let with_mem f = @@ -244,8 +244,7 @@ let make ~reveal_builtins ~write_debug state = ~payload:(Bytes.of_string payload)) in - List.map - (fun (name, impl) -> (Constants.wasm_host_funcs_virual_module, name, impl)) + let base = [ ("read_input", read_input); ("write_output", write_output); @@ -262,3 +261,8 @@ let make ~reveal_builtins ~write_debug state = ("reveal_preimage", reveal_preimage); ("reveal_metadata", reveal_metadata); ] + in + let extra = match version with Wasm_pvm_state.V0 | V1 -> [] in + List.map + (fun (name, impl) -> (Constants.wasm_host_funcs_virual_module, name, impl)) + (base @ extra) diff --git a/src/lib_scoru_wasm/fast/funcs.mli b/src/lib_scoru_wasm/fast/funcs.mli index 0b25208613757fb141159534399b014ba6bd33d8..39ed83addb0280532d13dc86f88b7d35b425d9ca 100644 --- a/src/lib_scoru_wasm/fast/funcs.mli +++ b/src/lib_scoru_wasm/fast/funcs.mli @@ -39,6 +39,7 @@ type host_state = { implementation for [write_debug] will be picked that prints to the standard output. *) val make : + version:Wasm_pvm_state.version -> reveal_builtins:Builtins.reveals -> write_debug:Builtins.write_debug -> host_state -> diff --git a/src/lib_scoru_wasm/fast/vm.ml b/src/lib_scoru_wasm/fast/vm.ml index 80a474334f67eb62d4eb037ad6772ccb772cf19e..e7094881123a8572154656575fe680926b338492 100644 --- a/src/lib_scoru_wasm/fast/vm.ml +++ b/src/lib_scoru_wasm/fast/vm.ml @@ -42,9 +42,11 @@ let compute_until_snapshot ~max_steps ?write_debug pvm_state = let compute_fast ~reveal_builtins ~write_debug pvm_state = let open Lwt.Syntax in + let* version = Wasm_vm.get_wasm_version pvm_state in (* Execute! *) let* durable = Exec.compute + ~version ~reveal_builtins ~write_debug pvm_state.durable @@ -161,10 +163,10 @@ let rec compute_step_many accum_ticks ?reveal_builtins let compute_step_many = compute_step_many 0L +let get_wasm_version = Wasm_vm.get_wasm_version + module Internal_for_tests = struct let compute_step_many_with_hooks = compute_step_many - - let get_wasm_version = Wasm_vm.Internal_for_tests.get_wasm_version end let compute_step_many = compute_step_many ?after_fast_exec:None diff --git a/src/lib_scoru_wasm/test/test_protocol_migration.ml b/src/lib_scoru_wasm/test/test_protocol_migration.ml index bf1e98fe1454d9e8d85640156f2bf2dc8f57db7f..ede388112a1cd17cecf964a03a4da50e9aeed6a8 100644 --- a/src/lib_scoru_wasm/test/test_protocol_migration.ml +++ b/src/lib_scoru_wasm/test/test_protocol_migration.ml @@ -47,15 +47,15 @@ let test_protocol_migration_message () = let open Lwt_syntax in let* tree = initial_tree ~version:V0 noop_module in let* tree = eval_until_input_requested tree in - let* version = Wasm.Internal_for_tests.get_wasm_version tree in + let* version = Wasm.get_wasm_version tree in assert (version = V0) ; let* tree = set_empty_inbox_step 0l tree in let* tree = eval_until_input_requested tree in - let* version = Wasm.Internal_for_tests.get_wasm_version tree in + let* version = Wasm.get_wasm_version tree in assert (version = V0) ; let* tree = set_empty_inbox_step ~migrate_to:Proto_alpha 0l tree in let* tree = eval_until_input_requested tree in - let* version = Wasm.Internal_for_tests.get_wasm_version tree in + let* version = Wasm.get_wasm_version tree in assert (version = V1) ; Lwt_result_syntax.return_unit diff --git a/src/lib_scoru_wasm/wasm_pvm.ml b/src/lib_scoru_wasm/wasm_pvm.ml index ddeb0a0da41c0529558cba044bc80433227d743e..e1b6f0bd64837681667da001da54e343f497ab3b 100644 --- a/src/lib_scoru_wasm/wasm_pvm.ml +++ b/src/lib_scoru_wasm/wasm_pvm.ml @@ -341,6 +341,11 @@ module Make_pvm (Wasm_vm : Wasm_vm_sig.S) (T : Tezos_tree_encoding.TREE) : let* pvm_state = Wasm_vm.reveal_step payload pvm_state in encode pvm_state tree + let get_wasm_version tree = + let open Lwt.Syntax in + let* pvm = Tree_encoding_runner.decode pvm_state_encoding tree in + Wasm_vm.get_wasm_version pvm + module Internal_for_tests = struct let get_tick_state tree = let open Lwt_syntax in @@ -409,11 +414,6 @@ module Make_pvm (Wasm_vm : Wasm_vm_sig.S) (T : Tezos_tree_encoding.TREE) : let+ pvm = Tree_encoding_runner.decode pvm_state_encoding tree in pvm.buffers.input - let get_wasm_version tree = - let open Lwt.Syntax in - let* pvm = Tree_encoding_runner.decode pvm_state_encoding tree in - Wasm_vm.Internal_for_tests.get_wasm_version pvm - let compute_step_many_with_hooks ?reveal_builtins ?write_debug ?after_fast_exec ?stop_at_snapshot ~max_steps tree = let open Lwt.Syntax in diff --git a/src/lib_scoru_wasm/wasm_vm.ml b/src/lib_scoru_wasm/wasm_vm.ml index a12d92712c5650a0f9fb22d7f96517b90fc8a52f..0df600753f17eff808ce8d6982598b1d764eaff6 100644 --- a/src/lib_scoru_wasm/wasm_vm.ml +++ b/src/lib_scoru_wasm/wasm_vm.ml @@ -711,6 +711,4 @@ module Internal_for_tests = struct let compute_step_many_with_hooks ?reveal_builtins ?write_debug ?after_fast_exec:_ = compute_step_many ?reveal_builtins ?write_debug - - let get_wasm_version = get_wasm_version end diff --git a/src/lib_scoru_wasm/wasm_vm_sig.ml b/src/lib_scoru_wasm/wasm_vm_sig.ml index faa756a6c22ece4aa1c63e4f9de2707ac7d9eac8..cb41e36f95fe983c541ac22319b0e4f004a44a01 100644 --- a/src/lib_scoru_wasm/wasm_vm_sig.ml +++ b/src/lib_scoru_wasm/wasm_vm_sig.ml @@ -37,8 +37,6 @@ module type Internal_for_tests = sig max_steps:int64 -> state -> (state * int64) Lwt.t - - val get_wasm_version : state -> version Lwt.t end module type Generic = sig @@ -88,6 +86,10 @@ module type Generic = sig Should not raise. *) val get_info : state -> info Lwt.t + (** [get_wasm_version pvm_state] returns the current version at + which the WASM PVM operates. *) + val get_wasm_version : state -> version Lwt.t + module Internal_for_tests : Internal_for_tests with type state := state end