From d3ffeb3fa3cba3aa31ab5eaf19f4b68b8183d3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 14 Jun 2023 06:34:26 +0200 Subject: [PATCH] wip --- Cargo.lock | 407 +++++++++-------- shared/Cargo.toml | 14 +- shared/src/vm/host_env.rs | 407 +++++++++-------- shared/src/vm/memory.rs | 14 +- .../src/vm/wasm/compilation_cache/common.rs | 10 +- shared/src/vm/wasm/host_env.rs | 131 +++--- shared/src/vm/wasm/memory.rs | 155 ++++--- shared/src/vm/wasm/run.rs | 74 +-- tests/src/e2e/ledger_tests.rs | 2 +- tests/src/lib.rs | 10 +- tests/src/vm_host_env/tx.rs | 8 +- tests/src/vm_host_env/vp.rs | 8 +- wasm/Cargo.lock | 423 +++++++++--------- wasm_for_tests/wasm_source/Cargo.lock | 423 +++++++++--------- 14 files changed, 1110 insertions(+), 976 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f69107f711..9d70aa4128 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -507,7 +507,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "miniz_oxide 0.6.2", - "object 0.30.3", + "object", "rustc-demangle", ] @@ -1364,6 +1364,19 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +[[package]] +name = "corosensei" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9847f90f32a50b0dcbd68bc23ff242798b13080b97b0569f6ed96a45ce4cf2cd" +dependencies = [ + "autocfg 1.1.0", + "cfg-if 1.0.0", + "libc", + "scopeguard", + "windows-sys 0.33.0", +] + [[package]] name = "cpufeatures" version = "0.2.7" @@ -1375,57 +1388,74 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e6bea67967505247f54fa2c85cf4f6e0e31c4e5692c9b70e4ae58e339067333" +checksum = "2a2ab4512dfd3a6f4be184403a195f76e81a8a9f9e6c898e19d2dc3ce20e0115" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48194035d2752bdd5bdae429e3ab88676e95f52a2b1355a5d4e809f9e39b1d74" +checksum = "98b022ed2a5913a38839dfbafe6cf135342661293b08049843362df4301261dc" dependencies = [ + "arrayvec 0.7.2", + "bumpalo", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", + "cranelift-egraph", "cranelift-entity", - "gimli 0.25.0", + "cranelift-isle", + "gimli 0.26.2", "log 0.4.17", - "regalloc", + "regalloc2", "smallvec 1.10.0", "target-lexicon", ] [[package]] name = "cranelift-codegen-meta" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976efb22fcab4f2cd6bd4e9913764616a54d895c1a23530128d04e03633c555f" +checksum = "639307b45434ad112a98f8300c0f0ab085cbefcd767efcdef9ef19d4c0756e74" dependencies = [ "cranelift-codegen-shared", - "cranelift-entity", ] [[package]] name = "cranelift-codegen-shared" -version = "0.76.0" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "278e52e29c53fcf32431ef08406c295699a70306d05a0715c5b1bf50e33a9ab7" + +[[package]] +name = "cranelift-egraph" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dabb5fe66e04d4652e434195b45ae65b5c8172d520247b8f66d8df42b2b45dc" +checksum = "624b54323b06e675293939311943ba82d323bb340468ce1889be5da7932c8d73" +dependencies = [ + "cranelift-entity", + "fxhash", + "hashbrown 0.12.3", + "indexmap", + "log 0.4.17", + "smallvec 1.10.0", +] [[package]] name = "cranelift-entity" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3329733e4d4b8e91c809efcaa4faee80bf66f20164e3dd16d707346bd3494799" +checksum = "9a59bcbca89c3f1b70b93ab3cbba5e5e0cbf3e63dadb23c7525cb142e21a9d4c" [[package]] name = "cranelift-frontend" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "279afcc0d3e651b773f94837c3d581177b348c8d69e928104b2e9fccb226f921" +checksum = "0d70abacb8cfef3dc8ff7e8836e9c1d70f7967dfdac824a4cd5e30223415aca6" dependencies = [ "cranelift-codegen", "log 0.4.17", @@ -1433,6 +1463,12 @@ dependencies = [ "target-lexicon", ] +[[package]] +name = "cranelift-isle" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "393bc73c451830ff8dbb3a07f61843d6cb41a084f9996319917c0b291ed785bb" + [[package]] name = "crc32fast" version = "1.3.2" @@ -1655,6 +1691,19 @@ dependencies = [ "syn 2.0.16", ] +[[package]] +name = "dashmap" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" +dependencies = [ + "cfg-if 1.0.0", + "hashbrown 0.12.3", + "lock_api 0.4.9", + "once_cell", + "parking_lot_core 0.9.7", +] + [[package]] name = "data-encoding" version = "2.3.3" @@ -2410,6 +2459,15 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "generic-array" version = "0.12.4" @@ -2457,9 +2515,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.25.0" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" dependencies = [ "fallible-iterator", "indexmap", @@ -3180,7 +3238,6 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg 1.1.0", "hashbrown 0.12.3", - "serde 1.0.163", ] [[package]] @@ -3555,27 +3612,6 @@ dependencies = [ "value-bag", ] -[[package]] -name = "loupe" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6a72dfa44fe15b5e76b94307eeb2ff995a8c5b283b55008940c02e0c5b634d" -dependencies = [ - "indexmap", - "loupe-derive", - "rustversion", -] - -[[package]] -name = "loupe-derive" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0fbfc88337168279f2e9ae06e157cfed4efd3316e14dc96ed074d4f2e6c5952" -dependencies = [ - "quote", - "syn 1.0.109", -] - [[package]] name = "mach" version = "0.3.2" @@ -3716,15 +3752,6 @@ dependencies = [ "libc", ] -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "memoffset" version = "0.7.1" @@ -3936,7 +3963,6 @@ dependencies = [ "ibc-proto", "itertools", "libsecp256k1 0.7.0", - "loupe", "masp_primitives", "masp_proofs", "namada_core", @@ -3974,8 +4000,6 @@ dependencies = [ "wasmer", "wasmer-cache", "wasmer-compiler-singlepass", - "wasmer-engine-dylib", - "wasmer-engine-universal", "wasmer-vm", "wasmparser 0.83.0", "zeroize", @@ -4450,18 +4474,6 @@ dependencies = [ "libc", ] -[[package]] -name = "object" -version = "0.28.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" -dependencies = [ - "crc32fast", - "hashbrown 0.11.2", - "indexmap", - "memchr", -] - [[package]] name = "object" version = "0.30.3" @@ -5435,13 +5447,14 @@ dependencies = [ ] [[package]] -name = "regalloc" -version = "0.0.31" +name = "regalloc2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571f7f397d61c4755285cd37853fe8e03271c243424a907415909379659381c5" +checksum = "300d4fbfb40c1c66a78ba3ddd41c1110247cf52f97b87d0f2fc9209bd49b030c" dependencies = [ + "fxhash", "log 0.4.17", - "rustc-hash", + "slice-group-by", "smallvec 1.10.0", ] @@ -5596,6 +5609,7 @@ dependencies = [ "bitvec 1.0.1", "bytecheck", "hashbrown 0.12.3", + "indexmap", "ptr_meta", "rend", "rkyv_derive", @@ -6050,6 +6064,17 @@ dependencies = [ "serde 0.8.23", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf" +dependencies = [ + "js-sys", + "serde 1.0.163", + "wasm-bindgen", +] + [[package]] name = "serde_bytes" version = "0.11.9" @@ -6288,6 +6313,12 @@ dependencies = [ "autocfg 1.1.0", ] +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + [[package]] name = "slip10_ed25519" version = "0.1.3" @@ -7702,6 +7733,29 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-downcast" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dac026d43bcca6e7ce1c0956ba68f59edf6403e8e930a5d891be72c31a44340" +dependencies = [ + "js-sys", + "once_cell", + "wasm-bindgen", + "wasm-bindgen-downcast-macros", +] + +[[package]] +name = "wasm-bindgen-downcast-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5020cfa87c7cecefef118055d44e3c1fc122c7ec25701d528ee458a0b45f38f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "wasm-bindgen-futures" version = "0.4.36" @@ -7754,24 +7808,26 @@ dependencies = [ [[package]] name = "wasmer" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfc7dff846db3f38f8ed0be4a009fdfeb729cf1f94a2c7fb6ff2fec01cefa110" +checksum = "78caedecd8cb71ed47ccca03b68d69414a3d278bb031e6f93f15759344efdd52" dependencies = [ + "bytes 1.4.0", "cfg-if 1.0.0", + "derivative", "indexmap", "js-sys", - "loupe", "more-asserts", + "rustc-demangle", + "serde 1.0.163", + "serde-wasm-bindgen", "target-lexicon", "thiserror", "wasm-bindgen", + "wasm-bindgen-downcast", "wasmer-compiler", "wasmer-compiler-cranelift", "wasmer-derive", - "wasmer-engine", - "wasmer-engine-dylib", - "wasmer-engine-universal", "wasmer-types", "wasmer-vm", "wat", @@ -7780,9 +7836,9 @@ dependencies = [ [[package]] name = "wasmer-cache" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "834a0de78bf30b9bce61c4c236344b9d8f2f4a3b7713f8de8a8274fbc2d4e9d5" +checksum = "7f0de969b05cc3c11196beeb46e5868a3712a187d777ee94113f7258c2ec121c" dependencies = [ "blake3", "hex", @@ -7792,34 +7848,37 @@ dependencies = [ [[package]] name = "wasmer-compiler" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c91abf22b16dad3826ec0d0e3ec0a8304262a6c7a14e16528c536131b80e63d" +checksum = "726a8450541af4a57c34af7b6973fdbfc79f896cc7e733429577dfd1d1687180" dependencies = [ + "backtrace", + "cfg-if 1.0.0", + "enum-iterator", "enumset", - "loupe", - "rkyv", - "serde 1.0.163", - "serde_bytes", + "lazy_static", + "leb128", + "memmap2", + "more-asserts", + "region", "smallvec 1.10.0", - "target-lexicon", "thiserror", "wasmer-types", "wasmer-vm", - "wasmparser 0.78.2", + "wasmparser 0.95.0", + "winapi 0.3.9", ] [[package]] name = "wasmer-compiler-cranelift" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7624a1f496b163139a7e0b442426cad805bec70486900287506f9d15a29323ab" +checksum = "a1e5633f90f372563ebbdf3f9799c7b29ba11c90e56cf9b54017112d2e656c95" dependencies = [ "cranelift-codegen", "cranelift-entity", "cranelift-frontend", - "gimli 0.25.0", - "loupe", + "gimli 0.26.2", "more-asserts", "rayon", "smallvec 1.10.0", @@ -7827,33 +7886,32 @@ dependencies = [ "tracing 0.1.37", "wasmer-compiler", "wasmer-types", - "wasmer-vm", ] [[package]] name = "wasmer-compiler-singlepass" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b63c1538ffb4b0e09edaebfcac35c34141d5944c52f77d137cbe0b634bd40fa" +checksum = "d4d38957de6f452115c0af3ff08cec268ee248d665b54d4bbf7da60b7453cb97" dependencies = [ "byteorder", "dynasm", "dynasmrt", + "enumset", + "gimli 0.26.2", "lazy_static", - "loupe", "more-asserts", "rayon", "smallvec 1.10.0", "wasmer-compiler", "wasmer-types", - "wasmer-vm", ] [[package]] name = "wasmer-derive" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "933b23b5cee0f58aa6c17c6de7e1f3007279357e0d555f22e24d6b395cfe7f89" +checksum = "97901fdbaae383dbb90ea162cc3a76a9fa58ac39aec7948b4c0b9bbef9307738" dependencies = [ "proc-macro-error", "proc-macro2", @@ -7862,115 +7920,43 @@ dependencies = [ ] [[package]] -name = "wasmer-engine" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41db0ac4df90610cda8320cfd5abf90c6ec90e298b6fe5a09a81dff718b55640" -dependencies = [ - "backtrace", - "enumset", - "lazy_static", - "loupe", - "memmap2", - "more-asserts", - "rustc-demangle", - "serde 1.0.163", - "serde_bytes", - "target-lexicon", - "thiserror", - "wasmer-compiler", - "wasmer-types", - "wasmer-vm", -] - -[[package]] -name = "wasmer-engine-dylib" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "591683f3356ac31cc88aaecaf77ac2cc9f456014348b01af46c164f44f531162" -dependencies = [ - "cfg-if 1.0.0", - "enum-iterator", - "enumset", - "leb128", - "libloading", - "loupe", - "object 0.28.4", - "rkyv", - "serde 1.0.163", - "tempfile", - "tracing 0.1.37", - "wasmer-compiler", - "wasmer-engine", - "wasmer-object", - "wasmer-types", - "wasmer-vm", - "which", -] - -[[package]] -name = "wasmer-engine-universal" -version = "2.2.0" +name = "wasmer-types" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dccfde103e9b87427099a6de344b7c791574f307d035c8c7dbbc00974c1af0c1" +checksum = "67f1f2839f4f61509550e4ddcd0e658e19f3af862b51c79fda15549d735d659b" dependencies = [ - "cfg-if 1.0.0", + "bytecheck", "enum-iterator", "enumset", - "leb128", - "loupe", - "region", - "rkyv", - "wasmer-compiler", - "wasmer-engine", - "wasmer-types", - "wasmer-vm", - "winapi 0.3.9", -] - -[[package]] -name = "wasmer-object" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0c4005592998bd840f2289102ef9c67b6138338ed78e1fc0809586aa229040" -dependencies = [ - "object 0.28.4", - "thiserror", - "wasmer-compiler", - "wasmer-types", -] - -[[package]] -name = "wasmer-types" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4deb854f178265a76b59823c41547d259c65da3687b606b0b9c12d80ab950e3e" -dependencies = [ "indexmap", - "loupe", + "more-asserts", "rkyv", - "serde 1.0.163", + "target-lexicon", "thiserror", ] [[package]] name = "wasmer-vm" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dbc5c989cb14a102433927e630473da52f83d82c469acd5cfa8fc7efacc1e70" +checksum = "043118ec4f16d1714fed3aab758b502b864bd865e1d5188626c9ad290100563f" dependencies = [ "backtrace", "cc", "cfg-if 1.0.0", + "corosensei", + "dashmap", + "derivative", "enum-iterator", + "fnv", "indexmap", + "lazy_static", "libc", - "loupe", - "memoffset 0.6.5", + "mach", + "memoffset 0.8.0", "more-asserts", "region", - "rkyv", - "serde 1.0.163", + "scopeguard", "thiserror", "wasmer-types", "winapi 0.3.9", @@ -7978,15 +7964,19 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.78.2" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52144d4c78e5cf8b055ceab8e5fa22814ce4315d6002ad32cfd914f37c12fd65" +checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" [[package]] name = "wasmparser" -version = "0.83.0" +version = "0.95.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" +checksum = "f2ea896273ea99b15132414be1da01ab0d8836415083298ecaffbe308eaac87a" +dependencies = [ + "indexmap", + "url 2.3.1", +] [[package]] name = "wast" @@ -8179,6 +8169,19 @@ dependencies = [ "windows-targets 0.48.0", ] +[[package]] +name = "windows-sys" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43dbb096663629518eb1dfa72d80243ca5a6aca764cae62a2df70af760a9be75" +dependencies = [ + "windows_aarch64_msvc 0.33.0", + "windows_i686_gnu 0.33.0", + "windows_i686_msvc 0.33.0", + "windows_x86_64_gnu 0.33.0", + "windows_x86_64_msvc 0.33.0", +] + [[package]] name = "windows-sys" version = "0.42.0" @@ -8254,6 +8257,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd761fd3eb9ab8cc1ed81e56e567f02dd82c4c837e48ac3b2181b9ffc5060807" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -8266,6 +8275,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +[[package]] +name = "windows_i686_gnu" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab0cf703a96bab2dc0c02c0fa748491294bf9b7feb27e1f4f96340f208ada0e" + [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -8278,6 +8293,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +[[package]] +name = "windows_i686_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cfdbe89cc9ad7ce618ba34abc34bbb6c36d99e96cae2245b7943cd75ee773d0" + [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -8290,6 +8311,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +[[package]] +name = "windows_x86_64_gnu" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4dd9b0c0e9ece7bb22e84d70d01b71c6d6248b81a3c60d11869451b4cb24784" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -8314,6 +8341,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +[[package]] +name = "windows_x86_64_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff1e4aa646495048ec7f3ffddc411e1d829c026a2ec62b39da15c1055e406eaa" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 469871f350..7edf375d58 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -21,14 +21,11 @@ ferveo-tpke = [ ] wasm-runtime = [ "namada_core/wasm-runtime", - "loupe", "parity-wasm", "pwasm-utils", "rayon", "wasmer-cache", "wasmer-compiler-singlepass", - "wasmer-engine-dylib", - "wasmer-engine-universal", "wasmer-vm", "wasmer", ] @@ -96,7 +93,6 @@ derivative = "2.2.0" ibc = {version = "0.36.0", default-features = false, features = ["serde"], optional = true} ibc-proto = {version = "0.26.0", default-features = false, optional = true} itertools = "0.10.0" -loupe = {version = "0.1.3", optional = true} parity-wasm = {version = "0.45.0", features = ["sign_ext"], optional = true} paste = "1.0.9" proptest = {version = "1.2.0", optional = true} @@ -119,12 +115,10 @@ tendermint-rpc = {version = "0.23.6", default-features = false, features = ["tra tendermint-proto = {version = "0.23.6", optional = true} thiserror = "1.0.38" tracing = "0.1.30" -wasmer = {version = "=2.2.0", optional = true} -wasmer-cache = {version = "=2.2.0", optional = true} -wasmer-compiler-singlepass = {version = "=2.2.0", optional = true} -wasmer-engine-dylib = {version = "=2.2.0", optional = true} -wasmer-engine-universal = {version = "=2.2.0", optional = true} -wasmer-vm = {version = "2.2.0", optional = true} +wasmer = {version = "3.3.0", optional = true} +wasmer-cache = {version = "3.3.0", optional = true} +wasmer-compiler-singlepass = {version = "3.3.0", optional = true} +wasmer-vm = {version = "3.3.0", optional = true} wasmparser = "0.83.0" # branch = "murisi/namada-integration" masp_primitives = { git = "https://github.com/anoma/masp", rev = "cfea8c95d3f73077ca3e25380fd27e5b46e828fd" } diff --git a/shared/src/vm/host_env.rs b/shared/src/vm/host_env.rs index abd3f62551..e42922a02f 100644 --- a/shared/src/vm/host_env.rs +++ b/shared/src/vm/host_env.rs @@ -7,6 +7,7 @@ use std::num::TryFromIntError; use borsh::{BorshDeserialize, BorshSerialize}; use namada_core::types::internal::KeyVal; use thiserror::Error; +use wasmer::FunctionEnvMut; #[cfg(feature = "wasm-runtime")] use super::wasm::TxCache; @@ -64,7 +65,7 @@ type TxResult = std::result::Result; /// A transaction's host environment pub struct TxVmEnv<'a, MEM, DB, H, CA> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, @@ -113,7 +114,7 @@ where impl<'a, MEM, DB, H, CA> TxVmEnv<'a, MEM, DB, H, CA> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, @@ -174,7 +175,7 @@ where impl Clone for TxVmEnv<'_, MEM, DB, H, CA> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, @@ -216,7 +217,7 @@ where /// A validity predicate's host environment pub struct VpVmEnv<'a, MEM, DB, H, EVAL, CA> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, @@ -298,7 +299,7 @@ pub trait VpEvaluator { impl<'a, MEM, DB, H, EVAL, CA> VpVmEnv<'a, MEM, DB, H, EVAL, CA> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, @@ -352,7 +353,7 @@ where impl Clone for VpVmEnv<'_, MEM, DB, H, EVAL, CA> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, @@ -463,30 +464,29 @@ where /// Called from tx wasm to request to use the given gas amount pub fn tx_charge_gas( - env: &TxVmEnv, + env: FunctionEnvMut>, used_gas: i32, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { - tx_add_gas( - env, + tx_add_gas_aux( + &env.data(), used_gas .try_into() .map_err(TxRuntimeError::NumConversionError)?, ) } -/// Add a gas cost incured in a transaction -pub fn tx_add_gas( - env: &TxVmEnv, +fn tx_add_gas_aux( + env: &TxVmEnv<'static, MEM, DB, H, CA>, used_gas: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, @@ -505,17 +505,17 @@ where /// Called from VP wasm to request to use the given gas amount pub fn vp_charge_gas( - env: &VpVmEnv, + env: FunctionEnvMut>, used_gas: i32, ) -> vp_host_fns::EnvResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { - let gas_meter = unsafe { env.ctx.gas_meter.get() }; + let gas_meter = unsafe { env.data().ctx.gas_meter.get() }; vp_host_fns::add_gas( gas_meter, used_gas @@ -527,21 +527,22 @@ where /// Storage `has_key` function exposed to the wasm VM Tx environment. It will /// try to check the write log first and if no entry found then the storage. pub fn tx_has_key( - env: &TxVmEnv, + mut env: FunctionEnvMut>, key_ptr: u64, key_len: u64, ) -> TxResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (key, gas) = env .memory - .read_string(key_ptr, key_len as _) + .read_string(&mut store, key_ptr, key_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; tracing::debug!("tx_has_key {}, key {}", key, key_ptr,); @@ -550,7 +551,7 @@ where // try to read from the write log first let write_log = unsafe { env.ctx.write_log.get() }; let (log_val, gas) = write_log.read(&key); - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; Ok(match log_val { Some(&write_log::StorageModification::Write { .. }) => { HostEnvResult::Success.to_i64() @@ -571,7 +572,7 @@ where let (present, gas) = storage .has_key(&key) .map_err(TxRuntimeError::StorageError)?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; HostEnvResult::from(present).to_i64() } }) @@ -583,21 +584,22 @@ where /// Returns `-1` when the key is not present, or the length of the data when /// the key is present (the length may be `0`). pub fn tx_read( - env: &TxVmEnv, + mut env: FunctionEnvMut>, key_ptr: u64, key_len: u64, ) -> TxResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (key, gas) = env .memory - .read_string(key_ptr, key_len as _) + .read_string(&mut store, key_ptr, key_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; tracing::debug!("tx_read {}, key {}", key, key_ptr,); @@ -606,7 +608,7 @@ where // try to read from the write log first let write_log = unsafe { env.ctx.write_log.get() }; let (log_val, gas) = write_log.read(&key); - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; Ok(match log_val { Some(write_log::StorageModification::Write { ref value }) => { let len: i64 = value @@ -647,7 +649,7 @@ where let storage = unsafe { env.ctx.storage.get() }; let (value, gas) = storage.read(&key).map_err(TxRuntimeError::StorageError)?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; match value { Some(value) => { let len: i64 = value @@ -673,43 +675,45 @@ where /// any) back to the guest, the second step reads the value from cache into a /// pre-allocated buffer with the obtained size. pub fn tx_result_buffer( - env: &TxVmEnv, + mut env: FunctionEnvMut>, result_ptr: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let result_buffer = unsafe { env.ctx.result_buffer.get() }; let value = result_buffer.take().unwrap(); let gas = env .memory - .write_bytes(result_ptr, value) + .write_bytes(&mut store, result_ptr, value) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas) + tx_add_gas_aux(&env, gas) } /// Storage prefix iterator function exposed to the wasm VM Tx environment. /// It will try to get an iterator from the storage and return the corresponding /// ID of the iterator, ordered by storage keys. pub fn tx_iter_prefix( - env: &TxVmEnv, + mut env: FunctionEnvMut>, prefix_ptr: u64, prefix_len: u64, ) -> TxResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: 'static + storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (prefix, gas) = env .memory - .read_string(prefix_ptr, prefix_len as _) + .read_string(&mut store, prefix_ptr, prefix_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; tracing::debug!("tx_iter_prefix {}", prefix); @@ -719,7 +723,7 @@ where let write_log = unsafe { env.ctx.write_log.get() }; let storage = unsafe { env.ctx.storage.get() }; let (iter, gas) = storage::iter_prefix_post(write_log, storage, &prefix); - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; let iterators = unsafe { env.ctx.iterators.get() }; Ok(iterators.insert(iter).id()) @@ -732,15 +736,16 @@ where /// Returns `-1` when the key is not present, or the length of the data when /// the key is present (the length may be `0`). pub fn tx_iter_next( - env: &TxVmEnv, + env: FunctionEnvMut>, iter_id: u64, ) -> TxResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let env = env.data(); tracing::debug!("tx_iter_next iter_id {}", iter_id,); let write_log = unsafe { env.ctx.write_log.get() }; @@ -751,7 +756,7 @@ where &Key::parse(key.clone()) .map_err(TxRuntimeError::StorageDataError)?, ); - tx_add_gas(env, iter_gas + log_gas)?; + tx_add_gas_aux(&env, iter_gas + log_gas)?; match log_val { Some(write_log::StorageModification::Write { ref value }) => { let key_val = KeyVal { @@ -811,28 +816,29 @@ where /// Storage write function exposed to the wasm VM Tx environment. The given /// key/value will be written to the write log. pub fn tx_write( - env: &TxVmEnv, + mut env: FunctionEnvMut>, key_ptr: u64, key_len: u64, val_ptr: u64, val_len: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (key, gas) = env .memory - .read_string(key_ptr, key_len as _) + .read_string(&mut store, key_ptr, key_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; let (value, gas) = env .memory - .read_bytes(val_ptr, val_len as _) + .read_bytes(&mut store, val_ptr, val_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; tracing::debug!("tx_update {}, {:?}", key, value); @@ -841,13 +847,13 @@ where tx_validate_vp_code_hash(env, &value)?; } - check_address_existence(env, &key)?; + check_address_existence(&env, &key)?; let write_log = unsafe { env.ctx.write_log.get() }; let (gas, _size_diff) = write_log .write(&key, value) .map_err(TxRuntimeError::StorageModificationError)?; - tx_add_gas(env, gas) + tx_add_gas_aux(&env, gas) // TODO: charge the size diff } @@ -855,49 +861,50 @@ where /// given key/value will be written only to the write log. It will be never /// written to the storage. pub fn tx_write_temp( - env: &TxVmEnv, + mut env: FunctionEnvMut>, key_ptr: u64, key_len: u64, val_ptr: u64, val_len: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (key, gas) = env .memory - .read_string(key_ptr, key_len as _) + .read_string(&mut store, key_ptr, key_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; let (value, gas) = env .memory - .read_bytes(val_ptr, val_len as _) + .read_bytes(&mut store, val_ptr, val_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; tracing::debug!("tx_write_temp {}, {:?}", key, value); let key = Key::parse(key).map_err(TxRuntimeError::StorageDataError)?; - check_address_existence(env, &key)?; + check_address_existence(&env, &key)?; let write_log = unsafe { env.ctx.write_log.get() }; let (gas, _size_diff) = write_log .write_temp(&key, value) .map_err(TxRuntimeError::StorageModificationError)?; - tx_add_gas(env, gas) + tx_add_gas_aux(&env, gas) // TODO: charge the size diff } fn check_address_existence( - env: &TxVmEnv, + env: &TxVmEnv<'static, MEM, DB, H, CA>, key: &Key, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, @@ -911,14 +918,14 @@ where } let vp_key = Key::validity_predicate(&addr); let (vp, gas) = write_log.read(&vp_key); - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; // just check the existence because the write log should not have the // delete log of the VP if vp.is_none() { let (is_present, gas) = storage .has_key(&vp_key) .map_err(TxRuntimeError::StorageError)?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; if !is_present { tracing::info!( "Trying to write into storage with a key containing an \ @@ -937,21 +944,22 @@ where /// Storage delete function exposed to the wasm VM Tx environment. The given /// key/value will be written as deleted to the write log. pub fn tx_delete( - env: &TxVmEnv, + mut env: FunctionEnvMut>, key_ptr: u64, key_len: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (key, gas) = env .memory - .read_string(key_ptr, key_len as _) + .read_string(&mut store, key_ptr, key_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; tracing::debug!("tx_delete {}", key); @@ -964,33 +972,34 @@ where let (gas, _size_diff) = write_log .delete(&key) .map_err(TxRuntimeError::StorageModificationError)?; - tx_add_gas(env, gas) + tx_add_gas_aux(&env, gas) // TODO: charge the size diff } /// Emitting an IBC event function exposed to the wasm VM Tx environment. /// The given IBC event will be set to the write log. pub fn tx_emit_ibc_event( - env: &TxVmEnv, + mut env: FunctionEnvMut>, event_ptr: u64, event_len: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (event, gas) = env .memory - .read_bytes(event_ptr, event_len as _) + .read_bytes(&mut store, event_ptr, event_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; let event: IbcEvent = BorshDeserialize::try_from_slice(&event) .map_err(TxRuntimeError::EncodingError)?; let write_log = unsafe { env.ctx.write_log.get() }; let gas = write_log.emit_ibc_event(event); - tx_add_gas(env, gas) + tx_add_gas_aux(&env, gas) } /// Storage read prior state (before tx execution) function exposed to the wasm @@ -999,20 +1008,21 @@ where /// Returns `-1` when the key is not present, or the length of the data when /// the key is present (the length may be `0`). pub fn vp_read_pre( - env: &VpVmEnv, + mut env: FunctionEnvMut>, key_ptr: u64, key_len: u64, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (key, gas) = env .memory - .read_string(key_ptr, key_len as _) + .read_string(&mut store, key_ptr, key_len as _) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; let gas_meter = unsafe { env.ctx.gas_meter.get() }; vp_host_fns::add_gas(gas_meter, gas)?; @@ -1050,20 +1060,21 @@ where /// Returns `-1` when the key is not present, or the length of the data when /// the key is present (the length may be `0`). pub fn vp_read_post( - env: &VpVmEnv, + mut env: FunctionEnvMut>, key_ptr: u64, key_len: u64, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (key, gas) = env .memory - .read_string(key_ptr, key_len as _) + .read_string(&mut store, key_ptr, key_len as _) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; let gas_meter = unsafe { env.ctx.gas_meter.get() }; vp_host_fns::add_gas(gas_meter, gas)?; @@ -1096,20 +1107,21 @@ where /// Returns `-1` when the key is not present, or the length of the data when /// the key is present (the length may be `0`). pub fn vp_read_temp( - env: &VpVmEnv, + mut env: FunctionEnvMut>, key_ptr: u64, key_len: u64, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (key, gas) = env .memory - .read_string(key_ptr, key_len as _) + .read_string(&mut store, key_ptr, key_len as _) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; let gas_meter = unsafe { env.ctx.gas_meter.get() }; vp_host_fns::add_gas(gas_meter, gas)?; @@ -1144,21 +1156,22 @@ where /// any) back to the guest, the second step reads the value from cache into a /// pre-allocated buffer with the obtained size. pub fn vp_result_buffer( - env: &VpVmEnv, + mut env: FunctionEnvMut>, result_ptr: u64, ) -> vp_host_fns::EnvResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let result_buffer = unsafe { env.ctx.result_buffer.get() }; let value = result_buffer.take().unwrap(); let gas = env .memory - .write_bytes(result_ptr, value) + .write_bytes(&mut store, result_ptr, value) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; let gas_meter = unsafe { env.ctx.gas_meter.get() }; vp_host_fns::add_gas(gas_meter, gas) @@ -1167,20 +1180,21 @@ where /// Storage `has_key` in prior state (before tx execution) function exposed to /// the wasm VM VP environment. It will try to read from the storage. pub fn vp_has_key_pre( - env: &VpVmEnv, + mut env: FunctionEnvMut>, key_ptr: u64, key_len: u64, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (key, gas) = env .memory - .read_string(key_ptr, key_len as _) + .read_string(&mut store, key_ptr, key_len as _) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; let gas_meter = unsafe { env.ctx.gas_meter.get() }; vp_host_fns::add_gas(gas_meter, gas)?; @@ -1200,20 +1214,21 @@ where /// to the wasm VM VP environment. It will try to check the write log first and /// if no entry found then the storage. pub fn vp_has_key_post( - env: &VpVmEnv, + mut env: FunctionEnvMut>, key_ptr: u64, key_len: u64, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (key, gas) = env .memory - .read_string(key_ptr, key_len as _) + .read_string(&mut store, key_ptr, key_len as _) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; let gas_meter = unsafe { env.ctx.gas_meter.get() }; vp_host_fns::add_gas(gas_meter, gas)?; @@ -1234,20 +1249,21 @@ where /// the storage and return the corresponding ID of the iterator, ordered by /// storage keys. pub fn vp_iter_prefix_pre( - env: &VpVmEnv, + mut env: FunctionEnvMut>, prefix_ptr: u64, prefix_len: u64, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: 'static + storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (prefix, gas) = env .memory - .read_string(prefix_ptr, prefix_len as _) + .read_string(&mut store, prefix_ptr, prefix_len as _) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; let gas_meter = unsafe { env.ctx.gas_meter.get() }; vp_host_fns::add_gas(gas_meter, gas)?; @@ -1271,20 +1287,21 @@ where /// the storage and return the corresponding ID of the iterator, ordered by /// storage keys. pub fn vp_iter_prefix_post( - env: &VpVmEnv, + mut env: FunctionEnvMut>, prefix_ptr: u64, prefix_len: u64, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: 'static + storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (prefix, gas) = env .memory - .read_string(prefix_ptr, prefix_len as _) + .read_string(&mut store, prefix_ptr, prefix_len as _) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; let gas_meter = unsafe { env.ctx.gas_meter.get() }; vp_host_fns::add_gas(gas_meter, gas)?; @@ -1309,16 +1326,17 @@ where /// Returns `-1` when the key is not present, or the length of the data when /// the key is present (the length may be `0`). pub fn vp_iter_next( - env: &VpVmEnv, + env: FunctionEnvMut>, iter_id: u64, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let env = env.data(); tracing::debug!("vp_iter_next iter_id {}", iter_id); let iterators = unsafe { env.ctx.iterators.get() }; @@ -1343,21 +1361,22 @@ where /// Verifier insertion function exposed to the wasm VM Tx environment. pub fn tx_insert_verifier( - env: &TxVmEnv, + mut env: FunctionEnvMut>, addr_ptr: u64, addr_len: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (addr, gas) = env .memory - .read_string(addr_ptr, addr_len as _) + .read_string(&mut store, addr_ptr, addr_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; tracing::debug!("tx_insert_verifier {}, addr_ptr {}", addr, addr_ptr,); @@ -1365,28 +1384,29 @@ where let verifiers = unsafe { env.ctx.verifiers.get() }; verifiers.insert(addr); - tx_add_gas(env, addr_len) + tx_add_gas_aux(&env, addr_len) } /// Update a validity predicate function exposed to the wasm VM Tx environment pub fn tx_update_validity_predicate( - env: &TxVmEnv, + mut env: FunctionEnvMut>, addr_ptr: u64, addr_len: u64, code_hash_ptr: u64, code_hash_len: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (addr, gas) = env .memory - .read_string(addr_ptr, addr_len as _) + .read_string(&mut store, addr_ptr, addr_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; let addr = Address::decode(addr).map_err(TxRuntimeError::AddressError)?; tracing::debug!("tx_update_validity_predicate for addr {}", addr); @@ -1394,9 +1414,9 @@ where let key = Key::validity_predicate(&addr); let (code_hash, gas) = env .memory - .read_bytes(code_hash_ptr, code_hash_len as _) + .read_bytes(&mut store, code_hash_ptr, code_hash_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; tx_validate_vp_code_hash(env, &code_hash)?; @@ -1404,28 +1424,29 @@ where let (gas, _size_diff) = write_log .write(&key, code_hash) .map_err(TxRuntimeError::StorageModificationError)?; - tx_add_gas(env, gas) + tx_add_gas_aux(&env, gas) // TODO: charge the size diff } /// Initialize a new account established address. pub fn tx_init_account( - env: &TxVmEnv, + mut env: FunctionEnvMut>, code_hash_ptr: u64, code_hash_len: u64, result_ptr: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (code_hash, gas) = env .memory - .read_bytes(code_hash_ptr, code_hash_len as _) + .read_bytes(&mut store, code_hash_ptr, code_hash_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; tx_validate_vp_code_hash(env, &code_hash)?; @@ -1438,50 +1459,52 @@ where let (addr, gas) = write_log.init_account(&storage.address_gen, code_hash); let addr_bytes = addr.try_to_vec().map_err(TxRuntimeError::EncodingError)?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; let gas = env .memory - .write_bytes(result_ptr, addr_bytes) + .write_bytes(&mut store, result_ptr, addr_bytes) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas) + tx_add_gas_aux(&env, gas) } /// Getting the chain ID function exposed to the wasm VM Tx environment. pub fn tx_get_chain_id( - env: &TxVmEnv, + mut env: FunctionEnvMut>, result_ptr: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let storage = unsafe { env.ctx.storage.get() }; let (chain_id, gas) = storage.get_chain_id(); - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; let gas = env .memory - .write_string(result_ptr, chain_id) + .write_string(&mut store, result_ptr, chain_id) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas) + tx_add_gas_aux(&env, gas) } /// Getting the block height function exposed to the wasm VM Tx /// environment. The height is that of the block to which the current /// transaction is being applied. pub fn tx_get_block_height( - env: &TxVmEnv, + env: FunctionEnvMut>, ) -> TxResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let env = env.data(); let storage = unsafe { env.ctx.storage.get() }; let (height, gas) = storage.get_block_height(); - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; Ok(height.0) } @@ -1489,16 +1512,17 @@ where /// environment. The index is that of the transaction being applied /// in the current block. pub fn tx_get_tx_index( - env: &TxVmEnv, + env: FunctionEnvMut>, ) -> TxResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let env = env.data(); let tx_index = unsafe { env.ctx.tx_index.get() }; - tx_add_gas(env, crate::vm::host_env::gas::MIN_STORAGE_GAS)?; + tx_add_gas_aux(&env, crate::vm::host_env::gas::MIN_STORAGE_GAS)?; Ok(tx_index.0) } @@ -1506,15 +1530,16 @@ where /// environment. The height is that of the block to which the current /// transaction is being applied. pub fn vp_get_tx_index( - env: &VpVmEnv, + env: FunctionEnvMut>, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let env = env.data(); let gas_meter = unsafe { env.ctx.gas_meter.get() }; let tx_index = unsafe { env.ctx.tx_index.get() }; let tx_idx = vp_host_fns::get_tx_index(gas_meter, tx_index)?; @@ -1524,76 +1549,80 @@ where /// Getting the block hash function exposed to the wasm VM Tx environment. The /// hash is that of the block to which the current transaction is being applied. pub fn tx_get_block_hash( - env: &TxVmEnv, + mut env: FunctionEnvMut>, result_ptr: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let storage = unsafe { env.ctx.storage.get() }; let (hash, gas) = storage.get_block_hash(); - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; let gas = env .memory - .write_bytes(result_ptr, hash.0) + .write_bytes(&mut store, result_ptr, hash.0) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas) + tx_add_gas_aux(&env, gas) } /// Getting the block epoch function exposed to the wasm VM Tx /// environment. The epoch is that of the block to which the current /// transaction is being applied. pub fn tx_get_block_epoch( - env: &TxVmEnv, + env: FunctionEnvMut>, ) -> TxResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let env = env.data(); let storage = unsafe { env.ctx.storage.get() }; let (epoch, gas) = storage.get_current_epoch(); - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; Ok(epoch.0) } /// Get the native token's address pub fn tx_get_native_token( - env: &TxVmEnv, + mut env: FunctionEnvMut>, result_ptr: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let storage = unsafe { env.ctx.storage.get() }; - tx_add_gas(env, MIN_STORAGE_GAS)?; + tx_add_gas_aux(&env, MIN_STORAGE_GAS)?; let native_token = storage.native_token.clone(); let native_token_string = native_token.encode(); let gas = env .memory - .write_string(result_ptr, native_token_string) + .write_string(&mut store, result_ptr, native_token_string) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_add_gas(env, gas) + tx_add_gas_aux(&env, gas) } /// Getting the block header function exposed to the wasm VM Tx environment. pub fn tx_get_block_header( - env: &TxVmEnv, + env: FunctionEnvMut>, height: u64, ) -> TxResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let env = env.data(); let storage = unsafe { env.ctx.storage.get() }; let (header, gas) = storage .get_block_header(Some(BlockHeight(height))) @@ -1608,7 +1637,7 @@ where .map_err(TxRuntimeError::NumConversionError)?; let result_buffer = unsafe { env.ctx.result_buffer.get() }; result_buffer.replace(value); - tx_add_gas(env, gas)?; + tx_add_gas_aux(&env, gas)?; len } None => HostEnvResult::Fail.to_i64(), @@ -1617,22 +1646,23 @@ where /// Getting the chain ID function exposed to the wasm VM VP environment. pub fn vp_get_chain_id( - env: &VpVmEnv, + mut env: FunctionEnvMut>, result_ptr: u64, ) -> vp_host_fns::EnvResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let gas_meter = unsafe { env.ctx.gas_meter.get() }; let storage = unsafe { env.ctx.storage.get() }; let chain_id = vp_host_fns::get_chain_id(gas_meter, storage)?; let gas = env .memory - .write_string(result_ptr, chain_id) + .write_string(&mut store, result_ptr, chain_id) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; vp_host_fns::add_gas(gas_meter, gas) } @@ -1641,15 +1671,16 @@ where /// environment. The height is that of the block to which the current /// transaction is being applied. pub fn vp_get_block_height( - env: &VpVmEnv, + env: FunctionEnvMut>, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let env = env.data(); let gas_meter = unsafe { env.ctx.gas_meter.get() }; let storage = unsafe { env.ctx.storage.get() }; let height = vp_host_fns::get_block_height(gas_meter, storage)?; @@ -1658,16 +1689,17 @@ where /// Getting the block header function exposed to the wasm VM VP environment. pub fn vp_get_block_header( - env: &VpVmEnv, + env: FunctionEnvMut>, height: u64, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let env = env.data(); let gas_meter = unsafe { env.ctx.gas_meter.get() }; let storage = unsafe { env.ctx.storage.get() }; let (header, gas) = storage @@ -1694,38 +1726,40 @@ where /// Getting the block hash function exposed to the wasm VM VP environment. The /// hash is that of the block to which the current transaction is being applied. pub fn vp_get_block_hash( - env: &VpVmEnv, + mut env: FunctionEnvMut>, result_ptr: u64, ) -> vp_host_fns::EnvResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let gas_meter = unsafe { env.ctx.gas_meter.get() }; let storage = unsafe { env.ctx.storage.get() }; let hash = vp_host_fns::get_block_hash(gas_meter, storage)?; let gas = env .memory - .write_bytes(result_ptr, hash.0) + .write_bytes(&mut store, result_ptr, hash.0) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; vp_host_fns::add_gas(gas_meter, gas) } /// Getting the transaction hash function exposed to the wasm VM VP environment. pub fn vp_get_tx_code_hash( - env: &VpVmEnv, + mut env: FunctionEnvMut>, result_ptr: u64, ) -> vp_host_fns::EnvResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let gas_meter = unsafe { env.ctx.gas_meter.get() }; let tx = unsafe { env.ctx.tx.get() }; let hash = vp_host_fns::get_tx_code_hash(gas_meter, tx)?; @@ -1738,7 +1772,7 @@ where }; let gas = env .memory - .write_bytes(result_ptr, result_bytes) + .write_bytes(&mut store, result_ptr, result_bytes) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; vp_host_fns::add_gas(gas_meter, gas) } @@ -1747,15 +1781,16 @@ where /// environment. The epoch is that of the block to which the current /// transaction is being applied. pub fn vp_get_block_epoch( - env: &VpVmEnv, + env: FunctionEnvMut>, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let env = env.data(); let gas_meter = unsafe { env.ctx.gas_meter.get() }; let storage = unsafe { env.ctx.storage.get() }; let epoch = vp_host_fns::get_block_epoch(gas_meter, storage)?; @@ -1764,23 +1799,24 @@ where /// Verify a ShieldedTransaction. pub fn vp_verify_masp( - env: &VpVmEnv, + mut env: FunctionEnvMut>, tx_ptr: u64, tx_len: u64, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { use masp_primitives::transaction::Transaction; + let (env, mut store) = env.data_and_store_mut(); let gas_meter = unsafe { env.ctx.gas_meter.get() }; let (tx_bytes, gas) = env .memory - .read_bytes(tx_ptr, tx_len as _) + .read_bytes(&mut store, tx_ptr, tx_len as _) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; vp_host_fns::add_gas(gas_meter, gas)?; @@ -1798,19 +1834,20 @@ where /// printed at the [`tracing::Level::INFO`]. This function is for development /// only. pub fn tx_log_string( - env: &TxVmEnv, + mut env: FunctionEnvMut>, str_ptr: u64, str_len: u64, ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (str, _gas) = env .memory - .read_string(str_ptr, str_len as _) + .read_string(&mut store, str_ptr, str_len as _) .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; tracing::info!("WASM Transaction log: {}", str); Ok(()) @@ -1818,28 +1855,28 @@ where /// Validate a VP WASM code hash in a tx environment. fn tx_validate_vp_code_hash( - env: &TxVmEnv, + env: &TxVmEnv<'static, MEM, DB, H, CA>, code_hash: &[u8], ) -> TxResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, CA: WasmCacheAccess, { - tx_add_gas(env, code_hash.len() as u64 * WASM_VALIDATION_GAS_PER_BYTE)?; + tx_add_gas_aux(env, code_hash.len() as u64 * WASM_VALIDATION_GAS_PER_BYTE)?; let hash = Hash::try_from(code_hash) .map_err(|e| TxRuntimeError::InvalidVpCodeHash(e.to_string()))?; let key = Key::wasm_code(&hash); let write_log = unsafe { env.ctx.write_log.get() }; let (result, gas) = write_log.read(&key); - tx_add_gas(env, gas)?; + tx_add_gas_aux(env, gas)?; if result.is_none() { let storage = unsafe { env.ctx.storage.get() }; let (is_present, gas) = storage .has_key(&key) .map_err(TxRuntimeError::StorageError)?; - tx_add_gas(env, gas)?; + tx_add_gas_aux(env, gas)?; if !is_present { return Err(TxRuntimeError::InvalidVpCodeHash( "The corresponding VP code doesn't exist".to_string(), @@ -1851,29 +1888,30 @@ where /// Evaluate a validity predicate with the given input data. pub fn vp_eval( - env: &VpVmEnv<'static, MEM, DB, H, EVAL, CA>, + mut env: FunctionEnvMut>, vp_code_ptr: u64, vp_code_len: u64, input_data_ptr: u64, input_data_len: u64, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (vp_code_hash, gas) = env .memory - .read_bytes(vp_code_ptr, vp_code_len as _) + .read_bytes(&mut store, vp_code_ptr, vp_code_len as _) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; let gas_meter = unsafe { env.ctx.gas_meter.get() }; vp_host_fns::add_gas(gas_meter, gas)?; let (input_data, gas) = env .memory - .read_bytes(input_data_ptr, input_data_len as _) + .read_bytes(&mut store, input_data_ptr, input_data_len as _) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; vp_host_fns::add_gas(gas_meter, gas)?; let input_data: Tx = BorshDeserialize::try_from_slice(&input_data) @@ -1893,38 +1931,40 @@ where /// Get the native token's address pub fn vp_get_native_token( - env: &VpVmEnv, + mut env: FunctionEnvMut>, result_ptr: u64, ) -> vp_host_fns::EnvResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let gas_meter = unsafe { env.ctx.gas_meter.get() }; let storage = unsafe { env.ctx.storage.get() }; let native_token = vp_host_fns::get_native_token(gas_meter, storage)?; let native_token_string = native_token.encode(); let gas = env .memory - .write_string(result_ptr, native_token_string) + .write_string(&mut store, result_ptr, native_token_string) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; vp_host_fns::add_gas(gas_meter, gas) } /// Find if the wrapper tx had a valid `testnet_pow::Solution` pub fn vp_has_valid_pow( - env: &VpVmEnv, + env: FunctionEnvMut>, ) -> vp_host_fns::EnvResult where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let env = env.data(); #[cfg(feature = "mainnet")] let _ = env; @@ -1945,20 +1985,21 @@ where /// printed at the [`tracing::Level::INFO`]. This function is for development /// only. pub fn vp_log_string( - env: &VpVmEnv, + mut env: FunctionEnvMut>, str_ptr: u64, str_len: u64, ) -> vp_host_fns::EnvResult<()> where - MEM: VmMemory, + MEM: VmMemory + 'static, DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let (env, mut store) = env.data_and_store_mut(); let (str, _gas) = env .memory - .read_string(str_ptr, str_len as _) + .read_string(&mut store, str_ptr, str_len as _) .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; tracing::info!("WASM Validity predicate log: {}", str); Ok(()) diff --git a/shared/src/vm/memory.rs b/shared/src/vm/memory.rs index e55117726c..92352186b0 100644 --- a/shared/src/vm/memory.rs +++ b/shared/src/vm/memory.rs @@ -10,6 +10,7 @@ pub trait VmMemory: Clone + Send + Sync { /// Returns bytes read from memory together with the associated gas cost. fn read_bytes( &self, + store: &mut wasmer::StoreMut<'_>, offset: u64, len: usize, ) -> Result<(Vec, u64), Self::Error>; @@ -17,6 +18,7 @@ pub trait VmMemory: Clone + Send + Sync { /// Write bytes to memory. Returns the gas cost. fn write_bytes( &self, + store: &mut wasmer::StoreMut<'_>, offset: u64, bytes: impl AsRef<[u8]>, ) -> Result; @@ -24,6 +26,7 @@ pub trait VmMemory: Clone + Send + Sync { /// Returns string read from memory together with the associated gas cost. fn read_string( &self, + store: &mut wasmer::StoreMut<'_>, offset: u64, len: usize, ) -> Result<(String, u64), Self::Error>; @@ -31,6 +34,7 @@ pub trait VmMemory: Clone + Send + Sync { /// Write string to memory. Returns the gas cost. fn write_string( &self, + store: &mut wasmer::StoreMut<'_>, offset: u64, string: String, ) -> Result; @@ -56,6 +60,7 @@ pub mod testing { fn read_bytes( &self, + _store: &mut wasmer::StoreMut<'_>, offset: u64, len: usize, ) -> Result<(Vec, u64)> { @@ -65,6 +70,7 @@ pub mod testing { fn write_bytes( &self, + _store: &mut wasmer::StoreMut<'_>, offset: u64, bytes: impl AsRef<[u8]>, ) -> Result { @@ -78,6 +84,7 @@ pub mod testing { fn read_string( &self, + _store: &mut wasmer::StoreMut<'_>, offset: u64, len: usize, ) -> Result<(String, u64)> { @@ -88,7 +95,12 @@ pub mod testing { Ok((string, 0)) } - fn write_string(&self, offset: u64, string: String) -> Result { + fn write_string( + &self, + _store: &mut wasmer::StoreMut<'_>, + offset: u64, + string: String, + ) -> Result { let bytes = string.as_bytes(); let len = bytes.len(); let target = diff --git a/shared/src/vm/wasm/compilation_cache/common.rs b/shared/src/vm/wasm/compilation_cache/common.rs index 5d38a7a993..73f7620e65 100644 --- a/shared/src/vm/wasm/compilation_cache/common.rs +++ b/shared/src/vm/wasm/compilation_cache/common.rs @@ -65,7 +65,9 @@ impl WeightScale for ModuleCacheScale { // elements, so we use the size of the module as its scale // and subtract 1 from it to negate the increment of the cache length. - let size = loupe::size_of_val(&value) + HASH_LENGTH; + let size = + // loupe::size_of_val(&value) + + HASH_LENGTH; tracing::debug!( "WASM module hash {}, size including the hash {}", key.to_string(), @@ -542,8 +544,7 @@ mod dylib { #[allow(dead_code)] pub fn store() -> Store { let compiler = wasmer_compiler_singlepass::Singlepass::default(); - let engine = wasmer_engine_dylib::Dylib::new(compiler).engine(); - Store::new_with_tunables(&engine, memory::vp_limit()) + Store::new_with_tunables(compiler, memory::vp_limit()) } } @@ -1010,7 +1011,8 @@ mod test { ); let (module, _store) = cache.compile_or_fetch(&code).unwrap().unwrap(); - loupe::size_of_val(&module) + HASH_LENGTH + extra_bytes + // loupe::size_of_val(&module) + + HASH_LENGTH + extra_bytes }; println!( "Compiled module {} size including the hash: {} ({})", diff --git a/shared/src/vm/wasm/host_env.rs b/shared/src/vm/wasm/host_env.rs index 3212649624..b344c5e391 100644 --- a/shared/src/vm/wasm/host_env.rs +++ b/shared/src/vm/wasm/host_env.rs @@ -3,53 +3,21 @@ //! Here, we expose the host functions into wasm's //! imports, so they can be called from inside the wasm. -use wasmer::{ - Function, HostEnvInitError, ImportObject, Instance, Memory, Store, - WasmerEnv, -}; +use wasmer::{Function, FunctionEnv, Imports, Instance, Memory, Store}; use crate::ledger::storage::{self, StorageHasher}; use crate::vm::host_env::{TxVmEnv, VpEvaluator, VpVmEnv}; use crate::vm::wasm::memory::WasmMemory; use crate::vm::{host_env, WasmCacheAccess}; -impl WasmerEnv for TxVmEnv<'_, WasmMemory, DB, H, CA> -where - DB: storage::DB + for<'iter> storage::DBIter<'iter>, - H: StorageHasher, - CA: WasmCacheAccess, -{ - fn init_with_instance( - &mut self, - instance: &Instance, - ) -> std::result::Result<(), HostEnvInitError> { - self.memory.init_env_memory(&instance.exports) - } -} - -impl WasmerEnv for VpVmEnv<'_, WasmMemory, DB, H, EVAL, CA> -where - DB: storage::DB + for<'iter> storage::DBIter<'iter>, - H: StorageHasher, - EVAL: VpEvaluator, - CA: WasmCacheAccess, -{ - fn init_with_instance( - &mut self, - instance: &Instance, - ) -> std::result::Result<(), HostEnvInitError> { - self.memory.init_env_memory(&instance.exports) - } -} - /// Prepare imports (memory and host functions) exposed to the vm guest running /// transaction code #[allow(clippy::too_many_arguments)] pub fn tx_imports( - wasm_store: &Store, + wasm_store: &mut Store, initial_memory: Memory, - env: TxVmEnv<'static, WasmMemory, DB, H, CA>, -) -> ImportObject + env: &FunctionEnv>, +) -> Imports where DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, @@ -59,27 +27,27 @@ where // default namespace "env" => { "memory" => initial_memory, - "gas" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_charge_gas), - "namada_tx_read" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_read), - "namada_tx_result_buffer" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_result_buffer), - "namada_tx_has_key" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_has_key), - "namada_tx_write" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_write), - "namada_tx_write_temp" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_write_temp), - "namada_tx_delete" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_delete), - "namada_tx_iter_prefix" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_iter_prefix), - "namada_tx_iter_next" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_iter_next), - "namada_tx_insert_verifier" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_insert_verifier), - "namada_tx_update_validity_predicate" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_update_validity_predicate), - "namada_tx_init_account" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_init_account), - "namada_tx_emit_ibc_event" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_emit_ibc_event), - "namada_tx_get_chain_id" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_chain_id), - "namada_tx_get_tx_index" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_tx_index), - "namada_tx_get_block_height" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_block_height), - "namada_tx_get_block_header" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_block_header), - "namada_tx_get_block_hash" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_block_hash), - "namada_tx_get_block_epoch" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_block_epoch), - "namada_tx_get_native_token" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_native_token), - "namada_tx_log_string" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_log_string), + "gas" => Function::new_typed_with_env(wasm_store, env, host_env::tx_charge_gas), + "namada_tx_read" => Function::new_typed_with_env(wasm_store, env, host_env::tx_read), + "namada_tx_result_buffer" => Function::new_typed_with_env(wasm_store, env, host_env::tx_result_buffer), + "namada_tx_has_key" => Function::new_typed_with_env(wasm_store, env, host_env::tx_has_key), + "namada_tx_write" => Function::new_typed_with_env(wasm_store, env, host_env::tx_write), + "namada_tx_write_temp" => Function::new_typed_with_env(wasm_store, env, host_env::tx_write_temp), + "namada_tx_delete" => Function::new_typed_with_env(wasm_store, env, host_env::tx_delete), + "namada_tx_iter_prefix" => Function::new_typed_with_env(wasm_store, env, host_env::tx_iter_prefix), + "namada_tx_iter_next" => Function::new_typed_with_env(wasm_store, env, host_env::tx_iter_next), + "namada_tx_insert_verifier" => Function::new_typed_with_env(wasm_store, env, host_env::tx_insert_verifier), + "namada_tx_update_validity_predicate" => Function::new_typed_with_env(wasm_store, env, host_env::tx_update_validity_predicate), + "namada_tx_init_account" => Function::new_typed_with_env(wasm_store, env, host_env::tx_init_account), + "namada_tx_emit_ibc_event" => Function::new_typed_with_env(wasm_store, env, host_env::tx_emit_ibc_event), + "namada_tx_get_chain_id" => Function::new_typed_with_env(wasm_store, env, host_env::tx_get_chain_id), + "namada_tx_get_tx_index" => Function::new_typed_with_env(wasm_store, env, host_env::tx_get_tx_index), + "namada_tx_get_block_height" => Function::new_typed_with_env(wasm_store, env, host_env::tx_get_block_height), + "namada_tx_get_block_header" => Function::new_typed_with_env(wasm_store, env, host_env::tx_get_block_header), + "namada_tx_get_block_hash" => Function::new_typed_with_env(wasm_store, env, host_env::tx_get_block_hash), + "namada_tx_get_block_epoch" => Function::new_typed_with_env(wasm_store, env, host_env::tx_get_block_epoch), + "namada_tx_get_native_token" => Function::new_typed_with_env(wasm_store, env, host_env::tx_get_native_token), + "namada_tx_log_string" => Function::new_typed_with_env(wasm_store, env, host_env::tx_log_string), }, } } @@ -87,42 +55,43 @@ where /// Prepare imports (memory and host functions) exposed to the vm guest running /// validity predicate code pub fn vp_imports( - wasm_store: &Store, + wasm_store: &mut Store, initial_memory: Memory, env: VpVmEnv<'static, WasmMemory, DB, H, EVAL, CA>, -) -> ImportObject +) -> Imports where DB: storage::DB + for<'iter> storage::DBIter<'iter>, H: StorageHasher, EVAL: VpEvaluator, CA: WasmCacheAccess, { + let env = FunctionEnv::new(wasm_store, env); wasmer::imports! { // default namespace "env" => { "memory" => initial_memory, - "gas" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_charge_gas), - "namada_vp_read_pre" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_read_pre), - "namada_vp_read_post" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_read_post), - "namada_vp_read_temp" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_read_temp), - "namada_vp_result_buffer" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_result_buffer), - "namada_vp_has_key_pre" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_has_key_pre), - "namada_vp_has_key_post" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_has_key_post), - "namada_vp_iter_prefix_pre" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_iter_prefix_pre), - "namada_vp_iter_prefix_post" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_iter_prefix_pre), - "namada_vp_iter_next" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_iter_next), - "namada_vp_get_chain_id" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_chain_id), - "namada_vp_get_tx_index" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_tx_index), - "namada_vp_get_block_height" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_block_height), - "namada_vp_get_block_header" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_block_header), - "namada_vp_get_block_hash" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_block_hash), - "namada_vp_get_tx_code_hash" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_tx_code_hash), - "namada_vp_get_block_epoch" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_block_epoch), - "namada_vp_verify_masp" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_verify_masp), - "namada_vp_eval" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_eval), - "namada_vp_get_native_token" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_native_token), - "namada_vp_has_valid_pow" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_has_valid_pow), - "namada_vp_log_string" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_log_string), + "gas" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_charge_gas), + "namada_vp_read_pre" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_read_pre), + "namada_vp_read_post" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_read_post), + "namada_vp_read_temp" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_read_temp), + "namada_vp_result_buffer" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_result_buffer), + "namada_vp_has_key_pre" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_has_key_pre), + "namada_vp_has_key_post" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_has_key_post), + "namada_vp_iter_prefix_pre" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_iter_prefix_pre), + "namada_vp_iter_prefix_post" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_iter_prefix_pre), + "namada_vp_iter_next" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_iter_next), + "namada_vp_get_chain_id" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_get_chain_id), + "namada_vp_get_tx_index" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_get_tx_index), + "namada_vp_get_block_height" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_get_block_height), + "namada_vp_get_block_header" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_get_block_header), + "namada_vp_get_block_hash" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_get_block_hash), + "namada_vp_get_tx_code_hash" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_get_tx_code_hash), + "namada_vp_get_block_epoch" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_get_block_epoch), + "namada_vp_verify_masp" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_verify_masp), + "namada_vp_eval" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_eval), + "namada_vp_get_native_token" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_get_native_token), + "namada_vp_has_valid_pow" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_has_valid_pow), + "namada_vp_log_string" => Function::new_typed_with_env(wasm_store, &env, host_env::vp_log_string), }, } } diff --git a/shared/src/vm/wasm/memory.rs b/shared/src/vm/wasm/memory.rs index 7e79ab1be0..2a7f59b04f 100644 --- a/shared/src/vm/wasm/memory.rs +++ b/shared/src/vm/wasm/memory.rs @@ -8,11 +8,12 @@ use std::sync::Arc; use borsh::BorshSerialize; use thiserror::Error; use wasmer::{ - vm, BaseTunables, HostEnvInitError, LazyInit, Memory, MemoryError, - MemoryType, Pages, TableType, Target, Tunables, + vm, BaseTunables, ExportError, Memory, MemoryError, MemoryType, Pages, + TableType, Target, Tunables, }; use wasmer_vm::{ - MemoryStyle, TableStyle, VMMemoryDefinition, VMTableDefinition, + MemoryStyle, TableStyle, VMMemory, VMMemoryDefinition, VMTable, + VMTableDefinition, }; use crate::proto::Tx; @@ -26,6 +27,8 @@ pub enum Error { InitMemoryError(wasmer::MemoryError), #[error("Memory ouf of bounds: {0}")] MemoryOutOfBounds(wasmer::MemoryError), + #[error("Memory access error: {0}")] + MemoryAccessError(#[from] wasmer::MemoryAccessError), #[error("Encoding error: {0}")] EncodingError(std::io::Error), #[error("Memory is not initialized")] @@ -50,7 +53,7 @@ pub const VP_MEMORY_INIT_PAGES: u32 = 100; // 6.4 MiB pub const VP_MEMORY_MAX_PAGES: u32 = 200; // 12.8 MiB /// Prepare memory for instantiating a transaction module -pub fn prepare_tx_memory(store: &wasmer::Store) -> Result { +pub fn prepare_tx_memory(store: &mut wasmer::Store) -> Result { let mem_type = wasmer::MemoryType::new( TX_MEMORY_INIT_PAGES, Some(TX_MEMORY_MAX_PAGES), @@ -60,7 +63,7 @@ pub fn prepare_tx_memory(store: &wasmer::Store) -> Result { } /// Prepare memory for instantiating a validity predicate module -pub fn prepare_vp_memory(store: &wasmer::Store) -> Result { +pub fn prepare_vp_memory(store: &mut wasmer::Store) -> Result { let mem_type = wasmer::MemoryType::new( VP_MEMORY_INIT_PAGES, Some(VP_MEMORY_MAX_PAGES), @@ -82,13 +85,14 @@ pub struct TxCallInput { /// Write transaction inputs into wasm memory pub fn write_tx_inputs( memory: &wasmer::Memory, + store: &mut wasmer::StoreMut<'_>, tx_data: &Tx, ) -> Result { let tx_data_ptr = 0; let tx_data_bytes = tx_data.try_to_vec().map_err(Error::EncodingError)?; let tx_data_len = tx_data_bytes.len() as _; - write_memory_bytes(memory, tx_data_ptr, tx_data_bytes)?; + write_memory_bytes(memory, store, tx_data_ptr, tx_data_bytes)?; Ok(TxCallInput { tx_data_ptr, @@ -120,6 +124,7 @@ pub struct VpCallInput { /// Write validity predicate inputs into wasm memory pub fn write_vp_inputs( memory: &wasmer::Memory, + store: &mut wasmer::StoreMut<'_>, VpInput { addr, data, @@ -152,7 +157,7 @@ pub fn write_vp_inputs( &verifiers_bytes[..], ] .concat(); - write_memory_bytes(memory, addr_ptr, bytes)?; + write_memory_bytes(memory, store, addr_ptr, bytes)?; Ok(VpCallInput { addr_ptr, @@ -168,62 +173,65 @@ pub fn write_vp_inputs( /// Check that the given offset and length fits into the memory bounds. If not, /// it will try to grow the memory. -fn check_bounds(memory: &Memory, offset: u64, len: usize) -> Result<()> { - tracing::debug!( - "check_bounds pages {}, data_size {}, offset + len {}", - memory.size().0, - memory.data_size(), - offset + len as u64 - ); - if memory.data_size() < offset + len as u64 { - let cur_pages = memory.size().0; - let capacity = cur_pages as usize * wasmer::WASM_PAGE_SIZE; - let missing = offset as usize + len - capacity; - // Ceiling division - let req_pages = ((missing + wasmer::WASM_PAGE_SIZE - 1) - / wasmer::WASM_PAGE_SIZE) as u32; - tracing::info!("trying to grow memory by {} pages", req_pages); - memory.grow(req_pages).map_err(Error::MemoryOutOfBounds)?; - } +fn check_bounds( + memory: &Memory, + store: &mut wasmer::StoreMut<'_>, + offset: u64, + len: usize, +) -> Result<()> { + // TODO: fucked big time + // tracing::debug!( + // "check_bounds pages {}, data_size {}, offset + len {}", + // memory.size().0, + // memory.data_size(), + // offset + len as u64 + // ); + // if memory.data_size() < offset + len as u64 { + // let cur_pages = memory.size().0; + // let capacity = cur_pages as usize * wasmer::WASM_PAGE_SIZE; + // let missing = offset as usize + len - capacity; + // // Ceiling division + // let req_pages = ((missing + wasmer::WASM_PAGE_SIZE - 1) + // / wasmer::WASM_PAGE_SIZE) as u32; + // tracing::info!("trying to grow memory by {} pages", req_pages); + // memory + // .grow(store, req_pages) + // .map_err(Error::MemoryOutOfBounds)?; + // } Ok(()) } /// Read bytes from memory at the given offset and length fn read_memory_bytes( memory: &Memory, + store: &mut wasmer::StoreMut<'_>, offset: u64, len: usize, ) -> Result> { - check_bounds(memory, offset, len)?; - let offset = offset as usize; - let vec: Vec<_> = memory.view()[offset..(offset + len)] - .iter() - .map(|cell| cell.get()) - .collect(); - Ok(vec) + check_bounds(memory, store, offset, len)?; + let mut buf = vec![]; + memory.view(store).read(offset, &mut buf)?; + Ok(buf) } /// Write bytes into memory at the given offset fn write_memory_bytes( memory: &Memory, + store: &mut wasmer::StoreMut<'_>, offset: u64, bytes: impl AsRef<[u8]>, ) -> Result<()> { let slice = bytes.as_ref(); let len = slice.len(); - check_bounds(memory, offset, len as _)?; - let offset = offset as usize; - memory.view()[offset..(offset + len)] - .iter() - .zip(slice.iter()) - .for_each(|(cell, v)| cell.set(*v)); + check_bounds(memory, store, offset, len as _)?; + memory.view(store).write(offset, slice)?; Ok(()) } /// The wasm memory #[derive(Debug, Clone, Default)] pub struct WasmMemory { - inner: LazyInit, + inner: Option, } impl WasmMemory { @@ -232,7 +240,7 @@ impl WasmMemory { pub fn init_env_memory( &mut self, exports: &wasmer::Exports, - ) -> std::result::Result<(), HostEnvInitError> { + ) -> std::result::Result<(), ExportError> { // "`TxEnv` holds a reference to the Wasm `Memory`, which itself // internally holds a reference to the instance which owns that // memory. However the instance itself also holds a reference to @@ -241,10 +249,7 @@ impl WasmMemory { // You can work around this by using `get_with_generics_weak` which // creates a weak reference to the `Instance` internally." // - let memory = exports.get_with_generics_weak("memory")?; - if !self.inner.initialize(memory) { - tracing::error!("wasm memory is already initialized"); - } + self.inner = Some(exports.get_memory("memory")?.clone()); Ok(()) } } @@ -254,25 +259,40 @@ impl VmMemory for WasmMemory { /// Read bytes from memory at the given offset and length, return the bytes /// and the gas cost - fn read_bytes(&self, offset: u64, len: usize) -> Result<(Vec, u64)> { - let memory = self.inner.get_ref().ok_or(Error::UninitializedMemory)?; - let bytes = read_memory_bytes(memory, offset, len)?; + fn read_bytes( + &self, + store: &mut wasmer::StoreMut<'_>, + offset: u64, + len: usize, + ) -> Result<(Vec, u64)> { + let memory = self.inner.as_ref().ok_or(Error::UninitializedMemory)?; + let bytes = read_memory_bytes(memory, store, offset, len)?; let gas = bytes.len(); Ok((bytes, gas as _)) } /// Write bytes into memory at the given offset and return the gas cost - fn write_bytes(&self, offset: u64, bytes: impl AsRef<[u8]>) -> Result { + fn write_bytes( + &self, + store: &mut wasmer::StoreMut<'_>, + offset: u64, + bytes: impl AsRef<[u8]>, + ) -> Result { let gas = bytes.as_ref().len(); - let memory = self.inner.get_ref().ok_or(Error::UninitializedMemory)?; - write_memory_bytes(memory, offset, bytes)?; + let memory = self.inner.as_ref().ok_or(Error::UninitializedMemory)?; + write_memory_bytes(memory, store, offset, bytes)?; Ok(gas as _) } /// Read string from memory at the given offset and bytes length, and return /// the gas cost - fn read_string(&self, offset: u64, len: usize) -> Result<(String, u64)> { - let (bytes, gas) = self.read_bytes(offset, len)?; + fn read_string( + &self, + store: &mut wasmer::StoreMut<'_>, + offset: u64, + len: usize, + ) -> Result<(String, u64)> { + let (bytes, gas) = self.read_bytes(store, offset, len)?; let string = std::str::from_utf8(&bytes) .map_err(Error::InvalidUtf8String)? .to_string(); @@ -281,12 +301,17 @@ impl VmMemory for WasmMemory { /// Write string into memory at the given offset and return the gas cost #[allow(dead_code)] - fn write_string(&self, offset: u64, string: String) -> Result { - self.write_bytes(offset, string.as_bytes()) + fn write_string( + &self, + store: &mut wasmer::StoreMut<'_>, + offset: u64, + string: String, + ) -> Result { + self.write_bytes(store, offset, string.as_bytes()) } } -#[derive(loupe::MemoryUsage)] +// #[derive(loupe::MemoryUsage)] /// A custom [`Tunables`] to set a WASM memory limits. /// /// Adapted from . @@ -377,7 +402,7 @@ impl Tunables for Limit { &self, ty: &MemoryType, style: &MemoryStyle, - ) -> std::result::Result, MemoryError> { + ) -> std::result::Result { let adjusted = self.adjust_memory(ty); self.validate_memory(&adjusted)?; self.base.create_host_memory(&adjusted, style) @@ -392,7 +417,7 @@ impl Tunables for Limit { ty: &MemoryType, style: &MemoryStyle, vm_definition_location: NonNull, - ) -> std::result::Result, MemoryError> { + ) -> std::result::Result { let adjusted = self.adjust_memory(ty); self.validate_memory(&adjusted)?; self.base @@ -407,7 +432,7 @@ impl Tunables for Limit { &self, ty: &TableType, style: &TableStyle, - ) -> std::result::Result, String> { + ) -> std::result::Result { self.base.create_host_table(ty, style) } @@ -420,7 +445,7 @@ impl Tunables for Limit { ty: &TableType, style: &TableStyle, vm_definition_location: NonNull, - ) -> std::result::Result, String> { + ) -> std::result::Result { self.base.create_vm_table(ty, style, vm_definition_location) } } @@ -428,7 +453,8 @@ impl Tunables for Limit { #[cfg(test)] pub mod tests { use wasmer::{ - wat2wasm, BaseTunables, Cranelift, Instance, Module, Store, Target, + wat2wasm, AsStoreRef, BaseTunables, Cranelift, Instance, Module, Store, + Target, }; use super::*; @@ -446,14 +472,13 @@ pub mod tests { // Any compiler and any engine do the job here let compiler = Cranelift::default(); - let engine = wasmer_engine_universal::Universal::new(compiler).engine(); let base = BaseTunables::for_target(&Target::default()); let limit = Pages(24); let tunables = Limit { limit, base }; // Create a store, that holds the engine and our custom tunables - let store = Store::new_with_tunables(&engine, tunables); + let mut store = wasmer::Store::new_with_tunables(compiler, tunables); println!("Compiling module..."); let module = Module::new(&store, wasm_bytes).unwrap(); @@ -462,7 +487,8 @@ pub mod tests { let import_object = wasmer::imports! {}; // Now at this point, our custom tunables are used - let instance = Instance::new(&module, &import_object).unwrap(); + let instance = + Instance::new(&mut store, &module, &import_object).unwrap(); // Check what happened let mut memories: Vec = instance @@ -475,6 +501,9 @@ pub mod tests { let first_memory = memories.pop().unwrap(); println!("Memory of this instance: {:?}", first_memory); - assert_eq!(first_memory.ty().maximum.unwrap(), limit); + assert_eq!( + first_memory.ty(&store.as_store_ref()).maximum.unwrap(), + limit + ); } } diff --git a/shared/src/vm/wasm/run.rs b/shared/src/vm/wasm/run.rs index ae20b9e6d2..85a2a45793 100644 --- a/shared/src/vm/wasm/run.rs +++ b/shared/src/vm/wasm/run.rs @@ -6,7 +6,7 @@ use std::marker::PhantomData; use parity_wasm::elements; use pwasm_utils::{self, rules}; use thiserror::Error; -use wasmer::{BaseTunables, Module, Store}; +use wasmer::{AsStoreMut, BaseTunables, Module}; use super::memory::{Limit, WasmMemory}; use super::TxCache; @@ -99,7 +99,7 @@ where .get_section(tx.code_sechash()) .and_then(Section::code_sec) .ok_or(Error::MissingCode)?; - let (module, store) = match tx_code.code { + let (module, mut store) = match tx_code.code { Commitment::Hash(code_hash) => { fetch_or_compile(tx_wasm_cache, &code_hash, write_log, storage)? } @@ -130,12 +130,17 @@ where ); let initial_memory = - memory::prepare_tx_memory(&store).map_err(Error::MemoryError)?; - let imports = tx_imports(&store, initial_memory, env); + memory::prepare_tx_memory(&mut store).map_err(Error::MemoryError)?; + let mut env = wasmer::FunctionEnv::new(&mut store, env); + let imports = tx_imports(&mut store, initial_memory, &env); // Instantiate the wasm module - let instance = wasmer::Instance::new(&module, &imports) + let instance = wasmer::Instance::new(&mut store, &module, &imports) .map_err(|e| Error::InstantiationError(Box::new(e)))?; + env.as_mut(&mut store) + .memory + .init_env_memory(&instance.exports) + .expect("todo"); // We need to write the inputs in the memory exported from the wasm // module @@ -146,19 +151,20 @@ where let memory::TxCallInput { tx_data_ptr, tx_data_len, - } = memory::write_tx_inputs(memory, tx).map_err(Error::MemoryError)?; + } = memory::write_tx_inputs(memory, &mut store.as_store_mut(), tx) + .map_err(Error::MemoryError)?; // Get the module's entrypoint to be called let apply_tx = instance .exports .get_function(TX_ENTRYPOINT) .map_err(Error::MissingModuleEntrypoint)? - .native::<(u64, u64), ()>() + .typed::<(u64, u64), ()>(&mut store) .map_err(|error| Error::UnexpectedModuleEntrypointInterface { entrypoint: TX_ENTRYPOINT, error, })?; match apply_tx - .call(tx_data_ptr, tx_data_len) + .call(&mut store, tx_data_ptr, tx_data_len) .map_err(Error::RuntimeError) { Err(Error::RuntimeError(err)) => { @@ -194,7 +200,7 @@ where CA: 'static + WasmCacheAccess, { // Compile the wasm module - let (module, store) = + let (module, mut store) = fetch_or_compile(&mut vp_wasm_cache, vp_code_hash, write_log, storage)?; let mut iterators: PrefixIterators<'_, DB> = PrefixIterators::default(); @@ -224,15 +230,25 @@ where ); let initial_memory = - memory::prepare_vp_memory(&store).map_err(Error::MemoryError)?; - let imports = vp_imports(&store, initial_memory, env); - - run_vp(module, imports, tx, address, keys_changed, verifiers) + memory::prepare_vp_memory(&mut store).map_err(Error::MemoryError)?; + let imports = vp_imports(&mut store, initial_memory, env); + + let mut store_mut = store.as_store_mut(); + run_vp( + module, + &mut store_mut, + imports, + tx, + address, + keys_changed, + verifiers, + ) } fn run_vp( - module: wasmer::Module, - vp_imports: wasmer::ImportObject, + mut module: wasmer::Module, + store: &mut wasmer::StoreMut<'_>, + vp_imports: wasmer::Imports, input_data: &Tx, address: &Address, keys_changed: &BTreeSet, @@ -246,7 +262,7 @@ fn run_vp( }; // Instantiate the wasm module - let instance = wasmer::Instance::new(&module, &vp_imports) + let instance = wasmer::Instance::new(store, &mut module, &vp_imports) .map_err(|e| Error::InstantiationError(Box::new(e)))?; // We need to write the inputs in the memory exported from the wasm @@ -264,20 +280,22 @@ fn run_vp( keys_changed_len, verifiers_ptr, verifiers_len, - } = memory::write_vp_inputs(memory, input).map_err(Error::MemoryError)?; + } = memory::write_vp_inputs(memory, store, input) + .map_err(Error::MemoryError)?; // Get the module's entrypoint to be called let validate_tx = instance .exports .get_function(VP_ENTRYPOINT) .map_err(Error::MissingModuleEntrypoint)? - .native::<(u64, u64, u64, u64, u64, u64, u64, u64), u64>() + .typed::<(u64, u64, u64, u64, u64, u64, u64, u64), u64>(store) .map_err(|error| Error::UnexpectedModuleEntrypointInterface { entrypoint: VP_ENTRYPOINT, error, })?; let is_valid = validate_tx .call( + store, addr_ptr, addr_len, data_ptr, @@ -367,16 +385,18 @@ where }; // Compile the wasm module - let (module, store) = + let (module, mut store) = fetch_or_compile(vp_wasm_cache, &vp_code_hash, write_log, storage)?; - let initial_memory = - memory::prepare_vp_memory(&store).map_err(Error::MemoryError)?; + let initial_memory = memory::prepare_vp_memory(&mut store) + .map_err(Error::MemoryError)?; - let imports = vp_imports(&store, initial_memory, env); + let imports = vp_imports(&mut store, initial_memory, env); + let mut store_mut = store.as_store_mut(); run_vp( module, + &mut store_mut, imports, &input_data, address, @@ -390,10 +410,10 @@ where pub fn untrusted_wasm_store(limit: Limit) -> wasmer::Store { // Use Singlepass compiler with the default settings let compiler = wasmer_compiler_singlepass::Singlepass::default(); - wasmer::Store::new_with_tunables( - &wasmer_engine_universal::Universal::new(compiler).engine(), - limit, - ) + let mut store = wasmer::Store::new(compiler); + // TODO: this is fucked + // store.engine().set_tunables(limit); + store } /// Inject gas counter and stack-height limiter into the given wasm code @@ -415,7 +435,7 @@ fn fetch_or_compile( code_hash: &Hash, write_log: &WriteLog, storage: &Storage, -) -> Result<(Module, Store)> +) -> Result<(Module, wasmer::Store)> where DB: 'static + storage::DB + for<'iter> storage::DBIter<'iter>, H: 'static + StorageHasher, diff --git a/tests/src/e2e/ledger_tests.rs b/tests/src/e2e/ledger_tests.rs index d4c910807c..21183772d7 100644 --- a/tests/src/e2e/ledger_tests.rs +++ b/tests/src/e2e/ledger_tests.rs @@ -494,7 +494,7 @@ fn ledger_txs_and_queries() -> Result<()> { ]; for tx_args in &txs_args { - for &dry_run in &[true, false] { + for &dry_run in &[false, true] { let tx_args = if dry_run { vec![tx_args.clone(), vec!["--dry-run"]].concat() } else { diff --git a/tests/src/lib.rs b/tests/src/lib.rs index db37039878..f630ba9709 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -7,14 +7,14 @@ pub use namada; -mod vm_host_env; -pub use vm_host_env::{ibc, tx, vp}; +// mod vm_host_env; +// pub use vm_host_env::{ibc, tx, vp}; #[cfg(test)] mod e2e; -pub mod native_vp; +// pub mod native_vp; pub mod storage; -#[cfg(test)] -mod storage_api; +// #[cfg(test)] +// mod storage_api; /// Using this import requires `tracing` and `tracing-subscriber` dependencies. /// Set env var `RUST_LOG=info` to see the logs from a test run (and diff --git a/tests/src/vm_host_env/tx.rs b/tests/src/vm_host_env/tx.rs index c9ab18a08a..5fa2ee7532 100644 --- a/tests/src/vm_host_env/tx.rs +++ b/tests/src/vm_host_env/tx.rs @@ -354,7 +354,9 @@ mod native_tx_host_env { // Call the `host_env` function and unwrap any // runtime errors - $fn( &tx_env, $($arg),* ).unwrap() + // TODO: this is fucked + // $fn( &tx_env, $($arg),* ).unwrap() + $fn( todo!(), $($arg),* ).unwrap() }) } }); @@ -394,7 +396,9 @@ mod native_tx_host_env { // Call the `host_env` function and unwrap any // runtime errors - $fn( &tx_env, $($arg),* ).unwrap() + // TODO: this is fucked + // $fn( &tx_env, $($arg),* ).unwrap() + $fn( todo!(), $($arg),* ).unwrap() }) } }); diff --git a/tests/src/vm_host_env/vp.rs b/tests/src/vm_host_env/vp.rs index afad40a69d..47a6467c75 100644 --- a/tests/src/vm_host_env/vp.rs +++ b/tests/src/vm_host_env/vp.rs @@ -290,7 +290,9 @@ mod native_vp_host_env { // Call the `host_env` function and unwrap any // runtime errors - $fn( &env, $($arg),* ).unwrap() + // TODO: this is fucked + // $fn( &env, $($arg),* ).unwrap() + $fn( todo!(), $($arg),* ).unwrap() }) } }); @@ -337,7 +339,9 @@ mod native_vp_host_env { // Call the `host_env` function and unwrap any // runtime errors - $fn( &env, $($arg),* ).unwrap() + // TODO: this is fucked + // $fn( &env, $($arg),* ).unwrap() + $fn( todo!(), $($arg),* ).unwrap() }) } }); diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index fc4bcac1a3..57f3472c82 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -432,7 +432,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "miniz_oxide", - "object 0.30.3", + "object", "rustc-demangle", ] @@ -1067,6 +1067,19 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +[[package]] +name = "corosensei" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9847f90f32a50b0dcbd68bc23ff242798b13080b97b0569f6ed96a45ce4cf2cd" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "libc", + "scopeguard", + "windows-sys 0.33.0", +] + [[package]] name = "cpufeatures" version = "0.2.7" @@ -1078,57 +1091,74 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e6bea67967505247f54fa2c85cf4f6e0e31c4e5692c9b70e4ae58e339067333" +checksum = "2a2ab4512dfd3a6f4be184403a195f76e81a8a9f9e6c898e19d2dc3ce20e0115" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48194035d2752bdd5bdae429e3ab88676e95f52a2b1355a5d4e809f9e39b1d74" +checksum = "98b022ed2a5913a38839dfbafe6cf135342661293b08049843362df4301261dc" dependencies = [ + "arrayvec 0.7.2", + "bumpalo", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", + "cranelift-egraph", "cranelift-entity", - "gimli 0.25.0", + "cranelift-isle", + "gimli 0.26.2", "log", - "regalloc", + "regalloc2", "smallvec", "target-lexicon", ] [[package]] name = "cranelift-codegen-meta" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976efb22fcab4f2cd6bd4e9913764616a54d895c1a23530128d04e03633c555f" +checksum = "639307b45434ad112a98f8300c0f0ab085cbefcd767efcdef9ef19d4c0756e74" dependencies = [ "cranelift-codegen-shared", - "cranelift-entity", ] [[package]] name = "cranelift-codegen-shared" -version = "0.76.0" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "278e52e29c53fcf32431ef08406c295699a70306d05a0715c5b1bf50e33a9ab7" + +[[package]] +name = "cranelift-egraph" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dabb5fe66e04d4652e434195b45ae65b5c8172d520247b8f66d8df42b2b45dc" +checksum = "624b54323b06e675293939311943ba82d323bb340468ce1889be5da7932c8d73" +dependencies = [ + "cranelift-entity", + "fxhash", + "hashbrown 0.12.3", + "indexmap", + "log", + "smallvec", +] [[package]] name = "cranelift-entity" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3329733e4d4b8e91c809efcaa4faee80bf66f20164e3dd16d707346bd3494799" +checksum = "9a59bcbca89c3f1b70b93ab3cbba5e5e0cbf3e63dadb23c7525cb142e21a9d4c" [[package]] name = "cranelift-frontend" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "279afcc0d3e651b773f94837c3d581177b348c8d69e928104b2e9fccb226f921" +checksum = "0d70abacb8cfef3dc8ff7e8836e9c1d70f7967dfdac824a4cd5e30223415aca6" dependencies = [ "cranelift-codegen", "log", @@ -1137,13 +1167,10 @@ dependencies = [ ] [[package]] -name = "crc32fast" -version = "1.3.2" +name = "cranelift-isle" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if 1.0.0", -] +checksum = "393bc73c451830ff8dbb3a07f61843d6cb41a084f9996319917c0b291ed785bb" [[package]] name = "crossbeam-channel" @@ -1185,7 +1212,7 @@ dependencies = [ "autocfg", "cfg-if 1.0.0", "crossbeam-utils 0.8.15", - "memoffset 0.8.0", + "memoffset", "scopeguard", ] @@ -1352,6 +1379,19 @@ dependencies = [ "syn 2.0.15", ] +[[package]] +name = "dashmap" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" +dependencies = [ + "cfg-if 1.0.0", + "hashbrown 0.12.3", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "data-encoding" version = "2.3.3" @@ -1959,6 +1999,15 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "generic-array" version = "0.12.4" @@ -2006,9 +2055,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.25.0" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" dependencies = [ "fallible-iterator", "indexmap", @@ -2668,7 +2717,6 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", - "serde", ] [[package]] @@ -2789,16 +2837,6 @@ version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" -[[package]] -name = "libloading" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" -dependencies = [ - "cfg-if 1.0.0", - "winapi", -] - [[package]] name = "libm" version = "0.2.6" @@ -2891,27 +2929,6 @@ dependencies = [ "value-bag", ] -[[package]] -name = "loupe" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6a72dfa44fe15b5e76b94307eeb2ff995a8c5b283b55008940c02e0c5b634d" -dependencies = [ - "indexmap", - "loupe-derive", - "rustversion", -] - -[[package]] -name = "loupe-derive" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0fbfc88337168279f2e9ae06e157cfed4efd3316e14dc96ed074d4f2e6c5952" -dependencies = [ - "quote", - "syn 1.0.109", -] - [[package]] name = "mach" version = "0.3.2" @@ -3030,15 +3047,6 @@ dependencies = [ "libc", ] -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - [[package]] name = "memoffset" version = "0.8.0" @@ -3164,7 +3172,6 @@ dependencies = [ "ibc", "ibc-proto 0.26.0", "itertools", - "loupe", "masp_primitives", "masp_proofs", "namada_core", @@ -3198,8 +3205,6 @@ dependencies = [ "wasmer", "wasmer-cache", "wasmer-compiler-singlepass", - "wasmer-engine-dylib", - "wasmer-engine-universal", "wasmer-vm", "wasmparser 0.83.0", "zeroize", @@ -3481,18 +3486,6 @@ dependencies = [ "libc", ] -[[package]] -name = "object" -version = "0.28.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" -dependencies = [ - "crc32fast", - "hashbrown 0.11.2", - "indexmap", - "memchr", -] - [[package]] name = "object" version = "0.30.3" @@ -4171,13 +4164,14 @@ dependencies = [ ] [[package]] -name = "regalloc" -version = "0.0.31" +name = "regalloc2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571f7f397d61c4755285cd37853fe8e03271c243424a907415909379659381c5" +checksum = "300d4fbfb40c1c66a78ba3ddd41c1110247cf52f97b87d0f2fc9209bd49b030c" dependencies = [ + "fxhash", "log", - "rustc-hash", + "slice-group-by", "smallvec", ] @@ -4294,6 +4288,7 @@ checksum = "21499ed91807f07ae081880aabb2ccc0235e9d88011867d984525e9a4c3cfa3e" dependencies = [ "bytecheck", "hashbrown 0.12.3", + "indexmap", "ptr_meta", "rend", "rkyv_derive", @@ -4664,6 +4659,17 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_bytes" version = "0.11.9" @@ -4848,6 +4854,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + [[package]] name = "slip10_ed25519" version = "0.1.3" @@ -5628,7 +5640,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if 1.0.0", - "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -5948,6 +5959,29 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-downcast" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dac026d43bcca6e7ce1c0956ba68f59edf6403e8e930a5d891be72c31a44340" +dependencies = [ + "js-sys", + "once_cell", + "wasm-bindgen", + "wasm-bindgen-downcast-macros", +] + +[[package]] +name = "wasm-bindgen-downcast-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5020cfa87c7cecefef118055d44e3c1fc122c7ec25701d528ee458a0b45f38f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "wasm-bindgen-futures" version = "0.4.35" @@ -6000,24 +6034,26 @@ dependencies = [ [[package]] name = "wasmer" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfc7dff846db3f38f8ed0be4a009fdfeb729cf1f94a2c7fb6ff2fec01cefa110" +checksum = "78caedecd8cb71ed47ccca03b68d69414a3d278bb031e6f93f15759344efdd52" dependencies = [ + "bytes", "cfg-if 1.0.0", + "derivative", "indexmap", "js-sys", - "loupe", "more-asserts", + "rustc-demangle", + "serde", + "serde-wasm-bindgen", "target-lexicon", "thiserror", "wasm-bindgen", + "wasm-bindgen-downcast", "wasmer-compiler", "wasmer-compiler-cranelift", "wasmer-derive", - "wasmer-engine", - "wasmer-engine-dylib", - "wasmer-engine-universal", "wasmer-types", "wasmer-vm", "wat", @@ -6026,9 +6062,9 @@ dependencies = [ [[package]] name = "wasmer-cache" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "834a0de78bf30b9bce61c4c236344b9d8f2f4a3b7713f8de8a8274fbc2d4e9d5" +checksum = "7f0de969b05cc3c11196beeb46e5868a3712a187d777ee94113f7258c2ec121c" dependencies = [ "blake3", "hex", @@ -6038,34 +6074,37 @@ dependencies = [ [[package]] name = "wasmer-compiler" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c91abf22b16dad3826ec0d0e3ec0a8304262a6c7a14e16528c536131b80e63d" +checksum = "726a8450541af4a57c34af7b6973fdbfc79f896cc7e733429577dfd1d1687180" dependencies = [ + "backtrace", + "cfg-if 1.0.0", + "enum-iterator", "enumset", - "loupe", - "rkyv", - "serde", - "serde_bytes", + "lazy_static", + "leb128", + "memmap2", + "more-asserts", + "region", "smallvec", - "target-lexicon", "thiserror", "wasmer-types", "wasmer-vm", - "wasmparser 0.78.2", + "wasmparser 0.95.0", + "winapi", ] [[package]] name = "wasmer-compiler-cranelift" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7624a1f496b163139a7e0b442426cad805bec70486900287506f9d15a29323ab" +checksum = "a1e5633f90f372563ebbdf3f9799c7b29ba11c90e56cf9b54017112d2e656c95" dependencies = [ "cranelift-codegen", "cranelift-entity", "cranelift-frontend", - "gimli 0.25.0", - "loupe", + "gimli 0.26.2", "more-asserts", "rayon", "smallvec", @@ -6073,33 +6112,32 @@ dependencies = [ "tracing", "wasmer-compiler", "wasmer-types", - "wasmer-vm", ] [[package]] name = "wasmer-compiler-singlepass" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b63c1538ffb4b0e09edaebfcac35c34141d5944c52f77d137cbe0b634bd40fa" +checksum = "d4d38957de6f452115c0af3ff08cec268ee248d665b54d4bbf7da60b7453cb97" dependencies = [ "byteorder", "dynasm", "dynasmrt", + "enumset", + "gimli 0.26.2", "lazy_static", - "loupe", "more-asserts", "rayon", "smallvec", "wasmer-compiler", "wasmer-types", - "wasmer-vm", ] [[package]] name = "wasmer-derive" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "933b23b5cee0f58aa6c17c6de7e1f3007279357e0d555f22e24d6b395cfe7f89" +checksum = "97901fdbaae383dbb90ea162cc3a76a9fa58ac39aec7948b4c0b9bbef9307738" dependencies = [ "proc-macro-error", "proc-macro2", @@ -6108,115 +6146,43 @@ dependencies = [ ] [[package]] -name = "wasmer-engine" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41db0ac4df90610cda8320cfd5abf90c6ec90e298b6fe5a09a81dff718b55640" -dependencies = [ - "backtrace", - "enumset", - "lazy_static", - "loupe", - "memmap2", - "more-asserts", - "rustc-demangle", - "serde", - "serde_bytes", - "target-lexicon", - "thiserror", - "wasmer-compiler", - "wasmer-types", - "wasmer-vm", -] - -[[package]] -name = "wasmer-engine-dylib" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "591683f3356ac31cc88aaecaf77ac2cc9f456014348b01af46c164f44f531162" -dependencies = [ - "cfg-if 1.0.0", - "enum-iterator", - "enumset", - "leb128", - "libloading", - "loupe", - "object 0.28.4", - "rkyv", - "serde", - "tempfile", - "tracing", - "wasmer-compiler", - "wasmer-engine", - "wasmer-object", - "wasmer-types", - "wasmer-vm", - "which", -] - -[[package]] -name = "wasmer-engine-universal" -version = "2.2.0" +name = "wasmer-types" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dccfde103e9b87427099a6de344b7c791574f307d035c8c7dbbc00974c1af0c1" +checksum = "67f1f2839f4f61509550e4ddcd0e658e19f3af862b51c79fda15549d735d659b" dependencies = [ - "cfg-if 1.0.0", + "bytecheck", "enum-iterator", "enumset", - "leb128", - "loupe", - "region", - "rkyv", - "wasmer-compiler", - "wasmer-engine", - "wasmer-types", - "wasmer-vm", - "winapi", -] - -[[package]] -name = "wasmer-object" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0c4005592998bd840f2289102ef9c67b6138338ed78e1fc0809586aa229040" -dependencies = [ - "object 0.28.4", - "thiserror", - "wasmer-compiler", - "wasmer-types", -] - -[[package]] -name = "wasmer-types" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4deb854f178265a76b59823c41547d259c65da3687b606b0b9c12d80ab950e3e" -dependencies = [ "indexmap", - "loupe", + "more-asserts", "rkyv", - "serde", + "target-lexicon", "thiserror", ] [[package]] name = "wasmer-vm" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dbc5c989cb14a102433927e630473da52f83d82c469acd5cfa8fc7efacc1e70" +checksum = "043118ec4f16d1714fed3aab758b502b864bd865e1d5188626c9ad290100563f" dependencies = [ "backtrace", "cc", "cfg-if 1.0.0", + "corosensei", + "dashmap", + "derivative", "enum-iterator", + "fnv", "indexmap", + "lazy_static", "libc", - "loupe", - "memoffset 0.6.5", + "mach", + "memoffset", "more-asserts", "region", - "rkyv", - "serde", + "scopeguard", "thiserror", "wasmer-types", "winapi", @@ -6224,15 +6190,19 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.78.2" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52144d4c78e5cf8b055ceab8e5fa22814ce4315d6002ad32cfd914f37c12fd65" +checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" [[package]] name = "wasmparser" -version = "0.83.0" +version = "0.95.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" +checksum = "f2ea896273ea99b15132414be1da01ab0d8836415083298ecaffbe308eaac87a" +dependencies = [ + "indexmap", + "url", +] [[package]] name = "wast" @@ -6357,6 +6327,19 @@ dependencies = [ "windows-targets 0.48.0", ] +[[package]] +name = "windows-sys" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43dbb096663629518eb1dfa72d80243ca5a6aca764cae62a2df70af760a9be75" +dependencies = [ + "windows_aarch64_msvc 0.33.0", + "windows_i686_gnu 0.33.0", + "windows_i686_msvc 0.33.0", + "windows_x86_64_gnu 0.33.0", + "windows_x86_64_msvc 0.33.0", +] + [[package]] name = "windows-sys" version = "0.42.0" @@ -6432,6 +6415,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd761fd3eb9ab8cc1ed81e56e567f02dd82c4c837e48ac3b2181b9ffc5060807" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -6444,6 +6433,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +[[package]] +name = "windows_i686_gnu" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab0cf703a96bab2dc0c02c0fa748491294bf9b7feb27e1f4f96340f208ada0e" + [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -6456,6 +6451,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +[[package]] +name = "windows_i686_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cfdbe89cc9ad7ce618ba34abc34bbb6c36d99e96cae2245b7943cd75ee773d0" + [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -6468,6 +6469,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +[[package]] +name = "windows_x86_64_gnu" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4dd9b0c0e9ece7bb22e84d70d01b71c6d6248b81a3c60d11869451b4cb24784" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -6492,6 +6499,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +[[package]] +name = "windows_x86_64_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff1e4aa646495048ec7f3ffddc411e1d829c026a2ec62b39da15c1055e406eaa" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index 7694d50eac..bbcd9acf53 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -432,7 +432,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "miniz_oxide", - "object 0.30.3", + "object", "rustc-demangle", ] @@ -1067,6 +1067,19 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +[[package]] +name = "corosensei" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9847f90f32a50b0dcbd68bc23ff242798b13080b97b0569f6ed96a45ce4cf2cd" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "libc", + "scopeguard", + "windows-sys 0.33.0", +] + [[package]] name = "cpufeatures" version = "0.2.7" @@ -1078,57 +1091,74 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e6bea67967505247f54fa2c85cf4f6e0e31c4e5692c9b70e4ae58e339067333" +checksum = "2a2ab4512dfd3a6f4be184403a195f76e81a8a9f9e6c898e19d2dc3ce20e0115" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48194035d2752bdd5bdae429e3ab88676e95f52a2b1355a5d4e809f9e39b1d74" +checksum = "98b022ed2a5913a38839dfbafe6cf135342661293b08049843362df4301261dc" dependencies = [ + "arrayvec 0.7.2", + "bumpalo", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", + "cranelift-egraph", "cranelift-entity", - "gimli 0.25.0", + "cranelift-isle", + "gimli 0.26.2", "log", - "regalloc", + "regalloc2", "smallvec", "target-lexicon", ] [[package]] name = "cranelift-codegen-meta" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976efb22fcab4f2cd6bd4e9913764616a54d895c1a23530128d04e03633c555f" +checksum = "639307b45434ad112a98f8300c0f0ab085cbefcd767efcdef9ef19d4c0756e74" dependencies = [ "cranelift-codegen-shared", - "cranelift-entity", ] [[package]] name = "cranelift-codegen-shared" -version = "0.76.0" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "278e52e29c53fcf32431ef08406c295699a70306d05a0715c5b1bf50e33a9ab7" + +[[package]] +name = "cranelift-egraph" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dabb5fe66e04d4652e434195b45ae65b5c8172d520247b8f66d8df42b2b45dc" +checksum = "624b54323b06e675293939311943ba82d323bb340468ce1889be5da7932c8d73" +dependencies = [ + "cranelift-entity", + "fxhash", + "hashbrown 0.12.3", + "indexmap", + "log", + "smallvec", +] [[package]] name = "cranelift-entity" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3329733e4d4b8e91c809efcaa4faee80bf66f20164e3dd16d707346bd3494799" +checksum = "9a59bcbca89c3f1b70b93ab3cbba5e5e0cbf3e63dadb23c7525cb142e21a9d4c" [[package]] name = "cranelift-frontend" -version = "0.76.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "279afcc0d3e651b773f94837c3d581177b348c8d69e928104b2e9fccb226f921" +checksum = "0d70abacb8cfef3dc8ff7e8836e9c1d70f7967dfdac824a4cd5e30223415aca6" dependencies = [ "cranelift-codegen", "log", @@ -1137,13 +1167,10 @@ dependencies = [ ] [[package]] -name = "crc32fast" -version = "1.3.2" +name = "cranelift-isle" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if 1.0.0", -] +checksum = "393bc73c451830ff8dbb3a07f61843d6cb41a084f9996319917c0b291ed785bb" [[package]] name = "crossbeam-channel" @@ -1185,7 +1212,7 @@ dependencies = [ "autocfg", "cfg-if 1.0.0", "crossbeam-utils 0.8.15", - "memoffset 0.8.0", + "memoffset", "scopeguard", ] @@ -1352,6 +1379,19 @@ dependencies = [ "syn 2.0.15", ] +[[package]] +name = "dashmap" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" +dependencies = [ + "cfg-if 1.0.0", + "hashbrown 0.12.3", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "data-encoding" version = "2.3.3" @@ -1959,6 +1999,15 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "generic-array" version = "0.12.4" @@ -2006,9 +2055,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.25.0" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" dependencies = [ "fallible-iterator", "indexmap", @@ -2668,7 +2717,6 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", - "serde", ] [[package]] @@ -2789,16 +2837,6 @@ version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" -[[package]] -name = "libloading" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" -dependencies = [ - "cfg-if 1.0.0", - "winapi", -] - [[package]] name = "libm" version = "0.2.6" @@ -2891,27 +2929,6 @@ dependencies = [ "value-bag", ] -[[package]] -name = "loupe" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6a72dfa44fe15b5e76b94307eeb2ff995a8c5b283b55008940c02e0c5b634d" -dependencies = [ - "indexmap", - "loupe-derive", - "rustversion", -] - -[[package]] -name = "loupe-derive" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0fbfc88337168279f2e9ae06e157cfed4efd3316e14dc96ed074d4f2e6c5952" -dependencies = [ - "quote", - "syn 1.0.109", -] - [[package]] name = "mach" version = "0.3.2" @@ -3030,15 +3047,6 @@ dependencies = [ "libc", ] -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - [[package]] name = "memoffset" version = "0.8.0" @@ -3164,7 +3172,6 @@ dependencies = [ "ibc", "ibc-proto 0.26.0", "itertools", - "loupe", "masp_primitives", "masp_proofs", "namada_core", @@ -3198,8 +3205,6 @@ dependencies = [ "wasmer", "wasmer-cache", "wasmer-compiler-singlepass", - "wasmer-engine-dylib", - "wasmer-engine-universal", "wasmer-vm", "wasmparser 0.83.0", "zeroize", @@ -3473,18 +3478,6 @@ dependencies = [ "libc", ] -[[package]] -name = "object" -version = "0.28.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" -dependencies = [ - "crc32fast", - "hashbrown 0.11.2", - "indexmap", - "memchr", -] - [[package]] name = "object" version = "0.30.3" @@ -4163,13 +4156,14 @@ dependencies = [ ] [[package]] -name = "regalloc" -version = "0.0.31" +name = "regalloc2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571f7f397d61c4755285cd37853fe8e03271c243424a907415909379659381c5" +checksum = "300d4fbfb40c1c66a78ba3ddd41c1110247cf52f97b87d0f2fc9209bd49b030c" dependencies = [ + "fxhash", "log", - "rustc-hash", + "slice-group-by", "smallvec", ] @@ -4286,6 +4280,7 @@ checksum = "21499ed91807f07ae081880aabb2ccc0235e9d88011867d984525e9a4c3cfa3e" dependencies = [ "bytecheck", "hashbrown 0.12.3", + "indexmap", "ptr_meta", "rend", "rkyv_derive", @@ -4656,6 +4651,17 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_bytes" version = "0.11.9" @@ -4840,6 +4846,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + [[package]] name = "slip10_ed25519" version = "0.1.3" @@ -5620,7 +5632,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if 1.0.0", - "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -5918,6 +5929,29 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-downcast" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dac026d43bcca6e7ce1c0956ba68f59edf6403e8e930a5d891be72c31a44340" +dependencies = [ + "js-sys", + "once_cell", + "wasm-bindgen", + "wasm-bindgen-downcast-macros", +] + +[[package]] +name = "wasm-bindgen-downcast-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5020cfa87c7cecefef118055d44e3c1fc122c7ec25701d528ee458a0b45f38f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "wasm-bindgen-futures" version = "0.4.35" @@ -5970,24 +6004,26 @@ dependencies = [ [[package]] name = "wasmer" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfc7dff846db3f38f8ed0be4a009fdfeb729cf1f94a2c7fb6ff2fec01cefa110" +checksum = "78caedecd8cb71ed47ccca03b68d69414a3d278bb031e6f93f15759344efdd52" dependencies = [ + "bytes", "cfg-if 1.0.0", + "derivative", "indexmap", "js-sys", - "loupe", "more-asserts", + "rustc-demangle", + "serde", + "serde-wasm-bindgen", "target-lexicon", "thiserror", "wasm-bindgen", + "wasm-bindgen-downcast", "wasmer-compiler", "wasmer-compiler-cranelift", "wasmer-derive", - "wasmer-engine", - "wasmer-engine-dylib", - "wasmer-engine-universal", "wasmer-types", "wasmer-vm", "wat", @@ -5996,9 +6032,9 @@ dependencies = [ [[package]] name = "wasmer-cache" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "834a0de78bf30b9bce61c4c236344b9d8f2f4a3b7713f8de8a8274fbc2d4e9d5" +checksum = "7f0de969b05cc3c11196beeb46e5868a3712a187d777ee94113f7258c2ec121c" dependencies = [ "blake3", "hex", @@ -6008,34 +6044,37 @@ dependencies = [ [[package]] name = "wasmer-compiler" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c91abf22b16dad3826ec0d0e3ec0a8304262a6c7a14e16528c536131b80e63d" +checksum = "726a8450541af4a57c34af7b6973fdbfc79f896cc7e733429577dfd1d1687180" dependencies = [ + "backtrace", + "cfg-if 1.0.0", + "enum-iterator", "enumset", - "loupe", - "rkyv", - "serde", - "serde_bytes", + "lazy_static", + "leb128", + "memmap2", + "more-asserts", + "region", "smallvec", - "target-lexicon", "thiserror", "wasmer-types", "wasmer-vm", - "wasmparser 0.78.2", + "wasmparser 0.95.0", + "winapi", ] [[package]] name = "wasmer-compiler-cranelift" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7624a1f496b163139a7e0b442426cad805bec70486900287506f9d15a29323ab" +checksum = "a1e5633f90f372563ebbdf3f9799c7b29ba11c90e56cf9b54017112d2e656c95" dependencies = [ "cranelift-codegen", "cranelift-entity", "cranelift-frontend", - "gimli 0.25.0", - "loupe", + "gimli 0.26.2", "more-asserts", "rayon", "smallvec", @@ -6043,33 +6082,32 @@ dependencies = [ "tracing", "wasmer-compiler", "wasmer-types", - "wasmer-vm", ] [[package]] name = "wasmer-compiler-singlepass" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b63c1538ffb4b0e09edaebfcac35c34141d5944c52f77d137cbe0b634bd40fa" +checksum = "d4d38957de6f452115c0af3ff08cec268ee248d665b54d4bbf7da60b7453cb97" dependencies = [ "byteorder", "dynasm", "dynasmrt", + "enumset", + "gimli 0.26.2", "lazy_static", - "loupe", "more-asserts", "rayon", "smallvec", "wasmer-compiler", "wasmer-types", - "wasmer-vm", ] [[package]] name = "wasmer-derive" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "933b23b5cee0f58aa6c17c6de7e1f3007279357e0d555f22e24d6b395cfe7f89" +checksum = "97901fdbaae383dbb90ea162cc3a76a9fa58ac39aec7948b4c0b9bbef9307738" dependencies = [ "proc-macro-error", "proc-macro2", @@ -6078,115 +6116,43 @@ dependencies = [ ] [[package]] -name = "wasmer-engine" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41db0ac4df90610cda8320cfd5abf90c6ec90e298b6fe5a09a81dff718b55640" -dependencies = [ - "backtrace", - "enumset", - "lazy_static", - "loupe", - "memmap2", - "more-asserts", - "rustc-demangle", - "serde", - "serde_bytes", - "target-lexicon", - "thiserror", - "wasmer-compiler", - "wasmer-types", - "wasmer-vm", -] - -[[package]] -name = "wasmer-engine-dylib" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "591683f3356ac31cc88aaecaf77ac2cc9f456014348b01af46c164f44f531162" -dependencies = [ - "cfg-if 1.0.0", - "enum-iterator", - "enumset", - "leb128", - "libloading", - "loupe", - "object 0.28.4", - "rkyv", - "serde", - "tempfile", - "tracing", - "wasmer-compiler", - "wasmer-engine", - "wasmer-object", - "wasmer-types", - "wasmer-vm", - "which", -] - -[[package]] -name = "wasmer-engine-universal" -version = "2.2.0" +name = "wasmer-types" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dccfde103e9b87427099a6de344b7c791574f307d035c8c7dbbc00974c1af0c1" +checksum = "67f1f2839f4f61509550e4ddcd0e658e19f3af862b51c79fda15549d735d659b" dependencies = [ - "cfg-if 1.0.0", + "bytecheck", "enum-iterator", "enumset", - "leb128", - "loupe", - "region", - "rkyv", - "wasmer-compiler", - "wasmer-engine", - "wasmer-types", - "wasmer-vm", - "winapi", -] - -[[package]] -name = "wasmer-object" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0c4005592998bd840f2289102ef9c67b6138338ed78e1fc0809586aa229040" -dependencies = [ - "object 0.28.4", - "thiserror", - "wasmer-compiler", - "wasmer-types", -] - -[[package]] -name = "wasmer-types" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4deb854f178265a76b59823c41547d259c65da3687b606b0b9c12d80ab950e3e" -dependencies = [ "indexmap", - "loupe", + "more-asserts", "rkyv", - "serde", + "target-lexicon", "thiserror", ] [[package]] name = "wasmer-vm" -version = "2.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dbc5c989cb14a102433927e630473da52f83d82c469acd5cfa8fc7efacc1e70" +checksum = "043118ec4f16d1714fed3aab758b502b864bd865e1d5188626c9ad290100563f" dependencies = [ "backtrace", "cc", "cfg-if 1.0.0", + "corosensei", + "dashmap", + "derivative", "enum-iterator", + "fnv", "indexmap", + "lazy_static", "libc", - "loupe", - "memoffset 0.6.5", + "mach", + "memoffset", "more-asserts", "region", - "rkyv", - "serde", + "scopeguard", "thiserror", "wasmer-types", "winapi", @@ -6194,15 +6160,19 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.78.2" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52144d4c78e5cf8b055ceab8e5fa22814ce4315d6002ad32cfd914f37c12fd65" +checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" [[package]] name = "wasmparser" -version = "0.83.0" +version = "0.95.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" +checksum = "f2ea896273ea99b15132414be1da01ab0d8836415083298ecaffbe308eaac87a" +dependencies = [ + "indexmap", + "url", +] [[package]] name = "wast" @@ -6327,6 +6297,19 @@ dependencies = [ "windows-targets 0.48.0", ] +[[package]] +name = "windows-sys" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43dbb096663629518eb1dfa72d80243ca5a6aca764cae62a2df70af760a9be75" +dependencies = [ + "windows_aarch64_msvc 0.33.0", + "windows_i686_gnu 0.33.0", + "windows_i686_msvc 0.33.0", + "windows_x86_64_gnu 0.33.0", + "windows_x86_64_msvc 0.33.0", +] + [[package]] name = "windows-sys" version = "0.42.0" @@ -6402,6 +6385,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd761fd3eb9ab8cc1ed81e56e567f02dd82c4c837e48ac3b2181b9ffc5060807" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -6414,6 +6403,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +[[package]] +name = "windows_i686_gnu" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab0cf703a96bab2dc0c02c0fa748491294bf9b7feb27e1f4f96340f208ada0e" + [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -6426,6 +6421,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +[[package]] +name = "windows_i686_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cfdbe89cc9ad7ce618ba34abc34bbb6c36d99e96cae2245b7943cd75ee773d0" + [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -6438,6 +6439,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +[[package]] +name = "windows_x86_64_gnu" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4dd9b0c0e9ece7bb22e84d70d01b71c6d6248b81a3c60d11869451b4cb24784" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -6462,6 +6469,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +[[package]] +name = "windows_x86_64_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff1e4aa646495048ec7f3ffddc411e1d829c026a2ec62b39da15c1055e406eaa" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2"