From 1c03145dbcac25522e3c5a88a0155ecacbd77bc5 Mon Sep 17 00:00:00 2001 From: Venkkatesh Sekar Date: Wed, 29 Apr 2026 09:19:34 +0000 Subject: [PATCH] chore: upgrade wirm from 2.1.0 to 4.0.4 Adapt to wirm 4.0.4 API changes: `Module::parse` and `Instructions::new` gained extra arguments, several methods (`unwrap_local_mut`, `get_ops_mut`, `params`, `encode`, `replace_import_in_module`) now return `Result`, and `wasmparser::TypeRef` gained a `FuncExact` variant which we reject in the import validation alongside other unsupported import kinds. --- Cargo.Bazel.json.lock | 354 +++++++++--------- Cargo.Bazel.toml.lock | 116 +++--- Cargo.lock | 133 ++++--- Cargo.toml | 2 +- bazel/rust.MODULE.bazel | 2 +- .../benches/embedders_bench/src/lib.rs | 2 +- .../src/wasm_utils/instrumentation.rs | 39 +- .../src/wasm_utils/system_api_replacements.rs | 6 +- rs/embedders/src/wasm_utils/validation.rs | 7 +- rs/embedders/tests/instrumentation.rs | 8 +- rs/embedders/tests/misc_tests.rs | 4 +- rs/embedders/tests/spec_tests.rs | 6 +- rs/embedders/tests/wirm_round_trip.rs | 4 +- 13 files changed, 368 insertions(+), 315 deletions(-) diff --git a/Cargo.Bazel.json.lock b/Cargo.Bazel.json.lock index 92984b8e5b92..2cbdd8157f99 100644 --- a/Cargo.Bazel.json.lock +++ b/Cargo.Bazel.json.lock @@ -1,5 +1,5 @@ { - "checksum": "973d5e40f08086e83617bf7cc893f4c4fbc17cd1d8798002a0f3c65eec39fe79", + "checksum": "e468bb9588953e73bdaa7908f2dd4d5f8a6e7fd9fc861e0bd647fa6472e5e857", "crates": { "abnf 0.12.0": { "name": "abnf", @@ -1998,7 +1998,7 @@ "target": "http" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -21905,7 +21905,7 @@ "target": "idna" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -22754,7 +22754,7 @@ "target": "which" }, { - "id": "wirm 2.1.0", + "id": "wirm 4.0.4", "target": "wirm" }, { @@ -30228,7 +30228,7 @@ "target": "hashbrown" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" } ], @@ -30803,7 +30803,7 @@ "target": "http" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -30896,7 +30896,7 @@ "target": "http" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -31391,6 +31391,65 @@ ], "license_file": "LICENSE-APACHE" }, + "hashbrown 0.17.0": { + "name": "hashbrown", + "version": "0.17.0", + "package_url": "https://github.com/rust-lang/hashbrown", + "repository": { + "Http": { + "url": "https://static.crates.io/crates/hashbrown/0.17.0/download", + "sha256": "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" + } + }, + "targets": [ + { + "Library": { + "crate_name": "hashbrown", + "crate_root": "src/lib.rs", + "srcs": { + "allow_empty": true, + "include": [ + "**/*.rs" + ] + } + } + } + ], + "library_target_name": "hashbrown", + "common_attrs": { + "compile_data_glob": [ + "**" + ], + "crate_features": { + "common": [ + "default-hasher", + "serde" + ], + "selects": {} + }, + "deps": { + "common": [ + { + "id": "foldhash 0.2.0", + "target": "foldhash" + }, + { + "id": "serde_core 1.0.228", + "target": "serde_core" + } + ], + "selects": {} + }, + "edition": "2024", + "version": "0.17.0" + }, + "license": "MIT OR Apache-2.0", + "license_ids": [ + "Apache-2.0", + "MIT" + ], + "license_file": "LICENSE-APACHE" + }, "hashlink 0.8.3": { "name": "hashlink", "version": "0.8.3", @@ -40220,14 +40279,14 @@ ], "license_file": "LICENSE-APACHE" }, - "indexmap 2.13.0": { + "indexmap 2.14.0": { "name": "indexmap", - "version": "2.13.0", + "version": "2.14.0", "package_url": "https://github.com/indexmap-rs/indexmap", "repository": { "Http": { - "url": "https://static.crates.io/crates/indexmap/2.13.0/download", - "sha256": "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" + "url": "https://static.crates.io/crates/indexmap/2.14.0/download", + "sha256": "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" } }, "targets": [ @@ -40264,7 +40323,7 @@ "target": "equivalent" }, { - "id": "hashbrown 0.16.1", + "id": "hashbrown 0.17.0", "target": "hashbrown" }, { @@ -40274,8 +40333,8 @@ ], "selects": {} }, - "edition": "2021", - "version": "2.13.0" + "edition": "2024", + "version": "2.14.0" }, "license": "Apache-2.0 OR MIT", "license_ids": [ @@ -40494,7 +40553,7 @@ "target": "dashmap" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -40612,7 +40671,7 @@ "target": "env_logger" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -52587,7 +52646,7 @@ "target": "hashbrown" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -53616,7 +53675,7 @@ "target": "futures_sink" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -56573,7 +56632,7 @@ "target": "fixedbitset" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" } ], @@ -65593,7 +65652,7 @@ "target": "aho_corasick" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -70848,7 +70907,7 @@ "target": "dyn_clone" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap", "alias": "indexmap2" }, @@ -73751,7 +73810,7 @@ "deps": { "common": [ { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -73815,7 +73874,7 @@ "deps": { "common": [ { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -83275,7 +83334,7 @@ "deps": { "common": [ { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -83339,7 +83398,7 @@ "deps": { "common": [ { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -83926,7 +83985,7 @@ "target": "hdrhistogram" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -89567,14 +89626,14 @@ ], "license_file": "LICENSE" }, - "wasm-encoder 0.239.0": { + "wasm-encoder 0.244.0": { "name": "wasm-encoder", - "version": "0.239.0", + "version": "0.244.0", "package_url": "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wasm-encoder", "repository": { "Http": { - "url": "https://static.crates.io/crates/wasm-encoder/0.239.0/download", - "sha256": "5be00faa2b4950c76fe618c409d2c3ea5a3c9422013e079482d78544bb2d184c" + "url": "https://static.crates.io/crates/wasm-encoder/0.244.0/download", + "sha256": "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" } }, "targets": [ @@ -89589,18 +89648,6 @@ ] } } - }, - { - "BuildScript": { - "crate_name": "build_script_build", - "crate_root": "build.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } } ], "library_target_name": "wasm_encoder", @@ -89611,9 +89658,7 @@ "crate_features": { "common": [ "component-model", - "default", - "std", - "wasmparser" + "std" ], "selects": {} }, @@ -89622,31 +89667,12 @@ { "id": "leb128fmt 0.1.0", "target": "leb128fmt" - }, - { - "id": "wasm-encoder 0.239.0", - "target": "build_script_build" - }, - { - "id": "wasmparser 0.239.0", - "target": "wasmparser" } ], "selects": {} }, "edition": "2021", - "version": "0.239.0" - }, - "build_script_attrs": { - "compile_data_glob": [ - "**" - ], - "compile_data_glob_excludes": [ - "**/*.rs" - ], - "data_glob": [ - "**" - ] + "version": "0.244.0" }, "license": "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT", "license_ids": [ @@ -89655,14 +89681,14 @@ ], "license_file": null }, - "wasm-encoder 0.244.0": { + "wasm-encoder 0.245.1": { "name": "wasm-encoder", - "version": "0.244.0", + "version": "0.245.1", "package_url": "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wasm-encoder", "repository": { "Http": { - "url": "https://static.crates.io/crates/wasm-encoder/0.244.0/download", - "sha256": "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" + "url": "https://static.crates.io/crates/wasm-encoder/0.245.1/download", + "sha256": "3f9dca005e69bf015e45577e415b9af8c67e8ee3c0e38b5b0add5aa92581ed5c" } }, "targets": [ @@ -89687,7 +89713,9 @@ "crate_features": { "common": [ "component-model", - "std" + "default", + "std", + "wasmparser" ], "selects": {} }, @@ -89696,12 +89724,16 @@ { "id": "leb128fmt 0.1.0", "target": "leb128fmt" + }, + { + "id": "wasmparser 0.245.1", + "target": "wasmparser" } ], "selects": {} }, "edition": "2021", - "version": "0.244.0" + "version": "0.245.1" }, "license": "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT", "license_ids": [ @@ -89710,14 +89742,14 @@ ], "license_file": null }, - "wasm-encoder 0.245.1": { + "wasm-encoder 0.247.0": { "name": "wasm-encoder", - "version": "0.245.1", + "version": "0.247.0", "package_url": "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wasm-encoder", "repository": { "Http": { - "url": "https://static.crates.io/crates/wasm-encoder/0.245.1/download", - "sha256": "3f9dca005e69bf015e45577e415b9af8c67e8ee3c0e38b5b0add5aa92581ed5c" + "url": "https://static.crates.io/crates/wasm-encoder/0.247.0/download", + "sha256": "30b6733b8b91d010a6ac5b0fb237dc46a19650bc4c67db66857e2e787d437204" } }, "targets": [ @@ -89755,21 +89787,21 @@ "target": "leb128fmt" }, { - "id": "wasmparser 0.245.1", + "id": "wasmparser 0.247.0", "target": "wasmparser" } ], "selects": {} }, "edition": "2021", - "version": "0.245.1" + "version": "0.247.0" }, "license": "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT", "license_ids": [ "Apache-2.0", "MIT" ], - "license_file": null + "license_file": "LICENSE-APACHE" }, "wasm-smith 0.245.1": { "name": "wasm-smith", @@ -89958,7 +89990,7 @@ "target": "hashbrown" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -90034,7 +90066,7 @@ "target": "hashbrown" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -90122,7 +90154,7 @@ "target": "hashbrown" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -90161,14 +90193,14 @@ ], "license_file": null }, - "wasmparser 0.239.0": { + "wasmparser 0.244.0": { "name": "wasmparser", - "version": "0.239.0", + "version": "0.244.0", "package_url": "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wasmparser", "repository": { "Http": { - "url": "https://static.crates.io/crates/wasmparser/0.239.0/download", - "sha256": "8c9d90bb93e764f6beabf1d02028c70a2156a6583e63ac4218dd07ef733368b0" + "url": "https://static.crates.io/crates/wasmparser/0.244.0/download", + "sha256": "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" } }, "targets": [ @@ -90183,18 +90215,6 @@ ] } } - }, - { - "BuildScript": { - "crate_name": "build_script_build", - "crate_root": "build.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } } ], "library_target_name": "wasmparser", @@ -90202,61 +90222,17 @@ "compile_data_glob": [ "**" ], - "crate_features": { - "common": [ - "component-model", - "default", - "features", - "hash-collections", - "serde", - "simd", - "std", - "validate" - ], - "selects": {} - }, "deps": { "common": [ { "id": "bitflags 2.10.0", "target": "bitflags" - }, - { - "id": "hashbrown 0.15.2", - "target": "hashbrown" - }, - { - "id": "indexmap 2.13.0", - "target": "indexmap" - }, - { - "id": "semver 1.0.27", - "target": "semver" - }, - { - "id": "serde 1.0.228", - "target": "serde" - }, - { - "id": "wasmparser 0.239.0", - "target": "build_script_build" } ], "selects": {} }, "edition": "2021", - "version": "0.239.0" - }, - "build_script_attrs": { - "compile_data_glob": [ - "**" - ], - "compile_data_glob_excludes": [ - "**/*.rs" - ], - "data_glob": [ - "**" - ] + "version": "0.244.0" }, "license": "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT", "license_ids": [ @@ -90265,14 +90241,14 @@ ], "license_file": null }, - "wasmparser 0.244.0": { + "wasmparser 0.245.1": { "name": "wasmparser", - "version": "0.244.0", + "version": "0.245.1", "package_url": "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wasmparser", "repository": { "Http": { - "url": "https://static.crates.io/crates/wasmparser/0.244.0/download", - "sha256": "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" + "url": "https://static.crates.io/crates/wasmparser/0.245.1/download", + "sha256": "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" } }, "targets": [ @@ -90294,17 +90270,46 @@ "compile_data_glob": [ "**" ], + "crate_features": { + "common": [ + "component-model", + "default", + "features", + "hash-collections", + "serde", + "simd", + "std", + "validate" + ], + "selects": {} + }, "deps": { "common": [ { "id": "bitflags 2.10.0", "target": "bitflags" + }, + { + "id": "hashbrown 0.16.1", + "target": "hashbrown" + }, + { + "id": "indexmap 2.14.0", + "target": "indexmap" + }, + { + "id": "semver 1.0.27", + "target": "semver" + }, + { + "id": "serde 1.0.228", + "target": "serde" } ], "selects": {} }, "edition": "2021", - "version": "0.244.0" + "version": "0.245.1" }, "license": "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT", "license_ids": [ @@ -90313,14 +90318,14 @@ ], "license_file": null }, - "wasmparser 0.245.1": { + "wasmparser 0.247.0": { "name": "wasmparser", - "version": "0.245.1", + "version": "0.247.0", "package_url": "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wasmparser", "repository": { "Http": { - "url": "https://static.crates.io/crates/wasmparser/0.245.1/download", - "sha256": "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" + "url": "https://static.crates.io/crates/wasmparser/0.247.0/download", + "sha256": "8e6fb4c2bee46c5ea4d40f8cdb5c131725cd976718ec56f1c8e82fbde5fa2a80" } }, "targets": [ @@ -90362,11 +90367,11 @@ "target": "bitflags" }, { - "id": "hashbrown 0.16.1", + "id": "hashbrown 0.17.0", "target": "hashbrown" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -90381,14 +90386,14 @@ "selects": {} }, "edition": "2021", - "version": "0.245.1" + "version": "0.247.0" }, "license": "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT", "license_ids": [ "Apache-2.0", "MIT" ], - "license_file": null + "license_file": "LICENSE-APACHE" }, "wasmprinter 0.245.1": { "name": "wasmprinter", @@ -90785,7 +90790,7 @@ "target": "hashbrown" }, { - "id": "indexmap 2.13.0", + "id": "indexmap 2.14.0", "target": "indexmap" }, { @@ -96360,14 +96365,14 @@ ], "license_file": "LICENSE" }, - "wirm 2.1.0": { + "wirm 4.0.4": { "name": "wirm", - "version": "2.1.0", - "package_url": "https://github.com/thesuhas/wirm", + "version": "4.0.4", + "package_url": "https://github.com/composablesys/wirm", "repository": { "Http": { - "url": "https://static.crates.io/crates/wirm/2.1.0/download", - "sha256": "14732cb9a0eaf9ec52ecd36b9394ade5c16eea5405d160d8829f0199d97d507d" + "url": "https://static.crates.io/crates/wirm/4.0.4/download", + "sha256": "4b545057c2fa3f2a83aa2d23f9010e372b880aa6973f04c0cb8400a2e813e8f0" } }, "targets": [ @@ -96408,26 +96413,27 @@ "target": "rayon" }, { - "id": "serde_json 1.0.145", - "target": "serde_json" - }, - { - "id": "tempfile 3.23.0", - "target": "tempfile" - }, - { - "id": "wasm-encoder 0.239.0", + "id": "wasm-encoder 0.247.0", "target": "wasm_encoder" }, { - "id": "wasmparser 0.239.0", + "id": "wasmparser 0.247.0", "target": "wasmparser" } ], "selects": {} }, "edition": "2021", - "version": "2.1.0" + "proc_macro_deps": { + "common": [ + { + "id": "paste 1.0.15", + "target": "paste" + } + ], + "selects": {} + }, + "version": "4.0.4" }, "license": "Apache-2.0", "license_ids": [ @@ -98994,7 +99000,7 @@ "icrc1-test-env 0.1.1", "icrc1-test-suite 0.1.1", "idna 1.0.3", - "indexmap 2.13.0", + "indexmap 2.14.0", "indicatif 0.17.5", "indoc 1.0.9", "inferno 0.12.0", @@ -99214,7 +99220,7 @@ "wat 1.245.1", "webpki-roots 1.0.6", "which 4.4.0", - "wirm 2.1.0", + "wirm 4.0.4", "wsl 0.1.0", "wycheproof 0.6.0", "x509-cert 0.2.5", diff --git a/Cargo.Bazel.toml.lock b/Cargo.Bazel.toml.lock index 3287600e3c3b..543ac0e14161 100644 --- a/Cargo.Bazel.toml.lock +++ b/Cargo.Bazel.toml.lock @@ -357,7 +357,7 @@ dependencies = [ "bytes", "cfg-if 1.0.0", "http 1.3.1", - "indexmap 2.13.0", + "indexmap 2.14.0", "schemars 0.8.21", "serde", "serde_json", @@ -3767,7 +3767,7 @@ dependencies = [ "icrc1-test-env", "icrc1-test-suite", "idna 1.0.3", - "indexmap 2.13.0", + "indexmap 2.14.0", "indicatif", "indoc 1.0.9", "inferno 0.12.0", @@ -5194,7 +5194,7 @@ checksum = "0bf7f043f89559805f8c7cacc432749b2fa0d0a0a9ee46ce47164ed5ba7f126c" dependencies = [ "fnv", "hashbrown 0.16.1", - "indexmap 2.13.0", + "indexmap 2.14.0", "stable_deref_trait", ] @@ -5308,7 +5308,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.13.0", + "indexmap 2.14.0", "slab", "tokio", "tokio-util", @@ -5327,7 +5327,7 @@ dependencies = [ "futures-sink", "futures-util", "http 1.3.1", - "indexmap 2.13.0", + "indexmap 2.14.0", "slab", "tokio", "tokio-util", @@ -5409,6 +5409,17 @@ dependencies = [ "serde_core", ] +[[package]] +name = "hashbrown" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" +dependencies = [ + "foldhash 0.2.0", + "serde", + "serde_core", +] + [[package]] name = "hashlink" version = "0.8.3" @@ -7057,12 +7068,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.13.0" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown 0.16.1", + "hashbrown 0.17.0", "serde", "serde_core", ] @@ -7105,7 +7116,7 @@ dependencies = [ "crossbeam-channel", "crossbeam-utils", "dashmap 5.5.0", - "indexmap 2.13.0", + "indexmap 2.14.0", "is-terminal", "itoa", "log", @@ -7128,7 +7139,7 @@ dependencies = [ "crossbeam-utils", "dashmap 6.1.0", "env_logger 0.11.2", - "indexmap 2.13.0", + "indexmap 2.14.0", "itoa", "log", "num-format", @@ -8989,7 +9000,7 @@ checksum = "271638cd5fa9cca89c4c304675ca658efc4e64a66c716b7cfe1afb4b9611dbbc" dependencies = [ "crc32fast", "hashbrown 0.16.1", - "indexmap 2.13.0", + "indexmap 2.14.0", "memchr", ] @@ -9143,7 +9154,7 @@ checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" dependencies = [ "futures-core", "futures-sink", - "indexmap 2.13.0", + "indexmap 2.14.0", "js-sys", "once_cell", "pin-project-lite", @@ -9640,7 +9651,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772" dependencies = [ "fixedbitset 0.5.7", - "indexmap 2.13.0", + "indexmap 2.14.0", ] [[package]] @@ -11134,7 +11145,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c11639076bf147be211b90e47790db89f4c22b6c8a9ca6e960833869da67166" dependencies = [ "aho-corasick", - "indexmap 2.13.0", + "indexmap 2.14.0", "itertools 0.13.0", "nohash", "regex", @@ -11403,7 +11414,7 @@ dependencies = [ "bytecheck 0.8.2", "bytes", "hashbrown 0.16.1", - "indexmap 2.13.0", + "indexmap 2.14.0", "munge", "ptr_meta 0.3.1", "rancor", @@ -11932,7 +11943,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" dependencies = [ "dyn-clone", - "indexmap 2.13.0", + "indexmap 2.14.0", "schemars_derive", "serde", "serde_json", @@ -12369,7 +12380,7 @@ dependencies = [ "chrono 0.4.42", "hex", "indexmap 1.9.3", - "indexmap 2.13.0", + "indexmap 2.14.0", "schemars 0.9.0", "schemars 1.1.0", "serde_core", @@ -12432,7 +12443,7 @@ version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.13.0", + "indexmap 2.14.0", "itoa", "ryu", "serde", @@ -12445,7 +12456,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b4db627b98b36d4203a7b458cf3573730f2bb591b28871d916dfa9efabfd41f" dependencies = [ - "indexmap 2.13.0", + "indexmap 2.14.0", "itoa", "ryu", "serde", @@ -13981,7 +13992,7 @@ version = "0.19.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" dependencies = [ - "indexmap 2.13.0", + "indexmap 2.14.0", "toml_datetime", "winnow 0.5.0", ] @@ -13992,7 +14003,7 @@ version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ - "indexmap 2.13.0", + "indexmap 2.14.0", "toml_datetime", "winnow 0.6.20", ] @@ -14099,7 +14110,7 @@ dependencies = [ "futures-core", "futures-util", "hdrhistogram", - "indexmap 2.13.0", + "indexmap 2.14.0", "pin-project-lite", "slab", "sync_wrapper 1.0.2", @@ -15070,32 +15081,32 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.239.0" +version = "0.244.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be00faa2b4950c76fe618c409d2c3ea5a3c9422013e079482d78544bb2d184c" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" dependencies = [ "leb128fmt", - "wasmparser 0.239.0", + "wasmparser 0.244.0", ] [[package]] name = "wasm-encoder" -version = "0.244.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +checksum = "3f9dca005e69bf015e45577e415b9af8c67e8ee3c0e38b5b0add5aa92581ed5c" dependencies = [ "leb128fmt", - "wasmparser 0.244.0", + "wasmparser 0.245.1", ] [[package]] name = "wasm-encoder" -version = "0.245.1" +version = "0.247.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9dca005e69bf015e45577e415b9af8c67e8ee3c0e38b5b0add5aa92581ed5c" +checksum = "30b6733b8b91d010a6ac5b0fb237dc46a19650bc4c67db66857e2e787d437204" dependencies = [ "leb128fmt", - "wasmparser 0.245.1", + "wasmparser 0.247.0", ] [[package]] @@ -15133,7 +15144,7 @@ dependencies = [ "ahash 0.8.11", "bitflags 2.10.0", "hashbrown 0.14.5", - "indexmap 2.13.0", + "indexmap 2.14.0", "semver", "serde", ] @@ -15147,7 +15158,7 @@ dependencies = [ "ahash 0.8.11", "bitflags 2.10.0", "hashbrown 0.14.5", - "indexmap 2.13.0", + "indexmap 2.14.0", "semver", "serde", ] @@ -15160,44 +15171,44 @@ checksum = "161296c618fa2d63f6ed5fffd1112937e803cb9ec71b32b01a76321555660917" dependencies = [ "bitflags 2.10.0", "hashbrown 0.15.2", - "indexmap 2.13.0", + "indexmap 2.14.0", "semver", "serde", ] [[package]] name = "wasmparser" -version = "0.239.0" +version = "0.244.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9d90bb93e764f6beabf1d02028c70a2156a6583e63ac4218dd07ef733368b0" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" dependencies = [ "bitflags 2.10.0", - "hashbrown 0.15.2", - "indexmap 2.13.0", + "indexmap 2.14.0", "semver", - "serde", ] [[package]] name = "wasmparser" -version = "0.244.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" dependencies = [ "bitflags 2.10.0", - "indexmap 2.13.0", + "hashbrown 0.16.1", + "indexmap 2.14.0", "semver", + "serde", ] [[package]] name = "wasmparser" -version = "0.245.1" +version = "0.247.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" +checksum = "8e6fb4c2bee46c5ea4d40f8cdb5c131725cd976718ec56f1c8e82fbde5fa2a80" dependencies = [ "bitflags 2.10.0", - "hashbrown 0.16.1", - "indexmap 2.13.0", + "hashbrown 0.17.0", + "indexmap 2.14.0", "semver", "serde", ] @@ -15264,7 +15275,7 @@ dependencies = [ "cranelift-entity", "gimli 0.33.0", "hashbrown 0.16.1", - "indexmap 2.13.0", + "indexmap 2.14.0", "log", "object 0.38.1", "postcard", @@ -16022,16 +16033,15 @@ dependencies = [ [[package]] name = "wirm" -version = "2.1.0" +version = "4.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14732cb9a0eaf9ec52ecd36b9394ade5c16eea5405d160d8829f0199d97d507d" +checksum = "4b545057c2fa3f2a83aa2d23f9010e372b880aa6973f04c0cb8400a2e813e8f0" dependencies = [ "log", + "paste", "rayon", - "serde_json", - "tempfile", - "wasm-encoder 0.239.0", - "wasmparser 0.239.0", + "wasm-encoder 0.247.0", + "wasmparser 0.247.0", ] [[package]] diff --git a/Cargo.lock b/Cargo.lock index d90fa9eed896..c00ec9639e8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -341,7 +341,7 @@ dependencies = [ "bytes", "cfg-if", "http 1.4.0", - "indexmap 2.13.0", + "indexmap 2.14.0", "schemars 0.8.22", "serde", "serde_json", @@ -5372,7 +5372,7 @@ checksum = "0bf7f043f89559805f8c7cacc432749b2fa0d0a0a9ee46ce47164ed5ba7f126c" dependencies = [ "fnv", "hashbrown 0.16.1", - "indexmap 2.13.0", + "indexmap 2.14.0", "stable_deref_trait", ] @@ -5673,7 +5673,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.13.0", + "indexmap 2.14.0", "slab", "tokio", "tokio-util", @@ -5692,7 +5692,7 @@ dependencies = [ "futures-core", "futures-sink", "http 1.4.0", - "indexmap 2.13.0", + "indexmap 2.14.0", "slab", "tokio", "tokio-util", @@ -5769,7 +5769,6 @@ dependencies = [ "allocator-api2", "equivalent", "foldhash 0.1.5", - "serde", ] [[package]] @@ -5785,6 +5784,17 @@ dependencies = [ "serde_core", ] +[[package]] +name = "hashbrown" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" +dependencies = [ + "foldhash 0.2.0", + "serde", + "serde_core", +] + [[package]] name = "hashlink" version = "0.8.4" @@ -6445,7 +6455,7 @@ dependencies = [ "ic-sns-init", "ic-sns-wasm", "ic-types", - "indexmap 2.13.0", + "indexmap 2.14.0", "itertools 0.12.1", "maplit", "pocket-ic", @@ -16589,12 +16599,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.13.0" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown 0.16.1", + "hashbrown 0.17.0", "serde", "serde_core", ] @@ -16634,7 +16644,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "232929e1d75fe899576a3d5c7416ad0d88dbfbb3c3d6aa00873a7408a50ddb88" dependencies = [ "ahash 0.8.12", - "indexmap 2.13.0", + "indexmap 2.14.0", "is-terminal", "itoa", "log", @@ -16657,7 +16667,7 @@ dependencies = [ "crossbeam-utils", "dashmap", "env_logger", - "indexmap 2.13.0", + "indexmap 2.14.0", "itoa", "log", "num-format", @@ -18882,7 +18892,7 @@ checksum = "271638cd5fa9cca89c4c304675ca658efc4e64a66c716b7cfe1afb4b9611dbbc" dependencies = [ "crc32fast", "hashbrown 0.16.1", - "indexmap 2.13.0", + "indexmap 2.14.0", "memchr", ] @@ -19620,7 +19630,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset 0.4.2", - "indexmap 2.13.0", + "indexmap 2.14.0", ] [[package]] @@ -19630,7 +19640,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772" dependencies = [ "fixedbitset 0.5.7", - "indexmap 2.13.0", + "indexmap 2.14.0", ] [[package]] @@ -21326,7 +21336,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c11639076bf147be211b90e47790db89f4c22b6c8a9ca6e960833869da67166" dependencies = [ "aho-corasick", - "indexmap 2.13.0", + "indexmap 2.14.0", "itertools 0.13.0", "nohash", "regex", @@ -21729,7 +21739,7 @@ dependencies = [ "bytecheck 0.8.2", "bytes", "hashbrown 0.16.1", - "indexmap 2.13.0", + "indexmap 2.14.0", "munge", "ptr_meta 0.3.1", "rancor", @@ -22386,7 +22396,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fbf2ae1b8bc8e02df939598064d22402220cd5bbcca1c76f7d6a310974d5615" dependencies = [ "dyn-clone", - "indexmap 2.13.0", + "indexmap 2.14.0", "schemars_derive", "serde", "serde_json", @@ -22831,7 +22841,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.13.0", + "indexmap 2.14.0", "schemars 0.9.0", "schemars 1.2.1", "serde_core", @@ -22870,7 +22880,7 @@ version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.13.0", + "indexmap 2.14.0", "itoa", "ryu", "serde", @@ -22883,7 +22893,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b4db627b98b36d4203a7b458cf3573730f2bb591b28871d916dfa9efabfd41f" dependencies = [ - "indexmap 2.13.0", + "indexmap 2.14.0", "itoa", "ryu", "serde", @@ -24596,7 +24606,7 @@ version = "0.25.4+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7193cbd0ce53dc966037f54351dbbcf0d5a642c7f0038c382ef9e677ce8c13f2" dependencies = [ - "indexmap 2.13.0", + "indexmap 2.14.0", "toml_datetime", "toml_parser", "winnow", @@ -24713,7 +24723,7 @@ dependencies = [ "futures-core", "futures-util", "hdrhistogram", - "indexmap 2.13.0", + "indexmap 2.14.0", "pin-project-lite", "slab", "sync_wrapper", @@ -25080,7 +25090,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f0d6c134ef37268c94d50fb74252af1c34c5c88389e2c1af85654da944ceb52" dependencies = [ "bytes", - "indexmap 2.13.0", + "indexmap 2.14.0", "rand 0.8.5", "rand_distr", "scoped-tls", @@ -25694,16 +25704,6 @@ dependencies = [ "leb128", ] -[[package]] -name = "wasm-encoder" -version = "0.239.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be00faa2b4950c76fe618c409d2c3ea5a3c9422013e079482d78544bb2d184c" -dependencies = [ - "leb128fmt", - "wasmparser 0.239.0", -] - [[package]] name = "wasm-encoder" version = "0.243.0" @@ -25734,6 +25734,16 @@ dependencies = [ "wasmparser 0.245.1", ] +[[package]] +name = "wasm-encoder" +version = "0.247.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b6733b8b91d010a6ac5b0fb237dc46a19650bc4c67db66857e2e787d437204" +dependencies = [ + "leb128fmt", + "wasmparser 0.247.0", +] + [[package]] name = "wasm-metadata" version = "0.244.0" @@ -25741,7 +25751,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" dependencies = [ "anyhow", - "indexmap 2.13.0", + "indexmap 2.14.0", "wasm-encoder 0.244.0", "wasmparser 0.244.0", ] @@ -25815,7 +25825,7 @@ dependencies = [ "ahash 0.8.12", "bitflags 2.11.0", "hashbrown 0.14.5", - "indexmap 2.13.0", + "indexmap 2.14.0", "semver", "serde", ] @@ -25829,20 +25839,7 @@ dependencies = [ "ahash 0.8.12", "bitflags 2.11.0", "hashbrown 0.14.5", - "indexmap 2.13.0", - "semver", - "serde", -] - -[[package]] -name = "wasmparser" -version = "0.239.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9d90bb93e764f6beabf1d02028c70a2156a6583e63ac4218dd07ef733368b0" -dependencies = [ - "bitflags 2.11.0", - "hashbrown 0.15.5", - "indexmap 2.13.0", + "indexmap 2.14.0", "semver", "serde", ] @@ -25854,7 +25851,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6d8db401b0528ec316dfbe579e6ab4152d61739cfe076706d2009127970159d" dependencies = [ "bitflags 2.11.0", - "indexmap 2.13.0", + "indexmap 2.14.0", ] [[package]] @@ -25865,7 +25862,7 @@ checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" dependencies = [ "bitflags 2.11.0", "hashbrown 0.15.5", - "indexmap 2.13.0", + "indexmap 2.14.0", "semver", ] @@ -25877,7 +25874,20 @@ checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" dependencies = [ "bitflags 2.11.0", "hashbrown 0.16.1", - "indexmap 2.13.0", + "indexmap 2.14.0", + "semver", + "serde", +] + +[[package]] +name = "wasmparser" +version = "0.247.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e6fb4c2bee46c5ea4d40f8cdb5c131725cd976718ec56f1c8e82fbde5fa2a80" +dependencies = [ + "bitflags 2.11.0", + "hashbrown 0.17.0", + "indexmap 2.14.0", "semver", "serde", ] @@ -25944,7 +25954,7 @@ dependencies = [ "cranelift-entity", "gimli 0.33.0", "hashbrown 0.16.1", - "indexmap 2.13.0", + "indexmap 2.14.0", "log", "object 0.38.1", "postcard", @@ -26600,16 +26610,15 @@ dependencies = [ [[package]] name = "wirm" -version = "2.1.0" +version = "4.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14732cb9a0eaf9ec52ecd36b9394ade5c16eea5405d160d8829f0199d97d507d" +checksum = "4b545057c2fa3f2a83aa2d23f9010e372b880aa6973f04c0cb8400a2e813e8f0" dependencies = [ "log", + "paste", "rayon", - "serde_json", - "tempfile", - "wasm-encoder 0.239.0", - "wasmparser 0.239.0", + "wasm-encoder 0.247.0", + "wasmparser 0.247.0", ] [[package]] @@ -26640,7 +26649,7 @@ checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" dependencies = [ "anyhow", "heck 0.5.0", - "indexmap 2.13.0", + "indexmap 2.14.0", "prettyplease", "syn 2.0.117", "wasm-metadata", @@ -26671,7 +26680,7 @@ checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" dependencies = [ "anyhow", "bitflags 2.11.0", - "indexmap 2.13.0", + "indexmap 2.14.0", "log", "serde", "serde_derive", @@ -26690,7 +26699,7 @@ checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" dependencies = [ "anyhow", "id-arena", - "indexmap 2.13.0", + "indexmap 2.14.0", "log", "semver", "serde", diff --git a/Cargo.toml b/Cargo.toml index ab83cc148cba..97fa1cbad8d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -921,7 +921,7 @@ wast = "245.0.0" wat = "~1.245.0" webpki-roots = "1.0.6" which = "6.0.3" -wirm = { version = "2.1.0", features = ["parallel"] } +wirm = { version = "4.0.4", features = ["parallel"] } wsl = "0.1.0" x509-cert = { version = "0.2.5", features = ["builder", "hazmat"] } x509-parser = { version = "0.16.0" } diff --git a/bazel/rust.MODULE.bazel b/bazel/rust.MODULE.bazel index cd10f87f534a..4afea149e664 100644 --- a/bazel/rust.MODULE.bazel +++ b/bazel/rust.MODULE.bazel @@ -1914,7 +1914,7 @@ crate.spec( crate.spec( features = ["parallel"], package = "wirm", - version = "2.1.0", + version = "4.0.4", ) crate.spec( package = "wsl", diff --git a/rs/embedders/benches/embedders_bench/src/lib.rs b/rs/embedders/benches/embedders_bench/src/lib.rs index 411ee5f2de98..c07a31ffcd20 100644 --- a/rs/embedders/benches/embedders_bench/src/lib.rs +++ b/rs/embedders/benches/embedders_bench/src/lib.rs @@ -34,7 +34,7 @@ fn initialize_execution_test( // Gzipped Wasm is wasm32. false } else { - let module = Module::parse(wasm, true).unwrap(); + let module = Module::parse(wasm, true, false).unwrap(); if let Some(mem) = module.memories.iter().next() { mem.ty.memory64 } else { diff --git a/rs/embedders/src/wasm_utils/instrumentation.rs b/rs/embedders/src/wasm_utils/instrumentation.rs index d1a5c67960aa..d4ba4161b1b5 100644 --- a/rs/embedders/src/wasm_utils/instrumentation.rs +++ b/rs/embedders/src/wasm_utils/instrumentation.rs @@ -998,10 +998,11 @@ fn export_additional_symbols<'a>( ]; let num_instructions = instructions.len(); + let instructions_with_offsets = instructions.into_iter().map(|op| (op, 0)).collect(); let body = Body { locals: vec![(1, DataType::I64)], num_locals: 1, - instructions: Instructions::new(instructions), + instructions: Instructions::new(instructions_with_offsets, 0, false), num_instructions, name: None, }; @@ -1088,10 +1089,11 @@ fn export_additional_symbols<'a>( ]; let num_instructions = instructions.len(); + let instructions_with_offsets = instructions.into_iter().map(|op| (op, 0)).collect(); let body = Body { locals: vec![(4, DataType::I32)], num_locals: 4, - instructions: Instructions::new(instructions), + instructions: Instructions::new(instructions_with_offsets, 0, false), num_instructions, name: None, }; @@ -1316,7 +1318,10 @@ fn inject_metering( InjectionPointCostDetail::StaticCost { scope: _, cost } => cost > 0, InjectionPointCostDetail::DynamicCost { .. } => true, }); - let orig_elems = body.instructions.get_ops_mut(); + let orig_elems = body + .instructions + .get_ops_mut() + .expect("instructions must not be instrumented at this point"); let mut elems: Vec = Vec::new(); let mut last_injection_position = 0; @@ -1414,7 +1419,10 @@ fn inject_try_grow_wasm_memory( WasmMemoryType::Wasm64 => func_body.locals.push((1, DataType::I64)), }; - let orig_elems = func_body.instructions.get_ops_mut(); + let orig_elems = func_body + .instructions + .get_ops_mut() + .expect("instructions must not be instrumented at this point"); let mut elems: Vec = Vec::new(); let mut last_injection_position = 0; for point in injection_points { @@ -1439,7 +1447,8 @@ fn inject_try_grow_wasm_memory( } elems.extend_from_slice(&orig_elems[last_injection_position..]); let num_instructions = elems.len(); - func_body.instructions = Instructions::new(elems); + let elems_with_offsets = elems.into_iter().map(|op| (op, 0)).collect(); + func_body.instructions = Instructions::new(elems_with_offsets, 0, false); func_body.num_instructions = num_instructions; } } @@ -1486,7 +1495,9 @@ fn replace_system_api_functions( if let Some(old_index) = api_indexes.get(&api) { let mut builder = FunctionBuilder::new(¶m, &ret); builder.body = body; - builder.replace_import_in_module(module, ImportsID(*old_index)); + builder + .replace_import_in_module(module, ImportsID(*old_index)) + .expect("failed to replace system API import"); } } } @@ -1579,7 +1590,7 @@ pub(super) fn instrument( .functions .iter_mut() .filter(|f| f.is_local()) - .map(|f| f.unwrap_local_mut()) + .map(|f| f.unwrap_local_mut().expect("function must be local")) // skip metering on injected functions .filter(|f| { *f.func_id != injected_counters.decr_instruction_counter_fn @@ -1600,9 +1611,15 @@ pub(super) fn instrument( .functions .iter_mut() .filter(|f| f.is_local()) - .map(Function::unwrap_local_mut) + .map(|f| Function::unwrap_local_mut(f).expect("function must be local")) { - let num_params = module.types.get(func_body.ty_id).unwrap().params().len() as u32; + let num_params = module + .types + .get(func_body.ty_id) + .unwrap() + .params() + .expect("function type must have params") + .len() as u32; inject_try_grow_wasm_memory( &mut func_body.body, num_params, @@ -1659,7 +1676,9 @@ pub(super) fn instrument( wasm_instruction_count += 2; } - let result = module.encode(); + let result = module.encode().map_err(|err| { + WasmInstrumentationError::WasmSerializeError(WasmError::new(err.to_string())) + })?; Ok(InstrumentationOutput { exported_functions, diff --git a/rs/embedders/src/wasm_utils/system_api_replacements.rs b/rs/embedders/src/wasm_utils/system_api_replacements.rs index 1099c9a5285e..1fb1242c10b5 100644 --- a/rs/embedders/src/wasm_utils/system_api_replacements.rs +++ b/rs/embedders/src/wasm_utils/system_api_replacements.rs @@ -31,11 +31,13 @@ fn make_body( locals: Vec<(u32, DataType)>, instructions: Vec, ) -> wirm::ir::types::Body { + let num_instructions = instructions.len(); + let instructions_with_offsets = instructions.into_iter().map(|op| (op, 0)).collect(); wirm::ir::types::Body { num_locals: locals.len() as u32, - num_instructions: instructions.len(), + num_instructions, locals, - instructions: Instructions::new(instructions), + instructions: Instructions::new(instructions_with_offsets, 0, false), name: None, } } diff --git a/rs/embedders/src/wasm_utils/validation.rs b/rs/embedders/src/wasm_utils/validation.rs index 9fad9538c375..ca21ec9487b2 100644 --- a/rs/embedders/src/wasm_utils/validation.rs +++ b/rs/embedders/src/wasm_utils/validation.rs @@ -1094,6 +1094,11 @@ fn validate_import_section(module: &Module) -> Result { + return Err(WasmValidationError::InvalidImportSection( + "Importing exact function references is not allowed.".to_string(), + )); + } } } } @@ -1803,7 +1808,7 @@ pub(super) fn validate_wasm_binary<'a>( ) -> Result<(WasmValidationDetails, Module<'a>), WasmValidationError> { let code_section_size = check_code_section_size(wasm)?; can_compile(wasm, config)?; - let module = Module::parse(wasm.as_slice(), false) + let module = Module::parse(wasm.as_slice(), false, false) .map_err(|err| WasmValidationError::DecodingError(format!("{err}")))?; let imports_details = validate_import_section(&module)?; validate_export_section( diff --git a/rs/embedders/tests/instrumentation.rs b/rs/embedders/tests/instrumentation.rs index d5c0101b033f..e3857b8c1e1a 100644 --- a/rs/embedders/tests/instrumentation.rs +++ b/rs/embedders/tests/instrumentation.rs @@ -175,7 +175,7 @@ fn test_get_data() { assert_eq!((2, b"a tree".to_vec()), data[0]); assert_eq!((11, b"is known".to_vec()), data[1]); assert_eq!((23, b"by its fruit".to_vec()), data[2]); - let module = Module::parse(output.binary.as_slice(), false).unwrap(); + let module = Module::parse(output.binary.as_slice(), false, false).unwrap(); if !module.data.is_empty() { panic!("instrumentation should have removed data sections"); } @@ -212,7 +212,7 @@ fn test_mixed_data_segments() { assert_eq!((32, b"active 4".to_vec()), data[2]); assert_eq!((48, b"active 6".to_vec()), data[3]); assert_eq!((64, b"active 7".to_vec()), data[4]); - let module = Module::parse(output.binary.as_slice(), false).unwrap(); + let module = Module::parse(output.binary.as_slice(), false, false).unwrap(); assert_eq!(module.data.len(), 6); assert_eq!(&module.data[0].data, &b"passive 0"); assert_eq!(module.data[1].data.len(), 0); @@ -266,7 +266,7 @@ fn test_exports_only_reserved_symbols() { &wasm, ) .unwrap(); - let module = Module::parse(instrumentation_details.binary.as_slice(), true).unwrap(); + let module = Module::parse(instrumentation_details.binary.as_slice(), true, false).unwrap(); for export in module.exports.iter() { assert!(RESERVED_SYMBOLS.contains(&&export.name[..])) @@ -1432,7 +1432,7 @@ fn assert_memories_have_max_limit(wat: &str) { &wasm, ) .unwrap(); - let module = Module::parse(instrumentation_details.binary.as_slice(), true).unwrap(); + let module = Module::parse(instrumentation_details.binary.as_slice(), true, false).unwrap(); assert!( module.memories.iter().count() >= 2, "Module should have at least a heap and stable memory" diff --git a/rs/embedders/tests/misc_tests.rs b/rs/embedders/tests/misc_tests.rs index 16f1dfca613b..495716c52020 100644 --- a/rs/embedders/tests/misc_tests.rs +++ b/rs/embedders/tests/misc_tests.rs @@ -61,7 +61,7 @@ fn test_instrument_module_rename_memory_table() { .unwrap() .1; - let module = Module::parse(output.binary.as_slice(), false).unwrap(); + let module = Module::parse(output.binary.as_slice(), false, false).unwrap(); assert_memory_and_table_exports(&module); // check that instrumented module instantiates correctly wasmtime_simple::wasmtime_instantiate_and_call_run(&output.binary); @@ -93,7 +93,7 @@ fn test_instrument_module_export_memory_table() { .unwrap() .1; - let module = Module::parse(output.binary.as_slice(), false).unwrap(); + let module = Module::parse(output.binary.as_slice(), false, false).unwrap(); assert_memory_and_table_exports(&module); // check that instrumented module instantiates correctly wasmtime_simple::wasmtime_instantiate_and_call_run(&output.binary); diff --git a/rs/embedders/tests/spec_tests.rs b/rs/embedders/tests/spec_tests.rs index 8affb80c8a15..11abad037e33 100644 --- a/rs/embedders/tests/spec_tests.rs +++ b/rs/embedders/tests/spec_tests.rs @@ -498,9 +498,11 @@ fn parse_and_encode( location(wat, text, path) ) })?; - let mut module = wirm::Module::parse(&wasm, enable_multi_memory) + let module = wirm::Module::parse(&wasm, enable_multi_memory, false) .map_err(|e| format!("Parsing error: {:?} in {}", e, location(wat, text, path)))?; - module.encode(); + module + .encode() + .map_err(|e| format!("Encoding error: {:?} in {}", e, location(wat, text, path)))?; Ok(wasm) } diff --git a/rs/embedders/tests/wirm_round_trip.rs b/rs/embedders/tests/wirm_round_trip.rs index 416a166159c3..4c569b207a98 100644 --- a/rs/embedders/tests/wirm_round_trip.rs +++ b/rs/embedders/tests/wirm_round_trip.rs @@ -9,8 +9,8 @@ fn round_trip(testname: &str, folder: &str) { ); let buff = wat::parse_file(filename).expect("couldn't convert the input wat to Wasm"); - let mut module = Module::parse(&buff, false).unwrap(); - let result = module.encode(); + let module = Module::parse(&buff, false, false).unwrap(); + let result = module.encode().expect("couldn't encode Wasm"); let out = wasmprinter::print_bytes(result).expect("couldn't translated Wasm to wat"); let original = wasmprinter::print_bytes(buff).expect("couldn't convert original Wasm to wat"); assert_eq!(out, original);