From 74338eef7c58ebda462db572d9814b7d50abbc32 Mon Sep 17 00:00:00 2001 From: xunilrj Date: Mon, 24 Jul 2023 15:09:14 +0100 Subject: [PATCH] u256 implementation --- .github/workflows/ci.yml | 2 +- Cargo.lock | 221 ++++++++------- Cargo.toml | 22 +- ci_checks.sh | 2 +- forc-pkg/src/pkg.rs | 64 +++-- forc-plugins/forc-client/Cargo.toml | 2 +- forc-plugins/forc-client/src/util/tx.rs | 8 +- .../forc-doc/src/render/item/type_anchor.rs | 1 + forc-plugins/forc-tx/src/lib.rs | 11 + sway-ast/src/literal.rs | 1 + sway-core/Cargo.toml | 2 + .../{evm_json_abi.rs => evm_abi.rs} | 60 ++-- .../{fuel_json_abi.rs => fuel_abi.rs} | 267 +++++++++--------- sway-core/src/abi_generation/mod.rs | 4 +- .../src/asm_generation/fuel/data_section.rs | 12 +- .../asm_generation/fuel/fuel_asm_builder.rs | 103 +++++-- .../src/asm_generation/fuel/functions.rs | 1 + .../asm_generation/fuel/register_allocator.rs | 9 +- sway-core/src/asm_lang/allocated_ops.rs | 11 + sway-core/src/asm_lang/mod.rs | 1 + sway-core/src/asm_lang/virtual_ops.rs | 66 ++++- sway-core/src/ir_generation.rs | 2 +- sway-core/src/ir_generation/const_eval.rs | 26 +- sway-core/src/ir_generation/convert.rs | 8 +- sway-core/src/language/literal.rs | 6 + sway-core/src/lib.rs | 4 +- .../match_expression/analysis/pattern.rs | 1 + .../ast_node/expression/typed_expression.rs | 2 + .../typed_expression/method_application.rs | 5 +- .../semantic_analysis/node_dependencies.rs | 1 + .../to_parsed_lang/convert_parse_tree.rs | 3 +- sway-core/src/type_system/info.rs | 4 + sway-ir/src/constant.rs | 4 +- sway-ir/src/irtype.rs | 25 +- sway-ir/src/optimize/constants.rs | 14 +- sway-ir/src/optimize/memcpyopt.rs | 3 +- sway-ir/src/parser.rs | 9 +- sway-ir/src/verify.rs | 30 +- sway-lib-core/src/ops.sw | 181 ++++++++---- sway-lsp/src/traverse/parsed_tree.rs | 1 + sway-lsp/src/utils/debug.rs | 1 + sway-parse/src/token.rs | 3 + sway-types/src/integer_bits.rs | 2 + templates/sway-test-rs/template/Cargo.toml | 2 +- test/src/e2e_vm_tests/mod.rs | 1 + .../language/ops/json_abi_oracle.json | 2 +- .../should_pass/language/u256_ops/Forc.lock | 13 + .../should_pass/language/u256_ops/Forc.toml | 8 + .../language/u256_ops/json_abi_oracle.json | 25 ++ .../should_pass/language/u256_ops/src/main.sw | 41 +++ .../should_pass/language/u256_ops/test.toml | 3 + .../array_of_structs_caller/src/main.sw | 2 +- .../bal_opcode/src/main.sw | 2 +- .../call_abi_with_tuples/src/main.sw | 2 +- .../call_basic_storage/src/main.sw | 2 +- .../src/main.sw | 2 +- .../call_increment_contract/src/main.sw | 2 +- .../caller_auth_test/src/main.sw | 2 +- .../caller_context_test/src/main.sw | 2 +- .../nested_struct_args_caller/src/main.sw | 2 +- .../storage_access_caller/src/main.sw | 2 +- .../token_ops_test/src/main.sw | 4 +- .../test_abis/auth_testing_abi/Forc.lock | 7 +- .../contract_multi_test/src/main.sw | 4 +- test/src/ir_generation/mod.rs | 12 +- .../src/ir_generation/tests/let_const_init.sw | 2 +- test/src/ir_generation/tests/u256.sw | 18 ++ test/src/sdk-harness/Cargo.lock | 229 ++++++++------- test/src/sdk-harness/Cargo.toml | 8 +- .../predicate_data_simple/mod.rs | 23 +- .../predicate_data_struct/mod.rs | 5 +- .../test_projects/script_data/mod.rs | 11 +- .../test_projects/tx_fields/mod.rs | 31 +- 73 files changed, 1060 insertions(+), 614 deletions(-) rename sway-core/src/abi_generation/{evm_json_abi.rs => evm_abi.rs} (80%) rename sway-core/src/abi_generation/{fuel_json_abi.rs => fuel_abi.rs} (81%) create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/Forc.lock create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/json_abi_oracle.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/test.toml create mode 100644 test/src/ir_generation/tests/u256.sw diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67b20c55d91..3d7d7847f7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -240,7 +240,7 @@ jobs: runs-on: ubuntu-latest services: fuel-core: - image: ghcr.io/fuellabs/fuel-core:v0.18.2 + image: ghcr.io/fuellabs/fuel-core:v0.19.1 ports: - 4000:4000 steps: diff --git a/Cargo.lock b/Cargo.lock index 4662816f85d..3706bcd4576 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -221,7 +221,7 @@ checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -427,15 +427,15 @@ dependencies = [ [[package]] name = "blake3" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729b71f35bd3fa1a4c86b85d32c8b9069ea7fe14f7a53cfabb65f62d4265b888" +checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5" dependencies = [ "arrayref", "arrayvec 0.7.4", "cc", "cfg-if", - "constant_time_eq 0.2.6", + "constant_time_eq 0.3.0", "digest 0.10.7", ] @@ -500,7 +500,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" dependencies = [ "memchr", - "regex-automata 0.3.0", + "regex-automata 0.3.2", "serde", ] @@ -681,7 +681,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -735,7 +735,7 @@ dependencies = [ "getrandom 0.2.10", "hmac", "once_cell", - "pbkdf2 0.12.1", + "pbkdf2 0.12.2", "rand", "sha2 0.10.7", "thiserror", @@ -858,6 +858,12 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21a53c0a4d288377e7415b53dcfc3c04da5cdc2cc95c8d5ac178b58f0b861ad6" +[[package]] +name = "constant_time_eq" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" + [[package]] name = "convert_case" version = "0.4.0" @@ -871,7 +877,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" dependencies = [ "percent-encoding", - "time 0.3.22", + "time 0.3.23", "version_check", ] @@ -888,7 +894,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "time 0.3.22", + "time 0.3.23", "url", ] @@ -1413,7 +1419,7 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -1505,6 +1511,12 @@ dependencies = [ "uint", ] +[[package]] +name = "ethnum" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0198b9d0078e0f30dedc7acbb21c974e838fc8fae3ee170128658a98cb2c1c04" + [[package]] name = "eventsource-client" version = "0.10.2" @@ -1528,7 +1540,7 @@ checksum = "dd65f1b59dd22d680c7a626cc4a000c1e03d241c51c3e034d2bc9f1e90734f9b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -1852,9 +1864,9 @@ dependencies = [ [[package]] name = "forc-wallet" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c665edcb55f5e6e4f839f1219b4aeab4ef9db354fc5f2eb499b9b93b5b93d84e" +checksum = "81c2e8aa94a9ab8b5f7f6b3aab53701d39b762b5add5b233e5f4241cdf86fad2" dependencies = [ "anyhow", "clap 4.3.11", @@ -1950,15 +1962,15 @@ dependencies = [ "regex", "serde", "serde_json", - "syn 2.0.23", + "syn 2.0.25", "thiserror", ] [[package]] name = "fuel-asm" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1331be83ba8ce8fa9217272b2709bbe29a01daff5fe7ef58ba1b64ec18fe40c0" +checksum = "938aaed0bfed319fab9c6f1196cecc11b55c734c0506613107e1319f98941d17" dependencies = [ "bitflags 1.3.2", "fuel-types", @@ -1968,9 +1980,9 @@ dependencies = [ [[package]] name = "fuel-core-chain-config" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e533fa1f86ae96579f4394205a7dfbad31715043f7119a82aa7a14effaed3a17" +checksum = "d5035cc52016a1d03946b15b776aded23a4dd57b20470ba7d32b0de7b5292319" dependencies = [ "anyhow", "bech32 0.9.1", @@ -1988,9 +2000,9 @@ dependencies = [ [[package]] name = "fuel-core-client" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38a6bf1c0a6e6acf848f4b994e0b91c96c4f443f71d26f437642d135d5d71d3d" +checksum = "730041e36f77a35d634e51f191497a2e182f10ef81721d26f0b2c49aac58469e" dependencies = [ "anyhow", "cynic", @@ -2011,9 +2023,9 @@ dependencies = [ [[package]] name = "fuel-core-storage" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ed1d03eb74feb0ea8538ab557e52c7bc4f1a1c3aaafba9076038da256d86920" +checksum = "b67a83eb8814625b3cfda2671b2bf81006b5164515a446b2274e68dbbdc3d093" dependencies = [ "anyhow", "fuel-core-types", @@ -2023,9 +2035,9 @@ dependencies = [ [[package]] name = "fuel-core-types" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "059da83a7e012a438c9962cbfe1e1b2d3e04f67a75d5be8899009b6456b04002" +checksum = "df7769e4edb5987d0f4cd53926a574ad8f1b5e3bc7c3462f4313799a8ac68f7b" dependencies = [ "anyhow", "derive_more", @@ -2039,9 +2051,9 @@ dependencies = [ [[package]] name = "fuel-crypto" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb3f73571a03523cb92826003753ff1bdd1882767e67801de223ce3ad6133349" +checksum = "aaa3e72ffbe936a643f2d83d91ac19ffd3c687a6f0b2015c6251c10bea60371f" dependencies = [ "borrown", "coins-bip32", @@ -2128,9 +2140,9 @@ dependencies = [ [[package]] name = "fuel-merkle" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d5646d95e02a63fd59da942fcf5d6217dbd8b6866c1ad3a0232be0913c4d077" +checksum = "abf2b9c4dc976a2e0fce4eda29673569fbe89ac86bf5255d3a928beb4c61b23b" dependencies = [ "digest 0.10.7", "fuel-storage", @@ -2142,15 +2154,15 @@ dependencies = [ [[package]] name = "fuel-storage" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b72444da90354b6d1d220b81c6803085689f5e7d53e1d4bd11cfa3d4c5a1b27" +checksum = "55e37ce148bbc07bd1398f717728976d9ad03f147bb500c70579cf317baacd32" [[package]] name = "fuel-tx" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04187579ecfbb04a380c60f9eecae1a288dbe463c111dc7dde66fa736445a638" +checksum = "960f7584fb62cd3af77d70deb015fad0ca1c52e3b0a8e29ff9b005e5b7157448" dependencies = [ "derivative", "fuel-asm", @@ -2168,9 +2180,9 @@ dependencies = [ [[package]] name = "fuel-types" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6543ca2f5124a19b1486507243188a57be64c9914d1908e154a1866eeffb69" +checksum = "d1f9f7bd0f0ae5f8dcebb2cec8d504f45a03fc0bca19c65bfd45b07ed5e9fb68" dependencies = [ "hex", "rand", @@ -2179,12 +2191,13 @@ dependencies = [ [[package]] name = "fuel-vm" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d42e99fe69e913bbde4900f96efb6ceae13b68d369bf22d4b435571d6ed7d65" +checksum = "d3a031708a34fcbee85bca5f4b9f0b61cd80bf8555972020ddee2420d7306a47" dependencies = [ "bitflags 1.3.2", "derivative", + "ethnum", "fuel-asm", "fuel-crypto", "fuel-merkle", @@ -2192,6 +2205,8 @@ dependencies = [ "fuel-tx", "fuel-types", "itertools", + "paste", + "primitive-types", "rand", "serde", "sha3", @@ -2201,9 +2216,9 @@ dependencies = [ [[package]] name = "fuels" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa81d69072a9d4ba6fac79d9b5b66348daf95089ecda85a9231e41e5dd45bc85" +checksum = "5280da1aababb8cae2c4f56d9ac43613e5aab328f62d146bc4598ed3a3e7d93b" dependencies = [ "fuel-core-client", "fuel-tx", @@ -2216,9 +2231,9 @@ dependencies = [ [[package]] name = "fuels-accounts" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9a03259b1ece608c33541477fed7dea07bb3e78f25f85a8a3060f6501d6e982" +checksum = "58e79e6b022c45f8e13cbdbded36232cac380e6885eaac12e8b3234613ad2c3a" dependencies = [ "async-trait", "bytes", @@ -2243,9 +2258,9 @@ dependencies = [ [[package]] name = "fuels-code-gen" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e8ec25373ed1ae06cfe53afc4e3ecd6057aa4ff3a3329e40f42784afe21726b" +checksum = "051906531d2f79ac3a790f06590a5f8b3e63229482494ebdabcce3ca41d581d8" dependencies = [ "Inflector", "fuel-abi-types 0.3.0", @@ -2254,14 +2269,14 @@ dependencies = [ "quote", "regex", "serde_json", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] name = "fuels-core" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b133aff726340284937e3233b8c9dd8429812dd463e4e6f53373ca13e644c99" +checksum = "3ca6bc2b138bcbbd94bc5e00129f0062268135f085208e63c58c9c59a4efc9e5" dependencies = [ "bech32 0.9.1", "chrono", @@ -2283,13 +2298,14 @@ dependencies = [ "strum", "strum_macros 0.24.3", "thiserror", + "uint", ] [[package]] name = "fuels-macros" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef684e13ddc8b16f7828dc98ca309f69a6516068bb307c78b8e64aaf010b397" +checksum = "9dfcb6d4b7f354a55c061350f8013f739b0833758baa1b89e2e1b35791e6030e" dependencies = [ "Inflector", "fuel-abi-types 0.3.0", @@ -2300,14 +2316,14 @@ dependencies = [ "rand", "regex", "serde_json", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] name = "fuels-programs" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09e582cc270a794e02e40150f79d2a92830bf5adaaadf4147de02689ae17c287" +checksum = "32e4febb48ea24ef35489174dc76f449f7d12dadbe22b970ab70250d024405e2" dependencies = [ "async-trait", "bytes", @@ -2333,9 +2349,9 @@ dependencies = [ [[package]] name = "fuels-test-helpers" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3b0f1475beb61ad66163dc57234170b7319aacf79d9147a28c7ff43cc6fd8f0" +checksum = "823d2016fbfe3efbc2e16f1f40f5bda85922e1207f00be50579036ed3a8639d9" dependencies = [ "fuel-core-chain-config", "fuel-core-client", @@ -2419,7 +2435,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -3151,9 +3167,9 @@ checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" [[package]] name = "is-terminal" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.2", "rustix 0.38.3", @@ -3906,7 +3922,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -4055,9 +4071,9 @@ dependencies = [ [[package]] name = "pbkdf2" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0ca0b5a68607598bf3bad68f32227a8164f6254833f84eafaac409cd6746c31" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ "digest 0.10.7", "hmac", @@ -4126,7 +4142,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -4213,7 +4229,7 @@ checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -4246,16 +4262,16 @@ checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "plist" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bd9647b268a3d3e14ff09c23201133a62589c658db02bb7388c7246aafe0590" +checksum = "bdc0001cfea3db57a2e24bc0d818e9e20e554b5f97fabb9bc231dc240269ae06" dependencies = [ "base64 0.21.2", "indexmap 1.9.3", "line-wrap", "quick-xml", "serde", - "time 0.3.22", + "time 0.3.23", ] [[package]] @@ -4390,9 +4406,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" dependencies = [ "unicode-ident", ] @@ -4426,9 +4442,9 @@ dependencies = [ [[package]] name = "quick-xml" -version = "0.28.2" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce5e73202a820a31f8a0ee32ada5e21029c81fd9e3ebf668a40832e4219d9d1" +checksum = "81b9228215d82c7b61490fec1de287136b5de6f5700f6e58ea9ad61a7964ca51" dependencies = [ "memchr", ] @@ -4572,13 +4588,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89089e897c013b3deb627116ae56a6955a72b8bed395c9526af31c9fe528b484" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.0", + "regex-automata 0.3.2", "regex-syntax 0.7.3", ] @@ -4593,9 +4609,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa250384981ea14565685dea16a9ccc4d1c541a13f82b9c168572264d1df8c56" +checksum = "83d3daa6976cffb758ec878f108ba0e062a45b2d6ca3a2cca965338855476caf" dependencies = [ "aho-corasick", "memchr", @@ -5113,22 +5129,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.166" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d01b7404f9d441d3ad40e6a636a7782c377d2abdbe4fa2440e2edcc2f4f10db8" +checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.166" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dd83d6dde2b6b2d466e14d9d1acce8816dedee94f735eac6395808b3483c6d6" +checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -5159,7 +5175,7 @@ checksum = "1d89a8107374290037607734c0b73a85db7ed80cae314b3c5791f192a496e731" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -5333,9 +5349,9 @@ checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" [[package]] name = "snafu" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0656e7e3ffb70f6c39b3c2a86332bb74aa3c679da781642590f3c1118c5045" +checksum = "e4de37ad025c587a29e8f3f5605c00f70b98715ef90b9061a815b9e59e9042d6" dependencies = [ "backtrace", "doc-comment", @@ -5344,9 +5360,9 @@ dependencies = [ [[package]] name = "snafu-derive" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "475b3bbe5245c26f2d8a6f62d67c1f30eb9fffeccee721c45d162c3ebbdf81b2" +checksum = "990079665f075b699031e9c08fd3ab99be5029b96f3b78dc0709e8f77e4efebf" dependencies = [ "heck 0.4.1", "proc-macro2", @@ -5527,6 +5543,7 @@ dependencies = [ "itertools", "lazy_static", "miden-core", + "num-bigint", "pest", "pest_derive", "petgraph", @@ -5708,9 +5725,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.23" +version = "2.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59fb7d6d8281a51045d62b8eb3a7d1ce347b76f312af50cd3dc0af39c87c1737" +checksum = "15e3fc8c0c74267e2df136e5e5fb656a464158aa57624053375eb9c8c6e25ae2" dependencies = [ "proc-macro2", "quote", @@ -5960,22 +5977,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.41" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c16a64ba9387ef3fdae4f9c1a7f07a0997fce91985c0336f1ddc1822b3b37802" +checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.41" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d14928354b01c4d6a4f0e549069adef399a284e7995c7ccca94e8a07a5346c59" +checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -6001,9 +6018,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea9e1b3cf1243ae005d9e74085d4d542f3125458f3a81af210d901dcd7411efd" +checksum = "59e399c068f43a5d116fedaf73b203fa4f9c519f17e2b34f63221d3792f81446" dependencies = [ "itoa", "serde", @@ -6019,9 +6036,9 @@ checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +checksum = "96ba15a897f3c86766b757e5ac7221554c6750054d74d5b28844fce5fb36a6c4" dependencies = [ "time-core", ] @@ -6107,7 +6124,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -6267,7 +6284,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -6353,9 +6370,9 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "ucd-trie" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "uint" @@ -6596,7 +6613,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", "wasm-bindgen-shared", ] @@ -6630,7 +6647,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6884,9 +6901,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca0ace3845f0d96209f0375e6d367e3eb87eb65d27d445bdc9f1843a26f39448" +checksum = "81a2094c43cc94775293eaa0e499fbc30048a6d824ac82c0351a8c0bf9112529" dependencies = [ "memchr", ] @@ -7039,5 +7056,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] diff --git a/Cargo.toml b/Cargo.toml index ccb7d375eec..728e050fde0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,21 +24,17 @@ members = [ "swayfmt", "test", ] -exclude = [ - "examples/*", - "swayfmt/test_macros", - "forc-test/test_data" -] +exclude = ["examples/*", "swayfmt/test_macros", "forc-test/test_data"] [workspace.dependencies] -fuel-asm = "0.31.1" -fuel-crypto = "0.31.1" -fuel-types = "0.31.1" -fuel-tx = "0.31.1" -fuel-core-client = { version = "0.18.2", default-features = false } -fuel-vm = "0.31.2" -fuels-core = "0.43" -fuels-accounts = "0.43" +fuel-asm = "0.34.1" +fuel-crypto = "0.34.1" +fuel-types = "0.34.1" +fuel-tx = "0.34.1" +fuel-core-client = { version = "0.19.1", default-features = false } +fuel-vm = "0.34.1" +fuels-core = "0.44" +fuels-accounts = "0.44" [workspace.package] edition = "2021" diff --git a/ci_checks.sh b/ci_checks.sh index adbb58dda43..ae689aa98ef 100755 --- a/ci_checks.sh +++ b/ci_checks.sh @@ -6,7 +6,7 @@ # - `cargo run --locked --release --bin test -- --locked` # # You can install `fuel-core` node by: -# `cargo install fuel-core-bin --git https://github.com/FuelLabs/fuel-core --tag v0.18.1 --locked` +# `cargo install fuel-core-bin --git https://github.com/FuelLabs/fuel-core --tag v0.19.1 --locked` # # And run it with: # `fuel-core run --db-type in-memory` diff --git a/forc-pkg/src/pkg.rs b/forc-pkg/src/pkg.rs index 354e65fc347..b6c53d35bc4 100644 --- a/forc-pkg/src/pkg.rs +++ b/forc-pkg/src/pkg.rs @@ -25,12 +25,12 @@ use std::{ str::FromStr, sync::Arc, }; -use sway_core::fuel_prelude::fuel_tx::ConsensusParameters; +use sway_core::fuel_prelude::fuel_types::ChainId; pub use sway_core::Programs; use sway_core::{ abi_generation::{ - evm_json_abi, - fuel_json_abi::{self, JsonAbiContext}, + evm_abi, + fuel_abi::{self, AbiContext}, }, asm_generation::ProgramABI, decl_engine::DeclRefFunction, @@ -428,27 +428,12 @@ impl BuiltPackage { Ok(()) } - /// Writes BuiltPackage to `output_dir`. - pub fn write_output( - &self, - minify: MinifyOpts, - pkg_name: &str, - output_dir: &Path, - ) -> Result<()> { - if !output_dir.exists() { - fs::create_dir_all(output_dir)?; - } - // Place build artifacts into the output directory. - let bin_path = output_dir.join(pkg_name).with_extension("bin"); - - self.write_bytecode(&bin_path)?; - - let program_abi_stem = format!("{pkg_name}-abi"); - let program_abi_path = output_dir.join(program_abi_stem).with_extension("json"); + /// Writes the ABI in JSON format to the given `path`. + pub fn write_json_abi(&self, path: &Path, minify: MinifyOpts) -> Result<()> { match &self.program_abi { ProgramABI::Fuel(program_abi) => { if !program_abi.functions.is_empty() { - let file = File::create(program_abi_path)?; + let file = File::create(path)?; let res = if minify.json_abi { serde_json::to_writer(&file, &program_abi) } else { @@ -459,7 +444,7 @@ impl BuiltPackage { } ProgramABI::Evm(program_abi) => { if !program_abi.is_empty() { - let file = File::create(program_abi_path)?; + let file = File::create(path)?; let res = if minify.json_abi { serde_json::to_writer(&file, &program_abi) } else { @@ -472,6 +457,28 @@ impl BuiltPackage { ProgramABI::MidenVM(_) => (), } + Ok(()) + } + + /// Writes BuiltPackage to `output_dir`. + pub fn write_output( + &self, + minify: MinifyOpts, + pkg_name: &str, + output_dir: &Path, + ) -> Result<()> { + if !output_dir.exists() { + fs::create_dir_all(output_dir)?; + } + // Place build artifacts into the output directory. + let bin_path = output_dir.join(pkg_name).with_extension("bin"); + + self.write_bytecode(&bin_path)?; + + let program_abi_stem = format!("{pkg_name}-abi"); + let json_abi_path = output_dir.join(program_abi_stem).with_extension("json"); + self.write_json_abi(&json_abi_path, minify.clone())?; + info!(" Bytecode size: {} bytes", self.bytecode.bytes.len()); // Additional ops required depending on the program type match self.tree_type { @@ -493,10 +500,7 @@ impl BuiltPackage { // TODO: Pass the user specified `ChainId` into `predicate_owner` let root = format!( "0x{}", - fuel_tx::Input::predicate_owner( - &self.bytecode.bytes, - &ConsensusParameters::DEFAULT - ) + fuel_tx::Input::predicate_owner(&self.bytecode.bytes, &ChainId::default(),) ); let root_file_name = format!("{}{}", &pkg_name, SWAY_BIN_ROOT_SUFFIX); let root_path = output_dir.join(root_file_name); @@ -1814,10 +1818,10 @@ pub fn compile( ProgramABI::Fuel(time_expr!( "generate JSON ABI program", "generate_json_abi", - fuel_json_abi::generate_json_abi_program( - &mut JsonAbiContext { + fuel_abi::generate_program_abi( + &mut AbiContext { program: typed_program, - json_abi_with_callpaths: profile.json_abi_with_callpaths, + abi_with_callpaths: profile.json_abi_with_callpaths, }, engines.te(), engines.de(), @@ -1841,7 +1845,7 @@ pub fn compile( let abi = time_expr!( "generate JSON ABI program", "generate_json_abi", - evm_json_abi::generate_json_abi_program(typed_program, engines), + evm_abi::generate_abi_program(typed_program, engines), Some(sway_build_config.clone()), metrics ); diff --git a/forc-plugins/forc-client/Cargo.toml b/forc-plugins/forc-client/Cargo.toml index 63ee2bdce89..bd0ae26629e 100644 --- a/forc-plugins/forc-client/Cargo.toml +++ b/forc-plugins/forc-client/Cargo.toml @@ -19,7 +19,7 @@ forc-pkg = { version = "0.42.1", path = "../../forc-pkg" } forc-tracing = { version = "0.42.1", path = "../../forc-tracing" } forc-tx = { version = "0.42.1", path = "../forc-tx" } forc-util = { version = "0.42.1", path = "../../forc-util" } -forc-wallet = "0.2.3" +forc-wallet = "0.2.4" fuel-abi-types = "0.3" fuel-core-client = { workspace = true } fuel-crypto = { workspace = true } diff --git a/forc-plugins/forc-client/src/util/tx.rs b/forc-plugins/forc-client/src/util/tx.rs index 2a081ea1ac3..d9846b92cd9 100644 --- a/forc-plugins/forc-client/src/util/tx.rs +++ b/forc-plugins/forc-client/src/util/tx.rs @@ -228,7 +228,7 @@ impl TransactionBuild None }; - let mut tx = self._finalize_without_signature(); + let mut tx = self.finalize_without_signature_inner(); if !unsigned { let signature = if let Some(signing_key) = signing_key { @@ -237,16 +237,16 @@ impl TransactionBuild // of a cryptographically secure hash. However, the bytes are // coming from `tx.id()`, which already uses `Hasher::hash()` // to hash it using a secure hash mechanism. - let message = Message::from_bytes(*tx.id(¶ms)); + let message = Message::from_bytes(*tx.id(¶ms.chain_id)); Signature::sign(&signing_key, &message) } else { - prompt_signature(tx.id(¶ms))? + prompt_signature(tx.id(¶ms.chain_id))? }; let witness = Witness::from(signature.as_ref()); tx.replace_witness(signature_witness_index, witness); } - tx.precompute(¶ms); + tx.precompute(¶ms.chain_id)?; Ok(tx) } diff --git a/forc-plugins/forc-doc/src/render/item/type_anchor.rs b/forc-plugins/forc-doc/src/render/item/type_anchor.rs index f57d67e2f7a..94ccf077c64 100644 --- a/forc-plugins/forc-doc/src/render/item/type_anchor.rs +++ b/forc-plugins/forc-doc/src/render/item/type_anchor.rs @@ -96,6 +96,7 @@ pub(crate) fn render_type_anchor( IntegerBits::Sixteen => "u16", IntegerBits::ThirtyTwo => "u32", IntegerBits::SixtyFour => "u64", + IntegerBits::V256 => "u256", }; Ok(box_html! { : uint; diff --git a/forc-plugins/forc-tx/src/lib.rs b/forc-plugins/forc-tx/src/lib.rs index 91939744cda..a29772c51ff 100644 --- a/forc-plugins/forc-tx/src/lib.rs +++ b/forc-plugins/forc-tx/src/lib.rs @@ -153,6 +153,9 @@ pub struct InputCoin { /// UTXO being spent must have been created at least this many blocks ago. #[clap(long)] pub maturity: u32, + /// Gas used by predicates. + #[clap(long, default_value_t = 0)] + pub predicate_gas_used: u64, #[clap(flatten)] pub predicate: Predicate, } @@ -199,6 +202,9 @@ pub struct InputMessage { /// Index of witness that authorizes the message. #[clap(long)] pub witness_ix: Option, + /// Gas used by predicates. + #[clap(long, default_value_t = 0)] + pub predicate_gas_used: u64, #[clap(flatten)] pub predicate: Predicate, } @@ -700,6 +706,7 @@ impl TryFrom for fuel_tx::Input { asset_id, tx_ptr: tx_pointer, maturity, + predicate_gas_used, predicate, witness_ix, } = coin; @@ -721,6 +728,7 @@ impl TryFrom for fuel_tx::Input { asset_id, tx_pointer, maturity.into(), + predicate_gas_used, std::fs::read(&predicate).map_err(|err| { ConvertInputError::PredicateRead { path: predicate, @@ -755,6 +763,7 @@ impl TryFrom for fuel_tx::Input { nonce, msg_data, witness_ix, + predicate_gas_used, predicate, } = msg; let data = @@ -803,6 +812,7 @@ impl TryFrom for fuel_tx::Input { recipient, amount, nonce, + predicate_gas_used, predicate, predicate_data, ) @@ -812,6 +822,7 @@ impl TryFrom for fuel_tx::Input { recipient, amount, nonce, + predicate_gas_used, data, predicate, predicate_data, diff --git a/sway-ast/src/literal.rs b/sway-ast/src/literal.rs index d2e8f4e94ae..c04700e2107 100644 --- a/sway-ast/src/literal.rs +++ b/sway-ast/src/literal.rs @@ -25,6 +25,7 @@ pub enum LitIntType { U16, U32, U64, + U256, I8, I16, I32, diff --git a/sway-core/Cargo.toml b/sway-core/Cargo.toml index 66f3da2a850..12904b0098a 100644 --- a/sway-core/Cargo.toml +++ b/sway-core/Cargo.toml @@ -27,6 +27,7 @@ im = "15.0" itertools = "0.10" lazy_static = "1.4" miden-core = "0.3.0" +num-bigint = { version = "0.4.3", features = ["serde"] } pest = "2.1.3" pest_derive = "2.1" petgraph = "0.6" @@ -47,5 +48,6 @@ tracing = "0.1" uint = "0.9" vec1 = "1.8.0" + [target.'cfg(not(target_os = "macos"))'.dependencies] sysinfo = "0.29.0" diff --git a/sway-core/src/abi_generation/evm_json_abi.rs b/sway-core/src/abi_generation/evm_abi.rs similarity index 80% rename from sway-core/src/abi_generation/evm_json_abi.rs rename to sway-core/src/abi_generation/evm_abi.rs index 7597af9699d..c58a5043289 100644 --- a/sway-core/src/abi_generation/evm_json_abi.rs +++ b/sway-core/src/abi_generation/evm_abi.rs @@ -7,17 +7,17 @@ use crate::{ Engines, TypeArgument, TypeEngine, TypeId, TypeInfo, }; -pub fn generate_json_abi_program(program: &TyProgram, engines: &Engines) -> EvmAbiResult { +pub fn generate_abi_program(program: &TyProgram, engines: &Engines) -> EvmAbiResult { let type_engine = engines.te(); let decl_engine = engines.de(); match &program.kind { TyProgramKind::Contract { abi_entries, .. } => abi_entries .iter() - .map(|x| generate_json_abi_function(x, type_engine, decl_engine)) + .map(|x| generate_abi_function(x, type_engine, decl_engine)) .collect(), TyProgramKind::Script { main_function, .. } | TyProgramKind::Predicate { main_function, .. } => { - vec![generate_json_abi_function( + vec![generate_abi_function( main_function, type_engine, decl_engine, @@ -28,7 +28,7 @@ pub fn generate_json_abi_program(program: &TyProgram, engines: &Engines) -> EvmA } /// Gives back a string that represents the type, considering what it resolves to -fn get_json_type_str( +fn get_type_str( type_id: &TypeId, type_engine: &TypeEngine, decl_engine: &DeclEngine, @@ -37,20 +37,20 @@ fn get_json_type_str( if type_id.is_generic_parameter(type_engine, decl_engine, resolved_type_id) { format!( "generic {}", - json_abi_str(&type_engine.get(*type_id), type_engine, decl_engine) + abi_str(&type_engine.get(*type_id), type_engine, decl_engine) ) } else { match (type_engine.get(*type_id), type_engine.get(resolved_type_id)) { (TypeInfo::Custom { .. }, TypeInfo::Struct { .. }) => { format!( "struct {}", - json_abi_str(&type_engine.get(*type_id), type_engine, decl_engine) + abi_str(&type_engine.get(*type_id), type_engine, decl_engine) ) } (TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => { format!( "enum {}", - json_abi_str(&type_engine.get(*type_id), type_engine, decl_engine) + abi_str(&type_engine.get(*type_id), type_engine, decl_engine) ) } (TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => { @@ -68,19 +68,15 @@ fn get_json_type_str( (TypeInfo::Custom { .. }, _) => { format!( "generic {}", - json_abi_str(&type_engine.get(*type_id), type_engine, decl_engine) + abi_str(&type_engine.get(*type_id), type_engine, decl_engine) ) } - _ => json_abi_str(&type_engine.get(*type_id), type_engine, decl_engine), + _ => abi_str(&type_engine.get(*type_id), type_engine, decl_engine), } } } -pub fn json_abi_str( - type_info: &TypeInfo, - type_engine: &TypeEngine, - decl_engine: &DeclEngine, -) -> String { +pub fn abi_str(type_info: &TypeInfo, type_engine: &TypeEngine, decl_engine: &DeclEngine) -> String { use TypeInfo::*; match type_info { Unknown => "unknown".into(), @@ -93,6 +89,7 @@ pub fn json_abi_str( IntegerBits::Sixteen => "uint16", IntegerBits::ThirtyTwo => "uint32", IntegerBits::SixtyFour => "uint64", + IntegerBits::V256 => todo!(), } .into(), Boolean => "bool".into(), @@ -100,7 +97,7 @@ pub fn json_abi_str( Tuple(fields) => { let field_strs = fields .iter() - .map(|field| json_abi_str_type_arg(field, type_engine, decl_engine)) + .map(|field| abi_str_type_arg(field, type_engine, decl_engine)) .collect::>(); format!("({})", field_strs.join(", ")) } @@ -123,7 +120,7 @@ pub fn json_abi_str( Array(elem_ty, length) => { format!( "{}[{}]", - json_abi_str_type_arg(elem_ty, type_engine, decl_engine), + abi_str_type_arg(elem_ty, type_engine, decl_engine), length.val() ) } @@ -131,22 +128,16 @@ pub fn json_abi_str( RawUntypedPtr => "raw untyped ptr".into(), RawUntypedSlice => "raw untyped slice".into(), Ptr(ty) => { - format!( - "__ptr {}", - json_abi_str_type_arg(ty, type_engine, decl_engine) - ) + format!("__ptr {}", abi_str_type_arg(ty, type_engine, decl_engine)) } Slice(ty) => { - format!( - "__slice {}", - json_abi_str_type_arg(ty, type_engine, decl_engine) - ) + format!("__slice {}", abi_str_type_arg(ty, type_engine, decl_engine)) } - Alias { ty, .. } => json_abi_str_type_arg(ty, type_engine, decl_engine), + Alias { ty, .. } => abi_str_type_arg(ty, type_engine, decl_engine), } } -pub fn json_abi_param_type( +pub fn abi_param_type( type_info: &TypeInfo, type_engine: &TypeEngine, decl_engine: &DeclEngine, @@ -159,6 +150,7 @@ pub fn json_abi_param_type( IntegerBits::Sixteen => ethabi::ParamType::Uint(16), IntegerBits::ThirtyTwo => ethabi::ParamType::Uint(32), IntegerBits::SixtyFour => ethabi::ParamType::Uint(64), + IntegerBits::V256 => todo!(), }, Boolean => ethabi::ParamType::Bool, B256 => ethabi::ParamType::Uint(256), @@ -167,7 +159,7 @@ pub fn json_abi_param_type( Tuple(fields) => ethabi::ParamType::Tuple( fields .iter() - .map(|f| json_abi_param_type(&type_engine.get(f.type_id), type_engine, decl_engine)) + .map(|f| abi_param_type(&type_engine.get(f.type_id), type_engine, decl_engine)) .collect::>(), ), Struct(decl_ref) => { @@ -176,7 +168,7 @@ pub fn json_abi_param_type( decl.fields .iter() .map(|f| { - json_abi_param_type( + abi_param_type( &type_engine.get(f.type_argument.type_id), type_engine, decl_engine, @@ -185,7 +177,7 @@ pub fn json_abi_param_type( .collect::>(), ) } - Array(elem_ty, ..) => ethabi::ParamType::Array(Box::new(json_abi_param_type( + Array(elem_ty, ..) => ethabi::ParamType::Array(Box::new(abi_param_type( &type_engine.get(elem_ty.type_id), type_engine, decl_engine, @@ -194,7 +186,7 @@ pub fn json_abi_param_type( } } -pub(self) fn generate_json_abi_function( +pub(self) fn generate_abi_function( fn_decl: &TyFunctionDecl, type_engine: &TypeEngine, decl_engine: &DeclEngine, @@ -206,7 +198,7 @@ pub(self) fn generate_json_abi_function( .map(|x| ethabi::Param { name: x.name.to_string(), kind: ethabi::ParamType::Address, - internal_type: Some(get_json_type_str( + internal_type: Some(get_type_str( &x.type_argument.type_id, type_engine, decl_engine, @@ -219,7 +211,7 @@ pub(self) fn generate_json_abi_function( let output_type = ethabi::Param { name: String::default(), kind: ethabi::ParamType::Address, - internal_type: Some(get_json_type_str( + internal_type: Some(get_type_str( &fn_decl.return_type.type_id, type_engine, decl_engine, @@ -238,10 +230,10 @@ pub(self) fn generate_json_abi_function( }) } -pub(self) fn json_abi_str_type_arg( +pub(self) fn abi_str_type_arg( type_arg: &TypeArgument, type_engine: &TypeEngine, decl_engine: &DeclEngine, ) -> String { - json_abi_str(&type_engine.get(type_arg.type_id), type_engine, decl_engine) + abi_str(&type_engine.get(type_arg.type_id), type_engine, decl_engine) } diff --git a/sway-core/src/abi_generation/fuel_json_abi.rs b/sway-core/src/abi_generation/fuel_abi.rs similarity index 81% rename from sway-core/src/abi_generation/fuel_json_abi.rs rename to sway-core/src/abi_generation/fuel_abi.rs index 83fa6f1106d..30d59b0a8dd 100644 --- a/sway-core/src/abi_generation/fuel_json_abi.rs +++ b/sway-core/src/abi_generation/fuel_abi.rs @@ -11,13 +11,13 @@ use crate::{ TypeArgument, TypeEngine, TypeId, TypeInfo, TypeParameter, }; -pub struct JsonAbiContext<'a> { +pub struct AbiContext<'a> { pub program: &'a TyProgram, - pub json_abi_with_callpaths: bool, + pub abi_with_callpaths: bool, } -pub fn generate_json_abi_program( - ctx: &mut JsonAbiContext, +pub fn generate_program_abi( + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, types: &mut Vec, @@ -26,11 +26,11 @@ pub fn generate_json_abi_program( TyProgramKind::Contract { abi_entries, .. } => { let functions = abi_entries .iter() - .map(|x| x.generate_json_abi_function(ctx, type_engine, decl_engine, types)) + .map(|x| x.generate_abi_function(ctx, type_engine, decl_engine, types)) .collect(); - let logged_types = generate_json_logged_types(ctx, type_engine, decl_engine, types); - let messages_types = generate_json_messages_types(ctx, type_engine, decl_engine, types); - let configurables = generate_json_configurables(ctx, type_engine, decl_engine, types); + let logged_types = generate_logged_types(ctx, type_engine, decl_engine, types); + let messages_types = generate_messages_types(ctx, type_engine, decl_engine, types); + let configurables = generate_configurables(ctx, type_engine, decl_engine, types); program_abi::ProgramABI { types: types.to_vec(), functions, @@ -41,15 +41,11 @@ pub fn generate_json_abi_program( } TyProgramKind::Script { main_function, .. } | TyProgramKind::Predicate { main_function, .. } => { - let functions = vec![main_function.generate_json_abi_function( - ctx, - type_engine, - decl_engine, - types, - )]; - let logged_types = generate_json_logged_types(ctx, type_engine, decl_engine, types); - let messages_types = generate_json_messages_types(ctx, type_engine, decl_engine, types); - let configurables = generate_json_configurables(ctx, type_engine, decl_engine, types); + let functions = + vec![main_function.generate_abi_function(ctx, type_engine, decl_engine, types)]; + let logged_types = generate_logged_types(ctx, type_engine, decl_engine, types); + let messages_types = generate_messages_types(ctx, type_engine, decl_engine, types); + let configurables = generate_configurables(ctx, type_engine, decl_engine, types); program_abi::ProgramABI { types: types.to_vec(), functions, @@ -68,8 +64,8 @@ pub fn generate_json_abi_program( } } -fn generate_json_logged_types( - ctx: &mut JsonAbiContext, +fn generate_logged_types( + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, types: &mut Vec, @@ -81,15 +77,15 @@ fn generate_json_logged_types( .iter() .map(|(_, type_id)| program_abi::TypeDeclaration { type_id: type_id.index(), - type_field: type_id.get_json_type_str(ctx, type_engine, decl_engine, *type_id), - components: type_id.get_json_type_components( + type_field: type_id.get_abi_type_str(ctx, type_engine, decl_engine, *type_id), + components: type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, *type_id, ), - type_parameters: type_id.get_json_type_parameters( + type_parameters: type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -111,7 +107,7 @@ fn generate_json_logged_types( application: program_abi::TypeApplication { name: "".to_string(), type_id: type_id.index(), - type_arguments: type_id.get_json_type_arguments( + type_arguments: type_id.get_abi_type_arguments( ctx, type_engine, decl_engine, @@ -123,8 +119,8 @@ fn generate_json_logged_types( .collect() } -fn generate_json_messages_types( - ctx: &mut JsonAbiContext, +fn generate_messages_types( + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, types: &mut Vec, @@ -136,15 +132,15 @@ fn generate_json_messages_types( .iter() .map(|(_, type_id)| program_abi::TypeDeclaration { type_id: type_id.index(), - type_field: type_id.get_json_type_str(ctx, type_engine, decl_engine, *type_id), - components: type_id.get_json_type_components( + type_field: type_id.get_abi_type_str(ctx, type_engine, decl_engine, *type_id), + components: type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, *type_id, ), - type_parameters: type_id.get_json_type_parameters( + type_parameters: type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -166,7 +162,7 @@ fn generate_json_messages_types( application: program_abi::TypeApplication { name: "".to_string(), type_id: type_id.index(), - type_arguments: type_id.get_json_type_arguments( + type_arguments: type_id.get_abi_type_arguments( ctx, type_engine, decl_engine, @@ -178,8 +174,8 @@ fn generate_json_messages_types( .collect() } -fn generate_json_configurables( - ctx: &mut JsonAbiContext, +fn generate_configurables( + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, types: &mut Vec, @@ -194,20 +190,20 @@ fn generate_json_configurables( type_ascription, .. }| program_abi::TypeDeclaration { type_id: type_ascription.type_id.index(), - type_field: type_ascription.type_id.get_json_type_str( + type_field: type_ascription.type_id.get_abi_type_str( ctx, type_engine, decl_engine, type_ascription.type_id, ), - components: type_ascription.type_id.get_json_type_components( + components: type_ascription.type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, type_ascription.type_id, ), - type_parameters: type_ascription.type_id.get_json_type_parameters( + type_parameters: type_ascription.type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -235,7 +231,7 @@ fn generate_json_configurables( application: program_abi::TypeApplication { name: "".to_string(), type_id: type_ascription.type_id.index(), - type_arguments: type_ascription.type_id.get_json_type_arguments( + type_arguments: type_ascription.type_id.get_abi_type_arguments( ctx, type_engine, decl_engine, @@ -251,9 +247,9 @@ fn generate_json_configurables( impl TypeId { /// Gives back a string that represents the type, considering what it resolves to - pub(self) fn get_json_type_str( + pub(self) fn get_abi_type_str( &self, - ctx: &mut JsonAbiContext, + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, resolved_type_id: TypeId, @@ -263,19 +259,19 @@ impl TypeId { "generic {}", type_engine .get(*self) - .json_abi_str(ctx, type_engine, decl_engine) + .abi_str(ctx, type_engine, decl_engine) ) } else { match (type_engine.get(*self), type_engine.get(resolved_type_id)) { (TypeInfo::Custom { .. }, TypeInfo::Struct { .. }) => type_engine .get(resolved_type_id) - .json_abi_str(ctx, type_engine, decl_engine), + .abi_str(ctx, type_engine, decl_engine), (TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => type_engine .get(resolved_type_id) - .json_abi_str(ctx, type_engine, decl_engine), + .abi_str(ctx, type_engine, decl_engine), (TypeInfo::Custom { .. }, TypeInfo::Alias { .. }) => type_engine .get(resolved_type_id) - .json_abi_str(ctx, type_engine, decl_engine), + .abi_str(ctx, type_engine, decl_engine), (TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => { assert_eq!(fields.len(), resolved_fields.len()); let field_strs = fields @@ -293,12 +289,12 @@ impl TypeId { "generic {}", type_engine .get(*self) - .json_abi_str(ctx, type_engine, decl_engine) + .abi_str(ctx, type_engine, decl_engine) ) } _ => type_engine .get(*self) - .json_abi_str(ctx, type_engine, decl_engine), + .abi_str(ctx, type_engine, decl_engine), } } } @@ -308,9 +304,9 @@ impl TypeId { /// basically the IDs of some set of `program_abi::TypeDeclaration`s. The method below also /// updates the provide list of `program_abi::TypeDeclaration`s to add the newly discovered /// types. - pub(self) fn get_json_type_parameters( + pub(self) fn get_abi_type_parameters( &self, - ctx: &mut JsonAbiContext, + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, types: &mut Vec, @@ -322,7 +318,7 @@ impl TypeId { .get_type_parameters(type_engine, decl_engine) .map(|v| { v.iter() - .map(|v| v.get_json_type_parameter(ctx, type_engine, decl_engine, types)) + .map(|v| v.get_abi_type_parameter(ctx, type_engine, decl_engine, types)) .collect::>() }), } @@ -331,9 +327,9 @@ impl TypeId { /// actually resolves to. These components are essentially of type of /// `program_abi::TypeApplication`. The method below also updates the provided list of /// `program_abi::TypeDeclaration`s to add the newly discovered types. - pub(self) fn get_json_type_components( + pub(self) fn get_abi_type_components( &self, - ctx: &mut JsonAbiContext, + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, types: &mut Vec, @@ -348,20 +344,20 @@ impl TypeId { .iter() .map(|x| program_abi::TypeDeclaration { type_id: x.type_argument.initial_type_id.index(), - type_field: x.type_argument.initial_type_id.get_json_type_str( + type_field: x.type_argument.initial_type_id.get_abi_type_str( ctx, type_engine, decl_engine, x.type_argument.type_id, ), - components: x.type_argument.initial_type_id.get_json_type_components( + components: x.type_argument.initial_type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, x.type_argument.type_id, ), - type_parameters: x.type_argument.initial_type_id.get_json_type_parameters( + type_parameters: x.type_argument.initial_type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -380,16 +376,13 @@ impl TypeId { .map(|x| program_abi::TypeApplication { name: x.name.to_string(), type_id: x.type_argument.initial_type_id.index(), - type_arguments: x - .type_argument - .initial_type_id - .get_json_type_arguments( - ctx, - type_engine, - decl_engine, - types, - x.type_argument.type_id, - ), + type_arguments: x.type_argument.initial_type_id.get_abi_type_arguments( + ctx, + type_engine, + decl_engine, + types, + x.type_argument.type_id, + ), }) .collect(), ) @@ -403,20 +396,20 @@ impl TypeId { .iter() .map(|x| program_abi::TypeDeclaration { type_id: x.type_argument.initial_type_id.index(), - type_field: x.type_argument.initial_type_id.get_json_type_str( + type_field: x.type_argument.initial_type_id.get_abi_type_str( ctx, type_engine, decl_engine, x.type_argument.type_id, ), - components: x.type_argument.initial_type_id.get_json_type_components( + components: x.type_argument.initial_type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, x.type_argument.type_id, ), - type_parameters: x.type_argument.initial_type_id.get_json_type_parameters( + type_parameters: x.type_argument.initial_type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -435,16 +428,13 @@ impl TypeId { .map(|x| program_abi::TypeApplication { name: x.name.to_string(), type_id: x.type_argument.initial_type_id.index(), - type_arguments: x - .type_argument - .initial_type_id - .get_json_type_arguments( - ctx, - type_engine, - decl_engine, - types, - x.type_argument.type_id, - ), + type_arguments: x.type_argument.initial_type_id.get_abi_type_arguments( + ctx, + type_engine, + decl_engine, + types, + x.type_argument.type_id, + ), }) .collect(), ) @@ -452,22 +442,22 @@ impl TypeId { TypeInfo::Array(..) => { if let TypeInfo::Array(elem_ty, _) = type_engine.get(resolved_type_id) { // The `program_abi::TypeDeclaration`s needed for the array element type - let elem_json_ty = program_abi::TypeDeclaration { + let elem_abi_ty = program_abi::TypeDeclaration { type_id: elem_ty.initial_type_id.index(), - type_field: elem_ty.initial_type_id.get_json_type_str( + type_field: elem_ty.initial_type_id.get_abi_type_str( ctx, type_engine, decl_engine, elem_ty.type_id, ), - components: elem_ty.initial_type_id.get_json_type_components( + components: elem_ty.initial_type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, elem_ty.type_id, ), - type_parameters: elem_ty.initial_type_id.get_json_type_parameters( + type_parameters: elem_ty.initial_type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -475,14 +465,14 @@ impl TypeId { elem_ty.type_id, ), }; - types.push(elem_json_ty); + types.push(elem_abi_ty); // Generate the JSON data for the array. This is basically a single // `program_abi::TypeApplication` for the array element type Some(vec![program_abi::TypeApplication { name: "__array_element".to_string(), type_id: elem_ty.initial_type_id.index(), - type_arguments: elem_ty.initial_type_id.get_json_type_arguments( + type_arguments: elem_ty.initial_type_id.get_abi_type_arguments( ctx, type_engine, decl_engine, @@ -501,20 +491,20 @@ impl TypeId { .iter() .map(|x| program_abi::TypeDeclaration { type_id: x.initial_type_id.index(), - type_field: x.initial_type_id.get_json_type_str( + type_field: x.initial_type_id.get_abi_type_str( ctx, type_engine, decl_engine, x.type_id, ), - components: x.initial_type_id.get_json_type_components( + components: x.initial_type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, x.type_id, ), - type_parameters: x.initial_type_id.get_json_type_parameters( + type_parameters: x.initial_type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -533,7 +523,7 @@ impl TypeId { .map(|x| program_abi::TypeApplication { name: "__tuple_element".to_string(), type_id: x.initial_type_id.index(), - type_arguments: x.initial_type_id.get_json_type_arguments( + type_arguments: x.initial_type_id.get_abi_type_arguments( ctx, type_engine, decl_engine, @@ -561,20 +551,20 @@ impl TypeId { ) .map(|(v, p)| program_abi::TypeDeclaration { type_id: v.initial_type_id.index(), - type_field: v.initial_type_id.get_json_type_str( + type_field: v.initial_type_id.get_abi_type_str( ctx, type_engine, decl_engine, p.type_id, ), - components: v.initial_type_id.get_json_type_components( + components: v.initial_type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, p.type_id, ), - type_parameters: v.initial_type_id.get_json_type_parameters( + type_parameters: v.initial_type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -585,7 +575,7 @@ impl TypeId { .collect::>(); types.extend(type_args); - resolved_type_id.get_json_type_components( + resolved_type_id.get_abi_type_components( ctx, type_engine, decl_engine, @@ -598,7 +588,7 @@ impl TypeId { } TypeInfo::Alias { .. } => { if let TypeInfo::Alias { ty, .. } = type_engine.get(resolved_type_id) { - ty.initial_type_id.get_json_type_components( + ty.initial_type_id.get_abi_type_components( ctx, type_engine, decl_engine, @@ -618,9 +608,9 @@ impl TypeId { /// actually resolves to. These arguments are essentially of type of /// `program_abi::TypeApplication`. The method below also updates the provided list of /// `program_abi::TypeDeclaration`s to add the newly discovered types. - pub(self) fn get_json_type_arguments( + pub(self) fn get_abi_type_arguments( &self, - ctx: &mut JsonAbiContext, + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, types: &mut Vec, @@ -633,25 +623,25 @@ impl TypeId { .. } => (!type_arguments.is_empty()).then_some({ let resolved_params = resolved_params.unwrap_or_default(); - let json_type_arguments = type_arguments + let abi_type_arguments = type_arguments .iter() .zip(resolved_params.iter()) .map(|(v, p)| program_abi::TypeDeclaration { type_id: v.initial_type_id.index(), - type_field: v.initial_type_id.get_json_type_str( + type_field: v.initial_type_id.get_abi_type_str( ctx, type_engine, decl_engine, p.type_id, ), - components: v.initial_type_id.get_json_type_components( + components: v.initial_type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, p.type_id, ), - type_parameters: v.initial_type_id.get_json_type_parameters( + type_parameters: v.initial_type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -660,14 +650,14 @@ impl TypeId { ), }) .collect::>(); - types.extend(json_type_arguments); + types.extend(abi_type_arguments); type_arguments .iter() .map(|arg| program_abi::TypeApplication { name: "".to_string(), type_id: arg.initial_type_id.index(), - type_arguments: arg.initial_type_id.get_json_type_arguments( + type_arguments: arg.initial_type_id.get_abi_type_arguments( ctx, type_engine, decl_engine, @@ -680,25 +670,25 @@ impl TypeId { TypeInfo::Enum(decl_ref) => { let decl = decl_engine.get_enum(&decl_ref); // Here, type_id for each type parameter should contain resolved types - let json_type_arguments = decl + let abi_type_arguments = decl .type_parameters .iter() .map(|v| program_abi::TypeDeclaration { type_id: v.type_id.index(), - type_field: v.type_id.get_json_type_str( + type_field: v.type_id.get_abi_type_str( ctx, type_engine, decl_engine, v.type_id, ), - components: v.type_id.get_json_type_components( + components: v.type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, v.type_id, ), - type_parameters: v.type_id.get_json_type_parameters( + type_parameters: v.type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -707,7 +697,7 @@ impl TypeId { ), }) .collect::>(); - types.extend(json_type_arguments); + types.extend(abi_type_arguments); Some( decl.type_parameters @@ -715,7 +705,7 @@ impl TypeId { .map(|arg| program_abi::TypeApplication { name: "".to_string(), type_id: arg.type_id.index(), - type_arguments: arg.type_id.get_json_type_arguments( + type_arguments: arg.type_id.get_abi_type_arguments( ctx, type_engine, decl_engine, @@ -730,25 +720,25 @@ impl TypeId { TypeInfo::Struct(decl_ref) => { let decl = decl_engine.get_struct(&decl_ref); // Here, type_id for each type parameter should contain resolved types - let json_type_arguments = decl + let abi_type_arguments = decl .type_parameters .iter() .map(|v| program_abi::TypeDeclaration { type_id: v.type_id.index(), - type_field: v.type_id.get_json_type_str( + type_field: v.type_id.get_abi_type_str( ctx, type_engine, decl_engine, v.type_id, ), - components: v.type_id.get_json_type_components( + components: v.type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, v.type_id, ), - type_parameters: v.type_id.get_json_type_parameters( + type_parameters: v.type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -757,7 +747,7 @@ impl TypeId { ), }) .collect::>(); - types.extend(json_type_arguments); + types.extend(abi_type_arguments); Some( decl.type_parameters @@ -765,7 +755,7 @@ impl TypeId { .map(|arg| program_abi::TypeApplication { name: "".to_string(), type_id: arg.type_id.index(), - type_arguments: arg.type_id.get_json_type_arguments( + type_arguments: arg.type_id.get_abi_type_arguments( ctx, type_engine, decl_engine, @@ -782,9 +772,9 @@ impl TypeId { } impl TypeInfo { - pub fn json_abi_str( + pub fn abi_str( &self, - ctx: &mut JsonAbiContext, + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, ) -> String { @@ -800,6 +790,7 @@ impl TypeInfo { IntegerBits::Sixteen => "u16", IntegerBits::ThirtyTwo => "u32", IntegerBits::SixtyFour => "u64", + IntegerBits::V256 => "u256", } .into(), Boolean => "bool".into(), @@ -807,7 +798,7 @@ impl TypeInfo { Tuple(fields) => { let field_strs = fields .iter() - .map(|field| field.json_abi_str(ctx, type_engine, decl_engine)) + .map(|field| field.abi_str(ctx, type_engine, decl_engine)) .collect::>(); format!("({})", field_strs.join(", ")) } @@ -830,7 +821,7 @@ impl TypeInfo { Array(elem_ty, length) => { format!( "[{}; {}]", - elem_ty.json_abi_str(ctx, type_engine, decl_engine), + elem_ty.abi_str(ctx, type_engine, decl_engine), length.val() ) } @@ -838,20 +829,20 @@ impl TypeInfo { RawUntypedPtr => "raw untyped ptr".into(), RawUntypedSlice => "raw untyped slice".into(), Ptr(ty) => { - format!("__ptr {}", ty.json_abi_str(ctx, type_engine, decl_engine)) + format!("__ptr {}", ty.abi_str(ctx, type_engine, decl_engine)) } Slice(ty) => { - format!("__slice {}", ty.json_abi_str(ctx, type_engine, decl_engine)) + format!("__slice {}", ty.abi_str(ctx, type_engine, decl_engine)) } - Alias { ty, .. } => ty.json_abi_str(ctx, type_engine, decl_engine), + Alias { ty, .. } => ty.abi_str(ctx, type_engine, decl_engine), } } } /// `call_path_display` returns the provided `call_path` without the first prefix in case it is equal to the program name. /// If the program name is `my_program` and the `call_path` is `my_program::MyStruct` then this function returns only `MyStruct`. -fn call_path_display(ctx: &mut JsonAbiContext, call_path: &CallPath) -> String { - if !ctx.json_abi_with_callpaths { +fn call_path_display(ctx: &mut AbiContext, call_path: &CallPath) -> String { + if !ctx.abi_with_callpaths { return call_path.suffix.as_str().to_string(); } let mut buf = String::new(); @@ -875,9 +866,9 @@ fn call_path_display(ctx: &mut JsonAbiContext, call_path: &CallPath) -> String { } impl TyFunctionDecl { - pub(self) fn generate_json_abi_function( + pub(self) fn generate_abi_function( &self, - ctx: &mut JsonAbiContext, + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, types: &mut Vec, @@ -888,20 +879,20 @@ impl TyFunctionDecl { .iter() .map(|x| program_abi::TypeDeclaration { type_id: x.type_argument.initial_type_id.index(), - type_field: x.type_argument.initial_type_id.get_json_type_str( + type_field: x.type_argument.initial_type_id.get_abi_type_str( ctx, type_engine, decl_engine, x.type_argument.type_id, ), - components: x.type_argument.initial_type_id.get_json_type_components( + components: x.type_argument.initial_type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, x.type_argument.type_id, ), - type_parameters: x.type_argument.type_id.get_json_type_parameters( + type_parameters: x.type_argument.type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -914,20 +905,20 @@ impl TyFunctionDecl { // The single `program_abi::TypeDeclaration` needed for the output let output_type = program_abi::TypeDeclaration { type_id: self.return_type.initial_type_id.index(), - type_field: self.return_type.initial_type_id.get_json_type_str( + type_field: self.return_type.initial_type_id.get_abi_type_str( ctx, type_engine, decl_engine, self.return_type.type_id, ), - components: self.return_type.type_id.get_json_type_components( + components: self.return_type.type_id.get_abi_type_components( ctx, type_engine, decl_engine, types, self.return_type.type_id, ), - type_parameters: self.return_type.type_id.get_json_type_parameters( + type_parameters: self.return_type.type_id.get_abi_type_parameters( ctx, type_engine, decl_engine, @@ -949,7 +940,7 @@ impl TyFunctionDecl { .map(|x| program_abi::TypeApplication { name: x.name.to_string(), type_id: x.type_argument.initial_type_id.index(), - type_arguments: x.type_argument.initial_type_id.get_json_type_arguments( + type_arguments: x.type_argument.initial_type_id.get_abi_type_arguments( ctx, type_engine, decl_engine, @@ -961,7 +952,7 @@ impl TyFunctionDecl { output: program_abi::TypeApplication { name: "".to_string(), type_id: self.return_type.initial_type_id.index(), - type_arguments: self.return_type.initial_type_id.get_json_type_arguments( + type_arguments: self.return_type.initial_type_id.get_abi_type_arguments( ctx, type_engine, decl_engine, @@ -969,14 +960,12 @@ impl TyFunctionDecl { self.return_type.type_id, ), }, - attributes: generate_json_abi_attributes_map(&self.attributes), + attributes: generate_attributes_map(&self.attributes), } } } -fn generate_json_abi_attributes_map( - attr_map: &AttributesMap, -) -> Option> { +fn generate_attributes_map(attr_map: &AttributesMap) -> Option> { if attr_map.is_empty() { None } else { @@ -997,22 +986,22 @@ fn generate_json_abi_attributes_map( impl TypeParameter { /// Returns the initial type ID of a TypeParameter. Also updates the provided list of types to /// append the current TypeParameter as a `program_abi::TypeDeclaration`. - pub(self) fn get_json_type_parameter( + pub(self) fn get_abi_type_parameter( &self, - ctx: &mut JsonAbiContext, + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, types: &mut Vec, ) -> usize { let type_parameter = program_abi::TypeDeclaration { type_id: self.initial_type_id.index(), - type_field: self.initial_type_id.get_json_type_str( + type_field: self.initial_type_id.get_abi_type_str( ctx, type_engine, decl_engine, self.type_id, ), - components: self.initial_type_id.get_json_type_components( + components: self.initial_type_id.get_abi_type_components( ctx, type_engine, decl_engine, @@ -1027,14 +1016,14 @@ impl TypeParameter { } impl TypeArgument { - pub(self) fn json_abi_str( + pub(self) fn abi_str( &self, - ctx: &mut JsonAbiContext, + ctx: &mut AbiContext, type_engine: &TypeEngine, decl_engine: &DeclEngine, ) -> String { type_engine .get(self.type_id) - .json_abi_str(ctx, type_engine, decl_engine) + .abi_str(ctx, type_engine, decl_engine) } } diff --git a/sway-core/src/abi_generation/mod.rs b/sway-core/src/abi_generation/mod.rs index b10a318da36..33b6c8c3885 100644 --- a/sway-core/src/abi_generation/mod.rs +++ b/sway-core/src/abi_generation/mod.rs @@ -1,2 +1,2 @@ -pub mod evm_json_abi; -pub mod fuel_json_abi; +pub mod evm_abi; +pub mod fuel_abi; diff --git a/sway-core/src/asm_generation/fuel/data_section.rs b/sway-core/src/asm_generation/fuel/data_section.rs index ff079dfa33f..9975964c3ea 100644 --- a/sway-core/src/asm_generation/fuel/data_section.rs +++ b/sway-core/src/asm_generation/fuel/data_section.rs @@ -99,8 +99,16 @@ impl Entry { match &constant.value { ConstantValue::Undef | ConstantValue::Unit => Entry::new_word(0, size, name), ConstantValue::Bool(b) => Entry::new_word(u64::from(*b), size, name), - ConstantValue::Uint(u) => Entry::new_word(*u, size, name), - + ConstantValue::Uint(u) => match constant.ty.get_uint_width(context) { + Some(width) if width <= 64 => Entry::new_word(*u, size, name), + Some(256) => { + let mut bytes = vec![0u8; 24]; + bytes.extend(u.to_be_bytes()); + assert!(bytes.len() == size.unwrap()); + Entry::new_byte_array(bytes, size, name) + } + _ => todo!(), + }, ConstantValue::B256(bs) => Entry::new_byte_array(bs.to_vec(), size, name), ConstantValue::String(bs) => Entry::new_byte_array(bs.clone(), size, name), diff --git a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs index b1c3a4ae0ac..8353f228512 100644 --- a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs +++ b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs @@ -10,7 +10,10 @@ use crate::{ }, ProgramKind, }, - asm_lang::{virtual_register::*, Label, Op, VirtualImmediate12, VirtualImmediate18, VirtualOp}, + asm_lang::{ + virtual_register::*, ImmediateOp, Label, Op, VirtualImmediate12, VirtualImmediate18, + VirtualOp, + }, decl_engine::DeclRefFunction, error::*, metadata::MetadataManager, @@ -142,12 +145,15 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { func_is_entry: bool, ) -> CompileResult<()> { let Some(instruction) = instr_val.get_instruction(self.context) else { - return err(vec![], vec![CompileError::Internal( - "Value not an instruction.", - self.md_mgr - .val_to_span(self.context, *instr_val) - .unwrap_or_else(Span::dummy), - )]); + return err( + vec![], + vec![CompileError::Internal( + "Value not an instruction.", + self.md_mgr + .val_to_span(self.context, *instr_val) + .unwrap_or_else(Span::dummy), + )], + ); }; // The only instruction whose compilation returns a CompileResult itself is AsmBlock, which @@ -482,21 +488,53 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { let val1_reg = self.value_to_register(arg1)?; let val2_reg = self.value_to_register(arg2)?; let res_reg = self.reg_seqr.next(); - let opcode = match op { - BinaryOpKind::Add => Either::Left(VirtualOp::ADD(res_reg.clone(), val1_reg, val2_reg)), - BinaryOpKind::Sub => Either::Left(VirtualOp::SUB(res_reg.clone(), val1_reg, val2_reg)), - BinaryOpKind::Mul => Either::Left(VirtualOp::MUL(res_reg.clone(), val1_reg, val2_reg)), - BinaryOpKind::Div => Either::Left(VirtualOp::DIV(res_reg.clone(), val1_reg, val2_reg)), - BinaryOpKind::And => Either::Left(VirtualOp::AND(res_reg.clone(), val1_reg, val2_reg)), - BinaryOpKind::Or => Either::Left(VirtualOp::OR(res_reg.clone(), val1_reg, val2_reg)), - BinaryOpKind::Xor => Either::Left(VirtualOp::XOR(res_reg.clone(), val1_reg, val2_reg)), - BinaryOpKind::Mod => Either::Left(VirtualOp::MOD(res_reg.clone(), val1_reg, val2_reg)), - BinaryOpKind::Rsh => Either::Left(VirtualOp::SRL(res_reg.clone(), val1_reg, val2_reg)), - BinaryOpKind::Lsh => Either::Left(VirtualOp::SLL(res_reg.clone(), val1_reg, val2_reg)), + + // Check op is on 256 bits and use the special opcodes + let arg1_width = arg1 + .get_type(self.context) + .and_then(|x| x.get_uint_width(self.context)); + let arg2_width = arg2 + .get_type(self.context) + .and_then(|x| x.get_uint_width(self.context)); + let (opcode, comment) = match (arg1_width, arg2_width) { + (Some(256), Some(256)) => match op { + BinaryOpKind::Add => ( + VirtualOp::WQOP( + res_reg.clone(), + val1_reg, + val2_reg, + ImmediateOp { + op: crate::asm_lang::ImmediateOpOperation::Add, + indirect: false, + }, + ), + Some("add"), + ), + _ => todo!(), + }, + _ => { + // Use the standard opcodes + ( + match op { + BinaryOpKind::Add => VirtualOp::ADD(res_reg.clone(), val1_reg, val2_reg), + BinaryOpKind::Sub => VirtualOp::SUB(res_reg.clone(), val1_reg, val2_reg), + BinaryOpKind::Mul => VirtualOp::MUL(res_reg.clone(), val1_reg, val2_reg), + BinaryOpKind::Div => VirtualOp::DIV(res_reg.clone(), val1_reg, val2_reg), + BinaryOpKind::And => VirtualOp::AND(res_reg.clone(), val1_reg, val2_reg), + BinaryOpKind::Or => VirtualOp::OR(res_reg.clone(), val1_reg, val2_reg), + BinaryOpKind::Xor => VirtualOp::XOR(res_reg.clone(), val1_reg, val2_reg), + BinaryOpKind::Mod => VirtualOp::MOD(res_reg.clone(), val1_reg, val2_reg), + BinaryOpKind::Rsh => VirtualOp::SRL(res_reg.clone(), val1_reg, val2_reg), + BinaryOpKind::Lsh => VirtualOp::SLL(res_reg.clone(), val1_reg, val2_reg), + }, + None, + ) + } }; + self.cur_bytecode.push(Op { - opcode, - comment: String::new(), + opcode: Either::Left(opcode), + comment: comment.map(Into::into).unwrap_or_default(), owning_span: self.md_mgr.val_to_span(self.context, *instr_val), }); @@ -1438,17 +1476,34 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { config_name: Option, span: Option, ) -> (VirtualRegister, Option) { + // Use cheaper $zero or $one registers if possible. match &constant.value { - // Use cheaper $zero or $one registers if possible. - ConstantValue::Unit | ConstantValue::Bool(false) | ConstantValue::Uint(0) - if config_name.is_none() => + ConstantValue::Uint(0) + if config_name.is_none() + && constant + .ty + .get_uint_width(self.context) + .map(|x| x <= 64) + .unwrap_or(false) => { (VirtualRegister::Constant(ConstantRegister::Zero), None) } - ConstantValue::Bool(true) | ConstantValue::Uint(1) if config_name.is_none() => { + ConstantValue::Unit | ConstantValue::Bool(false) if config_name.is_none() => { + (VirtualRegister::Constant(ConstantRegister::Zero), None) + } + + ConstantValue::Uint(1) + if config_name.is_none() + && constant + .ty + .get_uint_width(self.context) + .map(|x| x <= 64) + .unwrap_or(false) => + { (VirtualRegister::Constant(ConstantRegister::One), None) } + ConstantValue::Bool(true) => (VirtualRegister::Constant(ConstantRegister::One), None), _otherwise => { // Get the constant into the namespace. diff --git a/sway-core/src/asm_generation/fuel/functions.rs b/sway-core/src/asm_generation/fuel/functions.rs index 14f63e5f741..7c7d68c665f 100644 --- a/sway-core/src/asm_generation/fuel/functions.rs +++ b/sway-core/src/asm_generation/fuel/functions.rs @@ -645,6 +645,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { let ptr_ty = ptr.get_inner_type(self.context); let var_size = match ptr_ty.get_content(self.context) { + TypeContent::Uint(256) => 4, TypeContent::Unit | TypeContent::Bool | TypeContent::Uint(_) diff --git a/sway-core/src/asm_generation/fuel/register_allocator.rs b/sway-core/src/asm_generation/fuel/register_allocator.rs index 8677b6e64d2..6a00c00170b 100644 --- a/sway-core/src/asm_generation/fuel/register_allocator.rs +++ b/sway-core/src/asm_generation/fuel/register_allocator.rs @@ -825,9 +825,12 @@ fn spill(ops: &[Op], spills: &FxHashSet) -> Vec { let cfe_idx = cfe_idx_opt.expect("Function does not have CFEI instruction for locals"); - let Either::Left(VirtualOp::CFEI(VirtualImmediate24 { value: locals_size_bytes })) = ops[cfe_idx].opcode else { - panic!("Unexpected opcode"); - }; + let Either::Left(VirtualOp::CFEI(VirtualImmediate24 { + value: locals_size_bytes, + })) = ops[cfe_idx].opcode + else { + panic!("Unexpected opcode"); + }; // pad up the locals size in bytes to a word. let locals_size_bytes = size_bytes_round_up_to_word_alignment!(locals_size_bytes); diff --git a/sway-core/src/asm_lang/allocated_ops.rs b/sway-core/src/asm_lang/allocated_ops.rs index b2caec4ba1a..773755565de 100644 --- a/sway-core/src/asm_lang/allocated_ops.rs +++ b/sway-core/src/asm_lang/allocated_ops.rs @@ -91,6 +91,12 @@ pub(crate) enum AllocatedOpcode { SUBI(AllocatedRegister, AllocatedRegister, VirtualImmediate12), XOR(AllocatedRegister, AllocatedRegister, AllocatedRegister), XORI(AllocatedRegister, AllocatedRegister, VirtualImmediate12), + WQOP( + AllocatedRegister, + AllocatedRegister, + AllocatedRegister, + VirtualImmediate06, + ), /* Conrol Flow Instructions */ JMP(AllocatedRegister), @@ -243,6 +249,7 @@ impl AllocatedOpcode { SUBI(r1, _r2, _i) => vec![r1], XOR(r1, _r2, _r3) => vec![r1], XORI(r1, _r2, _i) => vec![r1], + WQOP(r1, _, _, _) => vec![r1], /* Control Flow Instructions */ JMP(_r1) => vec![], @@ -356,6 +363,7 @@ impl fmt::Display for AllocatedOpcode { SUBI(a, b, c) => write!(fmtr, "subi {a} {b} {c}"), XOR(a, b, c) => write!(fmtr, "xor {a} {b} {c}"), XORI(a, b, c) => write!(fmtr, "xori {a} {b} {c}"), + WQOP(a, b, c, d) => write!(fmtr, "wqop {a} {b} {c} {d}"), /* Control Flow Instructions */ JMP(a) => write!(fmtr, "jmp {a}"), @@ -500,6 +508,9 @@ impl AllocatedOp { SUBI(a, b, c) => op::SUBI::new(a.to_reg_id(), b.to_reg_id(), c.value.into()).into(), XOR(a, b, c) => op::XOR::new(a.to_reg_id(), b.to_reg_id(), c.to_reg_id()).into(), XORI(a, b, c) => op::XORI::new(a.to_reg_id(), b.to_reg_id(), c.value.into()).into(), + WQOP(a, b, c, d) => { + op::WQOP::new(a.to_reg_id(), b.to_reg_id(), c.to_reg_id(), d.value.into()).into() + } /* Control Flow Instructions */ JMP(a) => op::JMP::new(a.to_reg_id()).into(), diff --git a/sway-core/src/asm_lang/mod.rs b/sway-core/src/asm_lang/mod.rs index 9f544cff6ac..aadf934ba81 100644 --- a/sway-core/src/asm_lang/mod.rs +++ b/sway-core/src/asm_lang/mod.rs @@ -1440,6 +1440,7 @@ impl fmt::Display for VirtualOp { SUBI(a, b, c) => write!(fmtr, "subi {a} {b} {c}"), XOR(a, b, c) => write!(fmtr, "xor {a} {b} {c}"), XORI(a, b, c) => write!(fmtr, "xori {a} {b} {c}"), + WQOP(a, b, c, d) => write!(fmtr, "wqop {a} {b} {c} {d}"), /* Control Flow Instructions */ JMP(a) => write!(fmtr, "jmp {a}"), diff --git a/sway-core/src/asm_lang/virtual_ops.rs b/sway-core/src/asm_lang/virtual_ops.rs index dfb352b7b45..dcd728b2a08 100644 --- a/sway-core/src/asm_lang/virtual_ops.rs +++ b/sway-core/src/asm_lang/virtual_ops.rs @@ -11,11 +11,50 @@ use super::{ Op, }; use crate::asm_generation::fuel::{data_section::DataId, register_allocator::RegisterPool}; - use std::collections::{BTreeSet, HashMap}; - use std::fmt; +#[derive(Clone, Copy, Debug)] +#[repr(u16)] +pub enum ImmediateOpOperation { + // Add + Add = 0, + // Subtract + Sub = 1, + // Invert bits (discards rhs) + Not = 2, + // Bitwise or + Or = 3, + // Bitwise exclusive or + Xor = 4, + // Bitwise and + And = 5, + // Shift left (logical) + Shl = 6, + // Shift right (logical) + Shr = 7, +} + +#[derive(Clone, Debug)] +pub(crate) struct ImmediateOp { + pub op: ImmediateOpOperation, + pub indirect: bool, +} + +impl fmt::Display for ImmediateOp { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "i{}", self.immediate_value()) + } +} + +impl ImmediateOp { + pub fn immediate_value(&self) -> VirtualImmediate06 { + let a = self.op as u8; + let b = if self.indirect { 1u8 } else { 0u8 } << 5; + VirtualImmediate06 { value: a & b } + } +} + /// This enum is unfortunately a redundancy of the [fuel_asm::Opcode] enum. This variant, however, /// allows me to use the compiler's internal [VirtualRegister] types and maintain type safety /// between virtual ops and the real opcodes. A bit of copy/paste seemed worth it for that safety, @@ -55,6 +94,14 @@ pub(crate) enum VirtualOp { SUBI(VirtualRegister, VirtualRegister, VirtualImmediate12), XOR(VirtualRegister, VirtualRegister, VirtualRegister), XORI(VirtualRegister, VirtualRegister, VirtualImmediate12), + /// WQOP: Misc 256-bit integer operations + /// wqop $rA, $rB, $rC, imm + WQOP( + VirtualRegister, + VirtualRegister, + VirtualRegister, + ImmediateOp, + ), /* Control Flow Instructions */ JMP(VirtualRegister), @@ -207,6 +254,7 @@ impl VirtualOp { SUBI(r1, r2, _i) => vec![r1, r2], XOR(r1, r2, r3) => vec![r1, r2, r3], XORI(r1, r2, _i) => vec![r1, r2], + WQOP(r1, r2, r3, _) => vec![r1, r2, r3], /* Control Flow Instructions */ JMP(r1) => vec![r1], @@ -316,6 +364,7 @@ impl VirtualOp { SUBI(_r1, r2, _i) => vec![r2], XOR(_r1, r2, r3) => vec![r2, r3], XORI(_r1, r2, _i) => vec![r2], + WQOP(_, r2, r3, _) => vec![r2, r3], /* Control Flow Instructions */ JMP(r1) => vec![r1], @@ -425,6 +474,7 @@ impl VirtualOp { SUBI(r1, _r2, _i) => vec![r1], XOR(r1, _r2, _r3) => vec![r1], XORI(r1, _r2, _i) => vec![r1], + WQOP(r1, _, _, _) => vec![r1], /* Control Flow Instructions */ JMP(_r1) => vec![], @@ -670,6 +720,12 @@ impl VirtualOp { update_reg(reg_to_reg_map, r2), i.clone(), ), + WQOP(r1, r2, r3, i) => Self::WQOP( + update_reg(reg_to_reg_map, r1), + update_reg(reg_to_reg_map, r2), + update_reg(reg_to_reg_map, r3), + i.clone(), + ), /* Control Flow Instructions */ JMP(r1) => Self::JMP(update_reg(reg_to_reg_map, r1)), @@ -1088,6 +1144,12 @@ impl VirtualOp { map_reg(&mapping, reg2), imm.clone(), ), + WQOP(reg1, reg2, reg3, imm) => AllocatedOpcode::WQOP( + map_reg(&mapping, reg1), + map_reg(&mapping, reg2), + map_reg(&mapping, reg3), + imm.immediate_value(), + ), /* Control Flow Instructions */ JMP(reg1) => AllocatedOpcode::JMP(map_reg(&mapping, reg1)), diff --git a/sway-core/src/ir_generation.rs b/sway-core/src/ir_generation.rs index 8c0dc9f835d..0ba40406965 100644 --- a/sway-core/src/ir_generation.rs +++ b/sway-core/src/ir_generation.rs @@ -98,7 +98,7 @@ pub fn compile_program<'eng>( ), }?; - //println!("{ctx}"); + // println!("{}", ctx.to_string()); ctx.verify().map_err(|ir_error: sway_ir::IrError| { CompileError::InternalOwned(ir_error.to_string(), Span::dummy()) diff --git a/sway-core/src/ir_generation/const_eval.rs b/sway-core/src/ir_generation/const_eval.rs index 66e908a02ad..dde6b13da4b 100644 --- a/sway-core/src/ir_generation/const_eval.rs +++ b/sway-core/src/ir_generation/const_eval.rs @@ -739,7 +739,8 @@ fn const_eval_intrinsic( assert!( args.len() == 2 && ty.is_uint(lookup.context) && ty.eq(lookup.context, &args[1].ty) ); - let (ConstantValue::Uint(arg1), ConstantValue::Uint(ref arg2)) = (&args[0].value, &args[1].value) + let (ConstantValue::Uint(arg1), ConstantValue::Uint(ref arg2)) = + (&args[0].value, &args[1].value) else { panic!("Type checker allowed incorrect args to binary op"); }; @@ -768,14 +769,15 @@ fn const_eval_intrinsic( } } sway_ast::Intrinsic::Lsh | sway_ast::Intrinsic::Rsh => { - let ty = args[0].ty; + let ty: Type = args[0].ty; assert!( args.len() == 2 && ty.is_uint(lookup.context) && args[1].ty.is_uint64(lookup.context) ); - let (ConstantValue::Uint(arg1), ConstantValue::Uint(ref arg2)) = (&args[0].value, &args[1].value) + let (ConstantValue::Uint(arg1), ConstantValue::Uint(ref arg2)) = + (&args[0].value, &args[1].value) else { panic!("Type checker allowed incorrect args to binary op"); }; @@ -854,20 +856,22 @@ fn const_eval_intrinsic( })) } sway_ast::Intrinsic::Gt => { - let (ConstantValue::Uint(val1), ConstantValue::Uint(val2)) = (&args[0].value, &args[1].value) - else { - unreachable!("Type checker allowed non integer value for GreaterThan") - }; + let (ConstantValue::Uint(val1), ConstantValue::Uint(val2)) = + (&args[0].value, &args[1].value) + else { + unreachable!("Type checker allowed non integer value for GreaterThan") + }; Ok(Some(Constant { ty: Type::get_bool(lookup.context), value: ConstantValue::Bool(val1 > val2), })) } sway_ast::Intrinsic::Lt => { - let (ConstantValue::Uint(val1), ConstantValue::Uint(val2)) = (&args[0].value, &args[1].value) - else { - unreachable!("Type checker allowed non integer value for LessThan") - }; + let (ConstantValue::Uint(val1), ConstantValue::Uint(val2)) = + (&args[0].value, &args[1].value) + else { + unreachable!("Type checker allowed non integer value for LessThan") + }; Ok(Some(Constant { ty: Type::get_bool(lookup.context), value: ConstantValue::Bool(val1 < val2), diff --git a/sway-core/src/ir_generation/convert.rs b/sway-core/src/ir_generation/convert.rs index 0f26a80a472..883b96bdf62 100644 --- a/sway-core/src/ir_generation/convert.rs +++ b/sway-core/src/ir_generation/convert.rs @@ -9,7 +9,7 @@ use super::types::{create_tagged_union_type, create_tuple_aggregate}; use sway_error::error::CompileError; use sway_ir::{Constant, Context, Type, Value}; -use sway_types::span::Span; +use sway_types::{integer_bits::IntegerBits, span::Span}; pub(super) fn convert_literal_to_value(context: &mut Context, ast_literal: &Literal) -> Value { match ast_literal { @@ -25,6 +25,10 @@ pub(super) fn convert_literal_to_value(context: &mut Context, ast_literal: &Lite Literal::U16(n) => Constant::get_uint(context, 64, *n as u64), Literal::U32(n) => Constant::get_uint(context, 64, *n as u64), Literal::U64(n) => Constant::get_uint(context, 64, *n), + Literal::U256(n) => { + let n: u64 = n.try_into().unwrap(); // TODO u256 limited to 64 bits + Constant::get_uint(context, 256, n) + } Literal::Numeric(n) => Constant::get_uint(context, 64, *n), Literal::String(s) => Constant::get_string(context, s.as_str().as_bytes().to_vec()), Literal::Boolean(b) => Constant::get_bool(context, *b), @@ -42,6 +46,7 @@ pub(super) fn convert_literal_to_constant( Literal::U16(n) => Constant::new_uint(context, 64, *n as u64), Literal::U32(n) => Constant::new_uint(context, 64, *n as u64), Literal::U64(n) => Constant::new_uint(context, 64, *n), + Literal::U256(_) => todo!(), Literal::Numeric(n) => Constant::new_uint(context, 64, *n), Literal::String(s) => Constant::new_string(context, s.as_str().as_bytes().to_vec()), Literal::Boolean(b) => Constant::new_bool(context, *b), @@ -99,6 +104,7 @@ fn convert_resolved_type( Ok(match ast_type { // All integers are `u64`, see comment in convert_literal_to_value() above. + TypeInfo::UnsignedInteger(IntegerBits::V256) => Type::get_uint(context, 256), TypeInfo::UnsignedInteger(_) => Type::get_uint64(context), TypeInfo::Numeric => Type::get_uint64(context), TypeInfo::Boolean => Type::get_bool(context), diff --git a/sway-core/src/language/literal.rs b/sway-core/src/language/literal.rs index 83714384e14..5027258ccc7 100644 --- a/sway-core/src/language/literal.rs +++ b/sway-core/src/language/literal.rs @@ -1,5 +1,6 @@ use crate::{type_system::*, Engines}; +use num_bigint::BigUint; use sway_error::error::CompileError; use sway_types::{integer_bits::IntegerBits, span}; @@ -15,6 +16,7 @@ pub enum Literal { U16(u16), U32(u32), U64(u64), + U256(BigUint), String(span::Span), Numeric(u64), Boolean(bool), @@ -41,6 +43,7 @@ impl Hash for Literal { state.write_u8(4); x.hash(state); } + U256(_) => todo!(), Numeric(x) => { state.write_u8(5); x.hash(state); @@ -68,6 +71,7 @@ impl PartialEq for Literal { (Self::U16(l0), Self::U16(r0)) => l0 == r0, (Self::U32(l0), Self::U32(r0)) => l0 == r0, (Self::U64(l0), Self::U64(r0)) => l0 == r0, + (Self::U256(l0), Self::U256(r0)) => l0 == r0, (Self::String(l0), Self::String(r0)) => *l0.as_str() == *r0.as_str(), (Self::Numeric(l0), Self::Numeric(r0)) => l0 == r0, (Self::Boolean(l0), Self::Boolean(r0)) => l0 == r0, @@ -84,6 +88,7 @@ impl fmt::Display for Literal { Literal::U16(content) => content.to_string(), Literal::U32(content) => content.to_string(), Literal::U64(content) => content.to_string(), + Literal::U256(_) => todo!(), Literal::Numeric(content) => content.to_string(), Literal::String(content) => content.as_str().to_string(), Literal::Boolean(content) => content.to_string(), @@ -132,6 +137,7 @@ impl Literal { Literal::U16(_) => TypeInfo::UnsignedInteger(IntegerBits::Sixteen), Literal::U32(_) => TypeInfo::UnsignedInteger(IntegerBits::ThirtyTwo), Literal::U64(_) => TypeInfo::UnsignedInteger(IntegerBits::SixtyFour), + Literal::U256(_) => todo!(), Literal::Boolean(_) => TypeInfo::Boolean, Literal::B256(_) => TypeInfo::B256, } diff --git a/sway-core/src/lib.rs b/sway-core/src/lib.rs index 6a749ddda73..638d5ac9789 100644 --- a/sway-core/src/lib.rs +++ b/sway-core/src/lib.rs @@ -178,7 +178,7 @@ fn parse_in_memory( engines, module.value.clone(), )?; - let module_kind_span = module.value.kind.span().clone(); + let module_kind_span = module.value.kind.span(); let submodules = Default::default(); let attributes = module_attrs_to_map(handler, &module.attribute_list)?; let root = parsed::ParseModule { @@ -303,7 +303,7 @@ fn parse_module_tree( engines, module.value.clone(), )?; - let module_kind_span = module.value.kind.span().clone(); + let module_kind_span = module.value.kind.span(); let attributes = module_attrs_to_map(handler, &module.attribute_list)?; let lexed = lexed::LexedModule { 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 f36ce58c6dd..e2983426a4a 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 @@ -194,6 +194,7 @@ impl Pattern { Literal::U16(x) => Pattern::U16(Range::from_single(x)), Literal::U32(x) => Pattern::U32(Range::from_single(x)), Literal::U64(x) => Pattern::U64(Range::from_single(x)), + Literal::U256(_) => todo!(), Literal::B256(x) => Pattern::B256(x), Literal::Boolean(b) => Pattern::Boolean(b), Literal::Numeric(x) => Pattern::Numeric(Range::from_single(x)), diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs index 2b5d7ff7262..50f3832f2f8 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs @@ -396,6 +396,7 @@ impl ty::TyExpression { Literal::U16(_) => TypeInfo::UnsignedInteger(IntegerBits::Sixteen), Literal::U32(_) => TypeInfo::UnsignedInteger(IntegerBits::ThirtyTwo), Literal::U64(_) => TypeInfo::UnsignedInteger(IntegerBits::SixtyFour), + Literal::U256(_) => TypeInfo::UnsignedInteger(IntegerBits::V256), Literal::Boolean(_) => TypeInfo::Boolean, Literal::B256(_) => TypeInfo::B256, }; @@ -2014,6 +2015,7 @@ impl ty::TyExpression { }), new_type, ), + IntegerBits::V256 => todo!(), }, TypeInfo::Numeric => ( num.to_string().parse().map(Literal::Numeric).map_err(|e| { diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs index 28a629f706a..5aaf26c302b 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs @@ -34,12 +34,13 @@ pub(crate) fn type_check_method_application( .by_ref() .with_help_text("") .with_type_annotation(type_engine.insert(engines, TypeInfo::Unknown)); - args_buf.push_back(check!( + let r = check!( ty::TyExpression::type_check(ctx, arg.clone()), ty::TyExpression::error(span.clone(), engines), warnings, errors - )); + ); + args_buf.push_back(r); } // resolve the method name to a typed function declaration and type_check diff --git a/sway-core/src/semantic_analysis/node_dependencies.rs b/sway-core/src/semantic_analysis/node_dependencies.rs index a025a2a5f20..e5618e53fce 100644 --- a/sway-core/src/semantic_analysis/node_dependencies.rs +++ b/sway-core/src/semantic_analysis/node_dependencies.rs @@ -849,6 +849,7 @@ fn type_info_name(type_info: &TypeInfo) -> String { IntegerBits::Sixteen => "uint16", IntegerBits::ThirtyTwo => "uint32", IntegerBits::SixtyFour => "uint64", + IntegerBits::V256 => "uint256", }, TypeInfo::Boolean => "bool", TypeInfo::Custom { diff --git a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs index 00f96eab05e..5c5f04ef793 100644 --- a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs +++ b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs @@ -4,7 +4,6 @@ use crate::{ type_system::*, BuildTarget, Engines, }; - use itertools::Itertools; use sway_ast::{ attribute::Annotated, @@ -1257,6 +1256,7 @@ pub(crate) fn type_name_to_type_info_opt(name: &Ident) -> Option { "u16" => Some(TypeInfo::UnsignedInteger(IntegerBits::Sixteen)), "u32" => Some(TypeInfo::UnsignedInteger(IntegerBits::ThirtyTwo)), "u64" => Some(TypeInfo::UnsignedInteger(IntegerBits::SixtyFour)), + "u256" => Some(TypeInfo::UnsignedInteger(IntegerBits::V256)), "bool" => Some(TypeInfo::Boolean), "unit" => Some(TypeInfo::Tuple(Vec::new())), "b256" => Some(TypeInfo::B256), @@ -2887,6 +2887,7 @@ fn literal_to_literal( }; Literal::U64(value) } + LitIntType::U256 => Literal::U256(parsed), LitIntType::I8 | LitIntType::I16 | LitIntType::I32 | LitIntType::I64 => { let error = ConvertParseTreeError::SignedIntegersNotSupported { span }; return Err(handler.emit_err(error.into())); diff --git a/sway-core/src/type_system/info.rs b/sway-core/src/type_system/info.rs index 2d73371ff11..a4f1938a2fd 100644 --- a/sway-core/src/type_system/info.rs +++ b/sway-core/src/type_system/info.rs @@ -67,6 +67,7 @@ impl PartialEqWithEngines for VecSet { } /// Type information without an associated value, used for type inferencing and definition. +// see type_name_to_type_info_opt for known types strings to this enum #[derive(Debug, Clone, Default)] pub enum TypeInfo { #[default] @@ -433,6 +434,7 @@ impl DisplayWithEngines for TypeInfo { IntegerBits::Sixteen => "u16", IntegerBits::ThirtyTwo => "u32", IntegerBits::SixtyFour => "u64", + IntegerBits::V256 => "u256", } .into(), Boolean => "bool".into(), @@ -498,6 +500,7 @@ impl DebugWithEngines for TypeInfo { IntegerBits::Sixteen => "u16", IntegerBits::ThirtyTwo => "u32", IntegerBits::SixtyFour => "u64", + IntegerBits::V256 => "u256", } .into(), Boolean => "bool".into(), @@ -614,6 +617,7 @@ impl TypeInfo { Sixteen => "u16", ThirtyTwo => "u32", SixtyFour => "u64", + V256 => todo!(), } .into() } diff --git a/sway-ir/src/constant.rs b/sway-ir/src/constant.rs index 7bb29383366..e51456749bb 100644 --- a/sway-ir/src/constant.rs +++ b/sway-ir/src/constant.rs @@ -37,7 +37,7 @@ impl Constant { } } - pub fn new_uint(context: &mut Context, nbits: u8, n: u64) -> Self { + pub fn new_uint(context: &mut Context, nbits: u16, n: u64) -> Self { Constant { ty: Type::new_uint(context, nbits), value: ConstantValue::Uint(n), @@ -89,7 +89,7 @@ impl Constant { Value::new_constant(context, new_const) } - pub fn get_uint(context: &mut Context, nbits: u8, value: u64) -> Value { + pub fn get_uint(context: &mut Context, nbits: u16, value: u64) -> Value { let new_const = Constant::new_uint(context, nbits, value); Value::new_constant(context, new_const) } diff --git a/sway-ir/src/irtype.rs b/sway-ir/src/irtype.rs index 59f7f3f32eb..51139a74458 100644 --- a/sway-ir/src/irtype.rs +++ b/sway-ir/src/irtype.rs @@ -18,7 +18,7 @@ pub struct Type(pub generational_arena::Index); pub enum TypeContent { Unit, Bool, - Uint(u8), // XXX u256 is not unreasonable and can't fit in a `u8`. + Uint(u16), B256, String(u64), Array(Type, u64), @@ -51,6 +51,7 @@ impl Type { Self::get_or_create_unique_type(context, TypeContent::Bool); Self::get_or_create_unique_type(context, TypeContent::Uint(8)); Self::get_or_create_unique_type(context, TypeContent::Uint(64)); + Self::get_or_create_unique_type(context, TypeContent::Uint(256)); Self::get_or_create_unique_type(context, TypeContent::B256); Self::get_or_create_unique_type(context, TypeContent::Slice); } @@ -71,7 +72,7 @@ impl Type { } /// New unsigned integer type - pub fn new_uint(context: &mut Context, width: u8) -> Type { + pub fn new_uint(context: &mut Context, width: u16) -> Type { Self::get_or_create_unique_type(context, TypeContent::Uint(width)) } @@ -86,8 +87,8 @@ impl Type { } /// Get unsigned integer type - pub fn get_uint(context: &Context, width: u8) -> Option { - Self::get_type(context, &TypeContent::Uint(width)) + pub fn get_uint(context: &Context, width: u16) -> Type { + Self::get_type(context, &TypeContent::Uint(width)).expect("create_basic_types not called") } /// Get B256 type @@ -213,7 +214,7 @@ impl Type { } /// Is unsigned integer type of specific width - pub fn is_uint_of(&self, context: &Context, width: u8) -> bool { + pub fn is_uint_of(&self, context: &Context, width: u16) -> bool { matches!(*self.get_content(context), TypeContent::Uint(width_) if width == width_) } @@ -267,7 +268,7 @@ impl Type { } /// Get width of an integer type. - pub fn get_uint_width(&self, context: &Context) -> Option { + pub fn get_uint_width(&self, context: &Context) -> Option { if let TypeContent::Uint(width) = self.get_content(context) { Some(*width) } else { @@ -298,7 +299,10 @@ impl Type { let Some(Constant { value: ConstantValue::Uint(idx), ty: _, - }) = idx.get_constant(context) else { return None; }; + }) = idx.get_constant(context) + else { + return None; + }; ty.and_then(|(ty, accum_offset)| { if ty.is_struct(context) { // Sum up all sizes of all previous fields. @@ -379,10 +383,9 @@ impl Type { pub fn size_in_bytes(&self, context: &Context) -> u64 { match self.get_content(context) { - TypeContent::Unit - | TypeContent::Bool - | TypeContent::Uint(_) - | TypeContent::Pointer(_) => 8, + TypeContent::Uint(256) => 32, + TypeContent::Uint(width) => (*width as u64).max(64) / 8, + TypeContent::Unit | TypeContent::Bool | TypeContent::Pointer(_) => 8, TypeContent::Slice => 16, TypeContent::B256 => 32, TypeContent::String(n) => super::size_bytes_round_up_to_word_alignment!(*n), diff --git a/sway-ir/src/optimize/constants.rs b/sway-ir/src/optimize/constants.rs index a3e2d2f1dbf..e371530df74 100644 --- a/sway-ir/src/optimize/constants.rs +++ b/sway-ir/src/optimize/constants.rs @@ -120,18 +120,20 @@ fn combine_cmp(context: &mut Context, function: &Function) -> bool { let val1 = val1.get_constant(context).unwrap(); let val2 = val2.get_constant(context).unwrap(); match pred { - Predicate::Equal => { - Some((inst_val, block, val1.eq(context, val2))) - } + Predicate::Equal => Some((inst_val, block, val1.eq(context, val2))), Predicate::GreaterThan => { - let (ConstantValue::Uint(val1), ConstantValue::Uint(val2)) = (&val1.value, &val2.value) + let (ConstantValue::Uint(val1), ConstantValue::Uint(val2)) = + (&val1.value, &val2.value) else { - unreachable!("Type checker allowed non integer value for GreaterThan") + unreachable!( + "Type checker allowed non integer value for GreaterThan" + ) }; Some((inst_val, block, val1 > val2)) } Predicate::LessThan => { - let (ConstantValue::Uint(val1), ConstantValue::Uint(val2)) = (&val1.value, &val2.value) + let (ConstantValue::Uint(val1), ConstantValue::Uint(val2)) = + (&val1.value, &val2.value) else { unreachable!("Type checker allowed non integer value for LessThan") }; diff --git a/sway-ir/src/optimize/memcpyopt.rs b/sway-ir/src/optimize/memcpyopt.rs index 159c5854136..c9bb95f34ec 100644 --- a/sway-ir/src/optimize/memcpyopt.rs +++ b/sway-ir/src/optimize/memcpyopt.rs @@ -264,7 +264,8 @@ fn local_copy_prop_prememcpy(context: &mut Context, function: Function) -> Resul for (value, replace_with) in replaces.into_iter() { match replace_with { ReplaceWith::InPlaceLocal(replacement_var) => { - let Some(Instruction::GetLocal(redundant_var)) = value.get_instruction(context) else { + let Some(Instruction::GetLocal(redundant_var)) = value.get_instruction(context) + else { panic!("earlier match now fails"); }; if redundant_var.is_mutable(context) { diff --git a/sway-ir/src/parser.rs b/sway-ir/src/parser.rs index 17071441d47..3f6e66150e8 100644 --- a/sway-ir/src/parser.rs +++ b/sway-ir/src/parser.rs @@ -494,6 +494,7 @@ mod ir_builder { = ("unit" / "()") _ { IrAstTy::Unit } / "bool" _ { IrAstTy::Bool } / "u64" _ { IrAstTy::U64 } + / "u256" _ { IrAstTy::U256 } / "b256" _ { IrAstTy::B256 } / "string" _ "<" _ sz:decimal() ">" _ { IrAstTy::String(sz) } / array_ty() @@ -783,7 +784,11 @@ mod ir_builder { IrAstConstValue::Unit => Constant::get_unit(context), IrAstConstValue::Bool(b) => Constant::get_bool(context, *b), IrAstConstValue::B256(bs) => Constant::get_b256(context, *bs), - IrAstConstValue::Number(n) => Constant::get_uint(context, 64, *n), + IrAstConstValue::Number(n) => match val_ty { + IrAstTy::U64 => Constant::get_uint(context, 64, *n), + IrAstTy::U256 => Constant::get_uint(context, 256, *n), + _ => todo!(), + }, IrAstConstValue::String(s) => Constant::get_string(context, s.clone()), IrAstConstValue::Array(..) => { let array_const = self.as_constant(context, val_ty); @@ -802,6 +807,7 @@ mod ir_builder { Unit, Bool, U64, + U256, B256, String(u64), Array(Box, u64), @@ -816,6 +822,7 @@ mod ir_builder { IrAstTy::Unit => Type::get_unit(context), IrAstTy::Bool => Type::get_bool(context), IrAstTy::U64 => Type::get_uint64(context), + IrAstTy::U256 => Type::get_uint(context, 256), IrAstTy::B256 => Type::get_b256(context), IrAstTy::String(n) => Type::new_string(context, *n), IrAstTy::Array(el_ty, count) => { diff --git a/sway-ir/src/verify.rs b/sway-ir/src/verify.rs index 94da9de6d9a..2418cbc6bde 100644 --- a/sway-ir/src/verify.rs +++ b/sway-ir/src/verify.rs @@ -308,7 +308,7 @@ impl<'a, 'eng> InstructionVerifier<'a, 'eng> { fn verify_binary_op( &self, - _op: &BinaryOpKind, + op: &BinaryOpKind, arg1: &Value, arg2: &Value, ) -> Result<(), IrError> { @@ -318,8 +318,30 @@ impl<'a, 'eng> InstructionVerifier<'a, 'eng> { let arg2_ty = arg2 .get_type(self.context) .ok_or(IrError::VerifyBinaryOpIncorrectArgType)?; - if !arg1_ty.eq(self.context, &arg2_ty) || !arg1_ty.is_uint(self.context) { - return Err(IrError::VerifyBinaryOpIncorrectArgType); + + match op { + // left and right must have the same type and must be uint. + BinaryOpKind::Add + | BinaryOpKind::Sub + | BinaryOpKind::Mul + | BinaryOpKind::Div + | BinaryOpKind::And + | BinaryOpKind::Or + | BinaryOpKind::Xor + | BinaryOpKind::Mod => { + if !arg1_ty.eq(self.context, &arg2_ty) || !arg1_ty.is_uint(self.context) { + return Err(IrError::VerifyBinaryOpIncorrectArgType); + } + } + // left and right must be uint, but + // they dont need to be the same type + BinaryOpKind::Rsh | BinaryOpKind::Lsh => { + let is_arg1_nok = !arg1_ty.is_uint(self.context); + let is_arg2_nok = !arg2_ty.is_uint(self.context); + if is_arg1_nok || is_arg2_nok { + return Err(IrError::VerifyBinaryOpIncorrectArgType); + } + } } Ok(()) @@ -370,6 +392,8 @@ impl<'a, 'eng> InstructionVerifier<'a, 'eng> { let caller_arg_type = opt_caller_arg_type.as_ref().unwrap(); if !caller_arg_type.eq(self.context, callee_arg_type) { + dbg!(caller_arg_type.as_string(self.context)); + dbg!(callee_arg_type.as_string(self.context)); return Err(IrError::VerifyCallArgTypeMismatch( callee_content.name.clone(), caller_arg_type.as_string(self.context), diff --git a/sway-lib-core/src/ops.sw b/sway-lib-core/src/ops.sw index 6cd744a1f21..d1c9edd3e13 100644 --- a/sway-lib-core/src/ops.sw +++ b/sway-lib-core/src/ops.sw @@ -6,6 +6,13 @@ pub trait Add { fn add(self, other: Self) -> Self; } +impl Add for u256 { + fn add(self, other: Self) -> Self { + //let bytes: [u8; 64] = __be_bytes(self); + __add(self, other) + } +} + impl Add for u64 { fn add(self, other: Self) -> Self { __add(self, other) @@ -54,6 +61,12 @@ pub trait Subtract { fn subtract(self, other: Self) -> Self; } +impl Subtract for u256 { + fn subtract(self, other: Self) -> Self { + __sub(self, other) + } +} + impl Subtract for u64 { fn subtract(self, other: Self) -> Self { __sub(self, other) @@ -84,6 +97,12 @@ pub trait Multiply { fn multiply(self, other: Self) -> Self; } +impl Multiply for u256 { + fn multiply(self, other: Self) -> Self { + __mul(self, other) + } +} + impl Multiply for u64 { fn multiply(self, other: Self) -> Self { __mul(self, other) @@ -132,6 +151,12 @@ pub trait Divide { fn divide(self, other: Self) -> Self; } +impl Divide for u256 { + fn divide(self, other: Self) -> Self { + __div(self, other) + } +} + impl Divide for u64 { fn divide(self, other: Self) -> Self { __div(self, other) @@ -164,6 +189,12 @@ pub trait Mod { fn modulo(self, other: Self) -> Self; } +impl Mod for u256 { + fn modulo(self, other: Self) -> Self { + __mod(self, other) + } +} + impl Mod for u64 { fn modulo(self, other: Self) -> Self { __mod(self, other) @@ -198,6 +229,34 @@ impl Not for bool { } } + +impl Not for u64 { + fn not(self) -> Self { + __not(self) + } +} + +impl Not for u32 { + fn not(self) -> Self { + let v = __not(self); + __and(v, u32::max()) + } +} + +impl Not for u16 { + fn not(self) -> Self { + let v = __not(self); + __and(v, u16::max()) + } +} + +impl Not for u8 { + fn not(self) -> Self { + let v = __not(self); + __and(v, u8::max()) + } +} + pub trait Eq { fn eq(self, other: Self) -> bool; } { @@ -212,6 +271,12 @@ impl Eq for bool { } } +impl Eq for u256 { + fn eq(self, other: Self) -> bool { + __eq(self, other) + } +} + impl Eq for u64 { fn eq(self, other: Self) -> bool { __eq(self, other) @@ -258,6 +323,15 @@ pub trait Ord { fn lt(self, other: Self) -> bool; } +impl Ord for u256 { + fn gt(self, other: Self) -> bool { + __gt(self, other) + } + fn lt(self, other: Self) -> bool { + __lt(self, other) + } +} + impl Ord for u64 { fn gt(self, other: Self) -> bool { __gt(self, other) @@ -334,6 +408,12 @@ pub trait BitwiseAnd { fn binary_and(self, other: Self) -> Self; } +impl BitwiseAnd for u256 { + fn binary_and(self, other: Self) -> Self { + __and(self, other) + } +} + impl BitwiseAnd for u64 { fn binary_and(self, other: Self) -> Self { __and(self, other) @@ -358,10 +438,29 @@ impl BitwiseAnd for u8 { } } +impl BitwiseAnd for b256 { + fn binary_and(val: self, other: Self) -> Self { + let (value_word_1, value_word_2, value_word_3, value_word_4) = decompose(val); + let (other_word_1, other_word_2, other_word_3, other_word_4) = decompose(other); + let word_1 = value_word_1.binary_and(other_word_1); + let word_2 = value_word_2.binary_and(other_word_2); + let word_3 = value_word_3.binary_and(other_word_3); + let word_4 = value_word_4.binary_and(other_word_4); + let rebuilt = compose((word_1, word_2, word_3, word_4)); + rebuilt + } +} + pub trait BitwiseOr { fn binary_or(self, other: Self) -> Self; } +impl BitwiseOr for u256 { + fn binary_or(self, other: Self) -> Self { + __or(self, other) + } +} + impl BitwiseOr for u64 { fn binary_or(self, other: Self) -> Self { __or(self, other) @@ -386,10 +485,29 @@ impl BitwiseOr for u8 { } } +impl BitwiseOr for b256 { + fn binary_or(val: self, other: Self) -> Self { + let (value_word_1, value_word_2, value_word_3, value_word_4) = decompose(val); + let (other_word_1, other_word_2, other_word_3, other_word_4) = decompose(other); + let word_1 = value_word_1.binary_or(other_word_1); + let word_2 = value_word_2.binary_or(other_word_2); + let word_3 = value_word_3.binary_or(other_word_3); + let word_4 = value_word_4.binary_or(other_word_4); + let rebuilt = compose((word_1, word_2, word_3, word_4)); + rebuilt + } +} + pub trait BitwiseXor { fn binary_xor(self, other: Self) -> Self; } +impl BitwiseXor for u256 { + fn binary_xor(self, other: Self) -> Self { + __xor(self, other) + } +} + impl BitwiseXor for u64 { fn binary_xor(self, other: Self) -> Self { __xor(self, other) @@ -414,59 +532,6 @@ impl BitwiseXor for u8 { } } -impl Not for u64 { - fn not(self) -> Self { - __not(self) - } -} - -impl Not for u32 { - fn not(self) -> Self { - let v = __not(self); - __and(v, u32::max()) - } -} - -impl Not for u16 { - fn not(self) -> Self { - let v = __not(self); - __and(v, u16::max()) - } -} - -impl Not for u8 { - fn not(self) -> Self { - let v = __not(self); - __and(v, u8::max()) - } -} - -impl BitwiseAnd for b256 { - fn binary_and(val: self, other: Self) -> Self { - let (value_word_1, value_word_2, value_word_3, value_word_4) = decompose(val); - let (other_word_1, other_word_2, other_word_3, other_word_4) = decompose(other); - let word_1 = value_word_1.binary_and(other_word_1); - let word_2 = value_word_2.binary_and(other_word_2); - let word_3 = value_word_3.binary_and(other_word_3); - let word_4 = value_word_4.binary_and(other_word_4); - let rebuilt = compose((word_1, word_2, word_3, word_4)); - rebuilt - } -} - -impl BitwiseOr for b256 { - fn binary_or(val: self, other: Self) -> Self { - let (value_word_1, value_word_2, value_word_3, value_word_4) = decompose(val); - let (other_word_1, other_word_2, other_word_3, other_word_4) = decompose(other); - let word_1 = value_word_1.binary_or(other_word_1); - let word_2 = value_word_2.binary_or(other_word_2); - let word_3 = value_word_3.binary_or(other_word_3); - let word_4 = value_word_4.binary_or(other_word_4); - let rebuilt = compose((word_1, word_2, word_3, word_4)); - rebuilt - } -} - impl BitwiseXor for b256 { fn binary_xor(val: self, other: Self) -> Self { let (value_word_1, value_word_2, value_word_3, value_word_4) = decompose(val); @@ -490,6 +555,7 @@ trait OrdEq: Ord + Eq { } } +impl OrdEq for u256 {} impl OrdEq for u64 {} impl OrdEq for u32 {} impl OrdEq for u16 {} @@ -501,6 +567,15 @@ pub trait Shift { fn rsh(self, other: u64) -> Self; } +impl Shift for u256 { + fn lsh(self, other: u64) -> Self { + __lsh(self, other) + } + fn rsh(self, other: u64) -> Self { + __rsh(self, other) + } +} + impl Shift for u64 { fn lsh(self, other: u64) -> Self { __lsh(self, other) diff --git a/sway-lsp/src/traverse/parsed_tree.rs b/sway-lsp/src/traverse/parsed_tree.rs index 69eae13661d..8f463e16eca 100644 --- a/sway-lsp/src/traverse/parsed_tree.rs +++ b/sway-lsp/src/traverse/parsed_tree.rs @@ -1087,6 +1087,7 @@ fn literal_to_symbol_kind(value: &Literal) -> SymbolKind { | Literal::U16(..) | Literal::U32(..) | Literal::U64(..) + | Literal::U256(..) | Literal::Numeric(..) => SymbolKind::NumericLiteral, Literal::String(..) => SymbolKind::StringLiteral, Literal::B256(..) => SymbolKind::ByteLiteral, diff --git a/sway-lsp/src/utils/debug.rs b/sway-lsp/src/utils/debug.rs index 7baf327709e..d4579947037 100644 --- a/sway-lsp/src/utils/debug.rs +++ b/sway-lsp/src/utils/debug.rs @@ -51,6 +51,7 @@ fn literal_to_string(literal: &Literal) -> String { Literal::U16(_) => "u16".into(), Literal::U32(_) => "u32".into(), Literal::U64(_) => "u64".into(), + Literal::U256(_) => "u256".into(), Literal::Numeric(_) => "u64".into(), Literal::String(len) => format!("str[{}]", len.as_str().len()), Literal::Boolean(_) => "bool".into(), diff --git a/sway-parse/src/token.rs b/sway-parse/src/token.rs index 846539ba2a5..4f09d02ed0e 100644 --- a/sway-parse/src/token.rs +++ b/sway-parse/src/token.rs @@ -703,6 +703,7 @@ fn lex_int_ty_opt(l: &mut Lexer<'_>) -> Result> { None => break l.src.len(), } }; + // Parse the suffix to a known one, or if unknown, recover by throwing it away. let ty = match parse_int_suffix(&suffix) { Some(s) => s, @@ -726,6 +727,8 @@ pub fn parse_int_suffix(suffix: &str) -> Option { "u16" => LitIntType::U16, "u32" => LitIntType::U32, "u64" => LitIntType::U64, + "u128" => todo!(), + "u256" => LitIntType::U256, "i8" => LitIntType::I8, "i16" => LitIntType::I16, "i32" => LitIntType::I32, diff --git a/sway-types/src/integer_bits.rs b/sway-types/src/integer_bits.rs index 0b2f30dc7b9..0f405136fb2 100644 --- a/sway-types/src/integer_bits.rs +++ b/sway-types/src/integer_bits.rs @@ -6,6 +6,7 @@ pub enum IntegerBits { Sixteen, ThirtyTwo, SixtyFour, + V256, } impl fmt::Display for IntegerBits { @@ -16,6 +17,7 @@ impl fmt::Display for IntegerBits { Sixteen => "sixteen", ThirtyTwo => "thirty two", SixtyFour => "sixty four", + V256 => "256", }; write!(f, "{s}") } diff --git a/templates/sway-test-rs/template/Cargo.toml b/templates/sway-test-rs/template/Cargo.toml index 243a37f3208..0556e093861 100644 --- a/templates/sway-test-rs/template/Cargo.toml +++ b/templates/sway-test-rs/template/Cargo.toml @@ -7,7 +7,7 @@ authors = ["{{authors}}"] license = "Apache-2.0" [dev-dependencies] -fuels = { version = "0.42", features = ["fuel-core-lib"] } +fuels = { version = "0.44", features = ["fuel-core-lib"] } tokio = { version = "1.12", features = ["rt", "macros"] } [[test]] diff --git a/test/src/e2e_vm_tests/mod.rs b/test/src/e2e_vm_tests/mod.rs index ebe5514a7b6..80d5272934b 100644 --- a/test/src/e2e_vm_tests/mod.rs +++ b/test/src/e2e_vm_tests/mod.rs @@ -340,6 +340,7 @@ impl TestContext { .collect(); if !failed.is_empty() { + println!("FAILED!! output:\n{}", output); panic!( "For {name}\n{} tests failed:\n{}", failed.len(), diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/ops/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/ops/json_abi_oracle.json index 03b2f150939..dfa4d35b95e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/ops/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/ops/json_abi_oracle.json @@ -17,7 +17,7 @@ "types": [ { "components": null, - "type": "bool", + "type": "u256", "typeId": 0, "typeParameters": null } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/Forc.lock new file mode 100644 index 00000000000..f6131c8ee73 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = 'core' +source = 'path+from-root-0ACF6FE48FDFC4A8' + +[[package]] +name = 'std' +source = 'path+from-root-0ACF6FE48FDFC4A8' +dependencies = ['core'] + +[[package]] +name = 'typeinfo_custom_callpath2' +source = 'member' +dependencies = ['std'] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/Forc.toml new file mode 100644 index 00000000000..0b567cce62a --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/Forc.toml @@ -0,0 +1,8 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "typeinfo_custom_callpath2" + +[dependencies] +std = { path = "../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/json_abi_oracle.json new file mode 100644 index 00000000000..03b2f150939 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "bool", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/src/main.sw new file mode 100644 index 00000000000..a0cca240da9 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/src/main.sw @@ -0,0 +1,41 @@ +script; + +use core::ops::*; + +fn main() -> bool { + assert(0u256 == 0u256); + assert(0u256 != 1u256); + assert(2u256 == (1u256 + 1u256)); + assert(2u256 == (3u256 - 1u256)); + assert(10u256 == (5u256 * 2u256)); + assert(2u256 == (10u256 / 5u256)); + assert(2u256 == (12u256 % 5u256)); + // Not - still do not support big literals + + assert(1u256 > 0u256); + assert(1u256 >= 0u256); + assert(1u256 >= 1u256); + + assert(1u256 < 2u256); + assert(1u256 <= 2u256); + assert(2u256 <= 2u256); + + assert(1u256 == (1u256 & 1u256)); + assert(0u256 == (1u256 & 2u256)); + + assert(1u256 == (1u256 | 1u256)); + assert(3u256 == (1u256 | 2u256)); + + assert(0u256 == (1u256 ^ 1u256)); + assert(3u256 == (1u256 ^ 2u256)); + + assert(8u256 == (1u256 << 3)); + assert(2u256 == (16u256 >> 3)); + + // Errors + // add overflow + // minus underflow + // mul overflow + // divide by zero + true +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/test.toml new file mode 100644 index 00000000000..ace9e6f3186 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256_ops/test.toml @@ -0,0 +1,3 @@ +category = "run" +expected_result = { action = "return", value = 1 } +validate_abi = true diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/array_of_structs_caller/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/array_of_structs_caller/src/main.sw index d9da82249cc..bebc436b581 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/array_of_structs_caller/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/array_of_structs_caller/src/main.sw @@ -4,7 +4,7 @@ use array_of_structs_abi::{Id, TestContract, Wrapper}; use std::hash::sha256; fn main() -> u64 { - let addr = abi(TestContract, 0xb534f555ed15c5f99dc318f4260faeba317ecefa094aba85c5c5e7ad043480ad); + let addr = abi(TestContract, 0x6f21fe2568822746d1e6a3c2fc4ad1b010f43f8487ba130768b0f34c9ecb9da7); let input = [Wrapper { id: Id { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/bal_opcode/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/bal_opcode/src/main.sw index 1fa72f097cb..ce59d91be55 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/bal_opcode/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/bal_opcode/src/main.sw @@ -5,7 +5,7 @@ use balance_test_abi::BalanceTest; fn main() -> bool { // @todo switch to using ContractId when abi signature changes. - let balance_test_contract_id = 0xa49cbeebc26a586897a895092ee2bc138c982ee31404e7bc9d2c1d9bbec6e036; + let balance_test_contract_id = 0xd54323a3316a7cfd26a3bab076a0194dfffbcc9a583d152043f5237fa60753ed; let balance_test_contract = abi(BalanceTest, balance_test_contract_id); let number = balance_test_contract.get_42 { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw index 5f56edd1b87..b5c95057110 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw @@ -3,7 +3,7 @@ script; use abi_with_tuples::*; fn main() -> bool { - let the_abi = abi(MyContract, 0x553558ff0c47820e5012953153ec30658bd2df11ef013139839551579dbff2f0); + let the_abi = abi(MyContract, 0xae6af2e324ada9943f1c9b3d6ea2db1b9f9bb1cd1732321877b59bd75b6821fd); let param1 = ( Person { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw index f24dfc51f20..18a95879dab 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw @@ -2,7 +2,7 @@ script; use basic_storage_abi::{BasicStorage, Quad}; fn main() -> u64 { - let addr = abi(BasicStorage, 0xd32372eac35fc0d05d1cbefb6d5f6a51f14ea024e4cb452ed3faa99b4ddb165d); + let addr = abi(BasicStorage, 0x346251fd98fc1495c415daa4cf1d80281e7fbe5353e51125bbed63637fc1cd9b); let key = 0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; let value = 4242; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_contract_with_type_aliases/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_contract_with_type_aliases/src/main.sw index 5106224cdfe..c3319ace6bb 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_contract_with_type_aliases/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_contract_with_type_aliases/src/main.sw @@ -3,7 +3,7 @@ script; use contract_with_type_aliases_abi::*; fn main() { - let caller = abi(MyContract, 0x327fe8d236dd68c93d9e16e3a28fb3ab45404fa75b44e6ebf435e74984cd56fd); + let caller = abi(MyContract, 0xfcb02d42c5e47a434798b1ec463f9fea652fbb47d2f99e9919650ceceb013799); let x = AssetId::from(0x0101010101010101010101010101010101010101010101010101010101010101); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_increment_contract/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_increment_contract/src/main.sw index 030066e8aee..e7fcd99b0da 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_increment_contract/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_increment_contract/src/main.sw @@ -3,7 +3,7 @@ script; use increment_abi::Incrementor; fn main() -> bool { - let the_abi = abi(Incrementor, 0x0f18501abf5e6bb3117f73578dacbde5a51b0ba75d32d402e2e955e0c06a8112); + let the_abi = abi(Incrementor, 0x1ed1f82d3114e974dc70f82d8e425e28cc5fa4fcbc8458d602bc213bcedbc883); the_abi.increment(5); the_abi.increment(5); let result = the_abi.get(); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_auth_test/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_auth_test/src/main.sw index 10673282487..90884dd4a15 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_auth_test/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_auth_test/src/main.sw @@ -4,7 +4,7 @@ use auth_testing_abi::AuthTesting; // should be false in the case of a script fn main() -> bool { - let caller = abi(AuthTesting, 0x98c8c9232f0a2b2558889628ffb36cfc1a7224c9afc104522bfdb1b49a882489); + let caller = abi(AuthTesting, 0x66e88a6499e593af0358dc93f6c0733b783da91caefd58d7bd8579c8a2d0bd1b); let result = caller.returns_gm_one(); assert(result); result diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_context_test/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_context_test/src/main.sw index 4ce7c2fdfc3..41fe15b3927 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_context_test/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_context_test/src/main.sw @@ -7,7 +7,7 @@ fn main() -> bool { let zero = b256::min(); let gas: u64 = u64::max(); let amount: u64 = 11; - let other_contract_id = ContractId::from(0x8049358afbe3e0c919d595aab87074ad6e192ae6e13058fb0f15fc5ca09da66d); + let other_contract_id = ContractId::from(0x248afda385f2763d12712f668c52b78a928b7fdc848b67ae3c4fb12efd89ce94); let base_asset_id = BASE_ASSET_ID; let test_contract = abi(ContextTesting, other_contract_id.into()); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/nested_struct_args_caller/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/nested_struct_args_caller/src/main.sw index 33ac2857e19..dd69d69ae47 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/nested_struct_args_caller/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/nested_struct_args_caller/src/main.sw @@ -3,7 +3,7 @@ script; use nested_struct_args_abi::*; fn main() -> bool { - let contract_id = 0x33639d15e9187676324cf8a42f6e15349660dc04d4cd52a9919bb9b3f15f732e; + let contract_id = 0xbc305fb5e79e14f1cbd578ec5661686610720b6fe3117ffd54f49ef00bd4b011; let caller = abi(NestedStructArgs, contract_id); let param_one = StructOne { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw index a836cf6a0e7..b454ee1d910 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw @@ -4,7 +4,7 @@ use storage_access_abi::*; use std::hash::sha256; fn main() -> bool { - let contract_id = 0x1838d1e56392f46b1da5620c81cbb0d371520365dee7300b56112e74dd6fc24d; + let contract_id = 0x2a63e216624d51ad41942c40f5da7c932caa7b2d531b9ef0a6f4e517e860b6f8; let caller = abi(StorageAccess, contract_id); // Test initializers diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/token_ops_test/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/token_ops_test/src/main.sw index 80df85cdcef..f2dcdf8e403 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/token_ops_test/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/token_ops_test/src/main.sw @@ -14,10 +14,10 @@ fn main() -> bool { let default_gas = 1_000_000_000_000; // the deployed fuel_coin Contract_Id: - let fuelcoin_id = ContractId::from(0x1965bb988d9f2d052ee947f5ec33a5cba8f140cee7cf1ef084215c12915709e2); + let fuelcoin_id = ContractId::from(0x2eac4ac4fbff902244be04d8d60be35e5fd6e29cbab5c8ad7b6905c60ce921bf); // contract ID for sway/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/balance_test_contract/ - let balance_test_id = ContractId::from(0xa49cbeebc26a586897a895092ee2bc138c982ee31404e7bc9d2c1d9bbec6e036); + let balance_test_id = ContractId::from(0xd54323a3316a7cfd26a3bab076a0194dfffbcc9a583d152043f5237fa60753ed); // todo: use correct type ContractId let fuel_coin = abi(TestFuelCoin, fuelcoin_id.into()); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/auth_testing_abi/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/auth_testing_abi/Forc.lock index ccbfdf27499..5de996948cb 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/auth_testing_abi/Forc.lock +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_abis/auth_testing_abi/Forc.lock @@ -1,3 +1,8 @@ [[package]] name = 'auth_testing_abi' -dependencies = [] +source = 'member' +dependencies = ['core'] + +[[package]] +name = 'core' +source = 'path+from-root-5781B31F5E4458CC' diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/contract_multi_test/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/contract_multi_test/src/main.sw index bc931e1df58..2ae433b872a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/contract_multi_test/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/unit_tests/workspace_test/contract_multi_test/src/main.sw @@ -17,7 +17,7 @@ fn test_foo() { #[test(should_revert)] fn test_fail() { - let contract_id = 0x6c7fdd957919f63b4fd62074a2641425d20e077fe057cb2e48f1e35a8b6ef3f4; + let contract_id = 0x3fa23a7eb36576f090f6895a41a32189ce2e2a8406948cdf71a88b8ce023d5a5; let caller = abi(MyContract, contract_id); let result = caller.test_function {}(); assert(result == false) @@ -25,7 +25,7 @@ fn test_fail() { #[test] fn test_success() { - let contract_id = 0x6c7fdd957919f63b4fd62074a2641425d20e077fe057cb2e48f1e35a8b6ef3f4; + let contract_id = 0x3fa23a7eb36576f090f6895a41a32189ce2e2a8406948cdf71a88b8ce023d5a5; let caller = abi(MyContract, contract_id); let result = caller.test_function {}(); assert(result == true) diff --git a/test/src/ir_generation/mod.rs b/test/src/ir_generation/mod.rs index dabd3835c70..7f613babb10 100644 --- a/test/src/ir_generation/mod.rs +++ b/test/src/ir_generation/mod.rs @@ -248,7 +248,7 @@ pub(super) async fn run(filter_regex: Option<®ex::Regex>, verbose: bool) -> R // Compile to IR. let include_tests = true; - let mut ir = compile_program(typed_program, include_tests, &engines) + let ir = compile_program(typed_program, include_tests, &engines) .unwrap_or_else(|e| { use sway_types::span::Spanned; let span = e.span(); @@ -259,9 +259,11 @@ pub(super) async fn run(filter_regex: Option<®ex::Regex>, verbose: bool) -> R span.end(), span.as_str() ); - }) - .verify() + }); + let ir_string = ir.to_string(); + let mut ir = ir.verify() .unwrap_or_else(|err| { + println!("{ir_string}"); panic!("IR verification failed for test {}:\n{err}", path.display()); }); @@ -531,8 +533,10 @@ fn compile_core(build_target: BuildTarget, engines: &Engines) -> namespace::Modu std_module } _ => { + println!("Errors"); + println!("------"); for err in res.errors { - println!("{err:?}"); + println!(" {err:?}"); } panic!("Failed to compile sway-lib-core for IR tests."); } diff --git a/test/src/ir_generation/tests/let_const_init.sw b/test/src/ir_generation/tests/let_const_init.sw index d5b4c2efe0a..8dae1cc51b4 100644 --- a/test/src/ir_generation/tests/let_const_init.sw +++ b/test/src/ir_generation/tests/let_const_init.sw @@ -22,4 +22,4 @@ fn main() -> u64 { // not: local u64 a // check: entry(): // check: $(a=$VAL) = const u64 10 -// check: ret u64 $a +// check: ret u64 $a diff --git a/test/src/ir_generation/tests/u256.sw b/test/src/ir_generation/tests/u256.sw new file mode 100644 index 00000000000..0e77b7a0158 --- /dev/null +++ b/test/src/ir_generation/tests/u256.sw @@ -0,0 +1,18 @@ +script; + +fn main() -> u64 { + let a = 0u256 + 1u256; + 0 +} + +// ::check-ir:: +// check: v0 = const u256 0 +// check: v1 = const u256 1 +// check: v2 = call add_0(v0, v1) +// check: v3 = get_local ptr u256, a +// check: store v2 to v3 + +// check: entry(self: u256, other: u256) + +// ::check-asm:: +// check: wqop \ No newline at end of file diff --git a/test/src/sdk-harness/Cargo.lock b/test/src/sdk-harness/Cargo.lock index bc3d9fbc2ef..74db9d86c58 100644 --- a/test/src/sdk-harness/Cargo.lock +++ b/test/src/sdk-harness/Cargo.lock @@ -243,9 +243,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.71" +version = "0.1.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" +checksum = "7b2d0f03b3640e3a630367e40c468cb7f309529c708ed1d88597047b0e7c6ef7" dependencies = [ "proc-macro2", "quote", @@ -507,9 +507,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.11" +version = "4.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1640e5cc7fb47dbb8338fd471b105e7ed6c3cb2aeb00c2e067127ffd3764a05d" +checksum = "384e169cc618c613d5e3ca6404dda77a8685a63e08660dcc64abaf7da7cb0c7a" dependencies = [ "clap_builder", "clap_derive", @@ -518,9 +518,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.3.11" +version = "4.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c59138d527eeaf9b53f35a77fcc1fad9d883116070c63d5de1c7dc7b00c72b" +checksum = "ef137bbe35aab78bdb468ccfba75a5f4d8321ae011d34063770780545176af2d" dependencies = [ "anstream", "anstyle", @@ -694,9 +694,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" dependencies = [ "libc", ] @@ -1084,6 +1084,12 @@ dependencies = [ "uuid", ] +[[package]] +name = "ethnum" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0198b9d0078e0f30dedc7acbb21c974e838fc8fae3ee170128658a98cb2c1c04" + [[package]] name = "eventsource-client" version = "0.10.2" @@ -1164,9 +1170,9 @@ dependencies = [ [[package]] name = "fuel-asm" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1331be83ba8ce8fa9217272b2709bbe29a01daff5fe7ef58ba1b64ec18fe40c0" +checksum = "938aaed0bfed319fab9c6f1196cecc11b55c734c0506613107e1319f98941d17" dependencies = [ "bitflags 1.3.2", "fuel-types", @@ -1176,9 +1182,9 @@ dependencies = [ [[package]] name = "fuel-core" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c978d128cd4cc73675a5424a67c5c0dbb70fbb52bb6e5d1bf38664f966e369d" +checksum = "ef273accbd9652e90044b4ab0a1c6dc75a2a3ce83c5598d0869f58524e2eb13f" dependencies = [ "anyhow", "async-graphql", @@ -1218,9 +1224,9 @@ dependencies = [ [[package]] name = "fuel-core-chain-config" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e533fa1f86ae96579f4394205a7dfbad31715043f7119a82aa7a14effaed3a17" +checksum = "d5035cc52016a1d03946b15b776aded23a4dd57b20470ba7d32b0de7b5292319" dependencies = [ "anyhow", "bech32 0.9.1", @@ -1238,9 +1244,9 @@ dependencies = [ [[package]] name = "fuel-core-client" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38a6bf1c0a6e6acf848f4b994e0b91c96c4f443f71d26f437642d135d5d71d3d" +checksum = "730041e36f77a35d634e51f191497a2e182f10ef81721d26f0b2c49aac58469e" dependencies = [ "anyhow", "cynic", @@ -1249,7 +1255,7 @@ dependencies = [ "fuel-core-types", "futures", "hex", - "hyper-rustls 0.24.1", + "hyper-rustls 0.24.0", "itertools", "reqwest", "serde", @@ -1261,9 +1267,9 @@ dependencies = [ [[package]] name = "fuel-core-consensus-module" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10dfa90f07cd210da9e16c61f5405a9d5c71a701848e6f9e01a1568b3b8c0f91" +checksum = "6ad1435a0838e3707bb2450bbfa590b681244dd22246209d1718b6c8657b829b" dependencies = [ "anyhow", "fuel-core-chain-config", @@ -1274,9 +1280,9 @@ dependencies = [ [[package]] name = "fuel-core-database" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5b8f8f12e8b7dfa5e68ee32cbecfba2e8aa2a06b930fd181f0b4ae71652484" +checksum = "656f02a737146f2eec78fc97c57aa583b685dd51863617c028a930525e14cef4" dependencies = [ "anyhow", "fuel-core-storage", @@ -1286,9 +1292,9 @@ dependencies = [ [[package]] name = "fuel-core-executor" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f0dc752bfd46dee5ab51fd46f13858b9aa85865ba76d180c9c8e3cc0b25949b" +checksum = "42c1e532902b60a5272a9006e698c9bcc2797173515f8811b5087998ecde6835" dependencies = [ "anyhow", "fuel-core-chain-config", @@ -1298,9 +1304,9 @@ dependencies = [ [[package]] name = "fuel-core-importer" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0989eb91e18f3541b7a690ed3bca92521939e80f507a08ce0fd6d8bf34cf1eb" +checksum = "dc48cc7f2fda4d3d468cddd9259d2c5ddd7ca0eda09ab553557a358c2ed8680c" dependencies = [ "anyhow", "fuel-core-storage", @@ -1312,9 +1318,9 @@ dependencies = [ [[package]] name = "fuel-core-metrics" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "401e1a1187a91f1df5808c8416137623f119f058f6c6e2710d43c58744e9fa14" +checksum = "bee942c4d08547cc5242609ed8d21d64a2eeea3996c030c067e96706b89fedcd" dependencies = [ "axum", "lazy_static", @@ -1325,9 +1331,9 @@ dependencies = [ [[package]] name = "fuel-core-poa" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e15616957477d7c37f5845d58abcb13f8ab9a7f526a499a795bb7b8618c6e238" +checksum = "ae4df2341d6b178fd15bda16a41919268f38e48acb2018136b56ae700d2f15b5" dependencies = [ "anyhow", "async-trait", @@ -1342,9 +1348,9 @@ dependencies = [ [[package]] name = "fuel-core-producer" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df203c0e56c1827831a363e895aea7c9c642c18f1a57adbdd8ac6c4e115231dc" +checksum = "b5104778a7f964fa3a5f2386ade44b78461670bfd1d8a0ad3aa5e06e90efbe3d" dependencies = [ "anyhow", "async-trait", @@ -1358,9 +1364,9 @@ dependencies = [ [[package]] name = "fuel-core-services" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecc615cb429744e1783db0d5b30dd01ec0d73c675f47964e62edc1f01b40ac2" +checksum = "c263bb70c6a5d06618ff7fb96d9b9974da47f61b13e902e1dd492c0485e3f601" dependencies = [ "anyhow", "async-trait", @@ -1372,9 +1378,9 @@ dependencies = [ [[package]] name = "fuel-core-storage" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ed1d03eb74feb0ea8538ab557e52c7bc4f1a1c3aaafba9076038da256d86920" +checksum = "b67a83eb8814625b3cfda2671b2bf81006b5164515a446b2274e68dbbdc3d093" dependencies = [ "anyhow", "fuel-core-types", @@ -1384,9 +1390,9 @@ dependencies = [ [[package]] name = "fuel-core-txpool" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d563ceae0ed89ed34f78a7835d15a40ef9d35c9b260b622049335e6c8deb884f" +checksum = "942792c1a6a4d244fdd3922d63b1308c6f67bcc5a7a72289fa6c063c44cd9331" dependencies = [ "anyhow", "async-trait", @@ -1403,9 +1409,9 @@ dependencies = [ [[package]] name = "fuel-core-types" -version = "0.18.3" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "059da83a7e012a438c9962cbfe1e1b2d3e04f67a75d5be8899009b6456b04002" +checksum = "df7769e4edb5987d0f4cd53926a574ad8f1b5e3bc7c3462f4313799a8ac68f7b" dependencies = [ "anyhow", "derive_more", @@ -1419,9 +1425,9 @@ dependencies = [ [[package]] name = "fuel-crypto" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb3f73571a03523cb92826003753ff1bdd1882767e67801de223ce3ad6133349" +checksum = "aaa3e72ffbe936a643f2d83d91ac19ffd3c687a6f0b2015c6251c10bea60371f" dependencies = [ "borrown", "coins-bip32", @@ -1437,9 +1443,9 @@ dependencies = [ [[package]] name = "fuel-merkle" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d5646d95e02a63fd59da942fcf5d6217dbd8b6866c1ad3a0232be0913c4d077" +checksum = "abf2b9c4dc976a2e0fce4eda29673569fbe89ac86bf5255d3a928beb4c61b23b" dependencies = [ "digest 0.10.7", "fuel-storage", @@ -1451,15 +1457,15 @@ dependencies = [ [[package]] name = "fuel-storage" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b72444da90354b6d1d220b81c6803085689f5e7d53e1d4bd11cfa3d4c5a1b27" +checksum = "55e37ce148bbc07bd1398f717728976d9ad03f147bb500c70579cf317baacd32" [[package]] name = "fuel-tx" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04187579ecfbb04a380c60f9eecae1a288dbe463c111dc7dde66fa736445a638" +checksum = "960f7584fb62cd3af77d70deb015fad0ca1c52e3b0a8e29ff9b005e5b7157448" dependencies = [ "derivative", "fuel-asm", @@ -1477,9 +1483,9 @@ dependencies = [ [[package]] name = "fuel-types" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6543ca2f5124a19b1486507243188a57be64c9914d1908e154a1866eeffb69" +checksum = "d1f9f7bd0f0ae5f8dcebb2cec8d504f45a03fc0bca19c65bfd45b07ed5e9fb68" dependencies = [ "hex", "rand", @@ -1488,12 +1494,13 @@ dependencies = [ [[package]] name = "fuel-vm" -version = "0.31.2" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d42e99fe69e913bbde4900f96efb6ceae13b68d369bf22d4b435571d6ed7d65" +checksum = "d3a031708a34fcbee85bca5f4b9f0b61cd80bf8555972020ddee2420d7306a47" dependencies = [ "bitflags 1.3.2", "derivative", + "ethnum", "fuel-asm", "fuel-crypto", "fuel-merkle", @@ -1501,6 +1508,8 @@ dependencies = [ "fuel-tx", "fuel-types", "itertools", + "paste", + "primitive-types", "rand", "serde", "sha3", @@ -1510,9 +1519,9 @@ dependencies = [ [[package]] name = "fuels" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa81d69072a9d4ba6fac79d9b5b66348daf95089ecda85a9231e41e5dd45bc85" +checksum = "5280da1aababb8cae2c4f56d9ac43613e5aab328f62d146bc4598ed3a3e7d93b" dependencies = [ "fuel-core", "fuel-core-client", @@ -1526,9 +1535,9 @@ dependencies = [ [[package]] name = "fuels-accounts" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9a03259b1ece608c33541477fed7dea07bb3e78f25f85a8a3060f6501d6e982" +checksum = "58e79e6b022c45f8e13cbdbded36232cac380e6885eaac12e8b3234613ad2c3a" dependencies = [ "async-trait", "bytes", @@ -1553,9 +1562,9 @@ dependencies = [ [[package]] name = "fuels-code-gen" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e8ec25373ed1ae06cfe53afc4e3ecd6057aa4ff3a3329e40f42784afe21726b" +checksum = "051906531d2f79ac3a790f06590a5f8b3e63229482494ebdabcce3ca41d581d8" dependencies = [ "Inflector", "fuel-abi-types", @@ -1569,9 +1578,9 @@ dependencies = [ [[package]] name = "fuels-core" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b133aff726340284937e3233b8c9dd8429812dd463e4e6f53373ca13e644c99" +checksum = "3ca6bc2b138bcbbd94bc5e00129f0062268135f085208e63c58c9c59a4efc9e5" dependencies = [ "bech32 0.9.1", "chrono", @@ -1593,13 +1602,14 @@ dependencies = [ "strum", "strum_macros", "thiserror", + "uint", ] [[package]] name = "fuels-macros" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef684e13ddc8b16f7828dc98ca309f69a6516068bb307c78b8e64aaf010b397" +checksum = "9dfcb6d4b7f354a55c061350f8013f739b0833758baa1b89e2e1b35791e6030e" dependencies = [ "Inflector", "fuel-abi-types", @@ -1615,9 +1625,9 @@ dependencies = [ [[package]] name = "fuels-programs" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09e582cc270a794e02e40150f79d2a92830bf5adaaadf4147de02689ae17c287" +checksum = "32e4febb48ea24ef35489174dc76f449f7d12dadbe22b970ab70250d024405e2" dependencies = [ "async-trait", "bytes", @@ -1643,9 +1653,9 @@ dependencies = [ [[package]] name = "fuels-test-helpers" -version = "0.43.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3b0f1475beb61ad66163dc57234170b7319aacf79d9147a28c7ff43cc6fd8f0" +checksum = "823d2016fbfe3efbc2e16f1f40f5bda85922e1207f00be50579036ed3a8639d9" dependencies = [ "fuel-core", "fuel-core-chain-config", @@ -1885,9 +1895,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" [[package]] name = "hex" @@ -1990,15 +2000,14 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.24.1" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97" +checksum = "0646026eb1b3eea4cd9ba47912ea5ce9cc07713d105b1a14698f4e6433d348b7" dependencies = [ - "futures-util", "http", "hyper", "log", - "rustls 0.21.3", + "rustls 0.21.2", "rustls-native-certs 0.6.3", "tokio", "tokio-rustls 0.24.1", @@ -2155,12 +2164,12 @@ checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" [[package]] name = "is-terminal" -version = "0.4.9" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" dependencies = [ "hermit-abi", - "rustix 0.38.3", + "rustix 0.38.2", "windows-sys", ] @@ -2427,6 +2436,12 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "paste" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4b27ab7be369122c218afc2079489cdcb4b517c0a3fc386ff11e1fedfcc2b35" + [[package]] name = "pbkdf2" version = "0.11.0" @@ -2706,21 +2721,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89089e897c013b3deb627116ae56a6955a72b8bed395c9526af31c9fe528b484" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.3.0" +version = "1.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa250384981ea14565685dea16a9ccc4d1c541a13f82b9c168572264d1df8c56" +checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" dependencies = [ "aho-corasick", "memchr", @@ -2729,9 +2732,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.3" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846" +checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" [[package]] name = "reqwest" @@ -2750,7 +2753,7 @@ dependencies = [ "http", "http-body", "hyper", - "hyper-rustls 0.24.1", + "hyper-rustls 0.24.0", "ipnet", "js-sys", "log", @@ -2758,7 +2761,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.21.3", + "rustls 0.21.2", "rustls-pemfile", "serde", "serde_json", @@ -2831,9 +2834,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.23" +version = "0.37.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" +checksum = "8818fa822adcc98b18fedbb3632a6a33213c070556b5aa7c4c8cc21cff565c4c" dependencies = [ "bitflags 1.3.2", "errno", @@ -2845,9 +2848,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.3" +version = "0.38.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac5ffa1efe7548069688cd7028f32591853cd7b5b756d41bcffd2353e4fc75b4" +checksum = "aabcb0461ebd01d6b79945797c27f8529082226cb630a9865a71870ff63532a4" dependencies = [ "bitflags 2.3.3", "errno", @@ -2871,13 +2874,13 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19faa85ecb5197342b54f987b142fb3e30d0c90da40f80ef4fa9a726e6676ed" +checksum = "e32ca28af694bc1bbf399c33a516dbdf1c90090b8ab23c2bc24f834aa2247f5f" dependencies = [ "log", "ring", - "rustls-webpki 0.101.1", + "rustls-webpki", "sct 0.7.0", ] @@ -2924,16 +2927,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "rustls-webpki" -version = "0.101.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f36a6828982f422756984e47912a7a51dcbc2a197aa791158f8ca61cd8204e" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "rustversion" version = "1.0.13" @@ -3095,9 +3088,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.100" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c" +checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" dependencies = [ "itoa", "ryu", @@ -3349,7 +3342,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall", - "rustix 0.37.23", + "rustix 0.37.22", "windows-sys", ] @@ -3511,7 +3504,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.3", + "rustls 0.21.2", "tokio", ] @@ -3549,9 +3542,9 @@ checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" [[package]] name = "toml_edit" -version = "0.19.12" +version = "0.19.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c500344a19072298cd05a7224b3c0c629348b78692bf48466c5238656e315a78" +checksum = "266f016b7f039eec8a1a80dfe6156b633d208b9fccca5e4db1d6775b0c4e34a7" dependencies = [ "indexmap 2.0.0", "toml_datetime", @@ -3888,7 +3881,7 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" dependencies = [ - "rustls-webpki 0.100.1", + "rustls-webpki", ] [[package]] @@ -4001,9 +3994,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.4.8" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9482fe6ceabdf32f3966bfdd350ba69256a97c30253dc616fe0005af24f164e" +checksum = "ca0ace3845f0d96209f0375e6d367e3eb87eb65d27d445bdc9f1843a26f39448" dependencies = [ "memchr", ] diff --git a/test/src/sdk-harness/Cargo.toml b/test/src/sdk-harness/Cargo.toml index cc925cc2f9d..7446dde6397 100644 --- a/test/src/sdk-harness/Cargo.toml +++ b/test/src/sdk-harness/Cargo.toml @@ -8,10 +8,10 @@ publish = false [dependencies] assert_matches = "1.5.0" -fuel-core = { version = "0.18.2", default-features = false } -fuel-core-client = { version = "0.18.2", default-features = false } -fuel-vm = "0.31.2" -fuels = { version = "0.43", features = ["fuel-core-lib"] } +fuel-core = { version = "0.19.1", default-features = false } +fuel-core-client = { version = "0.19.1", default-features = false } +fuel-vm = "0.34.1" +fuels = { version = "0.44", features = ["fuel-core-lib"] } hex = "0.4.3" rand = "0.8" sha2 = "0.10" 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 5e36411862d..60ff33a6b81 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 @@ -24,7 +24,7 @@ async fn setup() -> (Vec, Address, WalletUnlocked, u64, AssetId) { ..Config::local_node() }; let predicate_address = - fuel_tx::Input::predicate_owner(&predicate_code, &config.chain_conf.transaction_parameters); + fuel_tx::Input::predicate_owner(&predicate_code, &config.chain_conf.transaction_parameters.chain_id); let wallets = launch_custom_provider_and_get_wallets(WalletsConfig::default(), Some(config), None).await; @@ -84,7 +84,7 @@ async fn submit_to_predicate( asset_id: AssetId, receiver_address: Address, predicate_data: UnresolvedBytes, -) { +) -> Result<()> { let filter = ResourceFilter { from: predicate_address.into(), asset_id, @@ -111,20 +111,23 @@ async fn submit_to_predicate( total_amount_in_predicate += coin.amount(); } - let output_coin = Output::coin(receiver_address, total_amount_in_predicate, asset_id); + let output_coin = Output::coin(receiver_address, total_amount_in_predicate - 1, asset_id); let output_change = Output::change(predicate_address, 0, asset_id); let params = wallet.provider().unwrap().consensus_parameters(); - let new_tx = ScriptTransactionBuilder::prepare_transfer( + + + let mut new_tx = ScriptTransactionBuilder::prepare_transfer( inputs, vec![output_coin, output_change], - TxParameters::default().set_gas_limit(1_000_000), + TxParameters::default().set_gas_price(1).set_gas_limit(1_000_000), ) .set_consensus_parameters(params) .build() .unwrap(); + new_tx.estimate_predicates(¶ms).unwrap(); - let _call_result = wallet.provider().unwrap().send_transaction(&new_tx).await; + wallet.provider().unwrap().send_transaction(&new_tx).await.map(|_| ()) } async fn get_balance(wallet: &Wallet, address: Address, asset_id: AssetId) -> u64 { @@ -161,11 +164,12 @@ async fn valid_predicate_data_simple() { receiver_address, predicate_data, ) - .await; + .await + .expect("Failed to submit to predicate"); let receiver_balance_after = get_balance(&wallet, receiver_address, asset_id).await; assert_eq!( - receiver_balance_before + amount_to_predicate, + receiver_balance_before + amount_to_predicate - 1, receiver_balance_after ); @@ -198,7 +202,8 @@ async fn invalid_predicate_data_simple() { receiver_address, predicate_data, ) - .await; + .await + .expect_err("Submitting to predicate should have failed"); let receiver_balance_after = get_balance(&wallet, receiver_address, asset_id).await; assert_eq!(receiver_balance_before, receiver_balance_after); 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 59fd889447f..486eed80530 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 @@ -24,7 +24,7 @@ async fn setup() -> (Vec, Address, WalletUnlocked, u64, AssetId) { ..Config::local_node() }; let predicate_address = - fuel_tx::Input::predicate_owner(&predicate_code, &config.chain_conf.transaction_parameters); + fuel_tx::Input::predicate_owner(&predicate_code, &config.chain_conf.transaction_parameters.chain_id); let wallets = launch_custom_provider_and_get_wallets(WalletsConfig::default(), Some(config), None).await; @@ -114,7 +114,7 @@ async fn submit_to_predicate( let output_change = Output::change(predicate_address, 0, asset_id); let params = wallet.provider().unwrap().consensus_parameters(); - let new_tx = ScriptTransactionBuilder::prepare_transfer( + let mut new_tx = ScriptTransactionBuilder::prepare_transfer( inputs, vec![output_coin, output_change], TxParameters::default().set_gas_limit(1_000_000), @@ -122,6 +122,7 @@ async fn submit_to_predicate( .set_consensus_parameters(params) .build() .unwrap(); + new_tx.estimate_predicates(¶ms).unwrap(); let _call_result = wallet.provider().unwrap().send_transaction(&new_tx).await; } 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 c04adbb6aca..54e37cb3714 100644 --- a/test/src/sdk-harness/test_projects/script_data/mod.rs +++ b/test/src/sdk-harness/test_projects/script_data/mod.rs @@ -8,8 +8,17 @@ use fuels::{ async fn call_script(script_data: Vec) -> Result> { let wallet = launch_provider_and_get_wallet().await; + let wallet_coins = wallet + .get_asset_inputs_for_amount( + AssetId::default(), + wallet.get_asset_balance(&AssetId::default()).await.unwrap(), + None, + ) + .await + .unwrap(); + let mut tx = - ScriptTransactionBuilder::prepare_transfer(vec![], vec![], TxParameters::default()) + ScriptTransactionBuilder::prepare_transfer(wallet_coins, vec![], TxParameters::default()) .set_script(std::fs::read( "test_projects/script_data/out/debug/script_data.bin", )?) 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 95aa29b6f2b..acd603b4455 100644 --- a/test/src/sdk-harness/test_projects/tx_fields/mod.rs +++ b/test/src/sdk-harness/test_projects/tx_fields/mod.rs @@ -5,8 +5,12 @@ use fuel_vm::fuel_tx::{ use fuels::{ accounts::{predicate::Predicate, wallet::WalletUnlocked, Account}, prelude::*, - types::Bits256, + types::{ + Bits256, + }, }; +use fuel_core_client::client::types::primitives::ChainId; + use std::str::FromStr; const MESSAGE_DATA: [u8; 3] = [1u8, 2u8, 3u8]; @@ -114,17 +118,20 @@ async fn generate_predicate_inputs( AssetId::from(predicate_coin.asset_id.clone()), TxPointer::default(), 0u32.into(), + 0, predicate_code.clone(), vec![], ); - let predicate_address: Address = predicate.address().into(); + let message = &wallet.get_messages().await.unwrap()[0]; + let predicate_address: Address = predicate.address().into(); let predicate_message = TxInput::message_coin_predicate( message.sender.clone().into(), predicate_address.clone().into(), message.amount, message.nonce.clone(), + 0, predicate_code.clone(), vec![], ); @@ -298,6 +305,7 @@ mod tx { let mut tx = handler.build_tx().await.unwrap(); add_message_input(&mut tx, wallet.clone()).await; + tx.precompute(*ChainId::default()).unwrap(); let inputs = tx.inputs(); @@ -358,7 +366,7 @@ mod tx { .await .unwrap(); - assert_eq!(receipts[1].val().unwrap(), 11032); + assert_eq!(receipts[1].val().unwrap(), 11040); } #[tokio::test] @@ -459,7 +467,7 @@ mod tx { let tx = handler.build_tx().await.unwrap(); let params = wallet.provider().unwrap().consensus_parameters(); - let tx_id = tx.id(¶ms); + let tx_id = tx.id(*params.chain_id); let receipts = wallet .provider() @@ -577,6 +585,8 @@ mod inputs { let mut tx = handler.build_tx().await.unwrap(); tx.tx.inputs_mut().push(predicate_coin); + tx.precompute(*ChainId::default()).unwrap(); + tx.estimate_predicates(&wallet.provider().unwrap().consensus_parameters()).unwrap(); let receipts = wallet .provider() @@ -597,6 +607,7 @@ mod inputs { let handler = contract_instance.methods().get_input_message_sender(2); let mut tx = handler.build_tx().await.unwrap(); add_message_input(&mut tx, wallet.clone()).await; // let result = contract_instance + tx.precompute(*ChainId::default())?; let messages = wallet.get_messages().await?; let receipts = wallet @@ -616,6 +627,7 @@ mod inputs { let handler = contract_instance.methods().get_input_message_recipient(2); let mut tx = handler.build_tx().await.unwrap(); add_message_input(&mut tx, wallet.clone()).await; + tx.precompute(*ChainId::default())?; let messages = wallet.get_messages().await?; let receipts = wallet @@ -634,6 +646,7 @@ mod inputs { let handler = contract_instance.methods().get_input_message_nonce(2); let mut tx = handler.build_tx().await.unwrap(); add_message_input(&mut tx, wallet.clone()).await; + tx.precompute(*ChainId::default())?; let messages = wallet.get_messages().await?; let receipts = wallet @@ -667,6 +680,7 @@ mod inputs { let handler = contract_instance.methods().get_input_message_data_length(2); let mut tx = handler.build_tx().await.unwrap(); add_message_input(&mut tx, wallet.clone()).await; + tx.precompute(*ChainId::default()).unwrap(); let receipts = wallet .provider() @@ -686,6 +700,8 @@ mod inputs { let handler = contract_instance.methods().get_input_predicate_length(2); let mut tx = handler.build_tx().await.unwrap(); tx.tx.inputs_mut().push(predicate_message); + tx.precompute(*ChainId::default()).unwrap(); + tx.estimate_predicates(&wallet.provider().unwrap().consensus_parameters()).unwrap(); let receipts = wallet .provider() @@ -706,6 +722,8 @@ mod inputs { .get_input_predicate_data_length(1); let mut tx = handler.build_tx().await.unwrap(); tx.tx.inputs_mut().push(predicate_message); + tx.precompute(*ChainId::default()).unwrap(); + tx.estimate_predicates(&wallet.provider().unwrap().consensus_parameters()).unwrap(); let receipts = wallet .provider() @@ -726,6 +744,7 @@ mod inputs { .get_input_message_data(2, 0, MESSAGE_DATA); let mut tx = handler.build_tx().await.unwrap(); add_message_input(&mut tx, wallet.clone()).await; + tx.precompute(*ChainId::default()).unwrap(); let receipts = wallet .provider() @@ -748,7 +767,9 @@ mod inputs { .get_input_predicate(2, predicate_bytes.clone()); let mut tx = handler.build_tx().await.unwrap(); - tx.tx.inputs_mut().push(predicate_message); + tx.tx.inputs_mut().push(predicate_message); + tx.precompute(*ChainId::default()).unwrap(); + tx.estimate_predicates(&wallet.provider().unwrap().consensus_parameters()).unwrap(); let receipts = wallet .provider()