From 11fd90a14d48ab363a297cec267b3f91327502f5 Mon Sep 17 00:00:00 2001 From: Nick Furfaro Date: Wed, 31 Aug 2022 06:59:45 -0600 Subject: [PATCH] Refactor std::tx to use gtf intrinsic (#2482) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add all gtf const values * cleanup: remove offset consts and doc comments * refactor: update tx_type() * refactor: update tx_script_gas_price() * refactor: update tx_script_gas_limit() * refactor: update tx_maturity() * refactor: remove tx_byte_price() * refactor: update tx_script_length() * refactor: update tx_script_data_length() * refactor: update tx_inputs_count() * refactor: update tx_outputs_count() * refactor: update tx_witnesses_count() * refactor: update tx_receipts_root() * refactor: update tx_script_start_pointer() * refactor: update tx_script_data_start_pointer() * refactor: update tx_script_data() * refactor: update tx_script_bytecode() * refactor: update tx_input_pointer() * refactor: update & rename tx_input_type() * refactor: update tx_input_owner() * cleanup" remove redundant tx_input_type() function * refactor: update tx_predicate_data_start_pointer() * refactor: rename get_predicate_data() * refactor: update fn predicate_data() to be generic * feat: add fn tx_coin_predicate_data_start_pointer() * refactor: update tx_output_pointer() * refactor: update tx_output_type() * refactor: remove tx_output_type_from_pointer() * refactor: update tx_output_amount() * refactor: update fn tx_id() * refactor: hardcode index 0 for tx field getters * fix: refactor predicate_data & fix implementation * docs: add GTF hex values to function docs * docs: commment out consts and make into comments * Revert "docs: commment out consts and make into comments" This reverts commit bdca7bbf36e83881595ca4150258d9b6dabdd74c. * cleanup * cleanup: consts * feat: add witness related functions to tx * feat: add mod inputs to std * Docs: Add high level module docs * refactor: remove unused imports * refactor: move all input consts to imputs.sw * refactor: remove input-related stuff from tx.sw * refactor: move inputs to inputs.sw * refactor: complete move of inputs * reafactor: input owner functions * refactor: move input predicate data func to inputs * refactor: extract 2 predicate data functions * feat: add fn input_coin_output_index * feat: add fn input_coin_amount() * chore: cleanup * refactor: switch to using __gtf intrinsic * fix: update calls to read() with turbofish * refactor: use read() consistently * fix: semicolon * fixup * refactor: make tx_gas_price() general-purpose * refactor: use gtf for fn tx_type() * refactor: make tx_gas_limit() general purpose * refactor: make tx_maturity() general purpose. * refactor: make tx_inputs_count() general purpose. * fix: use correct type for __gtf * refactor: fix tx_script length to return an option. * refactor: switch tx_script_data_length() to return option * refactor: update fn tx_outputs_count() to use gtf * refactor: make inputs/outputs count fns general * refactor: update fn tx_receipts_root() return type * refactor: update fn tx_script_data_start_pointer() return type * docs: add comments to tx_type() * chore: cleanup * feat: make fn tx_input_pointer() general purpose * fix: add GTF_OUTPUT_TYPE const * feat: refactor tx_id() to use gtf intrinsic * feat: refactor fn tx_input_type() to use gtf * refactor: switch fn tx_input_owner() to use gtf * refactor: make predicate_data() use gtf intrinsic * refactor: make tx_output_pointer() general purpose * refactor: use gtf intrinsic in tx_output_type() * refactor: update tx_output_amount() to use gtf * refactor: revert rather than returning None * feat: add fn tx_witness() * docs: add notes * fix: uncomment const GTF_OUTPUT_TYPE * refactor: change tx_type to return enum * fixup * refactor: rename tx_witness to tx_witness_pointer * refactor: add enum Output and modify tx_output_type * refactor: complete tx refactor with new enum types * refactor: update token.sw to handle enum returns from tx.sw * refactor: update auth.sw to handle enum returns from tx.sw * fix: update calls to read() * fix: add get_predicate_data() back * test: update tx_field tests * cleanup * refactor:start to move funcs to inputs module * refactor: split out all inputs related things * feat: add outputs module and refactor * cleanup * refactor: move & rename tx_outputs_count() * fix: changes to fix compile errors * fix: changes to fix compile errors * fix: update token & auth modules * fix: cleanup duplicate function * fix: update read() calls with type annotations * test: update tests to handles stdlib changes * chore: update test/ cargo manifest & lock * chore: update sdk-harness/ cargo manifest & tests * chore: update forc/ cargo manifest & lock * chore: update forc-pkg/ & sway-core/ cargo manifests & lock * chore: update sway-types/ cargo manifest & lock * chore: update test-sig-gen-util/ cargo manifest & lock * chore: update fuel-core in ci.yaml * cleanup: remove x.. opcodes from allocated_ops.rs * fix: complete removal of X.. opcodes from allocated_ops * chore: remove X.. opcodes from virtual_ops and mod.rs * resolve type annotation * refactor: remove byte_price & static_contracts * chore: bump fuel-core to 0.10.1 in ci.yml * fix: trying to update harness.rs in e2e tests * chore: add builder feature to fuel-tx dep * test: fix test harness * style: clippy * fix: remove X.. opcodes from op_codes.rs * fix: remove X.. opcodes from sway-parse/op_codes * fix: remove byte_price from parameters.rs * chore: commit updated cargo lockfile * fix: improve fn naming consistency * test: set index to 0 * chore: update lockfile * test: fix tests to work with patched SDK * chore: restore cargo manifest file to patchless version * test: update auth testing contract * test: update tx_fields tests * chore: patch SDK with local branch * temp: add logging to repro while-loop bug * fixup: temp logs * chore: bump to SDK v0.21 * test: update tests to use new wallet api * chore: bump forc-util * chore: fix merge-conflict in cargo.lock * test: fix some tx_field tests * cleanup * test: cleanup tx_output_type test * Remove unused deps * Remove more unused deps * Restore some deps * Fix can_get_script_start_offset test * fix get_tx_id test * fix can_get_tx_output_type test * Fix can_get_tx_input_coin_owner test * Disable mint/transfer tests and hopefully resolve the unused deps issue * Re-enable the token tests as they actually work now with a fix to token.sw * Some clean up and removing untested functions * Add some useful comments and return None as the owner of a message input * remove dead constants * fmt * update the lock file * Update the SDK version for forc new * cleanup: remove logging from token.sw * cleanup: remove stale TODO from test * style: consolidate imports in test file * Update comments for output_amount to point to a github issue * Using if let instead of a match statement * Link to github issue for testing * Update some constants based on the old spec until the new spec is implemented Co-authored-by: Alex Hansen Co-authored-by: Mohammad Fawaz Co-authored-by: João Matos --- .github/workflows/ci.yml | 8 +- Cargo.lock | 725 ++++++++++++------ forc-pkg/Cargo.toml | 4 +- forc-pkg/src/pkg.rs | 4 +- forc-plugins/forc-client/Cargo.toml | 6 +- forc-plugins/forc-client/src/ops/deploy/op.rs | 4 - forc-plugins/forc-client/src/ops/run/op.rs | 5 +- .../forc-client/src/ops/run/parameters.rs | 5 +- forc/Cargo.toml | 2 +- forc/src/utils/defaults.rs | 2 +- sway-ast/src/expr/op_code.rs | 6 - sway-core/Cargo.toml | 8 +- sway-core/src/asm_lang/allocated_ops.rs | 18 - sway-core/src/asm_lang/mod.rs | 60 -- sway-core/src/asm_lang/virtual_ops.rs | 74 +- .../match_expression/analysis/pattern.rs | 4 +- sway-lib-std/src/chain/auth.sw | 36 +- sway-lib-std/src/inputs.sw | 160 ++++ sway-lib-std/src/lib.sw | 2 + sway-lib-std/src/outputs.sw | 131 ++++ sway-lib-std/src/storage.sw | 4 +- sway-lib-std/src/token.sw | 20 +- sway-lib-std/src/tx.sw | 407 ++++------ sway-parse/src/expr/op_code.rs | 6 - sway-types/Cargo.toml | 6 +- test-sig-gen-util/Cargo.toml | 6 +- test/Cargo.toml | 6 +- test/src/e2e_vm_tests/harness.rs | 38 +- test/src/sdk-harness/Cargo.toml | 9 +- .../test_artifacts/tx_contract/src/main.sw | 56 +- .../src/sdk-harness/test_projects/auth/mod.rs | 10 +- .../sdk-harness/test_projects/context/mod.rs | 10 +- .../test_projects/exponentiation/mod.rs | 3 +- .../sdk-harness/test_projects/logging/mod.rs | 1 - .../sdk-harness/test_projects/methods/mod.rs | 3 +- .../predicate_data_simple/mod.rs | 18 +- .../predicate_data_simple/src/main.sw | 4 +- .../predicate_data_struct/mod.rs | 18 +- .../predicate_data_struct/src/main.sw | 4 +- .../test_projects/reentrancy/mod.rs | 5 +- .../test_projects/script_data/mod.rs | 1 - .../test_projects/token_ops/mod.rs | 5 +- .../test_projects/tx_fields/mod.rs | 103 +-- 43 files changed, 1139 insertions(+), 868 deletions(-) create mode 100644 sway-lib-std/src/inputs.sw create mode 100644 sway-lib-std/src/outputs.sw diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f7d7e6f9c2..c1efbc72895 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -117,8 +117,8 @@ jobs: args: --debug --path ./forc - name: Install Forc plugins run: | - cargo install --debug --path ./forc-plugins/forc-fmt - cargo install --debug --path ./forc-plugins/forc-lsp + cargo install --debug --path ./forc-plugins/forc-fmt + cargo install --debug --path ./forc-plugins/forc-lsp cargo install --debug --path ./forc-plugins/forc-explore cargo install --debug --path ./forc-plugins/forc-client - name: Install mdbook-forc-documenter @@ -231,7 +231,7 @@ jobs: runs-on: ubuntu-latest services: fuel-core: - image: ghcr.io/fuellabs/fuel-core:v0.9.4 + image: ghcr.io/fuellabs/fuel-core:v0.10.1 ports: - 4000:4000 steps: @@ -252,7 +252,7 @@ jobs: runs-on: ubuntu-latest services: fuel-core: - image: ghcr.io/fuellabs/fuel-core:v0.9.4 + image: ghcr.io/fuellabs/fuel-core:v0.10.1 ports: - 4000:4000 steps: diff --git a/Cargo.lock b/Cargo.lock index 78e813f697a..0639e70222a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,7 +18,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" dependencies = [ - "generic-array", + "generic-array 0.14.6", ] [[package]] @@ -53,7 +53,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" dependencies = [ "cipher", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -63,7 +63,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" dependencies = [ "cipher", - "opaque-debug", + "opaque-debug 0.3.0", +] + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.7", + "once_cell", + "version_check", ] [[package]] @@ -205,7 +216,7 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab006897723d9352f63e2b13047177c3982d8d79709d713ce7747a8f19fd1b0" dependencies = [ - "autocfg 1.1.0", + "autocfg", "concurrent-queue", "futures-lite", "libc", @@ -313,15 +324,6 @@ dependencies = [ "syn", ] -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -334,6 +336,28 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + +[[package]] +name = "base58" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" + +[[package]] +name = "base58check" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ee2fe4c9a0c84515f136aaae2466744a721af6d63339c18689d9e995d74d99b" +dependencies = [ + "base58", + "sha2 0.8.2", +] + [[package]] name = "base64" version = "0.12.3" @@ -346,12 +370,33 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "base64ct" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea2b2456fd614d856680dcd9fcc660a51a820fa09daef2e49772b56a193c8474" + +[[package]] +name = "bech32" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dabbe35f96fb9507f7330793dc490461b2962659ac5d427181e451a623751d1" + [[package]] name = "beef" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -367,6 +412,25 @@ dependencies = [ "typenum", ] +[[package]] +name = "bitvec" +version = "0.17.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41262f11d771fd4a61aa3ce019fca363b4b6c282fca9da2a31186d3965a47a5c" +dependencies = [ + "either", + "radium", +] + +[[package]] +name = "blake2" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9cf849ee05b2ee5fba5e36f97ff8ec2533916700fc0758d40d92136a42f3388" +dependencies = [ + "digest 0.10.3", +] + [[package]] name = "blake2b_simd" version = "0.5.11" @@ -378,14 +442,25 @@ dependencies = [ "constant_time_eq", ] +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array 0.12.4", +] + [[package]] name = "block-buffer" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "block-padding", - "generic-array", + "generic-array 0.14.6", ] [[package]] @@ -394,14 +469,17 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" dependencies = [ - "generic-array", + "generic-array 0.14.6", ] [[package]] name = "block-padding" -version = "0.2.1" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] [[package]] name = "blocking" @@ -423,6 +501,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "008b57b368e638ed60664350ea4f2f3647a0192173478df2736cc255a025a796" +[[package]] +name = "bs58" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" + [[package]] name = "bstr" version = "0.2.17" @@ -451,6 +535,12 @@ version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + [[package]] name = "byteorder" version = "1.4.3" @@ -512,7 +602,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" dependencies = [ - "generic-array", + "generic-array 0.14.6", ] [[package]] @@ -579,12 +669,60 @@ dependencies = [ ] [[package]] -name = "cloudabi" -version = "0.0.3" +name = "coins-bip32" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +checksum = "634c509653de24b439672164bbf56f5f582a2ab0e313d3b0f6af0b7345cf2560" dependencies = [ - "bitflags", + "bincode", + "bs58", + "coins-core", + "digest 0.10.3", + "getrandom 0.2.7", + "hmac 0.12.1", + "k256", + "lazy_static", + "serde", + "sha2 0.10.2", + "thiserror", +] + +[[package]] +name = "coins-bip39" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a11892bcac83b4c6e95ab84b5b06c76d9d70ad73548dd07418269c5c7977171" +dependencies = [ + "bitvec", + "coins-bip32", + "getrandom 0.2.7", + "hex", + "hmac 0.12.1", + "pbkdf2", + "rand 0.8.5", + "sha2 0.10.2", + "thiserror", +] + +[[package]] +name = "coins-core" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c94090a6663f224feae66ab01e41a2555a8296ee07b5f20dab8888bdefc9f617" +dependencies = [ + "base58check", + "base64 0.12.3", + "bech32", + "blake2", + "digest 0.10.3", + "generic-array 0.14.6", + "hex", + "ripemd", + "serde", + "serde_derive", + "sha2 0.10.2", + "sha3", + "thiserror", ] [[package]] @@ -630,6 +768,12 @@ dependencies = [ "serde", ] +[[package]] +name = "const-oid" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "722e23542a15cea1f65d4a1419c4cfd7a26706c70871a13a04238ca3f40f1661" + [[package]] name = "const_fn" version = "0.4.9" @@ -657,7 +801,7 @@ dependencies = [ "aes-gcm", "base64 0.13.0", "hkdf", - "hmac", + "hmac 0.10.1", "percent-encoding", "rand 0.8.5", "sha2 0.9.9", @@ -718,13 +862,25 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-bigint" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f2b443d17d49dad5ef0ede301c3179cc923b8822f3393b4d2c28c269dd4a122" +dependencies = [ + "generic-array 0.14.6", + "rand_core 0.6.3", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "generic-array", + "generic-array 0.14.6", "typenum", ] @@ -734,7 +890,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bff07008ec701e8028e2ceb8f83f0e4274ee62bd2dbdc4fefff2e9a91824081a" dependencies = [ - "generic-array", + "generic-array 0.14.6", "subtle", ] @@ -880,6 +1036,16 @@ dependencies = [ "tokio", ] +[[package]] +name = "der" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dd2ae565c0a381dde7fade45fce95984c568bdcb4700a4fdbe3175e0380b2f" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "derivative" version = "2.2.0" @@ -904,13 +1070,22 @@ dependencies = [ "syn", ] +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array 0.12.4", +] + [[package]] name = "digest" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array", + "generic-array 0.14.6", ] [[package]] @@ -921,6 +1096,7 @@ checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ "block-buffer 0.10.2", "crypto-common", + "subtle", ] [[package]] @@ -964,12 +1140,44 @@ checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" name = "docstrings" version = "0.0.0" +[[package]] +name = "ecdsa" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e852f4174d2a8646a0fa8a34b55797856c722f86267deb0aa1e93f7f247f800e" +dependencies = [ + "der", + "elliptic-curve", + "rfc6979", + "signature", +] + [[package]] name = "either" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "elliptic-curve" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" +dependencies = [ + "base16ct", + "crypto-bigint", + "der", + "digest 0.10.3", + "ff", + "generic-array 0.14.6", + "group", + "pkcs8", + "rand_core 0.6.3", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "encode_unicode" version = "0.3.6" @@ -1023,6 +1231,12 @@ dependencies = [ "syn", ] +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + [[package]] name = "fastrand" version = "1.8.0" @@ -1032,6 +1246,16 @@ dependencies = [ "instant", ] +[[package]] +name = "ff" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df689201f395c6b90dfe87127685f8dbfc083a5e779e613575d8bd7314300c3e" +dependencies = [ + "rand_core 0.6.3", + "subtle", +] + [[package]] name = "filecheck" version = "0.5.0" @@ -1088,7 +1312,7 @@ dependencies = [ "forc-pkg", "forc-util", "fs_extra", - "fuel-asm 0.6.0", + "fuel-asm", "hex", "serde", "serde_json", @@ -1190,7 +1414,7 @@ dependencies = [ "anyhow", "forc-util", "fuel-crypto", - "fuel-tx", + "fuel-gql-client", "git2", "petgraph", "semver 1.0.13", @@ -1239,27 +1463,11 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - -[[package]] -name = "fuel-asm" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16628e172a06a411c57972c55a67404f1684118be3bbca79148bf5a00fff48f0" -dependencies = [ - "fuel-types", - "serde", -] - [[package]] name = "fuel-asm" -version = "0.6.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf02de44ec38d5977d61896cd228b45c9596a38f940f964cacb2d683ada6a064" +checksum = "135ef9990debd1fa257988a0a8be5b9d787decaba911cc3b97d7712a4b70328d" dependencies = [ "fuel-types", "serde", @@ -1267,24 +1475,26 @@ dependencies = [ [[package]] name = "fuel-crypto" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8af1477833b63cf956b71a63a67a7af0e7477bd2f774536556fe0338f909542e" +checksum = "c27380c9c0a97da57123eb981289431069371cc71439f8d0192b604c1414f705" dependencies = [ "borrown", + "coins-bip32", + "coins-bip39", "fuel-types", "lazy_static", "rand 0.8.5", - "secp256k1", + "secp256k1 0.24.0", "serde", - "sha2 0.9.9", + "sha2 0.10.2", ] [[package]] name = "fuel-gql-client" -version = "0.9.8" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1749b9410bcdbcaa17a8aa233b6db84eaadf4c68b3930333fc6cb4996db07ee" +checksum = "927f424468993c779f4be9e798357b20985b99e27028f89991480cbbeab3f957" dependencies = [ "anyhow", "chrono", @@ -1306,39 +1516,18 @@ dependencies = [ [[package]] name = "fuel-merkle" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8148b67b9ca99755b8c73fbc5bad7710590e1d7e245680ffd351289915258851" -dependencies = [ - "bytes", - "digest 0.9.0", - "fuel-storage 0.1.0", - "generic-array", - "hex", - "lazy_static", - "sha2 0.9.9", - "thiserror", -] - -[[package]] -name = "fuel-merkle" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fab10247f9eababf72a64120da05cfef57fbf811ebd2c93dbbbbeccddcce5f11" +checksum = "1fa59f2a4e6cd6d83a51981c5ac706d58fc8ef53700003948c826827b88cfff1" dependencies = [ "digest 0.10.3", - "fuel-storage 0.2.0", + "fuel-storage", + "hashbrown 0.12.3", "hex", "sha2 0.10.2", "thiserror", ] -[[package]] -name = "fuel-storage" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f97a6a68c3378e486d645a47026bcd7139500345ef214653811ea4f016f142ce" - [[package]] name = "fuel-storage" version = "0.2.0" @@ -1347,15 +1536,16 @@ checksum = "34b9161e86d434a93088409530a4f71f42e074b3bbcbb7a27bfe666583f92fd7" [[package]] name = "fuel-tx" -version = "0.13.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43dbfcd95f2b6fb19e6272832b5d6ecf14f8283c3329994baa38a4faed65d437" +checksum = "118b773c25dbf645457fbd9b0288ac923c044d03ce68f492e539c840c3595f5e" dependencies = [ - "fuel-asm 0.5.3", + "fuel-asm", "fuel-crypto", - "fuel-merkle 0.2.0", + "fuel-merkle", "fuel-types", "itertools", + "num-integer", "rand 0.8.5", "serde", ] @@ -1372,21 +1562,22 @@ dependencies = [ [[package]] name = "fuel-vm" -version = "0.12.3" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f0fefd1a070f608742ed06141ee717bb3b77df13772506a98493550fafed5fb" +checksum = "516d60fc504570c0ad79f6dffcbd31687b15b76ecf8753bccaeae201baac29d2" dependencies = [ - "fuel-asm 0.5.3", + "fuel-asm", "fuel-crypto", - "fuel-merkle 0.1.1", - "fuel-storage 0.1.0", + "fuel-merkle", + "fuel-storage", "fuel-tx", "fuel-types", "itertools", "rand 0.8.5", - "secp256k1", + "secp256k1 0.24.0", "serde", - "sha3 0.9.1", + "sha3", + "tai64", "thiserror", "tracing", ] @@ -1514,6 +1705,15 @@ dependencies = [ "cfg-if 0.1.10", ] +[[package]] +name = "generic-array" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + [[package]] name = "generic-array" version = "0.14.6" @@ -1542,8 +1742,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -1552,7 +1754,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375" dependencies = [ - "opaque-debug", + "opaque-debug 0.3.0", "polyval", ] @@ -1599,6 +1801,17 @@ dependencies = [ "thiserror", ] +[[package]] +name = "group" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7391856def869c1c81063a03457c676fbcd419709c3dfb33d8d319de484b154d" +dependencies = [ + "ff", + "rand_core 0.6.3", + "subtle", +] + [[package]] name = "h2" version = "0.3.14" @@ -1643,6 +1856,9 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] [[package]] name = "headers" @@ -1706,7 +1922,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" dependencies = [ "digest 0.9.0", - "hmac", + "hmac 0.10.1", ] [[package]] @@ -1719,6 +1935,15 @@ dependencies = [ "digest 0.9.0", ] +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.3", +] + [[package]] name = "http" version = "0.2.8" @@ -1887,7 +2112,7 @@ version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ - "autocfg 1.1.0", + "autocfg", "hashbrown 0.12.3", ] @@ -1962,6 +2187,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "k256" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2573d3fd3e4cc741affc9b5ce1a8ce36cf29f09f80f36da4309d0ae6d7854" +dependencies = [ + "cfg-if 1.0.0", + "ecdsa", + "elliptic-curve", + "sha2 0.10.2", +] + [[package]] name = "keccak" version = "0.1.2" @@ -2057,7 +2294,7 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" dependencies = [ - "autocfg 1.1.0", + "autocfg", "scopeguard", ] @@ -2172,7 +2409,7 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -2238,7 +2475,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-integer", "num-traits", ] @@ -2249,7 +2486,7 @@ version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-traits", ] @@ -2259,7 +2496,7 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -2278,6 +2515,12 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + [[package]] name = "opaque-debug" version = "0.3.0" @@ -2315,7 +2558,7 @@ version = "0.9.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cc", "libc", "openssl-src", @@ -2379,12 +2622,35 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core 0.6.3", + "subtle", +] + [[package]] name = "paste" version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9423e2b32f7a043629287a536f21951e8c6a82482d0acb1eeebfc90bc2225b22" +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest 0.10.3", + "hmac 0.12.1", + "password-hash", + "sha2 0.10.2", +] + [[package]] name = "peg" version = "0.7.0" @@ -2550,6 +2816,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs8" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" +dependencies = [ + "der", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.25" @@ -2562,7 +2838,7 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "899b00b9c8ab553c743b3e11e87c5c7d423b2a2de229ba95b24a756344748011" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cfg-if 1.0.0", "libc", "log", @@ -2577,7 +2853,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd" dependencies = [ "cpuid-bool", - "opaque-debug", + "opaque-debug 0.3.0", "universal-hash", ] @@ -2689,23 +2965,10 @@ dependencies = [ ] [[package]] -name = "rand" -version = "0.6.5" +name = "radium" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.8", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi", -] +checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" [[package]] name = "rand" @@ -2717,7 +2980,7 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc 0.2.0", + "rand_hc", ] [[package]] @@ -2731,16 +2994,6 @@ dependencies = [ "rand_core 0.6.3", ] -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.3.1", -] - [[package]] name = "rand_chacha" version = "0.2.2" @@ -2761,21 +3014,6 @@ dependencies = [ "rand_core 0.6.3", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -2794,15 +3032,6 @@ dependencies = [ "getrandom 0.2.7", ] -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rand_hc" version = "0.2.0" @@ -2812,59 +3041,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rand_xoshiro" version = "0.6.0" @@ -2874,15 +3050,6 @@ dependencies = [ "rand_core 0.6.3", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.1.57" @@ -2994,6 +3161,17 @@ dependencies = [ "winreg", ] +[[package]] +name = "rfc6979" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88c86280f057430a52f4861551b092a01b419b8eacefc7c995eacb9dc132fe32" +dependencies = [ + "crypto-bigint", + "hmac 0.12.1", + "zeroize", +] + [[package]] name = "ring" version = "0.16.20" @@ -3009,6 +3187,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "ripemd" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1facec54cb5e0dc08553501fa740091086d0259ad0067e0d4103448e4cb22ed3" +dependencies = [ + "digest 0.10.3", +] + [[package]] name = "ropey" version = "1.5.0" @@ -3181,14 +3368,37 @@ dependencies = [ "untrusted", ] +[[package]] +name = "sec1" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" +dependencies = [ + "base16ct", + "der", + "generic-array 0.14.6", + "pkcs8", + "subtle", + "zeroize", +] + [[package]] name = "secp256k1" version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97d03ceae636d0fed5bae6a7f4f664354c5f4fcedf6eef053fef17e49f837d0a" dependencies = [ - "rand 0.6.5", - "secp256k1-sys", + "secp256k1-sys 0.4.2", +] + +[[package]] +name = "secp256k1" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7649a0b3ffb32636e60c7ce0d70511eda9c52c658cd0634e194d5a19943aeff" +dependencies = [ + "rand 0.8.5", + "secp256k1-sys 0.6.0", ] [[package]] @@ -3200,6 +3410,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7058dc8eaf3f2810d7828680320acda0b25a288f6d288e19278e249bbf74226b" +dependencies = [ + "cc", +] + [[package]] name = "semver" version = "0.9.0" @@ -3308,7 +3527,7 @@ dependencies = [ "cfg-if 1.0.0", "cpufeatures", "digest 0.9.0", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -3337,6 +3556,18 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" +[[package]] +name = "sha2" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +dependencies = [ + "block-buffer 0.7.3", + "digest 0.8.1", + "fake-simd", + "opaque-debug 0.2.3", +] + [[package]] name = "sha2" version = "0.9.9" @@ -3347,7 +3578,7 @@ dependencies = [ "cfg-if 1.0.0", "cpufeatures", "digest 0.9.0", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -3361,18 +3592,6 @@ dependencies = [ "digest 0.10.3", ] -[[package]] -name = "sha3" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" -dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", - "keccak", - "opaque-debug", -] - [[package]] name = "sha3" version = "0.10.2" @@ -3407,6 +3626,16 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0ea32af43239f0d353a7dd75a22d94c329c8cdaafdcb4c1c1335aa10c298a4a" +dependencies = [ + "digest 0.10.3", + "rand_core 0.6.3", +] + [[package]] name = "simple-mutex" version = "1.1.5" @@ -3438,7 +3667,7 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -3463,6 +3692,16 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spki" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "standback" version = "0.2.17" @@ -3615,7 +3854,7 @@ dependencies = [ "derivative", "dirs 3.0.2", "either", - "fuel-asm 0.6.0", + "fuel-asm", "fuel-crypto", "fuel-tx", "fuel-types", @@ -3720,7 +3959,7 @@ dependencies = [ name = "sway-types" version = "0.21.0" dependencies = [ - "fuel-asm 0.6.0", + "fuel-asm", "fuel-crypto", "fuel-tx", "lazy_static", @@ -3742,6 +3981,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tai64" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed7401421025f4132e6c1f7af5e7f8287383969f36e6628016cd509b8d3da9dc" + [[package]] name = "taplo" version = "0.7.0" @@ -3826,7 +4071,7 @@ dependencies = [ "forc-client", "forc-pkg", "forc-util", - "fuel-asm 0.6.0", + "fuel-asm", "fuel-tx", "fuel-vm", "gag", @@ -3851,8 +4096,8 @@ dependencies = [ "fuel-types", "fuel-vm", "hex", - "secp256k1", - "sha3 0.10.2", + "secp256k1 0.20.3", + "sha3", "tracing", ] @@ -3976,7 +4221,7 @@ version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" dependencies = [ - "autocfg 1.1.0", + "autocfg", "bytes", "libc", "memchr", @@ -4339,7 +4584,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" dependencies = [ - "generic-array", + "generic-array 0.14.6", "subtle", ] @@ -4745,3 +4990,9 @@ checksum = "fe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1" dependencies = [ "winapi", ] + +[[package]] +name = "zeroize" +version = "1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" diff --git a/forc-pkg/Cargo.toml b/forc-pkg/Cargo.toml index 96e053e3a22..76f27b314fb 100644 --- a/forc-pkg/Cargo.toml +++ b/forc-pkg/Cargo.toml @@ -11,8 +11,8 @@ description = "Building, locking, fetching and updating Sway projects as Forc pa [dependencies] anyhow = "1" forc-util = { version = "0.21.0", path = "../forc-util" } -fuel-crypto = "0.5" -fuel-tx = "0.13" +fuel-crypto = "0.6" +fuel-gql-client = { version = "0.10", default-features = false } git2 = { version = "0.14", features = ["vendored-libgit2", "vendored-openssl"] } petgraph = { version = "0.6", features = ["serde-1"] } semver = { version = "1.0", features = ["serde"] } diff --git a/forc-pkg/src/pkg.rs b/forc-pkg/src/pkg.rs index 76383c12ce6..cb859470bac 100644 --- a/forc-pkg/src/pkg.rs +++ b/forc-pkg/src/pkg.rs @@ -8,7 +8,9 @@ use forc_util::{ default_output_directory, find_file_name, git_checkouts_directory, kebab_to_snake_case, print_on_failure, print_on_success, print_on_success_library, }; -use fuel_tx::{Contract, StorageSlot}; +// Using `fuel_tx` directly instead of `fuel_gql_client` transitively is causing some weird issue. +// See https://github.com/FuelLabs/sway/issues/2659 +use fuel_gql_client::fuel_tx::{Contract, StorageSlot}; use petgraph::{ self, visit::{Bfs, Dfs, EdgeRef, Walker}, diff --git a/forc-plugins/forc-client/Cargo.toml b/forc-plugins/forc-client/Cargo.toml index 797388dca78..8c765eed114 100644 --- a/forc-plugins/forc-client/Cargo.toml +++ b/forc-plugins/forc-client/Cargo.toml @@ -13,9 +13,9 @@ anyhow = "1" clap = { version = "3", features = ["derive", "env"] } forc-pkg = { version = "0.21.0", path = "../../forc-pkg" } forc-util = { version = "0.21.0", path = "../../forc-util" } -fuel-gql-client = { version = "0.9", default-features = false } -fuel-tx = "0.13" -fuel-vm = "0.12" +fuel-gql-client = { version = "0.10", default-features = false } +fuel-tx = "0.18" +fuel-vm = "0.15" futures = "0.3" hex = "0.4.3" serde = { version = "1.0" } diff --git a/forc-plugins/forc-client/src/ops/deploy/op.rs b/forc-plugins/forc-client/src/ops/deploy/op.rs index 7ec76502749..438b3b99560 100644 --- a/forc-plugins/forc-client/src/ops/deploy/op.rs +++ b/forc-plugins/forc-client/src/ops/deploy/op.rs @@ -92,13 +92,11 @@ fn create_contract_tx( ) -> (Transaction, fuel_tx::ContractId) { let gas_price = 0; let gas_limit = fuel_tx::ConsensusParameters::default().max_gas_per_tx; - let byte_price = 0; let maturity = 0; let bytecode_witness_index = 0; let witnesses = vec![compiled_contract.clone().into()]; let salt = Salt::new([0; 32]); - let static_contracts = vec![]; let contract = Contract::from(compiled_contract); let root = contract.root(); @@ -124,11 +122,9 @@ fn create_contract_tx( Transaction::create( gas_price, gas_limit, - byte_price, maturity, bytecode_witness_index, salt, - static_contracts, storage_slots, inputs, outputs, diff --git a/forc-plugins/forc-client/src/ops/run/op.rs b/forc-plugins/forc-client/src/ops/run/op.rs index 257aa70612a..6c83a2b5061 100644 --- a/forc-plugins/forc-client/src/ops/run/op.rs +++ b/forc-plugins/forc-client/src/ops/run/op.rs @@ -52,7 +52,7 @@ pub async fn run(command: RunCommand) -> Result> { script_data, inputs, outputs, - TxParameters::new(command.byte_price, command.gas_limit, command.gas_price), + TxParameters::new(command.gas_limit, command.gas_price), ); let node_url = command.node_url.unwrap_or_else(|| match &manifest.network { @@ -121,14 +121,12 @@ fn create_tx_with_script_and_data( ) -> Transaction { let gas_price = tx_params.gas_price; let gas_limit = tx_params.gas_limit; - let byte_price = tx_params.byte_price; let maturity = 0; let witnesses = vec![]; Transaction::script( gas_price, gas_limit, - byte_price, maturity, script, script_data, @@ -148,6 +146,7 @@ fn construct_input_from_contract((_idx, contract): (usize, &String)) -> fuel_tx: utxo_id: fuel_tx::UtxoId::new(fuel_tx::Bytes32::zeroed(), 0), balance_root: fuel_tx::Bytes32::zeroed(), state_root: fuel_tx::Bytes32::zeroed(), + tx_pointer: fuel_tx::TxPointer::new(0, 0), contract_id: fuel_tx::ContractId::from_str(contract).unwrap(), } } diff --git a/forc-plugins/forc-client/src/ops/run/parameters.rs b/forc-plugins/forc-client/src/ops/run/parameters.rs index 5bfd2d1b9b7..ce20e20cac4 100644 --- a/forc-plugins/forc-client/src/ops/run/parameters.rs +++ b/forc-plugins/forc-client/src/ops/run/parameters.rs @@ -1,20 +1,17 @@ #[derive(Debug)] pub struct TxParameters { - pub byte_price: u64, pub gas_limit: u64, pub gas_price: u64, } impl TxParameters { pub const DEFAULT: Self = Self { - byte_price: 0, gas_limit: fuel_tx::ConsensusParameters::DEFAULT.max_gas_per_tx, gas_price: 0, }; - pub fn new(byte_price: Option, gas_limit: Option, gas_price: Option) -> Self { + pub fn new(gas_limit: Option, gas_price: Option) -> Self { Self { - byte_price: byte_price.unwrap_or(TxParameters::DEFAULT.byte_price), gas_limit: gas_limit.unwrap_or(TxParameters::DEFAULT.gas_limit), gas_price: gas_price.unwrap_or(TxParameters::DEFAULT.gas_price), } diff --git a/forc/Cargo.toml b/forc/Cargo.toml index 77169d1679e..5c3071ced17 100644 --- a/forc/Cargo.toml +++ b/forc/Cargo.toml @@ -24,7 +24,7 @@ clap_complete = "3.1" forc-pkg = { version = "0.21.0", path = "../forc-pkg" } forc-util = { version = "0.21.0", path = "../forc-util" } fs_extra = "1.2" -fuel-asm = "0.6" +fuel-asm = "0.8" hex = "0.4.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.73" diff --git a/forc/src/utils/defaults.rs b/forc/src/utils/defaults.rs index d2cc72f0975..194d91e5207 100644 --- a/forc/src/utils/defaults.rs +++ b/forc/src/utils/defaults.rs @@ -30,7 +30,7 @@ edition = "2021" license = "Apache-2.0" [dependencies] -fuels = {{ version = "0.20", features = ["fuel-core-lib"] }} +fuels = {{ version = "0.21", features = ["fuel-core-lib"] }} tokio = {{ version = "1.12", features = ["rt", "macros"] }} [[test]] diff --git a/sway-ast/src/expr/op_code.rs b/sway-ast/src/expr/op_code.rs index e108dcb4454..3b1f1e10f49 100644 --- a/sway-ast/src/expr/op_code.rs +++ b/sway-ast/src/expr/op_code.rs @@ -280,12 +280,6 @@ define_op_codes!( (Ecr, EcrOpcode, "ecr", (addr: reg, sig: reg, hash: reg)), (K256, K256Opcode, "k256", (addr: reg, data: reg, size: reg)), (S256, S256Opcode, "s256", (addr: reg, data: reg, size: reg)), - (Xil, XilOpcode, "xil", (ret: reg, input: reg)), - (Xis, XisOpcode, "xis", (ret: reg, input: reg)), - (Xol, XolOpcode, "xol", (ret: reg, output: reg)), - (Xos, XosOpcode, "xos", (ret: reg, output: reg)), - (Xwl, XwlOpcode, "xwl", (ret: reg, witness: reg)), - (Xws, XwsOpcode, "xws", (ret: reg, witness: reg)), (Flag, FlagOpcode, "flag", (value: reg)), (Gm, GmOpcode, "gm", (ret: reg, op: imm)), ); diff --git a/sway-core/Cargo.toml b/sway-core/Cargo.toml index 50fb11a9a52..8810cb0f3e3 100644 --- a/sway-core/Cargo.toml +++ b/sway-core/Cargo.toml @@ -13,11 +13,11 @@ clap = { version = "3.1", features = ["derive"], optional = true } derivative = "2.2.0" dirs = "3.0" either = "1.6" -fuel-asm = "0.6" -fuel-crypto = "0.5" -fuel-tx = "0.13" +fuel-asm = "0.8" +fuel-crypto = "0.6" +fuel-tx = "0.18" fuel-types = "0.5" -fuel-vm = "0.12" +fuel-vm = "0.15" hex = { version = "0.4", optional = true } im = "15.0" itertools = "0.10" diff --git a/sway-core/src/asm_lang/allocated_ops.rs b/sway-core/src/asm_lang/allocated_ops.rs index 9dcfba3c030..0ee2805414c 100644 --- a/sway-core/src/asm_lang/allocated_ops.rs +++ b/sway-core/src/asm_lang/allocated_ops.rs @@ -163,12 +163,6 @@ pub(crate) enum AllocatedOpcode { ECR(AllocatedRegister, AllocatedRegister, AllocatedRegister), K256(AllocatedRegister, AllocatedRegister, AllocatedRegister), S256(AllocatedRegister, AllocatedRegister, AllocatedRegister), - XIL(AllocatedRegister, AllocatedRegister), - XIS(AllocatedRegister, AllocatedRegister), - XOL(AllocatedRegister, AllocatedRegister), - XOS(AllocatedRegister, AllocatedRegister), - XWL(AllocatedRegister, AllocatedRegister), - XWS(AllocatedRegister, AllocatedRegister), NOOP, FLAG(AllocatedRegister), GM(AllocatedRegister, VirtualImmediate18), @@ -263,12 +257,6 @@ impl fmt::Display for AllocatedOp { ECR(a, b, c) => format!("ecr {} {} {}", a, b, c), K256(a, b, c) => format!("k256 {} {} {}", a, b, c), S256(a, b, c) => format!("s256 {} {} {}", a, b, c), - XIL(a, b) => format!("xil {} {}", a, b), - XIS(a, b) => format!("xis {} {}", a, b), - XOL(a, b) => format!("xol {} {}", a, b), - XOS(a, b) => format!("xos {} {}", a, b), - XWL(a, b) => format!("xwl {} {}", a, b), - XWS(a, b) => format!("xws {} {}", a, b), NOOP => "noop".to_string(), FLAG(a) => format!("flag {}", a), GM(a, b) => format!("gm {} {}", a, b), @@ -374,12 +362,6 @@ impl AllocatedOp { ECR (a, b, c) => VmOp::ECR (a.to_register_id(), b.to_register_id(), c.to_register_id()), K256(a, b, c) => VmOp::K256(a.to_register_id(), b.to_register_id(), c.to_register_id()), S256(a, b, c) => VmOp::S256(a.to_register_id(), b.to_register_id(), c.to_register_id()), - XIL (a, b) => VmOp::XIL(a.to_register_id(), b.to_register_id()), - XIS (a, b) => VmOp::XIS(a.to_register_id(), b.to_register_id()), - XOL (a, b) => VmOp::XOL(a.to_register_id(), b.to_register_id()), - XOS (a, b) => VmOp::XOS(a.to_register_id(), b.to_register_id()), - XWL (a, b) => VmOp::XWL(a.to_register_id(), b.to_register_id()), - XWS (a, b) => VmOp::XWS(a.to_register_id(), b.to_register_id()), NOOP => VmOp::NOOP, FLAG(a) => VmOp::FLAG(a.to_register_id()), GM(a, b) => VmOp::GM(a.to_register_id(), b.value), diff --git a/sway-core/src/asm_lang/mod.rs b/sway-core/src/asm_lang/mod.rs index 3248fe70ac8..154b7a96cea 100644 --- a/sway-core/src/asm_lang/mod.rs +++ b/sway-core/src/asm_lang/mod.rs @@ -922,60 +922,6 @@ impl Op { ); VirtualOp::S256(r1, r2, r3) } - "xil" => { - let (r1, r2) = check!( - two_regs(args, immediate, whole_op_span), - return err(warnings, errors), - warnings, - errors - ); - VirtualOp::XIL(r1, r2) - } - "xis" => { - let (r1, r2) = check!( - two_regs(args, immediate, whole_op_span), - return err(warnings, errors), - warnings, - errors - ); - VirtualOp::XIS(r1, r2) - } - "xol" => { - let (r1, r2) = check!( - two_regs(args, immediate, whole_op_span), - return err(warnings, errors), - warnings, - errors - ); - VirtualOp::XOL(r1, r2) - } - "xos" => { - let (r1, r2) = check!( - two_regs(args, immediate, whole_op_span), - return err(warnings, errors), - warnings, - errors - ); - VirtualOp::XOS(r1, r2) - } - "xwl" => { - let (r1, r2) = check!( - two_regs(args, immediate, whole_op_span), - return err(warnings, errors), - warnings, - errors - ); - VirtualOp::XWL(r1, r2) - } - "xws" => { - let (r1, r2) = check!( - two_regs(args, immediate, whole_op_span), - return err(warnings, errors), - warnings, - errors - ); - VirtualOp::XWS(r1, r2) - } "noop" => VirtualOp::NOOP, "flag" => { let r1 = check!( @@ -1410,12 +1356,6 @@ impl fmt::Display for Op { ECR(a, b, c) => format!("ecr {} {} {}", a, b, c), K256(a, b, c) => format!("k256 {} {} {}", a, b, c), S256(a, b, c) => format!("s256 {} {} {}", a, b, c), - XIL(a, b) => format!("xil {} {}", a, b), - XIS(a, b) => format!("xis {} {}", a, b), - XOL(a, b) => format!("xol {} {}", a, b), - XOS(a, b) => format!("xos {} {}", a, b), - XWL(a, b) => format!("xwl {} {}", a, b), - XWS(a, b) => format!("xws {} {}", a, b), NOOP => "noop".to_string(), FLAG(a) => format!("flag {}", a), GM(a, b) => format!("gm {} {}", a, b), diff --git a/sway-core/src/asm_lang/virtual_ops.rs b/sway-core/src/asm_lang/virtual_ops.rs index b2a9ae7f7bc..03855b7f8d8 100644 --- a/sway-core/src/asm_lang/virtual_ops.rs +++ b/sway-core/src/asm_lang/virtual_ops.rs @@ -137,12 +137,6 @@ pub(crate) enum VirtualOp { ECR(VirtualRegister, VirtualRegister, VirtualRegister), K256(VirtualRegister, VirtualRegister, VirtualRegister), S256(VirtualRegister, VirtualRegister, VirtualRegister), - XIL(VirtualRegister, VirtualRegister), - XIS(VirtualRegister, VirtualRegister), - XOL(VirtualRegister, VirtualRegister), - XOS(VirtualRegister, VirtualRegister), - XWL(VirtualRegister, VirtualRegister), - XWS(VirtualRegister, VirtualRegister), NOOP, FLAG(VirtualRegister), GM(VirtualRegister, VirtualImmediate18), @@ -228,12 +222,6 @@ impl VirtualOp { ECR(r1, r2, r3) => vec![r1, r2, r3], K256(r1, r2, r3) => vec![r1, r2, r3], S256(r1, r2, r3) => vec![r1, r2, r3], - XIL(r1, r2) => vec![r1, r2], - XIS(r1, r2) => vec![r1, r2], - XOL(r1, r2) => vec![r1, r2], - XOS(r1, r2) => vec![r1, r2], - XWL(r1, r2) => vec![r1, r2], - XWS(r1, r2) => vec![r1, r2], NOOP => vec![], FLAG(r1) => vec![r1], GM(r1, _imm) => vec![r1], @@ -324,12 +312,6 @@ impl VirtualOp { ECR(r1, r2, r3) => vec![r1, r2, r3], K256(r1, r2, r3) => vec![r1, r2, r3], S256(r1, r2, r3) => vec![r1, r2, r3], - XIL(_r1, r2) => vec![r2], - XIS(_r1, r2) => vec![r2], - XOL(_r1, r2) => vec![r2], - XOS(_r1, r2) => vec![r2], - XWL(_r1, r2) => vec![r2], - XWS(_r1, r2) => vec![r2], NOOP => vec![], FLAG(r1) => vec![r1], GM(_r1, _imm) => vec![], @@ -420,12 +402,6 @@ impl VirtualOp { ECR(_r1, _r2, _r3) => vec![], K256(_r1, _r2, _r3) => vec![], S256(_r1, _r2, _r3) => vec![], - XIL(r1, _r2) => vec![r1], - XIS(r1, _r2) => vec![r1], - XOL(r1, _r2) => vec![r1], - XOS(r1, _r2) => vec![r1], - XWL(r1, _r2) => vec![r1], - XWS(r1, _r2) => vec![r1], NOOP => vec![], FLAG(_r1) => vec![], GM(r1, _imm) => vec![r1], @@ -806,30 +782,6 @@ impl VirtualOp { update_reg(reg_to_reg_map, r2), update_reg(reg_to_reg_map, r3), ), - XIL(r1, r2) => Self::XIL( - update_reg(reg_to_reg_map, r1), - update_reg(reg_to_reg_map, r2), - ), - XIS(r1, r2) => Self::XIS( - update_reg(reg_to_reg_map, r1), - update_reg(reg_to_reg_map, r2), - ), - XOL(r1, r2) => Self::XOL( - update_reg(reg_to_reg_map, r1), - update_reg(reg_to_reg_map, r2), - ), - XOS(r1, r2) => Self::XOS( - update_reg(reg_to_reg_map, r1), - update_reg(reg_to_reg_map, r2), - ), - XWL(r1, r2) => Self::XWL( - update_reg(reg_to_reg_map, r1), - update_reg(reg_to_reg_map, r2), - ), - XWS(r1, r2) => Self::XWS( - update_reg(reg_to_reg_map, r1), - update_reg(reg_to_reg_map, r2), - ), NOOP => Self::NOOP, FLAG(r1) => Self::FLAG(update_reg(reg_to_reg_map, r1)), GM(r1, i) => Self::GM(update_reg(reg_to_reg_map, r1), i.clone()), @@ -900,9 +852,11 @@ impl VirtualOp { } } None => { - unimplemented!("The allocator cannot resolve a register mapping for this program. - This is a temporary artifact of the extremely early stage version of this language. - Try to lower the number of variables you use."); + unimplemented!( + "The allocator cannot resolve a register mapping for this program. + This is a temporary artifact of the extremely early stage version of this language. + Try to lower the number of variables you use." + ); } }; @@ -1204,24 +1158,6 @@ impl VirtualOp { map_reg(&mapping, reg2), map_reg(&mapping, reg3), ), - XIL(reg1, reg2) => { - AllocatedOpcode::XIL(map_reg(&mapping, reg1), map_reg(&mapping, reg2)) - } - XIS(reg1, reg2) => { - AllocatedOpcode::XIS(map_reg(&mapping, reg1), map_reg(&mapping, reg2)) - } - XOL(reg1, reg2) => { - AllocatedOpcode::XOL(map_reg(&mapping, reg1), map_reg(&mapping, reg2)) - } - XOS(reg1, reg2) => { - AllocatedOpcode::XOS(map_reg(&mapping, reg1), map_reg(&mapping, reg2)) - } - XWL(reg1, reg2) => { - AllocatedOpcode::XWL(map_reg(&mapping, reg1), map_reg(&mapping, reg2)) - } - XWS(reg1, reg2) => { - AllocatedOpcode::XWS(map_reg(&mapping, reg1), map_reg(&mapping, reg2)) - } NOOP => AllocatedOpcode::NOOP, FLAG(reg) => AllocatedOpcode::FLAG(map_reg(&mapping, reg)), GM(reg, imm) => AllocatedOpcode::GM(map_reg(&mapping, reg), imm.clone()), diff --git a/sway-core/src/semantic_analysis/ast_node/expression/match_expression/analysis/pattern.rs b/sway-core/src/semantic_analysis/ast_node/expression/match_expression/analysis/pattern.rs index 10fc2fa6552..02ad7aeb58b 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/match_expression/analysis/pattern.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/match_expression/analysis/pattern.rs @@ -805,7 +805,7 @@ impl fmt::Display for StructPattern { let (front, rest) = self.fields.split_at(start_of_wildcard_tail); let mut inner_builder = front .iter() - .map(|(name, field)| -> Result<_, _> { + .map(|(name, field)| -> Result<_, fmt::Error> { let mut inner_builder = String::new(); inner_builder.push_str(name); inner_builder.push_str(": "); @@ -822,7 +822,7 @@ impl fmt::Display for StructPattern { None => self .fields .iter() - .map(|(name, field)| -> Result<_, _> { + .map(|(name, field)| -> Result<_, fmt::Error> { let mut inner_builder = String::new(); inner_builder.push_str(name); inner_builder.push_str(": "); diff --git a/sway-lib-std/src/chain/auth.sw b/sway-lib-std/src/chain/auth.sw index 23325827a7a..abe3c030dd2 100644 --- a/sway-lib-std/src/chain/auth.sw +++ b/sway-lib-std/src/chain/auth.sw @@ -8,7 +8,7 @@ use ::contract_id::ContractId; use ::identity::Identity; use ::option::Option; use ::result::Result; -use ::tx::{INPUT_COIN, INPUT_MESSAGE, tx_input_owner, tx_input_type, tx_inputs_count}; +use ::inputs::{Input, input_count, input_owner, input_type}; pub enum AuthError { InputsNotAllOwnedBySameAddress: (), @@ -47,34 +47,42 @@ pub fn msg_sender() -> Result { /// Get the owner of the inputs (of type `InputCoin` or `InputMessage`) to a /// TransactionScript if they all share the same owner. fn inputs_owner() -> Result { - let inputs_count = tx_inputs_count(); + let inputs = input_count(); let mut candidate = Option::None::
(); - let mut i = 0; + let mut i = 0u8; // Note: `inputs_count` is guaranteed to be at least 1 for any valid tx. - while i < inputs_count { - let input_type = tx_input_type(i); - if input_type != INPUT_COIN && input_type != INPUT_MESSAGE { - // type != InputCoin or InputMessage, continue looping. - i += 1; - continue; + while i < inputs { + let type_of_input = input_type(i); + match type_of_input { + Input::Coin => { + (); + }, + Input::Message => { + (); + }, + _ => { + // type != InputCoin or InputMessage, continue looping. + i += 1u8; + continue; + } } // type == InputCoin or InputMessage - let input_owner = tx_input_owner(i); + let owner_of_input = input_owner(i); if candidate.is_none() { // This is the first input seen of the correct type. - candidate = input_owner; - i += 1; + candidate = owner_of_input; + i += 1u8; continue; } // Compare current input owner to candidate. // `candidate` and `input_owner` must be `Option::Some` // at this point, so we can unwrap safely. - if input_owner.unwrap() == candidate.unwrap() { + if owner_of_input.unwrap() == candidate.unwrap() { // Owners are a match, continue looping. - i += 1; + i += 1u8; continue; } diff --git a/sway-lib-std/src/inputs.sw b/sway-lib-std/src/inputs.sw new file mode 100644 index 00000000000..7700d92176b --- /dev/null +++ b/sway-lib-std/src/inputs.sw @@ -0,0 +1,160 @@ +//! Getters for fields on transaction inputs. +//! This includes InputCoins, InputMessages and InputContracts. +library inputs; + +use ::address::Address; +use ::mem::read; +use ::logging::log; +use ::option::Option; +use ::revert::revert; +use ::tx::{ + GTF_CREATE_INPUTS_COUNT, + GTF_CREATE_INPUT_AT_INDEX, + GTF_SCRIPT_INPUTS_COUNT, + GTF_SCRIPT_INPUT_AT_INDEX, + Transaction, + tx_type, +}; + +const GTF_INPUT_TYPE = 0x101; + +//////////////////////////////////////// +// GTF Opcode const selectors +//////////////////////////////////////// + +// const GTF_INPUT_COIN_TX_ID = 0x102; +// const GTF_INPUT_COIN_OUTPUT_INDEX = 0x103; +const GTF_INPUT_COIN_OWNER = 0x104; +// const GTF_INPUT_COIN_AMOUNT = 0x105; +// const GTF_INPUT_COIN_ASSET_ID = 0x106; +// const GTF_INPUT_COIN_TX_POINTER = 0x107; +// const GTF_INPUT_COIN_WITNESS_INDEX = 0x108; +// const GTF_INPUT_COIN_MATURITY = 0x109; +// const GTF_INPUT_COIN_PREDICATE_LENGTH = 0x10A; +// const GTF_INPUT_COIN_PREDICATE_DATA_LENGTH = 0x10B; +// const GTF_INPUT_COIN_PREDICATE = 0x10C; +const GTF_INPUT_COIN_PREDICATE_DATA = 0x10D; + +// const GTF_INPUT_CONTRACT_TX_ID = 0x10E; +// const GTF_INPUT_CONTRACT_OUTPUT_INDEX = 0x10F; +// const GTF_INPUT_CONTRACT_BALANCE_ROOT = 0x110; +// const GTF_INPUT_CONTRACT_STATE_ROOT = 0x111; +// const GTF_INPUT_CONTRACT_TX_POINTER = 0x112; +// const GTF_INPUT_CONTRACT_CONTRACT_ID = 0x113; + +// const GTF_INPUT_MESSAGE_MESSAGE_ID = 0x114; +// const GTF_INPUT_MESSAGE_SENDER = 0x115; +const GTF_INPUT_MESSAGE_RECIPIENT = 0x116; +// const GTF_INPUT_MESSAGE_AMOUNT = 0x117; +// const GTF_INPUT_MESSAGE_NONCE = 0x118; + +// These are based on the old spec (before +// https://github.com/FuelLabs/fuel-specs/pull/400) because that's what's +// currently implemented in `fuel-core`, `fuel-asm`, and `fuel-tx. They should +// eventually be updated. +// const GTF_INPUT_MESSAGE_WITNESS_INDEX = 0x11A; +// const GTF_INPUT_MESSAGE_DATA_LENGTH = 0x11B; +// const GTF_INPUT_MESSAGE_PREDICATE_LENGTH = 0x11C; +// const GTF_INPUT_MESSAGE_PREDICATE_DATA_LENGTH = 0x11D; +// const GTF_INPUT_MESSAGE_DATA = 0x11E; +// const GTF_INPUT_MESSAGE_PREDICATE = 0x11F; +const GTF_INPUT_MESSAGE_PREDICATE_DATA = 0x120; + +pub enum Input { + Coin: (), + Contract: (), + Message: (), +} + +/// Get the type of the input at `index`. +pub fn input_type(index: u64) -> Input { + let type = __gtf::(index, GTF_INPUT_TYPE); + match type { + 0u8 => { + Input::Coin + }, + 1u8 => { + Input::Contract + }, + 2u8 => { + Input::Message + }, + _ => { + revert(0); + } + } +} + +/// for either tx type (transaction-script or transaction-create). +pub fn input_pointer(index: u64) -> u64 { + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(index, GTF_SCRIPT_INPUT_AT_INDEX) + }, + Transaction::Create => { + __gtf::(index, GTF_CREATE_INPUT_AT_INDEX) + } + } +} + +/// If the input's type is `InputCoin` the owner as an Option::Some(owner). +/// Otherwise, returns Option::None. +pub fn input_owner(index: u64) -> Option
{ + let type = input_type(index); + match type { + Input::Coin => { + Option::Some(~Address::from(__gtf::(index, GTF_INPUT_COIN_OWNER))) + }, + _ => { + return Option::None; + }, + } +} + +/// Get the predicate data pointer from the input at `index`. +/// If the input's type is `InputCoin` or `InputMessage`, +/// return the data as an Option::Some(ptr). +/// Otherwise, returns Option::None. +pub fn input_predicate_data_pointer(index: u64) -> Option { + let type = input_type(index); + match type { + Input::Coin => { + Option::Some(__gtf::(index, GTF_INPUT_COIN_PREDICATE_DATA)) + }, + Input::Message => { + Option::Some(__gtf::(index, GTF_INPUT_MESSAGE_PREDICATE_DATA)) + }, + _ => { + Option::None + } + } +} + +pub fn input_predicate_data(index: u64) -> T { + let data = input_predicate_data_pointer(index); + match data { + Option::Some(d) => { + read::(d) + }, + Option::None => { + revert(0) + }, + } +} + +/// Get the transaction inputs count for either tx type +/// (transaction-script or transaction-create). +pub fn input_count() -> u8 { + let type = tx_type(); + match type { + Transaction::Script => { + log(17); + __gtf::(0, GTF_SCRIPT_INPUTS_COUNT) + }, + Transaction::Create => { + log(19); + __gtf::(0, GTF_CREATE_INPUTS_COUNT) + }, + } +} diff --git a/sway-lib-std/src/lib.sw b/sway-lib-std/src/lib.sw index dc4c9b2e142..0d299957530 100644 --- a/sway-lib-std/src/lib.sw +++ b/sway-lib-std/src/lib.sw @@ -17,6 +17,8 @@ dep b512; dep address; dep identity; dep tx; +dep inputs; +dep outputs; dep chain; dep math; dep block; diff --git a/sway-lib-std/src/outputs.sw b/sway-lib-std/src/outputs.sw new file mode 100644 index 00000000000..3e70b372e98 --- /dev/null +++ b/sway-lib-std/src/outputs.sw @@ -0,0 +1,131 @@ +//! Getters for fields on transaction outputs. +//! This includes OutputCoins, InputMessages and InputContracts. +library outputs; + +use ::contract_id::ContractId; +use ::mem::read; +use ::revert::revert; +use ::logging::log; +use ::tx::{ + GTF_CREATE_OUTPUTS_COUNT, + GTF_CREATE_OUTPUT_AT_INDEX, + GTF_SCRIPT_OUTPUTS_COUNT, + GTF_SCRIPT_OUTPUT_AT_INDEX, + Transaction, + tx_type, +}; + +//////////////////////////////////////// +// GTF Opcode const selectors +//////////////////////////////////////// + +const GTF_OUTPUT_TYPE = 0x201; +// const GTF_OUTPUT_COIN_TO = 0x202; +const GTF_OUTPUT_COIN_AMOUNT = 0x203; +// const GTF_OUTPUT_COIN_ASSET_ID = 0x204; +// const GTF_OUTPUT_CONTRACT_INPUT_INDEX = 0x205; +// const GTF_OUTPUT_CONTRACT_BALANCE_ROOT = 0x206; +// const GTF_OUTPUT_CONTRACT_STATE_ROOT = 0x207; +// const GTF_OUTPUT_MESSAGE_RECIPIENT = 0x208; +const GTF_OUTPUT_MESSAGE_AMOUNT = 0x209; +// const GTF_OUTPUT_CONTRACT_CREATED_CONTRACT_ID = 0x20A; +// const GTF_OUTPUT_CONTRACT_CREATED_STATE_ROOT = 0x20B; + +pub enum Output { + Coin: (), + Contract: (), + Message: (), + Change: (), + Variable: (), +} + +/// Get the type of an output at `index`. +pub fn output_type(index: u64) -> Output { + let type = __gtf::(index, GTF_OUTPUT_TYPE); + log(type); + match type { + 0u8 => { + Output::Coin + }, + 1u8 => { + Output::Contract + }, + 2u8 => { + Output::Message + }, + 3u8 => { + Output::Change + }, + 4u8 => { + Output::Variable + }, + _ => { + revert(0); + }, + } +} + +/// Get a pointer to the Ouput at `index` +/// for either tx type (transaction-script or transaction-create). +pub fn output_pointer(index: u64) -> u64 { + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(index, GTF_SCRIPT_OUTPUT_AT_INDEX) + }, + Transaction::Create => { + __gtf::(index, GTF_CREATE_OUTPUT_AT_INDEX) + }, + } +} + +/// Get the transaction outputs count for either tx type +/// (transaction-script or transaction-create). +pub fn output_count() -> u64 { + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(0, GTF_SCRIPT_OUTPUTS_COUNT) + }, + Transaction::Create => { + __gtf::(0, GTF_CREATE_OUTPUTS_COUNT) + }, + } +} + +/// Get the amount of coins to send for the output at `index`. +/// This method is only meaningful if the output type has the `amount` field. +/// Specifically: OutputCoin, OutputMessage, OutputChange, OutputVariable. +pub fn output_amount(index: u64) -> u64 { + let type = output_type(index); + match type { + Output::Coin => { + __gtf::(index, GTF_OUTPUT_COIN_AMOUNT) + }, + Output::Contract => { + revert(0); + }, + Output::Message => { + __gtf::(index, GTF_OUTPUT_MESSAGE_AMOUNT) + }, + // For now, output changes are always guaranteed to have an amount of + // zero since they're only set after execution terminates. + // use `__gtf` when GTF_OUTPUT_CHANGE_AMOUNT is available. + // See https://github.com/FuelLabs/fuel-specs/issues/402 + // and https://github.com/FuelLabs/sway/issues/2671. + Output::Change => { + 0 + }, + // use `__gtf` when GTF_OUTPUT_VARIABLE_AMOUNT is available. + // See https://github.com/FuelLabs/fuel-specs/issues/402 + // and https://github.com/FuelLabs/sway/issues/2671. + Output::Variable => { + let ptr = output_pointer(index); + asm(r1, r2, r3: ptr) { + addi r2 r3 i40; + lw r1 r2 i0; + r1: u64 + } + }, + } +} diff --git a/sway-lib-std/src/storage.sw b/sway-lib-std/src/storage.sw index 6be246ad879..e78b31a7756 100644 --- a/sway-lib-std/src/storage.sw +++ b/sway-lib-std/src/storage.sw @@ -10,7 +10,7 @@ use ::result::Result; #[storage(write)]pub fn store(key: b256, value: T) { if !__is_reference_type::() { // If copy type, then it's a single word - let value = asm (v: value) { + let value = asm(v: value) { v: u64 }; __state_store_word(key, value); @@ -49,7 +49,7 @@ use ::result::Result; if !__is_reference_type::() { // If copy type, then it's a single word let loaded_word = __state_load_word(key); - asm (l: loaded_word) { + asm(l: loaded_word) { l: T } } else { diff --git a/sway-lib-std/src/token.sw b/sway-lib-std/src/token.sw index b15dd2c4d81..28459ce2885 100644 --- a/sway-lib-std/src/token.sw +++ b/sway-lib-std/src/token.sw @@ -6,7 +6,8 @@ use ::context::call_frames::contract_id; use ::contract_id::ContractId; use ::identity::Identity; use ::revert::revert; -use ::tx::{OUTPUT_VARIABLE, tx_output_amount, tx_output_type, tx_outputs_count}; +use ::outputs::{Output, output_amount, output_count, output_type}; + /// Mint `amount` coins of the current contract's `asset_id` and transfer them /// to `to` by calling either force_transfer_to_contract() or @@ -95,13 +96,16 @@ pub fn transfer_to_output(amount: u64, asset_id: ContractId, to: Address) { // If an output of type `OutputVariable` is found, check if its `amount` is // zero. As one cannot transfer zero coins to an output without a panic, a // variable output with a value of zero is by definition unused. - let outputs_count = tx_outputs_count(); - while index < outputs_count { - if tx_output_type(index) == OUTPUT_VARIABLE && tx_output_amount(index) == 0 { - output_index = index; - output_found = true; - break; // break early and use the output we found - }; + let outputs = output_count(); + while index < outputs { + let type_of_output = output_type(index); + if let Output::Variable = type_of_output { + if output_amount(index) == 0 { + output_index = index; + output_found = true; + break; // break early and use the output we found + } + } index += 1; } diff --git a/sway-lib-std/src/tx.sw b/sway-lib-std/src/tx.sw index 952970aa4c2..b392df8cbeb 100644 --- a/sway-lib-std/src/tx.sw +++ b/sway-lib-std/src/tx.sw @@ -1,309 +1,238 @@ //! Transaction field getters. -//! This will be replaced by instructions: https://github.com/FuelLabs/fuel-specs/issues/287 library tx; use ::address::Address; -use ::context::registers::instrs_start; -use ::contract_id::ContractId; -use ::intrinsics::is_reference_type; use ::mem::read; use ::option::Option; +use ::revert::revert; //////////////////////////////////////// -// Transaction fields +// GTF Opcode const selectors //////////////////////////////////////// -// The transaction starts at -// TX_START = 32 + MAX_INPUTS*(32+8) + 8 = 32 + 255 * (40) + 8 = 10240 -// -// Note that everything when serialized is padded to word length. -// -// type = TX_START + 0*WORD_SIZE = 10240 + 0*8 = 10240 -// gasPrice = TX_START + 1*WORD_SIZE = 10240 + 1*8 = 10248 -// gasLimit = TX_START + 2*WORD_SIZE = 10240 + 2*8 = 10256 -// bytePrice = TX_START + 3*WORD_SIZE = 10240 + 3*8 = 10264 -// maturity = TX_START + 4*WORD_SIZE = 10240 + 4*8 = 10272 -// scriptLength = TX_START + 5*WORD_SIZE = 10240 + 5*8 = 10280 -// scriptDataLength = TX_START + 6*WORD_SIZE = 10240 + 6*8 = 10288 -// inputsCount = TX_START + 7*WORD_SIZE = 10240 + 7*8 = 10296 -// outputsCount = TX_START + 8*WORD_SIZE = 10240 + 8*8 = 10304 -// witnessesCount = TX_START + 9*WORD_SIZE = 10240 + 9*8 = 10312 -// receiptsRoot = TX_START + 10*WORD_SIZE = 10240 + 10*8 = 10320 -// SCRIPT_START = TX_START + 11*WORD_SIZE = 10240 + 14*8 = 10352 -// SCRIPT_DATA_START = SCRIPT_START + SCRIPT_LENGTH - -const TX_TYPE_OFFSET = 10240; -const TX_GAS_PRICE_OFFSET = 10248; -const TX_GAS_LIMIT_OFFSET = 10256; -const TX_BYTE_PRICE_OFFSET = 10264; -const TX_MATURITY_OFFSET = 10272; -const TX_SCRIPT_LENGTH_OFFSET = 10280; -const TX_SCRIPT_DATA_LENGTH_OFFSET = 10288; -const TX_INPUTS_COUNT_OFFSET = 10296; -const TX_OUTPUTS_COUNT_OFFSET = 10304; -const TX_WITNESSES_COUNT_OFFSET = 10312; -const TX_RECEIPTS_ROOT_OFFSET = 10320; -const TX_SCRIPT_START_OFFSET = 10352; -const TX_ID_OFFSET = 0; - -// Input types -pub const INPUT_COIN = 0u8; -pub const INPUT_CONTRACT = 1u8; -pub const INPUT_MESSAGE = 2u8; - -// Output types -pub const OUTPUT_COIN = 0u8; -pub const OUTPUT_CONTRACT = 1u8; -pub const OUTPUT_MESSAGE = 2u8; -pub const OUTPUT_CHANGE = 3u8; -pub const OUTPUT_VARIABLE = 4u8; -pub const OUTPUT_CONTRACT_CREATED = 5u8; - -/// Get the transaction type. -pub fn tx_type() -> u8 { - asm(r1, r2: TX_TYPE_OFFSET) { - lw r1 r2 i0; - r1: u8 +const GTF_TYPE = 0x001; +const GTF_SCRIPT_GAS_PRICE = 0x002; +const GTF_SCRIPT_GAS_LIMIT = 0x003; +const GTF_SCRIPT_MATURITY = 0x004; +const GTF_SCRIPT_SCRIPT_LENGTH = 0x005; +const GTF_SCRIPT_SCRIPT_DATA_LENGTH = 0x006; +pub const GTF_SCRIPT_INPUTS_COUNT = 0x007; +pub const GTF_SCRIPT_OUTPUTS_COUNT = 0x008; +const GTF_SCRIPT_WITNESSES_COUNT = 0x009; +const GTF_SCRIPT_RECEIPTS_ROOT = 0x00A; +const GTF_SCRIPT_SCRIPT = 0x00B; +const GTF_SCRIPT_SCRIPT_DATA = 0x00C; +pub const GTF_SCRIPT_INPUT_AT_INDEX = 0x00D; +pub const GTF_SCRIPT_OUTPUT_AT_INDEX = 0x00E; +const GTF_SCRIPT_WITNESS_AT_INDEX = 0x00F; + +const GTF_CREATE_GAS_PRICE = 0x010; +const GTF_CREATE_GAS_LIMIT = 0x011; +const GTF_CREATE_MATURITY = 0x012; +// const GTF_CREATE_BYTECODE_LENGTH = 0x013; +// const GTF_CREATE_BYTECODE_WITNESS_INDEX = 0x014; +// const GTF_CREATE_STORAGE_SLOTS_COUNT = 0x015; +pub const GTF_CREATE_INPUTS_COUNT = 0x016; +pub const GTF_CREATE_OUTPUTS_COUNT = 0x017; +const GTF_CREATE_WITNESSES_COUNT = 0x018; +// const GTF_CREATE_SALT = 0x019; +// const GTF_CREATE_STORAGE_SLOT_AT_INDEX = 0x01A; +pub const GTF_CREATE_INPUT_AT_INDEX = 0x01B; +pub const GTF_CREATE_OUTPUT_AT_INDEX = 0x01C; +const GTF_CREATE_WITNESS_AT_INDEX = 0x01D; + +const GTF_WITNESS_DATA_LENGTH = 0x301; +const GTF_WITNESS_DATA = 0x302; + +pub enum Transaction { + Script: (), + Create: (), +} + +/// Get the type of the current transaction. +/// Either 0 (transaction-script) or 1 (transaction-create) +pub fn tx_type() -> Transaction { + let type = __gtf::(0, GTF_TYPE); + match type { + 0u8 => { + Transaction::Script + }, + 1u8 => { + Transaction::Create + }, + _ => { + revert(0); + }, } } -/// Get the transaction gas price. +/// Get the transaction gas price for either tx type +/// (transaction-script or transaction-create). pub fn tx_gas_price() -> u64 { - asm(r1, r2: TX_GAS_PRICE_OFFSET) { - lw r1 r2 i0; - r1: u64 + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(0, GTF_SCRIPT_GAS_PRICE) + }, + Transaction::Create => { + __gtf::(0, GTF_CREATE_GAS_PRICE) + }, } } -/// Get the transaction gas limit. +/// Get the transaction-script gas limit for either tx type +/// (transaction-script or transaction-create). pub fn tx_gas_limit() -> u64 { - asm(r1, r2: TX_GAS_LIMIT_OFFSET) { - lw r1 r2 i0; - r1: u64 - } -} - -/// Get the transaction byte price. -pub fn tx_byte_price() -> u64 { - asm(r1, r2: TX_BYTE_PRICE_OFFSET) { - lw r1 r2 i0; - r1: u64 + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(0, GTF_SCRIPT_GAS_LIMIT) + }, + Transaction::Create => { + __gtf::(0, GTF_CREATE_GAS_LIMIT) + }, } } -/// Get the transaction maturity. +/// Get the transaction maturity for either tx type +/// (transaction-script or transaction-create). pub fn tx_maturity() -> u32 { - asm(r1, r2: TX_MATURITY_OFFSET) { - lw r1 r2 i0; - r1: u32 + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(0, GTF_SCRIPT_MATURITY) + }, + Transaction::Create => { + __gtf::(0, GTF_CREATE_MATURITY) + }, } } -/// Get the transaction script length. +/// Get the transaction-script script length. +/// Reverts if not a transaction-script. pub fn tx_script_length() -> u64 { - asm(r1, r2: TX_SCRIPT_LENGTH_OFFSET) { - lw r1 r2 i0; - r1: u64 + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(0, GTF_SCRIPT_SCRIPT_LENGTH) + }, + Transaction::Create => { + revert(0) + }, } } /// Get the transaction script data length. +/// Reverts if not a transaction-script. pub fn tx_script_data_length() -> u64 { - asm(r1, r2: TX_SCRIPT_DATA_LENGTH_OFFSET) { - lw r1 r2 i0; - r1: u64 + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(0, GTF_SCRIPT_SCRIPT_DATA_LENGTH) + }, + Transaction::Create => { + revert(0) + } } } -/// Get the transaction inputs count. -pub fn tx_inputs_count() -> u64 { - asm(r1, r2: TX_INPUTS_COUNT_OFFSET) { - lw r1 r2 i0; - r1: u64 +/// Get the transaction witnesses count for either tx type +/// (transaction-script or transaction-create). +pub fn tx_witnesses_count() -> u64 { + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(0, GTF_SCRIPT_WITNESSES_COUNT) + }, + Transaction::Create => { + __gtf::(0, GTF_CREATE_WITNESSES_COUNT) + }, } } -/// Get the transaction outputs count. -pub fn tx_outputs_count() -> u64 { - asm(r1, r2: TX_OUTPUTS_COUNT_OFFSET) { - lw r1 r2 i0; - r1: u64 +// Get a pointer to the witness at index `index` for either tx type +/// (transaction-script or transaction-create). +pub fn tx_witness_pointer(index: u64) -> u64 { + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(0, GTF_SCRIPT_WITNESS_AT_INDEX) + }, + Transaction::Create => { + __gtf::(0, GTF_CREATE_WITNESS_AT_INDEX) + }, } } -/// Get the transaction witnesses count. -pub fn tx_witnesses_count() -> u64 { - asm(r1, r2: TX_WITNESSES_COUNT_OFFSET) { - lw r1 r2 i0; - r1: u64 - } +// Get the length of the witness data at `index` +pub fn tx_witness_data_length(index: u64) -> u64 { + __gtf::(index, GTF_WITNESS_DATA_LENGTH) +} + +// Get the witness data at `index`. +pub fn tx_witness_data(index: u64) -> T { + read::(__gtf::(index, GTF_WITNESS_DATA)) } /// Get the transaction receipts root. +/// Reverts if not a transaction-script. pub fn tx_receipts_root() -> b256 { - asm(r1: TX_RECEIPTS_ROOT_OFFSET) { - r1: b256 + let type = tx_type(); + match type { + Transaction::Script => { + read::(__gtf::(0, GTF_SCRIPT_RECEIPTS_ROOT)) + }, + _ => { + revert(0); + } } } /// Get the transaction script start pointer. +/// Reverts if not a transaction-script. pub fn tx_script_start_pointer() -> u64 { - asm(r1, r2: TX_SCRIPT_START_OFFSET) { - move r1 r2; - r1: u64 + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(0, GTF_SCRIPT_SCRIPT) + }, + _ => { + revert(0); + } } } -//////////////////////////////////////// -// Script -//////////////////////////////////////// - /// Get the transaction script data start pointer. +/// Reverts if not a transaction-script +/// (transaction-create has no script data length), pub fn tx_script_data_start_pointer() -> u64 { - tx_script_start_pointer() + tx_script_length() + let type = tx_type(); + match type { + Transaction::Script => { + __gtf::(0, GTF_SCRIPT_SCRIPT_DATA) + }, + _ => { + // transaction-create has no script data length + revert(0); + } + } } /// Get the script data, typed. Unsafe. pub fn tx_script_data() -> T { + let ptr = tx_script_data_start_pointer(); // TODO some safety checks on the input data? We are going to assume it is the right type for now. - read(tx_script_data_start_pointer()) + read::(tx_script_data_start_pointer()) } /// Get the script bytecode /// Must be cast to a u64 array, with sufficient length to contain the bytecode. /// Bytecode will be padded to next whole word. pub fn tx_script_bytecode() -> T { - read(tx_script_start_pointer()) + read::(tx_script_start_pointer()) } -//////////////////////////////////////// -// Inputs -//////////////////////////////////////// - -/// Get a pointer to an input given the index of the input. -pub fn tx_input_pointer(index: u64) -> u64 { - asm(r1, r2: index) { - xis r1 r2; - r1: u64 - } -} - -/// Get the type of an input given a pointer to the input. -pub fn tx_input_type_from_pointer(ptr: u64) -> u8 { - asm(r1, r2: ptr) { - lw r1 r2 i0; - r1: u8 - } -} - -/// If the input's type is `InputCoin` or `InputMessage`, -/// return the owner as an Option::Some(owner). -/// Otherwise, returns Option::None. -pub fn tx_input_owner(index: u64) -> Option
{ - let type = tx_input_type(index); - let owner_offset = match type { - // 0 is the `Coin` Input type - 0u8 => { - // Need to skip over six words, so add 8*6=48 - 48 - }, - // 2 is the `Message` Input type - 2u8 => { - // Need to skip over eighteen words, so add 8*18=144 - 144 - }, - _ => { - return Option::None; - }, - }; - - let ptr = tx_input_pointer(index); - Option::Some(~Address::from(b256_from_pointer_offset(ptr, owner_offset))) -} - -/// Get the type of an input at a given index -pub fn tx_input_type(index: u64) -> u8 { - let ptr = tx_input_pointer(index); - tx_input_type_from_pointer(ptr) -} - -/// Read 256 bits from memory at a given offset from a given pointer -pub fn b256_from_pointer_offset(pointer: u64, offset: u64) -> b256 { - asm(buffer, ptr: pointer, off: offset) { - // Need to skip over `off` bytes - add ptr ptr off; - // Save old stack pointer - move buffer sp; - // Extend stack by 32 bytes - cfei i32; - // Copy 32 bytes - mcpi buffer ptr i32; - // `buffer` now points to the 32 bytes - buffer: b256 - } -} - -//////////////////////////////////////// -// Inputs > Predicate -//////////////////////////////////////// - -pub fn tx_predicate_data_start_pointer() -> u64 { - // $is is word-aligned - let is = instrs_start(); - let predicate_length_ptr = is - 16; - let predicate_code_length = asm(r1, r2: predicate_length_ptr) { - lw r1 r2 i0; - r1: u64 - }; - - let predicate_data_ptr = is + predicate_code_length; - // predicate_data_ptr % 8 is guaranteed to be either - // 0: if there are an even number of instructions (predicate_data_ptr is word-aligned already) - // 4: if there are an odd number of instructions - predicate_data_ptr + predicate_data_ptr % 8 -} - -pub fn get_predicate_data() -> T { - read(tx_predicate_data_start_pointer()) -} - -//////////////////////////////////////// -// Outputs -//////////////////////////////////////// - -/// Get a pointer to an output given the index of the output. -pub fn tx_output_pointer(index: u64) -> u64 { - asm(r1, r2: index) { - xos r1 r2; - r1: u64 - } -} - -/// Get the type of an output given a pointer to the output. -pub fn tx_output_type_from_pointer(ptr: u64) -> u8 { - asm(r1, r2: ptr) { - lw r1 r2 i0; - r1: u8 - } -} - -/// Get the type of an output at a given index -pub fn tx_output_type(index: u64) -> u8 { - let ptr = tx_output_pointer(index); - tx_output_type_from_pointer(ptr) -} - -/// Get the amount of coins to send for an output given a pointer to the output. -/// This method is only meaningful if the output type has the `amount` field. -/// Specifically: OutputCoin, OutputWithdrawal, OutputChange, OutputVariable. -pub fn tx_output_amount(index: u64) -> u64 { - let ptr = tx_output_pointer(index); - asm(r1, r2, r3: ptr) { - addi r2 r3 i40; - lw r1 r2 i0; - r1: u64 - } -} +const TX_ID_OFFSET = 0; /// Get the id of the current transaction. pub fn tx_id() -> b256 { diff --git a/sway-parse/src/expr/op_code.rs b/sway-parse/src/expr/op_code.rs index 77b171244ad..5eba56664ae 100644 --- a/sway-parse/src/expr/op_code.rs +++ b/sway-parse/src/expr/op_code.rs @@ -98,12 +98,6 @@ define_op_codes!( (Ecr, EcrOpcode, "ecr", (addr, sig, hash)), (K256, K256Opcode, "k256", (addr, data, size)), (S256, S256Opcode, "s256", (addr, data, size)), - (Xil, XilOpcode, "xil", (ret, input)), - (Xis, XisOpcode, "xis", (ret, input)), - (Xol, XolOpcode, "xol", (ret, output)), - (Xos, XosOpcode, "xos", (ret, output)), - (Xwl, XwlOpcode, "xwl", (ret, witness)), - (Xws, XwsOpcode, "xws", (ret, witness)), (Flag, FlagOpcode, "flag", (value)), (Gm, GmOpcode, "gm", (ret, op)), ); diff --git a/sway-types/Cargo.toml b/sway-types/Cargo.toml index b24bea3b219..df861ec8372 100644 --- a/sway-types/Cargo.toml +++ b/sway-types/Cargo.toml @@ -9,8 +9,8 @@ repository = "https://github.com/FuelLabs/sway" description = "Sway core types." [dependencies] -fuel-asm = "0.6" -fuel-crypto = "0.5" -fuel-tx = "0.13" +fuel-asm = "0.8" +fuel-crypto = "0.6" +fuel-tx = "0.18" lazy_static = "1.4" serde = { version = "1.0", features = ["derive"] } diff --git a/test-sig-gen-util/Cargo.toml b/test-sig-gen-util/Cargo.toml index 677818e1ae1..f5ce454af60 100644 --- a/test-sig-gen-util/Cargo.toml +++ b/test-sig-gen-util/Cargo.toml @@ -6,10 +6,10 @@ publish = false [dependencies] anyhow = "1.0.39" -fuel-crypto = "0.5" -fuel-tx = "0.13" +fuel-crypto = "0.6" +fuel-tx = "0.18" fuel-types = { version = "0.5", default-features = false } -fuel-vm = "0.12" +fuel-vm = "0.15" hex = "0.4" secp256k1 = { version = "0.20", features = ["recovery"] } sha3 = "0.10" diff --git a/test/Cargo.toml b/test/Cargo.toml index c711b72d3d6..4cdad4e40d0 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -13,9 +13,9 @@ forc = { path = "../forc", features = ["test"], default-features = false } forc-client = { path = "../forc-plugins/forc-client" } forc-pkg = { path = "../forc-pkg" } forc-util = { path = "../forc-util" } -fuel-asm = "0.6" -fuel-tx = "0.13" -fuel-vm = { version = "0.12", features = ["random"] } +fuel-asm = "0.8" +fuel-tx = { version = "0.18", features = ["builder"]} +fuel-vm = { version = "0.15", features = ["random"] } gag = "1.0" prettydiff = "0.6" rand = "0.8" diff --git a/test/src/e2e_vm_tests/harness.rs b/test/src/e2e_vm_tests/harness.rs index c42a49c9e18..d6133a1ff92 100644 --- a/test/src/e2e_vm_tests/harness.rs +++ b/test/src/e2e_vm_tests/harness.rs @@ -5,9 +5,11 @@ use forc_client::ops::{ run::{cmd::RunCommand, op::run}, }; use forc_pkg::Compiled; -use fuel_tx::Transaction; +use fuel_tx::TransactionBuilder; use fuel_vm::interpreter::Interpreter; use fuel_vm::prelude::*; +use rand::rngs::StdRng; +use rand::{Rng, SeedableRng}; use std::{fmt::Write, fs}; pub(crate) fn deploy_contract(file_name: &str, locked: bool) -> ContractId { @@ -71,32 +73,20 @@ pub(crate) fn runs_on_node( pub(crate) fn runs_in_vm(file_name: &str, locked: bool) -> (ProgramState, Compiled) { let storage = MemoryStorage::default(); + let rng = &mut StdRng::seed_from_u64(2322u64); let script = compile_to_bytes(file_name, locked).unwrap(); - let gas_price = 10; - let gas_limit = fuel_tx::ConsensusParameters::DEFAULT.max_gas_per_tx; - let byte_price = 0; - let maturity = 0; - let script_data = vec![]; - let inputs = vec![]; - let outputs = vec![]; - let witness = vec![]; - let tx_to_test = Transaction::script( - gas_price, - gas_limit, - byte_price, - maturity, - script.bytecode.clone(), - script_data, - inputs, - outputs, - witness, - ); + let maturity = 1; let block_height = (u32::MAX >> 1) as u64; - tx_to_test - .validate(block_height, &Default::default()) - .unwrap(); + let params = &ConsensusParameters::DEFAULT; + + let tx = TransactionBuilder::script(script.bytecode.clone(), Default::default()) + .add_unsigned_coin_input(rng.gen(), rng.gen(), 1, Default::default(), rng.gen(), 0) + .gas_limit(fuel_tx::ConsensusParameters::DEFAULT.max_gas_per_tx) + .maturity(maturity) + .finalize_checked(block_height as Word, params); + let mut i = Interpreter::with_storage(storage, Default::default()); - (*i.transact(tx_to_test).unwrap().state(), script) + (*i.transact(tx).unwrap().state(), script) } /// Compiles the code and captures the output of forc and the compilation. diff --git a/test/src/sdk-harness/Cargo.toml b/test/src/sdk-harness/Cargo.toml index d59c5870032..eb6b02c7849 100644 --- a/test/src/sdk-harness/Cargo.toml +++ b/test/src/sdk-harness/Cargo.toml @@ -7,12 +7,13 @@ version = "0.0.0" [dependencies] assert_matches = "1.5.0" -fuel-core = { version = "0.9", default-features = false } -fuel-gql-client = { version = "0.9", default-features = false } +fuel-core = { version = "0.10", default-features = false } +fuel-gql-client = { version = "0.10", default-features = false } fuel-types = "0.5" -fuel-vm = "0.12" -fuels = { version = "0.20", features = ["fuel-core-lib"] } +fuel-vm = "0.15" +fuels = { version = "0.21", features = ["fuel-core-lib"] } hex = "0.4.3" +rand = "0.8" sha2 = "0.10" sha3 = "0.10.1" tokio = { version = "1.12", features = ["rt", "macros"] } diff --git a/test/src/sdk-harness/test_artifacts/tx_contract/src/main.sw b/test/src/sdk-harness/test_artifacts/tx_contract/src/main.sw index bd11fd7662c..8af1d667649 100644 --- a/test/src/sdk-harness/test_artifacts/tx_contract/src/main.sw +++ b/test/src/sdk-harness/test_artifacts/tx_contract/src/main.sw @@ -1,14 +1,28 @@ contract; -use std::address::Address; -use std::option::Option; -use std::tx::*; +use std::{ + address::Address, + option::Option, + inputs::{ + Input, + input_count, + input_owner, + input_pointer, + input_type, + }, + outputs::{ + Output, + output_count, + output_pointer, + output_type, + }, + tx::*, + }; abi TxContractTest { - fn get_tx_type() -> u8; + fn get_tx_type() -> Transaction; fn get_tx_gas_price() -> u64; fn get_tx_gas_limit() -> u64; - fn get_tx_byte_price() -> u64; fn get_tx_maturity() -> u32; fn get_tx_script_length() -> u64; fn get_tx_script_data_length() -> u64; @@ -18,18 +32,17 @@ abi TxContractTest { fn get_tx_receipts_root() -> b256; fn get_tx_script_start_pointer() -> u64; - fn get_tx_input_type_from_ptr(ptr: u64) -> u8; + fn get_input_type(index: u64) -> Input; fn get_tx_input_pointer(index: u64) -> u64; - fn get_tx_input_type(ptr: u64) -> u8; fn get_tx_input_coin_owner(index: u64) -> Address; fn get_tx_output_pointer(index: u64) -> u64; - fn get_tx_output_type(ptr: u64) -> u8; + fn get_tx_output_type(ptr: u64) -> Output; fn get_tx_id() -> b256; } impl TxContractTest for Contract { - fn get_tx_type() -> u8 { + fn get_tx_type() -> Transaction { tx_type() } fn get_tx_gas_price() -> u64 { @@ -38,9 +51,6 @@ impl TxContractTest for Contract { fn get_tx_gas_limit() -> u64 { tx_gas_limit() } - fn get_tx_byte_price() -> u64 { - tx_byte_price() - } fn get_tx_maturity() -> u32 { tx_maturity() } @@ -51,10 +61,10 @@ impl TxContractTest for Contract { tx_script_data_length() } fn get_tx_inputs_count() -> u64 { - tx_inputs_count() + input_count() } fn get_tx_outputs_count() -> u64 { - tx_outputs_count() + output_count() } fn get_tx_witnesses_count() -> u64 { tx_witnesses_count() @@ -66,26 +76,24 @@ impl TxContractTest for Contract { tx_script_start_pointer() } fn get_tx_input_pointer(index: u64) -> u64 { - tx_input_pointer(index) - } - fn get_tx_input_type_from_ptr(ptr: u64) -> u8 { - tx_input_type_from_pointer(ptr) + input_pointer(index) } - fn get_tx_input_type(index: u64) -> u8 { - tx_input_type(index) + fn get_input_type(index: u64) -> Input { + input_type(index) } // TODO: Add test for getting InputMessage owner when we have InputMessages + // See https://github.com/FuelLabs/sway/issues/2672 // fn get_tx_input_message_owner(index: u64) -> Address { // tx_input_owner(index) // } fn get_tx_input_coin_owner(index: u64) -> Address { - tx_input_owner(index).unwrap() + input_owner(index).unwrap() } fn get_tx_output_pointer(index: u64) -> u64 { - tx_output_pointer(index) + output_pointer(index) } - fn get_tx_output_type(ptr: u64) -> u8 { - tx_output_type_from_pointer(ptr) + fn get_tx_output_type(ptr: u64) -> Output { + output_type(ptr) } fn get_tx_id() -> b256 { tx_id() diff --git a/test/src/sdk-harness/test_projects/auth/mod.rs b/test/src/sdk-harness/test_projects/auth/mod.rs index 779c5478e88..ed9d72a21c2 100644 --- a/test/src/sdk-harness/test_projects/auth/mod.rs +++ b/test/src/sdk-harness/test_projects/auth/mod.rs @@ -48,7 +48,7 @@ async fn get_contracts() -> ( ContractId, AuthCallerContract, ContractId, - LocalWallet, + Wallet, ) { let wallet = launch_provider_and_get_wallet().await; @@ -80,5 +80,11 @@ async fn get_contracts() -> ( let instance_1 = AuthContractBuilder::new(id_1.to_string(), wallet.clone()).build(); let instance_2 = AuthCallerContractBuilder::new(id_2.to_string(), wallet.clone()).build(); - (instance_1, id_1.into(), instance_2, id_2.into(), wallet) + ( + instance_1, + id_1.into(), + instance_2, + id_2.into(), + wallet.lock(), + ) } diff --git a/test/src/sdk-harness/test_projects/context/mod.rs b/test/src/sdk-harness/test_projects/context/mod.rs index 088a9a0b066..47619dcce94 100644 --- a/test/src/sdk-harness/test_projects/context/mod.rs +++ b/test/src/sdk-harness/test_projects/context/mod.rs @@ -63,7 +63,7 @@ async fn can_get_this_balance() { caller_instance .call_receive_coins(send_amount, context_id) .set_contracts(&[context_id.into()]) - .tx_params(TxParameters::new(None, Some(1_000_000), None, None)) + .tx_params(TxParameters::new(None, Some(1_000_000), None)) .call() .await .unwrap(); @@ -133,7 +133,7 @@ async fn can_get_msg_id() { let result = caller_instance .call_get_asset_id_with_coins(send_amount, context_id) .set_contracts(&[context_id.into()]) - .tx_params(TxParameters::new(None, Some(1_000_000), None, None)) + .tx_params(TxParameters::new(None, Some(1_000_000), None)) .call() .await .unwrap(); @@ -155,7 +155,7 @@ async fn can_get_msg_gas() { let result = caller_instance .call_get_gas_with_coins(send_amount, context_id) .set_contracts(&[context_id.into()]) - .tx_params(TxParameters::new(Some(0), Some(1_000_000), None, None)) + .tx_params(TxParameters::new(Some(0), Some(1_000_000), None)) .call() .await .unwrap(); @@ -170,7 +170,7 @@ async fn can_get_global_gas() { caller_instance .mint_coins(send_amount) - .tx_params(TxParameters::new(None, Some(1_000_000), None, None)) + .tx_params(TxParameters::new(None, Some(1_000_000), None)) .call() .await .unwrap(); @@ -178,7 +178,7 @@ async fn can_get_global_gas() { let result = caller_instance .call_get_global_gas_with_coins(send_amount, context_id) .set_contracts(&[context_id.into()]) - .tx_params(TxParameters::new(None, Some(1_000_000), None, None)) + .tx_params(TxParameters::new(None, Some(1_000_000), None)) .call() .await .unwrap(); diff --git a/test/src/sdk-harness/test_projects/exponentiation/mod.rs b/test/src/sdk-harness/test_projects/exponentiation/mod.rs index ae275357b43..78f526d0d91 100644 --- a/test/src/sdk-harness/test_projects/exponentiation/mod.rs +++ b/test/src/sdk-harness/test_projects/exponentiation/mod.rs @@ -1,5 +1,4 @@ use fuels::prelude::*; -use fuels::signers::LocalWallet; use fuels::tx::ContractId; abigen!(TestPowContract, "test_artifacts/pow/out/debug/pow-abi.json"); @@ -83,7 +82,7 @@ async fn overflowing_pow_u8_panics_max() { .unwrap(); } -async fn get_pow_test_instance(wallet: LocalWallet) -> (TestPowContract, ContractId) { +async fn get_pow_test_instance(wallet: WalletUnlocked) -> (TestPowContract, ContractId) { let pow_id = Contract::deploy( "test_artifacts/pow/out/debug/pow.bin", &wallet, diff --git a/test/src/sdk-harness/test_projects/logging/mod.rs b/test/src/sdk-harness/test_projects/logging/mod.rs index 8811a5445e2..b265db51cca 100644 --- a/test/src/sdk-harness/test_projects/logging/mod.rs +++ b/test/src/sdk-harness/test_projects/logging/mod.rs @@ -18,7 +18,6 @@ async fn run_valid() { gas_price: 0, gas_limit: ConsensusParameters::DEFAULT.max_gas_per_tx, maturity: 0, - byte_price: 0, receipts_root: Default::default(), script: bin.unwrap(), script_data: vec![], diff --git a/test/src/sdk-harness/test_projects/methods/mod.rs b/test/src/sdk-harness/test_projects/methods/mod.rs index bff0c48dbb2..fdf5da2d22a 100644 --- a/test/src/sdk-harness/test_projects/methods/mod.rs +++ b/test/src/sdk-harness/test_projects/methods/mod.rs @@ -1,5 +1,4 @@ use fuels::prelude::*; -use fuels::signers::wallet::Wallet; abigen!( MethodsContract, @@ -15,7 +14,7 @@ async fn run_methods_test() { assert_eq!(result.value, true); } -async fn get_methods_instance(wallet: Wallet) -> MethodsContract { +async fn get_methods_instance(wallet: WalletUnlocked) -> MethodsContract { let id = Contract::deploy( "test_artifacts/methods_contract/out/debug/methods_contract.bin", &wallet, diff --git a/test/src/sdk-harness/test_projects/predicate_data_simple/mod.rs b/test/src/sdk-harness/test_projects/predicate_data_simple/mod.rs index 0e697271d20..0e75423438e 100644 --- a/test/src/sdk-harness/test_projects/predicate_data_simple/mod.rs +++ b/test/src/sdk-harness/test_projects/predicate_data_simple/mod.rs @@ -1,14 +1,16 @@ -use fuel_core::service::Config; use fuel_vm::consts::*; use fuel_vm::prelude::Opcode; use fuels::contract::abi_encoder::ABIEncoder; use fuels::contract::script::Script; use fuels::prelude::*; use fuels::signers::wallet::Wallet; -use fuels::tx::{Address, AssetId, Contract, Input, Output, Transaction, UtxoId}; +use fuels::test_helpers::Config; +use fuels::tx::{Address, AssetId, Contract, Input, Output, Transaction, TxPointer, UtxoId}; +use rand::rngs::StdRng; +use rand::{Rng, SeedableRng}; use std::str::FromStr; -async fn setup() -> (Vec, Address, Wallet, u64, AssetId) { +async fn setup() -> (Vec, Address, WalletUnlocked, u64, AssetId) { let predicate_code = std::fs::read("test_projects/predicate_data_simple/out/debug/predicate_data_simple.bin") .unwrap(); @@ -35,7 +37,7 @@ async fn setup() -> (Vec, Address, Wallet, u64, AssetId) { async fn create_predicate( predicate_address: Address, - wallet: &Wallet, + wallet: &WalletUnlocked, amount_to_predicate: u64, asset_id: AssetId, ) { @@ -54,7 +56,6 @@ async fn create_predicate( 1, 1000000, 1, - 0, Opcode::RET(REG_ONE).to_bytes().to_vec(), vec![], wallet_coins, @@ -89,12 +90,18 @@ async fn submit_to_predicate( let mut inputs = vec![]; let mut total_amount_in_predicate = 0; + let block_height = u32::MAX >> 1; + let rng = &mut StdRng::seed_from_u64(2322u64); + let tx_index = rng.gen(); + let tx_pointer = TxPointer::new(block_height, tx_index); + for coin in utxo_predicate_hash { let input_coin = Input::coin_predicate( UtxoId::from(coin.utxo_id), coin.owner.into(), coin.amount.0, asset_id, + tx_pointer, 0, predicate_code.clone(), predicate_data.clone(), @@ -109,7 +116,6 @@ async fn submit_to_predicate( 0, 1000000, 0, - 0, vec![], vec![], inputs, diff --git a/test/src/sdk-harness/test_projects/predicate_data_simple/src/main.sw b/test/src/sdk-harness/test_projects/predicate_data_simple/src/main.sw index bcd20894429..df5d68c29ed 100644 --- a/test/src/sdk-harness/test_projects/predicate_data_simple/src/main.sw +++ b/test/src/sdk-harness/test_projects/predicate_data_simple/src/main.sw @@ -1,9 +1,9 @@ predicate; -use std::tx::get_predicate_data; +use std::inputs::input_predicate_data; fn main() -> bool { - let received: u32 = get_predicate_data(); + let received: u32 = input_predicate_data(0); let expected: u32 = 12345; received == expected diff --git a/test/src/sdk-harness/test_projects/predicate_data_struct/mod.rs b/test/src/sdk-harness/test_projects/predicate_data_struct/mod.rs index 83936c98be6..1989c73e447 100644 --- a/test/src/sdk-harness/test_projects/predicate_data_struct/mod.rs +++ b/test/src/sdk-harness/test_projects/predicate_data_struct/mod.rs @@ -1,14 +1,16 @@ -use fuel_core::service::Config; use fuel_vm::consts::*; use fuel_vm::prelude::Opcode; use fuels::contract::abi_encoder::ABIEncoder; use fuels::contract::script::Script; use fuels::prelude::*; use fuels::signers::wallet::Wallet; -use fuels::tx::{Address, AssetId, Contract, Input, Output, Transaction, UtxoId}; +use fuels::test_helpers::Config; +use fuels::tx::{Address, AssetId, Contract, Input, Output, Transaction, TxPointer, UtxoId}; +use rand::rngs::StdRng; +use rand::{Rng, SeedableRng}; use std::str::FromStr; -async fn setup() -> (Vec, Address, Wallet, u64, AssetId) { +async fn setup() -> (Vec, Address, WalletUnlocked, u64, AssetId) { let predicate_code = std::fs::read("test_projects/predicate_data_struct/out/debug/predicate_data_struct.bin") .unwrap(); @@ -35,7 +37,7 @@ async fn setup() -> (Vec, Address, Wallet, u64, AssetId) { async fn create_predicate( predicate_address: Address, - wallet: &Wallet, + wallet: &WalletUnlocked, amount_to_predicate: u64, asset_id: AssetId, ) { @@ -54,7 +56,6 @@ async fn create_predicate( 1, 1000000, 1, - 0, Opcode::RET(REG_ONE).to_bytes().to_vec(), vec![], wallet_coins, @@ -89,12 +90,18 @@ async fn submit_to_predicate( let mut inputs = vec![]; let mut total_amount_in_predicate = 0; + let block_height = u32::MAX >> 1; + let rng = &mut StdRng::seed_from_u64(2322u64); + let tx_index = rng.gen(); + let tx_pointer = TxPointer::new(block_height, tx_index); + for coin in utxo_predicate_hash { let input_coin = Input::coin_predicate( UtxoId::from(coin.utxo_id), coin.owner.into(), coin.amount.0, asset_id, + tx_pointer, 0, predicate_code.clone(), predicate_data.clone(), @@ -109,7 +116,6 @@ async fn submit_to_predicate( 0, 1000000, 0, - 0, vec![], vec![], inputs, diff --git a/test/src/sdk-harness/test_projects/predicate_data_struct/src/main.sw b/test/src/sdk-harness/test_projects/predicate_data_struct/src/main.sw index 7a9cbdf3418..9b2a9cba803 100644 --- a/test/src/sdk-harness/test_projects/predicate_data_struct/src/main.sw +++ b/test/src/sdk-harness/test_projects/predicate_data_struct/src/main.sw @@ -1,6 +1,6 @@ predicate; -use std::tx::get_predicate_data; +use std::inputs::input_predicate_data; struct Validation { has_account: bool, @@ -8,6 +8,6 @@ struct Validation { } fn main() -> bool { - let validation:Validation = get_predicate_data(); + let validation:Validation = input_predicate_data(0); validation.total_complete == 100 && validation.has_account } diff --git a/test/src/sdk-harness/test_projects/reentrancy/mod.rs b/test/src/sdk-harness/test_projects/reentrancy/mod.rs index 934a1d46165..37e703635ac 100644 --- a/test/src/sdk-harness/test_projects/reentrancy/mod.rs +++ b/test/src/sdk-harness/test_projects/reentrancy/mod.rs @@ -1,5 +1,4 @@ use fuels::prelude::*; -use fuels::signers::wallet::Wallet; use fuels::tx::ContractId; abigen!( @@ -74,7 +73,7 @@ async fn can_call_guarded_function() { assert_eq!(result.value, true) } -async fn get_attacker_instance(wallet: Wallet) -> (AttackerContract, ContractId) { +async fn get_attacker_instance(wallet: WalletUnlocked) -> (AttackerContract, ContractId) { let id = Contract::deploy( "test_artifacts/reentrancy_attacker_contract/out/debug/reentrancy_attacker_contract.bin", &wallet, @@ -93,7 +92,7 @@ async fn get_attacker_instance(wallet: Wallet) -> (AttackerContract, ContractId) (instance, id.into()) } -async fn get_target_instance(wallet: Wallet) -> (TargetContract, ContractId) { +async fn get_target_instance(wallet: WalletUnlocked) -> (TargetContract, ContractId) { let id = Contract::deploy( "test_artifacts/reentrancy_target_contract/out/debug/reentrancy_target_contract.bin", &wallet, diff --git a/test/src/sdk-harness/test_projects/script_data/mod.rs b/test/src/sdk-harness/test_projects/script_data/mod.rs index 75b8746ff2d..fec46831778 100644 --- a/test/src/sdk-harness/test_projects/script_data/mod.rs +++ b/test/src/sdk-harness/test_projects/script_data/mod.rs @@ -17,7 +17,6 @@ async fn call_script(script_data: Vec) -> Result, fuels::prelud gas_price: 0, gas_limit: ConsensusParameters::DEFAULT.max_gas_per_tx, maturity: 0, - byte_price: 0, receipts_root: Default::default(), script: bin.unwrap(), script_data, diff --git a/test/src/sdk-harness/test_projects/token_ops/mod.rs b/test/src/sdk-harness/test_projects/token_ops/mod.rs index f27a4202b3b..23ec0040d1e 100644 --- a/test/src/sdk-harness/test_projects/token_ops/mod.rs +++ b/test/src/sdk-harness/test_projects/token_ops/mod.rs @@ -1,5 +1,4 @@ use fuels::prelude::*; -use fuels::signers::wallet::Wallet; use fuels::tx::{AssetId, ContractId}; abigen!( @@ -304,7 +303,7 @@ async fn can_perform_generic_transfer_to_contract() { assert_eq!(result.value, amount) } -async fn get_fuelcoin_instance(wallet: Wallet) -> (TestFuelCoinContract, ContractId) { +async fn get_fuelcoin_instance(wallet: WalletUnlocked) -> (TestFuelCoinContract, ContractId) { let fuelcoin_id = Contract::deploy( "test_projects/token_ops/out/debug/token_ops.bin", &wallet, @@ -322,7 +321,7 @@ async fn get_fuelcoin_instance(wallet: Wallet) -> (TestFuelCoinContract, Contrac (fuelcoin_instance, fuelcoin_id.into()) } -async fn get_balance_contract_id(wallet: Wallet) -> ContractId { +async fn get_balance_contract_id(wallet: WalletUnlocked) -> ContractId { let balance_id = Contract::deploy( "test_artifacts/balance_contract/out/debug/balance_contract.bin", &wallet, diff --git a/test/src/sdk-harness/test_projects/tx_fields/mod.rs b/test/src/sdk-harness/test_projects/tx_fields/mod.rs index 4164a948b7f..b1f4d2da31c 100644 --- a/test/src/sdk-harness/test_projects/tx_fields/mod.rs +++ b/test/src/sdk-harness/test_projects/tx_fields/mod.rs @@ -1,7 +1,5 @@ -use fuel_types::bytes::WORD_SIZE; use fuel_vm::fuel_tx::ConsensusParameters; use fuels::prelude::*; -use fuels::signers::wallet::Wallet; use fuels::tx::{Bytes32, ContractId}; use std::str::FromStr; @@ -10,7 +8,7 @@ abigen!( "test_artifacts/tx_contract/out/debug/tx_contract-abi.json", ); -async fn get_contracts() -> (TxContractTest, ContractId, Wallet) { +async fn get_contracts() -> (TxContractTest, ContractId, WalletUnlocked) { let wallet = launch_provider_and_get_wallet().await; let contract_id = Contract::deploy( @@ -34,18 +32,17 @@ async fn can_get_tx_type() { let result = contract_instance.get_tx_type().call().await.unwrap(); // Script transactions are of type = 0 - assert_eq!(result.value, 0); + assert_eq!(result.value, Transaction::Script()); } #[tokio::test] async fn can_get_gas_price() { let (contract_instance, _, _) = get_contracts().await; - // TODO set this to a non-zero value once SDK supports spending coins. - let gas_price = 0; + let gas_price = 3; let result = contract_instance .get_tx_gas_price() - .tx_params(TxParameters::new(Some(gas_price), None, None, None)) + .tx_params(TxParameters::new(Some(gas_price), None, None)) .call() .await .unwrap(); @@ -59,28 +56,13 @@ async fn can_get_gas_limit() { let result = contract_instance .get_tx_gas_limit() - .tx_params(TxParameters::new(None, Some(gas_limit), None, None)) + .tx_params(TxParameters::new(None, Some(gas_limit), None)) .call() .await .unwrap(); assert_eq!(result.value, gas_limit); } -#[tokio::test] -async fn can_get_byte_price() { - let (contract_instance, _, _) = get_contracts().await; - // TODO set this to a non-zero value once SDK supports spending coins. - let byte_price = 0; - - let result = contract_instance - .get_tx_byte_price() - .tx_params(TxParameters::new(None, None, Some(byte_price), None)) - .call() - .await - .unwrap(); - assert_eq!(result.value, byte_price); -} - #[tokio::test] async fn can_get_maturity() { let (contract_instance, _, _) = get_contracts().await; @@ -176,20 +158,9 @@ async fn can_get_receipts_root() { #[tokio::test] async fn can_get_script_start_offset() { let (contract_instance, _, _) = get_contracts().await; - // TODO https://github.com/FuelLabs/fuel-tx/issues/98 - const TRANSACTION_SCRIPT_FIXED_SIZE: usize = WORD_SIZE // Identifier - + WORD_SIZE // Gas price - + WORD_SIZE // Gas limit - + WORD_SIZE // Byte price - + WORD_SIZE // Maturity - + WORD_SIZE // Script size - + WORD_SIZE // Script data size - + WORD_SIZE // Inputs size - + WORD_SIZE // Outputs size - + WORD_SIZE // Witnesses size - + Bytes32::LEN; // Receipts root - let script_start_offset = - ConsensusParameters::DEFAULT.tx_offset() + TRANSACTION_SCRIPT_FIXED_SIZE; + + let script_start_offset = ConsensusParameters::DEFAULT.tx_offset() + + fuel_vm::fuel_tx::consts::TRANSACTION_SCRIPT_FIXED_SIZE; let result = contract_instance .get_tx_script_start_pointer() @@ -200,37 +171,15 @@ async fn can_get_script_start_offset() { } #[tokio::test] -async fn can_get_tx_input_type() { +async fn can_get_input_type() { let (contract_instance, _, _) = get_contracts().await; - // Contract input - let input_type = 1; - let result_ptr = contract_instance - .get_tx_input_pointer(0) - .call() - .await - .unwrap(); + let result = contract_instance.get_input_type(0).call().await.unwrap(); + assert_eq!(result.value, Input::Contract()); - let result = contract_instance - .get_tx_input_type_from_ptr(result_ptr.value) - .call() - .await - .unwrap(); - assert_eq!(result.value, input_type); + let result = contract_instance.get_input_type(1).call().await.unwrap(); - // Coin input - let input_type = 0; - let result_ptr = contract_instance - .get_tx_input_pointer(1) - .call() - .await - .unwrap(); - let result = contract_instance - .get_tx_input_type_from_ptr(result_ptr.value) - .call() - .await - .unwrap(); - assert_eq!(result.value, input_type); + assert_eq!(result.value, Input::Coin()); } // TODO: Add tests for getting InputMessage owner, type when InputMessages land. @@ -239,6 +188,7 @@ async fn can_get_tx_input_coin_owner() { let (contract_instance, _, wallet) = get_contracts().await; let owner_result = contract_instance + // @review "InputNotFound" ! .get_tx_input_coin_owner(1) .call() .await @@ -250,34 +200,19 @@ async fn can_get_tx_input_coin_owner() { #[tokio::test] async fn can_get_tx_output_type() { let (contract_instance, _, _) = get_contracts().await; - - // Contract output - let output_type = 1; - let result_ptr = contract_instance - .get_tx_output_pointer(0) - .call() - .await - .unwrap(); let result = contract_instance - .get_tx_output_type(result_ptr.value) + .get_tx_output_type(0) .call() .await .unwrap(); - assert_eq!(result.value, output_type); + assert_eq!(result.value, Output::Contract()); - // Change output - let output_type = 3; - let result_ptr = contract_instance - .get_tx_output_pointer(1) - .call() - .await - .unwrap(); let result = contract_instance - .get_tx_output_type(result_ptr.value) + .get_tx_output_type(1) .call() .await .unwrap(); - assert_eq!(result.value, output_type); + assert_eq!(result.value, Output::Change()); } #[tokio::test] @@ -285,7 +220,7 @@ async fn can_get_tx_id() { let (contract_instance, _, _) = get_contracts().await; let call_handler = contract_instance.get_tx_id(); - let script = call_handler.get_script().await; + let script = call_handler.get_call_execution_script().await.unwrap(); let tx_id = script.tx.id(); let result = contract_instance.get_tx_id().call().await.unwrap();