From ce779c0b0595ad63a61859007a344faa3a58ea78 Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Thu, 2 Feb 2023 07:39:17 +0200 Subject: [PATCH 1/6] Update for refactored fuel-asm Tracks https://github.com/FuelLabs/fuel-vm/pull/283 --- Cargo.lock | 224 ++++++++++-------- Cargo.toml | 4 + benches/benches/set/alu.rs | 154 ++++++------ benches/benches/set/blockchain.rs | 174 +++++++------- benches/benches/set/crypto.rs | 34 +-- benches/benches/set/flow.rs | 34 +-- benches/benches/set/mem.rs | 64 ++--- benches/benches/vm.rs | 11 +- benches/src/lib.rs | 62 +++-- crates/chain-config/src/config.rs | 5 +- crates/client/src/client.rs | 4 +- crates/fuel-core/src/executor.rs | 82 ++++--- crates/fuel-core/src/schema/dap.rs | 6 +- crates/fuel-core/src/service/genesis.rs | 6 +- crates/services/txpool/src/test_helpers.rs | 4 +- .../txpool/src/transaction_selector.rs | 4 +- .../txpool/src/txpool/test_helpers.rs | 4 +- tests/tests/contract.rs | 44 ++-- tests/tests/dap.rs | 10 +- tests/tests/messages.rs | 26 +- tests/tests/metrics.rs | 8 +- tests/tests/relayer.rs | 2 +- tests/tests/sync/helpers.rs | 4 +- tests/tests/trigger_integration/hybrid.rs | 2 +- tests/tests/trigger_integration/instant.rs | 2 +- tests/tests/trigger_integration/interval.rs | 2 +- tests/tests/trigger_integration/never.rs | 5 +- tests/tests/tx.rs | 26 +- tests/tests/tx/predicates.rs | 4 +- tests/tests/tx/txn_status_subscription.rs | 6 +- tests/tests/tx/utxo_validation.rs | 10 +- 31 files changed, 520 insertions(+), 507 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f4ed12c309..efa5a674f52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -355,7 +355,7 @@ dependencies = [ "slab", "socket2", "waker-fn", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -391,9 +391,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.63" +version = "0.1.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eff18d764974428cf3a9328e23fc5c986f5fbed46e6cd4cdf42544df5d297ec1" +checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" dependencies = [ "proc-macro2", "quote", @@ -749,9 +749,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" dependencies = [ "serde", ] @@ -787,9 +787,9 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.15.2" +version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982a0cf6a99c350d7246035613882e376d58cebe571785abc5da4f648d53ac0a" +checksum = "08a1ec454bc3eead8719cb56e15dbbfecdbc14e4b3a3ae4936cc6e31f5fc0d07" dependencies = [ "camino", "cargo-platform", @@ -807,9 +807,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" dependencies = [ "jobserver", ] @@ -1093,7 +1093,7 @@ dependencies = [ "encode_unicode", "lazy_static", "libc", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1168,9 +1168,9 @@ checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" [[package]] name = "crc" -version = "3.0.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53757d12b596c16c78b83458d732a5d1a17ab3f53f2f7412f6fb57cc8a140ab3" +checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" dependencies = [ "crc-catalog", ] @@ -1386,7 +1386,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1631ca6e3c59112501a9d87fd86f21591ff77acd31331e8a73f8d80a65bbdd71" dependencies = [ "nix 0.26.2", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1404,9 +1404,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0-pre.5" +version = "4.0.0-rc.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67bc65846be335cb20f4e52d49a437b773a2c1fdb42b19fc84e79e6f6771536f" +checksum = "8da00a7a9a4eb92a0a0f8e75660926d48f0d0f3c537e455c457bcdaa1e16b1ac" dependencies = [ "cfg-if", "fiat-crypto", @@ -1801,9 +1801,9 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "encoding_rs" -version = "0.8.31" +version = "0.8.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" dependencies = [ "cfg-if", ] @@ -2276,8 +2276,7 @@ checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" [[package]] name = "fuel-asm" version = "0.25.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f56306747294a7ec2da07e9be050783cf6adbfd3d73bf820a66bde16336a309" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" dependencies = [ "fuel-types", "serde", @@ -2332,7 +2331,7 @@ dependencies = [ "tokio-stream", "tower-http", "tracing", - "uuid 1.2.2", + "uuid 1.3.0", ] [[package]] @@ -2717,8 +2716,7 @@ dependencies = [ [[package]] name = "fuel-crypto" version = "0.25.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eedf87b364293690782968202c247fd08470e3e17d2e2f42489b46d3f5c966e7" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" dependencies = [ "borrown", "coins-bip32", @@ -2736,8 +2734,7 @@ dependencies = [ [[package]] name = "fuel-merkle" version = "0.25.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9878202ea2f874de70e66b0349af8b1ad8300dcd2dec216920bb44850c5000ba" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" dependencies = [ "digest 0.10.6", "fuel-storage", @@ -2750,14 +2747,12 @@ dependencies = [ [[package]] name = "fuel-storage" version = "0.25.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d076e82c7c5d1d15cd983f744edd0bcb2552fab3428bde403c32fca07884212" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" [[package]] name = "fuel-tx" version = "0.25.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f692bcc2f6bfaf2cdadef553462fb23936865af5c646acf3fedfd6e0c136df3d" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" dependencies = [ "derivative", "fuel-asm", @@ -2774,8 +2769,7 @@ dependencies = [ [[package]] name = "fuel-types" version = "0.25.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7910fa716d6092210481a386ad29eeb6193fd911f0c6785af3c8b033817b05b" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" dependencies = [ "rand 0.8.5", "serde", @@ -2784,8 +2778,7 @@ dependencies = [ [[package]] name = "fuel-vm" version = "0.25.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0be0f72a67691df7f0929dee984eafbc47ded6b58d2c7d15dc85d4f2612e2b92" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" dependencies = [ "anyhow", "bitflags", @@ -2812,9 +2805,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" dependencies = [ "futures-channel", "futures-core", @@ -2827,9 +2820,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" dependencies = [ "futures-core", "futures-sink", @@ -2837,15 +2830,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" +checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" [[package]] name = "futures-executor" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" +checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" dependencies = [ "futures-core", "futures-task", @@ -2855,9 +2848,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" +checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" [[package]] name = "futures-lite" @@ -2886,9 +2879,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" +checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" dependencies = [ "proc-macro2", "quote", @@ -2908,15 +2901,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" +checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" [[package]] name = "futures-task" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" +checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" [[package]] name = "futures-timer" @@ -2926,9 +2919,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" +checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" dependencies = [ "futures-channel", "futures-core", @@ -3118,9 +3111,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" @@ -3504,12 +3497,12 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -3545,7 +3538,7 @@ dependencies = [ "hermit-abi 0.2.6", "io-lifetimes", "rustix", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -3574,9 +3567,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] @@ -4240,9 +4233,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.6.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +checksum = "f2e212582ede878b109755efd0773a4f0f4ec851584cf0aefbeb4d9ecc114822" dependencies = [ "adler", ] @@ -4256,7 +4249,7 @@ dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -4408,9 +4401,9 @@ dependencies = [ [[package]] name = "netlink-packet-utils" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25af9cf0dc55498b7bd94a1508af7a78706aa0ab715a73c5169273e03c84845e" +checksum = "0ede8a08c71ad5a95cdd0e4e52facd37190977039a4704eb82a283f713747d34" dependencies = [ "anyhow", "byteorder", @@ -4709,7 +4702,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.6", + "parking_lot_core 0.9.7", ] [[package]] @@ -4728,15 +4721,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.6" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -4927,7 +4920,7 @@ dependencies = [ "libc", "log", "wepoll-ffi", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -5619,7 +5612,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -5739,7 +5732,7 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" dependencies = [ - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -5862,9 +5855,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.8.1" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c4437699b6d34972de58652c68b98cb5b53a4199ab126db8e20ec8ded29a721" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ "bitflags", "core-foundation", @@ -5894,9 +5887,9 @@ dependencies = [ [[package]] name = "send_wrapper" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "930c0acf610d3fdb5e2ab6213019aaa04e227ebe9547b0649ba599b16d788bd7" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" @@ -6113,14 +6106,14 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "snow" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "774d05a3edae07ce6d68ea6984f3c05e9bba8927e3dd591e3b479e5b03213d0d" +checksum = "12ba5f4d4ff12bdb6a169ed51b7c48c0e0ac4b0b4b31012b2571e97d78d3201d" dependencies = [ "aes-gcm 0.9.4", "blake2", "chacha20poly1305", - "curve25519-dalek 4.0.0-pre.5", + "curve25519-dalek 4.0.0-rc.0", "rand_core 0.6.4", "ring", "rustc_version", @@ -6266,9 +6259,9 @@ dependencies = [ [[package]] name = "sync_wrapper" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] name = "synstructure" @@ -6478,9 +6471,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.24.2" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a12a59981d9e3c38d216785b0c37399f6e415e8d0712047620f189371b0bb" +checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ "autocfg", "bytes", @@ -6493,7 +6486,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -6877,9 +6870,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-xid" @@ -6959,9 +6952,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.2.2" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" +checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" dependencies = [ "getrandom 0.2.8", ] @@ -7040,9 +7033,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -7050,9 +7043,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", @@ -7065,9 +7058,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.33" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" dependencies = [ "cfg-if", "js-sys", @@ -7077,9 +7070,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -7087,9 +7080,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", @@ -7100,9 +7093,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "wasm-timer" @@ -7121,9 +7114,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" dependencies = [ "js-sys", "wasm-bindgen", @@ -7282,7 +7275,7 @@ dependencies = [ "tokio", "turn", "url", - "uuid 1.2.2", + "uuid 1.3.0", "waitgroup", "webrtc-mdns", "webrtc-util", @@ -7464,6 +7457,30 @@ dependencies = [ "windows_x86_64_msvc 0.42.1", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.1", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.1" @@ -7547,13 +7564,14 @@ dependencies = [ [[package]] name = "ws_stream_wasm" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47ca1ab42f5afed7fc332b22b6e932ca5414b209465412c8cdf0ad23bc0de645" +checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" dependencies = [ "async_io_stream", "futures", "js-sys", + "log", "pharos", "rustc_version", "send_wrapper", diff --git a/Cargo.toml b/Cargo.toml index 439a3acbc95..d8b29b5191b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,3 +35,7 @@ exclude = ["version-compatibility"] codegen-units = 1 lto = "fat" panic = "abort" + +[patch.crates-io.fuel-vm] +git = "https://github.com/FuelLabs/fuel-vm/" +branch = "mitchmindtree/monorepo-fuel-asm-refactor" diff --git a/benches/benches/set/alu.rs b/benches/benches/set/alu.rs index 75580a37f2e..37ff3d84d31 100644 --- a/benches/benches/set/alu.rs +++ b/benches/benches/set/alu.rs @@ -11,86 +11,86 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("add"), "add", - VmBench::new(Opcode::ADD(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::add(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("addi"), "addi", - VmBench::new(Opcode::ADDI(0x10, 0x11, 27)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::addi(0x10, 0x11, 27)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); run_group_ref( &mut c.benchmark_group("aloc"), "aloc", - VmBench::new(Opcode::ALOC(0x10)), + VmBench::new(op::aloc(0x10)), ); run_group_ref( &mut c.benchmark_group("and"), "and", - VmBench::new(Opcode::AND(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::and(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("andi"), "andi", - VmBench::new(Opcode::ANDI(0x10, 0x11, 27)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::andi(0x10, 0x11, 27)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); run_group_ref( &mut c.benchmark_group("div"), "div", - VmBench::new(Opcode::DIV(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::div(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("divi"), "divi", - VmBench::new(Opcode::DIVI(0x10, 0x11, 27)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::divi(0x10, 0x11, 27)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); run_group_ref( &mut c.benchmark_group("eq"), "eq", - VmBench::new(Opcode::EQ(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::eq(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("exp"), "exp", - VmBench::new(Opcode::EXP(0x10, 0x11, 0x12)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 23), Opcode::MOVI(0x12, 11)]), + VmBench::new(op::exp(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 23), op::movi(0x12, 11)]), ); run_group_ref( &mut c.benchmark_group("expi"), "expi", - VmBench::new(Opcode::EXP(0x10, 0x11, 11)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 23)]), + VmBench::new(op::exp(0x10, 0x11, 11)) + .with_prepare_script(vec![op::movi(0x11, 23)]), ); run_group_ref( &mut c.benchmark_group("gt"), "gt", - VmBench::new(Opcode::GT(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::gt(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); @@ -99,7 +99,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("gtf"), "gtf", - VmBench::new(Opcode::gtf(0x10, REG_ZERO, GTFArgs::ScriptData)) + VmBench::new(op::gtf_args(0x10, REG_ZERO.into(), GTFArgs::ScriptData)) .with_data(data), ); } @@ -107,165 +107,165 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("lt"), "lt", - VmBench::new(Opcode::LT(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::lt(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("mlog"), "mlog", - VmBench::new(Opcode::MLOG(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::mlog(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("mod"), "mod", - VmBench::new(Opcode::MOD(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::mod_(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("modi"), "modi", - VmBench::new(Opcode::MODI(0x10, 0x11, 27)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::modi(0x10, 0x11, 27)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); run_group_ref( &mut c.benchmark_group("move"), "move", - VmBench::new(Opcode::MOVE(0x10, 0x11)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::move_(0x10, 0x11)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); run_group_ref( &mut c.benchmark_group("movi"), "movi", - VmBench::new(Opcode::MOVI(0x10, 27)), + VmBench::new(op::movi(0x10, 27)), ); run_group_ref( &mut c.benchmark_group("mroo"), "mroo", - VmBench::new(Opcode::MROO(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::mroo(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("mul"), "mul", - VmBench::new(Opcode::MUL(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::mul(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("muli"), "muli", - VmBench::new(Opcode::MULI(0x10, 0x11, 27)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::muli(0x10, 0x11, 27)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); run_group_ref( &mut c.benchmark_group("noop"), "noop", - VmBench::new(Opcode::NOOP), + VmBench::new(op::noop()), ); run_group_ref( &mut c.benchmark_group("not"), "not", - VmBench::new(Opcode::NOT(0x10, 0x11)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::not(0x10, 0x11)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); run_group_ref( &mut c.benchmark_group("or"), "or", - VmBench::new(Opcode::OR(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::or(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("ori"), "ori", - VmBench::new(Opcode::ORI(0x10, 0x11, 27)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::ori(0x10, 0x11, 27)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); run_group_ref( &mut c.benchmark_group("sll"), "sll", - VmBench::new(Opcode::SLL(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::sll(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("slli"), "slli", - VmBench::new(Opcode::SLLI(0x10, 0x11, 27)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::slli(0x10, 0x11, 27)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); run_group_ref( &mut c.benchmark_group("srl"), "srl", - VmBench::new(Opcode::SRL(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::srl(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("srli"), "srli", - VmBench::new(Opcode::SRLI(0x10, 0x11, 27)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::srli(0x10, 0x11, 27)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); run_group_ref( &mut c.benchmark_group("sub"), "sub", - VmBench::new(Opcode::SUB(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::sub(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("subi"), "subi", - VmBench::new(Opcode::SUBI(0x10, 0x11, 27)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::subi(0x10, 0x11, 27)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); run_group_ref( &mut c.benchmark_group("xor"), "xor", - VmBench::new(Opcode::XOR(0x10, 0x11, 0x12)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 100000), - Opcode::MOVI(0x12, 27), + VmBench::new(op::xor(0x10, 0x11, 0x12)).with_prepare_script(vec![ + op::movi(0x11, 100000), + op::movi(0x12, 27), ]), ); run_group_ref( &mut c.benchmark_group("xori"), "xori", - VmBench::new(Opcode::XORI(0x10, 0x11, 27)) - .with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), + VmBench::new(op::xori(0x10, 0x11, 27)) + .with_prepare_script(vec![op::movi(0x11, 100000)]), ); } diff --git a/benches/benches/set/blockchain.rs b/benches/benches/set/blockchain.rs index d8578936005..da2bd903c9a 100644 --- a/benches/benches/set/blockchain.rs +++ b/benches/benches/set/blockchain.rs @@ -41,11 +41,11 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("bal"), "bal", - VmBench::new(Opcode::BAL(0x10, 0x10, 0x11)) + VmBench::new(op::bal(0x10, 0x10, 0x11)) .with_data(asset.iter().chain(contract.iter()).copied().collect()) .with_prepare_script(vec![ - Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), - Opcode::ADDI(0x11, 0x10, asset.len() as Immediate12), + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), + op::addi(0x11, 0x10, asset.len().try_into().unwrap()), ]) .with_dummy_contract(contract) .with_prepare_db(move |mut db| { @@ -64,7 +64,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("sww"), "sww", - VmBench::contract(rng, Opcode::SWW(REG_ZERO, 0x29, REG_ONE)) + VmBench::contract(rng, op::sww(REG_ZERO, 0x29, REG_ONE)) .expect("failed to prepare contract") .with_prepare_db(move |mut db| { let mut key = Bytes32::zeroed(); @@ -77,7 +77,7 @@ pub fn run(c: &mut Criterion) { }), ); { - let mut input = VmBench::contract(rng, Opcode::SRW(0x13, 0x14, 0x15)) + let mut input = VmBench::contract(rng, op::srw(0x13, 0x14, 0x15)) .expect("failed to prepare contract") .with_prepare_db(move |mut db| { let key = Bytes32::zeroed(); @@ -86,7 +86,7 @@ pub fn run(c: &mut Criterion) { Ok(db) }); - input.prepare_script.extend(vec![Opcode::MOVI(0x15, 2000)]); + input.prepare_script.extend(vec![op::movi(0x15, 2000)]); run_group_ref(&mut c.benchmark_group("srw"), "srw", input); } @@ -97,12 +97,12 @@ pub fn run(c: &mut Criterion) { let data = key.iter().copied().collect::>(); let post_call = vec![ - Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), - Opcode::ADDI(0x11, 0x10, ContractId::LEN as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), + op::addi(0x11, 0x10, ContractId::LEN.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), ]; - let mut bench = VmBench::contract(rng, Opcode::SCWQ(0x11, 0x29, REG_ONE)) + let mut bench = VmBench::contract(rng, op::scwq(0x11, 0x29, REG_ONE)) .expect("failed to prepare contract") .with_post_call(post_call) .with_prepare_db(move |mut db| { @@ -121,12 +121,12 @@ pub fn run(c: &mut Criterion) { let data = key.iter().copied().collect::>(); let post_call = vec![ - Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), - Opcode::ADDI(0x11, 0x10, ContractId::LEN as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), + op::addi(0x11, 0x10, ContractId::LEN.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), ]; - let mut bench = VmBench::contract(rng, Opcode::SWWQ(0x10, 0x11, 0x20, REG_ONE)) + let mut bench = VmBench::contract(rng, op::swwq(0x10, 0x11, 0x20, REG_ONE)) .expect("failed to prepare contract") .with_post_call(post_call) .with_prepare_db(move |mut db| { @@ -157,11 +157,11 @@ pub fn run(c: &mut Criterion) { .collect(); let prepare_script = vec![ - Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), - Opcode::ADDI(0x11, 0x10, ContractId::LEN as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), - Opcode::MOVI(0x12, 100_000), + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), + op::addi(0x11, 0x10, ContractId::LEN.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::movi(0x12, 100_000), ]; call.throughput(Throughput::Bytes(i)); @@ -169,7 +169,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut call, format!("{i}"), - VmBench::new(Opcode::CALL(0x10, REG_ZERO, 0x11, 0x12)) + VmBench::new(op::call(0x10, REG_ZERO, 0x11, 0x12)) .with_contract_code(code) .with_data(data) .with_prepare_script(prepare_script), @@ -197,12 +197,12 @@ pub fn run(c: &mut Criterion) { .collect(); let prepare_script = vec![ - Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), - Opcode::ADDI(0x11, 0x10, ContractId::LEN as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), - Opcode::MOVI(0x12, 100_000), - Opcode::MOVI(0x13, i as Immediate18), + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), + op::addi(0x11, 0x10, ContractId::LEN.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::movi(0x12, 100_000), + op::movi(0x13, i.try_into().unwrap()), ]; ldc.throughput(Throughput::Bytes(i)); @@ -210,7 +210,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut ldc, format!("{i}"), - VmBench::new(Opcode::LDC(0x10, REG_ZERO, 0x13)) + VmBench::new(op::ldc(0x10, REG_ZERO, 0x13)) .with_contract_code(code) .with_data(data) .with_prepare_script(prepare_script), @@ -238,18 +238,18 @@ pub fn run(c: &mut Criterion) { .collect(); let prepare_script = vec![ - Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), - Opcode::ADDI(0x11, 0x10, ContractId::LEN as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), - Opcode::MOVI(0x12, 100_000), - Opcode::MOVI(0x13, i as Immediate18), - Opcode::MOVI(0x14, i as Immediate18), - Opcode::MOVI(0x15, i as Immediate18), - Opcode::ADD(0x15, 0x15, 0x15), - Opcode::ADDI(0x15, 0x15, 32), - Opcode::ALOC(0x15), - Opcode::ADDI(0x15, REG_HP, 1), + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), + op::addi(0x11, 0x10, ContractId::LEN.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::movi(0x12, 100_000), + op::movi(0x13, i.try_into().unwrap()), + op::movi(0x14, i.try_into().unwrap()), + op::movi(0x15, i.try_into().unwrap()), + op::add(0x15, 0x15, 0x15), + op::addi(0x15, 0x15, 32), + op::aloc(0x15), + op::addi(0x15, REG_HP, 1), ]; ccp.throughput(Throughput::Bytes(i)); @@ -257,7 +257,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut ccp, format!("{i}"), - VmBench::new(Opcode::CCP(0x15, 0x10, REG_ZERO, 0x13)) + VmBench::new(op::ccp(0x15, 0x10, REG_ZERO, 0x13)) .with_contract_code(code) .with_data(data) .with_prepare_script(prepare_script), @@ -278,14 +278,14 @@ pub fn run(c: &mut Criterion) { let data = id.iter().copied().collect(); - let prepare_script = vec![Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData)]; + let prepare_script = vec![op::gtf_args(0x10, 0x00, GTFArgs::ScriptData)]; csiz.throughput(Throughput::Bytes(i)); run_group_ref( &mut csiz, format!("{i}"), - VmBench::new(Opcode::CSIZ(0x11, 0x10)) + VmBench::new(op::csiz(0x11, 0x10)) .with_contract_code(code) .with_data(data) .with_prepare_script(prepare_script), @@ -297,45 +297,45 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("bhei"), "bhei", - VmBench::new(Opcode::BHEI(0x10)), + VmBench::new(op::bhei(0x10)), ); run_group_ref( &mut c.benchmark_group("bhsh"), "bhsh", - VmBench::new(Opcode::BHSH(0x10, REG_ZERO)).with_prepare_script(vec![ - Opcode::MOVI(0x10, Bytes32::LEN as Immediate18), - Opcode::ALOC(0x10), - Opcode::ADDI(0x10, REG_HP, 1), + VmBench::new(op::bhsh(0x10, REG_ZERO)).with_prepare_script(vec![ + op::movi(0x10, Bytes32::LEN.try_into().unwrap()), + op::aloc(0x10), + op::addi(0x10, REG_HP, 1), ]), ); run_group_ref( &mut c.benchmark_group("mint"), "mint", - VmBench::contract(rng, Opcode::MINT(REG_ZERO)) + VmBench::contract(rng, op::mint(REG_ZERO)) .expect("failed to prepare contract"), ); run_group_ref( &mut c.benchmark_group("burn"), "burn", - VmBench::contract(rng, Opcode::MINT(REG_ZERO)) + VmBench::contract(rng, op::mint(REG_ZERO)) .expect("failed to prepare contract"), ); run_group_ref( &mut c.benchmark_group("cb"), "cb", - VmBench::new(Opcode::CB(0x10)).with_prepare_script(vec![ - Opcode::MOVI(0x10, Bytes32::LEN as Immediate18), - Opcode::ALOC(0x10), - Opcode::ADDI(0x10, REG_HP, 1), + VmBench::new(op::cb(0x10)).with_prepare_script(vec![ + op::movi(0x10, Bytes32::LEN.try_into().unwrap()), + op::aloc(0x10), + op::addi(0x10, REG_HP, 1), ]), ); { - let mut input = VmBench::contract(rng, Opcode::TR(0x15, 0x14, 0x15)) + let mut input = VmBench::contract(rng, op::tr(0x15, 0x14, 0x15)) .expect("failed to prepare contract") .with_prepare_db(move |mut db| { db.merkle_contract_asset_id_balance_insert( @@ -348,12 +348,12 @@ pub fn run(c: &mut Criterion) { }); input .prepare_script - .extend(vec![Opcode::MOVI(0x15, 2000), Opcode::MOVI(0x14, 100)]); + .extend(vec![op::movi(0x15, 2000), op::movi(0x14, 100)]); run_group_ref(&mut c.benchmark_group("tr"), "tr", input); } { - let mut input = VmBench::contract(rng, Opcode::TRO(0x15, 0x16, 0x14, 0x15)) + let mut input = VmBench::contract(rng, op::tro(0x15, 0x16, 0x14, 0x15)) .expect("failed to prepare contract") .with_prepare_db(move |mut db| { db.merkle_contract_asset_id_balance_insert( @@ -366,7 +366,7 @@ pub fn run(c: &mut Criterion) { }); let coin_output = Output::variable(Address::zeroed(), 100, AssetId::zeroed()); input.outputs.push(coin_output); - let predicate = Opcode::RET(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(REG_ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let coin_input = Input::coin_predicate( Default::default(), @@ -382,9 +382,9 @@ pub fn run(c: &mut Criterion) { let index = input.outputs.len() - 1; input.prepare_script.extend(vec![ - Opcode::MOVI(0x15, 2000), - Opcode::MOVI(0x14, 100), - Opcode::MOVI(0x16, index as Immediate18), + op::movi(0x15, 2000), + op::movi(0x14, 100), + op::movi(0x16, index.try_into().unwrap()), ]); run_group_ref(&mut c.benchmark_group("tro"), "tro", input); } @@ -392,17 +392,17 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("cfsi"), "cfsi", - VmBench::new(Opcode::CFSI(1)), + VmBench::new(op::cfsi(1)), ); { - let mut input = VmBench::contract(rng, Opcode::CROO(0x14, 0x16)) + let mut input = VmBench::contract(rng, op::croo(0x14, 0x16)) .expect("failed to prepare contract"); input.post_call.extend(vec![ - Opcode::gtf(0x16, 0x00, GTFArgs::ScriptData), - Opcode::MOVI(0x15, 2000), - Opcode::ALOC(0x15), - Opcode::ADDI(0x14, REG_HP, 1), + op::gtf_args(0x16, 0x00, GTFArgs::ScriptData), + op::movi(0x15, 2000), + op::aloc(0x15), + op::addi(0x14, REG_HP, 1), ]); run_group_ref(&mut c.benchmark_group("croo"), "croo", input); } @@ -410,29 +410,29 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("flag"), "flag", - VmBench::new(Opcode::FLAG(0x10)), + VmBench::new(op::flag(0x10)), ); run_group_ref( &mut c.benchmark_group("gm"), "gm", - VmBench::contract(rng, Opcode::GM(0x10, 1)).unwrap(), + VmBench::contract(rng, op::gm(0x10, 1)).unwrap(), ); let mut smo = c.benchmark_group("smo"); for i in linear.clone() { - let mut input = VmBench::contract(rng, Opcode::SMO(0x15, 0x16, 0x17, 0x18)) + let mut input = VmBench::contract(rng, op::smo(0x15, 0x16, 0x17, 0x18)) .expect("failed to prepare contract"); input.outputs.push(Output::message(Address::zeroed(), 1)); let index = input.outputs.len() - 1; input.post_call.extend(vec![ - Opcode::gtf(0x15, 0x00, GTFArgs::ScriptData), + op::gtf_args(0x15, 0x00, GTFArgs::ScriptData), // Offset 32 + 8+ 8 + 32 - Opcode::ADDI(0x15, 0x15, 32 + 8 + 8 + 32), - Opcode::MOVI(0x16, i as Immediate18), - Opcode::MOVI(0x17, index as Immediate18), - Opcode::MOVI(0x18, 10), + op::addi(0x15, 0x15, 32 + 8 + 8 + 32), + op::movi(0x16, i.try_into().unwrap()), + op::movi(0x17, index.try_into().unwrap()), + op::movi(0x18, 10), ]); input.data.extend( Address::new([1u8; 32]) @@ -440,7 +440,7 @@ pub fn run(c: &mut Criterion) { .copied() .chain(vec![2u8; i as usize]), ); - let predicate = Opcode::RET(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(REG_ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let coin_input = Input::coin_predicate( Default::default(), @@ -468,15 +468,15 @@ pub fn run(c: &mut Criterion) { let data = key.iter().copied().collect::>(); let post_call = vec![ - Opcode::MOVI(0x16, i as Immediate18), - Opcode::MOVI(0x17, 2000), - Opcode::MOVE(0x15, 0x16), - Opcode::MULI(0x15, 0x15, 32), - Opcode::ADDI(0x15, 0x15, 1), - Opcode::ALOC(0x15), - Opcode::ADDI(0x14, REG_HP, 1), + op::movi(0x16, i.try_into().unwrap()), + op::movi(0x17, 2000), + op::move_(0x15, 0x16), + op::muli(0x15, 0x15, 32), + op::addi(0x15, 0x15, 1), + op::aloc(0x15), + op::addi(0x14, REG_HP, 1), ]; - let mut bench = VmBench::contract(rng, Opcode::SRWQ(0x14, 0x11, 0x27, 0x16)) + let mut bench = VmBench::contract(rng, op::srwq(0x14, 0x11, 0x27, 0x16)) .expect("failed to prepare contract") .with_post_call(post_call) .with_prepare_db(move |mut db| { @@ -495,7 +495,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("time"), "time", - VmBench::new(Opcode::TIME(0x11, 0x10)) - .with_prepare_script(vec![Opcode::MOVI(0x10, 0)]), + VmBench::new(op::time(0x11, 0x10)) + .with_prepare_script(vec![op::movi(0x10, 0)]), ); } diff --git a/benches/benches/set/crypto.rs b/benches/benches/set/crypto.rs index 735e53f9c67..d8a2fed16eb 100644 --- a/benches/benches/set/crypto.rs +++ b/benches/benches/set/crypto.rs @@ -23,14 +23,14 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("ecr"), "ecr", - VmBench::new(Opcode::ECR(0x11, 0x20, 0x21)) + VmBench::new(op::ecr(0x11, 0x20, 0x21)) .with_prepare_script(vec![ - Opcode::gtf(0x20, 0x00, GTFArgs::ScriptData), - Opcode::ADDI(0x21, 0x20, signature.as_ref().len() as Immediate12), - Opcode::ADDI(0x22, 0x21, message.as_ref().len() as Immediate12), - Opcode::MOVI(0x10, PublicKey::LEN as Immediate18), - Opcode::ALOC(0x10), - Opcode::ADDI(0x11, REG_HP, 1), + op::gtf_args(0x20, 0x00, GTFArgs::ScriptData), + op::addi(0x21, 0x20, signature.as_ref().len().try_into().unwrap()), + op::addi(0x22, 0x21, message.as_ref().len().try_into().unwrap()), + op::movi(0x10, PublicKey::LEN.try_into().unwrap()), + op::aloc(0x10), + op::addi(0x11, REG_HP, 1), ]) .with_data(signature.iter().chain(message.iter()).copied().collect()), ); @@ -38,12 +38,12 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("s256"), "s256", - VmBench::new(Opcode::S256(0x10, 0x00, 0x11)) + VmBench::new(op::s256(0x10, 0x00, 0x11)) .with_prepare_script(vec![ - Opcode::MOVI(0x10, Bytes32::LEN as Immediate18), - Opcode::ALOC(0x10), - Opcode::ADDI(0x10, REG_HP, 1), - Opcode::MOVI(0x11, 32), + op::movi(0x10, Bytes32::LEN.try_into().unwrap()), + op::aloc(0x10), + op::addi(0x10, REG_HP, 1), + op::movi(0x11, 32), ]) .with_data(signature.iter().chain(message.iter()).copied().collect()), ); @@ -51,12 +51,12 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("k256"), "k256", - VmBench::new(Opcode::K256(0x10, 0x00, 0x11)) + VmBench::new(op::k256(0x10, 0x00, 0x11)) .with_prepare_script(vec![ - Opcode::MOVI(0x10, Bytes32::LEN as Immediate18), - Opcode::ALOC(0x10), - Opcode::ADDI(0x10, REG_HP, 1), - Opcode::MOVI(0x11, 32), + op::movi(0x10, Bytes32::LEN.try_into().unwrap()), + op::aloc(0x10), + op::addi(0x10, REG_HP, 1), + op::movi(0x11, 32), ]) .with_data(signature.iter().chain(message.iter()).copied().collect()), ); diff --git a/benches/benches/set/flow.rs b/benches/benches/set/flow.rs index 110db631487..25fd02a689b 100644 --- a/benches/benches/set/flow.rs +++ b/benches/benches/set/flow.rs @@ -30,44 +30,44 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("jmp"), "jmp", - VmBench::new(Opcode::JMP(0x10)).with_prepare_script(vec![Opcode::MOVI(0x10, 10)]), + VmBench::new(op::jmp(0x10)).with_prepare_script(vec![op::movi(0x10, 10)]), ); run_group_ref( &mut c.benchmark_group("ji"), "ji", - VmBench::new(Opcode::JI(10)), + VmBench::new(op::ji(10)), ); run_group_ref( &mut c.benchmark_group("jne"), "jne", - VmBench::new(Opcode::JNE(REG_ZERO, REG_ONE, 0x10)) - .with_prepare_script(vec![Opcode::MOVI(0x10, 10)]), + VmBench::new(op::jne(REG_ZERO, REG_ONE, 0x10)) + .with_prepare_script(vec![op::movi(0x10, 10)]), ); run_group_ref( &mut c.benchmark_group("jnei"), "jnei", - VmBench::new(Opcode::JNEI(REG_ZERO, REG_ONE, 10)), + VmBench::new(op::jnei(REG_ZERO, REG_ONE, 10)), ); run_group_ref( &mut c.benchmark_group("jnzi"), "jnzi", - VmBench::new(Opcode::JNZI(REG_ONE, 10)), + VmBench::new(op::jnzi(REG_ONE, 10)), ); run_group_ref( &mut c.benchmark_group("ret_script"), "ret_script", - VmBench::new(Opcode::RET(REG_ONE)), + VmBench::new(op::ret(REG_ONE)), ); run_group_ref( &mut c.benchmark_group("ret_contract"), "ret_contract", - VmBench::contract(rng, Opcode::RET(REG_ONE)).unwrap(), + VmBench::contract(rng, op::ret(REG_ONE)).unwrap(), ); let mut retd_contract = c.benchmark_group("retd_contract"); @@ -76,9 +76,9 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut retd_contract, format!("{i}"), - VmBench::contract(rng, Opcode::RETD(REG_ONE, 0x10)) + VmBench::contract(rng, op::retd(REG_ONE, 0x10)) .unwrap() - .with_post_call(vec![Opcode::MOVI(0x10, *i)]), + .with_post_call(vec![op::movi(0x10, *i)]), ); } retd_contract.finish(); @@ -89,9 +89,9 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut retd_script, format!("{i}"), - VmBench::contract(rng, Opcode::RETD(REG_ONE, 0x10)) + VmBench::contract(rng, op::retd(REG_ONE, 0x10)) .unwrap() - .with_post_call(vec![Opcode::MOVI(0x10, *i)]), + .with_post_call(vec![op::movi(0x10, *i)]), ); } retd_script.finish(); @@ -99,19 +99,19 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("rvrt_script"), "rvrt_script", - VmBench::new(Opcode::RVRT(REG_ONE)), + VmBench::new(op::rvrt(REG_ONE)), ); run_group_ref( &mut c.benchmark_group("rvrt_contract"), "rvrt_contract", - VmBench::contract(rng, Opcode::RET(REG_ONE)).unwrap(), + VmBench::contract(rng, op::ret(REG_ONE)).unwrap(), ); run_group_ref( &mut c.benchmark_group("log"), "log", - VmBench::new(Opcode::LOG(0x10, 0x11, 0x12, 0x13)), + VmBench::new(op::log(0x10, 0x11, 0x12, 0x13)), ); let mut logd = c.benchmark_group("logd"); @@ -120,8 +120,8 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut logd, format!("{i}"), - VmBench::new(Opcode::LOGD(0x10, 0x11, REG_ZERO, 0x13)) - .with_prepare_script(vec![Opcode::MOVI(0x13, *i)]), + VmBench::new(op::logd(0x10, 0x11, REG_ZERO, 0x13)) + .with_prepare_script(vec![op::movi(0x13, *i)]), ); } logd.finish(); diff --git a/benches/benches/set/mem.rs b/benches/benches/set/mem.rs index 3c3d6863901..ea6382af049 100644 --- a/benches/benches/set/mem.rs +++ b/benches/benches/set/mem.rs @@ -16,33 +16,33 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("lb"), "lb", - VmBench::new(Opcode::LB(0x10, REG_ONE, 10)), + VmBench::new(op::lb(0x10, REG_ONE, 10)), ); run_group_ref( &mut c.benchmark_group("lw"), "lw", - VmBench::new(Opcode::LW(0x10, REG_ONE, 10)), + VmBench::new(op::lw(0x10, REG_ONE, 10)), ); run_group_ref( &mut c.benchmark_group("sb"), "sb", - VmBench::new(Opcode::SB(0x10, 0x11, 0)).with_prepare_script(vec![ - Opcode::ALOC(REG_ONE), - Opcode::ADDI(0x10, REG_HP, 1), - Opcode::MOVI(0x11, 50), + VmBench::new(op::sb(0x10, 0x11, 0)).with_prepare_script(vec![ + op::aloc(REG_ONE), + op::addi(0x10, REG_HP, 1), + op::movi(0x11, 50), ]), ); run_group_ref( &mut c.benchmark_group("sw"), "sw", - VmBench::new(Opcode::SW(0x10, 0x11, 0)).with_prepare_script(vec![ - Opcode::MOVI(0x10, 8), - Opcode::ALOC(0x10), - Opcode::ADDI(0x10, REG_HP, 1), - Opcode::MOVI(0x11, 50), + VmBench::new(op::sw(0x10, 0x11, 0)).with_prepare_script(vec![ + op::movi(0x10, 8), + op::aloc(0x10), + op::addi(0x10, REG_HP, 1), + op::movi(0x11, 50), ]), ); @@ -57,7 +57,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("cfei"), "cfei", - VmBench::new(Opcode::CFEI(1)), + VmBench::new(op::cfei(1)), ); let mut mem_mcl = c.benchmark_group("mcl"); @@ -66,10 +66,10 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut mem_mcl, format!("{i}"), - VmBench::new(Opcode::MCL(0x10, 0x11)).with_prepare_script(vec![ - Opcode::MOVI(0x11, *i), - Opcode::ALOC(0x11), - Opcode::ADDI(0x10, REG_HP, 1), + VmBench::new(op::mcl(0x10, 0x11)).with_prepare_script(vec![ + op::movi(0x11, *i), + op::aloc(0x11), + op::addi(0x10, REG_HP, 1), ]), ); } @@ -81,10 +81,10 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut mem_mcli, format!("{i}"), - VmBench::new(Opcode::MCLI(0x10, *i)).with_prepare_script(vec![ - Opcode::MOVI(0x11, *i), - Opcode::ALOC(0x11), - Opcode::ADDI(0x10, REG_HP, 1), + VmBench::new(op::mcli(0x10, *i)).with_prepare_script(vec![ + op::movi(0x11, *i), + op::aloc(0x11), + op::addi(0x10, REG_HP, 1), ]), ); } @@ -96,10 +96,10 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut mem_mcp, format!("{i}"), - VmBench::new(Opcode::MCP(0x10, REG_ZERO, 0x11)).with_prepare_script(vec![ - Opcode::MOVI(0x11, *i), - Opcode::ALOC(0x11), - Opcode::ADDI(0x10, REG_HP, 1), + VmBench::new(op::mcp(0x10, REG_ZERO, 0x11)).with_prepare_script(vec![ + op::movi(0x11, *i), + op::aloc(0x11), + op::addi(0x10, REG_HP, 1), ]), ); } @@ -108,11 +108,11 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("mcpi"), "mcpi", - VmBench::new(Opcode::MCPI(0x10, REG_ZERO, 4000 as Immediate12)) + VmBench::new(op::mcpi(0x10, REG_ZERO, 4000)) .with_prepare_script(vec![ - Opcode::MOVI(0x11, 4000), - Opcode::ALOC(0x11), - Opcode::ADDI(0x10, REG_HP, 1), + op::movi(0x11, 4000), + op::aloc(0x11), + op::addi(0x10, REG_HP, 1), ]), ); @@ -122,10 +122,10 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut mem_meq, format!("{i}"), - VmBench::new(Opcode::MEQ(0x10, 0x11, 0x12, 0x13)).with_prepare_script(vec![ - Opcode::MOVI(0x11, 0), - Opcode::MOVI(0x12, i * 3), - Opcode::MOVI(0x13, *i), + VmBench::new(op::meq(0x10, 0x11, 0x12, 0x13)).with_prepare_script(vec![ + op::movi(0x11, 0), + op::movi(0x12, i * 3), + op::movi(0x13, *i), ]), ); } diff --git a/benches/benches/vm.rs b/benches/benches/vm.rs index 76bdfb1027d..dca72fe5690 100644 --- a/benches/benches/vm.rs +++ b/benches/benches/vm.rs @@ -11,7 +11,7 @@ use criterion::{ use fuel_core_benches::*; use fuel_core_storage::transactional::Transaction; -use fuel_core_types::fuel_asm::OpcodeRepr; +use fuel_core_types::fuel_asm::{Instruction}; use set::*; pub fn run_group_ref(group: &mut BenchmarkGroup, id: I, bench: VmBench) @@ -26,7 +26,6 @@ where instruction, diff, } = &mut i; - let code = OpcodeRepr::from_u8(instruction.op()); let original_db = vm.as_mut().database_mut().clone(); let mut db_txn = { let db = vm.as_mut().database_mut(); @@ -38,13 +37,13 @@ where let start = std::time::Instant::now(); for _ in 0..iters { - match code { - OpcodeRepr::CALL => { - let (_, ra, rb, rc, rd, _imm) = instruction.into_inner(); + match instruction { + Instruction::CALL(call) => { + let (ra, rb, rc, rd) = call.unpack(); vm.prepare_call(ra, rb, rc, rd).unwrap(); } _ => { - black_box(vm.instruction(*instruction).unwrap()); + black_box(vm.instruction((*instruction).into()).unwrap()); } } vm.reset_vm_state(diff); diff --git a/benches/src/lib.rs b/benches/src/lib.rs index 223f283101c..8d65d0aa8cd 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -53,10 +53,10 @@ impl From> for ContractCode { } pub struct PrepareCall { - ra: RegisterId, - rb: RegisterId, - rc: RegisterId, - rd: RegisterId, + ra: RegId, + rb: RegId, + rc: RegId, + rd: RegId, } pub struct VmBench { @@ -65,14 +65,14 @@ pub struct VmBench { pub gas_limit: Word, pub maturity: Word, pub height: Word, - pub prepare_script: Vec, - pub post_call: Vec, + pub prepare_script: Vec, + pub post_call: Vec, pub data: Vec, pub inputs: Vec, pub outputs: Vec, pub witnesses: Vec, pub db: Option, - pub instruction: Opcode, + pub instruction: Instruction, pub prepare_call: Option, pub dummy_contract: Option, pub contract_code: Option, @@ -90,7 +90,7 @@ impl VmBench { pub const SALT: Salt = Salt::zeroed(); pub const CONTRACT: ContractId = ContractId::zeroed(); - pub fn new(instruction: Opcode) -> Self { + pub fn new(instruction: Instruction) -> Self { Self { params: ConsensusParameters { max_gas_per_tx: LARGE_GAS_LIMIT + 1, @@ -115,14 +115,14 @@ impl VmBench { } } - pub fn contract(rng: &mut R, instruction: Opcode) -> io::Result + pub fn contract(rng: &mut R, instruction: Instruction) -> io::Result where R: Rng, { let bench = Self::new(instruction); let program = iter::once(instruction) - .chain(iter::once(Opcode::RET(REG_ONE))) + .chain(iter::once(op::ret(REG_ONE))) .collect::>(); let program = Witness::from(program); @@ -153,18 +153,18 @@ impl VmBench { .collect(); let prepare_script = vec![ - Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), - Opcode::ADDI(0x11, 0x10, ContractId::LEN as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), - Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), - Opcode::MOVI(0x12, 100_000), + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), + op::addi(0x11, 0x10, ContractId::LEN as u16), + op::addi(0x11, 0x11, WORD_SIZE as u16), + op::addi(0x11, 0x11, WORD_SIZE as u16), + op::movi(0x12, 100_000), ]; let prepare_call = PrepareCall { - ra: 0x10, + ra: RegId::new(0x10), rb: REG_ZERO, - rc: 0x11, - rd: 0x12, + rc: RegId::new(0x11), + rd: RegId::new(0x12), }; Ok(bench @@ -206,12 +206,12 @@ impl VmBench { self } - pub fn with_prepare_script(mut self, prepare_script: Vec) -> Self { + pub fn with_prepare_script(mut self, prepare_script: Vec) -> Self { self.prepare_script = prepare_script; self } - pub fn with_post_call(mut self, post_call: Vec) -> Self { + pub fn with_post_call(mut self, post_call: Vec) -> Self { self.post_call = post_call; self } @@ -290,7 +290,7 @@ impl TryFrom for VmBenchPrepared { let mut db = db.unwrap_or_else(new_db); - if prepare_script.iter().any(|op| matches!(op, Opcode::RET(_))) { + if prepare_script.iter().any(|op| matches!(op, Instruction::RET(_))) { return Err(io::Error::new( io::ErrorKind::Other, "a prepare script should not call/return into different contexts.", @@ -299,14 +299,14 @@ impl TryFrom for VmBenchPrepared { let prepare_script = prepare_script .into_iter() - .chain(iter::once(Opcode::RET(REG_ONE))) + .chain(iter::once(op::ret(REG_ONE))) .chain(iter::once(instruction)) .collect(); let mut tx = TransactionBuilder::script(prepare_script, data); if let Some(contract) = dummy_contract { - let code = iter::once(Opcode::RET(REG_ONE)); + let code = iter::once(op::ret(REG_ONE)); let code: Vec = code.collect(); let code = Contract::from(code); let root = code.root(); @@ -379,8 +379,6 @@ impl TryFrom for VmBenchPrepared { .maturity(maturity) .finalize_checked(height, &p, &Default::default()); - let instruction = Instruction::from(instruction); - let mut txtor = Transactor::new(db, params, GasCosts::free()); txtor.transact(tx); @@ -392,22 +390,20 @@ impl TryFrom for VmBenchPrepared { vm.prepare_call(ra, rb, rc, rd) .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; - for op in post_call { - let instruction = Instruction::from(op); - vm.instruction(instruction).unwrap(); + for instruction in post_call { + vm.instruction(instruction.into()).unwrap(); } } - let code = OpcodeRepr::from_u8(instruction.op()); let start_vm = vm.clone(); let mut vm = vm.add_recording(); - match code { - OpcodeRepr::CALL => { - let (_, ra, rb, rc, rd, _imm) = instruction.into_inner(); + match instruction { + Instruction::CALL(call) => { + let (ra, rb, rc, rd) = call.unpack(); vm.prepare_call(ra, rb, rc, rd).unwrap(); } _ => { - vm.instruction(instruction).unwrap(); + vm.instruction(instruction.into()).unwrap(); } } let storage_diff = vm.storage_diff(); diff --git a/crates/chain-config/src/config.rs b/crates/chain-config/src/config.rs index b901958220f..95310b3b796 100644 --- a/crates/chain-config/src/config.rs +++ b/crates/chain-config/src/config.rs @@ -16,7 +16,7 @@ pub use state::*; mod tests { use fuel_core_types::{ blockchain::primitives::DaBlockHeight, - fuel_asm::Opcode, + fuel_asm::{op}, fuel_types::{ AssetId, Bytes32, @@ -200,8 +200,7 @@ mod tests { } else { None }; - - let contract = Contract::from(Opcode::RET(0x10).to_bytes().to_vec()); + let contract = Contract::from(op::ret(0x10).to_bytes().to_vec()); ChainConfig { initial_state: Some(StateConfig { diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 22358a3f281..0143ef20ebb 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -17,7 +17,7 @@ use cynic::{ use eventsource_client::HttpsConnector; use fuel_core_types::{ fuel_asm::{ - Opcode, + Instruction, RegisterId, Word, }, @@ -340,7 +340,7 @@ impl FuelClient { self.query(query).await.map(|r| r.reset) } - pub async fn execute(&self, id: &str, op: &Opcode) -> io::Result { + pub async fn execute(&self, id: &str, op: &Instruction) -> io::Result { let op = serde_json::to_string(op)?; let query = schema::Execute::build(schema::ExecuteArgs { id: id.into(), op }); diff --git a/crates/fuel-core/src/executor.rs b/crates/fuel-core/src/executor.rs index ef30bf14bba..3db221712d6 100644 --- a/crates/fuel-core/src/executor.rs +++ b/crates/fuel-core/src/executor.rs @@ -1385,7 +1385,7 @@ mod tests { use fuel_core_types::{ blockchain::header::ConsensusHeader, entities::message::CheckedMessage, - fuel_asm::Opcode, + fuel_asm::{op}, fuel_crypto::SecretKey, fuel_merkle::common::empty_sum_sha256, fuel_tx, @@ -1407,8 +1407,6 @@ mod tests { fuel_types::{ bytes::SerializableVec, ContractId, - Immediate12, - Immediate18, Salt, }, fuel_vm::{ @@ -1444,17 +1442,17 @@ mod tests { let (create, contract_id) = create_contract( vec![ // load amount of coins to 0x10 - Opcode::ADDI(0x10, REG_FP, CallFrame::a_offset() as Immediate12), - Opcode::LW(0x10, 0x10, 0), + op::addi(0x10, REG_FP, CallFrame::a_offset().try_into().unwrap()), + op::lw(0x10, 0x10, 0), // load asset id to 0x11 - Opcode::ADDI(0x11, REG_FP, CallFrame::b_offset() as Immediate12), - Opcode::LW(0x11, 0x11, 0), + op::addi(0x11, REG_FP, CallFrame::b_offset().try_into().unwrap()), + op::lw(0x11, 0x11, 0), // load address to 0x12 - Opcode::ADDI(0x12, 0x11, 32), + op::addi(0x12, 0x11, 32), // load output index (0) to 0x13 - Opcode::ADDI(0x13, REG_ZERO, 0), - Opcode::TRO(0x12, 0x13, 0x10, 0x11), - Opcode::RET(REG_ONE), + op::addi(0x13, REG_ZERO, 0), + op::tro(0x12, 0x13, 0x10, 0x11), + op::ret(REG_ONE), ] .into_iter() .collect::>(), @@ -1464,14 +1462,14 @@ mod tests { data_offset, vec![ // set reg 0x10 to call data - Opcode::MOVI(0x10, (data_offset + 64) as Immediate18), + op::movi(0x10, data_offset + 64), // set reg 0x11 to asset id - Opcode::MOVI(0x11, data_offset), + op::movi(0x11, data_offset), // set reg 0x12 to call amount - Opcode::MOVI(0x12, variable_transfer_amount), + op::movi(0x12, variable_transfer_amount), // call contract without any tokens to transfer in (3rd arg arbitrary when 2nd is zero) - Opcode::CALL(0x10, 0x12, 0x11, REG_CGAS), - Opcode::RET(REG_ONE), + op::call(0x10, 0x12, 0x11, REG_CGAS), + op::ret(REG_ONE), ], ConsensusParameters::DEFAULT.tx_offset() ); @@ -1778,25 +1776,25 @@ mod tests { .gas_price(0) .start_script(vec![ // Store the size of the `Address`(32 bytes) into register `0x11`. - Opcode::MOVI(0x11, Address::LEN as Immediate18), + op::movi(0x11, Address::LEN.try_into().unwrap()), // Allocate 32 bytes on the heap. - Opcode::ALOC(0x11), + op::aloc(0x11), // Store the pointer to the beginning of the free memory into // register `0x10`. It requires shifting of `REG_HP` by 1 to point // on the free memory. - Opcode::ADDI(0x10, REG_HP, 1), + op::addi(0x10, REG_HP, 1), // Store `config_coinbase` `Address` into MEM[$0x10; 32]. - Opcode::CB(0x10), + op::cb(0x10), // Store the pointer on the beginning of script data into register `0x12`. // Script data contains `expected_in_tx_coinbase` - 32 bytes of data. - Opcode::gtf(0x12, 0x00, GTFArgs::ScriptData), + op::gtf_args(0x12, 0x00, GTFArgs::ScriptData), // Compare retrieved `config_coinbase`(register `0x10`) with // passed `expected_in_tx_coinbase`(register `0x12`) where the length // of memory comparison is 32 bytes(register `0x11`) and store result into // register `0x13`(1 - true, 0 - false). - Opcode::MEQ(0x13, 0x10, 0x12, 0x11), + op::meq(0x13, 0x10, 0x12, 0x11), // Return the result of the comparison as a receipt. - Opcode::RET(0x13) + op::ret(0x13) ], expected_in_tx_coinbase.to_vec() /* pass expected address as script data */) .coin_input(AssetId::BASE, 1000) .variable_output(Default::default()) @@ -2268,7 +2266,7 @@ mod tests { let mut rng = StdRng::seed_from_u64(2322u64); let tx = TransactionBuilder::script( - vec![Opcode::RET(REG_ONE)].into_iter().collect(), + vec![op::ret(REG_ONE)].into_iter().collect(), vec![], ) .add_unsigned_coin_input( @@ -2687,7 +2685,7 @@ mod tests { let non_modify_state_tx: Transaction = TxBuilder::new(2322) .gas_limit(10000) .coin_input(AssetId::zeroed(), 10000) - .start_script(vec![Opcode::RET(1)], vec![]) + .start_script(vec![op::ret(1)], vec![]) .contract_input(contract_id) .contract_output(&contract_id) .build() @@ -2753,7 +2751,7 @@ mod tests { let (create, contract_id) = create_contract(vec![], &mut rng); // The transaction with invalid script. let non_modify_state_tx: Transaction = TxBuilder::new(2322) - .start_script(vec![Opcode::ADD(REG_PC, REG_PC, REG_PC)], vec![]) + .start_script(vec![op::add(REG_PC, REG_PC, REG_PC)], vec![]) .contract_input(contract_id) .contract_output(&contract_id) .build() @@ -2826,8 +2824,8 @@ mod tests { let (create, contract_id) = create_contract( vec![ // Sets the state STATE[0x1; 32] = value of `REG_PC`; - Opcode::SWW(0x1, 0x29, REG_PC), - Opcode::RET(1), + op::sww(0x1, 0x29, REG_PC), + op::ret(1), ] .into_iter() .collect::>(), @@ -2840,13 +2838,13 @@ mod tests { data_offset, vec![ // Set register `0x10` to `Call` - Opcode::MOVI(0x10, (data_offset + AssetId::LEN as u32) as Immediate18), + op::movi(0x10, data_offset + AssetId::LEN as u32), // Set register `0x11` with offset to data that contains `asset_id` - Opcode::MOVI(0x11, data_offset), + op::movi(0x11, data_offset), // Set register `0x12` with `transfer_amount` - Opcode::MOVI(0x12, transfer_amount as u32), - Opcode::CALL(0x10, 0x12, 0x11, REG_CGAS), - Opcode::RET(REG_ONE), + op::movi(0x12, transfer_amount as u32), + op::call(0x10, 0x12, 0x11, REG_CGAS), + op::ret(REG_ONE), ], ConsensusParameters::DEFAULT.tx_offset() ); @@ -2940,7 +2938,7 @@ mod tests { let mut foreign_transfer = TxBuilder::new(2322) .gas_limit(10000) .coin_input(AssetId::zeroed(), 10000) - .start_script(vec![Opcode::RET(1)], vec![]) + .start_script(vec![op::ret(1)], vec![]) .coin_input(asset_id, transfer_amount) .coin_output(asset_id, transfer_amount) .build() @@ -2996,7 +2994,7 @@ mod tests { let starting_block = BlockHeight::from(5u64); let tx = TransactionBuilder::script( - vec![Opcode::RET(REG_ONE)].into_iter().collect(), + vec![op::ret(REG_ONE)].into_iter().collect(), vec![], ) .add_unsigned_coin_input( @@ -3096,7 +3094,7 @@ mod tests { }; let tx2: Transaction = TxBuilder::new(2322) - .start_script(vec![Opcode::RET(1)], vec![]) + .start_script(vec![op::ret(1)], vec![]) .contract_input(contract_id) .contract_output(&contract_id) .build() @@ -3157,7 +3155,7 @@ mod tests { let (tx, contract_id) = create_contract(vec![], &mut rng); let tx2: Transaction = TxBuilder::new(2322) .start_script( - vec![Opcode::ADDI(0x10, REG_ZERO, 0), Opcode::RET(1)], + vec![op::addi(0x10, REG_ZERO, 0), op::ret(1)], vec![], ) .contract_input(contract_id) @@ -3174,7 +3172,7 @@ mod tests { let tx3: Transaction = TxBuilder::new(2322) .start_script( - vec![Opcode::ADDI(0x10, REG_ZERO, 1), Opcode::RET(1)], + vec![op::addi(0x10, REG_ZERO, 1), op::ret(1)], vec![], ) .contract_input(contract_id) @@ -3546,7 +3544,7 @@ mod tests { let mut rng = StdRng::seed_from_u64(1234); // return current block height - let script = vec![Opcode::BHEI(0x10), Opcode::RET(0x10)]; + let script = vec![op::bhei(0x10), op::ret(0x10)]; let tx = TransactionBuilder::script(script.into_iter().collect(), vec![]) .gas_limit(10000) .add_unsigned_coin_input( @@ -3618,9 +3616,9 @@ mod tests { // return current block height let script = vec![ - Opcode::BHEI(0x10), - Opcode::TIME(0x11, 0x10), - Opcode::RET(0x11), + op::bhei(0x10), + op::time(0x11, 0x10), + op::ret(0x11), ]; let tx = TransactionBuilder::script(script.into_iter().collect(), vec![]) .gas_limit(10000) diff --git a/crates/fuel-core/src/schema/dap.rs b/crates/fuel-core/src/schema/dap.rs index b65c458a609..c36a64e4f28 100644 --- a/crates/fuel-core/src/schema/dap.rs +++ b/crates/fuel-core/src/schema/dap.rs @@ -18,7 +18,7 @@ use fuel_core_storage::{ }; use fuel_core_types::{ fuel_asm::{ - Opcode, + Instruction, RegisterId, Word, }, @@ -146,7 +146,7 @@ impl ConcreteStorage { Ok(()) } - pub fn exec(&mut self, id: &ID, op: Opcode) -> Result<(), InterpreterError> { + pub fn exec(&mut self, id: &ID, op: Instruction) -> Result<(), InterpreterError> { self.vm .get_mut(id) .map(|vm| vm.instruction(op.into())) @@ -273,7 +273,7 @@ impl DapMutation { ) -> async_graphql::Result { trace!("Execute encoded op {}", op); - let op: Opcode = serde_json::from_str(op.as_str())?; + let op: Instruction = serde_json::from_str(op.as_str())?; trace!("Op decoded to {:?}", op); diff --git a/crates/fuel-core/src/service/genesis.rs b/crates/fuel-core/src/service/genesis.rs index 36ccdae3c50..5e41f596e09 100644 --- a/crates/fuel-core/src/service/genesis.rs +++ b/crates/fuel-core/src/service/genesis.rs @@ -371,7 +371,7 @@ mod tests { DaBlockHeight, }, entities::coin::Coin, - fuel_asm::Opcode, + fuel_asm::{op}, fuel_types::{ Address, AssetId, @@ -539,7 +539,7 @@ mod tests { let test_value: Bytes32 = rng.gen(); let state = vec![(test_key, test_value)]; let salt: Salt = rng.gen(); - let contract = Contract::from(Opcode::RET(0x10).to_bytes().to_vec()); + let contract = Contract::from(op::ret(0x10).to_bytes().to_vec()); let root = contract.root(); let id = contract.id(&salt, &root, &Contract::default_state_root()); @@ -617,7 +617,7 @@ mod tests { let test_balance: u64 = rng.next_u64(); let balances = vec![(test_asset_id, test_balance)]; let salt: Salt = rng.gen(); - let contract = Contract::from(Opcode::RET(0x10).to_bytes().to_vec()); + let contract = Contract::from(op::ret(0x10).to_bytes().to_vec()); let root = contract.root(); let id = contract.id(&salt, &root, &Contract::default_state_root()); diff --git a/crates/services/txpool/src/test_helpers.rs b/crates/services/txpool/src/test_helpers.rs index fb9ca3ff540..cda776d90a3 100644 --- a/crates/services/txpool/src/test_helpers.rs +++ b/crates/services/txpool/src/test_helpers.rs @@ -8,7 +8,7 @@ use fuel_core_types::{ CoinStatus, CompressedCoin, }, - fuel_asm::Opcode, + fuel_asm::op, fuel_crypto::rand::{ rngs::StdRng, Rng, @@ -84,7 +84,7 @@ pub(crate) fn random_predicate( utxo_id: Option, ) -> Input { // use predicate inputs to avoid expensive cryptography for signatures - let mut predicate_code: Vec = vec![Opcode::RET(1)].into_iter().collect(); + let mut predicate_code: Vec = vec![op::ret(1)].into_iter().collect(); // append some randomizing bytes after the predicate has already returned. predicate_code.push(rng.gen()); let owner = Input::predicate_owner(&predicate_code); diff --git a/crates/services/txpool/src/transaction_selector.rs b/crates/services/txpool/src/transaction_selector.rs index 6d0b8925677..6c0ead73aad 100644 --- a/crates/services/txpool/src/transaction_selector.rs +++ b/crates/services/txpool/src/transaction_selector.rs @@ -43,7 +43,7 @@ pub fn select_transactions( mod tests { use fuel_core_txpool as _; use fuel_core_types::{ - fuel_asm::Opcode, + fuel_asm::{op}, fuel_crypto::rand::{ thread_rng, Rng, @@ -78,7 +78,7 @@ mod tests { .iter() .map(|tx_gas| { TransactionBuilder::script( - vec![Opcode::RET(REG_ONE)].into_iter().collect(), + vec![op::ret(REG_ONE)].into_iter().collect(), vec![], ) .gas_price(tx_gas.price) diff --git a/crates/services/txpool/src/txpool/test_helpers.rs b/crates/services/txpool/src/txpool/test_helpers.rs index c857c5c4296..efa6ce24a4c 100644 --- a/crates/services/txpool/src/txpool/test_helpers.rs +++ b/crates/services/txpool/src/txpool/test_helpers.rs @@ -1,7 +1,7 @@ use fuel_core_types::{ blockchain::primitives::BlockHeight, entities::message::Message, - fuel_asm::Opcode, + fuel_asm::{op}, fuel_tx::{ Contract, ContractId, @@ -17,7 +17,7 @@ pub(crate) fn create_message_predicate_from_message( amount: Word, spent_block: Option, ) -> (Message, Input) { - let predicate = vec![Opcode::RET(1)].into_iter().collect::>(); + let predicate = vec![op::ret(1)].into_iter().collect::>(); let message = Message { sender: Default::default(), recipient: Input::predicate_owner(&predicate), diff --git a/tests/tests/contract.rs b/tests/tests/contract.rs index 1331c964112..0d8fa41b427 100644 --- a/tests/tests/contract.rs +++ b/tests/tests/contract.rs @@ -137,30 +137,30 @@ async fn can_get_message_proof() { let contract = vec![ // Save the ptr to the script data to register 16. // Start db key - Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), // Set the location in memory to write the bytes to. - Opcode::MOVI(0x11, 100), - Opcode::ALOC(0x11), - Opcode::ADDI(0x11, REG_HP, 1), - Opcode::MOVI(0x13, 2), + op::movi(0x11, 100), + op::aloc(0x11), + op::addi(0x11, REG_HP, 1), + op::movi(0x13, 2), // Write read to 0x11. // Write status to 0x30. // Get the db key the memory location in 0x10. // Read the number of slots in 0x13. - Opcode::SRWQ(0x11, 0x30, 0x10, 0x13), - Opcode::SCWQ(0x10, 0x31, 0x13), - Opcode::ADDI(0x14, 0x10, Bytes32::LEN as Immediate12), - Opcode::SWWQ(0x10, 0x32, 0x14, 0x13), - Opcode::SRWQ(0x11, 0x33, 0x10, 0x13), + op::srwq(0x11, 0x30, 0x10, 0x13), + op::scwq(0x10, 0x31, 0x13), + op::addi(0x14, 0x10, Bytes32::LEN.try_into().unwrap()), + op::swwq(0x10, 0x32, 0x14, 0x13), + op::srwq(0x11, 0x33, 0x10, 0x13), // Log out the data. - Opcode::LOG(0x30, 0x31, 0x32, 0x33), - Opcode::SWWQ(0x10, 0x30, 0x14, 0x13), - Opcode::SCWQ(0x10, 0x31, 0x13), - Opcode::LOG(0x30, 0x31, 0x00, 0x00), - Opcode::MULI(0x15, 0x13, 32), - Opcode::LOGD(0x00, 0x00, 0x11, 0x15), + op::log(0x30, 0x31, 0x32, 0x33), + op::swwq(0x10, 0x30, 0x14, 0x13), + op::scwq(0x10, 0x31, 0x13), + op::log(0x30, 0x31, 0x00, 0x00), + op::muli(0x15, 0x13, 32), + op::logd(0x00, 0x00, 0x11, 0x15), // Return from the contract. - Opcode::RET(REG_ONE), + op::ret(REG_ONE), ]; // Return. @@ -199,19 +199,19 @@ async fn can_get_message_proof() { // Save the ptr to the script data to register 16. // This will be used to read the contract id + two // empty params. So 32 + 8 + 8. - Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), - Opcode::ADDI(0x10, 0x10, (Bytes32::LEN * 3) as Immediate12), + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), + op::addi(0x10, 0x10, (Bytes32::LEN * 3).try_into().unwrap()), // Call the contract and forward no coins. - Opcode::CALL(0x10, REG_ZERO, REG_ZERO, REG_CGAS), + op::call(0x10, REG_ZERO, REG_ZERO, REG_CGAS), // Return. - Opcode::RET(REG_ONE), + op::ret(REG_ONE), ]; let script: Vec = script .iter() .flat_map(|op| u32::from(*op).to_be_bytes()) .collect(); - let predicate = Opcode::RET(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(REG_ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let coin_input = Input::coin_predicate( Default::default(), diff --git a/tests/tests/dap.rs b/tests/tests/dap.rs index 00cae0b2b1f..f9a61f29716 100644 --- a/tests/tests/dap.rs +++ b/tests/tests/dap.rs @@ -47,7 +47,7 @@ async fn reset() { assert_eq!(0x00, register); let result = client - .execute(id, &Opcode::ADDI(0x10, 0x10, 0xfa)) + .execute(id, &op::addi(0x10, 0x10, 0xfa)) .await .unwrap(); assert!(result); @@ -56,22 +56,22 @@ async fn reset() { assert_eq!(0xfa, register); let result = client - .execute(id, &Opcode::ADDI(0x11, 0x11, 0x08)) + .execute(id, &op::addi(0x11, 0x11, 0x08)) .await .unwrap(); assert!(result); - let result = client.execute(id, &Opcode::ALOC(0x11)).await.unwrap(); + let result = client.execute(id, &op::aloc(0x11)).await.unwrap(); assert!(result); let result = client - .execute(id, &Opcode::ADDI(0x11, REG_HP, 1)) + .execute(id, &op::addi(0x11, REG_HP, 1)) .await .unwrap(); assert!(result); let result = client - .execute(id, &Opcode::SW(0x11, 0x10, 0)) + .execute(id, &op::sw(0x11, 0x10, 0)) .await .unwrap(); assert!(result); diff --git a/tests/tests/messages.rs b/tests/tests/messages.rs index 6c7c04c1d24..48ef28e3329 100644 --- a/tests/tests/messages.rs +++ b/tests/tests/messages.rs @@ -44,7 +44,7 @@ async fn can_submit_genesis_message() { da_height: DaBlockHeight(0), }; let tx1 = - TransactionBuilder::script(vec![Opcode::RET(0)].into_iter().collect(), vec![]) + TransactionBuilder::script(vec![op::ret(0)].into_iter().collect(), vec![]) .gas_limit(100000) .add_unsigned_message_input( secret_key, @@ -244,28 +244,28 @@ async fn can_get_message_proof() { let mut contract = vec![ // Save the ptr to the script data to register 16. - Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), // Offset 16 by the length of bytes for the contract id // and two empty params. This will now point to the address // of the message recipient. - Opcode::ADDI(0x10, 0x10, starting_offset), + op::addi(0x10, 0x10, starting_offset), ]; contract.extend(args.iter().enumerate().flat_map(|(index, arg)| { [ // The length of the message data in memory. - Opcode::MOVI(0x11, arg.message_data.len() as u32), + op::movi(0x11, arg.message_data.len() as u32), // The index of the of the output message in the transactions outputs. - Opcode::MOVI(0x12, (index + 1) as u32), + op::movi(0x12, (index + 1) as u32), // The amount to send in coins. - Opcode::MOVI(0x13, 10), + op::movi(0x13, 10), // Send the message output. - Opcode::SMO(0x10, 0x11, 0x12, 0x13), + op::smo(0x10, 0x11, 0x12, 0x13), // Offset to the next recipient address (this recipient address + message data len) - Opcode::ADDI(0x10, 0x10, 32 + arg.message_data.len() as u16), + op::addi(0x10, 0x10, 32 + arg.message_data.len() as u16), ] })); // Return. - contract.push(Opcode::RET(REG_ONE)); + contract.push(op::ret(REG_ONE)); // Contract code. let bytecode: Witness = contract.into_iter().collect::>().into(); @@ -303,18 +303,18 @@ async fn can_get_message_proof() { // Save the ptr to the script data to register 16. // This will be used to read the contract id + two // empty params. So 32 + 8 + 8. - Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), // Call the contract and forward no coins. - Opcode::CALL(0x10, REG_ZERO, REG_ZERO, REG_CGAS), + op::call(0x10, REG_ZERO, REG_ZERO, REG_CGAS), // Return. - Opcode::RET(REG_ONE), + op::ret(REG_ONE), ]; let script: Vec = script .iter() .flat_map(|op| u32::from(*op).to_be_bytes()) .collect(); - let predicate = Opcode::RET(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(REG_ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let coin_input = Input::coin_predicate( Default::default(), diff --git a/tests/tests/metrics.rs b/tests/tests/metrics.rs index 7e775c255e0..20f8f209fc5 100644 --- a/tests/tests/metrics.rs +++ b/tests/tests/metrics.rs @@ -34,10 +34,10 @@ async fn test_metrics_endpoint() { .unwrap(); let script = vec![ - Opcode::ADDI(0x10, REG_ZERO, 0xca), - Opcode::ADDI(0x11, REG_ZERO, 0xba), - Opcode::LOG(0x10, 0x11, REG_ZERO, REG_ZERO), - Opcode::RET(REG_ONE), + op::addi(0x10, REG_ZERO, 0xca), + op::addi(0x11, REG_ZERO, 0xba), + op::log(0x10, 0x11, REG_ZERO, REG_ZERO), + op::ret(REG_ONE), ]; let script: Vec = script .iter() diff --git a/tests/tests/relayer.rs b/tests/tests/relayer.rs index ce29f9a26be..5276dbf9a8f 100644 --- a/tests/tests/relayer.rs +++ b/tests/tests/relayer.rs @@ -170,7 +170,7 @@ async fn messages_are_spendable_after_relayer_is_synced() { // attempt to spend the message downloaded from the relayer let tx = - TransactionBuilder::script(vec![Opcode::RET(0)].into_iter().collect(), vec![]) + TransactionBuilder::script(vec![op::ret(0)].into_iter().collect(), vec![]) .gas_limit(10_000) .gas_price(0) .add_unsigned_message_input(secret_key, sender, nonce, amount, vec![]) diff --git a/tests/tests/sync/helpers.rs b/tests/tests/sync/helpers.rs index f8ae62db7bf..1f7182297a9 100644 --- a/tests/tests/sync/helpers.rs +++ b/tests/tests/sync/helpers.rs @@ -22,7 +22,7 @@ use fuel_core_storage::{ StorageAsRef, }; use fuel_core_types::{ - fuel_asm::Opcode, + fuel_asm::Instruction, fuel_crypto::SecretKey, fuel_tx::{ Input, @@ -173,7 +173,7 @@ pub async fn make_nodes( let initial_coin = ChainConfig::initial_coin(secret, 10000, Some(utxo_id)); let tx = TransactionBuilder::script( - vec![Opcode::RET(REG_ONE)].into_iter().collect(), + vec![op::ret(REG_ONE)].into_iter().collect(), vec![], ) .gas_limit(100000) diff --git a/tests/tests/trigger_integration/hybrid.rs b/tests/tests/trigger_integration/hybrid.rs index 41bd187d818..a43c950df0c 100644 --- a/tests/tests/trigger_integration/hybrid.rs +++ b/tests/tests/trigger_integration/hybrid.rs @@ -118,7 +118,7 @@ async fn poa_hybrid_produces_nonempty_blocks_at_correct_rate() { for i in 0..200 { let mut tx = TransactionBuilder::script( - [Opcode::MOVI(0x10, i as Immediate18)].into_iter().collect(), + [op::movi(0x10, i)].into_iter().collect(), vec![], ); let _tx_id = client.submit(&tx.finalize().into()).await.unwrap(); diff --git a/tests/tests/trigger_integration/instant.rs b/tests/tests/trigger_integration/instant.rs index cccf6759384..8e740b5062d 100644 --- a/tests/tests/trigger_integration/instant.rs +++ b/tests/tests/trigger_integration/instant.rs @@ -42,7 +42,7 @@ async fn poa_instant_trigger_is_produces_instantly() { for i in 0..10usize { let mut tx = TransactionBuilder::script( - [Opcode::MOVI(0x10, i as Immediate18)].into_iter().collect(), + [op::movi(0x10, i.try_into().unwrap())].into_iter().collect(), vec![], ); let _tx_id = client.submit(&tx.finalize().into()).await.unwrap(); diff --git a/tests/tests/trigger_integration/interval.rs b/tests/tests/trigger_integration/interval.rs index 8d96b33818e..9629b51b08a 100644 --- a/tests/tests/trigger_integration/interval.rs +++ b/tests/tests/trigger_integration/interval.rs @@ -111,7 +111,7 @@ async fn poa_interval_produces_nonempty_blocks_at_correct_rate() { for i in 0..tx_count { let mut tx = TransactionBuilder::script( - [Opcode::MOVI(0x10, i as Immediate18)].into_iter().collect(), + [op::movi(0x10, i.try_into().unwrap())].into_iter().collect(), vec![], ); let _tx_id = client.submit(&tx.finalize().into()).await.unwrap(); diff --git a/tests/tests/trigger_integration/never.rs b/tests/tests/trigger_integration/never.rs index 4f98219add5..5003dc940a0 100644 --- a/tests/tests/trigger_integration/never.rs +++ b/tests/tests/trigger_integration/never.rs @@ -12,13 +12,12 @@ use fuel_core_client::client::{ }; use fuel_core_poa::Trigger; use fuel_core_types::{ - fuel_asm::Opcode, fuel_crypto::SecretKey, fuel_tx::{ Finalizable, TransactionBuilder, }, - secrecy::Secret, + secrecy::Secret, fuel_asm::op, }; use rand::{ rngs::StdRng, @@ -39,7 +38,7 @@ async fn poa_never_trigger_doesnt_produce_blocks() { for i in 0..10 { let mut tx = TransactionBuilder::script( - [Opcode::MOVI(0x10, i)].into_iter().collect(), + [op::movi(0x10, i)].into_iter().collect(), vec![], ); let _tx_id = client.submit(&tx.finalize().into()).await.unwrap(); diff --git a/tests/tests/tx.rs b/tests/tests/tx.rs index 24b8f4f5815..df9eaf22e82 100644 --- a/tests/tests/tx.rs +++ b/tests/tests/tx.rs @@ -47,10 +47,10 @@ fn basic_script_snapshot() { // Since this script is referenced in docs, snapshot the byte representation in-case opcodes // are reassigned in the future let script = vec![ - Opcode::ADDI(0x10, REG_ZERO, 0xca), - Opcode::ADDI(0x11, REG_ZERO, 0xba), - Opcode::LOG(0x10, 0x11, REG_ZERO, REG_ZERO), - Opcode::RET(REG_ONE), + op::addi(0x10, REG_ZERO, 0xca), + op::addi(0x11, REG_ZERO, 0xba), + op::log(0x10, 0x11, REG_ZERO, REG_ZERO), + op::ret(REG_ONE), ]; let script: Vec = script .iter() @@ -69,10 +69,10 @@ async fn dry_run_script() { let maturity = 0; let script = vec![ - Opcode::ADDI(0x10, REG_ZERO, 0xca), - Opcode::ADDI(0x11, REG_ZERO, 0xba), - Opcode::LOG(0x10, 0x11, REG_ZERO, REG_ZERO), - Opcode::RET(REG_ONE), + op::addi(0x10, REG_ZERO, 0xca), + op::addi(0x11, REG_ZERO, 0xba), + op::log(0x10, 0x11, REG_ZERO, REG_ZERO), + op::ret(REG_ONE), ]; let script: Vec = script .iter() @@ -159,10 +159,10 @@ async fn submit() { let maturity = 0; let script = vec![ - Opcode::ADDI(0x10, REG_ZERO, 0xca), - Opcode::ADDI(0x11, REG_ZERO, 0xba), - Opcode::LOG(0x10, 0x11, REG_ZERO, REG_ZERO), - Opcode::RET(REG_ONE), + op::addi(0x10, REG_ZERO, 0xca), + op::addi(0x11, REG_ZERO, 0xba), + op::log(0x10, 0x11, REG_ZERO, REG_ZERO), + op::ret(REG_ONE), ]; let script: Vec = script .iter() @@ -549,7 +549,7 @@ impl TestContext { to: Address, amount: u64, ) -> io::Result { - let script = Opcode::RET(0x10).to_bytes().to_vec(); + let script = op::ret(0x10).to_bytes().to_vec(); let tx = Transaction::script( 0, 1_000_000, diff --git a/tests/tests/tx/predicates.rs b/tests/tests/tx/predicates.rs index f5df55d53bf..47e29aab21f 100644 --- a/tests/tests/tx/predicates.rs +++ b/tests/tests/tx/predicates.rs @@ -57,7 +57,7 @@ async fn transaction_with_predicate_is_executed_when_feature_enabled() { let limit = 1000; let asset_id = rng.gen(); // make predicate return 1 which mean valid - let predicate = Opcode::RET(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(REG_ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let predicate_tx = TransactionBuilder::script(Default::default(), Default::default()) .add_input(Input::coin_predicate( @@ -112,7 +112,7 @@ async fn transaction_with_invalid_predicate_is_rejected_when_feature_is_enabled( let amount = 500; let asset_id = rng.gen(); // make predicate return 0 which means invalid - let predicate = Opcode::RET(REG_ZERO).to_bytes().to_vec(); + let predicate = op::ret(REG_ZERO).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let predicate_tx = TransactionBuilder::script(Default::default(), Default::default()) .add_input(Input::coin_predicate( diff --git a/tests/tests/tx/txn_status_subscription.rs b/tests/tests/tx/txn_status_subscription.rs index 31df7f0612e..37867a34827 100644 --- a/tests/tests/tx/txn_status_subscription.rs +++ b/tests/tests/tx/txn_status_subscription.rs @@ -25,15 +25,15 @@ async fn subscribe_txn_status() { let gas_limit = 1_000_000; let maturity = 0; - let create_script = |i: usize| { + let create_script = |i: u8| { // The first two scripts will run and the rest will fail. - let script = vec![Opcode::ADDI(0x11 - i, 0x10, 1), Opcode::RET(REG_ONE)]; + let script = vec![op::addi(0x11 - i, 0x10, 1), op::ret(REG_ONE)]; let script: Vec = script .iter() .flat_map(|op| u32::from(*op).to_be_bytes()) .collect(); - let predicate = Opcode::RET(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(REG_ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); // The third transaction needs to have a different input. let utxo_id = if i == 2 { 2 } else { 1 }; diff --git a/tests/tests/tx/utxo_validation.rs b/tests/tests/tx/utxo_validation.rs index 46c290a280a..6320031003b 100644 --- a/tests/tests/tx/utxo_validation.rs +++ b/tests/tests/tx/utxo_validation.rs @@ -34,7 +34,7 @@ async fn submit_utxo_verified_tx_with_min_gas_price() { .into_iter() .map(|i| { TransactionBuilder::script( - Opcode::RET(REG_ONE).to_bytes().into_iter().collect(), + op::ret(REG_ONE).to_bytes().into_iter().collect(), vec![], ) .gas_limit(10000) @@ -110,7 +110,7 @@ async fn submit_utxo_verified_tx_with_min_gas_price() { async fn submit_utxo_verified_tx_below_min_gas_price_fails() { // initialize transaction let tx = TransactionBuilder::script( - Opcode::RET(REG_ONE).to_bytes().into_iter().collect(), + op::ret(REG_ONE).to_bytes().into_iter().collect(), vec![], ) .gas_limit(100) @@ -140,7 +140,7 @@ async fn dry_run_override_utxo_validation() { let asset_id = rng.gen(); let tx = TransactionBuilder::script( - Opcode::RET(REG_ONE).to_bytes().into_iter().collect(), + op::ret(REG_ONE).to_bytes().into_iter().collect(), vec![], ) .gas_limit(10000) @@ -185,7 +185,7 @@ async fn dry_run_no_utxo_validation_override() { let asset_id = rng.gen(); // construct a tx with invalid inputs let tx = TransactionBuilder::script( - Opcode::RET(REG_ONE).to_bytes().into_iter().collect(), + op::ret(REG_ONE).to_bytes().into_iter().collect(), vec![], ) .gas_limit(1000) @@ -231,7 +231,7 @@ async fn concurrent_tx_submission_produces_expected_blocks() { .into_iter() .map(|i| { TransactionBuilder::script( - Opcode::RET(REG_ONE).to_bytes().into_iter().collect(), + op::ret(REG_ONE).to_bytes().into_iter().collect(), vec![], ) .gas_limit(10000) From 5d4608bac7f8d31ab0ee0f7923d42006cb993ccf Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Thu, 2 Feb 2023 07:43:21 +0200 Subject: [PATCH 2/6] fmt --- benches/benches/set/alu.rs | 90 +++++++------------ benches/benches/set/blockchain.rs | 9 +- benches/benches/set/flow.rs | 6 +- benches/benches/set/mem.rs | 11 ++- benches/benches/vm.rs | 2 +- benches/src/lib.rs | 5 +- crates/chain-config/src/config.rs | 2 +- crates/fuel-core/src/executor.rs | 18 +--- crates/fuel-core/src/service/genesis.rs | 2 +- .../txpool/src/transaction_selector.rs | 2 +- .../txpool/src/txpool/test_helpers.rs | 2 +- tests/tests/dap.rs | 5 +- tests/tests/messages.rs | 21 +++-- tests/tests/relayer.rs | 13 ++- tests/tests/trigger_integration/hybrid.rs | 6 +- tests/tests/trigger_integration/instant.rs | 4 +- tests/tests/trigger_integration/interval.rs | 4 +- tests/tests/trigger_integration/never.rs | 9 +- 18 files changed, 81 insertions(+), 130 deletions(-) diff --git a/benches/benches/set/alu.rs b/benches/benches/set/alu.rs index 37ff3d84d31..0f748da84d6 100644 --- a/benches/benches/set/alu.rs +++ b/benches/benches/set/alu.rs @@ -11,10 +11,8 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("add"), "add", - VmBench::new(op::add(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::add(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( @@ -33,10 +31,8 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("and"), "and", - VmBench::new(op::and(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::and(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( @@ -49,10 +45,8 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("div"), "div", - VmBench::new(op::div(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::div(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( @@ -65,10 +59,8 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("eq"), "eq", - VmBench::new(op::eq(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::eq(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( @@ -88,10 +80,8 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("gt"), "gt", - VmBench::new(op::gt(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::gt(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); { @@ -107,28 +97,22 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("lt"), "lt", - VmBench::new(op::lt(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::lt(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( &mut c.benchmark_group("mlog"), "mlog", - VmBench::new(op::mlog(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::mlog(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( &mut c.benchmark_group("mod"), "mod", - VmBench::new(op::mod_(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::mod_(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( @@ -154,19 +138,15 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("mroo"), "mroo", - VmBench::new(op::mroo(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::mroo(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( &mut c.benchmark_group("mul"), "mul", - VmBench::new(op::mul(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::mul(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( @@ -192,10 +172,8 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("or"), "or", - VmBench::new(op::or(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::or(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( @@ -208,10 +186,8 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("sll"), "sll", - VmBench::new(op::sll(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::sll(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( @@ -224,10 +200,8 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("srl"), "srl", - VmBench::new(op::srl(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::srl(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( @@ -240,10 +214,8 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("sub"), "sub", - VmBench::new(op::sub(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::sub(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( @@ -256,10 +228,8 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("xor"), "xor", - VmBench::new(op::xor(0x10, 0x11, 0x12)).with_prepare_script(vec![ - op::movi(0x11, 100000), - op::movi(0x12, 27), - ]), + VmBench::new(op::xor(0x10, 0x11, 0x12)) + .with_prepare_script(vec![op::movi(0x11, 100000), op::movi(0x12, 27)]), ); run_group_ref( diff --git a/benches/benches/set/blockchain.rs b/benches/benches/set/blockchain.rs index da2bd903c9a..43ce76adff5 100644 --- a/benches/benches/set/blockchain.rs +++ b/benches/benches/set/blockchain.rs @@ -313,15 +313,13 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("mint"), "mint", - VmBench::contract(rng, op::mint(REG_ZERO)) - .expect("failed to prepare contract"), + VmBench::contract(rng, op::mint(REG_ZERO)).expect("failed to prepare contract"), ); run_group_ref( &mut c.benchmark_group("burn"), "burn", - VmBench::contract(rng, op::mint(REG_ZERO)) - .expect("failed to prepare contract"), + VmBench::contract(rng, op::mint(REG_ZERO)).expect("failed to prepare contract"), ); run_group_ref( @@ -495,7 +493,6 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("time"), "time", - VmBench::new(op::time(0x11, 0x10)) - .with_prepare_script(vec![op::movi(0x10, 0)]), + VmBench::new(op::time(0x11, 0x10)).with_prepare_script(vec![op::movi(0x10, 0)]), ); } diff --git a/benches/benches/set/flow.rs b/benches/benches/set/flow.rs index 25fd02a689b..c2d01d74b7e 100644 --- a/benches/benches/set/flow.rs +++ b/benches/benches/set/flow.rs @@ -33,11 +33,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::jmp(0x10)).with_prepare_script(vec![op::movi(0x10, 10)]), ); - run_group_ref( - &mut c.benchmark_group("ji"), - "ji", - VmBench::new(op::ji(10)), - ); + run_group_ref(&mut c.benchmark_group("ji"), "ji", VmBench::new(op::ji(10))); run_group_ref( &mut c.benchmark_group("jne"), diff --git a/benches/benches/set/mem.rs b/benches/benches/set/mem.rs index ea6382af049..8e74e59ff6c 100644 --- a/benches/benches/set/mem.rs +++ b/benches/benches/set/mem.rs @@ -108,12 +108,11 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("mcpi"), "mcpi", - VmBench::new(op::mcpi(0x10, REG_ZERO, 4000)) - .with_prepare_script(vec![ - op::movi(0x11, 4000), - op::aloc(0x11), - op::addi(0x10, REG_HP, 1), - ]), + VmBench::new(op::mcpi(0x10, REG_ZERO, 4000)).with_prepare_script(vec![ + op::movi(0x11, 4000), + op::aloc(0x11), + op::addi(0x10, REG_HP, 1), + ]), ); let mut mem_meq = c.benchmark_group("meq"); diff --git a/benches/benches/vm.rs b/benches/benches/vm.rs index dca72fe5690..37084149b5c 100644 --- a/benches/benches/vm.rs +++ b/benches/benches/vm.rs @@ -11,7 +11,7 @@ use criterion::{ use fuel_core_benches::*; use fuel_core_storage::transactional::Transaction; -use fuel_core_types::fuel_asm::{Instruction}; +use fuel_core_types::fuel_asm::Instruction; use set::*; pub fn run_group_ref(group: &mut BenchmarkGroup, id: I, bench: VmBench) diff --git a/benches/src/lib.rs b/benches/src/lib.rs index 8d65d0aa8cd..84005e84a69 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -290,7 +290,10 @@ impl TryFrom for VmBenchPrepared { let mut db = db.unwrap_or_else(new_db); - if prepare_script.iter().any(|op| matches!(op, Instruction::RET(_))) { + if prepare_script + .iter() + .any(|op| matches!(op, Instruction::RET(_))) + { return Err(io::Error::new( io::ErrorKind::Other, "a prepare script should not call/return into different contexts.", diff --git a/crates/chain-config/src/config.rs b/crates/chain-config/src/config.rs index 95310b3b796..0a6eb739dd8 100644 --- a/crates/chain-config/src/config.rs +++ b/crates/chain-config/src/config.rs @@ -16,7 +16,7 @@ pub use state::*; mod tests { use fuel_core_types::{ blockchain::primitives::DaBlockHeight, - fuel_asm::{op}, + fuel_asm::op, fuel_types::{ AssetId, Bytes32, diff --git a/crates/fuel-core/src/executor.rs b/crates/fuel-core/src/executor.rs index 3db221712d6..f4b1ca63a32 100644 --- a/crates/fuel-core/src/executor.rs +++ b/crates/fuel-core/src/executor.rs @@ -1385,7 +1385,7 @@ mod tests { use fuel_core_types::{ blockchain::header::ConsensusHeader, entities::message::CheckedMessage, - fuel_asm::{op}, + fuel_asm::op, fuel_crypto::SecretKey, fuel_merkle::common::empty_sum_sha256, fuel_tx, @@ -3154,10 +3154,7 @@ mod tests { // verify a block 2 containing contract id from block 1, with wrong input contract utxo_id let (tx, contract_id) = create_contract(vec![], &mut rng); let tx2: Transaction = TxBuilder::new(2322) - .start_script( - vec![op::addi(0x10, REG_ZERO, 0), op::ret(1)], - vec![], - ) + .start_script(vec![op::addi(0x10, REG_ZERO, 0), op::ret(1)], vec![]) .contract_input(contract_id) .contract_output(&contract_id) .build() @@ -3171,10 +3168,7 @@ mod tests { }; let tx3: Transaction = TxBuilder::new(2322) - .start_script( - vec![op::addi(0x10, REG_ZERO, 1), op::ret(1)], - vec![], - ) + .start_script(vec![op::addi(0x10, REG_ZERO, 1), op::ret(1)], vec![]) .contract_input(contract_id) .contract_output(&contract_id) .build() @@ -3615,11 +3609,7 @@ mod tests { let mut rng = StdRng::seed_from_u64(1234); // return current block height - let script = vec![ - op::bhei(0x10), - op::time(0x11, 0x10), - op::ret(0x11), - ]; + let script = vec![op::bhei(0x10), op::time(0x11, 0x10), op::ret(0x11)]; let tx = TransactionBuilder::script(script.into_iter().collect(), vec![]) .gas_limit(10000) .add_unsigned_coin_input( diff --git a/crates/fuel-core/src/service/genesis.rs b/crates/fuel-core/src/service/genesis.rs index 5e41f596e09..0ab2f4d95dc 100644 --- a/crates/fuel-core/src/service/genesis.rs +++ b/crates/fuel-core/src/service/genesis.rs @@ -371,7 +371,7 @@ mod tests { DaBlockHeight, }, entities::coin::Coin, - fuel_asm::{op}, + fuel_asm::op, fuel_types::{ Address, AssetId, diff --git a/crates/services/txpool/src/transaction_selector.rs b/crates/services/txpool/src/transaction_selector.rs index 6c0ead73aad..b959f30bdf6 100644 --- a/crates/services/txpool/src/transaction_selector.rs +++ b/crates/services/txpool/src/transaction_selector.rs @@ -43,7 +43,7 @@ pub fn select_transactions( mod tests { use fuel_core_txpool as _; use fuel_core_types::{ - fuel_asm::{op}, + fuel_asm::op, fuel_crypto::rand::{ thread_rng, Rng, diff --git a/crates/services/txpool/src/txpool/test_helpers.rs b/crates/services/txpool/src/txpool/test_helpers.rs index efa6ce24a4c..8d496845efc 100644 --- a/crates/services/txpool/src/txpool/test_helpers.rs +++ b/crates/services/txpool/src/txpool/test_helpers.rs @@ -1,7 +1,7 @@ use fuel_core_types::{ blockchain::primitives::BlockHeight, entities::message::Message, - fuel_asm::{op}, + fuel_asm::op, fuel_tx::{ Contract, ContractId, diff --git a/tests/tests/dap.rs b/tests/tests/dap.rs index f9a61f29716..20f64de5817 100644 --- a/tests/tests/dap.rs +++ b/tests/tests/dap.rs @@ -70,10 +70,7 @@ async fn reset() { .unwrap(); assert!(result); - let result = client - .execute(id, &op::sw(0x11, 0x10, 0)) - .await - .unwrap(); + let result = client.execute(id, &op::sw(0x11, 0x10, 0)).await.unwrap(); assert!(result); let memory = client.register(id, 0x11).await.unwrap(); diff --git a/tests/tests/messages.rs b/tests/tests/messages.rs index 48ef28e3329..bb95386ea7f 100644 --- a/tests/tests/messages.rs +++ b/tests/tests/messages.rs @@ -43,17 +43,16 @@ async fn can_submit_genesis_message() { data: vec![rng.gen()], da_height: DaBlockHeight(0), }; - let tx1 = - TransactionBuilder::script(vec![op::ret(0)].into_iter().collect(), vec![]) - .gas_limit(100000) - .add_unsigned_message_input( - secret_key, - msg1.sender, - msg1.nonce, - msg1.amount, - msg1.data.clone(), - ) - .finalize_as_transaction(); + let tx1 = TransactionBuilder::script(vec![op::ret(0)].into_iter().collect(), vec![]) + .gas_limit(100000) + .add_unsigned_message_input( + secret_key, + msg1.sender, + msg1.nonce, + msg1.amount, + msg1.data.clone(), + ) + .finalize_as_transaction(); let mut node_config = Config::local_node(); node_config.chain_conf.initial_state = Some(StateConfig { diff --git a/tests/tests/relayer.rs b/tests/tests/relayer.rs index 5276dbf9a8f..b60e16bd568 100644 --- a/tests/tests/relayer.rs +++ b/tests/tests/relayer.rs @@ -169,13 +169,12 @@ async fn messages_are_spendable_after_relayer_is_synced() { srv.await_relayer_synced().await.unwrap(); // attempt to spend the message downloaded from the relayer - let tx = - TransactionBuilder::script(vec![op::ret(0)].into_iter().collect(), vec![]) - .gas_limit(10_000) - .gas_price(0) - .add_unsigned_message_input(secret_key, sender, nonce, amount, vec![]) - .add_output(Output::change(rng.gen(), 0, AssetId::BASE)) - .finalize(); + let tx = TransactionBuilder::script(vec![op::ret(0)].into_iter().collect(), vec![]) + .gas_limit(10_000) + .gas_price(0) + .add_unsigned_message_input(secret_key, sender, nonce, amount, vec![]) + .add_output(Output::change(rng.gen(), 0, AssetId::BASE)) + .finalize(); let status = client .submit_and_await_commit(&tx.clone().into()) diff --git a/tests/tests/trigger_integration/hybrid.rs b/tests/tests/trigger_integration/hybrid.rs index a43c950df0c..1312605931a 100644 --- a/tests/tests/trigger_integration/hybrid.rs +++ b/tests/tests/trigger_integration/hybrid.rs @@ -117,10 +117,8 @@ async fn poa_hybrid_produces_nonempty_blocks_at_correct_rate() { let client = FuelClient::from(srv.bound_address); for i in 0..200 { - let mut tx = TransactionBuilder::script( - [op::movi(0x10, i)].into_iter().collect(), - vec![], - ); + let mut tx = + TransactionBuilder::script([op::movi(0x10, i)].into_iter().collect(), vec![]); let _tx_id = client.submit(&tx.finalize().into()).await.unwrap(); } diff --git a/tests/tests/trigger_integration/instant.rs b/tests/tests/trigger_integration/instant.rs index 8e740b5062d..ecc670a1ddb 100644 --- a/tests/tests/trigger_integration/instant.rs +++ b/tests/tests/trigger_integration/instant.rs @@ -42,7 +42,9 @@ async fn poa_instant_trigger_is_produces_instantly() { for i in 0..10usize { let mut tx = TransactionBuilder::script( - [op::movi(0x10, i.try_into().unwrap())].into_iter().collect(), + [op::movi(0x10, i.try_into().unwrap())] + .into_iter() + .collect(), vec![], ); let _tx_id = client.submit(&tx.finalize().into()).await.unwrap(); diff --git a/tests/tests/trigger_integration/interval.rs b/tests/tests/trigger_integration/interval.rs index 9629b51b08a..0dbd2ca6b46 100644 --- a/tests/tests/trigger_integration/interval.rs +++ b/tests/tests/trigger_integration/interval.rs @@ -111,7 +111,9 @@ async fn poa_interval_produces_nonempty_blocks_at_correct_rate() { for i in 0..tx_count { let mut tx = TransactionBuilder::script( - [op::movi(0x10, i.try_into().unwrap())].into_iter().collect(), + [op::movi(0x10, i.try_into().unwrap())] + .into_iter() + .collect(), vec![], ); let _tx_id = client.submit(&tx.finalize().into()).await.unwrap(); diff --git a/tests/tests/trigger_integration/never.rs b/tests/tests/trigger_integration/never.rs index 5003dc940a0..ec039512408 100644 --- a/tests/tests/trigger_integration/never.rs +++ b/tests/tests/trigger_integration/never.rs @@ -12,12 +12,13 @@ use fuel_core_client::client::{ }; use fuel_core_poa::Trigger; use fuel_core_types::{ + fuel_asm::op, fuel_crypto::SecretKey, fuel_tx::{ Finalizable, TransactionBuilder, }, - secrecy::Secret, fuel_asm::op, + secrecy::Secret, }; use rand::{ rngs::StdRng, @@ -37,10 +38,8 @@ async fn poa_never_trigger_doesnt_produce_blocks() { let client = FuelClient::from(srv.bound_address); for i in 0..10 { - let mut tx = TransactionBuilder::script( - [op::movi(0x10, i)].into_iter().collect(), - vec![], - ); + let mut tx = + TransactionBuilder::script([op::movi(0x10, i)].into_iter().collect(), vec![]); let _tx_id = client.submit(&tx.finalize().into()).await.unwrap(); tokio::time::advance(tokio::time::Duration::new(10, 0)).await; let resp = client From 8a26e6fed99719f763ad2e49a680a02bc7cea3a3 Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Thu, 2 Feb 2023 15:33:15 +0200 Subject: [PATCH 3/6] Fix missing import in test helpers --- tests/tests/sync/helpers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/sync/helpers.rs b/tests/tests/sync/helpers.rs index 1f7182297a9..c8e519f1f68 100644 --- a/tests/tests/sync/helpers.rs +++ b/tests/tests/sync/helpers.rs @@ -22,7 +22,7 @@ use fuel_core_storage::{ StorageAsRef, }; use fuel_core_types::{ - fuel_asm::Instruction, + fuel_asm::op, fuel_crypto::SecretKey, fuel_tx::{ Input, From 639e746e2f3d54bc4dd440715ab6e63d095ea544 Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Fri, 3 Feb 2023 12:46:12 +0200 Subject: [PATCH 4/6] Update with latest REG_* -> RegId::* changes --- Cargo.lock | 40 +++++++------- README.md | 8 +-- benches/benches/set/alu.rs | 7 +-- benches/benches/set/blockchain.rs | 34 ++++++------ benches/benches/set/crypto.rs | 7 ++- benches/benches/set/flow.rs | 25 ++++----- benches/benches/set/mem.rs | 27 +++++----- benches/src/lib.rs | 8 +-- crates/fuel-core/src/executor.rs | 54 ++++++++----------- .../txpool/src/transaction_selector.rs | 12 ++--- tests/tests/contract.rs | 12 ++--- tests/tests/dap.rs | 7 +-- tests/tests/messages.rs | 9 ++-- tests/tests/metrics.rs | 9 ++-- tests/tests/sync/helpers.rs | 8 +-- tests/tests/tx.rs | 25 +++++---- tests/tests/tx/predicates.rs | 5 +- tests/tests/tx/txn_status_subscription.rs | 5 +- tests/tests/tx/utxo_validation.rs | 11 ++-- 19 files changed, 144 insertions(+), 169 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efa5a674f52..aeedb2783fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2275,8 +2275,8 @@ checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" [[package]] name = "fuel-asm" -version = "0.25.2" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" +version = "0.25.3" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" dependencies = [ "fuel-types", "serde", @@ -2715,8 +2715,8 @@ dependencies = [ [[package]] name = "fuel-crypto" -version = "0.25.2" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" +version = "0.25.3" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" dependencies = [ "borrown", "coins-bip32", @@ -2733,8 +2733,8 @@ dependencies = [ [[package]] name = "fuel-merkle" -version = "0.25.2" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" +version = "0.25.3" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" dependencies = [ "digest 0.10.6", "fuel-storage", @@ -2746,13 +2746,13 @@ dependencies = [ [[package]] name = "fuel-storage" -version = "0.25.2" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" +version = "0.25.3" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" [[package]] name = "fuel-tx" -version = "0.25.2" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" +version = "0.25.3" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" dependencies = [ "derivative", "fuel-asm", @@ -2768,8 +2768,8 @@ dependencies = [ [[package]] name = "fuel-types" -version = "0.25.2" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" +version = "0.25.3" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" dependencies = [ "rand 0.8.5", "serde", @@ -2777,8 +2777,8 @@ dependencies = [ [[package]] name = "fuel-vm" -version = "0.25.2" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#8250dfd70d2f8d4875416743716ecb043d2acafe" +version = "0.25.3" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" dependencies = [ "anyhow", "bitflags", @@ -3266,9 +3266,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.23" +version = "0.14.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" +checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" dependencies = [ "bytes", "futures-channel", @@ -4233,9 +4233,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.6.4" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2e212582ede878b109755efd0773a4f0f4ec851584cf0aefbeb4d9ecc114822" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" dependencies = [ "adler", ] @@ -6465,9 +6465,9 @@ dependencies = [ [[package]] name = "tinyvec_macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" diff --git a/README.md b/README.md index eed3dd992ab..b6f12761767 100644 --- a/README.md +++ b/README.md @@ -158,10 +158,10 @@ The service expects a mutation defined as `submit` that receives a [Transaction] This example will execute a script that represents the following sequence of [ASM](https://github.com/FuelLabs/fuel-asm): ```rs -ADDI(0x10, REG_ZERO, 0xca), -ADDI(0x11, REG_ZERO, 0xba), -LOG(0x10, 0x11, REG_ZERO, REG_ZERO), -RET(REG_ONE), +ADDI(0x10, RegId::ZERO, 0xca), +ADDI(0x11, RegId::ZERO, 0xba), +LOG(0x10, 0x11, RegId::ZERO, RegId::ZERO), +RET(RegId::ONE), ``` ```console diff --git a/benches/benches/set/alu.rs b/benches/benches/set/alu.rs index 0f748da84d6..667f6a748bf 100644 --- a/benches/benches/set/alu.rs +++ b/benches/benches/set/alu.rs @@ -2,10 +2,7 @@ use super::run_group_ref; use criterion::Criterion; use fuel_core_benches::*; -use fuel_core_types::{ - fuel_asm::*, - fuel_vm::consts::REG_ZERO, -}; +use fuel_core_types::fuel_asm::*; pub fn run(c: &mut Criterion) { run_group_ref( @@ -89,7 +86,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("gtf"), "gtf", - VmBench::new(op::gtf_args(0x10, REG_ZERO.into(), GTFArgs::ScriptData)) + VmBench::new(op::gtf_args(0x10, RegId::ZERO.into(), GTFArgs::ScriptData)) .with_data(data), ); } diff --git a/benches/benches/set/blockchain.rs b/benches/benches/set/blockchain.rs index 43ce76adff5..bfe8854671e 100644 --- a/benches/benches/set/blockchain.rs +++ b/benches/benches/set/blockchain.rs @@ -64,7 +64,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("sww"), "sww", - VmBench::contract(rng, op::sww(REG_ZERO, 0x29, REG_ONE)) + VmBench::contract(rng, op::sww(RegId::ZERO, 0x29, RegId::ONE)) .expect("failed to prepare contract") .with_prepare_db(move |mut db| { let mut key = Bytes32::zeroed(); @@ -102,7 +102,7 @@ pub fn run(c: &mut Criterion) { op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), ]; - let mut bench = VmBench::contract(rng, op::scwq(0x11, 0x29, REG_ONE)) + let mut bench = VmBench::contract(rng, op::scwq(0x11, 0x29, RegId::ONE)) .expect("failed to prepare contract") .with_post_call(post_call) .with_prepare_db(move |mut db| { @@ -126,7 +126,7 @@ pub fn run(c: &mut Criterion) { op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), ]; - let mut bench = VmBench::contract(rng, op::swwq(0x10, 0x11, 0x20, REG_ONE)) + let mut bench = VmBench::contract(rng, op::swwq(0x10, 0x11, 0x20, RegId::ONE)) .expect("failed to prepare contract") .with_post_call(post_call) .with_prepare_db(move |mut db| { @@ -169,7 +169,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut call, format!("{i}"), - VmBench::new(op::call(0x10, REG_ZERO, 0x11, 0x12)) + VmBench::new(op::call(0x10, RegId::ZERO, 0x11, 0x12)) .with_contract_code(code) .with_data(data) .with_prepare_script(prepare_script), @@ -210,7 +210,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut ldc, format!("{i}"), - VmBench::new(op::ldc(0x10, REG_ZERO, 0x13)) + VmBench::new(op::ldc(0x10, RegId::ZERO, 0x13)) .with_contract_code(code) .with_data(data) .with_prepare_script(prepare_script), @@ -249,7 +249,7 @@ pub fn run(c: &mut Criterion) { op::add(0x15, 0x15, 0x15), op::addi(0x15, 0x15, 32), op::aloc(0x15), - op::addi(0x15, REG_HP, 1), + op::addi(0x15, RegId::HP, 1), ]; ccp.throughput(Throughput::Bytes(i)); @@ -257,7 +257,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut ccp, format!("{i}"), - VmBench::new(op::ccp(0x15, 0x10, REG_ZERO, 0x13)) + VmBench::new(op::ccp(0x15, 0x10, RegId::ZERO, 0x13)) .with_contract_code(code) .with_data(data) .with_prepare_script(prepare_script), @@ -303,23 +303,25 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("bhsh"), "bhsh", - VmBench::new(op::bhsh(0x10, REG_ZERO)).with_prepare_script(vec![ + VmBench::new(op::bhsh(0x10, RegId::ZERO)).with_prepare_script(vec![ op::movi(0x10, Bytes32::LEN.try_into().unwrap()), op::aloc(0x10), - op::addi(0x10, REG_HP, 1), + op::addi(0x10, RegId::HP, 1), ]), ); run_group_ref( &mut c.benchmark_group("mint"), "mint", - VmBench::contract(rng, op::mint(REG_ZERO)).expect("failed to prepare contract"), + VmBench::contract(rng, op::mint(RegId::ZERO)) + .expect("failed to prepare contract"), ); run_group_ref( &mut c.benchmark_group("burn"), "burn", - VmBench::contract(rng, op::mint(REG_ZERO)).expect("failed to prepare contract"), + VmBench::contract(rng, op::mint(RegId::ZERO)) + .expect("failed to prepare contract"), ); run_group_ref( @@ -328,7 +330,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::cb(0x10)).with_prepare_script(vec![ op::movi(0x10, Bytes32::LEN.try_into().unwrap()), op::aloc(0x10), - op::addi(0x10, REG_HP, 1), + op::addi(0x10, RegId::HP, 1), ]), ); @@ -364,7 +366,7 @@ pub fn run(c: &mut Criterion) { }); let coin_output = Output::variable(Address::zeroed(), 100, AssetId::zeroed()); input.outputs.push(coin_output); - let predicate = op::ret(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(RegId::ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let coin_input = Input::coin_predicate( Default::default(), @@ -400,7 +402,7 @@ pub fn run(c: &mut Criterion) { op::gtf_args(0x16, 0x00, GTFArgs::ScriptData), op::movi(0x15, 2000), op::aloc(0x15), - op::addi(0x14, REG_HP, 1), + op::addi(0x14, RegId::HP, 1), ]); run_group_ref(&mut c.benchmark_group("croo"), "croo", input); } @@ -438,7 +440,7 @@ pub fn run(c: &mut Criterion) { .copied() .chain(vec![2u8; i as usize]), ); - let predicate = op::ret(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(RegId::ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let coin_input = Input::coin_predicate( Default::default(), @@ -472,7 +474,7 @@ pub fn run(c: &mut Criterion) { op::muli(0x15, 0x15, 32), op::addi(0x15, 0x15, 1), op::aloc(0x15), - op::addi(0x14, REG_HP, 1), + op::addi(0x14, RegId::HP, 1), ]; let mut bench = VmBench::contract(rng, op::srwq(0x14, 0x11, 0x27, 0x16)) .expect("failed to prepare contract") diff --git a/benches/benches/set/crypto.rs b/benches/benches/set/crypto.rs index d8a2fed16eb..31003ecabb9 100644 --- a/benches/benches/set/crypto.rs +++ b/benches/benches/set/crypto.rs @@ -6,7 +6,6 @@ use fuel_core_types::{ fuel_asm::*, fuel_crypto::*, fuel_types::*, - fuel_vm::consts::*, }; use rand::{ rngs::StdRng, @@ -30,7 +29,7 @@ pub fn run(c: &mut Criterion) { op::addi(0x22, 0x21, message.as_ref().len().try_into().unwrap()), op::movi(0x10, PublicKey::LEN.try_into().unwrap()), op::aloc(0x10), - op::addi(0x11, REG_HP, 1), + op::addi(0x11, RegId::HP, 1), ]) .with_data(signature.iter().chain(message.iter()).copied().collect()), ); @@ -42,7 +41,7 @@ pub fn run(c: &mut Criterion) { .with_prepare_script(vec![ op::movi(0x10, Bytes32::LEN.try_into().unwrap()), op::aloc(0x10), - op::addi(0x10, REG_HP, 1), + op::addi(0x10, RegId::HP, 1), op::movi(0x11, 32), ]) .with_data(signature.iter().chain(message.iter()).copied().collect()), @@ -55,7 +54,7 @@ pub fn run(c: &mut Criterion) { .with_prepare_script(vec![ op::movi(0x10, Bytes32::LEN.try_into().unwrap()), op::aloc(0x10), - op::addi(0x10, REG_HP, 1), + op::addi(0x10, RegId::HP, 1), op::movi(0x11, 32), ]) .with_data(signature.iter().chain(message.iter()).copied().collect()), diff --git a/benches/benches/set/flow.rs b/benches/benches/set/flow.rs index c2d01d74b7e..ceb096754c5 100644 --- a/benches/benches/set/flow.rs +++ b/benches/benches/set/flow.rs @@ -7,10 +7,7 @@ use criterion::{ Throughput, }; use fuel_core_benches::*; -use fuel_core_types::{ - fuel_asm::*, - fuel_vm::consts::*, -}; +use fuel_core_types::fuel_asm::*; use rand::{ rngs::StdRng, SeedableRng, @@ -38,32 +35,32 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("jne"), "jne", - VmBench::new(op::jne(REG_ZERO, REG_ONE, 0x10)) + VmBench::new(op::jne(RegId::ZERO, RegId::ONE, 0x10)) .with_prepare_script(vec![op::movi(0x10, 10)]), ); run_group_ref( &mut c.benchmark_group("jnei"), "jnei", - VmBench::new(op::jnei(REG_ZERO, REG_ONE, 10)), + VmBench::new(op::jnei(RegId::ZERO, RegId::ONE, 10)), ); run_group_ref( &mut c.benchmark_group("jnzi"), "jnzi", - VmBench::new(op::jnzi(REG_ONE, 10)), + VmBench::new(op::jnzi(RegId::ONE, 10)), ); run_group_ref( &mut c.benchmark_group("ret_script"), "ret_script", - VmBench::new(op::ret(REG_ONE)), + VmBench::new(op::ret(RegId::ONE)), ); run_group_ref( &mut c.benchmark_group("ret_contract"), "ret_contract", - VmBench::contract(rng, op::ret(REG_ONE)).unwrap(), + VmBench::contract(rng, op::ret(RegId::ONE)).unwrap(), ); let mut retd_contract = c.benchmark_group("retd_contract"); @@ -72,7 +69,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut retd_contract, format!("{i}"), - VmBench::contract(rng, op::retd(REG_ONE, 0x10)) + VmBench::contract(rng, op::retd(RegId::ONE, 0x10)) .unwrap() .with_post_call(vec![op::movi(0x10, *i)]), ); @@ -85,7 +82,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut retd_script, format!("{i}"), - VmBench::contract(rng, op::retd(REG_ONE, 0x10)) + VmBench::contract(rng, op::retd(RegId::ONE, 0x10)) .unwrap() .with_post_call(vec![op::movi(0x10, *i)]), ); @@ -95,13 +92,13 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("rvrt_script"), "rvrt_script", - VmBench::new(op::rvrt(REG_ONE)), + VmBench::new(op::rvrt(RegId::ONE)), ); run_group_ref( &mut c.benchmark_group("rvrt_contract"), "rvrt_contract", - VmBench::contract(rng, op::ret(REG_ONE)).unwrap(), + VmBench::contract(rng, op::ret(RegId::ONE)).unwrap(), ); run_group_ref( @@ -116,7 +113,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut logd, format!("{i}"), - VmBench::new(op::logd(0x10, 0x11, REG_ZERO, 0x13)) + VmBench::new(op::logd(0x10, 0x11, RegId::ZERO, 0x13)) .with_prepare_script(vec![op::movi(0x13, *i)]), ); } diff --git a/benches/benches/set/mem.rs b/benches/benches/set/mem.rs index 8e74e59ff6c..d946e9379d8 100644 --- a/benches/benches/set/mem.rs +++ b/benches/benches/set/mem.rs @@ -7,30 +7,27 @@ use criterion::{ Throughput, }; use fuel_core_benches::*; -use fuel_core_types::{ - fuel_asm::*, - fuel_vm::consts::*, -}; +use fuel_core_types::fuel_asm::*; pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("lb"), "lb", - VmBench::new(op::lb(0x10, REG_ONE, 10)), + VmBench::new(op::lb(0x10, RegId::ONE, 10)), ); run_group_ref( &mut c.benchmark_group("lw"), "lw", - VmBench::new(op::lw(0x10, REG_ONE, 10)), + VmBench::new(op::lw(0x10, RegId::ONE, 10)), ); run_group_ref( &mut c.benchmark_group("sb"), "sb", VmBench::new(op::sb(0x10, 0x11, 0)).with_prepare_script(vec![ - op::aloc(REG_ONE), - op::addi(0x10, REG_HP, 1), + op::aloc(RegId::ONE), + op::addi(0x10, RegId::HP, 1), op::movi(0x11, 50), ]), ); @@ -41,7 +38,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::sw(0x10, 0x11, 0)).with_prepare_script(vec![ op::movi(0x10, 8), op::aloc(0x10), - op::addi(0x10, REG_HP, 1), + op::addi(0x10, RegId::HP, 1), op::movi(0x11, 50), ]), ); @@ -69,7 +66,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::mcl(0x10, 0x11)).with_prepare_script(vec![ op::movi(0x11, *i), op::aloc(0x11), - op::addi(0x10, REG_HP, 1), + op::addi(0x10, RegId::HP, 1), ]), ); } @@ -84,7 +81,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::mcli(0x10, *i)).with_prepare_script(vec![ op::movi(0x11, *i), op::aloc(0x11), - op::addi(0x10, REG_HP, 1), + op::addi(0x10, RegId::HP, 1), ]), ); } @@ -96,10 +93,10 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut mem_mcp, format!("{i}"), - VmBench::new(op::mcp(0x10, REG_ZERO, 0x11)).with_prepare_script(vec![ + VmBench::new(op::mcp(0x10, RegId::ZERO, 0x11)).with_prepare_script(vec![ op::movi(0x11, *i), op::aloc(0x11), - op::addi(0x10, REG_HP, 1), + op::addi(0x10, RegId::HP, 1), ]), ); } @@ -108,10 +105,10 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("mcpi"), "mcpi", - VmBench::new(op::mcpi(0x10, REG_ZERO, 4000)).with_prepare_script(vec![ + VmBench::new(op::mcpi(0x10, RegId::ZERO, 4000)).with_prepare_script(vec![ op::movi(0x11, 4000), op::aloc(0x11), - op::addi(0x10, REG_HP, 1), + op::addi(0x10, RegId::HP, 1), ]), ); diff --git a/benches/src/lib.rs b/benches/src/lib.rs index 84005e84a69..50b33b8a930 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -122,7 +122,7 @@ impl VmBench { let bench = Self::new(instruction); let program = iter::once(instruction) - .chain(iter::once(op::ret(REG_ONE))) + .chain(iter::once(op::ret(RegId::ONE))) .collect::>(); let program = Witness::from(program); @@ -162,7 +162,7 @@ impl VmBench { let prepare_call = PrepareCall { ra: RegId::new(0x10), - rb: REG_ZERO, + rb: RegId::ZERO, rc: RegId::new(0x11), rd: RegId::new(0x12), }; @@ -302,14 +302,14 @@ impl TryFrom for VmBenchPrepared { let prepare_script = prepare_script .into_iter() - .chain(iter::once(op::ret(REG_ONE))) + .chain(iter::once(op::ret(RegId::ONE))) .chain(iter::once(instruction)) .collect(); let mut tx = TransactionBuilder::script(prepare_script, data); if let Some(contract) = dummy_contract { - let code = iter::once(op::ret(REG_ONE)); + let code = iter::once(op::ret(RegId::ONE)); let code: Vec = code.collect(); let code = Contract::from(code); let root = code.root(); diff --git a/crates/fuel-core/src/executor.rs b/crates/fuel-core/src/executor.rs index f4b1ca63a32..04d4c12ca75 100644 --- a/crates/fuel-core/src/executor.rs +++ b/crates/fuel-core/src/executor.rs @@ -44,7 +44,10 @@ use fuel_core_types::{ }, message::Message, }, - fuel_asm::Word, + fuel_asm::{ + RegId, + Word, + }, fuel_tx::{ field::{ Inputs, @@ -72,7 +75,6 @@ use fuel_core_types::{ IntoChecked, ScriptCheckedMetadata, }, - consts::REG_SP, interpreter::{ CheckedMetadata, ExecutableTransaction, @@ -1113,7 +1115,7 @@ impl Executor { backtrace.contract(), backtrace.registers(), backtrace.call_stack(), - hex::encode(&backtrace.memory()[..backtrace.registers()[REG_SP] as usize]), // print stack + hex::encode(&backtrace.memory()[..backtrace.registers()[RegId::SP] as usize]), // print stack ); } } @@ -1410,13 +1412,6 @@ mod tests { Salt, }, fuel_vm::{ - consts::{ - REG_CGAS, - REG_FP, - REG_ONE, - REG_PC, - REG_ZERO, - }, script_with_data_offset, util::test_helpers::TestBuilder as TxBuilder, Call, @@ -1442,17 +1437,17 @@ mod tests { let (create, contract_id) = create_contract( vec![ // load amount of coins to 0x10 - op::addi(0x10, REG_FP, CallFrame::a_offset().try_into().unwrap()), + op::addi(0x10, RegId::FP, CallFrame::a_offset().try_into().unwrap()), op::lw(0x10, 0x10, 0), // load asset id to 0x11 - op::addi(0x11, REG_FP, CallFrame::b_offset().try_into().unwrap()), + op::addi(0x11, RegId::FP, CallFrame::b_offset().try_into().unwrap()), op::lw(0x11, 0x11, 0), // load address to 0x12 op::addi(0x12, 0x11, 32), // load output index (0) to 0x13 - op::addi(0x13, REG_ZERO, 0), + op::addi(0x13, RegId::ZERO, 0), op::tro(0x12, 0x13, 0x10, 0x11), - op::ret(REG_ONE), + op::ret(RegId::ONE), ] .into_iter() .collect::>(), @@ -1468,8 +1463,8 @@ mod tests { // set reg 0x12 to call amount op::movi(0x12, variable_transfer_amount), // call contract without any tokens to transfer in (3rd arg arbitrary when 2nd is zero) - op::call(0x10, 0x12, 0x11, REG_CGAS), - op::ret(REG_ONE), + op::call(0x10, 0x12, 0x11, RegId::CGAS), + op::ret(RegId::ONE), ], ConsensusParameters::DEFAULT.tx_offset() ); @@ -1627,10 +1622,7 @@ mod tests { mod coinbase { use super::*; - use fuel_core_types::{ - fuel_asm::GTFArgs, - fuel_vm::consts::REG_HP, - }; + use fuel_core_types::fuel_asm::GTFArgs; #[test] fn executor_commits_transactions_with_non_zero_coinbase_generation() { @@ -1780,9 +1772,9 @@ mod tests { // Allocate 32 bytes on the heap. op::aloc(0x11), // Store the pointer to the beginning of the free memory into - // register `0x10`. It requires shifting of `REG_HP` by 1 to point + // register `0x10`. It requires shifting of `RegId::HP` by 1 to point // on the free memory. - op::addi(0x10, REG_HP, 1), + op::addi(0x10, RegId::HP, 1), // Store `config_coinbase` `Address` into MEM[$0x10; 32]. op::cb(0x10), // Store the pointer on the beginning of script data into register `0x12`. @@ -2266,7 +2258,7 @@ mod tests { let mut rng = StdRng::seed_from_u64(2322u64); let tx = TransactionBuilder::script( - vec![op::ret(REG_ONE)].into_iter().collect(), + vec![op::ret(RegId::ONE)].into_iter().collect(), vec![], ) .add_unsigned_coin_input( @@ -2751,7 +2743,7 @@ mod tests { let (create, contract_id) = create_contract(vec![], &mut rng); // The transaction with invalid script. let non_modify_state_tx: Transaction = TxBuilder::new(2322) - .start_script(vec![op::add(REG_PC, REG_PC, REG_PC)], vec![]) + .start_script(vec![op::add(RegId::PC, RegId::PC, RegId::PC)], vec![]) .contract_input(contract_id) .contract_output(&contract_id) .build() @@ -2823,8 +2815,8 @@ mod tests { // Create a contract that modifies the state let (create, contract_id) = create_contract( vec![ - // Sets the state STATE[0x1; 32] = value of `REG_PC`; - op::sww(0x1, 0x29, REG_PC), + // Sets the state STATE[0x1; 32] = value of `RegId::PC`; + op::sww(0x1, 0x29, RegId::PC), op::ret(1), ] .into_iter() @@ -2843,8 +2835,8 @@ mod tests { op::movi(0x11, data_offset), // Set register `0x12` with `transfer_amount` op::movi(0x12, transfer_amount as u32), - op::call(0x10, 0x12, 0x11, REG_CGAS), - op::ret(REG_ONE), + op::call(0x10, 0x12, 0x11, RegId::CGAS), + op::ret(RegId::ONE), ], ConsensusParameters::DEFAULT.tx_offset() ); @@ -2994,7 +2986,7 @@ mod tests { let starting_block = BlockHeight::from(5u64); let tx = TransactionBuilder::script( - vec![op::ret(REG_ONE)].into_iter().collect(), + vec![op::ret(RegId::ONE)].into_iter().collect(), vec![], ) .add_unsigned_coin_input( @@ -3154,7 +3146,7 @@ mod tests { // verify a block 2 containing contract id from block 1, with wrong input contract utxo_id let (tx, contract_id) = create_contract(vec![], &mut rng); let tx2: Transaction = TxBuilder::new(2322) - .start_script(vec![op::addi(0x10, REG_ZERO, 0), op::ret(1)], vec![]) + .start_script(vec![op::addi(0x10, RegId::ZERO, 0), op::ret(1)], vec![]) .contract_input(contract_id) .contract_output(&contract_id) .build() @@ -3168,7 +3160,7 @@ mod tests { }; let tx3: Transaction = TxBuilder::new(2322) - .start_script(vec![op::addi(0x10, REG_ZERO, 1), op::ret(1)], vec![]) + .start_script(vec![op::addi(0x10, RegId::ZERO, 1), op::ret(1)], vec![]) .contract_input(contract_id) .contract_output(&contract_id) .build() diff --git a/crates/services/txpool/src/transaction_selector.rs b/crates/services/txpool/src/transaction_selector.rs index b959f30bdf6..1a288df6472 100644 --- a/crates/services/txpool/src/transaction_selector.rs +++ b/crates/services/txpool/src/transaction_selector.rs @@ -43,7 +43,10 @@ pub fn select_transactions( mod tests { use fuel_core_txpool as _; use fuel_core_types::{ - fuel_asm::op, + fuel_asm::{ + op, + RegId, + }, fuel_crypto::rand::{ thread_rng, Rng, @@ -53,10 +56,7 @@ mod tests { Output, TransactionBuilder, }, - fuel_vm::{ - checked_transaction::builder::TransactionBuilderExt, - consts::REG_ONE, - }, + fuel_vm::checked_transaction::builder::TransactionBuilderExt, }; use itertools::Itertools; use std::sync::Arc; @@ -78,7 +78,7 @@ mod tests { .iter() .map(|tx_gas| { TransactionBuilder::script( - vec![op::ret(REG_ONE)].into_iter().collect(), + vec![op::ret(RegId::ONE)].into_iter().collect(), vec![], ) .gas_price(tx_gas.price) diff --git a/tests/tests/contract.rs b/tests/tests/contract.rs index 0d8fa41b427..3a8ac2edc2b 100644 --- a/tests/tests/contract.rs +++ b/tests/tests/contract.rs @@ -119,8 +119,6 @@ fn key(i: u8) -> Bytes32 { #[tokio::test] async fn can_get_message_proof() { - use fuel_core_types::fuel_vm::consts::*; - let config = Config::local_node(); let coin = config .chain_conf @@ -141,7 +139,7 @@ async fn can_get_message_proof() { // Set the location in memory to write the bytes to. op::movi(0x11, 100), op::aloc(0x11), - op::addi(0x11, REG_HP, 1), + op::addi(0x11, RegId::HP, 1), op::movi(0x13, 2), // Write read to 0x11. // Write status to 0x30. @@ -160,7 +158,7 @@ async fn can_get_message_proof() { op::muli(0x15, 0x13, 32), op::logd(0x00, 0x00, 0x11, 0x15), // Return from the contract. - op::ret(REG_ONE), + op::ret(RegId::ONE), ]; // Return. @@ -202,16 +200,16 @@ async fn can_get_message_proof() { op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), op::addi(0x10, 0x10, (Bytes32::LEN * 3).try_into().unwrap()), // Call the contract and forward no coins. - op::call(0x10, REG_ZERO, REG_ZERO, REG_CGAS), + op::call(0x10, RegId::ZERO, RegId::ZERO, RegId::CGAS), // Return. - op::ret(REG_ONE), + op::ret(RegId::ONE), ]; let script: Vec = script .iter() .flat_map(|op| u32::from(*op).to_be_bytes()) .collect(); - let predicate = op::ret(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(RegId::ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let coin_input = Input::coin_predicate( Default::default(), diff --git a/tests/tests/dap.rs b/tests/tests/dap.rs index 20f64de5817..b2f17e3d30b 100644 --- a/tests/tests/dap.rs +++ b/tests/tests/dap.rs @@ -3,10 +3,7 @@ use fuel_core::service::{ FuelService, }; use fuel_core_client::client::FuelClient; -use fuel_core_types::{ - fuel_asm::*, - fuel_vm::consts::*, -}; +use fuel_core_types::fuel_asm::*; use std::convert::TryInto; #[tokio::test] @@ -65,7 +62,7 @@ async fn reset() { assert!(result); let result = client - .execute(id, &op::addi(0x11, REG_HP, 1)) + .execute(id, &op::addi(0x11, RegId::HP, 1)) .await .unwrap(); assert!(result); diff --git a/tests/tests/messages.rs b/tests/tests/messages.rs index bb95386ea7f..166d003516e 100644 --- a/tests/tests/messages.rs +++ b/tests/tests/messages.rs @@ -19,7 +19,6 @@ use fuel_core_types::{ fuel_asm::*, fuel_crypto::*, fuel_tx::*, - fuel_vm::consts::*, }; use rand::{ rngs::StdRng, @@ -264,7 +263,7 @@ async fn can_get_message_proof() { ] })); // Return. - contract.push(op::ret(REG_ONE)); + contract.push(op::ret(RegId::ONE)); // Contract code. let bytecode: Witness = contract.into_iter().collect::>().into(); @@ -304,16 +303,16 @@ async fn can_get_message_proof() { // empty params. So 32 + 8 + 8. op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), // Call the contract and forward no coins. - op::call(0x10, REG_ZERO, REG_ZERO, REG_CGAS), + op::call(0x10, RegId::ZERO, RegId::ZERO, RegId::CGAS), // Return. - op::ret(REG_ONE), + op::ret(RegId::ONE), ]; let script: Vec = script .iter() .flat_map(|op| u32::from(*op).to_be_bytes()) .collect(); - let predicate = op::ret(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(RegId::ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let coin_input = Input::coin_predicate( Default::default(), diff --git a/tests/tests/metrics.rs b/tests/tests/metrics.rs index 20f8f209fc5..e5566589e5d 100644 --- a/tests/tests/metrics.rs +++ b/tests/tests/metrics.rs @@ -8,7 +8,6 @@ use fuel_core_client::client::FuelClient; use fuel_core_types::{ fuel_asm::*, fuel_tx::*, - fuel_vm::consts::*, }; use tempfile::TempDir; @@ -34,10 +33,10 @@ async fn test_metrics_endpoint() { .unwrap(); let script = vec![ - op::addi(0x10, REG_ZERO, 0xca), - op::addi(0x11, REG_ZERO, 0xba), - op::log(0x10, 0x11, REG_ZERO, REG_ZERO), - op::ret(REG_ONE), + op::addi(0x10, RegId::ZERO, 0xca), + op::addi(0x11, RegId::ZERO, 0xba), + op::log(0x10, 0x11, RegId::ZERO, RegId::ZERO), + op::ret(RegId::ONE), ]; let script: Vec = script .iter() diff --git a/tests/tests/sync/helpers.rs b/tests/tests/sync/helpers.rs index c8e519f1f68..7219201e286 100644 --- a/tests/tests/sync/helpers.rs +++ b/tests/tests/sync/helpers.rs @@ -22,7 +22,10 @@ use fuel_core_storage::{ StorageAsRef, }; use fuel_core_types::{ - fuel_asm::op, + fuel_asm::{ + op, + RegId, + }, fuel_crypto::SecretKey, fuel_tx::{ Input, @@ -36,7 +39,6 @@ use fuel_core_types::{ Address, Bytes32, }, - fuel_vm::consts::REG_ONE, secrecy::Secret, services::block_importer::ImportResult, }; @@ -173,7 +175,7 @@ pub async fn make_nodes( let initial_coin = ChainConfig::initial_coin(secret, 10000, Some(utxo_id)); let tx = TransactionBuilder::script( - vec![op::ret(REG_ONE)].into_iter().collect(), + vec![op::ret(RegId::ONE)].into_iter().collect(), vec![], ) .gas_limit(100000) diff --git a/tests/tests/tx.rs b/tests/tests/tx.rs index df9eaf22e82..06cb7df49af 100644 --- a/tests/tests/tx.rs +++ b/tests/tests/tx.rs @@ -23,7 +23,6 @@ use fuel_core_types::{ }, fuel_asm::*, fuel_tx::*, - fuel_vm::consts::*, services::executor::ExecutionBlock, tai64::Tai64, }; @@ -47,10 +46,10 @@ fn basic_script_snapshot() { // Since this script is referenced in docs, snapshot the byte representation in-case opcodes // are reassigned in the future let script = vec![ - op::addi(0x10, REG_ZERO, 0xca), - op::addi(0x11, REG_ZERO, 0xba), - op::log(0x10, 0x11, REG_ZERO, REG_ZERO), - op::ret(REG_ONE), + op::addi(0x10, RegId::ZERO, 0xca), + op::addi(0x11, RegId::ZERO, 0xba), + op::log(0x10, 0x11, RegId::ZERO, RegId::ZERO), + op::ret(RegId::ONE), ]; let script: Vec = script .iter() @@ -69,10 +68,10 @@ async fn dry_run_script() { let maturity = 0; let script = vec![ - op::addi(0x10, REG_ZERO, 0xca), - op::addi(0x11, REG_ZERO, 0xba), - op::log(0x10, 0x11, REG_ZERO, REG_ZERO), - op::ret(REG_ONE), + op::addi(0x10, RegId::ZERO, 0xca), + op::addi(0x11, RegId::ZERO, 0xba), + op::log(0x10, 0x11, RegId::ZERO, RegId::ZERO), + op::ret(RegId::ONE), ]; let script: Vec = script .iter() @@ -159,10 +158,10 @@ async fn submit() { let maturity = 0; let script = vec![ - op::addi(0x10, REG_ZERO, 0xca), - op::addi(0x11, REG_ZERO, 0xba), - op::log(0x10, 0x11, REG_ZERO, REG_ZERO), - op::ret(REG_ONE), + op::addi(0x10, RegId::ZERO, 0xca), + op::addi(0x11, RegId::ZERO, 0xba), + op::log(0x10, 0x11, RegId::ZERO, RegId::ZERO), + op::ret(RegId::ONE), ]; let script: Vec = script .iter() diff --git a/tests/tests/tx/predicates.rs b/tests/tests/tx/predicates.rs index 47e29aab21f..5e181b4154d 100644 --- a/tests/tests/tx/predicates.rs +++ b/tests/tests/tx/predicates.rs @@ -7,7 +7,6 @@ use fuel_core_types::{ field::Outputs, *, }, - fuel_vm::consts::*, }; use rand::{ rngs::StdRng, @@ -57,7 +56,7 @@ async fn transaction_with_predicate_is_executed_when_feature_enabled() { let limit = 1000; let asset_id = rng.gen(); // make predicate return 1 which mean valid - let predicate = op::ret(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(RegId::ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let predicate_tx = TransactionBuilder::script(Default::default(), Default::default()) .add_input(Input::coin_predicate( @@ -112,7 +111,7 @@ async fn transaction_with_invalid_predicate_is_rejected_when_feature_is_enabled( let amount = 500; let asset_id = rng.gen(); // make predicate return 0 which means invalid - let predicate = op::ret(REG_ZERO).to_bytes().to_vec(); + let predicate = op::ret(RegId::ZERO).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); let predicate_tx = TransactionBuilder::script(Default::default(), Default::default()) .add_input(Input::coin_predicate( diff --git a/tests/tests/tx/txn_status_subscription.rs b/tests/tests/tx/txn_status_subscription.rs index 37867a34827..124e4d4c5ac 100644 --- a/tests/tests/tx/txn_status_subscription.rs +++ b/tests/tests/tx/txn_status_subscription.rs @@ -8,7 +8,6 @@ use fuel_core_client::client::FuelClient; use fuel_core_types::{ fuel_asm::*, fuel_tx::*, - fuel_vm::consts::*, }; use futures::StreamExt; @@ -27,13 +26,13 @@ async fn subscribe_txn_status() { let create_script = |i: u8| { // The first two scripts will run and the rest will fail. - let script = vec![op::addi(0x11 - i, 0x10, 1), op::ret(REG_ONE)]; + let script = vec![op::addi(0x11 - i, 0x10, 1), op::ret(RegId::ONE)]; let script: Vec = script .iter() .flat_map(|op| u32::from(*op).to_be_bytes()) .collect(); - let predicate = op::ret(REG_ONE).to_bytes().to_vec(); + let predicate = op::ret(RegId::ONE).to_bytes().to_vec(); let owner = Input::predicate_owner(&predicate); // The third transaction needs to have a different input. let utxo_id = if i == 2 { 2 } else { 1 }; diff --git a/tests/tests/tx/utxo_validation.rs b/tests/tests/tx/utxo_validation.rs index 6320031003b..01b8ad0cba6 100644 --- a/tests/tests/tx/utxo_validation.rs +++ b/tests/tests/tx/utxo_validation.rs @@ -13,7 +13,6 @@ use fuel_core_types::{ fuel_asm::*, fuel_crypto::*, fuel_tx::*, - fuel_vm::consts::*, }; use futures::future::join_all; use itertools::Itertools; @@ -34,7 +33,7 @@ async fn submit_utxo_verified_tx_with_min_gas_price() { .into_iter() .map(|i| { TransactionBuilder::script( - op::ret(REG_ONE).to_bytes().into_iter().collect(), + op::ret(RegId::ONE).to_bytes().into_iter().collect(), vec![], ) .gas_limit(10000) @@ -110,7 +109,7 @@ async fn submit_utxo_verified_tx_with_min_gas_price() { async fn submit_utxo_verified_tx_below_min_gas_price_fails() { // initialize transaction let tx = TransactionBuilder::script( - op::ret(REG_ONE).to_bytes().into_iter().collect(), + op::ret(RegId::ONE).to_bytes().into_iter().collect(), vec![], ) .gas_limit(100) @@ -140,7 +139,7 @@ async fn dry_run_override_utxo_validation() { let asset_id = rng.gen(); let tx = TransactionBuilder::script( - op::ret(REG_ONE).to_bytes().into_iter().collect(), + op::ret(RegId::ONE).to_bytes().into_iter().collect(), vec![], ) .gas_limit(10000) @@ -185,7 +184,7 @@ async fn dry_run_no_utxo_validation_override() { let asset_id = rng.gen(); // construct a tx with invalid inputs let tx = TransactionBuilder::script( - op::ret(REG_ONE).to_bytes().into_iter().collect(), + op::ret(RegId::ONE).to_bytes().into_iter().collect(), vec![], ) .gas_limit(1000) @@ -231,7 +230,7 @@ async fn concurrent_tx_submission_produces_expected_blocks() { .into_iter() .map(|i| { TransactionBuilder::script( - op::ret(REG_ONE).to_bytes().into_iter().collect(), + op::ret(RegId::ONE).to_bytes().into_iter().collect(), vec![], ) .gas_limit(10000) From 90ffdd583657cc48f989666c80db62a47e1a5360 Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Fri, 3 Feb 2023 17:43:49 +0200 Subject: [PATCH 5/6] Track fuel-vm changes: vm.instruction(op::*(...) -> .into() <- ) removal --- Cargo.lock | 14 +++++++------- benches/benches/set/alu.rs | 2 +- benches/benches/vm.rs | 2 +- benches/src/lib.rs | 4 ++-- crates/fuel-core/src/schema/dap.rs | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aeedb2783fd..bf4f8a222a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2276,7 +2276,7 @@ checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" [[package]] name = "fuel-asm" version = "0.25.3" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#c8b6ad168792051061825faf5af5ca475252b723" dependencies = [ "fuel-types", "serde", @@ -2716,7 +2716,7 @@ dependencies = [ [[package]] name = "fuel-crypto" version = "0.25.3" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#c8b6ad168792051061825faf5af5ca475252b723" dependencies = [ "borrown", "coins-bip32", @@ -2734,7 +2734,7 @@ dependencies = [ [[package]] name = "fuel-merkle" version = "0.25.3" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#c8b6ad168792051061825faf5af5ca475252b723" dependencies = [ "digest 0.10.6", "fuel-storage", @@ -2747,12 +2747,12 @@ dependencies = [ [[package]] name = "fuel-storage" version = "0.25.3" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#c8b6ad168792051061825faf5af5ca475252b723" [[package]] name = "fuel-tx" version = "0.25.3" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#c8b6ad168792051061825faf5af5ca475252b723" dependencies = [ "derivative", "fuel-asm", @@ -2769,7 +2769,7 @@ dependencies = [ [[package]] name = "fuel-types" version = "0.25.3" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#c8b6ad168792051061825faf5af5ca475252b723" dependencies = [ "rand 0.8.5", "serde", @@ -2778,7 +2778,7 @@ dependencies = [ [[package]] name = "fuel-vm" version = "0.25.3" -source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#7939bcbdabcce04b08c8fc49f47dec62eddec928" +source = "git+https://github.com/FuelLabs/fuel-vm/?branch=mitchmindtree/monorepo-fuel-asm-refactor#c8b6ad168792051061825faf5af5ca475252b723" dependencies = [ "anyhow", "bitflags", diff --git a/benches/benches/set/alu.rs b/benches/benches/set/alu.rs index 667f6a748bf..8659e6c45c5 100644 --- a/benches/benches/set/alu.rs +++ b/benches/benches/set/alu.rs @@ -86,7 +86,7 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("gtf"), "gtf", - VmBench::new(op::gtf_args(0x10, RegId::ZERO.into(), GTFArgs::ScriptData)) + VmBench::new(op::gtf_args(0x10, RegId::ZERO, GTFArgs::ScriptData)) .with_data(data), ); } diff --git a/benches/benches/vm.rs b/benches/benches/vm.rs index 37084149b5c..8ba78d30e63 100644 --- a/benches/benches/vm.rs +++ b/benches/benches/vm.rs @@ -43,7 +43,7 @@ where vm.prepare_call(ra, rb, rc, rd).unwrap(); } _ => { - black_box(vm.instruction((*instruction).into()).unwrap()); + black_box(vm.instruction(*instruction).unwrap()); } } vm.reset_vm_state(diff); diff --git a/benches/src/lib.rs b/benches/src/lib.rs index 50b33b8a930..de21ec261e7 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -394,7 +394,7 @@ impl TryFrom for VmBenchPrepared { vm.prepare_call(ra, rb, rc, rd) .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; for instruction in post_call { - vm.instruction(instruction.into()).unwrap(); + vm.instruction(instruction).unwrap(); } } @@ -406,7 +406,7 @@ impl TryFrom for VmBenchPrepared { vm.prepare_call(ra, rb, rc, rd).unwrap(); } _ => { - vm.instruction(instruction.into()).unwrap(); + vm.instruction(instruction).unwrap(); } } let storage_diff = vm.storage_diff(); diff --git a/crates/fuel-core/src/schema/dap.rs b/crates/fuel-core/src/schema/dap.rs index c36a64e4f28..ce5d9fb6533 100644 --- a/crates/fuel-core/src/schema/dap.rs +++ b/crates/fuel-core/src/schema/dap.rs @@ -149,7 +149,7 @@ impl ConcreteStorage { pub fn exec(&mut self, id: &ID, op: Instruction) -> Result<(), InterpreterError> { self.vm .get_mut(id) - .map(|vm| vm.instruction(op.into())) + .map(|vm| vm.instruction(op)) .transpose()? .map(|_| ()) .ok_or_else(|| { From d4a8cd73aa9806b17c6cb1fa205019faebf151af Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Tue, 7 Feb 2023 22:11:07 +0200 Subject: [PATCH 6/6] Update to fuel-vm 0.26.0 --- Cargo.lock | 36 ++++++++++++++++++------------------ Cargo.toml | 4 ++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 10791f95c6c..72d9d3f2ad8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2269,9 +2269,9 @@ checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" [[package]] name = "fuel-asm" -version = "0.25.3" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dbd44608c617570330c4039ec4bd747178dadbadcab08dffb92552eef07db0d" +checksum = "7df7be33ffb99e92e8c76a25de7d6460566822420ee86e59d2214eec58e90a1d" dependencies = [ "fuel-types", "serde", @@ -2709,9 +2709,9 @@ dependencies = [ [[package]] name = "fuel-crypto" -version = "0.25.3" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9cf3e72a4c284736abff5044c524730f3636bc54581ac48122923064007bce" +checksum = "46f09781cbc54fc422456e1bc0c7b3101d879d848cc13992aeae60d088cf1bbd" dependencies = [ "borrown", "coins-bip32", @@ -2728,9 +2728,9 @@ dependencies = [ [[package]] name = "fuel-merkle" -version = "0.25.3" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae61a2b45f8cc5e4ca3137d1041138125d93c04051449a36b484c2fd7c32fc41" +checksum = "c54de90857ac30eee21c9bbc60e0e6701c0d21913418f6c8be88d0ea8d1cded9" dependencies = [ "digest 0.10.6", "fuel-storage", @@ -2742,15 +2742,15 @@ dependencies = [ [[package]] name = "fuel-storage" -version = "0.25.3" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20ffcfef458127e461a22f7355b31cce17407ee3e80568a71591502bee98b4d4" +checksum = "b93354a7d1ba3de35a3073237eebf492df9c76a4bf4ccfc4af8ed76fee2b164f" [[package]] name = "fuel-tx" -version = "0.25.3" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a14d2d28da679cbbb6bbfc35098362789f243db051fe097404b403724c4e660a" +checksum = "f0da1d6c6886e670e0c37da53f7b73935712ea346d216d275d0e72b81c2eb982" dependencies = [ "derivative", "fuel-asm", @@ -2766,9 +2766,9 @@ dependencies = [ [[package]] name = "fuel-types" -version = "0.25.3" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a162badbc642e3b820878e27c8cdc71393378bcf56db2f53f1603e1bccc74250" +checksum = "b6a893af21a88f56f912964c734d007c9d46224146e3e9877262a39e25135fa3" dependencies = [ "rand 0.8.5", "serde", @@ -2776,9 +2776,9 @@ dependencies = [ [[package]] name = "fuel-vm" -version = "0.25.3" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef54b86c2e41652d114657fb6f42945b74103192199e264507700690f6883c33" +checksum = "dfbc26d8221b5d40f4ac24a6d566475416665443adae5b6a9cedc3712d7bc185" dependencies = [ "anyhow", "bitflags", @@ -3105,7 +3105,7 @@ dependencies = [ "hash32", "rustc_version", "serde", - "spin 0.9.4", + "spin 0.9.5", "stable_deref_trait", ] @@ -4299,7 +4299,7 @@ dependencies = [ "log", "memchr", "mime", - "spin 0.9.4", + "spin 0.9.5", "version_check", ] @@ -6161,9 +6161,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spin" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +checksum = "7dccf47db1b41fa1573ed27ccf5e08e3ca771cb994f776668c5ebda893b248fc" dependencies = [ "lock_api", ] diff --git a/Cargo.toml b/Cargo.toml index e110446ad36..481fbc40f75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,8 +74,8 @@ fuel-core-tests = { version = "0.0.0", path = "./tests" } fuel-core-xtask = { version = "0.0.0", path = "./xtask" } # Fuel dependencies -fuel-vm = { version = "0.25" } -fuel-vm-private = { version = "0.25", package = "fuel-vm" } +fuel-vm = { version = "0.26" } +fuel-vm-private = { version = "0.26", package = "fuel-vm" } # Common dependencies anyhow = "1.0"