From 247fec538218ec495c7baa53a078bbe515158400 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 5 Dec 2024 16:49:32 +0100 Subject: [PATCH] Migrate code to `pallet-revive` Remove `LimitParamsV1` + `pallet-contracts` Use RISC-V target in CI Use latest `polkadot-sdk` `master` Use `H256` instead of `E::Hash` Remove generic from `ToAddr` and `FromAddr` Remove support for `no_implicit_prelude` Remove `Determinism` --- .github/riscv64emac-unknown-none-polkavm.json | 26 + .github/rust-info/action.yml | 2 + .github/workflows/ci.yml | 82 +- ARCHITECTURE.md | 2 +- Cargo.lock | 1972 ++++++++++------- Cargo.toml | 43 +- crates/allocator/src/bump.rs | 74 +- crates/e2e/Cargo.toml | 15 +- crates/e2e/macro/src/codegen.rs | 2 +- crates/e2e/sandbox/Cargo.toml | 7 +- crates/e2e/sandbox/src/api.rs | 4 +- crates/e2e/sandbox/src/api/balance_api.rs | 8 +- .../api/{contracts_api.rs => revive_api.rs} | 261 ++- crates/e2e/sandbox/src/lib.rs | 36 +- crates/e2e/sandbox/src/macros.rs | 59 +- .../e2e/sandbox/test-resources/dummy.polkavm | Bin 0 -> 846 bytes crates/e2e/sandbox/test-resources/dummy.wat | 25 - crates/e2e/src/backend.rs | 40 +- crates/e2e/src/backend_calls.rs | 80 +- crates/e2e/src/builders.rs | 4 +- crates/e2e/src/client_utils.rs | 12 +- crates/e2e/src/contract_build.rs | 9 +- crates/e2e/src/contract_results.rs | 200 +- crates/e2e/src/error.rs | 10 - crates/e2e/src/events.rs | 42 +- crates/e2e/src/lib.rs | 31 +- crates/e2e/src/node_proc.rs | 6 +- crates/e2e/src/sandbox_client.rs | 257 ++- crates/e2e/src/subxt_client.rs | 172 +- crates/e2e/src/xts.rs | 166 +- crates/engine/Cargo.toml | 2 - crates/engine/src/database.rs | 96 +- crates/engine/src/exec_context.rs | 29 +- crates/engine/src/ext.rs | 50 +- crates/engine/src/lib.rs | 5 +- crates/engine/src/test_api.rs | 131 +- crates/engine/src/tests.rs | 40 +- crates/engine/src/types.rs | 47 +- crates/env/Cargo.toml | 16 +- crates/env/src/api.rs | 65 +- crates/env/src/backend.rs | 40 +- crates/env/src/call/call_builder/call.rs | 21 +- crates/env/src/call/call_builder/delegate.rs | 38 +- crates/env/src/call/call_builder/mod.rs | 39 +- crates/env/src/call/create_builder.rs | 213 +- crates/env/src/call/mod.rs | 2 +- crates/env/src/engine/mod.rs | 33 +- crates/env/src/engine/off_chain/impls.rs | 55 +- crates/env/src/engine/off_chain/mod.rs | 8 +- crates/env/src/engine/off_chain/test_api.rs | 164 +- crates/env/src/engine/off_chain/tests.rs | 65 +- crates/env/src/engine/off_chain/types.rs | 3 + crates/env/src/engine/on_chain/impls/mod.rs | 5 - .../engine/on_chain/impls/pallet_contracts.rs | 782 ------- crates/env/src/engine/on_chain/mod.rs | 2 +- .../on_chain/{impls => }/pallet_revive.rs | 164 +- crates/env/src/lib.rs | 10 +- crates/env/src/types.rs | 103 +- crates/ink/Cargo.toml | 12 +- crates/ink/codegen/Cargo.toml | 1 - .../generator/as_dependency/call_builder.rs | 33 +- .../generator/as_dependency/contract_ref.rs | 25 +- crates/ink/codegen/src/generator/dispatch.rs | 39 +- crates/ink/codegen/src/generator/env.rs | 1 + .../ink/codegen/src/generator/storage_item.rs | 2 +- .../src/generator/trait_def/call_builder.rs | 72 +- .../src/generator/trait_def/call_forwarder.rs | 49 +- .../src/generator/trait_def/definition.rs | 4 +- .../generator/trait_def/message_builder.rs | 2 +- .../codegen/src/generator/trait_def/mod.rs | 2 +- .../src/generator/trait_def/trait_registry.rs | 2 +- crates/ink/ir/src/ir/item_impl/callable.rs | 6 +- crates/ink/ir/src/ir/utils.rs | 2 +- crates/ink/macro/Cargo.toml | 6 - crates/ink/macro/src/event/mod.rs | 1 + crates/ink/macro/src/lib.rs | 6 +- crates/ink/src/codegen/dispatch/execution.rs | 8 +- crates/ink/src/contract_ref.rs | 47 +- crates/ink/src/env_access.rs | 175 +- crates/ink/src/lib.rs | 5 +- crates/ink/src/message_builder.rs | 10 +- crates/ink/src/reflect/dispatch.rs | 3 +- crates/ink/tests/return_type_metadata.rs | 2 + .../tests/ui/chain_extension/E-01-simple.rs | 1 + .../constructor-return-result-invalid.stderr | 4 +- ...uctor-return-result-non-codec-error.stderr | 4 +- .../ui/contract/pass/config-custom-env.rs | 1 + ...onstructor-return-result-cross-contract.rs | 8 +- .../ink/tests/ui/contract/pass/env-access.rs | 2 - .../contract/pass/event-config-more-topics.rs | 1 + .../ui/contract/pass/example-erc20-works.rs | 33 +- .../ui/contract/pass/example-erc721-works.rs | 79 +- .../ui/contract/pass/no-implicit-prelude.rs | 29 - .../fail/message_input_non_codec.stderr | 4 - .../ui/trait_def/pass/no-implicit-prelude.rs | 11 - crates/metadata/src/specs.rs | 1 + crates/metadata/src/utils.rs | 2 +- crates/primitives/Cargo.toml | 8 +- crates/primitives/src/lib.rs | 3 + crates/primitives/src/types.rs | 24 + crates/storage/Cargo.toml | 2 - crates/storage/traits/src/layout/impls.rs | 7 +- .../internal/call-builder-return-value/lib.rs | 13 +- .../internal/e2e-runtime-only-backend/lib.rs | 4 +- .../lang-err/call-builder-delegate/lib.rs | 4 +- .../internal/lang-err/call-builder/lib.rs | 32 +- .../lang-err/constructors-return-value/lib.rs | 10 +- .../internal/lang-err/contract-ref/lib.rs | 4 +- integration-tests/internal/mother/lib.rs | 5 +- .../internal/storage-types/lib.rs | 2 +- .../public/call-runtime/Cargo.toml | 4 +- .../public/call-runtime/README.md | 6 +- .../public/conditional-compilation/lib.rs | 4 +- .../public/contract-terminate/lib.rs | 2 +- .../public/contract-transfer/lib.rs | 57 +- .../public/contract-xcm/Cargo.toml | 4 +- .../public/cross-contract-calls/lib.rs | 6 +- .../public/custom-environment/README.md | 6 +- .../public/custom-environment/lib.rs | 2 +- integration-tests/public/dns/lib.rs | 6 +- integration-tests/public/erc20/lib.rs | 64 +- integration-tests/public/flipper/Cargo.toml | 1 - integration-tests/public/flipper/lib.rs | 7 +- .../public/multi-contract-caller/lib.rs | 6 +- integration-tests/public/multisig/lib.rs | 6 +- .../public/payment-channel/lib.rs | 6 +- .../public/psp22-extension/README.md | 4 +- .../runtime/psp22-extension-example.rs | 24 +- .../public/rand-extension/README.md | 4 +- .../runtime/chain-extension-example.rs | 2 +- .../public/runtime-call-contract/Cargo.toml | 11 +- .../public/runtime-call-contract/e2e_tests.rs | 13 +- .../sandbox-runtime/Cargo.toml | 4 +- .../pallet-contract-caller/src/executor.rs | 59 - .../Cargo.toml | 6 +- .../pallet-revive-caller/src/executor.rs | 74 + .../src/lib.rs | 32 +- .../sandbox-runtime/src/lib.rs | 4 +- integration-tests/public/static-buffer/lib.rs | 2 +- .../trait-dyn-cross-contract-calls/lib.rs | 2 +- integration-tests/public/trait-flipper/lib.rs | 10 +- .../delegator/delegatee/lib.rs | 3 +- .../delegator/delegatee2/lib.rs | 3 +- .../upgradeable-contracts/delegator/lib.rs | 18 +- .../set-code-hash-migration/lib.rs | 2 +- .../set-code-hash-migration/migration/lib.rs | 2 +- .../updated-incrementer/lib.rs | 2 +- .../set-code-hash/lib.rs | 2 +- .../set-code-hash/updated-incrementer/lib.rs | 2 +- .../public/wildcard-selector/lib.rs | 4 +- linting/extra/Cargo.toml | 5 - 151 files changed, 3555 insertions(+), 3614 deletions(-) create mode 100644 .github/riscv64emac-unknown-none-polkavm.json rename crates/e2e/sandbox/src/api/{contracts_api.rs => revive_api.rs} (55%) create mode 100644 crates/e2e/sandbox/test-resources/dummy.polkavm delete mode 100644 crates/e2e/sandbox/test-resources/dummy.wat delete mode 100644 crates/env/src/engine/on_chain/impls/mod.rs delete mode 100644 crates/env/src/engine/on_chain/impls/pallet_contracts.rs rename crates/env/src/engine/on_chain/{impls => }/pallet_revive.rs (85%) delete mode 100644 crates/ink/tests/ui/contract/pass/no-implicit-prelude.rs delete mode 100644 crates/ink/tests/ui/trait_def/pass/no-implicit-prelude.rs delete mode 100644 integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/executor.rs rename integration-tests/public/runtime-call-contract/sandbox-runtime/{pallet-contract-caller => pallet-revive-caller}/Cargo.toml (88%) create mode 100644 integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/executor.rs rename integration-tests/public/runtime-call-contract/sandbox-runtime/{pallet-contract-caller => pallet-revive-caller}/src/lib.rs (58%) diff --git a/.github/riscv64emac-unknown-none-polkavm.json b/.github/riscv64emac-unknown-none-polkavm.json new file mode 100644 index 00000000000..7e9c482ca08 --- /dev/null +++ b/.github/riscv64emac-unknown-none-polkavm.json @@ -0,0 +1,26 @@ +{ + "arch": "riscv64", + "cpu": "generic-rv64", + "crt-objects-fallback": "false", + "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S64", + "eh-frame-header": false, + "emit-debug-gdb-scripts": false, + "features": "+e,+m,+a,+c,+auipc-addi-fusion,+ld-add-fusion,+lui-addi-fusion,+xtheadcondmov", + "linker": "rust-lld", + "linker-flavor": "ld.lld", + "llvm-abiname": "lp64e", + "llvm-target": "riscv64", + "max-atomic-width": 64, + "panic-strategy": "abort", + "relocation-model": "pie", + "target-pointer-width": "64", + "singlethread": true, + "pre-link-args": { + "ld": [ + "--emit-relocs", + "--unique", + "--relocatable" + ] + }, + "env": "polkavm" +} diff --git a/.github/rust-info/action.yml b/.github/rust-info/action.yml index b66a1f4e028..09bd7a9c420 100644 --- a/.github/rust-info/action.yml +++ b/.github/rust-info/action.yml @@ -11,5 +11,7 @@ runs: cargo spellcheck --version bash --version substrate-contracts-node --version + + cargo install --git https://github.com/paritytech/cargo-contract --locked --branch cmichi-remove-wasm-default-to-revive --force cargo-contract --version shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c5e67be727..11981f536fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,11 +26,12 @@ on: - 'FILE_HEADER' env: + # Image can be edited at https://github.com/use-ink/docker-images IMAGE: useink/ci CARGO_TARGET_DIR: /ci-cache/${{ github.repository }}/targets/${{ github.ref_name }}/${{ github.job }} CARGO_INCREMENTAL: 0 PURELY_STD_CRATES: ink/codegen metadata engine e2e e2e/macro ink/ir - ALSO_WASM_CRATES: env storage storage/traits allocator prelude primitives ink ink/macro + ALSO_RISCV_CRATES: env storage storage/traits allocator prelude primitives ink ink/macro # TODO `cargo clippy --all-targets --all-features` for this crate # currently fails on `stable`, but succeeds on `nightly`. This is due to # this fix not yet in stable: https://github.com/rust-lang/rust-clippy/issues/8895. @@ -40,8 +41,8 @@ env: # RISC-V does not have a standard library in contrast to Wasm. Compiling against # this target also makes sure that we don't pull in `std` by accident (through dependencies). # RISC-V is a modular architecture. We might switch to a different flavor with more features - # later. For example, `riscv32imc-unknown-none-elf`. - RISCV_TARGET: riscv32ema-unknown-none-elf + # later. For example, `riscv64imc-unknown-none-elf`. + RISCV_TARGET: .github/riscv64emac-unknown-none-polkavm.json concurrency: # Cancel in-progress jobs triggered only on pull_requests @@ -84,6 +85,7 @@ jobs: cargo spellcheck check -v --cfg=.config/cargo_spellcheck.toml --checkers hunspell --code 1 -- recursive ./integration-tests/* fmt: + if: false runs-on: ubuntu-latest defaults: run: @@ -138,16 +140,17 @@ jobs: - name: Run Clippy run: | - ALL_CRATES="${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}" + ALL_CRATES="${PURELY_STD_CRATES} ${ALSO_RISCV_CRATES}" for crate in ${ALL_CRATES}; do cargo clippy --all-targets --all-features --manifest-path ./crates/${crate}/Cargo.toml \ -- -D warnings -A ${CLIPPY_ALLOWED}; done - - name: Run Clippy for WASM Crates + - name: Run Clippy for RISC-V Crates run: | - for crate in ${ALSO_WASM_CRATES}; do - cargo clippy --no-default-features --manifest-path ./crates/${crate}/Cargo.toml --target wasm32-unknown-unknown \ + for crate in ${ALSO_RISCV_CRATES}; do + cargo clippy --no-default-features --manifest-path ./crates/${crate}/Cargo.toml \ + --target ${RISCV_TARGET} \ -- -D warnings -A ${CLIPPY_ALLOWED}; done @@ -162,7 +165,7 @@ jobs: strategy: fail-fast: false matrix: - type: [STD, WASM] + type: [STD, RISCV] steps: - name: Checkout uses: actions/checkout@v4 @@ -183,11 +186,12 @@ jobs: scripts/for_all_contracts_exec.sh --path integration-tests -- cargo clippy --all-targets \ --manifest-path {} -- -D warnings -A $CLIPPY_ALLOWED - - name: Run Clippy for WASM Examples - if: ${{ matrix.type == 'WASM' }} + - name: Run Clippy for RISC-V Examples + if: ${{ matrix.type == 'RISCV' }} run: | scripts/for_all_contracts_exec.sh --path integration-tests -- cargo clippy --no-default-features \ - --target wasm32-unknown-unknown --manifest-path {} -- -D warnings -A $CLIPPY_ALLOWED + --target ${RISCV_TARGET} \ + --manifest-path {} -- -D warnings -A $CLIPPY_ALLOWED check: runs-on: ubuntu-latest @@ -200,7 +204,7 @@ jobs: strategy: fail-fast: false matrix: - type: [STD, WASM, RISCV] + type: [STD, RISCV] steps: - name: Checkout uses: actions/checkout@v4 @@ -218,26 +222,17 @@ jobs: - name: Check if: ${{ matrix.type == 'STD' }} run: | - ALL_CRATES="${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}" + ALL_CRATES="${PURELY_STD_CRATES} ${ALSO_RISCV_CRATES}" for crate in ${ALL_CRATES}; do cargo check --all-features --manifest-path ./crates/${crate}/Cargo.toml; done - - name: Check WASM - if: ${{ matrix.type == 'WASM' }} - run: | - for crate in ${ALSO_WASM_CRATES}; do - cargo check --no-default-features --target wasm32-unknown-unknown \ - --manifest-path ./crates/${crate}/Cargo.toml; - done - - name: Check RISCV - if: ${{ matrix.type == 'RISCV-disabled' }} + if: ${{ matrix.type == 'RISCV' }} env: RUSTC_BOOTSTRAP: 1 - RUSTUP_TOOLCHAIN: rve-nightly run: | - for crate in ${ALSO_WASM_CRATES}; do + for crate in ${ALSO_RISCV_CRATES}; do cargo check --no-default-features --target $RISCV_TARGET -Zbuild-std="core,alloc" \ --manifest-path ./crates/${crate}/Cargo.toml; done @@ -291,7 +286,7 @@ jobs: strategy: fail-fast: false matrix: - type: [STD, WASM] + type: [STD, RISCV] steps: - name: Checkout uses: actions/checkout@v4 @@ -309,16 +304,17 @@ jobs: - name: Build if: ${{ matrix.type == 'STD' }} run: | - ALL_CRATES="${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}" + ALL_CRATES="${PURELY_STD_CRATES} ${ALSO_RISCV_CRATES}" for crate in ${ALL_CRATES}; do cargo build --all-features --release --manifest-path ./crates/${crate}/Cargo.toml; done - name: Build WASM - if: ${{ matrix.type == 'WASM' }} + if: ${{ matrix.type == 'RISCV' }} run: | for crate in ${ALSO_WASM_CRATES}; do - cargo build --no-default-features --release --target wasm32-unknown-unknown \ + cargo build --no-default-features --release + --target RISCV_TARGET \ --manifest-path ./crates/${crate}/Cargo.toml; done @@ -571,15 +567,8 @@ jobs: strategy: fail-fast: false matrix: - type: [WASM, RISCV] + type: [RISCV] partition: [1, 2, 3, 4] - exclude: - - type: RISCV - partition: 2 - - type: RISCV - partition: 3 - - type: RISCV - partition: 4 steps: - name: Checkout uses: actions/checkout@v4 @@ -594,27 +583,10 @@ jobs: - name: Rust Info uses: ./.github/rust-info - - name: Build Contract WASM Examples - if: ${{ matrix.type == 'WASM' }} - run: | - rustup component add rust-src --toolchain stable - cargo contract -V - # Build all examples - scripts/for_all_contracts_exec.sh --path integration-tests --partition ${{ matrix.partition }}/4 -- cargo contract build --release --manifest-path {} - if [ ${{ matrix.partition }} -eq 4 ]; then - # Build the different features for the conditional compilation example - pushd ./integration-tests/public/conditional-compilation - cargo contract build --release --features "foo" - cargo contract build --release --features "bar" - cargo contract build --release --features "foo, bar" - popd - fi - - name: Build Contract RISCV Examples - if: ${{ matrix.type == 'RISCV-disabled' }} + if: ${{ matrix.type == 'RISCV' }} env: RUSTC_BOOTSTRAP: 1 - RUSTUP_TOOLCHAIN: rve-nightly run: | rustup component add rust-src --toolchain stable cargo contract -V @@ -702,7 +674,7 @@ jobs: run: | # We fuzz-test only crates which possess the `ink-fuzz-tests` feature all_tests_passed=0 - ALL_CRATES="${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}" + ALL_CRATES="${PURELY_STD_CRATES} ${ALSO_RISCV_CRATES}" for crate in ${ALL_CRATES}; do if grep "ink-fuzz-tests =" ./crates/${crate}/Cargo.toml; then diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index b0f6ee0909f..fb70ef07147 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -154,7 +154,7 @@ If you look at the implementations you'll see a common pattern of ### The pallet API Signatures of host API functions are defined in -[`pallet-contracts-uapi`](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/contracts/uapi/src/host/wasm32.rs). +[`pallet-revive-uapi`](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/revive/uapi/src/host/riscv64.rs). You'll see that we import different versions of API functions, something like the following excerpt: diff --git a/Cargo.lock b/Cargo.lock index bf151590890..22b27228aba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -173,9 +173,21 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb00293ba84f51ce3bd026bd0de55899c4e68f0a39a5728cebae3a73ffdc0a4f" dependencies = [ - "ark-ec", - "ark-ff", - "ark-std", + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-std 0.4.0", +] + +[[package]] +name = "ark-bls12-377-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20c7021f180a0cbea0380eba97c2af3c57074cdaffe0eef7e840e1c9f2841e55" +dependencies = [ + "ark-bls12-377", + "ark-ec 0.4.2", + "ark-models-ext", + "ark-std 0.4.0", ] [[package]] @@ -184,10 +196,49 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c775f0d12169cba7aae4caeb547bb6a50781c7449a8aa53793827c9ec4abf488" dependencies = [ - "ark-ec", - "ark-ff", - "ark-serialize", - "ark-std", + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", +] + +[[package]] +name = "ark-bls12-381-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1dc4b3d08f19e8ec06e949712f95b8361e43f1391d94f65e4234df03480631c" +dependencies = [ + "ark-bls12-381", + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-models-ext", + "ark-serialize 0.4.2", + "ark-std 0.4.0", +] + +[[package]] +name = "ark-bw6-761" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e0605daf0cc5aa2034b78d008aaf159f56901d92a52ee4f6ecdfdac4f426700" +dependencies = [ + "ark-bls12-377", + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-std 0.4.0", +] + +[[package]] +name = "ark-bw6-761-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccee5fba47266f460067588ee1bf070a9c760bf2050c1c509982c5719aadb4f2" +dependencies = [ + "ark-bw6-761", + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-models-ext", + "ark-std 0.4.0", ] [[package]] @@ -196,34 +247,126 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" dependencies = [ - "ark-ff", - "ark-poly", - "ark-serialize", - "ark-std", + "ark-ff 0.4.2", + "ark-poly 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", "derivative", "hashbrown 0.13.2", "itertools 0.10.5", "num-traits", + "rayon", + "zeroize", +] + +[[package]] +name = "ark-ec" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d68f2d516162846c1238e755a7c4d131b892b70cc70c471a8e3ca3ed818fce" +dependencies = [ + "ahash", + "ark-ff 0.5.0", + "ark-poly 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe", + "fnv", + "hashbrown 0.15.2", + "itertools 0.13.0", + "num-bigint", + "num-integer", + "num-traits", "zeroize", ] +[[package]] +name = "ark-ed-on-bls12-377" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b10d901b9ac4b38f9c32beacedfadcdd64e46f8d7f8e88c1ae1060022cf6f6c6" +dependencies = [ + "ark-bls12-377", + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-std 0.4.0", +] + +[[package]] +name = "ark-ed-on-bls12-377-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524a4fb7540df2e1a8c2e67a83ba1d1e6c3947f4f9342cc2359fc2e789ad731d" +dependencies = [ + "ark-ec 0.4.2", + "ark-ed-on-bls12-377", + "ark-ff 0.4.2", + "ark-models-ext", + "ark-std 0.4.0", +] + +[[package]] +name = "ark-ed-on-bls12-381-bandersnatch" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9cde0f2aa063a2a5c28d39b47761aa102bda7c13c84fc118a61b87c7b2f785c" +dependencies = [ + "ark-bls12-381", + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-std 0.4.0", +] + +[[package]] +name = "ark-ed-on-bls12-381-bandersnatch-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d15185f1acb49a07ff8cbe5f11a1adc5a93b19e211e325d826ae98e98e124346" +dependencies = [ + "ark-ec 0.4.2", + "ark-ed-on-bls12-381-bandersnatch", + "ark-ff 0.4.2", + "ark-models-ext", + "ark-std 0.4.0", +] + [[package]] name = "ark-ff" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" dependencies = [ - "ark-ff-asm", - "ark-ff-macros", - "ark-serialize", - "ark-std", + "ark-ff-asm 0.4.2", + "ark-ff-macros 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", "derivative", "digest 0.10.7", "itertools 0.10.5", "num-bigint", "num-traits", "paste", - "rustc_version 0.4.1", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a177aba0ed1e0fbb62aa9f6d0502e9b46dad8c2eab04c14258a1212d2557ea70" +dependencies = [ + "ark-ff-asm 0.5.0", + "ark-ff-macros 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "arrayvec 0.7.6", + "digest 0.10.7", + "educe", + "itertools 0.13.0", + "num-bigint", + "num-traits", + "paste", "zeroize", ] @@ -237,6 +380,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ark-ff-asm" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62945a2f7e6de02a31fe400aa489f0e0f5b2502e69f95f853adb82a96c7a6b60" +dependencies = [ + "quote", + "syn 2.0.90", +] + [[package]] name = "ark-ff-macros" version = "0.4.2" @@ -250,27 +403,110 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ark-ff-macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09be120733ee33f7693ceaa202ca41accd5653b779563608f1234f78ae07c4b3" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 2.0.90", +] + +[[package]] +name = "ark-models-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e9eab5d4b5ff2f228b763d38442adc9b084b0a465409b059fac5c2308835ec2" +dependencies = [ + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "derivative", +] + [[package]] name = "ark-poly" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" dependencies = [ - "ark-ff", - "ark-serialize", - "ark-std", + "ark-ff 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", "derivative", "hashbrown 0.13.2", ] +[[package]] +name = "ark-poly" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579305839da207f02b89cd1679e50e67b4331e2f9294a57693e5051b7703fe27" +dependencies = [ + "ahash", + "ark-ff 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe", + "fnv", + "hashbrown 0.15.2", +] + +[[package]] +name = "ark-scale" +version = "0.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f69c00b3b529be29528a6f2fd5fa7b1790f8bed81b9cdca17e326538545a179" +dependencies = [ + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "ark-secret-scalar" +version = "0.0.2" +source = "git+https://github.com/w3f/ring-vrf?rev=0fef826#0fef8266d851932ad25d6b41bc4b34d834d1e11d" +dependencies = [ + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "ark-transcript", + "digest 0.10.7", + "getrandom_or_panic", + "zeroize", +] + [[package]] name = "ark-serialize" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" dependencies = [ - "ark-serialize-derive", - "ark-std", + "ark-serialize-derive 0.4.2", + "ark-std 0.4.0", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-serialize" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f4d068aaf107ebcd7dfb52bc748f8030e0fc930ac8e360146ca54c1203088f7" +dependencies = [ + "ark-serialize-derive 0.5.0", + "ark-std 0.5.0", + "arrayvec 0.7.6", "digest 0.10.7", "num-bigint", ] @@ -286,6 +522,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ark-serialize-derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213888f660fddcca0d257e88e54ac05bca01885f258ccdf695bafd77031bb69d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "ark-std" version = "0.4.0" @@ -294,6 +541,30 @@ checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" dependencies = [ "num-traits", "rand", + "rayon", +] + +[[package]] +name = "ark-std" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246a225cc6131e9ee4f24619af0f19d67761fff15d7ccc22e42b80846e69449a" +dependencies = [ + "num-traits", + "rand", +] + +[[package]] +name = "ark-transcript" +version = "0.0.2" +source = "git+https://github.com/w3f/ring-vrf?rev=0fef826#0fef8266d851932ad25d6b41bc4b34d834d1e11d" +dependencies = [ + "ark-ff 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "digest 0.10.7", + "rand_core", + "sha3", ] [[package]] @@ -493,6 +764,27 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "bandersnatch_vrfs" +version = "0.0.4" +source = "git+https://github.com/w3f/ring-vrf?rev=0fef826#0fef8266d851932ad25d6b41bc4b34d834d1e11d" +dependencies = [ + "ark-bls12-381", + "ark-ec 0.4.2", + "ark-ed-on-bls12-381-bandersnatch", + "ark-ff 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "dleq_vrf", + "rand_chacha", + "rand_core", + "ring 0.1.0", + "sha2 0.10.8", + "sp-ark-bls12-381", + "sp-ark-ed-on-bls12-381-bandersnatch", + "zeroize", +] + [[package]] name = "base16ct" version = "0.2.0" @@ -523,6 +815,32 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "binary-merkle-tree" +version = "13.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" +dependencies = [ + "hash-db", + "log", + "parity-scale-codec", +] + +[[package]] +name = "bip32" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa13fae8b6255872fd86f7faf4b41168661d7d78609f7bfe6771b85c6739a15b" +dependencies = [ + "bs58", + "hmac 0.12.1", + "k256", + "rand_core", + "ripemd", + "sha2 0.10.8", + "subtle", + "zeroize", +] + [[package]] name = "bip39" version = "2.1.0" @@ -677,7 +995,7 @@ dependencies = [ "serde_json", "serde_repr", "serde_urlencoded", - "thiserror 2.0.4", + "thiserror 2.0.8", "tokio", "tokio-util", "tower-service", @@ -714,6 +1032,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" dependencies = [ + "sha2 0.10.8", "tinyvec", ] @@ -773,17 +1092,17 @@ checksum = "8769706aad5d996120af43197bf46ef6ad0fda35216b4505f926a365a232d924" dependencies = [ "camino", "cargo-platform", - "semver 1.0.23", + "semver", "serde", "serde_json", - "thiserror 2.0.4", + "thiserror 2.0.8", ] [[package]] name = "cc" -version = "1.2.2" +version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" +checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf" dependencies = [ "jobserver", "libc", @@ -824,9 +1143,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" dependencies = [ "android-tzdata", "iana-time-zone", @@ -848,9 +1167,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.22" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69371e34337c4c984bbe322360c2547210bf632eb2814bbe78a6e87a2935bd2b" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" dependencies = [ "clap_builder", "clap_derive", @@ -858,9 +1177,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.22" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e24c1b4099818523236a8ca881d2b45db98dadfb4625cf6608c12069fcbbde1" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" dependencies = [ "anstream", "anstyle", @@ -882,9 +1201,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "codespan-reporting" @@ -893,7 +1212,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" dependencies = [ "termcolor", - "unicode-width 0.1.14", + "unicode-width", ] [[package]] @@ -904,12 +1223,12 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "colored" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -922,6 +1241,22 @@ dependencies = [ "memchr", ] +[[package]] +name = "common" +version = "0.1.0" +source = "git+https://github.com/w3f/ring-proof?rev=665f5f5#665f5f51af5734c7b6d90b985dd6861d4c5b4752" +dependencies = [ + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-poly 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "fflonk", + "getrandom_or_panic", + "merlin", + "rand_chacha", +] + [[package]] name = "common-path" version = "1.0.0" @@ -1004,8 +1339,7 @@ checksum = "cd7e35aee659887cbfb97aaf227ac12cad1a9d7c71e55ff3376839ed4e282d08" [[package]] name = "contract-build" version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "857769855bf40d230e41baf6575cc44bd5e6869f69f88f45f6791da793f49a0c" +source = "git+https://github.com/use-ink/cargo-contract?branch=cmichi-remove-wasm-default-to-revive#a5b6c364c39a10929ca3d530a606f5d69940a5aa" dependencies = [ "anyhow", "blake2", @@ -1018,11 +1352,12 @@ dependencies = [ "duct", "heck 0.5.0", "hex", - "impl-serde 0.5.0", + "impl-serde", "parity-scale-codec", + "polkavm-linker 0.17.1", "regex", - "rustc_version 0.4.1", - "semver 1.0.23", + "rustc_version", + "semver", "serde", "serde_json", "strum 0.26.3", @@ -1035,9 +1370,8 @@ dependencies = [ "url", "uzers", "walkdir", - "wasm-encoder 0.220.0", "wasm-opt", - "wasmparser 0.220.0", + "wasmparser", "which", "zip", ] @@ -1045,12 +1379,11 @@ dependencies = [ [[package]] name = "contract-metadata" version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "733a6624ea05dd71050641c3cd9baff7a1445032a0082f0e55c800c078716424" +source = "git+https://github.com/use-ink/cargo-contract?branch=cmichi-remove-wasm-default-to-revive#a5b6c364c39a10929ca3d530a606f5d69940a5aa" dependencies = [ "anyhow", - "impl-serde 0.5.0", - "semver 1.0.23", + "impl-serde", + "semver", "serde", "serde_json", "url", @@ -1096,20 +1429,39 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-queue" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crossterm" @@ -1201,7 +1553,7 @@ dependencies = [ "curve25519-dalek-derive", "digest 0.10.7", "fiat-crypto", - "rustc_version 0.4.1", + "rustc_version", "subtle", "zeroize", ] @@ -1219,9 +1571,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.133" +version = "1.0.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e1ec88093d2abd9cf1b09ffd979136b8e922bf31cad966a8fe0d73233112ef" +checksum = "4d44ff199ff93242c3afe480ab588d544dd08d72e92885e152ffebc670f076ad" dependencies = [ "cc", "cxxbridge-cmd", @@ -1233,9 +1585,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.133" +version = "1.0.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9afa390d956ee7ccb41aeed7ed7856ab3ffb4fc587e7216be7e0f83e949b4e6c" +checksum = "66fd8f17ad454fc1e4f4ab83abffcc88a532e90350d3ffddcb73030220fcbd52" dependencies = [ "cc", "codespan-reporting", @@ -1247,9 +1599,9 @@ dependencies = [ [[package]] name = "cxxbridge-cmd" -version = "1.0.133" +version = "1.0.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c23bfff654d6227cbc83de8e059d2f8678ede5fc3a6c5a35d5c379983cc61e6" +checksum = "4717c9c806a9e07fdcb34c84965a414ea40fafe57667187052cf1eb7f5e8a8a9" dependencies = [ "clap", "codespan-reporting", @@ -1260,15 +1612,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.133" +version = "1.0.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c01b36e22051bc6928a78583f1621abaaf7621561c2ada1b00f7878fbe2caa" +checksum = "2f6515329bf3d98f4073101c7866ff2bec4e635a13acb82e3f3753fff0bf43cb" [[package]] name = "cxxbridge-macro" -version = "1.0.133" +version = "1.0.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6e14013136fac689345d17b9a6df55977251f11d333c0a571e8d963b55e1f95" +checksum = "fb93e6a7ce8ec985c02bbb758237a31598b340acbbc3c19c5a4fa6adaaac92ab" dependencies = [ "proc-macro2", "quote", @@ -1384,7 +1736,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.4.1", + "rustc_version", "syn 2.0.90", ] @@ -1436,6 +1788,27 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -1453,6 +1826,22 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59f8e79d1fbf76bdfbde321e902714bf6c49df88a7dda6fc682fc2979226962d" +[[package]] +name = "dleq_vrf" +version = "0.0.2" +source = "git+https://github.com/w3f/ring-vrf?rev=0fef826#0fef8266d851932ad25d6b41bc4b34d834d1e11d" +dependencies = [ + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-scale", + "ark-secret-scalar", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "ark-transcript", + "arrayvec 0.7.6", + "zeroize", +] + [[package]] name = "docify" version = "0.2.9" @@ -1579,6 +1968,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "educe" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7bc049e1bd8cdeb31b68bbd586a9464ecf9f3944af3958a7a9d0f8b9799417" +dependencies = [ + "enum-ordinalize", + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "either" version = "1.13.0" @@ -1605,6 +2006,26 @@ dependencies = [ "zeroize", ] +[[package]] +name = "enum-ordinalize" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "env_logger" version = "0.8.4" @@ -1637,6 +2058,37 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "ethbloom" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c321610643004cf908ec0f5f2aa0d8f1f8e14b540562a2887a1111ff1ecbf7b" +dependencies = [ + "crunchy", + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "scale-info", + "tiny-keccak", +] + +[[package]] +name = "ethereum-types" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ab15ed80916029f878e0267c3a9f92b67df55e79af370bf66199059ae2b4ee3" +dependencies = [ + "ethbloom", + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "primitive-types", + "scale-info", + "uint", +] + [[package]] name = "event-listener" version = "5.3.1" @@ -1673,11 +2125,17 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + [[package]] name = "fastrand" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "ff" @@ -1689,6 +2147,19 @@ dependencies = [ "subtle", ] +[[package]] +name = "fflonk" +version = "0.1.1" +source = "git+https://github.com/w3f/fflonk#eda051ea3b80042e844a3ebd17c2f60536e6ee3f" +dependencies = [ + "ark-ec 0.5.0", + "ark-ff 0.5.0", + "ark-poly 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "merlin", +] + [[package]] name = "fiat-crypto" version = "0.2.9" @@ -1740,9 +2211,8 @@ dependencies = [ [[package]] name = "frame-benchmarking" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01bdd47c2d541b38bd892da647d1e972c9d85b4ecd7094ad64f7600175da54d" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-support", "frame-support-procedural", @@ -1758,8 +2228,8 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-runtime-interface", - "sp-storage", + "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "static_assertions", ] @@ -1774,14 +2244,13 @@ dependencies = [ "scale-decode", "scale-info", "scale-type-resolver", - "sp-crypto-hashing", + "sp-crypto-hashing 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "frame-election-provider-solution-type" -version = "14.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8156f209055d352994ecd49e19658c6b469d7c6de923bd79868957d0dcfb6f71" +version = "13.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1791,9 +2260,8 @@ dependencies = [ [[package]] name = "frame-election-provider-support" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c36f5116192c63d39f1b4556fa30ac7db5a6a52575fa241b045f7dfa82ecc2be" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -1808,9 +2276,9 @@ dependencies = [ [[package]] name = "frame-metadata" -version = "16.0.0" +version = "17.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cf1549fba25a6fcac22785b61698317d958e96cac72a59102ea45b9ae64692" +checksum = "701bac17e9b55e0f95067c428ebcb46496587f08e8cf4ccc0fe5903bea10dbb8" dependencies = [ "cfg-if", "parity-scale-codec", @@ -1820,9 +2288,9 @@ dependencies = [ [[package]] name = "frame-metadata" -version = "17.0.0" +version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "701bac17e9b55e0f95067c428ebcb46496587f08e8cf4ccc0fe5903bea10dbb8" +checksum = "daaf440c68eb2c3d88e5760fe8c7af3f9fee9181fab6c2f2c4e7cc48dcc40bb8" dependencies = [ "cfg-if", "parity-scale-codec", @@ -1832,16 +2300,16 @@ dependencies = [ [[package]] name = "frame-support" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e44af69fa61bc5005ffe0339e198957e77f0f255704a9bee720da18a733e3dc" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "aquamarine", "array-bytes", + "binary-merkle-tree", "bitflags 1.3.2", "docify", "environmental", - "frame-metadata 16.0.0", + "frame-metadata 18.0.0", "frame-support-procedural", "impl-trait-for-tuples", "k256", @@ -1857,7 +2325,7 @@ dependencies = [ "sp-arithmetic", "sp-core", "sp-crypto-hashing-proc-macro", - "sp-debug-derive", + "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-genesis-builder", "sp-inherents", "sp-io", @@ -1865,8 +2333,9 @@ dependencies = [ "sp-runtime", "sp-staking", "sp-state-machine", - "sp-std", - "sp-tracing", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-trie", "sp-weights", "static_assertions", "tt-call", @@ -1874,13 +2343,13 @@ dependencies = [ [[package]] name = "frame-support-procedural" -version = "30.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e8f9b6bc1517a6fcbf0b2377e5c8c6d39f5bb7862b191a59a9992081d63972d" +version = "23.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "Inflector", "cfg-expr", "derive-syn-parse", + "docify", "expander", "frame-support-procedural-tools", "itertools 0.11.0", @@ -1888,15 +2357,14 @@ dependencies = [ "proc-macro-warning", "proc-macro2", "quote", - "sp-crypto-hashing", + "sp-crypto-hashing 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "syn 2.0.90", ] [[package]] name = "frame-support-procedural-tools" -version = "13.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bead15a320be1764cdd50458c4cfacb23e0cee65f64f500f8e34136a94c7eeca" +version = "10.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -1907,9 +2375,8 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" -version = "12.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed971c6435503a099bdac99fe4c5bea08981709e5b5a0a8535a1856f48561191" +version = "11.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "proc-macro2", "quote", @@ -1918,9 +2385,8 @@ dependencies = [ [[package]] name = "frame-system" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c7fa02f8c305496d2ae52edaecdb9d165f11afa965e05686d7d7dd1ce93611" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "cfg-if", "docify", @@ -1932,7 +2398,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-version", "sp-weights", ] @@ -2098,6 +2564,10 @@ name = "gimli" version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +dependencies = [ + "fallible-iterator", + "stable_deref_trait", +] [[package]] name = "glob" @@ -2251,11 +2721,11 @@ dependencies = [ [[package]] name = "home" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2306,9 +2776,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97818827ef4f364230e16705d4706e2897df2bb60617d6ca15d598025a3c481f" +checksum = "256fb8d4bd6413123cc9d91832d78325c48ff41677595be797d90f42969beae0" dependencies = [ "bytes", "futures-channel", @@ -2543,29 +3013,31 @@ dependencies = [ [[package]] name = "impl-codec" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +checksum = "b67aa010c1e3da95bf151bd8b4c059b2ed7e75387cdb969b4f8f2723a43f9941" dependencies = [ "parity-scale-codec", ] [[package]] -name = "impl-codec" -version = "0.7.0" +name = "impl-num-traits" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67aa010c1e3da95bf151bd8b4c059b2ed7e75387cdb969b4f8f2723a43f9941" +checksum = "803d15461ab0dcc56706adf266158acbc44ccf719bf7d0af30705f58b90a4b8c" dependencies = [ - "parity-scale-codec", + "integer-sqrt", + "num-traits", + "uint", ] [[package]] -name = "impl-serde" +name = "impl-rlp" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" +checksum = "54ed8ad1f3877f7e775b8cbf30ed1bd3209a95401817f19a0eb4402d13f8cf90" dependencies = [ - "serde", + "rlp", ] [[package]] @@ -2647,10 +3119,9 @@ dependencies = [ "ink_prelude", "ink_primitives", "ink_storage", - "pallet-contracts-uapi", "pallet-revive-uapi", "parity-scale-codec", - "polkavm-derive 0.17.1", + "polkavm-derive", "scale-info", "sp-io", "staging-xcm", @@ -2674,12 +3145,12 @@ dependencies = [ "derive_more 1.0.0", "either", "heck 0.5.0", - "impl-serde 0.5.0", + "impl-serde", "ink_ir", "ink_primitives", "itertools 0.13.0", "parity-scale-codec", - "polkavm-derive 0.17.1", + "polkavm-derive", "proc-macro2", "quote", "serde", @@ -2695,15 +3166,15 @@ dependencies = [ "contract-build", "frame-support", "funty", - "impl-serde 0.5.0", + "impl-serde", "ink", "ink_e2e_macro", "ink_env", "ink_primitives", "ink_sandbox", "jsonrpsee", - "pallet-contracts", - "pallet-contracts-mock-network", + "pallet-revive", + "pallet-revive-mock-network", "parity-scale-codec", "regex", "scale-info", @@ -2716,11 +3187,10 @@ dependencies = [ "subxt", "subxt-metadata", "subxt-signer", - "thiserror 2.0.4", + "thiserror 2.0.8", "tokio", "tracing", "tracing-subscriber", - "wasm-instrument", "which", ] @@ -2748,7 +3218,6 @@ dependencies = [ "blake2", "derive_more 1.0.0", "ink_primitives", - "pallet-contracts-uapi", "pallet-revive-uapi", "parity-scale-codec", "secp256k1 0.30.0", @@ -2771,12 +3240,10 @@ dependencies = [ "ink_primitives", "ink_storage_traits", "num-traits", - "pallet-contracts-uapi", "pallet-revive-uapi", "parity-scale-codec", "paste", - "polkavm-derive 0.17.1", - "rlibc", + "polkavm-derive", "scale-decode", "scale-encode", "scale-info", @@ -2785,6 +3252,7 @@ dependencies = [ "sha2 0.10.8", "sha3", "sp-io", + "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "staging-xcm", "static_assertions", ] @@ -2795,7 +3263,7 @@ version = "5.1.0" dependencies = [ "blake2", "either", - "impl-serde 0.5.0", + "impl-serde", "ink_prelude", "itertools 0.13.0", "proc-macro2", @@ -2828,7 +3296,7 @@ name = "ink_metadata" version = "5.1.0" dependencies = [ "derive_more 1.0.0", - "impl-serde 0.5.0", + "impl-serde", "ink_prelude", "ink_primitives", "linkme", @@ -2854,9 +3322,11 @@ dependencies = [ "derive_more 1.0.0", "ink_prelude", "parity-scale-codec", + "primitive-types", "scale-decode", "scale-encode", "scale-info", + "serde", "xxhash-rust", ] @@ -2864,19 +3334,20 @@ dependencies = [ name = "ink_sandbox" version = "5.1.0" dependencies = [ - "frame-metadata 16.0.0", + "frame-metadata 18.0.0", "frame-support", "frame-system", + "ink_primitives", "pallet-balances", - "pallet-contracts", + "pallet-revive", "pallet-timestamp", "parity-scale-codec", "paste", "scale-info", + "sha3", "sp-core", - "sp-externalities", + "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-io", - "wat", ] [[package]] @@ -2893,7 +3364,6 @@ dependencies = [ "ink_primitives", "ink_storage_traits", "itertools 0.13.0", - "pallet-contracts-uapi", "pallet-revive-uapi", "parity-scale-codec", "quickcheck", @@ -3001,9 +3471,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.74" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a865e038f7f6ed956f788f0d7d60c541fff74c7bd74272c5d4cf15c63743e705" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" dependencies = [ "once_cell", "wasm-bindgen", @@ -3055,7 +3525,7 @@ dependencies = [ "futures-util", "jsonrpsee-types", "pin-project", - "rustc-hash", + "rustc-hash 2.1.0", "serde", "serde_json", "thiserror 1.0.69", @@ -3118,7 +3588,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e1b8590eb6148af2ea2d75f38e7d29f5ca970d5a4df456b3ef19b8b415d0264" dependencies = [ - "primitive-types 0.13.1", + "primitive-types", "tiny-keccak", ] @@ -3128,17 +3598,11 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - [[package]] name = "libc" -version = "0.2.167" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "libm" @@ -3146,6 +3610,16 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.6.0", + "libc", +] + [[package]] name = "libsecp256k1" version = "0.7.1" @@ -3371,9 +3845,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.8.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" dependencies = [ "adler2", ] @@ -3555,6 +4029,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "os_pipe" version = "1.2.1" @@ -3573,9 +4053,8 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "pallet-asset-conversion" -version = "20.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33f0078659ae95efe6a1bf138ab5250bc41ab98f22ff3651d0208684f08ae797" +version = "10.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-benchmarking", "frame-support", @@ -3592,9 +4071,8 @@ dependencies = [ [[package]] name = "pallet-assets" -version = "40.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f45f4eb6027fc34c4650e0ed6a7e57ed3335cc364be74b4531f714237676bcee" +version = "29.1.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-benchmarking", "frame-support", @@ -3609,9 +4087,8 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb0208f0538d58dcb78ce1ff5e6e8641c5f37b23b20b05587e51da30ab13541" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-support", "frame-system", @@ -3625,9 +4102,8 @@ dependencies = [ [[package]] name = "pallet-authorship" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "625d47577cabbe1318ccec5d612e2379002d1b6af1ab6edcef3243c66ec246df" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-support", "frame-system", @@ -3639,9 +4115,8 @@ dependencies = [ [[package]] name = "pallet-babe" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ee096c0def13832475b340d00121025e0225de29604d44bc6dfcaa294c995b4" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-benchmarking", "frame-support", @@ -3663,9 +4138,8 @@ dependencies = [ [[package]] name = "pallet-balances" -version = "39.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6945b078919acb14d126490e4b0973a688568b30142476ca69c6df2bed27ad" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "docify", "frame-benchmarking", @@ -3679,9 +4153,8 @@ dependencies = [ [[package]] name = "pallet-broker" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3043c90106d88cb93fcf0d9b6d19418f11f44cc2b11873414aec3b46044a24ea" +version = "0.6.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "bitvec", "frame-benchmarking", @@ -3697,180 +4170,144 @@ dependencies = [ ] [[package]] -name = "pallet-contracts" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5df77077745d891c822b4275f273f336077a97e69e62a30134776aa721c96fee" +name = "pallet-message-queue" +version = "31.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ - "bitflags 1.3.2", "environmental", "frame-benchmarking", "frame-support", "frame-system", - "impl-trait-for-tuples", "log", - "pallet-balances", - "pallet-contracts-proc-macro", - "pallet-contracts-uapi", "parity-scale-codec", - "paste", - "rand", "scale-info", - "serde", - "smallvec", - "sp-api", + "sp-arithmetic", "sp-core", "sp-io", "sp-runtime", - "sp-std", - "staging-xcm", - "staging-xcm-builder", - "wasm-instrument", - "wasmi", + "sp-weights", ] [[package]] -name = "pallet-contracts-mock-network" -version = "14.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "309666537ed001c61a99f59fa7b98680f4a6e4e361ed3bc64f7b0237da3e3e06" +name = "pallet-mmr" +version = "27.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", - "pallet-assets", - "pallet-balances", - "pallet-contracts", - "pallet-contracts-proc-macro", - "pallet-contracts-uapi", - "pallet-insecure-randomness-collective-flip", - "pallet-message-queue", - "pallet-proxy", - "pallet-timestamp", - "pallet-utility", - "pallet-xcm", + "log", "parity-scale-codec", - "polkadot-parachain-primitives", - "polkadot-primitives", - "polkadot-runtime-parachains", "scale-info", - "sp-api", "sp-core", "sp-io", - "sp-keystore", - "sp-runtime", - "sp-tracing", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", - "xcm-simulator", -] - -[[package]] -name = "pallet-contracts-proc-macro" -version = "23.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94226cbd48516b7c310eb5dae8d50798c1ce73a7421dc0977c55b7fc2237a283" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.90", -] - -[[package]] -name = "pallet-contracts-uapi" -version = "12.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f74b000590c33fadea48585d3ae3f4b7867e99f0a524c444d5779f36b9a1b6" -dependencies = [ - "bitflags 1.3.2", - "parity-scale-codec", - "paste", - "polkavm-derive 0.9.1", - "scale-info", -] - -[[package]] -name = "pallet-insecure-randomness-collective-flip" -version = "26.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce7ad80675d78bd38a7a66ecbbf2d218dd32955e97f8e301d0afe6c87b0f251" -dependencies = [ - "frame-support", - "frame-system", - "parity-scale-codec", - "safe-mix", - "scale-info", + "sp-mmr-primitives", "sp-runtime", ] [[package]] -name = "pallet-message-queue" -version = "41.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "983f7d1be18e9a089a3e23670918f5085705b4403acd3fdde31878d57b76a1a8" +name = "pallet-revive" +version = "0.1.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ + "derive_more 0.99.18", "environmental", + "ethereum-types", "frame-benchmarking", "frame-support", "frame-system", + "hex", + "impl-trait-for-tuples", "log", + "pallet-revive-fixtures", + "pallet-revive-proc-macro", + "pallet-revive-uapi", + "pallet-transaction-payment", "parity-scale-codec", + "paste", + "polkavm", + "rlp", "scale-info", + "serde", + "sp-api", "sp-arithmetic", "sp-core", "sp-io", "sp-runtime", - "sp-weights", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "staging-xcm", + "staging-xcm-builder", + "subxt-signer", ] [[package]] -name = "pallet-mmr" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6932dfb85f77a57c2d1fdc28a7b3a59ffe23efd8d5bb02dc3039d91347e4a3b" +name = "pallet-revive-fixtures" +version = "0.1.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "log", - "parity-scale-codec", - "scale-info", + "anyhow", + "polkavm-linker 0.18.0", "sp-core", "sp-io", - "sp-mmr-primitives", - "sp-runtime", + "toml", ] [[package]] -name = "pallet-proxy" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d39df395f0dbcf07dafe842916adea3266a87ce36ed87b5132184b6bcd746393" +name = "pallet-revive-mock-network" +version = "0.1.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", + "pallet-assets", + "pallet-balances", + "pallet-message-queue", + "pallet-revive", + "pallet-revive-uapi", + "pallet-timestamp", + "pallet-xcm", "parity-scale-codec", + "polkadot-parachain-primitives", + "polkadot-primitives", + "polkadot-runtime-parachains", "scale-info", + "sp-core", "sp-io", "sp-runtime", + "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "xcm-simulator", +] + +[[package]] +name = "pallet-revive-proc-macro" +version = "0.1.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", ] [[package]] name = "pallet-revive-uapi" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2412-rc2#a86fb861573b31fb35db97d6ffe3eb4ff4a80359" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "bitflags 1.3.2", + "pallet-revive-proc-macro", + "parity-scale-codec", "paste", - "polkavm-derive 0.14.0", + "polkavm-derive", + "scale-info", ] [[package]] name = "pallet-session" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8474b62b6b7622f891e83d922a589e2ad5be5471f5ca47d45831a797dba0b3f4" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-support", "frame-system", @@ -3890,9 +4327,8 @@ dependencies = [ [[package]] name = "pallet-staking" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c870d123f4f053b56af808a4beae1ffc4309a696e829796c26837936c926db3b" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -3912,9 +4348,8 @@ dependencies = [ [[package]] name = "pallet-timestamp" -version = "37.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9ba9b71bbfd33ae672f23ba7efaeed2755fdac37b8f946cb7474fc37841b7e1" +version = "27.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "docify", "frame-benchmarking", @@ -3926,37 +4361,21 @@ dependencies = [ "sp-inherents", "sp-io", "sp-runtime", - "sp-storage", + "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-timestamp", ] [[package]] name = "pallet-transaction-payment" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b1aa3498107a30237f941b0f02180db3b79012c3488878ff01a4ac3e8ee04e" -dependencies = [ - "frame-support", - "frame-system", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core", - "sp-io", - "sp-runtime", -] - -[[package]] -name = "pallet-utility" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fdcade6efc0b66fc7fc4138964802c02d0ffb7380d894e26b9dd5073727d2b3" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", "scale-info", + "serde", "sp-core", "sp-io", "sp-runtime", @@ -3964,9 +4383,8 @@ dependencies = [ [[package]] name = "pallet-vesting" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "807df2ef13ab6bf940879352c3013bfa00b670458b4c125c2f60e5753f68e3d5" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-benchmarking", "frame-support", @@ -3979,15 +4397,13 @@ dependencies = [ [[package]] name = "pallet-xcm" -version = "17.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "989676964dbda5f5275650fbdcd3894fe7fac626d113abf89d572b4952adcc36" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "bounded-collections", "frame-benchmarking", "frame-support", "frame-system", - "log", "pallet-balances", "parity-scale-codec", "scale-info", @@ -4176,9 +4592,8 @@ dependencies = [ [[package]] name = "polkadot-core-primitives" -version = "15.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2900d3b857e34c480101618a950c3a4fbcddc8c0d50573d48553376185908b8" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "parity-scale-codec", "scale-info", @@ -4188,9 +4603,8 @@ dependencies = [ [[package]] name = "polkadot-parachain-primitives" -version = "14.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52b5648a2e8ce1f9a0f8c41c38def670cefd91932cd793468e1a5b0b0b4e4af1" +version = "6.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "bounded-collections", "derive_more 0.99.18", @@ -4205,9 +4619,8 @@ dependencies = [ [[package]] name = "polkadot-primitives" -version = "16.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb20b75d33212150242d39890d7ededab55f1084160c337f15d0eb8ca8c3ad4" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "bitvec", "hex-literal", @@ -4228,26 +4641,26 @@ dependencies = [ "sp-keystore", "sp-runtime", "sp-staking", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "thiserror 1.0.69", ] [[package]] name = "polkadot-runtime-metrics" -version = "17.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c306f1ace7644a24de860479f92cf8d6467393bb0c9b0777c57e2d42c9d452a" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "bs58", "frame-benchmarking", "parity-scale-codec", "polkadot-primitives", - "sp-tracing", + "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", ] [[package]] name = "polkadot-runtime-parachains" -version = "17.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd58e3a17e5df678f5737b018cbfec603af2c93bec56bbb9f8fb8b2b017b54b1" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "bitflags 1.3.2", "bitvec", @@ -4287,7 +4700,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-staking", - "sp-std", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "staging-xcm", "staging-xcm-executor", ] @@ -4298,20 +4711,30 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb819108697967452fa6d8d96ab4c0d48cbaa423b3156499dcb24f1cf95d6775" dependencies = [ - "sp-crypto-hashing", + "sp-crypto-hashing 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "polkavm-common" -version = "0.9.0" +name = "polkavm" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d9428a5cfcc85c5d7b9fc4b6a18c4b802d0173d768182a51cc7751640f08b92" +checksum = "dd044ab1d3b11567ab6b98ca71259a992b4034220d5972988a0e96518e5d343d" +dependencies = [ + "libc", + "log", + "polkavm-assembler", + "polkavm-common 0.18.0", + "polkavm-linux-raw", +] [[package]] -name = "polkavm-common" -version = "0.14.0" +name = "polkavm-assembler" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711952a783e9c5ad407cdacb1ed147f36d37c5d43417c1091d86456d2999417b" +checksum = "eaad38dc420bfed79e6f731471c973ce5ff5e47ab403e63cf40358fef8a6368f" +dependencies = [ + "log", +] [[package]] name = "polkavm-common" @@ -4320,97 +4743,83 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f0dbafef4ab6ceecb4982ac3b550df430ef4f9fdbf07c108b7d4f91a0682fce" [[package]] -name = "polkavm-derive" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8c4bea6f3e11cd89bb18bcdddac10bd9a24015399bd1c485ad68a985a19606" -dependencies = [ - "polkavm-derive-impl-macro 0.9.0", -] - -[[package]] -name = "polkavm-derive" -version = "0.14.0" +name = "polkavm-common" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4832a0aebf6cefc988bb7b2d74ea8c86c983164672e2fc96300f356a1babfc1" +checksum = "31ff33982a807d8567645d4784b9b5d7ab87bcb494f534a57cadd9012688e102" dependencies = [ - "polkavm-derive-impl-macro 0.14.0", + "log", + "polkavm-assembler", ] [[package]] name = "polkavm-derive" -version = "0.17.1" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206caf322dfc02144510ad8360ff2051e5072f0874dcab3b410f78cdd52d0ebb" +checksum = "c2eb703f3b6404c13228402e98a5eae063fd16b8f58afe334073ec105ee4117e" dependencies = [ - "polkavm-derive-impl-macro 0.17.0", + "polkavm-derive-impl-macro", ] [[package]] name = "polkavm-derive-impl" -version = "0.9.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4fdfc49717fb9a196e74a5d28e0bc764eb394a2c803eb11133a31ac996c60c" +checksum = "12d2840cc62a0550156b1676fed8392271ddf2fab4a00661db56231424674624" dependencies = [ - "polkavm-common 0.9.0", + "polkavm-common 0.18.0", "proc-macro2", "quote", "syn 2.0.90", ] [[package]] -name = "polkavm-derive-impl" -version = "0.14.0" +name = "polkavm-derive-impl-macro" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e339fc7c11310fe5adf711d9342278ac44a75c9784947937cce12bd4f30842f2" +checksum = "48c16669ddc7433e34c1007d31080b80901e3e8e523cb9d4b441c3910cf9294b" dependencies = [ - "polkavm-common 0.14.0", - "proc-macro2", - "quote", + "polkavm-derive-impl", "syn 2.0.90", ] [[package]] -name = "polkavm-derive-impl" -version = "0.17.0" +name = "polkavm-linker" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42565aed4adbc4034612d0b17dea8db3681fb1bd1aed040d6edc5455a9f478a1" +checksum = "0422ead3030d5cde69e2206dbc7d65da872b121876507cd5363f6c6e6aa45157" dependencies = [ + "dirs", + "gimli", + "hashbrown 0.14.5", + "log", + "object", "polkavm-common 0.17.0", - "proc-macro2", - "quote", - "syn 2.0.90", -] - -[[package]] -name = "polkavm-derive-impl-macro" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" -dependencies = [ - "polkavm-derive-impl 0.9.0", - "syn 2.0.90", + "regalloc2", + "rustc-demangle", ] [[package]] -name = "polkavm-derive-impl-macro" -version = "0.14.0" +name = "polkavm-linker" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b569754b15060d03000c09e3bf11509d527f60b75d79b4c30c3625b5071d9702" +checksum = "e9bfe793b094d9ea5c99b7c43ba46e277b0f8f48f4bbfdbabf8d3ebf701a4bd3" dependencies = [ - "polkavm-derive-impl 0.14.0", - "syn 2.0.90", + "dirs", + "gimli", + "hashbrown 0.14.5", + "log", + "object", + "polkavm-common 0.18.0", + "regalloc2", + "rustc-demangle", ] [[package]] -name = "polkavm-derive-impl-macro" -version = "0.17.0" +name = "polkavm-linux-raw" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d9838e95241b0bce4fe269cdd4af96464160505840ed5a8ac8536119ba19e2" -dependencies = [ - "polkavm-derive-impl 0.17.0", - "syn 2.0.90", -] +checksum = "23eff02c070c70f31878a3d915e88a914ecf3e153741e2fb572dde28cce20fde" [[package]] name = "polling" @@ -4473,19 +4882,6 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "primitive-types" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" -dependencies = [ - "fixed-hash", - "impl-codec 0.6.0", - "impl-serde 0.4.0", - "scale-info", - "uint 0.9.5", -] - [[package]] name = "primitive-types" version = "0.13.1" @@ -4493,10 +4889,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d15600a7d856470b7d278b3fe0e311fe28c2526348549f8ef2ff7db3299c87f5" dependencies = [ "fixed-hash", - "impl-codec 0.7.0", - "impl-serde 0.5.0", + "impl-codec", + "impl-num-traits", + "impl-rlp", + "impl-serde", "scale-info", - "uint 0.10.0", + "uint", ] [[package]] @@ -4647,15 +5045,46 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redox_syscall" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom", + "libredox", + "thiserror 1.0.69", +] + [[package]] name = "ref-cast" version = "1.0.23" @@ -4676,6 +5105,19 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "regalloc2" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad156d539c879b7a24a363a2016d77961786e71f48f2e2fc8302a92abd2429a6" +dependencies = [ + "hashbrown 0.13.2", + "log", + "rustc-hash 1.1.0", + "slice-group-by", + "smallvec", +] + [[package]] name = "regex" version = "1.11.1" @@ -4730,6 +5172,23 @@ dependencies = [ "subtle", ] +[[package]] +name = "ring" +version = "0.1.0" +source = "git+https://github.com/w3f/ring-proof?rev=665f5f5#665f5f51af5734c7b6d90b985dd6861d4c5b4752" +dependencies = [ + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-poly 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "arrayvec 0.7.6", + "blake2", + "common", + "fflonk", + "merlin", +] + [[package]] name = "ring" version = "0.17.8" @@ -4746,10 +5205,23 @@ dependencies = [ ] [[package]] -name = "rlibc" -version = "1.0.0" +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "rlp" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe" +checksum = "fa24e92bb2a83198bb76d661a71df9f7076b8c420b8696e4d3d97d50d94479e3" +dependencies = [ + "bytes", + "rustc-hex", +] [[package]] name = "rustc-demangle" @@ -4757,6 +5229,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc-hash" version = "2.1.0" @@ -4769,46 +5247,37 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - [[package]] name = "rustc_version" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ - "semver 1.0.23", + "semver", ] [[package]] name = "rustix" -version = "0.38.41" +version = "0.38.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" dependencies = [ "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "rustls" -version = "0.23.19" +version = "0.23.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" +checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b" dependencies = [ "log", "once_cell", - "ring", + "ring 0.17.8", "rustls-pki-types", "rustls-webpki", "subtle", @@ -4839,9 +5308,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" +checksum = "d2bf47e6ff922db3825eb750c4e2ff784c6ff8fb9e13046ef6a1d1c5401b0b37" [[package]] name = "rustls-platform-verifier" @@ -4876,7 +5345,7 @@ version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ - "ring", + "ring 0.17.8", "rustls-pki-types", "untrusted", ] @@ -4903,15 +5372,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "safe-mix" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d3d055a2582e6b00ed7a31c1524040aa391092bf636328350813f3a0605215c" -dependencies = [ - "rustc_version 0.2.3", -] - [[package]] name = "safe_arch" version = "0.7.2" @@ -4959,7 +5419,7 @@ checksum = "f8ae9cc099ae85ff28820210732b00f019546f36f33225f509fe25d5816864a0" dependencies = [ "derive_more 1.0.0", "parity-scale-codec", - "primitive-types 0.13.1", + "primitive-types", "scale-bits", "scale-decode-derive", "scale-type-resolver", @@ -4986,7 +5446,7 @@ checksum = "5f9271284d05d0749c40771c46180ce89905fd95aa72a2a2fddb4b7c0aa424db" dependencies = [ "derive_more 1.0.0", "parity-scale-codec", - "primitive-types 0.13.1", + "primitive-types", "scale-bits", "scale-encode-derive", "scale-type-resolver", @@ -5250,9 +5710,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.12.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" +checksum = "1863fd3768cd83c56a7f60faa4dc0d403f1b6df0a38c3c25f44b7894e45370d5" dependencies = [ "core-foundation-sys", "libc", @@ -5260,33 +5720,18 @@ dependencies = [ [[package]] name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" dependencies = [ "serde", ] -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" dependencies = [ "serde_derive", ] @@ -5302,9 +5747,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" dependencies = [ "proc-macro2", "quote", @@ -5537,6 +5982,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + [[package]] name = "smallvec" version = "1.13.2" @@ -5677,9 +6128,8 @@ dependencies = [ [[package]] name = "sp-api" -version = "34.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbce492e0482134128b7729ea36f5ef1a9f9b4de2d48ff8dde7b5e464e28ce75" +version = "26.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "docify", "hash-db", @@ -5688,10 +6138,10 @@ dependencies = [ "scale-info", "sp-api-proc-macro", "sp-core", - "sp-externalities", + "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-metadata-ir", "sp-runtime", - "sp-runtime-interface", + "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-state-machine", "sp-trie", "sp-version", @@ -5700,9 +6150,8 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" -version = "20.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9aadf9e97e694f0e343978aa632938c5de309cbcc8afed4136cb71596737278" +version = "15.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "Inflector", "blake2", @@ -5715,9 +6164,8 @@ dependencies = [ [[package]] name = "sp-application-crypto" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8133012faa5f75b2f0b1619d9f720c1424ac477152c143e5f7dbde2fe1a958" +version = "30.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "parity-scale-codec", "scale-info", @@ -5728,9 +6176,8 @@ dependencies = [ [[package]] name = "sp-arithmetic" -version = "26.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46d0d0a4c591c421d3231ddd5e27d828618c24456d51445d21a1f79fcee97c23" +version = "23.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "docify", "integer-sqrt", @@ -5738,15 +6185,31 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-std", "static_assertions", ] +[[package]] +name = "sp-ark-bls12-381" +version = "0.4.2" +source = "git+https://github.com/paritytech/arkworks-substrate#caa2eed74beb885dd07c7db5f916f2281dad818f" +dependencies = [ + "ark-bls12-381-ext", + "sp-crypto-ec-utils", +] + +[[package]] +name = "sp-ark-ed-on-bls12-381-bandersnatch" +version = "0.4.2" +source = "git+https://github.com/paritytech/arkworks-substrate#caa2eed74beb885dd07c7db5f916f2281dad818f" +dependencies = [ + "ark-ed-on-bls12-381-bandersnatch-ext", + "sp-crypto-ec-utils", +] + [[package]] name = "sp-authority-discovery" -version = "34.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "519c33af0e25ba2dd2eb3790dc404d634b6e4ce0801bcc8fa3574e07c365e734" +version = "26.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "parity-scale-codec", "scale-info", @@ -5757,9 +6220,8 @@ dependencies = [ [[package]] name = "sp-consensus-babe" -version = "0.40.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36ee95e17ee8dcd14db7d584b899a426565ca9abe5a266ab82277977fc547f86" +version = "0.32.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "async-trait", "parity-scale-codec", @@ -5776,9 +6238,8 @@ dependencies = [ [[package]] name = "sp-consensus-slots" -version = "0.40.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbafb7ed44f51c22fa277fb39b33dc601fa426133a8e2b53f3f46b10f07fba43" +version = "0.32.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "parity-scale-codec", "scale-info", @@ -5788,11 +6249,11 @@ dependencies = [ [[package]] name = "sp-core" -version = "34.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c961a5e33fb2962fa775c044ceba43df9c6f917e2c35d63bfe23738468fa76a7" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "array-bytes", + "bandersnatch_vrfs", "bitflags 1.3.2", "blake2", "bounded-collections", @@ -5802,7 +6263,7 @@ dependencies = [ "futures", "hash-db", "hash256-std-hasher", - "impl-serde 0.4.0", + "impl-serde", "itertools 0.11.0", "k256", "libsecp256k1", @@ -5812,19 +6273,19 @@ dependencies = [ "parity-scale-codec", "parking_lot", "paste", - "primitive-types 0.12.2", + "primitive-types", "rand", "scale-info", "schnorrkel", "secp256k1 0.28.2", "secrecy 0.8.0", "serde", - "sp-crypto-hashing", - "sp-debug-derive", - "sp-externalities", - "sp-runtime-interface", - "sp-std", - "sp-storage", + "sp-crypto-hashing 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "ss58-registry", "substrate-bip39", "thiserror 1.0.69", @@ -5833,6 +6294,26 @@ dependencies = [ "zeroize", ] +[[package]] +name = "sp-crypto-ec-utils" +version = "0.10.0" +source = "git+https://github.com/paritytech/polkadot-sdk#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" +dependencies = [ + "ark-bls12-377", + "ark-bls12-377-ext", + "ark-bls12-381", + "ark-bls12-381-ext", + "ark-bw6-761", + "ark-bw6-761-ext", + "ark-ec 0.4.2", + "ark-ed-on-bls12-377", + "ark-ed-on-bls12-377-ext", + "ark-ed-on-bls12-381-bandersnatch", + "ark-ed-on-bls12-381-bandersnatch-ext", + "ark-scale", + "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk)", +] + [[package]] name = "sp-crypto-hashing" version = "0.1.0" @@ -5847,22 +6328,43 @@ dependencies = [ "twox-hash", ] +[[package]] +name = "sp-crypto-hashing" +version = "0.1.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" +dependencies = [ + "blake2b_simd", + "byteorder", + "digest 0.10.7", + "sha2 0.10.8", + "sha3", + "twox-hash", +] + [[package]] name = "sp-crypto-hashing-proc-macro" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b85d0f1f1e44bd8617eb2a48203ee854981229e3e79e6f468c7175d5fd37489b" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "quote", - "sp-crypto-hashing", + "sp-crypto-hashing 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "syn 2.0.90", ] [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d09fa0a5f7299fb81ee25ae3853d26200f7a348148aed6de76be905c007dbe" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + +[[package]] +name = "sp-debug-derive" +version = "14.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "proc-macro2", "quote", @@ -5871,20 +6373,28 @@ dependencies = [ [[package]] name = "sp-externalities" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a904407d61cb94228c71b55a9d3708e9d6558991f9e83bd42bd91df37a159d30" +version = "0.25.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" +dependencies = [ + "environmental", + "parity-scale-codec", + "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", +] + +[[package]] +name = "sp-externalities" +version = "0.25.0" +source = "git+https://github.com/paritytech/polkadot-sdk#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "environmental", "parity-scale-codec", - "sp-storage", + "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk)", ] [[package]] name = "sp-genesis-builder" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a646ed222fd86d5680faa4a8967980eb32f644cae6c8523e1c689a6deda3e8" +version = "0.8.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "parity-scale-codec", "scale-info", @@ -5895,9 +6405,8 @@ dependencies = [ [[package]] name = "sp-inherents" -version = "34.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afffbddc380d99a90c459ba1554bbbc01d62e892de9f1485af6940b89c4c0d57" +version = "26.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -5909,9 +6418,8 @@ dependencies = [ [[package]] name = "sp-io" -version = "38.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ef7eb561bb4839cc8424ce58c5ea236cbcca83f26fcc0426d8decfe8aa97d4" +version = "30.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "bytes", "docify", @@ -5919,16 +6427,16 @@ dependencies = [ "libsecp256k1", "log", "parity-scale-codec", - "polkavm-derive 0.9.1", + "polkavm-derive", "rustversion", "secp256k1 0.28.2", "sp-core", - "sp-crypto-hashing", - "sp-externalities", + "sp-crypto-hashing 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-keystore", - "sp-runtime-interface", + "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-state-machine", - "sp-tracing", + "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-trie", "tracing", "tracing-core", @@ -5936,9 +6444,8 @@ dependencies = [ [[package]] name = "sp-keyring" -version = "39.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c0e20624277f578b27f44ecfbe2ebc2e908488511ee2c900c5281599f700ab3" +version = "31.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "sp-core", "sp-runtime", @@ -5947,32 +6454,29 @@ dependencies = [ [[package]] name = "sp-keystore" -version = "0.40.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0248b4d784cb4a01472276928977121fa39d977a5bb24793b6b15e64b046df42" +version = "0.34.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "parity-scale-codec", "parking_lot", "sp-core", - "sp-externalities", + "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", ] [[package]] name = "sp-metadata-ir" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a616fa51350b35326682a472ee8e6ba742fdacb18babac38ecd46b3e05ead869" +version = "0.6.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ - "frame-metadata 16.0.0", + "frame-metadata 18.0.0", "parity-scale-codec", "scale-info", ] [[package]] name = "sp-mmr-primitives" -version = "34.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a12dd76e368f1e48144a84b4735218b712f84b3f976970e2f25a29b30440e10" +version = "26.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "log", "parity-scale-codec", @@ -5981,16 +6485,15 @@ dependencies = [ "serde", "sp-api", "sp-core", - "sp-debug-derive", + "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-runtime", "thiserror 1.0.69", ] [[package]] name = "sp-npos-elections" -version = "34.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af922f112c7c1ed199eabe14f12a82ceb75e1adf0804870eccfbcf3399492847" +version = "26.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "parity-scale-codec", "scale-info", @@ -6003,20 +6506,18 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "13.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8f5a17a0a11de029a8b811cb6e8b32ce7e02183cc04a3e965c383246798c416" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "backtrace", - "lazy_static", "regex", ] [[package]] name = "sp-runtime" -version = "39.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658f23be7c79a85581029676a73265c107c5469157e3444c8c640fdbaa8bfed0" +version = "31.0.1" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ + "binary-merkle-tree", "docify", "either", "hash256-std-hasher", @@ -6033,36 +6534,68 @@ dependencies = [ "sp-arithmetic", "sp-core", "sp-io", - "sp-std", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-trie", "sp-weights", "tracing", + "tuplex", ] [[package]] name = "sp-runtime-interface" -version = "28.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "985eb981f40c689c6a0012c937b68ed58dabb4341d06f2dfe4dfd5ed72fa4017" +version = "24.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" +dependencies = [ + "bytes", + "impl-trait-for-tuples", + "parity-scale-codec", + "polkavm-derive", + "primitive-types", + "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-runtime-interface-proc-macro 17.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "sp-wasm-interface 20.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", + "static_assertions", +] + +[[package]] +name = "sp-runtime-interface" +version = "24.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "bytes", "impl-trait-for-tuples", "parity-scale-codec", - "polkavm-derive 0.9.1", - "primitive-types 0.12.2", - "sp-externalities", - "sp-runtime-interface-proc-macro", - "sp-std", - "sp-storage", - "sp-tracing", - "sp-wasm-interface", + "polkavm-derive", + "primitive-types", + "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk)", + "sp-runtime-interface-proc-macro 17.0.0 (git+https://github.com/paritytech/polkadot-sdk)", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", + "sp-storage 19.0.0 (git+https://github.com/paritytech/polkadot-sdk)", + "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk)", + "sp-wasm-interface 20.0.0 (git+https://github.com/paritytech/polkadot-sdk)", "static_assertions", ] [[package]] name = "sp-runtime-interface-proc-macro" -version = "18.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0195f32c628fee3ce1dfbbf2e7e52a30ea85f3589da9fe62a8b816d70fc06294" +version = "17.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" +dependencies = [ + "Inflector", + "expander", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.90", +] + +[[package]] +name = "sp-runtime-interface-proc-macro" +version = "17.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "Inflector", "expander", @@ -6074,9 +6607,8 @@ dependencies = [ [[package]] name = "sp-session" -version = "36.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00a3a307fedc423fb8cd2a7726a3bbb99014f1b4b52f26153993e2aae3338fe6" +version = "27.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "parity-scale-codec", "scale-info", @@ -6089,9 +6621,8 @@ dependencies = [ [[package]] name = "sp-staking" -version = "36.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a73eedb4b85f4cd420d31764827546aa22f82ce1646d0fd258993d051de7a90" +version = "26.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -6103,9 +6634,8 @@ dependencies = [ [[package]] name = "sp-state-machine" -version = "0.43.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "930104d6ae882626e8880d9b1578da9300655d337a3ffb45e130c608b6c89660" +version = "0.35.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "hash-db", "log", @@ -6114,7 +6644,7 @@ dependencies = [ "rand", "smallvec", "sp-core", - "sp-externalities", + "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-panic-handler", "sp-trie", "thiserror 1.0.69", @@ -6125,27 +6655,41 @@ dependencies = [ [[package]] name = "sp-std" version = "14.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f8ee986414b0a9ad741776762f4083cd3a5128449b982a3919c4df36874834" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" + +[[package]] +name = "sp-std" +version = "14.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" [[package]] name = "sp-storage" -version = "21.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99c82989b3a4979a7e1ad848aad9f5d0b4388f1f454cc131766526601ab9e8f8" +version = "19.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" +dependencies = [ + "impl-serde", + "parity-scale-codec", + "ref-cast", + "serde", + "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", +] + +[[package]] +name = "sp-storage" +version = "19.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ - "impl-serde 0.4.0", + "impl-serde", "parity-scale-codec", "ref-cast", "serde", - "sp-debug-derive", + "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", ] [[package]] name = "sp-timestamp" -version = "34.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72a1cb4df653d62ccc0dbce1db45d1c9443ec60247ee9576962d24da4c9c6f07" +version = "26.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "async-trait", "parity-scale-codec", @@ -6156,9 +6700,19 @@ dependencies = [ [[package]] name = "sp-tracing" -version = "17.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf641a1d17268c8fcfdb8e0fa51a79c2d4222f4cfda5f3944dbdbc384dced8d5" +version = "16.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" +dependencies = [ + "parity-scale-codec", + "tracing", + "tracing-core", + "tracing-subscriber", +] + +[[package]] +name = "sp-tracing" +version = "16.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "parity-scale-codec", "tracing", @@ -6168,13 +6722,11 @@ dependencies = [ [[package]] name = "sp-trie" -version = "37.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6282aef9f4b6ecd95a67a45bcdb67a71f4a4155c09a53c10add4ffe823db18cd" +version = "29.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "ahash", "hash-db", - "lazy_static", "memory-db", "nohash-hasher", "parity-scale-codec", @@ -6183,7 +6735,7 @@ dependencies = [ "scale-info", "schnellru", "sp-core", - "sp-externalities", + "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "thiserror 1.0.69", "tracing", "trie-db", @@ -6192,29 +6744,28 @@ dependencies = [ [[package]] name = "sp-version" -version = "37.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d521a405707b5be561367cd3d442ff67588993de24062ce3adefcf8437ee9fe1" +version = "29.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ - "impl-serde 0.4.0", + "impl-serde", "parity-scale-codec", "parity-wasm", "scale-info", "serde", "sp-crypto-hashing-proc-macro", "sp-runtime", - "sp-std", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "sp-version-proc-macro", "thiserror 1.0.69", ] [[package]] name = "sp-version-proc-macro" -version = "14.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aee8f6730641a65fcf0c8f9b1e448af4b3bb083d08058b47528188bccc7b7a7" +version = "13.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "parity-scale-codec", + "proc-macro-warning", "proc-macro2", "quote", "syn 2.0.90", @@ -6222,9 +6773,19 @@ dependencies = [ [[package]] name = "sp-wasm-interface" -version = "21.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b066baa6d57951600b14ffe1243f54c47f9c23dd89c262e17ca00ae8dca58be9" +version = "20.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" +dependencies = [ + "anyhow", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", +] + +[[package]] +name = "sp-wasm-interface" +version = "20.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -6234,9 +6795,8 @@ dependencies = [ [[package]] name = "sp-weights" -version = "31.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93cdaf72a1dad537bbb130ba4d47307ebe5170405280ed1aa31fa712718a400e" +version = "27.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "bounded-collections", "parity-scale-codec", @@ -6244,7 +6804,7 @@ dependencies = [ "serde", "smallvec", "sp-arithmetic", - "sp-debug-derive", + "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", ] [[package]] @@ -6286,14 +6846,15 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "staging-xcm" -version = "14.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96bee7cd999e9cdf10f8db72342070d456e21e82a0f5962ff3b87edbd5f2b20e" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "array-bytes", "bounded-collections", "derivative", "environmental", + "frame-support", + "hex-literal", "impl-trait-for-tuples", "log", "parity-scale-codec", @@ -6306,9 +6867,8 @@ dependencies = [ [[package]] name = "staging-xcm-builder" -version = "17.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3746adbbae27b1e6763f0cca622e15482ebcb94835a9e078c212dd7be896e35" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-support", "frame-system", @@ -6329,9 +6889,8 @@ dependencies = [ [[package]] name = "staging-xcm-executor" -version = "17.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79dd0c5332a5318e58f0300b20768b71cf9427c906f94a743c9dc7c3ee9e7fa9" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "environmental", "frame-benchmarking", @@ -6362,7 +6921,6 @@ checksum = "1c6a0d765f5807e98a091107bae0a56ea3799f66a5de47b2c84c94a39c09974e" dependencies = [ "cfg-if", "hashbrown 0.14.5", - "serde", ] [[package]] @@ -6414,9 +6972,8 @@ dependencies = [ [[package]] name = "substrate-bip39" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca58ffd742f693dc13d69bdbb2e642ae239e0053f6aab3b104252892f856700a" +version = "0.4.7" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "hmac 0.12.1", "pbkdf2", @@ -6443,11 +7000,11 @@ dependencies = [ "frame-metadata 17.0.0", "futures", "hex", - "impl-serde 0.5.0", + "impl-serde", "jsonrpsee", "parity-scale-codec", "polkadot-sdk", - "primitive-types 0.13.1", + "primitive-types", "scale-bits", "scale-decode", "scale-encode", @@ -6498,11 +7055,11 @@ dependencies = [ "frame-metadata 17.0.0", "hashbrown 0.14.5", "hex", - "impl-serde 0.5.0", + "impl-serde", "keccak-hash", "parity-scale-codec", "polkadot-sdk", - "primitive-types 0.13.1", + "primitive-types", "scale-bits", "scale-decode", "scale-encode", @@ -6568,11 +7125,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7a336d6a1f86f126100a4a717be58352de4c8214300c4f7807f974494efdb9" dependencies = [ "base64 0.22.1", + "bip32", "bip39", "cfg-if", "crypto_secretbox", "hex", "hmac 0.12.1", + "keccak-hash", "parity-scale-codec", "pbkdf2", "polkadot-sdk", @@ -6696,11 +7255,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.4" +version = "2.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f49a1853cf82743e3b7950f77e0f4d622ca36cf4317cba00c767838bac8d490" +checksum = "08f5383f3e0071702bf93ab5ee99b52d26936be9dedd9413067cbdcddcb6141a" dependencies = [ - "thiserror-impl 2.0.4", + "thiserror-impl 2.0.8", ] [[package]] @@ -6716,9 +7275,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.4" +version = "2.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8381894bb3efe0c4acac3ded651301ceee58a15d47c2e34885ed1908ad667061" +checksum = "f2f357fcec90b3caef6623a099691be676d033b40a058ac95d2a6ade6fa0c943" dependencies = [ "proc-macro2", "quote", @@ -6829,20 +7388,19 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.26.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37" dependencies = [ "rustls", - "rustls-pki-types", "tokio", ] [[package]] name = "tokio-stream" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" dependencies = [ "futures-core", "pin-project-lite", @@ -7015,6 +7573,12 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4f195fd851901624eee5a58c4bb2b4f06399148fcd0ed336e6f1cb60a9881df" +[[package]] +name = "tuplex" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "676ac81d5454c4dcf37955d34fa8626ede3490f744b86ca14a7b90168d2a08aa" + [[package]] name = "twox-hash" version = "1.6.3" @@ -7033,18 +7597,6 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" -[[package]] -name = "uint" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" -dependencies = [ - "byteorder", - "crunchy", - "hex", - "static_assertions", -] - [[package]] name = "uint" version = "0.10.0" @@ -7078,12 +7630,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" -[[package]] -name = "unicode-width" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" - [[package]] name = "unicode-xid" version = "0.2.6" @@ -7166,10 +7712,10 @@ checksum = "70a3028804c8bbae2a97a15b71ffc0e308c4b01a520994aafa77d56e94e19024" dependencies = [ "ark-bls12-377", "ark-bls12-381", - "ark-ec", - "ark-ff", - "ark-serialize", - "ark-serialize-derive", + "ark-ec 0.4.2", + "ark-ff 0.4.2", + "ark-serialize 0.4.2", + "ark-serialize-derive 0.4.2", "arrayref", "constcat", "digest 0.10.7", @@ -7209,9 +7755,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d15e63b4482863c109d70a7b8706c1e364eb6ea449b201a76c5b89cedcec2d5c" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" dependencies = [ "cfg-if", "once_cell", @@ -7220,13 +7766,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d36ef12e3aaca16ddd3f67922bc63e48e953f126de60bd33ccc0101ef9998cd" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", "syn 2.0.90", @@ -7235,9 +7780,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.47" +version = "0.4.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dfaf8f50e5f293737ee323940c7d8b08a66a95a419223d9f41610ca08b0833d" +checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" dependencies = [ "cfg-if", "js-sys", @@ -7248,9 +7793,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "705440e08b42d3e4b36de7d66c944be628d579796b8090bfa3471478a2260051" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -7258,9 +7803,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c9ae5a76e46f4deecd0f0255cc223cfa18dc9b261213b8aa0c7b36f61b3f1d" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", @@ -7271,38 +7816,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee99da9c5ba11bd675621338ef6fa52296b76b83305e9b6e5c77d4c286d6d49" - -[[package]] -name = "wasm-encoder" -version = "0.220.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebf48234b389415b226a4daef6562933d38c7b28a8b8f64c5c4130dad1561ab7" -dependencies = [ - "leb128", - "wasmparser 0.220.0", -] - -[[package]] -name = "wasm-encoder" -version = "0.221.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17a3bd88f2155da63a1f2fcb8a56377a24f0b6dfed12733bb5f544e86f690c5" -dependencies = [ - "leb128", - "wasmparser 0.221.2", -] - -[[package]] -name = "wasm-instrument" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a47ecb37b9734d1085eaa5ae1a81e60801fd8c28d4cabdd8aedb982021918bc" -dependencies = [ - "parity-wasm", -] +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" [[package]] name = "wasm-opt" @@ -7394,21 +7910,10 @@ dependencies = [ "bitflags 2.6.0", "hashbrown 0.14.5", "indexmap 2.7.0", - "semver 1.0.23", + "semver", "serde", ] -[[package]] -name = "wasmparser" -version = "0.221.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9845c470a2e10b61dd42c385839cdd6496363ed63b5c9e420b5488b77bd22083" -dependencies = [ - "bitflags 2.6.0", - "indexmap 2.7.0", - "semver 1.0.23", -] - [[package]] name = "wasmparser-nostd" version = "0.100.2" @@ -7418,33 +7923,11 @@ dependencies = [ "indexmap-nostd", ] -[[package]] -name = "wast" -version = "221.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc4470b9de917ba199157d1f0ae104f2ae362be728c43e68c571c7715bd629e" -dependencies = [ - "bumpalo", - "leb128", - "memchr", - "unicode-width 0.2.0", - "wasm-encoder 0.221.2", -] - -[[package]] -name = "wat" -version = "1.221.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b1f3c6d82af47286494c6caea1d332037f5cbeeac82bbf5ef59cb8c201c466e" -dependencies = [ - "wast", -] - [[package]] name = "web-sys" -version = "0.3.74" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a98bc3c33f0fe7e59ad7cd041b89034fa82a7c2d4365ca538dda6cdaf513863c" +checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" dependencies = [ "js-sys", "wasm-bindgen", @@ -7729,9 +8212,8 @@ dependencies = [ [[package]] name = "xcm-procedural" -version = "10.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87fb4f14094d65c500a59bcf540cf42b99ee82c706edd6226a92e769ad60563e" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "Inflector", "proc-macro2", @@ -7741,9 +8223,8 @@ dependencies = [ [[package]] name = "xcm-runtime-apis" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d4473a5d157e4d437d9ebcb1b99f9693a64983877ee57d97005f0167869935" +version = "0.1.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-support", "parity-scale-codec", @@ -7756,9 +8237,8 @@ dependencies = [ [[package]] name = "xcm-simulator" -version = "17.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "058e21bfc3e1180bbd83cad3690d0e63f34f43ab309e338afe988160aa776fcf" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c#cbeb66fbf4c7a950ed90a979373bbcca412dc63c" dependencies = [ "frame-support", "frame-system", @@ -7771,7 +8251,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?rev=cbeb66fbf4c7a950ed90a979373bbcca412dc63c)", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", @@ -7905,9 +8385,9 @@ dependencies = [ [[package]] name = "zip" -version = "2.2.1" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d52293fc86ea7cf13971b3bb81eb21683636e7ae24c729cdaf1b7c4157a352" +checksum = "ae9c1ea7b3a5e1f4b922ff856a129881167511563dc219869afe3787fc0c1a45" dependencies = [ "arbitrary", "crc32fast", @@ -7915,5 +8395,5 @@ dependencies = [ "displaydoc", "indexmap 2.7.0", "memchr", - "thiserror 2.0.4", + "thiserror 2.0.8", ] diff --git a/Cargo.toml b/Cargo.toml index 4b7cff9ff97..0dd55b8703c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ authors = ["Use Ink "] categories = ["no-std", "embedded"] edition = "2021" homepage = "https://use.ink" -keywords = ["wasm", "ink", "webassembly", "blockchain", "edsl"] +keywords = ["polkavm", "ink", "riscv", "blockchain", "edsl"] license = "Apache-2.0" repository = "https://github.com/use-ink/ink" version = "5.1.0" @@ -38,7 +38,7 @@ array-init = { version = "2.0", default-features = false } blake2 = { version = "0.10" } cargo_metadata = { version = "0.19.0" } cfg-if = { version = "1.0" } -contract-build = { version = "5.0.1" } +contract-build = { git = "https://github.com/use-ink/cargo-contract", branch = "cmichi-remove-wasm-default-to-revive" } darling = { version = "0.20.10" } derive_more = { version = "1.0.0", default-features = false } either = { version = "1.13", default-features = false } @@ -55,7 +55,6 @@ proc-macro2 = { version = "1" } quickcheck = { version = "1" } quickcheck_macros = { version = "1" } quote = { version = "1" } -rlibc = { version = "1" } scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] } scale-decode = { version = "0.14.0", default-features = false } scale-encode = { version = "0.8.0", default-features = false } @@ -77,34 +76,30 @@ tokio = { version = "1.41.1" } tracing = { version = "0.1.41" } tracing-subscriber = { version = "0.3.19" } trybuild = { version = "1.0.101" } -wasm-instrument = { version = "0.4.0" } which = { version = "7.0.0" } xxhash-rust = { version = "0.8" } const_env = { version = "0.1"} -wat = { version = "1.221.2" } # Substrate dependencies -frame-metadata = { version = "16.0.0" } -frame-system = { version = "38.0.0", default-features = false } -frame-support = { version = "38.0.0", default-features = false } -pallet-contracts = { version = "38.0.0", default-features = false } -pallet-balances = { version = "39.0.0", default-features = false } -pallet-timestamp = { version = "37.0.0", default-features = false } -pallet-contracts-uapi = { version = "12.0.0", default-features = false } -pallet-revive-uapi = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2412-rc2", default-features = false } -# TODO include mock-network for revive -pallet-contracts-mock-network = { version = "14.0.0", default-features = false } -sp-externalities = { version = "0.29.0", default-features = false } -sp-io = { version = "38.0.0", default-features = false } -sp-runtime-interface = { version = "28.0.0" } -sp-core = { version = "34.0.0", default-features = false } -sp-keyring = { version = "39.0.0", default-features = false } -sp-runtime = { version = "39.0.2", default-features = false } -sp-weights = { version = "31.0.0", default-features = false } -xcm = { package = "staging-xcm", version = "14.2.0", default-features = false } +frame-metadata = { version = "18.0.0", default-features = false } +frame-system = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +frame-support = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +pallet-revive = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +pallet-revive-uapi = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false, features = ["unstable-hostfn"] } +pallet-revive-mock-network = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +sp-externalities = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +sp-io = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +sp-runtime-interface = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false, features = ["disable_target_static_assertions"] } +sp-core = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +sp-keyring = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +sp-weights = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } # PolkaVM dependencies -polkavm-derive = { version = "0.17.1", default-features = false } +polkavm-derive = { version = "0.18.0", default-features = false } # Local dependencies ink = { version = "=5.1.0", path = "crates/ink", default-features = false } diff --git a/crates/allocator/src/bump.rs b/crates/allocator/src/bump.rs index 56aef9c1ae6..068e7e9e17d 100644 --- a/crates/allocator/src/bump.rs +++ b/crates/allocator/src/bump.rs @@ -24,12 +24,14 @@ use core::alloc::{ }; /// A page in Wasm is `64KiB` +/// todo: remove +#[allow(dead_code)] const PAGE_SIZE: usize = 64 * 1024; static mut INNER: Option = None; -#[cfg(target_arch = "riscv32")] -static mut RISCV_HEAP: [u8; 1024 * 1024] = [0; 1024 * 1024]; +#[cfg(target_arch = "riscv64")] +static mut RISCV_HEAP: [u8; 1024 * 10] = [1; 1024 * 10]; /// A bump allocator suitable for use in a Wasm environment. pub struct BumpAllocator; @@ -53,6 +55,7 @@ unsafe impl GlobalAlloc for BumpAllocator { #[inline] unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + // todo // A new page in Wasm is guaranteed to already be zero initialized, so we can just // use our regular `alloc` call here and save a bit of work. // @@ -97,6 +100,7 @@ impl InnerAlloc { /// /// This implementation is only meant to be used for testing, since we cannot (easily) /// test the `wasm32` implementation. + #[allow(dead_code)] fn request_pages(&mut self, _pages: usize) -> Option { Some(self.upper_limit) } @@ -109,62 +113,33 @@ impl InnerAlloc { 0 } + #[allow(dead_code)] fn request_pages(&mut self, _pages: usize) -> Option { unreachable!( "This branch is only used to keep the compiler happy when building tests, and should never actually be called outside of a test run." ) } - } else if #[cfg(target_arch = "wasm32")] { - fn heap_start() -> usize { - extern "C" { - static __heap_base: usize; - } - // # SAFETY - // - // The `__heap_base` symbol is defined by the wasm linker and is guaranteed - // to point to the start of the heap. - let heap_start = unsafe { &__heap_base as *const usize as usize }; - // if the symbol isn't found it will resolve to 0 - // for that to happen the rust compiler or linker need to break or change - assert_ne!(heap_start, 0, "Can't find `__heap_base` symbol."); - heap_start - } - - fn heap_end() -> usize { - // Cannot overflow on this architecture - core::arch::wasm32::memory_size(0) * PAGE_SIZE - } - - /// Request a `pages` number of pages of Wasm memory. Each page is `64KiB` in size. - /// - /// Returns `None` if a page is not available. - fn request_pages(&mut self, pages: usize) -> Option { - let prev_page = core::arch::wasm32::memory_grow(0, pages); - if prev_page == usize::MAX { - return None; - } - - // Cannot overflow on this architecture - Some(prev_page * PAGE_SIZE) - } - } else if #[cfg(target_arch = "riscv32")] { + } else if #[cfg(target_arch = "riscv64")] { fn heap_start() -> usize { + #[allow(static_mut_refs)] unsafe { RISCV_HEAP.as_mut_ptr() as usize } } + #[allow(static_mut_refs)] fn heap_end() -> usize { Self::heap_start() + unsafe { RISCV_HEAP.len() } } + #[allow(dead_code)] fn request_pages(&mut self, _pages: usize) -> Option { // On riscv the memory can't be grown - None + core::panic!("no request possible"); } } else { - core::compile_error!("ink! only supports wasm32 and riscv32"); + core::compile_error!("ink! only supports riscv64"); } } @@ -181,15 +156,7 @@ impl InnerAlloc { let alloc_end = alloc_start.checked_add(aligned_size)?; if alloc_end > self.upper_limit { - let required_pages = required_pages(aligned_size)?; - let page_start = self.request_pages(required_pages)?; - - self.upper_limit = required_pages - .checked_mul(PAGE_SIZE) - .and_then(|pages| page_start.checked_add(pages))?; - self.next = page_start.checked_add(aligned_size)?; - - Some(page_start) + panic!("exhausted heap limit"); } else { self.next = alloc_end; Some(alloc_start) @@ -205,6 +172,7 @@ impl InnerAlloc { /// - the binary with the inverse of the align creates a bitmask that is used to zero /// out bits, ensuring alignment according to type requirements and ensures that the /// next allocated pointer address is of the power of 2. + #[allow(clippy::arithmetic_side_effects)] // todo fn align_ptr(&self, layout: &Layout) -> usize { (self.next + layout.align() - 1) & !(layout.align() - 1) } @@ -216,12 +184,13 @@ impl InnerAlloc { /// `size = PAGE_SIZE / 2` this function will indicate that one page is required to /// satisfy the allocation. #[inline] -fn required_pages(size: usize) -> Option { - size.checked_add(PAGE_SIZE - 1) - .and_then(|num| num.checked_div(PAGE_SIZE)) +#[allow(dead_code)] +fn required_pages(_size: usize) -> Option { + core::panic!("required_pages"); } -#[cfg(test)] +// todo +#[cfg(all(test, target_os = "dragonfly"))] mod tests { use super::*; use std::mem::size_of; @@ -357,7 +326,8 @@ mod tests { } } -#[cfg(all(test, feature = "ink-fuzz-tests"))] +// todo +#[cfg(all(test, feature = "ink-fuzz-tests", target_os = "dragonfly"))] mod fuzz_tests { use super::*; use quickcheck::{ diff --git a/crates/e2e/Cargo.toml b/crates/e2e/Cargo.toml index fac65b83791..0792239d0e8 100644 --- a/crates/e2e/Cargo.toml +++ b/crates/e2e/Cargo.toml @@ -23,7 +23,8 @@ ink_primitives = { workspace = true, default-features = true } cargo_metadata = { workspace = true } contract-build = { workspace = true } ink_sandbox = { version = "=5.1.0", path = "./sandbox", optional = true } -pallet-contracts-mock-network = { workspace = true, optional = true } +pallet-revive = { workspace = true } +pallet-revive-mock-network = { workspace = true, optional = true } funty = { workspace = true } impl-serde = { workspace = true } jsonrpsee = { workspace = true, features = ["ws-client"] } @@ -37,12 +38,10 @@ subxt = { workspace = true } subxt-metadata = { workspace = true, optional = true } subxt-signer = { workspace = true, features = ["subxt", "sr25519"] } thiserror = { workspace = true } -wasm-instrument = { workspace = true } which = { workspace = true } # Substrate frame-support = { workspace = true } -pallet-contracts = { workspace = true } sp-core = { workspace = true } sp-keyring = { workspace = true } sp-runtime = { workspace = true } @@ -58,7 +57,7 @@ default = [ "std" ] std = [ "impl-serde/std", "ink_e2e_macro/std", - "pallet-contracts/std", + "pallet-revive/std", "scale-info/std", "scale/std", "serde/std", @@ -69,16 +68,12 @@ std = [ "ink_e2e_macro/std", "ink_sandbox/std", "frame-support/std", - "pallet-contracts-mock-network?/std", + "pallet-revive-mock-network?/std", ] sandbox = [ "dep:ink_sandbox", "subxt-metadata", - "pallet-contracts-mock-network", + "pallet-revive-mock-network", "ink_e2e_macro/sandbox", ] -revive = [ - "ink/revive", - "ink_env/revive" -] diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index df59283007e..abe02f4b486 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -150,6 +150,6 @@ fn build_full_client( fn build_runtime_client(contracts: TokenStream2, runtime: syn::Path) -> TokenStream2 { quote! { let contracts = #contracts; - let mut client = ::ink_e2e::SandboxClient::<_, _, #runtime>::new(contracts); + let mut client = ::ink_e2e::SandboxClient::<_, #runtime>::new(contracts); } } diff --git a/crates/e2e/sandbox/Cargo.toml b/crates/e2e/sandbox/Cargo.toml index 4d347500932..df5c09c4631 100644 --- a/crates/e2e/sandbox/Cargo.toml +++ b/crates/e2e/sandbox/Cargo.toml @@ -10,20 +10,21 @@ documentation = "https://docs.rs/ink_sandbox" homepage.workspace = true [dependencies] +sha3 = "0.10.8" frame-metadata = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } pallet-balances = { workspace = true } -pallet-contracts = { workspace = true } +pallet-revive = { workspace = true } pallet-timestamp = { workspace = true } scale = { workspace = true } sp-core = { workspace = true } sp-externalities = { workspace = true } sp-io = { workspace = true } +ink_primitives = { workspace = true } paste = { workspace = true } scale-info = { workspace = true } -wat = { workspace = true } [features] default = [ @@ -34,7 +35,7 @@ std = [ "frame-support/std", "frame-system/std", "pallet-balances/std", - "pallet-contracts/std", + "pallet-revive/std", "pallet-timestamp/std", "scale/std", "scale-info/std", diff --git a/crates/e2e/sandbox/src/api.rs b/crates/e2e/sandbox/src/api.rs index 01fe8d48367..190d9ad8f87 100644 --- a/crates/e2e/sandbox/src/api.rs +++ b/crates/e2e/sandbox/src/api.rs @@ -1,12 +1,12 @@ pub mod balance_api; -pub mod contracts_api; +pub mod revive_api; pub mod system_api; pub mod timestamp_api; pub mod prelude { pub use super::{ balance_api::BalanceAPI, - contracts_api::ContractAPI, + revive_api::ContractAPI, system_api::SystemAPI, timestamp_api::TimestampAPI, }; diff --git a/crates/e2e/sandbox/src/api/balance_api.rs b/crates/e2e/sandbox/src/api/balance_api.rs index 70fb0e7ba8a..a0fbda4c0aa 100644 --- a/crates/e2e/sandbox/src/api/balance_api.rs +++ b/crates/e2e/sandbox/src/api/balance_api.rs @@ -31,10 +31,10 @@ where /// /// # Arguments /// - /// * `address` - The address of the account to query. + /// * `account` - The account id of the account to query. fn free_balance( &mut self, - address: &AccountIdFor, + account_id: &AccountIdFor, ) -> BalanceOf; } @@ -55,9 +55,9 @@ where fn free_balance( &mut self, - address: &AccountIdFor, + account_id: &AccountIdFor, ) -> BalanceOf { - self.execute_with(|| pallet_balances::Pallet::::free_balance(address)) + self.execute_with(|| pallet_balances::Pallet::::free_balance(account_id)) } } diff --git a/crates/e2e/sandbox/src/api/contracts_api.rs b/crates/e2e/sandbox/src/api/revive_api.rs similarity index 55% rename from crates/e2e/sandbox/src/api/contracts_api.rs rename to crates/e2e/sandbox/src/api/revive_api.rs index c02c5c27f14..e0d97c0f2a9 100644 --- a/crates/e2e/sandbox/src/api/contracts_api.rs +++ b/crates/e2e/sandbox/src/api/revive_api.rs @@ -1,33 +1,58 @@ use crate::{ AccountIdFor, ContractExecResultFor, - ContractInstantiateResultFor, - EventRecordOf, + ContractResultInstantiate, Sandbox, + H256, }; use frame_support::{ - traits::fungible::Inspect, + pallet_prelude::DispatchError, + sp_runtime::traits::Bounded, + traits::{ + fungible::Inspect, + Time, + }, weights::Weight, }; -use frame_system::Config as SysConfig; -use pallet_contracts::{ +use frame_system::pallet_prelude::OriginFor; +use ink_primitives::DepositLimit; +use pallet_revive::{ Code, CodeUploadResult, CollectEvents, - ContractInstantiateResult, DebugInfo, - Determinism, }; use scale::Decode as _; +use sp_core::{ + H160, + U256, +}; use std::ops::Not; type BalanceOf = - <::Currency as Inspect>>::Balance; + <::Currency as Inspect>>::Balance; + +type MomentOf = <::Time as Time>::Moment; /// Contract API used to interact with the contracts pallet. pub trait ContractAPI { /// The runtime contract config. - type T: pallet_contracts::Config; + type T: pallet_revive::Config; + + /// Interface for `bare_instantiate` contract call with a simultaneous upload. + /// + /// # Arguments + /// + /// * `contract_bytes` - The contract code. + /// * `value` - The number of tokens to be transferred to the contract. + /// * `data` - The input data to be passed to the contract (including constructor + /// name). + /// * `salt` - The salt to be used for contract address derivation. + /// * `origin` - The sender of the contract call. + /// * `gas_limit` - The gas limit for the contract call. + /// * `storage_deposit_limit` - The storage deposit limit for the contract call. + #[allow(clippy::type_complexity, clippy::too_many_arguments)] + fn map_account(&mut self, account: OriginFor) -> Result<(), DispatchError>; /// Interface for `bare_instantiate` contract call with a simultaneous upload. /// @@ -47,15 +72,11 @@ pub trait ContractAPI { contract_bytes: Vec, value: BalanceOf, data: Vec, - salt: Vec, - origin: AccountIdFor, + salt: Option<[u8; 32]>, + origin: OriginFor, gas_limit: Weight, - storage_deposit_limit: Option>, - ) -> ContractInstantiateResult< - AccountIdFor, - BalanceOf, - EventRecordOf, - >; + storage_deposit_limit: DepositLimit>, + ) -> ContractResultInstantiate; /// Interface for `bare_instantiate` contract call for a previously uploaded contract. /// @@ -75,15 +96,11 @@ pub trait ContractAPI { code_hash: Vec, value: BalanceOf, data: Vec, - salt: Vec, - origin: AccountIdFor, + salt: Option<[u8; 32]>, + origin: OriginFor, gas_limit: Weight, - storage_deposit_limit: Option>, - ) -> ContractInstantiateResult< - AccountIdFor, - BalanceOf, - EventRecordOf, - >; + storage_deposit_limit: DepositLimit>, + ) -> ContractResultInstantiate; /// Interface for `bare_upload_code` contract call. /// @@ -95,10 +112,9 @@ pub trait ContractAPI { fn upload_contract( &mut self, contract_bytes: Vec, - origin: AccountIdFor, - storage_deposit_limit: Option>, - determinism: Determinism, - ) -> CodeUploadResult<::Hash, BalanceOf>; + origin: OriginFor, + storage_deposit_limit: BalanceOf, + ) -> CodeUploadResult>; /// Interface for `bare_call` contract call. /// @@ -113,35 +129,47 @@ pub trait ContractAPI { #[allow(clippy::type_complexity, clippy::too_many_arguments)] fn call_contract( &mut self, - address: AccountIdFor, + address: H160, value: BalanceOf, data: Vec, - origin: AccountIdFor, + origin: OriginFor, gas_limit: Weight, - storage_deposit_limit: Option>, - determinism: Determinism, + storage_deposit_limit: DepositLimit>, ) -> ContractExecResultFor; } impl ContractAPI for T where T: Sandbox, - T::Runtime: pallet_contracts::Config, + T::Runtime: pallet_revive::Config, + + BalanceOf: Into + TryFrom + Bounded, + MomentOf: Into, + <::Runtime as frame_system::Config>::Hash: + frame_support::traits::IsType, { type T = T::Runtime; + fn map_account( + &mut self, + account_id: OriginFor, + ) -> Result<(), DispatchError> { + self.execute_with(|| pallet_revive::Pallet::::map_account(account_id)) + } + fn deploy_contract( &mut self, contract_bytes: Vec, value: BalanceOf, data: Vec, - salt: Vec, - origin: AccountIdFor, + salt: Option<[u8; 32]>, + origin: OriginFor, gas_limit: Weight, - storage_deposit_limit: Option>, - ) -> ContractInstantiateResultFor { + storage_deposit_limit: DepositLimit>, + ) -> ContractResultInstantiate { + let storage_deposit_limit = storage_deposit_limit_fn(storage_deposit_limit); self.execute_with(|| { - pallet_contracts::Pallet::::bare_instantiate( + pallet_revive::Pallet::::bare_instantiate( origin, value, gas_limit, @@ -160,30 +188,24 @@ where code_hash: Vec, value: BalanceOf, data: Vec, - salt: Vec, - origin: AccountIdFor, + salt: Option<[u8; 32]>, + origin: OriginFor, gas_limit: Weight, - storage_deposit_limit: Option>, - ) -> ContractInstantiateResult< - AccountIdFor, - BalanceOf, - EventRecordOf, - > { + storage_deposit_limit: DepositLimit>, + ) -> ContractResultInstantiate { let mut code_hash = &code_hash[..]; + let storage_deposit_limit = storage_deposit_limit_fn(storage_deposit_limit); self.execute_with(|| { - pallet_contracts::Pallet::::bare_instantiate( + pallet_revive::Pallet::::bare_instantiate( origin, value, gas_limit, storage_deposit_limit, - Code::Existing( - ::Hash::decode(&mut code_hash) - .expect("Invalid code hash"), - ), + Code::Existing(H256::decode(&mut code_hash).expect("Invalid code hash")), data, salt, DebugInfo::UnsafeDebug, - CollectEvents::UnsafeCollect, + CollectEvents::Skip, ) }) } @@ -191,33 +213,30 @@ where fn upload_contract( &mut self, contract_bytes: Vec, - origin: AccountIdFor, - storage_deposit_limit: Option>, - determinism: Determinism, - ) -> CodeUploadResult<::Hash, BalanceOf> - { + origin: OriginFor, + storage_deposit_limit: BalanceOf, + ) -> CodeUploadResult> { self.execute_with(|| { - pallet_contracts::Pallet::::bare_upload_code( + pallet_revive::Pallet::::bare_upload_code( origin, contract_bytes, storage_deposit_limit, - determinism, ) }) } fn call_contract( &mut self, - address: AccountIdFor, + address: H160, value: BalanceOf, data: Vec, - origin: AccountIdFor, + origin: OriginFor, gas_limit: Weight, - storage_deposit_limit: Option>, - determinism: Determinism, + storage_deposit_limit: DepositLimit>, ) -> ContractExecResultFor { + let storage_deposit_limit = storage_deposit_limit_fn(storage_deposit_limit); self.execute_with(|| { - pallet_contracts::Pallet::::bare_call( + pallet_revive::Pallet::::bare_call( origin, address, value, @@ -226,12 +245,21 @@ where data, DebugInfo::UnsafeDebug, CollectEvents::UnsafeCollect, - determinism, ) }) } } +/// todo +fn storage_deposit_limit_fn( + limit: DepositLimit, +) -> pallet_revive::DepositLimit { + match limit { + DepositLimit::Unchecked => pallet_revive::DepositLimit::Unchecked, + DepositLimit::Balance(v) => pallet_revive::DepositLimit::Balance(v), + } +} + /// Converts bytes to a '\n'-split string, ignoring empty lines. pub fn decode_debug_buffer(buffer: &[u8]) -> Vec { let decoded = buffer.iter().map(|b| *b as char).collect::(); @@ -250,34 +278,35 @@ mod tests { RuntimeEventOf, RuntimeOf, }; - use frame_support::sp_runtime::traits::Hash; - use pallet_contracts::Origin; + + const STORAGE_DEPOSIT_LIMIT: DepositLimit = DepositLimit::Unchecked; fn compile_module(contract_name: &str) -> Vec { let path = [ std::env::var("CARGO_MANIFEST_DIR").as_deref().unwrap(), "/test-resources/", contract_name, - ".wat", + ".polkavm", ] .concat(); - wat::parse_file(path).expect("Failed to parse wat file") + std::fs::read(std::path::Path::new(&path)).unwrap() } #[test] fn can_upload_code() { let mut sandbox = DefaultSandbox::default(); let wasm_binary = compile_module("dummy"); - let hash = < as frame_system::Config>::Hashing>::hash( - &wasm_binary, - ); - let result = sandbox.upload_contract( - wasm_binary, - DefaultSandbox::default_actor(), - None, - Determinism::Enforced, - ); + use sha3::{ + Digest, + Keccak256, + }; + let hash = Keccak256::digest(wasm_binary.as_slice()); + let hash = H256::from_slice(hash.as_slice()); + + let origin = + DefaultSandbox::convert_account_to_origin(DefaultSandbox::default_actor()); + let result = sandbox.upload_contract(wasm_binary, origin, 100000000000000); assert!(result.is_ok()); assert_eq!(hash, result.unwrap().code_hash); @@ -291,14 +320,17 @@ mod tests { let events_before = sandbox.events(); assert!(events_before.is_empty()); + let origin = + DefaultSandbox::convert_account_to_origin(DefaultSandbox::default_actor()); + sandbox.map_account(origin.clone()).expect("cannot map"); let result = sandbox.deploy_contract( wasm_binary, 0, vec![], - vec![], - DefaultSandbox::default_actor(), - DefaultSandbox::default_gas_limit(), None, + origin, + DefaultSandbox::default_gas_limit(), + DepositLimit::Balance(100000000000000), ); assert!(result.result.is_ok()); assert!(!result.result.unwrap().result.did_revert()); @@ -308,50 +340,50 @@ mod tests { let instantiation_event = events[event_count - 2].clone(); assert!(matches!( instantiation_event.event, - RuntimeEventOf::::Contracts(pallet_contracts::Event::< + RuntimeEventOf::::Revive(pallet_revive::Event::< RuntimeOf, >::Instantiated { .. }) )); let deposit_event = events[event_count - 1].clone(); assert!(matches!( deposit_event.event, - RuntimeEventOf::::Contracts( - pallet_contracts::Event::>::StorageDepositTransferredAndHeld { .. } - ) + RuntimeEventOf::::Revive(pallet_revive::Event::< + RuntimeOf, + >::StorageDepositTransferredAndHeld { .. }) )); } #[test] fn can_call_contract() { let mut sandbox = DefaultSandbox::default(); - let actor = DefaultSandbox::default_actor(); + let _actor = DefaultSandbox::default_actor(); let wasm_binary = compile_module("dummy"); + let origin = + DefaultSandbox::convert_account_to_origin(DefaultSandbox::default_actor()); + sandbox.map_account(origin.clone()).expect("unable to map"); let result = sandbox.deploy_contract( wasm_binary, 0, vec![], - vec![], - actor.clone(), - DefaultSandbox::default_gas_limit(), None, + origin.clone(), + DefaultSandbox::default_gas_limit(), + STORAGE_DEPOSIT_LIMIT, ); + assert!(!result.result.clone().unwrap().result.did_revert()); - let contract_address = result - .result - .expect("Contract should be deployed") - .account_id; + let contract_address = result.result.expect("Contract should be deployed").addr; sandbox.reset_events(); let result = sandbox.call_contract( - contract_address.clone(), + contract_address, 0, vec![], - actor.clone(), + origin.clone(), DefaultSandbox::default_gas_limit(), - None, - Determinism::Enforced, + STORAGE_DEPOSIT_LIMIT, ); assert!(result.result.is_ok()); assert!(!result.result.unwrap().did_revert()); @@ -361,22 +393,31 @@ mod tests { assert_eq!( events[0].event, - RuntimeEventOf::::Contracts(pallet_contracts::Event::< + RuntimeEventOf::::Revive(pallet_revive::Event::< RuntimeOf, >::ContractEmitted { - contract: contract_address.clone(), - data: vec![0, 0, 0, 0], + contract: contract_address, + topics: vec![H256::from([42u8; 32])], + data: vec![1, 2, 3, 4], }) ); - assert_eq!( - events[1].event, - RuntimeEventOf::::Contracts(pallet_contracts::Event::< - RuntimeOf, - >::Called { - contract: contract_address, - caller: Origin::Signed(actor), - }), - ); + // TODO Wait for `pallet_revive::exec::Origin` re-export. + // let account_id = DefaultSandbox::default_actor(); + // let caller = origin.clone(); + // let caller = pallet_revive::exec::Origin::from_runtime_origin(caller).unwrap(); + // let origin = + // DefaultSandbox::convert_account_to_origin(DefaultSandbox::default_actor()); + // let foo = pallet_revive::Origin::>::from(origin); + // assert_eq!( + // events[1].event, + // RuntimeEventOf::::Revive(pallet_revive::Event::< + // RuntimeOf, + // >::Called { + // contract: contract_address, + // caller: frame_system::EnsureSigned::try_origin(actor).unwrap(), + // caller, + // }), + // ); } } diff --git a/crates/e2e/sandbox/src/lib.rs b/crates/e2e/sandbox/src/lib.rs index d4a46c4e1d9..6e4c914f1f9 100644 --- a/crates/e2e/sandbox/src/lib.rs +++ b/crates/e2e/sandbox/src/lib.rs @@ -10,16 +10,20 @@ use frame_support::{ traits::fungible::Inspect, }; use frame_system::{ - pallet_prelude::BlockNumberFor, + pallet_prelude::{ + BlockNumberFor, + OriginFor, + }, EventRecord, }; pub use macros::{ BlockBuilder, DefaultSandbox, }; -use pallet_contracts::{ - ContractExecResult, - ContractInstantiateResult, +use pallet_revive::{ + ContractResult, + ExecReturnValue, + InstantiateReturnValue, }; /// Export pallets that are used in [`crate::create_sandbox`] pub use { @@ -33,7 +37,7 @@ pub use { }, frame_system, pallet_balances, - pallet_contracts, + pallet_revive, pallet_timestamp, paste, sp_core::crypto::Ss58Codec, @@ -58,7 +62,7 @@ pub type StorageRoot = H256; /// Alias for the balance type. type BalanceOf = - <::Currency as Inspect>>::Balance; + <::Currency as Inspect>>::Balance; /// Alias for the account ID type. pub type AccountIdFor = ::AccountId; @@ -73,15 +77,21 @@ pub type EventRecordOf = EventRecord< >; /// Alias for the contract instantiate result. -pub type ContractInstantiateResultFor = ContractInstantiateResult< - AccountIdFor, - BalanceOf, - EventRecordOf, ->; +pub type ContractInstantiateResultFor = + ContractResult, BalanceOf, EventRecordOf>; + +pub type ContractResultFor = + ContractResult, EventRecordOf>; + +pub type ContractResultInstantiate = + ContractResult, EventRecordOf>; /// Alias for the contract exec result. pub type ContractExecResultFor = - ContractExecResult, EventRecordOf>; + ContractResult, EventRecordOf>; + +/// Alias for the `map_acocunt` result. +pub type MapAccountResultFor = Result<(), DispatchError>; /// Alias for the runtime of a sandbox. pub type RuntimeOf = ::Runtime; @@ -121,7 +131,7 @@ pub trait Sandbox { fn default_actor() -> AccountIdFor; fn default_gas_limit() -> Weight { - Weight::from_parts(100_000_000_000, 3 * 1024 * 1024) + Weight::from_parts(100_000_000_000_000, 6 * 1024 * 1024) } /// Metadata of the runtime. diff --git a/crates/e2e/sandbox/src/macros.rs b/crates/e2e/sandbox/src/macros.rs index 0b251b9b99b..5b722e833ba 100644 --- a/crates/e2e/sandbox/src/macros.rs +++ b/crates/e2e/sandbox/src/macros.rs @@ -19,7 +19,7 @@ pub struct BlockBuilder(std::marker::PhantomData); impl< T: pallet_balances::Config + pallet_timestamp::Config - + pallet_contracts::Config, + + pallet_revive::Config, > BlockBuilder { /// Create a new externalities with the given balances. @@ -55,7 +55,7 @@ impl< .as_secs(), ); pallet_timestamp::Pallet::::on_initialize(height); - pallet_contracts::Pallet::::on_initialize(height); + pallet_revive::Pallet::::on_initialize(height); frame_system::Pallet::::note_finished_initialize(); } @@ -63,7 +63,7 @@ impl< pub fn finalize_block( height: frame_system::pallet_prelude::BlockNumberFor, ) -> ::Hash { - pallet_contracts::Pallet::::on_finalize(height); + pallet_revive::Pallet::::on_finalize(height); pallet_timestamp::Pallet::::on_finalize(height); pallet_balances::Pallet::::on_finalize(height); frame_system::Pallet::::finalize().hash() @@ -107,11 +107,10 @@ mod construct_runtime { derive_impl, parameter_types, sp_runtime::{ - testing::H256, traits::Convert, AccountId32, Perbill, }, - traits::{ConstBool, ConstU128, ConstU32, ConstU64, Currency, Randomness}, + traits::{ConstBool, ConstU128, ConstU32, ConstU64, Currency}, weights::Weight, }; @@ -123,7 +122,7 @@ mod construct_runtime { System: $crate::frame_system, Balances: $crate::pallet_balances, Timestamp: $crate::pallet_timestamp, - Contracts: $crate::pallet_contracts, + Revive: $crate::pallet_revive, $( $pallet_name: $pallet, )* @@ -154,6 +153,7 @@ mod construct_runtime { type MaxFreezes = (); type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; + type DoneSlashHandler = (); } // Configure pallet timestamp @@ -164,14 +164,7 @@ mod construct_runtime { type WeightInfo = (); } - // Configure pallet contracts - pub enum SandboxRandomness {} - impl Randomness for SandboxRandomness { - fn random(_subject: &[u8]) -> (H256, u32) { - unreachable!("No randomness") - } - } - + // Configure pallet revive type BalanceOf = >::Balance; impl Convert for $runtime { fn convert(w: Weight) -> BalanceOf { @@ -180,46 +173,36 @@ mod construct_runtime { } parameter_types! { - pub SandboxSchedule: $crate::pallet_contracts::Schedule<$runtime> = { - <$crate::pallet_contracts::Schedule<$runtime>>::default() - }; + // TODO can we delete some? pub DeletionWeightLimit: Weight = Weight::zero(); pub DefaultDepositLimit: BalanceOf = 10_000_000; pub CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(0); pub MaxDelegateDependencies: u32 = 32; } - impl $crate::pallet_contracts::Config for $runtime { + impl $crate::pallet_revive::Config for $runtime { + type AddressMapper = $crate::pallet_revive::AccountId32Mapper; + type ChainId = ConstU64<0>; // TODO + type NativeToEthRatio = ConstU32<1>; type Time = Timestamp; - type Randomness = SandboxRandomness; type Currency = Balances; type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; type CallFilter = (); + type DepositPerItem = ConstU128<1>; + type DepositPerByte = ConstU128<1>; type WeightPrice = Self; type WeightInfo = (); type ChainExtension = $chain_extension; - type Schedule = SandboxSchedule; - type CallStack = [$crate::pallet_contracts::Frame; 5]; - type DepositPerByte = ConstU128<1>; - type DepositPerItem = ConstU128<1>; - type AddressGenerator = $crate::pallet_contracts::DefaultAddressGenerator; - type MaxCodeLen = ConstU32<{ 123 * 1024 }>; - type MaxStorageKeyLen = ConstU32<128>; - type MaxTransientStorageSize = ConstU32<{ 1024 * 1024 }>; - type UnsafeUnstableInterface = ConstBool; - type UploadOrigin = $crate::frame_system::EnsureSigned; - type InstantiateOrigin = $crate::frame_system::EnsureSigned; - type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>; - type Migrations = (); - type DefaultDepositLimit = DefaultDepositLimit; - type Debug = $debug; + type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>; + type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>; + type UnsafeUnstableInterface = ConstBool; type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent; - type MaxDelegateDependencies = MaxDelegateDependencies; type RuntimeHoldReason = RuntimeHoldReason; - type Environment = (); + type Debug = $debug; type Xcm = (); - type ApiVersion = (); + type UploadOrigin = $crate::frame_system::EnsureSigned; + type InstantiateOrigin = $crate::frame_system::EnsureSigned; } // Implement `crate::Sandbox` trait @@ -320,7 +303,7 @@ mod construct_runtime { // Export runtime type itself, pallets and useful types from the auxiliary module pub use construct_runtime::{ - $sandbox, $runtime, Balances, Contracts, PalletInfo, RuntimeCall, RuntimeEvent, RuntimeHoldReason, + $sandbox, $runtime, Balances, Revive, PalletInfo, RuntimeCall, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, System, Timestamp, }; }; diff --git a/crates/e2e/sandbox/test-resources/dummy.polkavm b/crates/e2e/sandbox/test-resources/dummy.polkavm new file mode 100644 index 0000000000000000000000000000000000000000..34c003082a46d6eb6e0f5b0ee82f6076bcb53b9b GIT binary patch literal 846 zcmcIjzi-n(6uxsVj)_DYSCL$VB2rN#+9~$gu6;rO%I z)k`O41{MbX1vYm60wlyAz{&>aG*CLV3nzW|PTzg+>3dIi&t5zM;Asb}7DN(w2L#Eb zVfgjqrypoXX!)BQ9!ugpC>&O@d66?3IvFb#*}QwZ1NyDrne(e`OXR{ZUJg;qi9P_w zjr=nmU9ui5|&_d z3*kQMH{0k>mA&_G4-e7V?veJPs(*pI-Xe;Ygj{$b#Bq{1d_&8~VJAtP6{8}f5vPJV zBjmM5HH$JvecSRh6RTDAAmOH2!CNbXk~s^S1Y8&A1tD3GyQQfUk}q?5LamvY?~|cX7o1WCbrVi^GSP{Y`Y=_icmC+?lFPD7&-n@O;8ob$4*UsH&@2 zGfmf2u|N7}K3Cp0|b#L>oMjy(?W8?goUA^-pY literal 0 HcmV?d00001 diff --git a/crates/e2e/sandbox/test-resources/dummy.wat b/crates/e2e/sandbox/test-resources/dummy.wat deleted file mode 100644 index 23eff87ad51..00000000000 --- a/crates/e2e/sandbox/test-resources/dummy.wat +++ /dev/null @@ -1,25 +0,0 @@ -;; Dummy contract emitting a dummy event. -(module - (import "seal0" "seal_deposit_event" (func $seal_deposit_event (param i32 i32 i32 i32))) - (import "seal0" "seal_return" (func $seal_return (param i32 i32 i32))) - (import "env" "memory" (memory 1 1)) - - (func (export "deploy")) - - (func (export "call") - ;; emit dummy event - (call $seal_deposit_event - (i32.const 0) ;; The topics buffer - (i32.const 0) ;; The topics buffer's length - (i32.const 8) ;; The data buffer - (i32.const 4) ;; The data buffer's length - ) - - ;; exit with success - (call $seal_return - (i32.const 0) ;; flags - (i32.const 0) ;; returned value - (i32.const 4) ;; length of returned value - ) - ) -) diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index 760a44dff0c..ea2afbcaf42 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -12,7 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::Keypair; +use super::{ + Keypair, + H256, +}; use crate::{ backend_calls::{ InstantiateBuilder, @@ -21,8 +24,8 @@ use crate::{ }, builders::CreateBuilderPartial, contract_results::{ + BareInstantiationDryRunResult, BareInstantiationResult, - InstantiateDryRunResult, }, CallBuilder, CallBuilderFinal, @@ -33,6 +36,7 @@ use ink_env::{ DefaultEnvironment, Environment, }; +use ink_primitives::DepositLimit; use jsonrpsee::core::async_trait; use scale::{ Decode, @@ -175,7 +179,7 @@ pub trait ContractsBackend { fn remove_code<'a>( &'a mut self, caller: &'a Keypair, - code_hash: E::Hash, + code_hash: H256, ) -> RemoveCodeBuilder<'a, E, Self> where Self: Sized + BuilderClient, @@ -230,7 +234,8 @@ pub trait BuilderClient: ContractsBackend { message: &CallBuilderFinal, value: E::Balance, gas_limit: Weight, - storage_deposit_limit: Option, + storage_deposit_limit: DepositLimit, + //storage_deposit_limit: E::Balance, ) -> Result where CallBuilderFinal: Clone; @@ -244,7 +249,8 @@ pub trait BuilderClient: ContractsBackend { caller: &Keypair, message: &CallBuilderFinal, value: E::Balance, - storage_deposit_limit: Option, + storage_deposit_limit: DepositLimit, + //storage_deposit_limit: E::Balance, ) -> Result, Self::Error> where CallBuilderFinal: Clone; @@ -260,14 +266,14 @@ pub trait BuilderClient: ContractsBackend { &mut self, contract_name: &str, caller: &Keypair, - storage_deposit_limit: Option, + storage_deposit_limit: E::Balance, ) -> Result, Self::Error>; /// Removes the code of the contract at `code_hash`. async fn bare_remove_code( &mut self, caller: &Keypair, - code_hash: E::Hash, + code_hash: crate::H256, ) -> Result; /// Bare instantiate call. This function does not perform a dry-run, @@ -290,8 +296,8 @@ pub trait BuilderClient: ContractsBackend { constructor: &mut CreateBuilderPartial, value: E::Balance, gas_limit: Weight, - storage_deposit_limit: Option, - ) -> Result, Self::Error>; + storage_deposit_limit: DepositLimit, + ) -> Result, Self::Error>; /// Dry run contract instantiation. async fn bare_instantiate_dry_run< @@ -304,6 +310,18 @@ pub trait BuilderClient: ContractsBackend { caller: &Keypair, constructor: &mut CreateBuilderPartial, value: E::Balance, - storage_deposit_limit: Option, - ) -> Result, Self::Error>; + storage_deposit_limit: DepositLimit, + ) -> Result, Self::Error>; + + /// todo + async fn map_account( + &mut self, + caller: &Keypair, + ) -> Result<(), Self::Error>; + + /// todo + async fn map_account_dry_run( + &mut self, + caller: &Keypair, + ) -> Result<(), Self::Error>; } diff --git a/crates/e2e/src/backend_calls.rs b/crates/e2e/src/backend_calls.rs index aedba9683bb..7768d673471 100644 --- a/crates/e2e/src/backend_calls.rs +++ b/crates/e2e/src/backend_calls.rs @@ -13,26 +13,28 @@ // limitations under the License. use ink_env::Environment; +use ink_primitives::DepositLimit; use scale::{ Decode, Encode, }; use sp_weights::Weight; +use std::marker::PhantomData; +use super::{balance_to_deposit_limit, Keypair}; use crate::{ backend::BuilderClient, builders::CreateBuilderPartial, + contract_results::BareInstantiationDryRunResult, CallBuilderFinal, CallDryRunResult, CallResult, ContractsBackend, - InstantiateDryRunResult, InstantiationResult, UploadResult, + H256, }; -use super::Keypair; - /// Allows to build an end-to-end call using a builder pattern. pub struct CallBuilder<'a, E, Args, RetType, B> where @@ -48,7 +50,7 @@ where value: E::Balance, extra_gas_portion: Option, gas_limit: Option, - storage_deposit_limit: Option, + storage_deposit_limit: E::Balance, } impl<'a, E, Args, RetType, B> CallBuilder<'a, E, Args, RetType, B> @@ -75,7 +77,7 @@ where value: 0u32.into(), extra_gas_portion: None, gas_limit: None, - storage_deposit_limit: None, + storage_deposit_limit: 0u32.into(), } } @@ -107,7 +109,7 @@ where /// # Notes /// /// Overwrites any values specified for `extra_gas_portion`. - /// The gas estimate fro dry-run will be ignored. + /// The gas estimate from the dry-run will be ignored. pub fn gas_limit(&mut self, limit: Weight) -> &mut Self { if limit == Weight::from_parts(0, 0) { self.gas_limit = None @@ -122,11 +124,7 @@ where &mut self, storage_deposit_limit: E::Balance, ) -> &mut Self { - if storage_deposit_limit == 0u32.into() { - self.storage_deposit_limit = None - } else { - self.storage_deposit_limit = Some(storage_deposit_limit) - } + self.storage_deposit_limit = storage_deposit_limit; self } @@ -140,12 +138,18 @@ where where CallBuilderFinal: Clone, { + // todo must be added to remove as well + let _map = B::map_account( + self.client, + self.caller + ).await; // todo will fail if instantiation happened before + let dry_run = B::bare_call_dry_run( self.client, self.caller, self.message, self.value, - self.storage_deposit_limit, + balance_to_deposit_limit::(self.storage_deposit_limit), ) .await?; @@ -164,7 +168,7 @@ where self.message, self.value, gas_limit, - self.storage_deposit_limit, + balance_to_deposit_limit::(self.storage_deposit_limit), ) .await?; @@ -184,7 +188,7 @@ where self.caller, self.message, self.value, - self.storage_deposit_limit, + balance_to_deposit_limit::(self.storage_deposit_limit), ) .await } @@ -206,7 +210,7 @@ where value: E::Balance, extra_gas_portion: Option, gas_limit: Option, - storage_deposit_limit: Option, + storage_deposit_limit: DepositLimit, } impl<'a, E, Contract, Args, R, B> InstantiateBuilder<'a, E, Contract, Args, R, B> @@ -235,7 +239,7 @@ where value: 0u32.into(), extra_gas_portion: None, gas_limit: None, - storage_deposit_limit: None, + storage_deposit_limit: DepositLimit::Unchecked, } } @@ -280,13 +284,9 @@ where /// Specify the max amount of funds that can be charged for storage. pub fn storage_deposit_limit( &mut self, - storage_deposit_limit: E::Balance, + storage_deposit_limit: DepositLimit, ) -> &mut Self { - if storage_deposit_limit == 0u32.into() { - self.storage_deposit_limit = None - } else { - self.storage_deposit_limit = Some(storage_deposit_limit) - } + self.storage_deposit_limit = storage_deposit_limit; self } @@ -297,20 +297,26 @@ where pub async fn submit( &mut self, ) -> Result, B::Error> { + // we have to make sure the account was mapped + let _map = B::map_account( + self.client, + self.caller + ).await; // todo will fail if instantiation happened before + let dry_run = B::bare_instantiate_dry_run( self.client, self.contract_name, self.caller, self.constructor, self.value, - self.storage_deposit_limit, + self.storage_deposit_limit.clone(), ) .await?; let gas_limit = if let Some(limit) = self.gas_limit { limit } else { - let gas_required = dry_run.contract_result.gas_required; + let gas_required = dry_run.gas_required; let proof_size = gas_required.proof_size(); let ref_time = gas_required.ref_time(); calculate_weight(proof_size, ref_time, self.extra_gas_portion) @@ -323,26 +329,28 @@ where self.constructor, self.value, gas_limit, - self.storage_deposit_limit, + balance_to_deposit_limit::(dry_run.storage_deposit.charge_or_zero()), ) .await?; Ok(InstantiationResult { - account_id: instantiate_result.account_id, + addr: instantiate_result.addr, dry_run, events: instantiate_result.events, }) } /// Dry run the instantiate call. - pub async fn dry_run(&mut self) -> Result, B::Error> { + pub async fn dry_run( + &mut self, + ) -> Result, B::Error> { B::bare_instantiate_dry_run( self.client, self.contract_name, self.caller, self.constructor, self.value, - self.storage_deposit_limit, + self.storage_deposit_limit.clone(), ) .await } @@ -357,7 +365,7 @@ where client: &'a mut B, contract_name: &'a str, caller: &'a Keypair, - storage_deposit_limit: Option, + storage_deposit_limit: E::Balance, } impl<'a, E, B> UploadBuilder<'a, E, B> @@ -371,7 +379,7 @@ where client, contract_name, caller, - storage_deposit_limit: None, + storage_deposit_limit: 0u32.into(), } } @@ -380,11 +388,7 @@ where &mut self, storage_deposit_limit: E::Balance, ) -> &mut Self { - if storage_deposit_limit == 0u32.into() { - self.storage_deposit_limit = None - } else { - self.storage_deposit_limit = Some(storage_deposit_limit) - } + self.storage_deposit_limit = storage_deposit_limit; self } @@ -408,7 +412,8 @@ where { client: &'a mut B, caller: &'a Keypair, - code_hash: E::Hash, + code_hash: crate::H256, + _phantom: PhantomData E>, } impl<'a, E, B> RemoveCodeBuilder<'a, E, B> @@ -417,11 +422,12 @@ where B: BuilderClient, { /// Initialize a remove code builder with essential values. - pub fn new(client: &'a mut B, caller: &'a Keypair, code_hash: E::Hash) -> Self { + pub fn new(client: &'a mut B, caller: &'a Keypair, code_hash: H256) -> Self { Self { client, caller, code_hash, + _phantom: Default::default(), } } diff --git a/crates/e2e/src/builders.rs b/crates/e2e/src/builders.rs index 93453c32d4c..d43fe2ec05b 100644 --- a/crates/e2e/src/builders.rs +++ b/crates/e2e/src/builders.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use crate::H256; use ink_env::{ call::{ utils::{ @@ -32,7 +33,6 @@ use scale::Encode; pub type CreateBuilderPartial = CreateBuilder< E, ContractRef, - Unset<::Hash>, Set>, Unset<::Balance>, Set>, @@ -50,7 +50,7 @@ where // set all the other properties to default values, we only require the `exec_input`. builder .endowment(0u32.into()) - .code_hash(ink_primitives::Clear::CLEAR_HASH) + .code_hash(H256::zero()) .salt_bytes(Vec::new()) .params() .exec_input() diff --git a/crates/e2e/src/client_utils.rs b/crates/e2e/src/client_utils.rs index 69b9901fcd9..2b04c975d47 100644 --- a/crates/e2e/src/client_utils.rs +++ b/crates/e2e/src/client_utils.rs @@ -19,16 +19,19 @@ use std::{ }; /// Generate a unique salt based on the system time. -pub fn salt() -> Vec { +pub fn salt() -> Option<[u8; 32]> { use funty::Fundamental as _; - std::time::SystemTime::now() + let mut arr = [0u8; 32]; + let t: [u8; 16] = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .unwrap_or_else(|err| panic!("unable to get unix time: {err}")) .as_millis() .as_u128() - .to_le_bytes() - .to_vec() + .to_le_bytes(); + arr[..16].copy_from_slice(t.as_slice()); + arr[16..].copy_from_slice(t.as_slice()); + Some(arr) } /// A registry of contracts that can be loaded. @@ -65,6 +68,7 @@ impl ContractsRegistry { self.contracts.keys() ) ); + eprintln!("wasm path {:?}", wasm_path); let code = std::fs::read(wasm_path).unwrap_or_else(|err| { panic!("Error loading '{}': {:?}", wasm_path.display(), err) }); diff --git a/crates/e2e/src/contract_build.rs b/crates/e2e/src/contract_build.rs index c65357fd9e5..0466582e7ba 100644 --- a/crates/e2e/src/contract_build.rs +++ b/crates/e2e/src/contract_build.rs @@ -22,7 +22,6 @@ use contract_build::{ Network, OptimizationPasses, OutputType, - Target, UnstableFlags, Verbosity, DEFAULT_MAX_MEMORY_PAGES, @@ -47,6 +46,7 @@ use std::{ pub fn build_root_and_contract_dependencies() -> Vec { let contract_project = ContractProject::new(); let contract_manifests = contract_project.root_with_contract_dependencies(); + eprintln!("contract_manifests {:?}", contract_manifests); build_contracts(&contract_manifests) } @@ -113,6 +113,7 @@ impl ContractProject { } fn root_with_contract_dependencies(&self) -> Vec { + eprintln!("contract dependencies {:#?}", self.contract_dependencies); self.root_with_additional_contracts(&self.contract_dependencies) } } @@ -129,8 +130,10 @@ fn build_contracts(contract_manifests: &[PathBuf]) -> Vec { .lock() .unwrap(); + // todo rename wasm to riscv let mut wasm_paths = Vec::new(); for manifest in contract_manifests { + eprintln!("processing {:?}", manifest); let wasm_path = match contract_build_jobs.entry(manifest.clone()) { Entry::Occupied(entry) => entry.get().clone(), Entry::Vacant(entry) => { @@ -144,6 +147,7 @@ fn build_contracts(contract_manifests: &[PathBuf]) -> Vec { wasm_paths } +// todo replace all mentions of Wasm /// Builds the contract at `manifest_path`, returns the path to the contract /// Wasm build artifact. fn build_contract(path_to_cargo_toml: &Path) -> PathBuf { @@ -165,8 +169,8 @@ fn build_contract(path_to_cargo_toml: &Path) -> PathBuf { keep_debug_symbols: false, extra_lints: false, output_type: OutputType::HumanReadable, + // todo remove skip_wasm_validation: false, - target: Target::Wasm, max_memory_pages: DEFAULT_MAX_MEMORY_PAGES, image: ImageVariant::Default, }; @@ -175,6 +179,7 @@ fn build_contract(path_to_cargo_toml: &Path) -> PathBuf { Ok(build_result) => { build_result .dest_wasm + // todo Replace Wasm with Risc-V everywhere .expect("Wasm code artifact not generated") .canonicalize() .expect("Invalid dest bundle path") diff --git a/crates/e2e/src/contract_results.rs b/crates/e2e/src/contract_results.rs index 2c19473a270..d0ed89ea081 100644 --- a/crates/e2e/src/contract_results.rs +++ b/crates/e2e/src/contract_results.rs @@ -12,61 +12,165 @@ // See the License for the specific language governing permissions and // limitations under the License. +use crate::H256; use ink::codegen::ContractCallBuilder; -use ink_env::{ - call::FromAccountId, - Environment, -}; +use ink_env::Environment; use ink_primitives::{ ConstructorResult, MessageResult, }; -use pallet_contracts::{ +use pallet_revive::{ + evm::H160, CodeUploadResult, - ContractExecResult, - ContractInstantiateResult, + ContractResult, ExecReturnValue, InstantiateReturnValue, + StorageDeposit, +}; +use sp_runtime::{ + DispatchError, + Weight, }; use std::{ fmt, fmt::Debug, marker::PhantomData, }; +use frame_support::pallet_prelude::{Decode, Encode}; +use ink_env::call::FromAddr; + +/// Alias for the contract instantiate result. +pub type ContractInstantiateResultFor = ContractResult< + InstantiateReturnValue, + ::Balance, + ::EventRecord, +>; + +/// Result type of a `bare_call` or `bare_instantiate` call as well as `ContractsApi::call` and +/// `ContractsApi::instantiate`. +/// +/// It contains the execution result together with some auxiliary information. +/// +/// #Note +/// +/// It has been extended to include `events` at the end of the struct while not bumping the +/// `ContractsApi` version. Therefore when SCALE decoding a `ContractResult` its trailing data +/// should be ignored to avoid any potential compatibility issues. +#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode)] +pub struct ContractResultBar { + /// How much weight was consumed during execution. + pub gas_consumed: Weight, + /// How much weight is required as gas limit in order to execute this call. + /// + /// This value should be used to determine the weight limit for on-chain execution. + /// + /// # Note + /// + /// This can only different from [`Self::gas_consumed`] when weight pre-charging + /// is used. Currently, only `seal_call_runtime` makes use of pre-charging. + /// Additionally, any `seal_call` or `seal_instantiate` makes use of pre-charging + /// when a non-zero `gas_limit` argument is supplied. + pub gas_required: Weight, + /// How much balance was paid by the origin into the contract's deposit account in order to + /// pay for storage. + /// + /// The storage deposit is never actually charged from the origin in case of [`Self::result`] + /// is `Err`. This is because on error all storage changes are rolled back including the + /// payment of the deposit. + pub storage_deposit: StorageDeposit, + /// An optional debug message. This message is only filled when explicitly requested + /// by the code that calls into the contract. Otherwise it is empty. + /// + /// The contained bytes are valid UTF-8. This is not declared as `String` because + /// this type is not allowed within the runtime. + /// + /// Clients should not make any assumptions about the format of the buffer. + /// They should just display it as-is. It is **not** only a collection of log lines + /// provided by a contract but a formatted buffer with different sections. + /// + /// # Note + /// + /// The debug message is never generated during on-chain execution. It is reserved for + /// RPC calls. + pub debug_message: Vec, + /// The execution result of the Wasm code. + pub result: Result, +} + +/// Alias for the contract exec result. +pub type ContractExecResultFor = ContractResultBar< + ExecReturnValue, + ::Balance, +>; + +/// Copied from `pallet-revive`. +#[derive(Debug, Encode, Decode)] +pub struct BareInstantiationDryRunResult { + /// How much weight was consumed during execution. + pub gas_consumed: Weight, + /// How much weight is required as gas limit in order to execute this call. + /// + /// This value should be used to determine the weight limit for on-chain execution. + /// + /// # Note + /// + /// This can only different from [`Self::gas_consumed`] when weight pre-charging + /// is used. Currently, only `seal_call_runtime` makes use of pre-charging. + /// Additionally, any `seal_call` or `seal_instantiate` makes use of pre-charging + /// when a non-zero `gas_limit` argument is supplied. + pub gas_required: Weight, + /// How much balance was paid by the origin into the contract's deposit account in + /// order to pay for storage. + /// + /// The storage deposit is never actually charged from the origin in case of + /// [`Self::result`] is `Err`. This is because on error all storage changes are + /// rolled back including the payment of the deposit. + pub storage_deposit: StorageDeposit, + /// An optional debug message. This message is only filled when explicitly requested + /// by the code that calls into the contract. Otherwise it is empty. + /// + /// The contained bytes are valid UTF-8. This is not declared as `String` because + /// this type is not allowed within the runtime. + /// + /// Clients should not make any assumptions about the format of the buffer. + /// They should just display it as-is. It is **not** only a collection of log lines + /// provided by a contract but a formatted buffer with different sections. + /// + /// # Note + /// + /// The debug message is never generated during on-chain execution. It is reserved + /// for RPC calls. + pub debug_message: Vec, + /// The execution result of the Wasm code. + pub result: Result, +} /// Result of a contract instantiation using bare call. -pub struct BareInstantiationResult { - /// The account id at which the contract was instantiated. - pub account_id: E::AccountId, +pub struct BareInstantiationResult { + /// The address at which the contract was instantiated. + pub addr: H160, /// Events that happened with the contract instantiation. pub events: EventLog, } -impl BareInstantiationResult { +impl BareInstantiationResult { /// Returns the account id at which the contract was instantiated. - pub fn call(&self) -> ::Type - where - Contract: ContractCallBuilder, - Contract::Type: FromAccountId, - { - <::Type as FromAccountId>::from_account_id( - self.account_id.clone(), - ) + pub fn call(&self) -> H160 { + self.addr } } /// We implement a custom `Debug` here, as to avoid requiring the trait bound `Debug` for /// `E`. -impl Debug for BareInstantiationResult +impl Debug for BareInstantiationResult where - E::AccountId: Debug, - E::Balance: Debug, EventLog: Debug, { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { f.debug_struct("InstantiationResult") - .field("account_id", &self.account_id) + .field("account_id", &self.addr) .field("events", &self.events) + // todo .finish() } } @@ -74,10 +178,10 @@ where /// Result of a contract instantiation. pub struct InstantiationResult { /// The account id at which the contract was instantiated. - pub account_id: E::AccountId, + pub addr: H160, /// The result of the dry run, contains debug messages /// if there were any. - pub dry_run: InstantiateDryRunResult, + pub dry_run: BareInstantiationDryRunResult, /// Events that happened with the contract instantiation. pub events: EventLog, } @@ -87,10 +191,10 @@ impl InstantiationResult { pub fn call_builder(&self) -> ::Type where Contract: ContractCallBuilder, - Contract::Type: FromAccountId, + Contract::Type: FromAddr, { - <::Type as FromAccountId>::from_account_id( - self.account_id.clone(), + <::Type as FromAddr>::from_addr( + self.addr ) } } @@ -101,12 +205,13 @@ impl Debug for InstantiationResult where E::AccountId: Debug, E::Balance: Debug, + E::EventRecord: Debug, EventLog: Debug, { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { f.debug_struct("InstantiationResult") - .field("account_id", &self.account_id) - .field("dry_run", &self.dry_run) + .field("account_id", &self.addr) + // .field("dry_run", &self.dry_run) // todo .field("events", &self.events) .finish() } @@ -115,9 +220,9 @@ where /// Result of a contract upload. pub struct UploadResult { /// The hash with which the contract can be instantiated. - pub code_hash: E::Hash, + pub code_hash: H256, /// The result of the dry run, contains debug messages if there were any. - pub dry_run: CodeUploadResult, + pub dry_run: CodeUploadResult, /// Events that happened with the contract instantiation. pub events: EventLog, } @@ -127,7 +232,7 @@ pub struct UploadResult { impl Debug for UploadResult where E::Balance: Debug, - E::Hash: Debug, + H256: Debug, EventLog: Debug, { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { @@ -184,6 +289,7 @@ impl Debug for CallResult where E: Debug, E::Balance: Debug, + E::EventRecord: Debug, V: Debug, EventLog: Debug, { @@ -196,13 +302,26 @@ where } /// Result of the dry run of a contract call. -#[derive(Debug)] pub struct CallDryRunResult { /// The result of the dry run, contains debug messages if there were any. - pub exec_result: ContractExecResult, + pub exec_result: ContractExecResultFor, pub _marker: PhantomData, } +/// We implement a custom `Debug` here, as to avoid requiring the trait bound `Debug` for +/// `E`. +impl Debug for CallDryRunResult +where + E::Balance: Debug, + E::EventRecord: Debug, +{ + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + f.debug_struct("CallDryRunResult") + .field("exec_result", &self.exec_result) + .finish() + } +} + impl CallDryRunResult { /// Returns true if the dry-run execution resulted in an error. pub fn is_err(&self) -> bool { @@ -262,15 +381,13 @@ impl CallDryRunResult { /// Result of the dry run of a contract call. pub struct InstantiateDryRunResult { /// The result of the dry run, contains debug messages if there were any. - pub contract_result: ContractInstantiateResult, + pub contract_result: ContractInstantiateResultFor, } -impl From> +impl From> for InstantiateDryRunResult { - fn from( - contract_result: ContractInstantiateResult, - ) -> Self { + fn from(contract_result: ContractInstantiateResultFor) -> Self { Self { contract_result } } } @@ -284,7 +401,7 @@ impl InstantiateDryRunResult { /// Returns the [`InstantiateReturnValue`] resulting from the dry-run message call. /// /// Panics if the dry-run message call failed to execute. - pub fn instantiate_return_value(&self) -> &InstantiateReturnValue { + pub fn instantiate_return_value(&self) -> &InstantiateReturnValue { self.contract_result .result .as_ref() @@ -314,6 +431,7 @@ where E: Environment, E::AccountId: Debug, E::Balance: Debug, + E::EventRecord: Debug, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("InstantiateDryRunResult") diff --git a/crates/e2e/src/error.rs b/crates/e2e/src/error.rs index f043607f8a5..2b31d23f22d 100644 --- a/crates/e2e/src/error.rs +++ b/crates/e2e/src/error.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use pallet_contracts::ContractExecResult; - use std::fmt; /// An error occurred while interacting with the E2E backend. @@ -96,11 +94,3 @@ impl fmt::Display for SandboxErr { write!(f, "SandboxErr: {}", self.msg) } } - -impl From> for SandboxErr { - fn from(_value: ContractExecResult) -> Self { - Self { - msg: "ContractExecResult".to_string(), - } - } -} diff --git a/crates/e2e/src/events.rs b/crates/e2e/src/events.rs index 96c5a605d3b..fcafca84c71 100644 --- a/crates/e2e/src/events.rs +++ b/crates/e2e/src/events.rs @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use ink_env::Environment; +use crate::H256; +use pallet_revive::evm::H160; #[cfg(feature = "std")] use std::fmt::Debug; - use subxt::{ events::StaticEvent, ext::{ @@ -34,18 +34,16 @@ use subxt::{ )] #[decode_as_type(trait_bounds = "", crate_path = "subxt::ext::scale_decode")] #[encode_as_type(crate_path = "subxt::ext::scale_encode")] -pub struct ContractInstantiatedEvent { - /// Account id of the deployer. - pub deployer: E::AccountId, - /// Account id where the contract was instantiated to. - pub contract: E::AccountId, +pub struct ContractInstantiatedEvent { + /// Address of the deployer. + pub deployer: H160, + /// Address where the contract was instantiated to. + pub contract: H160, } -impl StaticEvent for ContractInstantiatedEvent -where - E: Environment, +impl StaticEvent for ContractInstantiatedEvent { - const PALLET: &'static str = "Contracts"; + const PALLET: &'static str = "Revive"; const EVENT: &'static str = "Instantiated"; } @@ -59,16 +57,13 @@ where )] #[decode_as_type(trait_bounds = "", crate_path = "subxt::ext::scale_decode")] #[encode_as_type(crate_path = "subxt::ext::scale_encode")] -pub struct CodeStoredEvent { +pub struct CodeStoredEvent { /// Hash under which the contract code was stored. - pub code_hash: E::Hash, + pub code_hash: H256, } -impl StaticEvent for CodeStoredEvent -where - E: Environment, -{ - const PALLET: &'static str = "Contracts"; +impl StaticEvent for CodeStoredEvent { + const PALLET: &'static str = "Revive"; const EVENT: &'static str = "CodeStored"; } @@ -82,16 +77,13 @@ where #[decode_as_type(trait_bounds = "", crate_path = "subxt::ext::scale_decode")] #[encode_as_type(crate_path = "subxt::ext::scale_encode")] /// A custom event emitted by the contract. -pub struct ContractEmitted { - pub contract: E::AccountId, +pub struct ContractEmitted { + pub contract: H160, pub data: Vec, } -impl StaticEvent for ContractEmitted -where - E: Environment, -{ - const PALLET: &'static str = "Contracts"; +impl StaticEvent for ContractEmitted { + const PALLET: &'static str = "Revive"; const EVENT: &'static str = "ContractEmitted"; } diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index 61cfada3a84..3884defc0c3 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -60,8 +60,7 @@ pub use sandbox_client::{ preset, Client as SandboxClient, }; -pub use sp_core::H256; -pub use sp_keyring::AccountKeyring; +pub use sp_keyring::Sr25519Keyring; pub use subxt::{ self, backend::rpc::RpcClient, @@ -87,14 +86,11 @@ pub use ink_sandbox::DefaultSandbox; use ink::codegen::ContractCallBuilder; use ink_env::{ - call::FromAccountId, + call::FromAddr, ContractEnv, Environment, }; -use pallet_contracts::{ - ContractExecResult, - ContractInstantiateResult, -}; +use ink_primitives::{DepositLimit, H160, H256}; use std::{ cell::RefCell, sync::Once, @@ -132,22 +128,31 @@ pub fn log_error(msg: &str) { } /// Get an ink! [`ink_primitives::AccountId`] for a given keyring account. -pub fn account_id(account: AccountKeyring) -> ink_primitives::AccountId { +pub fn account_id(account: Sr25519Keyring) -> ink_primitives::AccountId { ink_primitives::AccountId::try_from(account.to_account_id().as_ref()) .expect("account keyring has a valid account id") } /// Creates a call builder builder for `Contract`, based on an account id. pub fn create_call_builder( - acc_id: <::Env as Environment>::AccountId, + acc_id: H160, ) -> ::Type where ::Env: Environment, Contract: ContractCallBuilder, Contract: ContractEnv, - Contract::Type: FromAccountId<::Env>, + Contract::Type: FromAddr, { - <::Type as FromAccountId< - ::Env, - >>::from_account_id(acc_id) + <::Type as FromAddr>::from_addr(acc_id) +} + +fn balance_to_deposit_limit(b: ::Balance) -> DepositLimit<::Balance> { + DepositLimit::Balance(b) +} + +fn deposit_limit_to_balance(l: DepositLimit<::Balance>) -> ::Balance { + match l { + DepositLimit::Balance(l) => l, + DepositLimit::Unchecked => panic!("oh no"), + } } diff --git a/crates/e2e/src/node_proc.rs b/crates/e2e/src/node_proc.rs index ed707953248..8b1ac498557 100644 --- a/crates/e2e/src/node_proc.rs +++ b/crates/e2e/src/node_proc.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use sp_keyring::AccountKeyring; +use sp_keyring::Sr25519Keyring; use std::{ ffi::{ OsStr, @@ -113,7 +113,7 @@ where /// Construct a test node process. pub struct TestNodeProcessBuilder { node_path: OsString, - authority: Option, + authority: Option, marker: std::marker::PhantomData, } @@ -133,7 +133,7 @@ where } /// Set the authority development account for a node in validator mode e.g. --alice. - pub fn with_authority(&mut self, account: AccountKeyring) -> &mut Self { + pub fn with_authority(&mut self, account: Sr25519Keyring) -> &mut Self { self.authority = Some(account); self } diff --git a/crates/e2e/src/sandbox_client.rs b/crates/e2e/src/sandbox_client.rs index e6f12032b0f..a5060d25d71 100644 --- a/crates/e2e/src/sandbox_client.rs +++ b/crates/e2e/src/sandbox_client.rs @@ -30,28 +30,37 @@ use crate::{ ChainBackend, ContractsBackend, E2EBackend, - InstantiateDryRunResult, UploadResult, + H256, }; - -use frame_support::traits::fungible::Inspect; +use crate::contract_results::{BareInstantiationDryRunResult, ContractExecResultFor}; +use frame_support::{ + pallet_prelude::DispatchError, + dispatch::RawOrigin, + traits::{ + fungible::Inspect, + IsType, + }, +}; +use ink_env::Environment; +use ink_primitives::DepositLimit; use ink_sandbox::{ api::prelude::*, + frame_system, + frame_system::pallet_prelude::OriginFor, pallet_balances, - pallet_contracts, + pallet_revive, AccountIdFor, RuntimeCall, Sandbox, Weight, }; -use pallet_contracts::ContractResult; - -use ink_env::Environment; use jsonrpsee::core::async_trait; -use pallet_contracts::{ +use pallet_revive::{ + evm::U256, CodeUploadReturnValue, - ContractInstantiateResult, InstantiateReturnValue, + MomentOf, }; use scale::{ Decode, @@ -61,6 +70,7 @@ use sp_core::{ sr25519::Pair, Pair as _, }; +use sp_runtime::traits::Bounded; use std::{ marker::PhantomData, path::PathBuf, @@ -73,22 +83,22 @@ use subxt_signer::sr25519::Keypair; type BalanceOf = ::Balance; type ContractsBalanceOf = - <::Currency as Inspect>>::Balance; + <::Currency as Inspect>>::Balance; -pub struct Client { +pub struct Client { sandbox: S, contracts: ContractsRegistry, - _phantom: PhantomData<(AccountId, Hash)>, + _phantom: PhantomData, } // While it is not necessary true that `Client` is `Send`, it will not be used in a way // that would violate this bound. In particular, all `Client` instances will be operating // synchronously. -unsafe impl Send for Client {} -impl Client +unsafe impl Send for Client {} +impl Client where S: Default, - S::Runtime: pallet_balances::Config + pallet_contracts::Config, + S::Runtime: pallet_balances::Config + pallet_revive::Config, AccountIdFor: From<[u8; 32]>, BalanceOf: From, { @@ -127,8 +137,7 @@ where } #[async_trait] -impl + Send, Hash, S: Sandbox> ChainBackend - for Client +impl + Send, S: Sandbox> ChainBackend for Client where S::Runtime: pallet_balances::Config, AccountIdFor: From<[u8; 32]>, @@ -208,18 +217,19 @@ where #[async_trait] impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, - Hash: Copy + Send + From<[u8; 32]>, S: Sandbox, - E: Environment< - AccountId = AccountId, - Balance = ContractsBalanceOf, - Hash = Hash, - > + 'static, - > BuilderClient for Client + E: Environment> + + 'static, + > BuilderClient for Client where - S::Runtime: pallet_balances::Config + pallet_contracts::Config, + S::Runtime: pallet_balances::Config + pallet_revive::Config, AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, ContractsBalanceOf: Send + Sync, + + ContractsBalanceOf: Into + TryFrom + Bounded, + MomentOf: Into, + <::Runtime as frame_system::Config>::Hash: + frame_support::traits::IsType, { async fn bare_instantiate( &mut self, @@ -228,32 +238,39 @@ where constructor: &mut CreateBuilderPartial, value: E::Balance, gas_limit: Weight, - storage_deposit_limit: Option, - ) -> Result, Self::Error> { + storage_deposit_limit: DepositLimit, + ) -> Result, Self::Error> { + let _ = as BuilderClient>::map_account(self, caller).await; + + // todo reduce code duplication + let caller = keypair_to_account(caller); + let origin = RawOrigin::Signed(caller); + let origin = OriginFor::::from(origin); + let code = self.contracts.load_code(contract_name); let data = constructor_exec_input(constructor.clone()); + let s: [u8; 32] = salt().unwrap(); // todo let result = self.sandbox.deploy_contract( code, value, data, - salt(), - keypair_to_account(caller), + Some(s), // todo + origin, gas_limit, storage_deposit_limit, ); - let account_id_raw = match &result.result { + let addr_raw = match &result.result { Err(err) => { log_error(&format!("Instantiation failed: {err:?}")); return Err(SandboxErr::new(format!("bare_instantiate: {err:?}"))); } - Ok(res) => *res.account_id.as_ref(), + Ok(res) => res.addr, }; - let account_id = AccountId::from(account_id_raw); Ok(BareInstantiationResult { - account_id: account_id.clone(), + addr: addr_raw, events: (), // todo: https://github.com/Cardinal-Cryptography/drink/issues/32 }) } @@ -264,31 +281,39 @@ where caller: &Keypair, constructor: &mut CreateBuilderPartial, value: E::Balance, - storage_deposit_limit: Option, - ) -> Result, Self::Error> { + storage_deposit_limit: DepositLimit, + ) -> Result, Self::Error> { + // todo has to be: let _ = as BuilderClient>::map_account_dry_run(self, &caller).await; + let _ = as BuilderClient>::map_account(self, caller).await; + + // todo reduce code duplication + let caller = keypair_to_account(caller); + let origin = RawOrigin::Signed(caller); + let origin = OriginFor::::from(origin); + let code = self.contracts.load_code(contract_name); let data = constructor_exec_input(constructor.clone()); + let result = self.sandbox.dry_run(|sandbox| { sandbox.deploy_contract( code, value, data, salt(), - keypair_to_account(caller), + origin, S::default_gas_limit(), storage_deposit_limit, ) }); - let account_id_raw = match &result.result { + let addr_id_raw = match &result.result { Err(err) => { panic!("Instantiate dry-run failed: {err:?}!") } - Ok(res) => *res.account_id.as_ref(), + Ok(res) => res.addr, }; - let account_id = AccountId::from(account_id_raw); - let result = ContractInstantiateResult { + let result = BareInstantiationDryRunResult:: { gas_consumed: result.gas_consumed, gas_required: result.gas_required, storage_deposit: result.storage_deposit, @@ -296,45 +321,42 @@ where result: result.result.map(|r| { InstantiateReturnValue { result: r.result, - account_id, + addr: addr_id_raw, // todo } }), - events: None, }; - Ok(result.into()) + Ok(result) } async fn bare_upload( &mut self, contract_name: &str, caller: &Keypair, - storage_deposit_limit: Option, + storage_deposit_limit: E::Balance, ) -> Result, Self::Error> { let code = self.contracts.load_code(contract_name); - let result = match self.sandbox.upload_contract( - code, - keypair_to_account(caller), - storage_deposit_limit, - pallet_contracts::Determinism::Enforced, - ) { - Ok(result) => result, - Err(err) => { - log_error(&format!("Upload failed: {err:?}")); - return Err(SandboxErr::new(format!("bare_upload: {err:?}"))) - } - }; + // todo reduce code duplication + let caller = keypair_to_account(caller); + let origin = RawOrigin::Signed(caller); + let origin = OriginFor::::from(origin); + + let result = + match self + .sandbox + .upload_contract(code, origin, storage_deposit_limit) + { + Ok(result) => result, + Err(err) => { + log_error(&format!("Upload failed: {err:?}")); + return Err(SandboxErr::new(format!("bare_upload: {err:?}"))) + } + }; - let code_hash_raw: [u8; 32] = result - .code_hash - .as_ref() - .try_into() - .expect("Invalid code hash"); - let code_hash = Hash::from(code_hash_raw); Ok(UploadResult { - code_hash, + code_hash: result.code_hash, dry_run: Ok(CodeUploadReturnValue { - code_hash, + code_hash: result.code_hash, deposit: result.deposit, }), events: (), @@ -344,7 +366,7 @@ where async fn bare_remove_code( &mut self, _caller: &Keypair, - _code_hash: E::Hash, + _code_hash: H256, ) -> Result { unimplemented!("sandbox does not yet support remove_code") } @@ -355,24 +377,30 @@ where message: &CallBuilderFinal, value: E::Balance, gas_limit: Weight, - storage_deposit_limit: Option, + storage_deposit_limit: DepositLimit, ) -> Result where CallBuilderFinal: Clone, { - let account_id = message.clone().params().callee().clone(); + let _ = as BuilderClient>::map_account(self, caller).await; + + // todo reduce code duplication + let caller = keypair_to_account(caller); + let origin = RawOrigin::Signed(caller); + let origin = OriginFor::::from(origin); + + // todo rename any account_id coming back from callee + let addr = *message.clone().params().callee(); let exec_input = Encode::encode(message.clone().params().exec_input()); - let account_id = (*account_id.as_ref()).into(); self.sandbox .call_contract( - account_id, + addr, value, exec_input, - keypair_to_account(caller), + origin, gas_limit, storage_deposit_limit, - pallet_contracts::Determinism::Enforced, ) .result .map_err(|err| SandboxErr::new(format!("bare_call: {err:?}")))?; @@ -385,54 +413,103 @@ where caller: &Keypair, message: &CallBuilderFinal, value: E::Balance, - storage_deposit_limit: Option, + storage_deposit_limit: DepositLimit, ) -> Result, Self::Error> where CallBuilderFinal: Clone, { - let account_id = message.clone().params().callee().clone(); + // todo there's side effects here + let _ = as BuilderClient>::map_account(self, caller).await; + + // todo reduce code duplication + let caller = keypair_to_account(caller); + let origin = RawOrigin::Signed(caller); + let origin = OriginFor::::from(origin); + + let addr = *message.clone().params().callee(); let exec_input = Encode::encode(message.clone().params().exec_input()); - let account_id = (*account_id.as_ref()).into(); let result = self.sandbox.dry_run(|sandbox| { sandbox.call_contract( - account_id, + addr, value, exec_input, - keypair_to_account(caller), + origin, S::default_gas_limit(), storage_deposit_limit, - pallet_contracts::Determinism::Enforced, ) }); + if result.result.is_err() { + let res = result.result.clone().unwrap_err(); + if let DispatchError::Module(m) = res { + let msg = m.message; + if msg.is_some() { + let s = msg.unwrap(); + if s.contains("AccountUnmapped") { + panic!("something is wrong, we mapped the account before") + } + } + } + } + // todo error when `AccountUnmapped` Ok(CallDryRunResult { - exec_result: ContractResult { + exec_result: ContractExecResultFor:: { gas_consumed: result.gas_consumed, gas_required: result.gas_required, storage_deposit: result.storage_deposit, debug_message: result.debug_message, result: result.result, - events: None, + //events: None, }, _marker: Default::default(), }) } + + async fn map_account_dry_run(&mut self, caller: &Keypair) -> Result<(), Self::Error> + { + let caller = keypair_to_account(caller); + let origin = RawOrigin::Signed(caller); + let origin = OriginFor::::from(origin); + + self.sandbox.dry_run(|sandbox| { + sandbox.map_account( + origin, + ) + }) + .map_err(|err| { + SandboxErr::new(format!("map_account_dry_run: execution error {:?}", err)) + }) + } + + async fn map_account(&mut self, caller: &Keypair) -> Result<(), Self::Error> { + let caller = keypair_to_account(caller); + let origin = RawOrigin::Signed(caller); + let origin = OriginFor::::from(origin); + + self.sandbox.map_account( + origin, + ) + .map_err(|err| { + SandboxErr::new(format!("map_account: execution error {:?}", err)) + }) + } } impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, - Hash: Copy + Send + From<[u8; 32]>, Config: Sandbox, E: Environment< AccountId = AccountId, Balance = ContractsBalanceOf, - Hash = Hash, > + 'static, - > E2EBackend for Client + > E2EBackend for Client where - Config::Runtime: pallet_balances::Config + pallet_contracts::Config, + Config::Runtime: pallet_balances::Config + pallet_revive::Config, AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, ContractsBalanceOf: Send + Sync, + ContractsBalanceOf: Into + TryFrom + Bounded, + MomentOf: Into, + ::Hash: IsType, { } @@ -443,16 +520,12 @@ fn keypair_to_account>(keypair: &Keypair) -> AccountId #[async_trait] impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, - Hash: Copy + From<[u8; 32]>, S: Sandbox, - E: Environment< - AccountId = AccountId, - Balance = ContractsBalanceOf, - Hash = Hash, - > + 'static, - > ContractsBackend for Client + E: Environment> + + 'static, + > ContractsBackend for Client where - S::Runtime: pallet_balances::Config + pallet_contracts::Config, + S::Runtime: pallet_balances::Config + pallet_revive::Config, AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, { type Error = SandboxErr; @@ -471,7 +544,7 @@ pub mod preset { Sandbox, Snapshot, }; - pub use pallet_contracts_mock_network::*; + pub use pallet_revive_mock_network::*; use sp_runtime::traits::Dispatchable; /// A [`ink_sandbox::Sandbox`] that can be used to test contracts diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index ba70d5e3129..1e421ffc169 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -12,23 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::{ - builders::{ - constructor_exec_input, - CreateBuilderPartial, - }, - events::{ - CodeStoredEvent, - ContractInstantiatedEvent, - EventWithTopics, - }, - log_error, - log_info, - sr25519, - ContractsApi, - InstantiateDryRunResult, - Keypair, -}; +use super::{builders::{ + constructor_exec_input, + CreateBuilderPartial, +}, deposit_limit_to_balance, events::{ + CodeStoredEvent, + ContractInstantiatedEvent, + EventWithTopics, +}, log_error, log_info, sr25519, ContractsApi, Keypair, H256}; use crate::{ backend::BuilderClient, contract_results::{ @@ -49,8 +40,8 @@ use ink_env::{ }, Environment, }; +use ink_primitives::DepositLimit; use jsonrpsee::core::async_trait; -use pallet_contracts::ContractResult; use scale::{ Decode, Encode, @@ -66,6 +57,7 @@ use crate::{ salt, ContractsRegistry, }, + contract_results::BareInstantiationDryRunResult, error::DryRunError, events, ContractsBackend, @@ -86,6 +78,7 @@ use subxt::{ }, tx::Signer, }; +use crate::contract_results::ContractResultBar; pub type Error = crate::error::Error; @@ -122,8 +115,9 @@ where E: Environment, E::AccountId: Debug, + E::EventRecord: Debug, E::Balance: Debug + scale::HasCompact + serde::Serialize, - E::Hash: Debug + scale::Encode, + H256: Debug + scale::Encode, { /// Creates a new [`Client`] instance using a `subxt` client. pub async fn new>( @@ -144,8 +138,8 @@ where data: Vec, value: E::Balance, gas_limit: Weight, - storage_deposit_limit: Option, - ) -> Result>, Error> { + storage_deposit_limit: E::Balance, + ) -> Result>, Error> { let salt = salt(); let tx_events = self @@ -161,14 +155,14 @@ where ) .await; - let mut account_id = None; + let mut addr = None; for evt in tx_events.iter() { let evt = evt.unwrap_or_else(|err| { panic!("unable to unwrap event: {err:?}"); }); if let Some(instantiated) = evt - .as_event::>() + .as_event::() .unwrap_or_else(|err| { panic!("event conversion to `Instantiated` failed: {err:?}"); }) @@ -177,7 +171,7 @@ where "contract was instantiated at {:?}", instantiated.contract )); - account_id = Some(instantiated.contract); + addr = Some(instantiated.contract); // We can't `break` here, we need to assign the account id from the // last `ContractInstantiatedEvent`, in case the contract instantiates @@ -193,12 +187,12 @@ where return Err(Error::InstantiateExtrinsic(dispatch_error)) } } - let account_id = account_id.expect("cannot extract `account_id` from events"); + let addr = addr.expect("cannot extract `account_id` from events"); Ok(BareInstantiationResult { // The `account_id` must exist at this point. If the instantiation fails // the dry-run must already return that. - account_id, + addr, events: tx_events, }) } @@ -208,9 +202,9 @@ where &mut self, signer: &Keypair, code: Vec, - storage_deposit_limit: Option, + storage_deposit_limit: E::Balance, ) -> Result>, Error> { - // dry run the instantiate to calculate the gas limit + // dry run instantiate to calculate the gas limit let dry_run = self .api .upload_dry_run(signer, code.clone(), storage_deposit_limit) @@ -230,7 +224,7 @@ where }); if let Some(uploaded) = - evt.as_event::>().unwrap_or_else(|err| { + evt.as_event::().unwrap_or_else(|err| { panic!("event conversion to `Uploaded` failed: {err:?}"); }) { @@ -272,20 +266,15 @@ where }) } + /// todo check if comment still holds /// Transforms a [`ContractResult`] from a dry run into a [`Result`] type, containing /// details of the [`DispatchError`] if the dry run failed. #[allow(clippy::type_complexity)] fn contract_result_to_result( &self, - contract_result: ContractResult< - Result, - E::Balance, - (), - >, - ) -> Result< - ContractResult, E::Balance, ()>, - DryRunError, - > { + contract_result: ContractResultBar, + ) -> Result, DryRunError> + { if let Err(error) = contract_result.result { let debug_message = String::from_utf8(contract_result.debug_message.clone()) .expect("invalid utf8 debug message"); @@ -339,6 +328,7 @@ where + TryFrom + scale::HasCompact + serde::Serialize, + E::EventRecord: Debug, { type AccountId = E::AccountId; type Balance = E::Balance; @@ -472,9 +462,10 @@ where E: Environment, E::AccountId: Debug + Send + Sync, + E::EventRecord: Debug, E::Balance: Clone + Debug + Send + Sync + From + scale::HasCompact + serde::Serialize, - E::Hash: Debug + Send + Sync + scale::Encode, + H256: Debug + Send + Sync + scale::Encode, { async fn bare_instantiate( &mut self, @@ -483,14 +474,15 @@ where constructor: &mut CreateBuilderPartial, value: E::Balance, gas_limit: Weight, - storage_deposit_limit: Option, - ) -> Result, Self::Error> { + storage_deposit_limit: DepositLimit, + ) -> Result, Self::Error> { let code = self.contracts.load_code(contract_name); let data = constructor_exec_input(constructor.clone()); + let storage_deposit_limit = deposit_limit_to_balance::(storage_deposit_limit); let ret = self .exec_instantiate(caller, code, data, value, gas_limit, storage_deposit_limit) .await?; - log_info(&format!("instantiated contract at {:?}", ret.account_id)); + log_info(&format!("instantiated contract at {:?}", ret.addr)); Ok(ret) } @@ -504,8 +496,8 @@ where caller: &Keypair, constructor: &mut CreateBuilderPartial, value: E::Balance, - storage_deposit_limit: Option, - ) -> Result, Self::Error> { + storage_deposit_limit: DepositLimit, + ) -> Result, Self::Error> { let code = self.contracts.load_code(contract_name); let data = constructor_exec_input(constructor.clone()); @@ -520,19 +512,14 @@ where caller, ) .await; - - let result = self - .contract_result_to_result(result) - .map_err(Error::InstantiateDryRun)?; - - Ok(result.into()) + Ok(result) } async fn bare_upload( &mut self, contract_name: &str, caller: &Keypair, - storage_deposit_limit: Option, + storage_deposit_limit: E::Balance, ) -> Result, Self::Error> { let code = self.contracts.load_code(contract_name); let ret = self @@ -545,7 +532,7 @@ where async fn bare_remove_code( &mut self, caller: &Keypair, - code_hash: E::Hash, + code_hash: H256, ) -> Result { let tx_events = self.api.remove_code(caller, code_hash).await; @@ -572,22 +559,22 @@ where message: &CallBuilderFinal, value: E::Balance, gas_limit: Weight, - storage_deposit_limit: Option, + storage_deposit_limit: DepositLimit, ) -> Result where CallBuilderFinal: Clone, { - let account_id = message.clone().params().callee().clone(); + let account_id = *message.clone().params().callee(); let exec_input = Encode::encode(message.clone().params().exec_input()); log_info(&format!("call: {:02X?}", exec_input)); let tx_events = self .api .call( - subxt::utils::MultiAddress::Id(account_id.clone()), + account_id, value, gas_limit.into(), - storage_deposit_limit, + deposit_limit_to_balance::(storage_deposit_limit), exec_input, caller, ) @@ -611,17 +598,22 @@ where Ok(tx_events) } + // todo ist gar kein `bare_call` async fn bare_call_dry_run( &mut self, caller: &Keypair, message: &CallBuilderFinal, value: E::Balance, - storage_deposit_limit: Option, + storage_deposit_limit: DepositLimit, ) -> Result, Self::Error> where CallBuilderFinal: Clone, { - let dest = message.clone().params().callee().clone(); + // todo beware side effect! this is wrong, we have to batch up the `map_account` + // into the RPC dry run instead + let _ = self.map_account(caller).await; + + let dest = *message.clone().params().callee(); let exec_input = Encode::encode(message.clone().params().exec_input()); let exec_result = self @@ -631,7 +623,7 @@ where dest, exec_input, value, - storage_deposit_limit, + deposit_limit_to_balance::(storage_deposit_limit), ) .await; log_info(&format!("call dry run: {:?}", &exec_result.result)); @@ -649,6 +641,59 @@ where _marker: Default::default(), }) } + + async fn map_account(&mut self, caller: &Keypair) -> Result<(), Self::Error> { + let tx_events = self + .api + .map_account( + caller, + ) + .await; + + for evt in tx_events.iter() { + let evt = evt.unwrap_or_else(|err| { + panic!("unable to unwrap event: {err:?}"); + }); + + if is_extrinsic_failed_event(&evt) { + let metadata = self.api.client.metadata(); + let dispatch_error = + DispatchError::decode_from(evt.field_bytes(), metadata) + .map_err(|e| Error::Decoding(e.to_string()))?; + log_error(&format!("extrinsic for call failed: {dispatch_error}")); + return Err(Error::CallExtrinsic(dispatch_error)) + } + } + + // todo: Ok(tx_events) + Ok(()) + } + + async fn map_account_dry_run(&mut self, caller: &Keypair) -> Result<(), Self::Error> { + let tx_events = self + .api + .map_account( + caller, + ) + .await; + + for evt in tx_events.iter() { + let evt = evt.unwrap_or_else(|err| { + panic!("unable to unwrap event: {err:?}"); + }); + + if is_extrinsic_failed_event(&evt) { + let metadata = self.api.client.metadata(); + let dispatch_error = + DispatchError::decode_from(evt.field_bytes(), metadata) + .map_err(|e| Error::Decoding(e.to_string()))?; + log_error(&format!("extrinsic for call failed: {dispatch_error}")); + return Err(Error::CallExtrinsic(dispatch_error)) + } + } + + Ok(()) + } } impl ContractsBackend for Client @@ -670,7 +715,7 @@ where E::AccountId: Debug + Send + Sync, E::Balance: Clone + Debug + Send + Sync + From + scale::HasCompact + serde::Serialize, - E::Hash: Debug + Send + scale::Encode, + H256: Debug + Send + scale::Encode, { type Error = Error; type EventLog = ExtrinsicEvents; @@ -695,9 +740,10 @@ where E: Environment, E::AccountId: Debug + Send + Sync, + E::EventRecord: Debug, E::Balance: Clone + Debug + Send + Sync + From + scale::HasCompact + serde::Serialize, - E::Hash: Debug + Send + Sync + scale::Encode, + H256: Debug + Send + Sync + scale::Encode, { } @@ -742,14 +788,14 @@ impl CallResult> { /// Returns all the `ContractEmitted` events emitted by the contract. pub fn contract_emitted_events( &self, - ) -> Result>>, subxt::Error> + ) -> Result>, subxt::Error> where C::Hash: Into, { let mut events_with_topics = Vec::new(); for event in self.events.iter() { let event = event?; - if let Some(decoded_event) = event.as_event::>()? { + if let Some(decoded_event) = event.as_event::()? { let event_with_topics = EventWithTopics { event: decoded_event, topics: event.topics().iter().cloned().map(Into::into).collect(), diff --git a/crates/e2e/src/xts.rs b/crates/e2e/src/xts.rs index ef63d036dd0..ea599d20ad4 100644 --- a/crates/e2e/src/xts.rs +++ b/crates/e2e/src/xts.rs @@ -15,14 +15,17 @@ use super::{ log_info, sr25519, - ContractExecResult, - ContractInstantiateResult, Keypair, }; use ink_env::Environment; +use crate::contract_results::{BareInstantiationDryRunResult, ContractExecResultFor}; use core::marker::PhantomData; -use pallet_contracts::CodeUploadResult; +use ink_primitives::DepositLimit; +use pallet_revive::{ + evm::H160, + CodeUploadResult, +}; use sp_core::H256; use subxt::{ backend::{ @@ -40,7 +43,6 @@ use subxt::{ Signer, TxStatus, }, - utils::MultiAddress, OnlineClient, }; @@ -91,24 +93,32 @@ pub struct InstantiateWithCode { #[codec(compact)] value: E::Balance, gas_limit: Weight, - storage_deposit_limit: Option, + #[codec(compact)] + storage_deposit_limit: E::Balance, code: Vec, data: Vec, - salt: Vec, + salt: Option<[u8; 32]>, } /// A raw call to `pallet-contracts`'s `call`. #[derive(Debug, scale::Decode, scale::Encode, scale_encode::EncodeAsType)] #[encode_as_type(trait_bounds = "", crate_path = "subxt::ext::scale_encode")] pub struct Call { - dest: MultiAddress, + dest: H160, #[codec(compact)] value: E::Balance, gas_limit: Weight, - storage_deposit_limit: Option, + #[codec(compact)] + storage_deposit_limit: E::Balance, data: Vec, } +/// A raw call to `pallet-contracts`'s `map_account`. +#[derive(Debug, scale::Decode, scale::Encode, scale_encode::EncodeAsType)] +#[encode_as_type(trait_bounds = "", crate_path = "subxt::ext::scale_encode")] +pub struct MapAccount { +} + /// A raw call to `pallet-contracts`'s `call`. #[derive(Debug, scale::Decode, scale::Encode, scale_encode::EncodeAsType)] #[encode_as_type(trait_bounds = "", crate_path = "subxt::ext::scale_encode")] @@ -118,89 +128,61 @@ pub struct Transfer { value: E::Balance, } -#[derive( - Debug, - Clone, - Copy, - PartialEq, - Eq, - serde::Serialize, - scale::Decode, - scale::Encode, - scale_encode::EncodeAsType, -)] -#[encode_as_type(crate_path = "subxt::ext::scale_encode")] -pub enum Determinism { - /// The execution should be deterministic and hence no indeterministic instructions - /// are allowed. - /// - /// Dispatchables always use this mode in order to make on-chain execution - /// deterministic. - Enforced, - /// Allow calling or uploading an indeterministic code. - /// - /// This is only possible when calling into `pallet-contracts` directly via - /// [`crate::Pallet::bare_call`]. - /// - /// # Note - /// - /// **Never** use this mode for on-chain execution. - Relaxed, -} - /// A raw call to `pallet-contracts`'s `remove_code`. #[derive(Debug, scale::Encode, scale::Decode, scale_encode::EncodeAsType)] #[encode_as_type(trait_bounds = "", crate_path = "subxt::ext::scale_encode")] -pub struct RemoveCode { - code_hash: E::Hash, +pub struct RemoveCode { + code_hash: H256, } -/// A raw call to `pallet-contracts`'s `upload`. +/// A raw call to `pallet-contracts`'s `upload_code`. #[derive(Debug, scale::Encode, scale::Decode, scale_encode::EncodeAsType)] #[encode_as_type(trait_bounds = "", crate_path = "subxt::ext::scale_encode")] pub struct UploadCode { code: Vec, - storage_deposit_limit: Option, - determinism: Determinism, + #[codec(compact)] + storage_deposit_limit: E::Balance, } /// A struct that encodes RPC parameters required to instantiate a new smart contract. -#[derive(serde::Serialize, scale::Encode)] -#[serde(rename_all = "camelCase")] +#[derive(scale::Encode)] +// todo: #[derive(serde::Serialize, scale::Encode)] +// todo: #[serde(rename_all = "camelCase")] struct RpcInstantiateRequest { origin: C::AccountId, value: E::Balance, gas_limit: Option, - storage_deposit_limit: Option, + storage_deposit_limit: DepositLimit, code: Code, data: Vec, - salt: Vec, + salt: Option<[u8; 32]>, } /// A struct that encodes RPC parameters required to upload a new smart contract. -#[derive(serde::Serialize, scale::Encode)] -#[serde(rename_all = "camelCase")] +#[derive(scale::Encode)] +// todo: #[derive(serde::Serialize, scale::Encode)] +// todo: #[serde(rename_all = "camelCase")] struct RpcCodeUploadRequest where E::Balance: serde::Serialize, { origin: C::AccountId, code: Vec, - storage_deposit_limit: Option, - determinism: Determinism, + storage_deposit_limit: E::Balance, } /// A struct that encodes RPC parameters required for a call to a smart contract. /// /// Copied from [`pallet-contracts-rpc`]. -#[derive(serde::Serialize, scale::Encode)] -#[serde(rename_all = "camelCase")] +#[derive(scale::Encode)] +// todo: #[derive(serde::Serialize, scale::Encode)] +// todo: #[serde(rename_all = "camelCase")] struct RpcCallRequest { origin: C::AccountId, - dest: E::AccountId, + dest: H160, value: E::Balance, gas_limit: Option, - storage_deposit_limit: Option, + storage_deposit_limit: DepositLimit, input_data: Vec, } @@ -215,7 +197,7 @@ enum Code { Existing(H256), } -/// Provides functions for interacting with the `pallet-contracts` API. +/// Provides functions for interacting with the `pallet-revive` API. pub struct ContractsApi { pub rpc: LegacyRpcMethods, pub client: OnlineClient, @@ -274,12 +256,13 @@ where pub async fn instantiate_with_code_dry_run( &self, value: E::Balance, - storage_deposit_limit: Option, + storage_deposit_limit: DepositLimit, code: Vec, data: Vec, - salt: Vec, + salt: Option<[u8; 32]>, signer: &Keypair, - ) -> ContractInstantiateResult { + ) -> BareInstantiationDryRunResult { + // todo map_account beforehand? let code = Code::Upload(code); let call_request = RpcInstantiateRequest:: { origin: Signer::::account_id(signer), @@ -290,14 +273,14 @@ where data, salt, }; - let func = "ContractsApi_instantiate"; + let func = "ReviveApi_instantiate"; let params = scale::Encode::encode(&call_request); let bytes = self .rpc .state_call(func, Some(¶ms), None) .await .unwrap_or_else(|err| { - panic!("error on ws request `contracts_instantiate`: {err:?}"); + panic!("error on ws request `revive_instantiate`: {err:?}"); }); scale::Decode::decode(&mut bytes.as_ref()).unwrap_or_else(|err| { panic!("decoding ContractInstantiateResult failed: {err}") @@ -412,19 +395,19 @@ where &self, value: E::Balance, gas_limit: Weight, - storage_deposit_limit: Option, + storage_deposit_limit: E::Balance, code: Vec, data: Vec, - salt: Vec, + salt: Option<[u8; 32]>, signer: &Keypair, ) -> ExtrinsicEvents { let call = subxt::tx::DefaultPayload::new( - "Contracts", + "Revive", "instantiate_with_code", InstantiateWithCode:: { value, gas_limit, - storage_deposit_limit, + storage_deposit_limit, // todo code, data, salt, @@ -440,15 +423,14 @@ where &self, signer: &Keypair, code: Vec, - storage_deposit_limit: Option, - ) -> CodeUploadResult { + storage_deposit_limit: E::Balance, + ) -> CodeUploadResult { let call_request = RpcCodeUploadRequest:: { origin: Signer::::account_id(signer), code, storage_deposit_limit, - determinism: Determinism::Enforced, }; - let func = "ContractsApi_upload_code"; + let func = "ReviveApi_upload_code"; let params = scale::Encode::encode(&call_request); let bytes = self .rpc @@ -469,15 +451,14 @@ where &self, signer: &Keypair, code: Vec, - storage_deposit_limit: Option, + storage_deposit_limit: E::Balance, ) -> ExtrinsicEvents { let call = subxt::tx::DefaultPayload::new( - "Contracts", + "Revive", "upload_code", UploadCode:: { code, storage_deposit_limit, - determinism: Determinism::Enforced, }, ) .unvalidated(); @@ -492,12 +473,12 @@ where pub async fn remove_code( &self, signer: &Keypair, - code_hash: E::Hash, + code_hash: H256, ) -> ExtrinsicEvents { let call = subxt::tx::DefaultPayload::new( - "Contracts", + "Revive", "remove_code", - RemoveCode:: { code_hash }, + RemoveCode { code_hash }, ) .unvalidated(); @@ -508,20 +489,20 @@ where pub async fn call_dry_run( &self, origin: C::AccountId, - dest: E::AccountId, + dest: H160, input_data: Vec, value: E::Balance, - storage_deposit_limit: Option, - ) -> ContractExecResult { + _storage_deposit_limit: E::Balance, // todo + ) -> ContractExecResultFor { let call_request = RpcCallRequest:: { origin, dest, value, gas_limit: None, - storage_deposit_limit, + storage_deposit_limit: DepositLimit::Unchecked, input_data, }; - let func = "ContractsApi_call"; + let func = "ReviveApi_call"; let params = scale::Encode::encode(&call_request); let bytes = self .rpc @@ -540,15 +521,15 @@ where /// contains all events that are associated with this transaction. pub async fn call( &self, - contract: MultiAddress, + contract: H160, value: E::Balance, gas_limit: Weight, - storage_deposit_limit: Option, + storage_deposit_limit: E::Balance, data: Vec, signer: &Keypair, ) -> ExtrinsicEvents { let call = subxt::tx::DefaultPayload::new( - "Contracts", + "Revive", "call", Call:: { dest: contract, @@ -563,6 +544,25 @@ where self.submit_extrinsic(&call, signer).await } + /// todo + /// Submits an extrinsic to call a contract with the given parameters. + /// + /// Returns when the transaction is included in a block. The return value + /// contains all events that are associated with this transaction. + pub async fn map_account( + &self, + signer: &Keypair, + ) -> ExtrinsicEvents { + let call = subxt::tx::DefaultPayload::new( + "Revive", + "map_account", + MapAccount{} + ) + .unvalidated(); + + self.submit_extrinsic(&call, signer).await + } + /// Submit an extrinsic `call_name` for the `pallet_name`. /// The `call_data` is a `Vec` that holds /// a representation of some value. diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml index 5afd2e36dc4..ae46dedd530 100644 --- a/crates/engine/Cargo.toml +++ b/crates/engine/Cargo.toml @@ -17,7 +17,6 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"] [dependencies] ink_primitives = { workspace = true } scale = { workspace = true } -pallet-contracts-uapi = { workspace = true } pallet-revive-uapi = { workspace = true } derive_more = { workspace = true, features = ["from", "display"] } @@ -36,4 +35,3 @@ std = [ "secp256k1", "derive_more/std" ] -revive = [] diff --git a/crates/engine/src/database.rs b/crates/engine/src/database.rs index 84604a60355..c145585ba91 100644 --- a/crates/engine/src/database.rs +++ b/crates/engine/src/database.rs @@ -12,24 +12,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::types::Balance; +use crate::types::{ + Balance, + H160, +}; +use ink_primitives::AccountId; use scale::KeyedVec; use std::collections::HashMap; const BALANCE_OF: &[u8] = b"balance:"; const STORAGE_OF: &[u8] = b"contract-storage:"; -/// Returns the database key under which to find the balance for account `who`. -pub fn balance_of_key(who: &[u8]) -> [u8; 32] { - let keyed = who.to_vec().to_keyed_vec(BALANCE_OF); +/// Returns the database key under which to find the balance for contract `who`. +pub fn balance_of_key(who: &H160) -> [u8; 32] { + let keyed = who.0.to_vec().to_keyed_vec(BALANCE_OF); let mut hashed_key: [u8; 32] = [0; 32]; super::hashing::blake2b_256(&keyed[..], &mut hashed_key); hashed_key } -/// Returns the database key under which to find the balance for account `who`. -pub fn storage_of_contract_key(who: &[u8], key: &[u8]) -> [u8; 32] { - let keyed = who.to_vec().to_keyed_vec(key).to_keyed_vec(STORAGE_OF); +/// Returns the database key under which to find the storage for contract `who`. +pub fn storage_of_contract_key(who: &H160, key: &[u8]) -> [u8; 32] { + let keyed = who + .as_bytes() + .to_vec() + .to_keyed_vec(key) + .to_keyed_vec(STORAGE_OF); let mut hashed_key: [u8; 32] = [0; 32]; super::hashing::blake2b_256(&keyed[..], &mut hashed_key); hashed_key @@ -37,7 +45,7 @@ pub fn storage_of_contract_key(who: &[u8], key: &[u8]) -> [u8; 32] { /// The chain database. /// -/// Everything is stored in here: accounts, balances, contract storage, etc.. +/// Everything is stored in here: contracts, balances, contract storage, etc. /// Just like in Substrate a prefix hash is computed for every contract. #[derive(Default)] pub struct Database { @@ -64,33 +72,29 @@ impl Database { } /// Returns a reference to the value corresponding to the key. - pub fn get_from_contract_storage( - &self, - account_id: &[u8], - key: &[u8], - ) -> Option<&Vec> { - let hashed_key = storage_of_contract_key(account_id, key); + pub fn get_from_contract_storage(&self, addr: &H160, key: &[u8]) -> Option<&Vec> { + let hashed_key = storage_of_contract_key(addr, key); self.hmap.get(hashed_key.as_slice()) } - /// Inserts `value` into the contract storage of `account_id` at storage key `key`. + /// Inserts `value` into the contract storage of `addr` at storage key `key`. pub fn insert_into_contract_storage( &mut self, - account_id: &[u8], + addr: &H160, key: &[u8], value: Vec, ) -> Option> { - let hashed_key = storage_of_contract_key(account_id, key); + let hashed_key = storage_of_contract_key(addr, key); self.hmap.insert(hashed_key.to_vec(), value) } - /// Removes the value at the contract storage of `account_id` at storage key `key`. + /// Removes the value at the contract storage of `addr` at storage key `key`. pub fn remove_contract_storage( &mut self, - account_id: &[u8], + addr: &H160, key: &[u8], ) -> Option> { - let hashed_key = storage_of_contract_key(account_id, key); + let hashed_key = storage_of_contract_key(addr, key); self.hmap.remove(hashed_key.as_slice()) } @@ -110,18 +114,27 @@ impl Database { self.hmap.clear(); } - /// Returns the balance of `account_id`, if available. - pub fn get_balance(&self, account_id: &[u8]) -> Option { - let hashed_key = balance_of_key(account_id); + /// Returns the balance of the contract at `addr`, if available. + pub fn get_acc_balance(&self, _addr: &AccountId) -> Option { + todo!() + } + + /// Sets the balance of `addr` to `new_balance`. + pub fn set_acc_balance(&mut self, _addr: &AccountId, _new_balance: Balance) { + todo!() + } + + pub fn get_balance(&self, addr: &H160) -> Option { + let hashed_key = balance_of_key(addr); self.get(&hashed_key).map(|encoded_balance| { scale::Decode::decode(&mut &encoded_balance[..]) .expect("unable to decode balance from database") }) } - /// Sets the balance of `account_id` to `new_balance`. - pub fn set_balance(&mut self, account_id: &[u8], new_balance: Balance) { - let hashed_key = balance_of_key(account_id); + /// Sets the balance of `addr` to `new_balance`. + pub fn set_balance(&mut self, addr: &H160, new_balance: Balance) { + let hashed_key = balance_of_key(addr); let encoded_balance = scale::Encode::encode(&new_balance); self.hmap .entry(hashed_key.to_vec()) @@ -133,6 +146,7 @@ impl Database { #[cfg(test)] mod tests { use super::Database; + use crate::types::H160; #[test] fn basic_operations() { @@ -159,7 +173,7 @@ mod tests { #[test] fn contract_storage() { - let account_id = vec![1; 32]; + let addr = H160::from([1; 20]); let mut storage = Database::new(); let key1 = vec![42]; let key2 = vec![43]; @@ -168,37 +182,25 @@ mod tests { let val3 = vec![46]; assert_eq!(storage.len(), 0); - assert_eq!(storage.get_from_contract_storage(&account_id, &key1), None); + assert_eq!(storage.get_from_contract_storage(&addr, &key1), None); assert_eq!( - storage.insert_into_contract_storage(&account_id, &key1, val1.clone()), + storage.insert_into_contract_storage(&addr, &key1, val1.clone()), None ); + assert_eq!(storage.get_from_contract_storage(&addr, &key1), Some(&val1)); assert_eq!( - storage.get_from_contract_storage(&account_id, &key1), - Some(&val1) - ); - assert_eq!( - storage.insert_into_contract_storage(&account_id, &key1, val2.clone()), + storage.insert_into_contract_storage(&addr, &key1, val2.clone()), Some(val1) ); + assert_eq!(storage.get_from_contract_storage(&addr, &key1), Some(&val2)); assert_eq!( - storage.get_from_contract_storage(&account_id, &key1), - Some(&val2) - ); - assert_eq!( - storage.insert_into_contract_storage(&account_id, &key2, val3.clone()), + storage.insert_into_contract_storage(&addr, &key2, val3.clone()), None ); assert_eq!(storage.len(), 2); - assert_eq!( - storage.remove_contract_storage(&account_id, &key2), - Some(val3) - ); + assert_eq!(storage.remove_contract_storage(&addr, &key2), Some(val3)); assert_eq!(storage.len(), 1); - assert_eq!( - storage.remove_contract_storage(&account_id, &key1), - Some(val2) - ); + assert_eq!(storage.remove_contract_storage(&addr, &key1), Some(val2)); assert_eq!(storage.len(), 0); } } diff --git a/crates/engine/src/exec_context.rs b/crates/engine/src/exec_context.rs index 4ee6daa50fe..a671734a595 100644 --- a/crates/engine/src/exec_context.rs +++ b/crates/engine/src/exec_context.rs @@ -13,10 +13,10 @@ // limitations under the License. use super::types::{ - AccountId, Balance, BlockNumber, BlockTimestamp, + H160, }; /// The context of a contract execution. @@ -25,18 +25,19 @@ use super::types::{ pub struct ExecContext { /// The caller of the contract execution. Might be user or another contract. /// + /// TODO check next comment /// We don't know the specifics of the `AccountId` ‒ like how many bytes or what /// type of default `AccountId` makes sense ‒ they are left to be initialized /// by the crate which uses the `engine`. Methods which require a caller might /// panic when it has not been set. - pub caller: Option, + pub caller: H160, /// The callee of the contract execution. Might be user or another contract. /// /// We don't know the specifics of the `AccountId` ‒ like how many bytes or what /// type of default `AccountId` makes sense ‒ they are left to be initialized /// by the crate which uses the `engine`. Methods which require a callee might /// panic when it has not been set. - pub callee: Option, + pub callee: Option, /// The value transferred to the contract as part of the call. pub value_transferred: Balance, /// The current block number. @@ -44,7 +45,7 @@ pub struct ExecContext { /// The current block timestamp. pub block_timestamp: BlockTimestamp, /// Known contract accounts - pub contracts: Vec>, + pub contracts: Vec, // todo use H160 } impl ExecContext { @@ -54,12 +55,8 @@ impl ExecContext { } /// Returns the callee. - pub fn callee(&self) -> Vec { - self.callee - .as_ref() - .expect("no callee has been set") - .as_bytes() - .into() + pub fn callee(&self) -> H160 { + self.callee.expect("no callee has been set") } /// Resets the execution context @@ -80,19 +77,17 @@ impl ExecContext { #[cfg(test)] mod tests { - use super::{ - AccountId, - ExecContext, - }; + use super::ExecContext; + use crate::types::H160; #[test] fn basic_operations() { let mut exec_cont = ExecContext::new(); - exec_cont.callee = Some(AccountId::from_bytes(&[13])); - exec_cont.caller = Some(AccountId::from_bytes(&[14])); + exec_cont.callee = Some(H160::from([13; 20])); + exec_cont.caller = H160::from([14; 20]); exec_cont.value_transferred = 15; - assert_eq!(exec_cont.callee(), vec![13]); + assert_eq!(exec_cont.callee(), H160::from([13; 20])); exec_cont.reset(); diff --git a/crates/engine/src/ext.rs b/crates/engine/src/ext.rs index 3184c5e1520..4dca2f21ff3 100644 --- a/crates/engine/src/ext.rs +++ b/crates/engine/src/ext.rs @@ -26,9 +26,9 @@ use crate::{ EmittedEvent, }, types::{ - AccountId, Balance, BlockTimestamp, + H160, }, }; pub use pallet_revive_uapi::ReturnErrorCode as Error; @@ -73,7 +73,7 @@ impl Default for ChainSpec { fn default() -> Self { Self { gas_price: 100, - minimum_balance: 1000000, + minimum_balance: 42, block_time: 6, } } @@ -100,18 +100,18 @@ impl Default for Engine { impl Engine { /// Transfers value from the contract to the destination account. - pub fn transfer(&mut self, account_id: &[u8], mut value: &[u8]) -> Result<(), Error> { + #[allow(clippy::arithmetic_side_effects)] // todo + pub fn transfer(&mut self, dest: H160, mut value: &[u8]) -> Result<(), Error> { // Note that a transfer of `0` is allowed here let increment = ::decode(&mut value) .map_err(|_| Error::TransferFailed)?; - let dest = account_id.to_vec(); // Note that the destination account does not have to exist - let dest_old_balance = self.get_balance(dest.clone()).unwrap_or_default(); + let dest_old_balance = self.get_balance(dest).unwrap_or_default(); let contract = self.get_callee(); let contract_old_balance = self - .get_balance(contract.clone()) + .get_balance(contract) .map_err(|_| Error::TransferFailed)?; self.database @@ -122,6 +122,7 @@ impl Engine { } /// Deposits an event identified by the supplied topics and data. + #[allow(clippy::arithmetic_side_effects)] // todo pub fn deposit_event(&mut self, topics: &[u8], data: &[u8]) { // The first byte contains the number of topics in the slice let topics_count: scale::Compact = scale::Decode::decode(&mut &topics[0..1]) @@ -152,11 +153,10 @@ impl Engine { /// Returns the size of the previously stored value at the key if any. pub fn set_storage(&mut self, key: &[u8], encoded_value: &[u8]) -> Option { let callee = self.get_callee(); - let account_id = AccountId::from_bytes(&callee[..]); - self.debug_info.inc_writes(account_id.clone()); + self.debug_info.inc_writes(callee); self.debug_info - .record_cell_for_account(account_id, key.to_vec()); + .record_cell_for_account(callee, key.to_vec()); self.database .insert_into_contract_storage(&callee, key, encoded_value.to_vec()) @@ -166,9 +166,8 @@ impl Engine { /// Returns the contract storage bytes at the key if any. pub fn get_storage(&mut self, key: &[u8]) -> Result<&[u8], Error> { let callee = self.get_callee(); - let account_id = AccountId::from_bytes(&callee[..]); - self.debug_info.inc_reads(account_id); + self.debug_info.inc_reads(callee); match self.database.get_from_contract_storage(&callee, key) { Some(val) => Ok(val), None => Err(Error::KeyNotFound), @@ -179,9 +178,8 @@ impl Engine { /// returning previously stored value at the key if any. pub fn take_storage(&mut self, key: &[u8]) -> Result, Error> { let callee = self.get_callee(); - let account_id = AccountId::from_bytes(&callee[..]); - self.debug_info.inc_writes(account_id); + self.debug_info.inc_writes(callee); match self.database.remove_contract_storage(&callee, key) { Some(val) => Ok(val), None => Err(Error::KeyNotFound), @@ -191,9 +189,8 @@ impl Engine { /// Returns the size of the value stored in the contract storage at the key if any. pub fn contains_storage(&mut self, key: &[u8]) -> Option { let callee = self.get_callee(); - let account_id = AccountId::from_bytes(&callee[..]); - self.debug_info.inc_reads(account_id); + self.debug_info.inc_reads(callee); self.database .get_from_contract_storage(&callee, key) .map(|val| val.len() as u32) @@ -203,11 +200,10 @@ impl Engine { /// Returns the size of the previously stored value at the key if any. pub fn clear_storage(&mut self, key: &[u8]) -> Option { let callee = self.get_callee(); - let account_id = AccountId::from_bytes(&callee[..]); - self.debug_info.inc_writes(account_id.clone()); + self.debug_info.inc_writes(callee); let _ = self .debug_info - .remove_cell_for_account(account_id, key.to_vec()); + .remove_cell_for_account(callee, key.to_vec()); self.database .remove_contract_storage(&callee, key) .map(|val| val.len() as u32) @@ -215,10 +211,11 @@ impl Engine { /// Remove the calling account and transfer remaining balance. /// + /// todo is the following comment still correct? /// This function never returns. Either the termination was successful and the /// execution of the destroyed contract is halted. Or it failed during the /// termination which is considered fatal. - pub fn terminate(&mut self, beneficiary: &[u8]) -> ! { + pub fn terminate(&mut self, beneficiary: H160) -> ! { // Send the remaining balance to the beneficiary let contract = self.get_callee(); let all = self @@ -231,19 +228,15 @@ impl Engine { // Encode the result of the termination and panic with it. // This enables testing for the proper result and makes sure this // method returns `Never`. - let res = (all, beneficiary.to_vec()); + let res = (all, beneficiary); panic_any(scale::Encode::encode(&res)); } /// Returns the address of the caller. pub fn caller(&self, output: &mut &mut [u8]) { - let caller = self - .exec_context - .caller - .as_ref() - .expect("no caller has been set") - .as_bytes(); - set_output(output, caller); + let caller = self.exec_context.caller; + let caller = scale::Encode::encode(&caller); + set_output(output, &caller[..]) } /// Returns the balance of the executed contract. @@ -256,7 +249,7 @@ impl Engine { let balance_in_storage = self .database - .get_balance(contract.as_bytes()) + .get_balance(contract) .expect("currently executing contract must exist"); let balance = scale::Encode::encode(&balance_in_storage); set_output(output, &balance[..]) @@ -383,6 +376,7 @@ impl Engine { /// Recovers the compressed ECDSA public key for given `signature` and `message_hash`, /// and stores the result in `output`. + #[allow(clippy::arithmetic_side_effects)] // todo pub fn ecdsa_recover( &mut self, signature: &[u8; 65], diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 5155af87a2f..0aa3afb822f 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -30,7 +30,10 @@ mod types; mod tests; pub use chain_extension::ChainExtension; -pub use types::AccountError; +pub use types::{ + AccountError, + // Origin, +}; use derive_more::From; diff --git a/crates/engine/src/test_api.rs b/crates/engine/src/test_api.rs index 460faf774ad..9bd622ba2c0 100644 --- a/crates/engine/src/test_api.rs +++ b/crates/engine/src/test_api.rs @@ -15,14 +15,15 @@ use crate::{ ext::Engine, types::{ - AccountId, Balance, BlockNumber, BlockTimestamp, + H160, }, AccountError, Error, }; +use ink_primitives::AccountId; use std::collections::HashMap; /// Record for an emitted event. @@ -80,11 +81,11 @@ pub struct DebugInfo { /// Emitted print messages recorder. emitted_debug_messages: RecordedDebugMessages, /// The total number of reads to the storage. - count_reads: HashMap, + count_reads: HashMap, /// The total number of writes to the storage. - count_writes: HashMap, - /// The number of storage cells used by each account id. - cells_per_account: HashMap, bool>>, + count_writes: HashMap, + /// The number of storage cells used by each contract. + cells_per_contract: HashMap, bool>>, } impl Default for DebugInfo { @@ -101,7 +102,7 @@ impl DebugInfo { emitted_debug_messages: RecordedDebugMessages::new(), count_reads: HashMap::new(), count_writes: HashMap::new(), - cells_per_account: HashMap::new(), + cells_per_contract: HashMap::new(), } } @@ -111,21 +112,23 @@ impl DebugInfo { self.count_writes.clear(); self.emitted_events.clear(); self.emitted_debug_messages.clear(); - self.cells_per_account.clear(); + self.cells_per_contract.clear(); } /// Increases the number of storage writes for the supplied account by one. - pub fn inc_writes(&mut self, account_id: AccountId) { + #[allow(clippy::arithmetic_side_effects)] // todo + pub fn inc_writes(&mut self, addr: H160) { self.count_writes - .entry(account_id) + .entry(addr) .and_modify(|v| *v += 1) .or_insert(1); } /// Increases the number of storage reads for the supplied account by one. - pub fn inc_reads(&mut self, account_id: AccountId) { + #[allow(clippy::arithmetic_side_effects)] // todo + pub fn inc_reads(&mut self, addr: H160) { self.count_reads - .entry(account_id) + .entry(addr) .and_modify(|v| *v += 1) .or_insert(1); } @@ -134,9 +137,9 @@ impl DebugInfo { /// /// Calling this function multiple times won't change the fact that only /// one cell is recorded. - pub fn record_cell_for_account(&mut self, account_id: AccountId, key: Vec) { - self.cells_per_account - .entry(account_id) + pub fn record_cell_for_account(&mut self, addr: H160, key: Vec) { + self.cells_per_contract + .entry(addr) .and_modify(|hm| { let _ = hm.insert(key.clone(), true); }) @@ -150,13 +153,9 @@ impl DebugInfo { /// Removes the cell under `key` for the supplied account. /// /// Returns the removed cell, if there was one. - pub fn remove_cell_for_account( - &mut self, - account_id: AccountId, - key: Vec, - ) -> Option { - self.cells_per_account - .get_mut(&account_id) + pub fn remove_cell_for_account(&mut self, addr: H160, key: Vec) -> Option { + self.cells_per_contract + .get_mut(&addr) .map(|hm| hm.remove(&key)) .unwrap_or(None) } @@ -181,10 +180,9 @@ impl Engine { } /// Returns the total number of reads and writes of the contract's storage. - pub fn get_contract_storage_rw(&self, account_id: Vec) -> (usize, usize) { - let account_id = AccountId::from(account_id); - let reads = self.debug_info.count_reads.get(&account_id).unwrap_or(&0); - let writes = self.debug_info.count_writes.get(&account_id).unwrap_or(&0); + pub fn get_contract_storage_rw(&self, addr: H160) -> (usize, usize) { + let reads = self.debug_info.count_reads.get(&addr).unwrap_or(&0); + let writes = self.debug_info.count_writes.get(&addr).unwrap_or(&0); (*reads, *writes) } @@ -199,48 +197,47 @@ impl Engine { } /// Sets a caller for the next call. - pub fn set_caller(&mut self, caller: Vec) { - self.exec_context.caller = Some(caller.into()); + pub fn set_caller(&mut self, caller: H160) { + self.exec_context.caller = caller; } /// Sets a known contract by adding it to a vector of known contracts accounts - pub fn set_contract(&mut self, caller: Vec) { + pub fn set_contract(&mut self, caller: H160) { self.exec_context.contracts.push(caller); } /// Sets the callee for the next call. - pub fn set_callee(&mut self, callee: Vec) { - self.exec_context.callee = Some(callee.into()); + pub fn set_callee(&mut self, callee: H160) { + self.exec_context.callee = Some(callee); } - /// Returns the amount of storage cells used by the account `account_id`. + /// Returns the amount of storage cells used by the contract `addr`. /// - /// Returns `None` if the `account_id` is non-existent. - pub fn count_used_storage_cells(&self, account_id: &[u8]) -> Result { + /// Returns `None` if the contract `addr` is non-existent. + pub fn count_used_storage_cells(&self, addr: &H160) -> Result { let cells = self .debug_info - .cells_per_account - .get(&account_id.to_owned().into()) - .ok_or_else(|| { - Error::Account(AccountError::NoAccountForId(account_id.to_vec())) - })?; + .cells_per_contract + .get(addr) + .ok_or(Error::Account(AccountError::NoContractForId(*addr)))?; Ok(cells.len()) } /// Advances the chain by a single block. + #[allow(clippy::arithmetic_side_effects)] // todo pub fn advance_block(&mut self) { self.exec_context.block_number += 1; self.exec_context.block_timestamp += self.chain_spec.block_time; } /// Returns the callee, i.e. the currently executing contract. - pub fn get_callee(&self) -> Vec { + pub fn get_callee(&self) -> H160 { self.exec_context.callee() } /// Returns boolean value indicating whether the account is a contract - pub fn is_contract(&self, account_id: Vec) -> bool { - self.exec_context.contracts.contains(&account_id) + pub fn is_contract(&self, addr: &H160) -> bool { + self.exec_context.contracts.contains(addr) } /// Returns the contents of the past performed environmental `debug_message` in order. @@ -253,16 +250,28 @@ impl Engine { self.debug_info.emitted_events.clone().into_iter() } - /// Returns the current balance of `account_id`. - pub fn get_balance(&self, account_id: Vec) -> Result { + /// Returns the current balance of `addr`. + pub fn get_acc_balance(&self, addr: AccountId) -> Result { self.database - .get_balance(&account_id) - .ok_or(Error::Account(AccountError::NoAccountForId(account_id))) + .get_acc_balance(&addr) + .ok_or(Error::Account(AccountError::NoAccountForId(addr))) } - /// Sets the balance of `account_id` to `new_balance`. - pub fn set_balance(&mut self, account_id: Vec, new_balance: Balance) { - self.database.set_balance(&account_id, new_balance); + /// Sets the balance of `addr` to `new_balance`. + pub fn set_acc_balance(&mut self, addr: AccountId, new_balance: Balance) { + self.database.set_acc_balance(&addr, new_balance); + } + + /// Returns the current balance of `addr`. + pub fn get_balance(&self, addr: H160) -> Result { + self.database + .get_balance(&addr) + .ok_or(Error::Account(AccountError::NoContractForId(addr))) + } + + /// Sets the balance of `addr` to `new_balance`. + pub fn set_balance(&mut self, addr: H160, new_balance: Balance) { + self.database.set_balance(&addr, new_balance); } /// Sets the value transferred from the caller to the callee as part of the call. @@ -288,20 +297,20 @@ mod tests { #[test] fn setting_getting_callee() { let mut engine = Engine::new(); - let account_id = vec![1; 32]; - engine.set_callee(account_id.clone()); - assert_eq!(engine.get_callee(), account_id); + let addr = H160::from([1; 20]); + engine.set_callee(addr); + assert_eq!(engine.get_callee(), addr); } #[test] fn count_cells_per_account_must_stay_the_same() { // given let mut engine = Engine::new(); - let account_id = vec![1; 32]; - engine.set_callee(account_id.clone()); + let addr = H160::from([1; 20]); + engine.set_callee(addr); let key: &[u8; 32] = &[0x42; 32]; engine.set_storage(key, &[0x05_u8; 5]); - assert_eq!(engine.count_used_storage_cells(&account_id), Ok(1)); + assert_eq!(engine.count_used_storage_cells(&addr), Ok(1)); // when // we set the storage a second time @@ -309,24 +318,24 @@ mod tests { // then // the amount of storage cells used must have stayed the same - assert_eq!(engine.count_used_storage_cells(&account_id), Ok(1)); + assert_eq!(engine.count_used_storage_cells(&addr), Ok(1)); } #[test] fn count_cells_per_account_must_be_reset() { // given let mut engine = Engine::new(); - let account_id = vec![1; 32]; - engine.set_callee(account_id.clone()); + let addr = H160::from([1; 20]); + engine.set_callee(addr); let key: &[u8; 32] = &[0x42; 32]; engine.set_storage(key, &[0x05_u8; 5]); - assert_eq!(engine.count_used_storage_cells(&account_id), Ok(1)); + assert_eq!(engine.count_used_storage_cells(&addr), Ok(1)); // when engine.clear_storage(key); // then - assert_eq!(engine.count_used_storage_cells(&account_id), Ok(0)); + assert_eq!(engine.count_used_storage_cells(&addr), Ok(0)); } #[test] @@ -336,12 +345,12 @@ mod tests { let key: &[u8; 32] = &[0x42; 32]; // when - engine.set_callee(vec![1; 32]); + engine.set_callee(H160::from([1; 20])); engine.set_storage(key, &[0x05_u8; 5]); engine.set_storage(key, &[0x05_u8; 6]); engine.get_storage(key).unwrap(); - engine.set_callee(vec![2; 32]); + engine.set_callee(H160::from([2; 20])); engine.set_storage(key, &[0x07_u8; 7]); engine.get_storage(key).unwrap(); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index afcdb507b04..5be2f5ee597 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -12,9 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::ext::{ - Engine, - Error, +use crate::{ + ext::{ + Engine, + Error, + }, + types::H160, }; use secp256k1::{ ecdsa::RecoverableSignature, @@ -38,7 +41,7 @@ fn get_buffer() -> [u8; 1024] { #[test] fn store_load_clear() { let mut engine = Engine::new(); - engine.set_callee(vec![1; 32]); + engine.set_callee(H160::from([1; 20])); let key: &[u8; 32] = &[0x42; 32]; let res = engine.get_storage(key); assert_eq!(res, Err(Error::KeyNotFound)); @@ -57,10 +60,10 @@ fn store_load_clear() { fn setting_getting_balance() { // given let mut engine = Engine::new(); - let account_id = vec![1; 32]; + let addr = H160::from([1; 20]); let balance = 1337; - engine.set_callee(account_id.clone()); - engine.set_balance(account_id, balance); + engine.set_callee(addr); + engine.set_balance(addr, balance); // when let mut output = get_buffer(); @@ -76,44 +79,45 @@ fn setting_getting_balance() { fn setting_getting_caller() { // given let mut engine = Engine::new(); - let account_id = vec![1; 32]; + let caller = H160::from([1u8; 20]); // when - engine.set_caller(account_id.clone()); + engine.set_caller(caller); // then let mut output = get_buffer(); engine.caller(&mut &mut output[..]); - assert_eq!(&output[..account_id.len()], &account_id); + let val = scale::Encode::encode(&caller); + assert!(&output[..val.len()].eq(val.as_slice())); } #[test] fn address() { // given let mut engine = Engine::new(); - let account_id = vec![1; 32]; - engine.set_callee(account_id.clone()); + let addr = H160::from([1; 20]); + engine.set_callee(addr); // when let mut output = get_buffer(); engine.address(&mut &mut output[..]); // then - assert_eq!(&output[..account_id.len()], &account_id); + assert!(&output[..20].eq(addr.as_bytes())); } #[test] fn transfer() { // given let mut engine = Engine::new(); - let alice = vec![1; 32]; - let bob = vec![2; 32]; - engine.set_callee(alice.clone()); - engine.set_balance(alice.clone(), 1337); + let alice = H160::from([1; 20]); + let bob = H160::from([2; 20]); + engine.set_callee(alice); + engine.set_balance(alice, 1337); // when let val = scale::Encode::encode(&337u128); - assert_eq!(engine.transfer(&bob, &val), Ok(())); + assert_eq!(engine.transfer(bob, &val), Ok(())); // then assert_eq!(engine.get_balance(alice), Ok(1000)); diff --git a/crates/engine/src/types.rs b/crates/engine/src/types.rs index 131db420809..fcc826e0b26 100644 --- a/crates/engine/src/types.rs +++ b/crates/engine/src/types.rs @@ -16,6 +16,8 @@ //! This is a known limitation that we want to address in the future. use derive_more::From; +use ink_primitives::AccountId; +pub use ink_primitives::H160; /// Same type as the `DefaultEnvironment::BlockNumber` type. pub type BlockNumber = u32; @@ -26,23 +28,6 @@ pub type BlockTimestamp = u64; /// Same type as the `DefaultEnvironment::Balance` type. pub type Balance = u128; -/// The Account Id type used by this crate. -#[derive(Debug, From, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[repr(transparent)] -pub struct AccountId(Vec); - -impl AccountId { - /// Creates a new `AccountId` from the given raw bytes. - pub fn from_bytes(bytes: &[u8]) -> Self { - Self(bytes.to_vec()) - } - - /// Returns the `AccountId` as bytes. - pub fn as_bytes(&self) -> &[u8] { - &self.0[..] - } -} - /// Key into the database. /// /// Used to identify contract storage cells for read and write operations. @@ -58,6 +43,7 @@ impl Key { } } +// todo rename the whole thing /// Errors encountered upon interacting with accounts. #[derive(Clone, Debug, From, PartialEq, Eq)] pub enum AccountError { @@ -65,5 +51,30 @@ pub enum AccountError { #[from(ignore)] UnexpectedUserAccount, #[from(ignore)] - NoAccountForId(Vec), + NoAccountForId(AccountId), + NoContractForId(H160), +} + +/// The type of origins supported by `pallet-revive`. +#[derive(Debug, Eq, Default, Clone, scale::Encode, scale::Decode, PartialEq)] +//#[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] +pub enum Origin { + #[default] + Root, + Signed(Vec), } + +// impl Origin { +// Returns the AccountId of a Signed Origin or an error if the origin is Root. +// pub fn account_id(&self) -> Result { +// match self { +// Origin::Signed(id) => { +// let mut arr = [0u8; 32]; +// arr.copy_from_slice(id.as_slice()); +// Ok(AccountId::from(arr)) +// }, +// Origin::Root => Err(()), +// } +// } +// } +// diff --git a/crates/env/Cargo.toml b/crates/env/Cargo.toml index ac23f175042..b56ab244c2d 100644 --- a/crates/env/Cargo.toml +++ b/crates/env/Cargo.toml @@ -20,7 +20,6 @@ ink_allocator = { workspace = true } ink_storage_traits = { workspace = true } ink_prelude = { workspace = true } ink_primitives = { workspace = true } -pallet-contracts-uapi = { workspace = true } pallet-revive-uapi = { workspace = true } scale = { workspace = true, features = ["max-encoded-len"] } @@ -33,16 +32,13 @@ const_env = { workspace = true } xcm = { workspace = true } # We add the `sp-io` here to disable those features -sp-io = { version = "38.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } +sp-io = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } +sp-runtime-interface = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false, features = ["disable_target_static_assertions"] } -[target.'cfg(target_arch = "wasm32")'.dependencies] -rlibc = "1" - -[target.'cfg(target_arch = "riscv32")'.dependencies] +[target.'cfg(target_arch = "riscv64")'.dependencies] polkavm-derive = { workspace = true, default-features = false } -# TODO -[target.'cfg(all(not(target_arch = "wasm32"), not(target_arch = "riscv32")))'.dependencies] +[target.'cfg(not(target_arch = "riscv64"))'.dependencies] ink_engine = { workspace = true, default-features = true, optional = true } # Hashes for the off-chain environment. @@ -101,7 +97,3 @@ no-allocator = [ "ink_allocator/no-allocator" ] # Disable the ink! provided panic handler. no-panic-handler = [] - -revive = [ - "ink_engine/revive" -] diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index f5bdb056972..680ccc842e8 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -25,7 +25,7 @@ use crate::{ ConstructorReturnType, CreateParams, DelegateCall, - FromAccountId, + FromAddr, LimitParamsV2, }, engine::{ @@ -41,6 +41,7 @@ use crate::{ Environment, Result, }; +use ink_primitives::{H160, H256, U256}; use ink_storage_traits::Storable; use pallet_revive_uapi::ReturnFlags; @@ -49,13 +50,8 @@ use pallet_revive_uapi::ReturnFlags; /// # Errors /// /// If the returned caller cannot be properly decoded. -pub fn caller() -> E::AccountId -where - E: Environment, -{ - ::on_instance(|instance| { - TypedEnvBackend::caller::(instance) - }) +pub fn caller() -> H160 { + ::on_instance(TypedEnvBackend::caller) } /// Returns the transferred value for the contract execution. @@ -63,12 +59,10 @@ where /// # Errors /// /// If the returned value cannot be properly decoded. -pub fn transferred_value() -> E::Balance -where - E: Environment, +pub fn transferred_value() -> U256 { ::on_instance(|instance| { - TypedEnvBackend::transferred_value::(instance) + TypedEnvBackend::transferred_value(instance) }) } @@ -118,6 +112,18 @@ where }) } +/// Returns the address of the executed contract. +/// +/// # Errors +/// +/// If the returned value cannot be properly decoded. +pub fn address() -> H160 +{ + ::on_instance(|instance| { + TypedEnvBackend::address(instance) + }) +} + /// Returns the balance of the executed contract. /// /// # Errors @@ -290,7 +296,7 @@ where /// - If arguments passed to the called code message are invalid. /// - If the called code execution has trapped. pub fn invoke_contract_delegate( - params: &CallParams, Args, R>, + params: &CallParams, ) -> Result> where E: Environment, @@ -328,7 +334,7 @@ pub fn instantiate_contract( > where E: Environment, - ContractRef: FromAccountId, + ContractRef: FromAddr, Args: scale::Encode, Salt: AsRef<[u8]>, R: ConstructorReturnType, @@ -350,12 +356,9 @@ where /// This function never returns. Either the termination was successful and the /// execution of the destroyed contract is halted. Or it failed during the termination /// which is considered fatal and results in a trap and rollback. -pub fn terminate_contract(beneficiary: E::AccountId) -> ! -where - E: Environment, -{ +pub fn terminate_contract(beneficiary: H160) -> ! { ::on_instance(|instance| { - TypedEnvBackend::terminate_contract::(instance, beneficiary) + TypedEnvBackend::terminate_contract(instance, beneficiary) }) } @@ -372,7 +375,7 @@ where /// - If the contract does not have sufficient free funds. /// - If the transfer had brought the sender's total balance below the minimum balance. /// You need to use [`terminate_contract`] in case this is your intention. -pub fn transfer(destination: E::AccountId, value: E::Balance) -> Result<()> +pub fn transfer(destination: H160, value: E::Balance) -> Result<()> where E: Environment, { @@ -584,12 +587,9 @@ pub fn sr25519_verify( /// # Errors /// /// If the returned value cannot be properly decoded. -pub fn is_contract(account: &E::AccountId) -> bool -where - E: Environment, -{ +pub fn is_contract(account: &H160) -> bool { ::on_instance(|instance| { - TypedEnvBackend::is_contract::(instance, account) + TypedEnvBackend::is_contract(instance, account) }) } @@ -599,12 +599,9 @@ where /// /// - If no code hash was found for the specified account id. /// - If the returned value cannot be properly decoded. -pub fn code_hash(account: &E::AccountId) -> Result -where - E: Environment, -{ +pub fn code_hash(addr: &H160) -> Result { ::on_instance(|instance| { - TypedEnvBackend::code_hash::(instance, account) + TypedEnvBackend::code_hash(instance, addr) }) } @@ -613,7 +610,7 @@ where /// # Errors /// /// If the returned value cannot be properly decoded. -pub fn own_code_hash() -> Result +pub fn own_code_hash() -> Result where E: Environment, { @@ -764,7 +761,7 @@ where /// Please refer to the /// [Open Zeppelin docs](https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#modifying-your-contracts) /// for more details and examples. -pub fn set_code_hash(code_hash: &E::Hash) -> Result<()> +pub fn set_code_hash(code_hash: &H256) -> Result<()> where E: Environment, { @@ -812,7 +809,7 @@ where /// - If the `code_hash` is the same as the calling contract. /// - If the maximum number of delegate dependencies is reached. /// - If the delegate dependency already exists. -pub fn lock_delegate_dependency(code_hash: &E::Hash) +pub fn lock_delegate_dependency(code_hash: &H256) where E: Environment, { @@ -830,7 +827,7 @@ where /// # Errors /// /// - If the delegate dependency does not exist. -pub fn unlock_delegate_dependency(code_hash: &E::Hash) +pub fn unlock_delegate_dependency(code_hash: &H256) where E: Environment, { diff --git a/crates/env/src/backend.rs b/crates/env/src/backend.rs index e1cfde3a458..98222f6de72 100644 --- a/crates/env/src/backend.rs +++ b/crates/env/src/backend.rs @@ -19,7 +19,7 @@ use crate::{ ConstructorReturnType, CreateParams, DelegateCall, - FromAccountId, + FromAddr, LimitParamsV2, }, event::Event, @@ -30,6 +30,7 @@ use crate::{ Environment, Result, }; +use ink_primitives::{H160, H256, U256}; use ink_storage_traits::Storable; pub use pallet_revive_uapi::ReturnFlags; @@ -222,14 +223,14 @@ pub trait TypedEnvBackend: EnvBackend { /// # Note /// /// For more details visit: [`caller`][`crate::caller`] - fn caller(&mut self) -> E::AccountId; + fn caller(&mut self) -> H160; /// Returns the transferred value for the contract execution. /// /// # Note /// /// For more details visit: [`transferred_value`][`crate::transferred_value`] - fn transferred_value(&mut self) -> E::Balance; + fn transferred_value(&mut self) -> U256; /// Returns the price for the specified amount of gas. /// @@ -252,6 +253,13 @@ pub trait TypedEnvBackend: EnvBackend { /// For more details visit: [`account_id`][`crate::account_id`] fn account_id(&mut self) -> E::AccountId; + /// Returns the address of the executed contract. + /// + /// # Note + /// + /// For more details visit: [`address`][`crate::address`] + fn address(&mut self) -> H160; + /// Returns the balance of the executed contract. /// /// # Note @@ -308,7 +316,7 @@ pub trait TypedEnvBackend: EnvBackend { /// [`invoke_contract_delegate`][`crate::invoke_contract_delegate`] fn invoke_contract_delegate( &mut self, - call_data: &CallParams, Args, R>, + call_data: &CallParams, ) -> Result> where E: Environment, @@ -330,7 +338,7 @@ pub trait TypedEnvBackend: EnvBackend { > where E: Environment, - ContractRef: FromAccountId, + ContractRef: FromAddr, Args: scale::Encode, Salt: AsRef<[u8]>, R: ConstructorReturnType; @@ -340,28 +348,24 @@ pub trait TypedEnvBackend: EnvBackend { /// # Note /// /// For more details visit: [`terminate_contract`][`crate::terminate_contract`] - fn terminate_contract(&mut self, beneficiary: E::AccountId) -> ! - where - E: Environment; + fn terminate_contract(&mut self, beneficiary: H160) -> !; /// Transfers value from the contract to the destination account ID. /// /// # Note /// /// For more details visit: [`transfer`][`crate::transfer`] - fn transfer(&mut self, destination: E::AccountId, value: E::Balance) -> Result<()> + fn transfer(&mut self, destination: H160, value: E::Balance) -> Result<()> where E: Environment; - /// Checks whether a specified account belongs to a contract. + /// Checks whether a specified contract lives at `addr`. /// /// # Note /// /// For more details visit: [`is_contract`][`crate::is_contract`] #[allow(clippy::wrong_self_convention)] - fn is_contract(&mut self, account: &E::AccountId) -> bool - where - E: Environment; + fn is_contract(&mut self, account: &H160) -> bool; /// Checks whether the caller of the current contract is the origin of the whole call /// stack. @@ -387,16 +391,14 @@ pub trait TypedEnvBackend: EnvBackend { /// # Note /// /// For more details visit: [`code_hash`][`crate::code_hash`] - fn code_hash(&mut self, account: &E::AccountId) -> Result - where - E: Environment; + fn code_hash(&mut self, account: &H160) -> Result; /// Retrieves the code hash of the currently executing contract. /// /// # Note /// /// For more details visit: [`own_code_hash`][`crate::own_code_hash`] - fn own_code_hash(&mut self) -> Result + fn own_code_hash(&mut self) -> Result where E: Environment; @@ -411,7 +413,7 @@ pub trait TypedEnvBackend: EnvBackend { /// /// For more details visit: /// [`lock_delegate_dependency`][`crate::lock_delegate_dependency`] - fn lock_delegate_dependency(&mut self, code_hash: &E::Hash) + fn lock_delegate_dependency(&mut self, code_hash: &H256) where E: Environment; @@ -421,7 +423,7 @@ pub trait TypedEnvBackend: EnvBackend { /// /// For more details visit: /// [`unlock_delegate_dependency`][`crate::unlock_delegate_dependency`]. - fn unlock_delegate_dependency(&mut self, code_hash: &E::Hash) + fn unlock_delegate_dependency(&mut self, code_hash: &H256) where E: Environment; diff --git a/crates/env/src/call/call_builder/call.rs b/crates/env/src/call/call_builder/call.rs index 45b0462b03b..98f24b335de 100644 --- a/crates/env/src/call/call_builder/call.rs +++ b/crates/env/src/call/call_builder/call.rs @@ -28,7 +28,7 @@ use crate::{ Error, Gas, }; -use num_traits::Zero; +use ink_primitives::{H160, U256}; use pallet_revive_uapi::CallFlags; /// The default call type for cross-contract calls, for calling into the latest `call_v2` @@ -36,23 +36,23 @@ use pallet_revive_uapi::CallFlags; /// well as `storage_deposit_limit`. #[derive(Clone)] pub struct Call { - callee: E::AccountId, + callee: H160, ref_time_limit: u64, proof_size_limit: u64, - storage_deposit_limit: Option, - transferred_value: E::Balance, + storage_deposit_limit: Option, // todo + transferred_value: U256, call_flags: CallFlags, } impl Call { /// Returns a clean builder for [`Call`]. - pub fn new(callee: E::AccountId) -> Self { + pub fn new(callee: H160) -> Self { Self { callee, ref_time_limit: Default::default(), proof_size_limit: Default::default(), storage_deposit_limit: None, - transferred_value: E::Balance::zero(), + transferred_value: U256::zero(), call_flags: CallFlags::empty(), } } @@ -121,7 +121,7 @@ where /// /// This value specifies the amount of user funds that are transferred /// to the other contract with this call. - pub fn transferred_value(self, transferred_value: E::Balance) -> Self { + pub fn transferred_value(self, transferred_value: U256) -> Self { let call_type = self.call_type.value(); CallBuilder { call_type: Set(Call { @@ -246,9 +246,9 @@ impl CallParams, Args, R> where E: Environment, { - /// Returns the account ID of the called contract instance. + /// Returns the contract address of the called contract instance. #[inline] - pub fn callee(&self) -> &E::AccountId { + pub fn callee(&self) -> &H160 { &self.call_type.callee } @@ -265,6 +265,7 @@ where } /// Returns the chosen storage deposit limit for the called contract execution. + /// todo #[inline] pub fn storage_deposit_limit(&self) -> Option<&E::Balance> { self.call_type.storage_deposit_limit.as_ref() @@ -272,7 +273,7 @@ where /// Returns the transferred value for the called contract. #[inline] - pub fn transferred_value(&self) -> &E::Balance { + pub fn transferred_value(&self) -> &U256 { &self.call_type.transferred_value } diff --git a/crates/env/src/call/call_builder/delegate.rs b/crates/env/src/call/call_builder/delegate.rs index e4cbb19c173..9b730820178 100644 --- a/crates/env/src/call/call_builder/delegate.rs +++ b/crates/env/src/call/call_builder/delegate.rs @@ -27,18 +27,19 @@ use crate::{ Environment, Error, }; +use ink_primitives::H256; use pallet_revive_uapi::CallFlags; /// The `delegatecall` call type. Performs a call with the given code hash. #[derive(Clone)] -pub struct DelegateCall { - code_hash: E::Hash, +pub struct DelegateCall { + code_hash: H256, call_flags: CallFlags, } -impl DelegateCall { +impl DelegateCall { /// Returns a clean builder for [`DelegateCall`] - pub const fn new(code_hash: E::Hash) -> Self { + pub const fn new(code_hash: H256) -> Self { DelegateCall { code_hash, call_flags: CallFlags::empty(), @@ -46,7 +47,7 @@ impl DelegateCall { } /// Sets the `code_hash` to perform a delegate call with. - pub fn code_hash(self, code_hash: E::Hash) -> Self { + pub fn code_hash(self, code_hash: H256) -> Self { DelegateCall { code_hash, call_flags: CallFlags::empty(), @@ -54,12 +55,12 @@ impl DelegateCall { } } -impl CallBuilder>, Args, RetType> +impl CallBuilder, Args, RetType> where E: Environment, { /// Sets the `code_hash` to perform a delegate call with. - pub fn code_hash(self, code_hash: E::Hash) -> Self { + pub fn code_hash(self, code_hash: H256) -> Self { let call_type = self.call_type.value(); CallBuilder { call_type: Set(DelegateCall { @@ -85,17 +86,12 @@ where } impl - CallBuilder< - E, - Set>, - Set>, - Set>, - > + CallBuilder, Set>, Set>> where E: Environment, { /// Finalizes the call builder to call a function. - pub fn params(self) -> CallParams, Args, RetType> { + pub fn params(self) -> CallParams { CallParams { call_type: self.call_type.value(), _return_type: Default::default(), @@ -108,7 +104,7 @@ where impl CallBuilder< E, - Set>, + Set, Unset>, Unset, > @@ -116,7 +112,7 @@ where E: Environment, { /// Finalizes the call builder to call a function. - pub fn params(self) -> CallParams, EmptyArgumentList, ()> { + pub fn params(self) -> CallParams { CallParams { call_type: self.call_type.value(), _return_type: Default::default(), @@ -129,7 +125,7 @@ where impl CallBuilder< E, - Set>, + Set, Unset>, Unset>, > @@ -159,7 +155,7 @@ where } impl - CallBuilder>, Set>, Set>> + CallBuilder, Set>, Set>> where E: Environment, Args: scale::Encode, @@ -190,13 +186,13 @@ where } } -impl CallParams, Args, R> +impl CallParams where E: Environment, { /// Returns the code hash which we use to perform a delegate call. #[inline] - pub fn code_hash(&self) -> &E::Hash { + pub fn code_hash(&self) -> &H256 { &self.call_type.code_hash } @@ -207,7 +203,7 @@ where } } -impl CallParams, Args, R> +impl CallParams where E: Environment, Args: scale::Encode, diff --git a/crates/env/src/call/call_builder/mod.rs b/crates/env/src/call/call_builder/mod.rs index bb0ac398880..a735c5129d6 100644 --- a/crates/env/src/call/call_builder/mod.rs +++ b/crates/env/src/call/call_builder/mod.rs @@ -32,6 +32,10 @@ use crate::{ Environment, }; use core::marker::PhantomData; +use ink_primitives::{ + H160, + H256, +}; /// The final parameters to the cross-contract call. #[derive(Debug)] @@ -85,12 +89,14 @@ where /// # DefaultEnvironment, /// # call::{build_call, Selector, ExecutionInput} /// # }; -/// # use ink_env::call::CallV1; -/// # type AccountId = ::AccountId; +/// # use ink_env::call::Call; +/// # use ink_primitives::H160; +/// +/// type AccountId = ::AccountId; /// # type Balance = ::Balance; /// build_call::() -/// .call_v1(AccountId::from([0x42; 32])) -/// .gas_limit(5000) +/// .call(H160::from([0x42; 20])) +/// .ref_time_limit(5000) /// .transferred_value(10) /// .exec_input( /// ExecutionInput::new(Selector::new([0xDE, 0xAD, 0xBE, 0xEF])) @@ -117,12 +123,12 @@ where /// # use ::ink_env::{ /// # Environment, /// # DefaultEnvironment, -/// # call::{build_call, Selector, ExecutionInput, CallV1}, +/// # call::{build_call, Selector, ExecutionInput, Call}, /// # }; /// # type AccountId = ::AccountId; /// let my_return_value: i32 = build_call::() -/// .call_type(CallV1::new(AccountId::from([0x42; 32]))) -/// .gas_limit(5000) +/// .call_type(Call::new(AccountId::from([0x42; 32]))) +/// .ref_time_limit(5000) /// .transferred_value(10) /// .exec_input( /// ExecutionInput::new(Selector::new([0xDE, 0xAD, 0xBE, 0xEF])) @@ -181,12 +187,14 @@ where /// # DefaultEnvironment, /// # call::{build_call, Selector, ExecutionInput} /// # }; -/// # use ink_env::call::CallV1; -/// # type AccountId = ::AccountId; +/// # use ink_env::call::Call; +/// # use ink_primitives::H160; +/// +/// type AccountId = ::AccountId; /// # type Balance = ::Balance; /// let call_result = build_call::() -/// .call_v1(AccountId::from([0x42; 32])) -/// .gas_limit(5000) +/// .call(H160::from([0x42; 20])) +/// .ref_time_limit(5000) /// .transferred_value(10) /// .try_invoke() /// .expect("Got an error from the Contract's pallet."); @@ -314,10 +322,7 @@ where { /// Prepares the `CallBuilder` for a cross-contract [`Call`] to the latest `call_v2` /// host function. - pub fn call( - self, - callee: E::AccountId, - ) -> CallBuilder>, Args, RetType> { + pub fn call(self, callee: H160) -> CallBuilder>, Args, RetType> { CallBuilder { call_type: Set(Call::new(callee)), exec_input: self.exec_input, @@ -329,8 +334,8 @@ where /// Prepares the `CallBuilder` for a cross-contract [`DelegateCall`]. pub fn delegate( self, - code_hash: E::Hash, - ) -> CallBuilder>, Args, RetType> { + code_hash: H256, + ) -> CallBuilder, Args, RetType> { CallBuilder { call_type: Set(DelegateCall::new(code_hash)), exec_input: self.exec_input, diff --git a/crates/env/src/call/create_builder.rs b/crates/env/src/call/create_builder.rs index 0ce459a651e..b2d416d7eb3 100644 --- a/crates/env/src/call/create_builder.rs +++ b/crates/env/src/call/create_builder.rs @@ -28,6 +28,10 @@ use crate::{ Error, }; use core::marker::PhantomData; +use ink_primitives::{ + H160, + H256, +}; pub mod state { //! Type states that tell what state of a instantiation argument has not @@ -46,13 +50,10 @@ pub mod state { /// /// But it is possible to use `From for T` with [`crate::AccountIdGuard`] /// bound. -pub trait FromAccountId -where - T: Environment, -{ +pub trait FromAddr { /// Creates the contract instance from the account ID of the already instantiated /// contract. - fn from_account_id(account_id: ::AccountId) -> Self; + fn from_addr(addr: H160) -> Self; } /// Represents any type that can be returned from an `ink!` constructor. The following @@ -134,7 +135,7 @@ pub trait ConstructorReturnType { /// type will become the type of the `ContractRef`'s type. impl ConstructorReturnType for C where - C: ContractEnv + FromAccountId<::Env>, + C: ContractEnv + FromAddr, { type Output = C; type Error = (); @@ -148,7 +149,7 @@ where /// of a `ContractRef` inherent becomes the `ContractRef`s type. impl ConstructorReturnType for core::result::Result where - C: ContractEnv + FromAccountId<::Env>, + C: ContractEnv + FromAddr, E: scale::Decode, { const IS_RESULT: bool = true; @@ -165,14 +166,6 @@ where } } -/// Defines the limit params for the legacy `ext::instantiate_v1` host function, -/// consisting of the `gas_limit` which is equivalent to the `ref_time_limit` in the new -/// `ext::instantiate`. -#[derive(Clone, Debug)] -pub struct LimitParamsV1 { - gas_limit: u64, -} - /// Defines the limit params for the new `ext::instantiate` host function. #[derive(Clone, Debug)] pub struct LimitParamsV2 @@ -191,11 +184,12 @@ where E: Environment, { /// The code hash of the created contract. - code_hash: E::Hash, + code_hash: H256, /// Parameters for weight and storage limits, differs for versions of the instantiate /// host function. limits: Limits, /// The endowment for the instantiated contract. + /// todo: is this correct? or is the value here `U256`? endowment: E::Balance, /// The input data for the instantiation. exec_input: ExecutionInput, @@ -214,7 +208,7 @@ where { /// The code hash of the contract. #[inline] - pub fn code_hash(&self) -> &E::Hash { + pub fn code_hash(&self) -> &H256 { &self.code_hash } @@ -264,18 +258,6 @@ where } } -impl - CreateParams -where - E: Environment, -{ - /// The gas limit for the contract instantiation. - #[inline] - pub fn gas_limit(&self) -> u64 { - self.limits.gas_limit - } -} - impl CreateParams where @@ -293,7 +275,7 @@ impl CreateParams, Args, Salt, R> where E: Environment, - ContractRef: FromAccountId, + ContractRef: FromAddr, Args: scale::Encode, Salt: AsRef<[u8]>, R: ConstructorReturnType, @@ -339,11 +321,11 @@ where /// Builds up contract instantiations. #[derive(Clone)] -pub struct CreateBuilder +pub struct CreateBuilder where E: Environment, { - code_hash: CodeHash, + code_hash: H256, limits: Limits, endowment: Endowment, exec_input: Args, @@ -377,7 +359,7 @@ where /// # use ::ink_env::{ /// # Environment, /// # DefaultEnvironment, -/// # call::{build_create, Selector, ExecutionInput, FromAccountId} +/// # call::{build_create, Selector, ExecutionInput, FromAddr} /// # }; /// # type Hash = ::Hash; /// # @@ -415,7 +397,7 @@ where /// # use ::ink_env::{ /// # Environment, /// # DefaultEnvironment, -/// # call::{build_create, Selector, ExecutionInput, FromAccountId} +/// # call::{build_create, Selector, ExecutionInput, FromAddr} /// # }; /// # type Hash = ::Hash; /// # @@ -457,7 +439,6 @@ where pub fn build_create() -> CreateBuilder< ::Env, ContractRef, - Unset<<::Env as Environment>::Hash>, Set::Env>>, Unset<<::Env as Environment>::Balance>, Unset>, @@ -483,7 +464,7 @@ where } impl - CreateBuilder, Limits, Endowment, Args, Salt, RetType> + CreateBuilder where E: Environment, { @@ -491,11 +472,10 @@ where #[inline] pub fn code_hash( self, - code_hash: E::Hash, - ) -> CreateBuilder, Limits, Endowment, Args, Salt, RetType> - { + code_hash: H256, + ) -> CreateBuilder { CreateBuilder { - code_hash: Set(code_hash), + code_hash, limits: self.limits, endowment: self.endowment, exec_input: self.exec_input, @@ -506,76 +486,11 @@ where } } -impl - CreateBuilder< - E, - ContractRef, - CodeHash, - Set, - Endowment, - Args, - Salt, - RetType, - > -where - E: Environment, -{ - /// Sets the maximum allowed gas costs for the contract instantiation. - #[inline] - pub fn gas_limit(self, gas_limit: u64) -> Self { - CreateBuilder { - limits: Set(LimitParamsV1 { gas_limit }), - ..self - } - } -} - -impl - CreateBuilder< - E, - ContractRef, - CodeHash, - Set>, - Endowment, - Args, - Salt, - RetType, - > +impl + CreateBuilder>, Endowment, Args, Salt, RetType> where E: Environment, { - /// Switch to the original `instantiate` host function API, which only allows the - /// `gas_limit` limit parameter (equivalent to the `ref_time_limit` in the latest - /// `instantiate_v2`). - /// - /// This method instance is used to allow usage of the generated builder methods - /// for constructors which initialize the builder with the new [`LimitParamsV2`] type. - #[inline] - pub fn instantiate_v1( - self, - ) -> CreateBuilder< - E, - ContractRef, - CodeHash, - Set, - Endowment, - Args, - Salt, - RetType, - > { - CreateBuilder { - code_hash: self.code_hash, - limits: Set(LimitParamsV1 { - gas_limit: self.limits.value().ref_time_limit, - }), - endowment: self.endowment, - exec_input: self.exec_input, - salt: self.salt, - return_type: self.return_type, - _phantom: Default::default(), - } - } - /// Sets the `ref_time_limit` part of the weight limit for the contract instantiation. #[inline] pub fn ref_time_limit(self, ref_time_limit: u64) -> Self { @@ -614,17 +529,8 @@ where } } -impl - CreateBuilder< - E, - ContractRef, - CodeHash, - Limits, - Unset, - Args, - Salt, - RetType, - > +impl + CreateBuilder, Args, Salt, RetType> where E: Environment, { @@ -633,16 +539,7 @@ where pub fn endowment( self, endowment: E::Balance, - ) -> CreateBuilder< - E, - ContractRef, - CodeHash, - Limits, - Set, - Args, - Salt, - RetType, - > { + ) -> CreateBuilder, Args, Salt, RetType> { CreateBuilder { code_hash: self.code_hash, limits: self.limits, @@ -655,11 +552,10 @@ where } } -impl +impl CreateBuilder< E, ContractRef, - CodeHash, Limits, Endowment, Unset>, @@ -677,7 +573,6 @@ where ) -> CreateBuilder< E, ContractRef, - CodeHash, Limits, Endowment, Set>, @@ -696,17 +591,8 @@ where } } -impl - CreateBuilder< - E, - ContractRef, - CodeHash, - Limits, - Endowment, - Args, - Unset, - RetType, - > +impl + CreateBuilder, RetType> where E: Environment, { @@ -715,16 +601,7 @@ where pub fn salt_bytes( self, salt: Salt, - ) -> CreateBuilder< - E, - ContractRef, - CodeHash, - Limits, - Endowment, - Args, - Set, - RetType, - > + ) -> CreateBuilder, RetType> where Salt: AsRef<[u8]>, { @@ -740,17 +617,8 @@ where } } -impl - CreateBuilder< - E, - ContractRef, - CodeHash, - Limits, - Endowment, - Args, - Salt, - Unset>, - > +impl + CreateBuilder>> where E: Environment, { @@ -766,18 +634,9 @@ where #[inline] pub fn returns( self, - ) -> CreateBuilder< - E, - ContractRef, - CodeHash, - Limits, - Endowment, - Args, - Salt, - Set>, - > + ) -> CreateBuilder>> where - ContractRef: FromAccountId, + ContractRef: FromAddr, R: ConstructorReturnType, { CreateBuilder { @@ -796,7 +655,6 @@ impl CreateBuilder< E, ContractRef, - Set, Set, Set, Set>, @@ -810,7 +668,7 @@ where #[inline] pub fn params(self) -> CreateParams { CreateParams { - code_hash: self.code_hash.value(), + code_hash: self.code_hash, limits: self.limits.value(), endowment: self.endowment.value(), exec_input: self.exec_input.value(), @@ -825,7 +683,6 @@ impl CreateBuilder< E, ContractRef, - Set, Set>, Set, Set>, @@ -834,7 +691,7 @@ impl > where E: Environment, - ContractRef: FromAccountId, + ContractRef: FromAddr, Args: scale::Encode, Salt: AsRef<[u8]>, RetType: ConstructorReturnType, diff --git a/crates/env/src/call/mod.rs b/crates/env/src/call/mod.rs index 9166af06362..cb28951c255 100644 --- a/crates/env/src/call/mod.rs +++ b/crates/env/src/call/mod.rs @@ -53,7 +53,7 @@ pub use self::{ ConstructorReturnType, CreateBuilder, CreateParams, - FromAccountId, + FromAddr, LimitParamsV2, }, execution::{ diff --git a/crates/env/src/engine/mod.rs b/crates/env/src/engine/mod.rs index a4ec50608d8..fb50f2ad5c0 100644 --- a/crates/env/src/engine/mod.rs +++ b/crates/env/src/engine/mod.rs @@ -19,7 +19,7 @@ use crate::{ }, call::{ ConstructorReturnType, - FromAccountId, + FromAddr, }, Error, Result as EnvResult, @@ -70,40 +70,37 @@ cfg_if! { // We only use this function when 1) compiling to Wasm 2) compiling for tests. #[cfg_attr(all(feature = "std", not(test)), allow(dead_code))] -pub(crate) fn decode_instantiate_result( +pub(crate) fn decode_instantiate_result( instantiate_result: EnvResult<()>, out_address: &mut I, out_return_value: &mut I, ) -> EnvResult>::Output>> where I: scale::Input, - E: crate::Environment, - ContractRef: FromAccountId, + ContractRef: FromAddr, R: ConstructorReturnType, { match instantiate_result { Ok(()) => { let account_id = scale::Decode::decode(out_address)?; - let contract_ref = - >::from_account_id(account_id); + let contract_ref = ::from_addr(account_id); let output = >::ok(contract_ref); Ok(Ok(output)) } Err(Error::ReturnError(ReturnErrorCode::CalleeReverted)) => { - decode_instantiate_err::(out_return_value) + decode_instantiate_err::(out_return_value) } Err(actual_error) => Err(actual_error), } } #[cfg_attr(all(feature = "std", not(test)), allow(dead_code))] -fn decode_instantiate_err( +fn decode_instantiate_err( out_return_value: &mut I, ) -> EnvResult>::Output>> where I: scale::Input, - E: crate::Environment, - ContractRef: FromAccountId, + ContractRef: FromAddr, R: ConstructorReturnType, { let constructor_result_variant = out_return_value.read_byte()?; @@ -147,10 +144,8 @@ where #[cfg(test)] mod decode_instantiate_result_tests { use super::*; - use crate::{ - DefaultEnvironment, - Environment, - }; + use crate::DefaultEnvironment; + use ink_primitives::H160; use scale::Encode; // The `Result` type used to represent the programmer defined contract output. @@ -159,18 +154,17 @@ mod decode_instantiate_result_tests { #[derive(scale::Encode, scale::Decode)] struct ContractError(String); - type AccountId = ::AccountId; // The `allow(dead_code)` is for the `AccountId` in the struct. #[allow(dead_code)] - struct TestContractRef(AccountId); + struct TestContractRef(H160); impl crate::ContractEnv for TestContractRef { type Env = DefaultEnvironment; } - impl FromAccountId for TestContractRef { - fn from_account_id(account_id: AccountId) -> Self { - Self(account_id) + impl FromAddr for TestContractRef { + fn from_addr(addr: H160) -> Self { + Self(addr) } } @@ -191,7 +185,6 @@ mod decode_instantiate_result_tests { ) -> EnvResult>> { decode_instantiate_result::< I, - DefaultEnvironment, TestContractRef, Result, >( diff --git a/crates/env/src/engine/off_chain/impls.rs b/crates/env/src/engine/off_chain/impls.rs index 82517dc3520..bd3ca573189 100644 --- a/crates/env/src/engine/off_chain/impls.rs +++ b/crates/env/src/engine/off_chain/impls.rs @@ -20,7 +20,7 @@ use crate::{ ConstructorReturnType, CreateParams, DelegateCall, - FromAccountId, + FromAddr, LimitParamsV2, }, event::{ @@ -42,6 +42,7 @@ use crate::{ TypedEnvBackend, }; use ink_engine::ext::Engine; +use ink_primitives::{H160, H256, U256}; use ink_storage_traits::{ decode_all, Storable, @@ -259,6 +260,7 @@ impl EnvBackend for EnvInstance { ::hash(enc_input, output) } + #[allow(clippy::arithmetic_side_effects)] // todo fn ecdsa_recover( &mut self, signature: &[u8; 65], @@ -372,13 +374,13 @@ impl EnvBackend for EnvInstance { } impl TypedEnvBackend for EnvInstance { - fn caller(&mut self) -> E::AccountId { - self.get_property::(Engine::caller) + fn caller(&mut self) -> H160 { + self.get_property::(Engine::caller) .unwrap_or_else(|error| panic!("could not read `caller` property: {error:?}")) } - fn transferred_value(&mut self) -> E::Balance { - self.get_property::(Engine::value_transferred) + fn transferred_value(&mut self) -> U256 { + self.get_property(Engine::value_transferred) .unwrap_or_else(|error| { panic!("could not read `transferred_value` property: {error:?}") }) @@ -392,12 +394,20 @@ impl TypedEnvBackend for EnvInstance { } fn account_id(&mut self) -> E::AccountId { + // todo should not use `Engine::account_id` self.get_property::(Engine::address) .unwrap_or_else(|error| { panic!("could not read `account_id` property: {error:?}") }) } + fn address(&mut self) -> H160 { + self.get_property::(Engine::address) + .unwrap_or_else(|error| { + panic!("could not read `account_id` property: {error:?}") + }) + } + fn balance(&mut self) -> E::Balance { self.get_property::(Engine::balance) .unwrap_or_else(|error| { @@ -444,7 +454,7 @@ impl TypedEnvBackend for EnvInstance { fn invoke_contract_delegate( &mut self, - params: &CallParams, Args, R>, + params: &CallParams, ) -> Result> where E: Environment, @@ -467,7 +477,7 @@ impl TypedEnvBackend for EnvInstance { > where E: Environment, - ContractRef: FromAccountId, + ContractRef: FromAddr, Args: scale::Encode, Salt: AsRef<[u8]>, R: ConstructorReturnType, @@ -482,22 +492,17 @@ impl TypedEnvBackend for EnvInstance { unimplemented!("off-chain environment does not support contract instantiation") } - fn terminate_contract(&mut self, beneficiary: E::AccountId) -> ! - where - E: Environment, - { - let buffer = scale::Encode::encode(&beneficiary); - self.engine.terminate(&buffer[..]) + fn terminate_contract(&mut self, beneficiary: H160) -> ! { + self.engine.terminate(beneficiary) } - fn transfer(&mut self, destination: E::AccountId, value: E::Balance) -> Result<()> + fn transfer(&mut self, destination: H160, value: E::Balance) -> Result<()> where E: Environment, { - let enc_destination = &scale::Encode::encode(&destination)[..]; let enc_value = &scale::Encode::encode(&value)[..]; self.engine - .transfer(enc_destination, enc_value) + .transfer(destination, enc_value) .map_err(Into::into) } @@ -509,11 +514,8 @@ impl TypedEnvBackend for EnvInstance { }) } - fn is_contract(&mut self, account: &E::AccountId) -> bool - where - E: Environment, - { - self.engine.is_contract(scale::Encode::encode(&account)) + fn is_contract(&mut self, account: &H160) -> bool { + self.engine.is_contract(account) } fn caller_is_origin(&mut self) -> bool @@ -530,14 +532,11 @@ impl TypedEnvBackend for EnvInstance { unimplemented!("off-chain environment does not support `caller_is_root`") } - fn code_hash(&mut self, _account: &E::AccountId) -> Result - where - E: Environment, - { + fn code_hash(&mut self, _addr: &H160) -> Result { unimplemented!("off-chain environment does not support `code_hash`") } - fn own_code_hash(&mut self) -> Result + fn own_code_hash(&mut self) -> Result where E: Environment, { @@ -551,7 +550,7 @@ impl TypedEnvBackend for EnvInstance { unimplemented!("off-chain environment does not support `call_runtime`") } - fn lock_delegate_dependency(&mut self, _code_hash: &E::Hash) + fn lock_delegate_dependency(&mut self, _code_hash: &H256) where E: Environment, { @@ -576,7 +575,7 @@ impl TypedEnvBackend for EnvInstance { unimplemented!("off-chain environment does not support `xcm_send`") } - fn unlock_delegate_dependency(&mut self, _code_hash: &E::Hash) + fn unlock_delegate_dependency(&mut self, _code_hash: &H256) where E: Environment, { diff --git a/crates/env/src/engine/off_chain/mod.rs b/crates/env/src/engine/off_chain/mod.rs index 3b856ba71fd..c69ae38048c 100644 --- a/crates/env/src/engine/off_chain/mod.rs +++ b/crates/env/src/engine/off_chain/mod.rs @@ -25,6 +25,10 @@ use crate::Error; use derive_more::From; use ink_engine::ext::Engine; +use ink_primitives::{ + AccountId, + H160, +}; /// The off-chain environment. pub struct EnvInstance { @@ -59,6 +63,7 @@ pub enum OffChainError { UnregisteredChainExtension, } +// todo rename /// Errors encountered upon interacting with the accounts database. #[derive(Debug, From, PartialEq, Eq)] pub enum AccountError { @@ -66,5 +71,6 @@ pub enum AccountError { #[from(ignore)] UnexpectedUserAccount, #[from(ignore)] - NoAccountForId(Vec), + NoAccountForId(AccountId), + NoContractForId(H160), } diff --git a/crates/env/src/engine/off_chain/test_api.rs b/crates/env/src/engine/off_chain/test_api.rs index 5c1e00bfeb2..e4a001a5574 100644 --- a/crates/env/src/engine/off_chain/test_api.rs +++ b/crates/env/src/engine/off_chain/test_api.rs @@ -31,6 +31,7 @@ pub use ink_engine::{ ext::ChainSpec, ChainExtension, }; +use ink_primitives::H160; /// Record for an emitted event. #[derive(Clone)] @@ -57,11 +58,13 @@ pub struct EmittedEvent { /// - If the underlying `account` type does not match. /// - If the underlying `new_balance` type does not match. /// - If the `new_balance` is less than the existential minimum. -pub fn set_account_balance(account_id: T::AccountId, new_balance: T::Balance) +pub fn set_account_balance(addr: H160, new_balance: T::Balance) where T: Environment, // Just temporary for the MVP! { let min = ChainSpec::default().minimum_balance; + eprintln!("new balance {new_balance}"); + eprintln!("min {min}"); if new_balance < min && new_balance != 0u128 { panic!( "Balance must be at least [{}]. Use 0 as balance to reap the account.", @@ -70,9 +73,7 @@ where } ::on_instance(|instance| { - instance - .engine - .set_balance(scale::Encode::encode(&account_id), new_balance); + instance.engine.set_balance(addr, new_balance); }) } @@ -88,15 +89,12 @@ where /// /// - If `account` does not exist. /// - If the underlying `account` type does not match. -pub fn get_account_balance(account_id: T::AccountId) -> Result +pub fn get_account_balance(addr: H160) -> Result where T: Environment, // Just temporary for the MVP! { ::on_instance(|instance| { - instance - .engine - .get_balance(scale::Encode::encode(&account_id)) - .map_err(Into::into) + instance.engine.get_balance(addr).map_err(Into::into) }) } @@ -144,57 +142,37 @@ where } /// Sets a caller for the next call. -pub fn set_caller(caller: T::AccountId) -where - T: Environment, - ::AccountId: From<[u8; 32]>, -{ +pub fn set_caller(caller: H160) { ::on_instance(|instance| { - instance.engine.set_caller(scale::Encode::encode(&caller)); + instance.engine.set_caller(caller); }) } /// Sets the callee for the next call. -pub fn set_callee(callee: T::AccountId) -where - T: Environment, - ::AccountId: From<[u8; 32]>, -{ +pub fn set_callee(callee: H160) { ::on_instance(|instance| { - instance.engine.set_callee(scale::Encode::encode(&callee)); + instance.engine.set_callee(callee); }) } /// Sets an account as a contract -pub fn set_contract(contract: T::AccountId) -where - T: Environment, - ::AccountId: From<[u8; 32]>, -{ +pub fn set_contract(contract: H160) { ::on_instance(|instance| { - instance - .engine - .set_contract(scale::Encode::encode(&contract)); + instance.engine.set_contract(contract); }) } /// Returns a boolean to indicate whether an account is a contract -pub fn is_contract(contract: T::AccountId) -> bool -where - T: Environment, - ::AccountId: From<[u8; 32]>, -{ +pub fn is_contract(contract: H160) -> bool { ::on_instance(|instance| { - instance - .engine - .is_contract(scale::Encode::encode(&contract)) + instance.engine.is_contract(&contract) }) } /// Gets the currently set callee. /// -/// This is account id of the currently executing contract. -pub fn callee() -> T::AccountId +/// This is the address of the currently executing contract. +pub fn callee() -> H160 where T: Environment, { @@ -206,14 +184,9 @@ where } /// Returns the total number of reads and writes of the contract's storage. -pub fn get_contract_storage_rw(account_id: &T::AccountId) -> (usize, usize) -where - T: Environment, -{ +pub fn get_contract_storage_rw(addr: H160) -> (usize, usize) { ::on_instance(|instance| { - instance - .engine - .get_contract_storage_rw(scale::Encode::encode(&account_id)) + instance.engine.get_contract_storage_rw(addr) }) } @@ -234,30 +207,19 @@ where /// /// Please note that the acting accounts should be set with [`set_caller()`] and /// [`set_callee()`] beforehand. +#[allow(clippy::arithmetic_side_effects)] // todo pub fn transfer_in(value: T::Balance) where T: Environment, // Just temporary for the MVP! { ::on_instance(|instance| { - let caller = instance - .engine - .exec_context - .caller - .as_ref() - .expect("no caller has been set") - .as_bytes() - .to_vec(); - - let caller_old_balance = instance - .engine - .get_balance(caller.clone()) - .unwrap_or_default(); + let caller = instance.engine.exec_context.caller; + + let caller_old_balance = instance.engine.get_balance(caller).unwrap_or_default(); let callee = instance.engine.get_callee(); - let contract_old_balance = instance - .engine - .get_balance(callee.clone()) - .unwrap_or_default(); + let contract_old_balance = + instance.engine.get_balance(callee).unwrap_or_default(); instance .engine @@ -269,17 +231,17 @@ where }); } -/// Returns the amount of storage cells used by the account `account_id`. +/// Returns the amount of storage cells used by the contract `addr`. /// -/// Returns `None` if the `account_id` is non-existent. -pub fn count_used_storage_cells(account_id: &T::AccountId) -> Result +/// Returns `None` if the contract at `addr` is non-existent. +pub fn count_used_storage_cells(addr: H160) -> Result where T: Environment, { ::on_instance(|instance| { instance .engine - .count_used_storage_cells(&scale::Encode::encode(&account_id)) + .count_used_storage_cells(&addr) .map_err(Into::into) }) } @@ -309,74 +271,56 @@ where pub fn run_test(f: F) -> Result<()> where T: Environment, - F: FnOnce(DefaultAccounts) -> Result<()>, - ::AccountId: From<[u8; 32]>, + F: FnOnce(DefaultAccounts) -> Result<()>, { - let default_accounts = default_accounts::(); + let default_accounts = default_accounts(); ::on_instance(|instance| { instance.engine.initialize_or_reset(); - let encoded_alice = scale::Encode::encode(&default_accounts.alice); - instance.engine.set_caller(encoded_alice.clone()); - instance.engine.set_callee(encoded_alice.clone()); + let alice = default_accounts.alice; + // instance.engine.set_caller(alice.clone()); // todo + instance.engine.set_callee(alice); // set up the funds for the default accounts let substantial = 1_000_000; let some = 1_000; - instance.engine.set_balance(encoded_alice, substantial); - instance - .engine - .set_balance(scale::Encode::encode(&default_accounts.bob), some); - instance - .engine - .set_balance(scale::Encode::encode(&default_accounts.charlie), some); - instance - .engine - .set_balance(scale::Encode::encode(&default_accounts.django), 0); - instance - .engine - .set_balance(scale::Encode::encode(&default_accounts.eve), 0); - instance - .engine - .set_balance(scale::Encode::encode(&default_accounts.frank), 0); + instance.engine.set_balance(alice, substantial); + instance.engine.set_balance(default_accounts.bob, some); + instance.engine.set_balance(default_accounts.charlie, some); + instance.engine.set_balance(default_accounts.django, 0); + instance.engine.set_balance(default_accounts.eve, 0); + instance.engine.set_balance(default_accounts.frank, 0); }); f(default_accounts) } /// Returns the default accounts for testing purposes: /// Alice, Bob, Charlie, Django, Eve and Frank. -pub fn default_accounts() -> DefaultAccounts -where - T: Environment, - ::AccountId: From<[u8; 32]>, -{ +pub fn default_accounts() -> DefaultAccounts { DefaultAccounts { - alice: T::AccountId::from([0x01; 32]), - bob: T::AccountId::from([0x02; 32]), - charlie: T::AccountId::from([0x03; 32]), - django: T::AccountId::from([0x04; 32]), - eve: T::AccountId::from([0x05; 32]), - frank: T::AccountId::from([0x06; 32]), + alice: H160::from([0x01; 20]), + bob: H160::from([0x02; 20]), + charlie: H160::from([0x03; 20]), + django: H160::from([0x04; 20]), + eve: H160::from([0x05; 20]), + frank: H160::from([0x06; 20]), } } /// The default accounts. -pub struct DefaultAccounts -where - T: Environment, -{ +pub struct DefaultAccounts { /// The predefined `ALICE` account holding substantial amounts of value. - pub alice: T::AccountId, + pub alice: H160, /// The predefined `BOB` account holding some amounts of value. - pub bob: T::AccountId, + pub bob: H160, /// The predefined `CHARLIE` account holding some amounts of value. - pub charlie: T::AccountId, + pub charlie: H160, /// The predefined `DJANGO` account holding no value. - pub django: T::AccountId, + pub django: H160, /// The predefined `EVE` account holding no value. - pub eve: T::AccountId, + pub eve: H160, /// The predefined `FRANK` account holding no value. - pub frank: T::AccountId, + pub frank: H160, } /// Returns the recorded emitted events in order. diff --git a/crates/env/src/engine/off_chain/tests.rs b/crates/env/src/engine/off_chain/tests.rs index 9b9848576cc..d7e1395a510 100644 --- a/crates/env/src/engine/off_chain/tests.rs +++ b/crates/env/src/engine/off_chain/tests.rs @@ -13,13 +13,8 @@ // limitations under the License. use crate::{ - engine::off_chain::{ - impls::TopicsBuilder, - test_api::set_account_balance, - }, + engine::off_chain::impls::TopicsBuilder, event::TopicsBuilderBackend, - types::Environment, - DefaultEnvironment, Result, }; @@ -46,32 +41,34 @@ fn topics_builder() -> Result<()> { Ok(()) }) } -#[test] -fn test_set_account_balance() -> Result<()> { - pub use ink_engine::ext::ChainSpec; - - crate::test::run_test::(|_| { - let minimum_balance = ChainSpec::default().minimum_balance; - - let result = std::panic::catch_unwind(|| { - set_account_balance::( - ::AccountId::from([0x1; 32]), - ::Balance::from(minimum_balance - 1), - ) - }); - - assert!(result.is_err()); - set_account_balance::( - ::AccountId::from([0x1; 32]), - ::Balance::from(0u128), - ); - - set_account_balance::( - ::AccountId::from([0x1; 32]), - ::Balance::from(minimum_balance + 1), - ); - - Ok(()) - }) -} +// #[test] +// fn test_set_account_balance() -> Result<()> { +// pub use ink_engine::ext::ChainSpec; +// +// use crate::{DefaultEnvironment, Environment}; +// crate::test::run_test::(|_| { +// let minimum_balance = ChainSpec::default().minimum_balance; +// +// let result = std::panic::catch_unwind(|| { +// set_account_balance::( +// ::AccountId::from([0x1; 32]), +// ::Balance::from(minimum_balance - 1), +// ) +// }); +// +// assert!(result.is_err()); +// +// set_account_balance::( +// ::AccountId::from([0x1; 32]), +// ::Balance::from(0u128), +// ); +// +// set_account_balance::( +// ::AccountId::from([0x1; 32]), +// ::Balance::from(minimum_balance + 1), +// ); +// +// Ok(()) +// }) +// } diff --git a/crates/env/src/engine/off_chain/types.rs b/crates/env/src/engine/off_chain/types.rs index 0fcbba3459e..b5d240165fd 100644 --- a/crates/env/src/engine/off_chain/types.rs +++ b/crates/env/src/engine/off_chain/types.rs @@ -57,6 +57,9 @@ impl From for AccountError { ink_engine::AccountError::NoAccountForId(acc) => { AccountError::NoAccountForId(acc) } + ink_engine::AccountError::NoContractForId(addr) => { + AccountError::NoContractForId(addr) + } } } } diff --git a/crates/env/src/engine/on_chain/impls/mod.rs b/crates/env/src/engine/on_chain/impls/mod.rs deleted file mode 100644 index 56a0bd1c4a9..00000000000 --- a/crates/env/src/engine/on_chain/impls/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[cfg(target_arch = "wasm32")] -mod pallet_contracts; - -#[cfg(target_arch = "riscv32")] -mod pallet_revive; diff --git a/crates/env/src/engine/on_chain/impls/pallet_contracts.rs b/crates/env/src/engine/on_chain/impls/pallet_contracts.rs deleted file mode 100644 index 1bb27d193a6..00000000000 --- a/crates/env/src/engine/on_chain/impls/pallet_contracts.rs +++ /dev/null @@ -1,782 +0,0 @@ -// Copyright (C) Use Ink (UK) Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{ - call::{ - Call, - CallParams, - CallV1, - ConstructorReturnType, - CreateParams, - DelegateCall, - FromAccountId, - LimitParamsV1, - LimitParamsV2, - }, - engine::{ - on_chain::{ - EncodeScope, - ScopedBuffer, - }, - EnvInstance, - }, - event::{ - Event, - TopicsBuilderBackend, - }, - hash::{ - Blake2x128, - Blake2x256, - CryptoHash, - HashOutput, - Keccak256, - Sha2x256, - }, - Clear, - EnvBackend, - Environment, - FromLittleEndian, - Result, - TypedEnvBackend, -}; -use ink_storage_traits::{ - decode_all, - Storable, -}; -use pallet_contracts_uapi::{ - CallFlags, - HostFn, - HostFnImpl as ext, - ReturnErrorCode, - ReturnFlags, -}; -use xcm::VersionedXcm; - -impl CryptoHash for Blake2x128 { - fn hash(input: &[u8], output: &mut ::Type) { - type OutputType = [u8; 16]; - static_assertions::assert_type_eq_all!( - ::Type, - OutputType - ); - let output: &mut OutputType = array_mut_ref!(output, 0, 16); - ext::hash_blake2_128(input, output); - } -} - -impl CryptoHash for Blake2x256 { - fn hash(input: &[u8], output: &mut ::Type) { - type OutputType = [u8; 32]; - static_assertions::assert_type_eq_all!( - ::Type, - OutputType - ); - let output: &mut OutputType = array_mut_ref!(output, 0, 32); - ext::hash_blake2_256(input, output); - } -} - -impl CryptoHash for Sha2x256 { - fn hash(input: &[u8], output: &mut ::Type) { - type OutputType = [u8; 32]; - static_assertions::assert_type_eq_all!( - ::Type, - OutputType - ); - let output: &mut OutputType = array_mut_ref!(output, 0, 32); - ext::hash_sha2_256(input, output); - } -} - -impl CryptoHash for Keccak256 { - fn hash(input: &[u8], output: &mut ::Type) { - type OutputType = [u8; 32]; - static_assertions::assert_type_eq_all!( - ::Type, - OutputType - ); - let output: &mut OutputType = array_mut_ref!(output, 0, 32); - ext::hash_keccak_256(input, output); - } -} - -pub struct TopicsBuilder<'a, E> { - scoped_buffer: ScopedBuffer<'a>, - marker: core::marker::PhantomData E>, -} - -impl<'a, E> From> for TopicsBuilder<'a, E> -where - E: Environment, -{ - fn from(scoped_buffer: ScopedBuffer<'a>) -> Self { - Self { - scoped_buffer, - marker: Default::default(), - } - } -} - -impl<'a, E> TopicsBuilderBackend for TopicsBuilder<'a, E> -where - E: Environment, -{ - type Output = (ScopedBuffer<'a>, &'a mut [u8]); - - fn expect(&mut self, expected_topics: usize) { - self.scoped_buffer - .append_encoded(&scale::Compact(expected_topics as u32)); - } - - fn push_topic(&mut self, topic_value: &T) - where - T: scale::Encode, - { - fn inner(encoded: &mut [u8]) -> ::Hash { - let len_encoded = encoded.len(); - let mut result = ::Hash::CLEAR_HASH; - let len_result = result.as_ref().len(); - if len_encoded <= len_result { - result.as_mut()[..len_encoded].copy_from_slice(encoded); - } else { - let mut hash_output = ::Type::default(); - ::hash(encoded, &mut hash_output); - let copy_len = core::cmp::min(hash_output.len(), len_result); - result.as_mut()[0..copy_len].copy_from_slice(&hash_output[0..copy_len]); - } - result - } - - let mut split = self.scoped_buffer.split(); - let encoded = split.take_encoded(topic_value); - let result = inner::(encoded); - self.scoped_buffer.append_encoded(&result); - } - - fn output(mut self) -> Self::Output { - let encoded_topics = self.scoped_buffer.take_appended(); - (self.scoped_buffer, encoded_topics) - } -} - -impl EnvInstance { - #[inline(always)] - /// Returns a new scoped buffer for the entire scope of the static 16 kB buffer. - fn scoped_buffer(&mut self) -> ScopedBuffer { - ScopedBuffer::from(&mut self.buffer[..]) - } - - /// Returns the contract property value from its little-endian representation. - /// - /// # Note - /// - /// This skips the potentially costly decoding step that is often equivalent to a - /// `memcpy`. - #[inline(always)] - fn get_property_little_endian(&mut self, ext_fn: fn(output: &mut &mut [u8])) -> T - where - T: FromLittleEndian, - { - let mut result = ::Bytes::default(); - ext_fn(&mut result.as_mut()); - ::from_le_bytes(result) - } - - /// Returns the contract property value. - #[inline(always)] - fn get_property(&mut self, ext_fn: fn(output: &mut &mut [u8])) -> Result - where - T: scale::Decode, - { - let full_scope = &mut self.scoped_buffer().take_rest(); - ext_fn(full_scope); - scale::Decode::decode(&mut &full_scope[..]).map_err(Into::into) - } -} - -impl EnvBackend for EnvInstance { - fn set_contract_storage(&mut self, key: &K, value: &V) -> Option - where - K: scale::Encode, - V: Storable, - { - let mut buffer = self.scoped_buffer(); - let key = buffer.take_encoded(key); - let value = buffer.take_storable_encoded(value); - ext::set_storage_v2(key, value) - } - - fn get_contract_storage(&mut self, key: &K) -> Result> - where - K: scale::Encode, - R: Storable, - { - let mut buffer = self.scoped_buffer(); - let key = buffer.take_encoded(key); - let output = &mut buffer.take_rest(); - match ext::get_storage_v1(key, output) { - Ok(_) => (), - Err(ReturnErrorCode::KeyNotFound) => return Ok(None), - Err(_) => panic!("encountered unexpected error"), - } - let decoded = decode_all(&mut &output[..])?; - Ok(Some(decoded)) - } - - fn take_contract_storage(&mut self, key: &K) -> Result> - where - K: scale::Encode, - R: Storable, - { - let mut buffer = self.scoped_buffer(); - let key = buffer.take_encoded(key); - let output = &mut buffer.take_rest(); - match ext::take_storage(key, output) { - Ok(_) => (), - Err(ReturnErrorCode::KeyNotFound) => return Ok(None), - Err(_) => panic!("encountered unexpected error"), - } - let decoded = decode_all(&mut &output[..])?; - Ok(Some(decoded)) - } - - fn contains_contract_storage(&mut self, key: &K) -> Option - where - K: scale::Encode, - { - let mut buffer = self.scoped_buffer(); - let key = buffer.take_encoded(key); - ext::contains_storage_v1(key) - } - - fn clear_contract_storage(&mut self, key: &K) -> Option - where - K: scale::Encode, - { - let mut buffer = self.scoped_buffer(); - let key = buffer.take_encoded(key); - ext::clear_storage_v1(key) - } - - fn decode_input(&mut self) -> Result - where - T: scale::Decode, - { - self.get_property::(ext::input) - } - - fn return_value(&mut self, flags: ReturnFlags, return_value: &R) -> ! - where - R: scale::Encode, - { - let mut scope = EncodeScope::from(&mut self.buffer[..]); - return_value.encode_to(&mut scope); - let len = scope.len(); - ext::return_value(flags, &self.buffer[..][..len]); - } - - #[cfg(not(feature = "ink-debug"))] - /// A no-op. Enable the `ink-debug` feature for debug messages. - fn debug_message(&mut self, _content: &str) {} - - #[cfg(feature = "ink-debug")] - fn debug_message(&mut self, content: &str) { - static mut DEBUG_ENABLED: bool = false; - static mut FIRST_RUN: bool = true; - - // SAFETY: safe because executing in a single threaded context - // We need those two variables in order to make sure that the assignment is - // performed in the "logging enabled" case. This is because during RPC - // execution logging might be enabled while it is disabled during the - // actual execution as part of a transaction. The gas estimation takes - // place during RPC execution. We want to overestimate instead - // of underestimate gas usage. Otherwise using this estimate could lead to a out - // of gas error. - if unsafe { DEBUG_ENABLED || FIRST_RUN } { - let ret_code = ext::debug_message(content.as_bytes()); - if !matches!(ret_code, Err(ReturnErrorCode::LoggingDisabled)) { - // SAFETY: safe because executing in a single threaded context - unsafe { DEBUG_ENABLED = true } - } - // SAFETY: safe because executing in a single threaded context - unsafe { FIRST_RUN = false } - } - } - - fn hash_bytes(&mut self, input: &[u8], output: &mut ::Type) - where - H: CryptoHash, - { - ::hash(input, output) - } - - fn hash_encoded(&mut self, input: &T, output: &mut ::Type) - where - H: CryptoHash, - T: scale::Encode, - { - let mut scope = self.scoped_buffer(); - let enc_input = scope.take_encoded(input); - ::hash(enc_input, output) - } - - fn ecdsa_recover( - &mut self, - signature: &[u8; 65], - message_hash: &[u8; 32], - output: &mut [u8; 33], - ) -> Result<()> { - ext::ecdsa_recover(signature, message_hash, output).map_err(Into::into) - } - - fn ecdsa_to_eth_address( - &mut self, - pubkey: &[u8; 33], - output: &mut [u8; 20], - ) -> Result<()> { - ext::ecdsa_to_eth_address(pubkey, output).map_err(Into::into) - } - - fn sr25519_verify( - &mut self, - signature: &[u8; 64], - message: &[u8], - pub_key: &[u8; 32], - ) -> Result<()> { - ext::sr25519_verify(signature, message, pub_key).map_err(Into::into) - } - - fn call_chain_extension( - &mut self, - id: u32, - input: &I, - status_to_result: F, - decode_to_result: D, - ) -> ::core::result::Result - where - I: scale::Encode, - T: scale::Decode, - E: From, - F: FnOnce(u32) -> ::core::result::Result<(), ErrorCode>, - D: FnOnce(&[u8]) -> ::core::result::Result, - { - let mut scope = self.scoped_buffer(); - let enc_input = scope.take_encoded(input); - let output = &mut scope.take_rest(); - status_to_result(ext::call_chain_extension(id, enc_input, Some(output)))?; - let decoded = decode_to_result(output)?; - Ok(decoded) - } - - fn set_code_hash(&mut self, code_hash_ptr: &[u8]) -> Result<()> { - ext::set_code_hash(code_hash_ptr).map_err(Into::into) - } -} - -impl TypedEnvBackend for EnvInstance { - fn caller(&mut self) -> E::AccountId { - self.get_property::(ext::caller) - .expect("The executed contract must have a caller with a valid account id.") - } - - fn transferred_value(&mut self) -> E::Balance { - self.get_property_little_endian::(ext::value_transferred) - } - - fn gas_left(&mut self) -> u64 { - self.get_property_little_endian::(ext::gas_left) - } - - fn block_timestamp(&mut self) -> E::Timestamp { - self.get_property_little_endian::(ext::now) - } - - fn account_id(&mut self) -> E::AccountId { - self.get_property::(ext::address) - .expect("A contract being executed must have a valid account id.") - } - - fn balance(&mut self) -> E::Balance { - self.get_property_little_endian::(ext::balance) - } - - fn block_number(&mut self) -> E::BlockNumber { - self.get_property_little_endian::(ext::block_number) - } - - fn minimum_balance(&mut self) -> E::Balance { - self.get_property_little_endian::(ext::minimum_balance) - } - - fn emit_event(&mut self, event: Evt) - where - E: Environment, - Evt: Event, - { - let (mut scope, enc_topics) = - event.topics::(TopicsBuilder::from(self.scoped_buffer()).into()); - let enc_data = scope.take_encoded(&event); - ext::deposit_event(enc_topics, enc_data); - } - - fn invoke_contract_v1( - &mut self, - params: &CallParams, Args, R>, - ) -> Result> - where - E: Environment, - Args: scale::Encode, - R: scale::Decode, - { - let mut scope = self.scoped_buffer(); - let gas_limit = params.gas_limit(); - let enc_callee = scope.take_encoded(params.callee()); - let enc_transferred_value = scope.take_encoded(params.transferred_value()); - let call_flags = params.call_flags(); - let enc_input = if !call_flags.contains(CallFlags::FORWARD_INPUT) - && !call_flags.contains(CallFlags::CLONE_INPUT) - { - scope.take_encoded(params.exec_input()) - } else { - &mut [] - }; - let output = &mut scope.take_rest(); - let flags = params.call_flags(); - #[allow(deprecated)] - let call_result = ext::call_v1( - *flags, - enc_callee, - gas_limit, - enc_transferred_value, - enc_input, - Some(output), - ); - match call_result { - Ok(()) | Err(ReturnErrorCode::CalleeReverted) => { - let decoded = scale::DecodeAll::decode_all(&mut &output[..])?; - Ok(decoded) - } - Err(actual_error) => Err(actual_error.into()), - } - } - - fn invoke_contract( - &mut self, - params: &CallParams, Args, R>, - ) -> Result> - where - E: Environment, - Args: scale::Encode, - R: scale::Decode, - { - let mut scope = self.scoped_buffer(); - let ref_time_limit = params.ref_time_limit(); - let proof_size_limit = params.proof_size_limit(); - let storage_deposit_limit = params - .storage_deposit_limit() - .map(|limit| &*scope.take_encoded(limit)); - let enc_callee = scope.take_encoded(params.callee()); - let enc_transferred_value = scope.take_encoded(params.transferred_value()); - let call_flags = params.call_flags(); - let enc_input = if !call_flags.contains(CallFlags::FORWARD_INPUT) - && !call_flags.contains(CallFlags::CLONE_INPUT) - { - scope.take_encoded(params.exec_input()) - } else { - &mut [] - }; - let output = &mut scope.take_rest(); - let flags = params.call_flags(); - #[allow(deprecated)] - let call_result = ext::call_v2( - *flags, - enc_callee, - ref_time_limit, - proof_size_limit, - storage_deposit_limit, - enc_transferred_value, - enc_input, - Some(output), - ); - match call_result { - Ok(()) | Err(ReturnErrorCode::CalleeReverted) => { - let decoded = scale::DecodeAll::decode_all(&mut &output[..])?; - Ok(decoded) - } - Err(actual_error) => Err(actual_error.into()), - } - } - - fn invoke_contract_delegate( - &mut self, - params: &CallParams, Args, R>, - ) -> Result> - where - E: Environment, - Args: scale::Encode, - R: scale::Decode, - { - let mut scope = self.scoped_buffer(); - let call_flags = params.call_flags(); - let enc_code_hash = scope.take_encoded(params.code_hash()); - let enc_input = if !call_flags.contains(CallFlags::FORWARD_INPUT) - && !call_flags.contains(CallFlags::CLONE_INPUT) - { - scope.take_encoded(params.exec_input()) - } else { - &mut [] - }; - let output = &mut scope.take_rest(); - let flags = params.call_flags(); - let call_result = - ext::delegate_call(*flags, enc_code_hash, enc_input, Some(output)); - match call_result { - Ok(()) | Err(ReturnErrorCode::CalleeReverted) => { - let decoded = scale::DecodeAll::decode_all(&mut &output[..])?; - Ok(decoded) - } - Err(actual_error) => Err(actual_error.into()), - } - } - - fn instantiate_contract( - &mut self, - params: &CreateParams, Args, Salt, RetType>, - ) -> Result< - ink_primitives::ConstructorResult< - >::Output, - >, - > - where - E: Environment, - ContractRef: FromAccountId, - Args: scale::Encode, - Salt: AsRef<[u8]>, - RetType: ConstructorReturnType, - { - let mut scoped = self.scoped_buffer(); - let ref_time_limit = params.ref_time_limit(); - let proof_size_limit = params.proof_size_limit(); - let storage_deposit_limit = params - .storage_deposit_limit() - .map(|limit| &*scoped.take_encoded(limit)); - let enc_code_hash = scoped.take_encoded(params.code_hash()); - let enc_endowment = scoped.take_encoded(params.endowment()); - let enc_input = scoped.take_encoded(params.exec_input()); - let out_address = &mut scoped.take_max_encoded_len::(); - let salt = params.salt_bytes().as_ref(); - let out_return_value = &mut scoped.take_rest(); - - let instantiate_result = ext::instantiate_v2( - enc_code_hash, - ref_time_limit, - proof_size_limit, - storage_deposit_limit, - enc_endowment, - enc_input, - Some(out_address), - Some(out_return_value), - salt, - ); - - crate::engine::decode_instantiate_result::<_, E, ContractRef, RetType>( - instantiate_result.map_err(Into::into), - &mut &out_address[..], - &mut &out_return_value[..], - ) - } - - fn instantiate_contract_v1( - &mut self, - params: &CreateParams, - ) -> Result< - ink_primitives::ConstructorResult< - >::Output, - >, - > - where - E: Environment, - ContractRef: FromAccountId, - Args: scale::Encode, - Salt: AsRef<[u8]>, - RetType: ConstructorReturnType, - { - let mut scoped = self.scoped_buffer(); - let gas_limit = params.gas_limit(); - let enc_code_hash = scoped.take_encoded(params.code_hash()); - let enc_endowment = scoped.take_encoded(params.endowment()); - let enc_input = scoped.take_encoded(params.exec_input()); - let out_address = &mut scoped.take_max_encoded_len::(); - let salt = params.salt_bytes().as_ref(); - let out_return_value = &mut scoped.take_rest(); - - #[allow(deprecated)] - let instantiate_result = ext::instantiate_v1( - enc_code_hash, - gas_limit, - enc_endowment, - enc_input, - Some(out_address), - Some(out_return_value), - salt, - ); - - crate::engine::decode_instantiate_result::<_, E, ContractRef, RetType>( - instantiate_result.map_err(Into::into), - &mut &out_address[..], - &mut &out_return_value[..], - ) - } - - fn terminate_contract(&mut self, beneficiary: E::AccountId) -> ! - where - E: Environment, - { - let buffer = self.scoped_buffer().take_encoded(&beneficiary); - ext::terminate_v1(buffer); - } - - fn transfer(&mut self, destination: E::AccountId, value: E::Balance) -> Result<()> - where - E: Environment, - { - let mut scope = self.scoped_buffer(); - let enc_destination = scope.take_encoded(&destination); - let enc_value = scope.take_encoded(&value); - ext::transfer(enc_destination, enc_value).map_err(Into::into) - } - - fn weight_to_fee(&mut self, gas: u64) -> E::Balance { - let mut result = ::Bytes::default(); - ext::weight_to_fee(gas, &mut result.as_mut()); - ::from_le_bytes(result) - } - - fn is_contract(&mut self, account_id: &E::AccountId) -> bool - where - E: Environment, - { - let mut scope = self.scoped_buffer(); - let enc_account_id = scope.take_encoded(account_id); - ext::is_contract(enc_account_id) - } - - fn caller_is_origin(&mut self) -> bool - where - E: Environment, - { - ext::caller_is_origin() - } - - fn caller_is_root(&mut self) -> bool - where - E: Environment, - { - // `ext::caller_is_root()` currently returns `u32`. - // See https://github.com/paritytech/polkadot-sdk/issues/6767 for more details. - let ret = ext::caller_is_root(); - match ret { - 0u32 => false, - 1u32 => true, - _ => panic!("Invalid value for bool conversion: {}", ret), - } - } - - fn code_hash(&mut self, account_id: &E::AccountId) -> Result - where - E: Environment, - { - let mut scope = self.scoped_buffer(); - let output = scope.take_max_encoded_len::(); - scope.append_encoded(account_id); - let enc_account_id = scope.take_appended(); - - ext::code_hash(enc_account_id, output)?; - let hash = scale::Decode::decode(&mut &output[..])?; - Ok(hash) - } - - fn own_code_hash(&mut self) -> Result - where - E: Environment, - { - let output = &mut self.scoped_buffer().take_max_encoded_len::(); - ext::own_code_hash(output); - let hash = scale::Decode::decode(&mut &output[..])?; - Ok(hash) - } - - fn call_runtime(&mut self, call: &Call) -> Result<()> - where - E: Environment, - Call: scale::Encode, - { - let mut scope = self.scoped_buffer(); - let enc_call = scope.take_encoded(call); - ext::call_runtime(enc_call).map_err(Into::into) - } - - fn lock_delegate_dependency(&mut self, code_hash: &E::Hash) - where - E: Environment, - { - let mut scope = self.scoped_buffer(); - let enc_code_hash = scope.take_encoded(code_hash); - ext::lock_delegate_dependency(enc_code_hash) - } - - fn unlock_delegate_dependency(&mut self, code_hash: &E::Hash) - where - E: Environment, - { - let mut scope = self.scoped_buffer(); - let enc_code_hash = scope.take_encoded(code_hash); - ext::unlock_delegate_dependency(enc_code_hash) - } - - fn xcm_execute(&mut self, msg: &VersionedXcm) -> Result<()> - where - E: Environment, - Call: scale::Encode, - { - let mut scope = self.scoped_buffer(); - - let enc_msg = scope.take_encoded(msg); - - #[allow(deprecated)] - ext::xcm_execute(enc_msg).map_err(Into::into) - } - - fn xcm_send( - &mut self, - dest: &xcm::VersionedLocation, - msg: &VersionedXcm, - ) -> Result - where - E: Environment, - Call: scale::Encode, - { - let mut scope = self.scoped_buffer(); - let output = scope.take(32); - scope.append_encoded(dest); - let enc_dest = scope.take_appended(); - - scope.append_encoded(msg); - let enc_msg = scope.take_appended(); - #[allow(deprecated)] - ext::xcm_send(enc_dest, enc_msg, output.try_into().unwrap())?; - let hash: xcm::v4::XcmHash = scale::Decode::decode(&mut &output[..])?; - Ok(hash) - } -} diff --git a/crates/env/src/engine/on_chain/mod.rs b/crates/env/src/engine/on_chain/mod.rs index 274384174b7..1b687703bfa 100644 --- a/crates/env/src/engine/on_chain/mod.rs +++ b/crates/env/src/engine/on_chain/mod.rs @@ -13,7 +13,7 @@ // limitations under the License. mod buffer; -mod impls; +mod pallet_revive; use self::buffer::{ EncodeScope, diff --git a/crates/env/src/engine/on_chain/impls/pallet_revive.rs b/crates/env/src/engine/on_chain/pallet_revive.rs similarity index 85% rename from crates/env/src/engine/on_chain/impls/pallet_revive.rs rename to crates/env/src/engine/on_chain/pallet_revive.rs index 8a15edd1eaf..ef93960b350 100644 --- a/crates/env/src/engine/on_chain/impls/pallet_revive.rs +++ b/crates/env/src/engine/on_chain/pallet_revive.rs @@ -19,7 +19,7 @@ use crate::{ ConstructorReturnType, CreateParams, DelegateCall, - FromAccountId, + FromAddr, LimitParamsV2, }, engine::on_chain::{ @@ -46,6 +46,11 @@ use crate::{ Result, TypedEnvBackend, }; +use ink_primitives::{ + H160, + H256, + U256, +}; use ink_storage_traits::{ decode_all, Storable, @@ -193,17 +198,6 @@ impl EnvInstance { result.as_mut()[..].copy_from_slice(&u256[..len]); ::from_le_bytes(result) } - - /// Returns the contract property value. - #[inline(always)] - fn get_property(&mut self, ext_fn: fn(output: &mut &mut [u8])) -> Result - where - T: scale::Decode, - { - let full_scope = &mut self.scoped_buffer().take_rest(); - ext_fn(full_scope); - scale::Decode::decode(&mut &full_scope[..]).map_err(Into::into) - } } const STORAGE_FLAGS: StorageFlags = StorageFlags::empty(); @@ -276,7 +270,9 @@ impl EnvBackend for EnvInstance { where T: scale::Decode, { - self.get_property::(ext::input) + let full_scope = &mut self.scoped_buffer().take_rest(); + ext::call_data_copy(full_scope, 0); + scale::Decode::decode(&mut &full_scope[..]).map_err(Into::into) } fn return_value(&mut self, flags: ReturnFlags, return_value: &R) -> ! @@ -384,33 +380,26 @@ impl EnvBackend for EnvInstance { fn set_code_hash(&mut self, code_hash_ptr: &[u8]) -> Result<()> { let code_hash: &[u8; 32] = code_hash_ptr.try_into().unwrap(); - ext::set_code_hash(code_hash).map_err(Into::into) + ext::set_code_hash(code_hash); + Ok(()) // todo } } +// TODO remove anything with hash impl TypedEnvBackend for EnvInstance { - fn caller(&mut self) -> E::AccountId { + fn caller(&mut self) -> H160 { let mut scope = self.scoped_buffer(); let h160: &mut [u8; 20] = scope.take(20).try_into().unwrap(); ext::caller(h160); - - let account_id: &mut [u8; 32] = scope.take(32).try_into().unwrap(); - // TODO - // ext::to_account_id(h160, account_id); - - scale::Decode::decode(&mut &account_id[..]) + scale::Decode::decode(&mut &h160[..]) .expect("The executed contract must have a caller with a valid account id.") } - fn transferred_value(&mut self) -> E::Balance { - self.get_property_little_endian::(ext::value_transferred) + fn transferred_value(&mut self) -> U256 { + self.get_property_little_endian::(ext::value_transferred) } - // fn gas_left(&mut self) -> u64 { - // self.get_property_little_endian::(ext::gas_left) - // } - fn block_timestamp(&mut self) -> E::Timestamp { self.get_property_little_endian::(ext::now) } @@ -418,6 +407,7 @@ impl TypedEnvBackend for EnvInstance { fn account_id(&mut self) -> E::AccountId { let mut scope = self.scoped_buffer(); + // todo this is wrong let account_id: &mut [u8; 32] = scope.take(32).try_into().unwrap(); account_id[20..].fill(0xEE); let h160: &mut [u8; 20] = account_id[..20].as_mut().try_into().unwrap(); @@ -427,6 +417,16 @@ impl TypedEnvBackend for EnvInstance { .expect("A contract being executed must have a valid account id.") } + fn address(&mut self) -> H160 { + let mut scope = self.scoped_buffer(); + + let h160: &mut [u8; 20] = scope.take(20).try_into().unwrap(); + ext::address(h160); + + scale::Decode::decode(&mut &h160[..]) + .expect("A contract being executed must have a valid address.") + } + fn balance(&mut self) -> E::Balance { self.get_property_little_endian::(ext::balance) } @@ -489,7 +489,7 @@ impl TypedEnvBackend for EnvInstance { }; let output = &mut scope.take_rest(); let flags = params.call_flags(); - #[allow(deprecated)] + #[allow(deprecated)] // todo let call_result = ext::call( *flags, enc_callee, @@ -511,7 +511,7 @@ impl TypedEnvBackend for EnvInstance { fn invoke_contract_delegate( &mut self, - _params: &CallParams, Args, R>, + _params: &CallParams, ) -> Result> where E: Environment, @@ -531,7 +531,7 @@ impl TypedEnvBackend for EnvInstance { > where E: Environment, - ContractRef: FromAccountId, + ContractRef: FromAddr, Args: scale::Encode, Salt: AsRef<[u8]>, RetType: ConstructorReturnType, @@ -569,17 +569,14 @@ impl TypedEnvBackend for EnvInstance { Some(salt), ); - crate::engine::decode_instantiate_result::<_, E, ContractRef, RetType>( + crate::engine::decode_instantiate_result::<_, ContractRef, RetType>( instantiate_result.map_err(Into::into), &mut &out_address[..], &mut &out_return_value[..], ) } - fn terminate_contract(&mut self, beneficiary: E::AccountId) -> ! - where - E: Environment, - { + fn terminate_contract(&mut self, beneficiary: H160) -> ! { let buffer: &mut [u8; 20] = self.scoped_buffer().take_encoded(&beneficiary) [0..20] .as_mut() @@ -588,15 +585,61 @@ impl TypedEnvBackend for EnvInstance { ext::terminate(buffer); } - fn transfer( - &mut self, - _destination: E::AccountId, - _value: E::Balance, - ) -> Result<()> + fn transfer(&mut self, destination: H160, value: E::Balance) -> Result<()> where E: Environment, { - todo!("has to be implemented") + let mut scope = self.scoped_buffer(); + /* + let ref_time_limit = params.ref_time_limit(); + let proof_size_limit = params.proof_size_limit(); + let storage_deposit_limit = params.storage_deposit_limit().map(|limit| { + let mut enc_storage_limit = EncodeScope::from(scope.take(32)); + scale::Encode::encode_to(&limit, &mut enc_storage_limit); + let enc_storage_limit: &mut [u8; 32] = + enc_storage_limit.into_buffer().try_into().unwrap(); + enc_storage_limit + }); + + */ + + let enc_callee: &[u8; 20] = destination.as_ref().try_into().unwrap(); + + //let value: &[u8] = scale::Encode::encode_to(value, &mut scope); + //let value: u128 = scale::Decode::decode(&mut &value[..]).expect("foo"); + //let value_u128: u128 = value.try_into().expect("oh no"); //core::mem::transmute(value); + // todo + let value_u128: u128 = unsafe { + core::mem::transmute_copy::<::Balance, u128>(&value) }; + //let value = scale::Decode::primitive_types::U256::from(value_u128); + let value = U256::from(value_u128); + let mut enc_value = EncodeScope::from(scope.take(32)); + scale::Encode::encode_to(&value, &mut enc_value); + let enc_value: &mut [u8; 32] = + enc_value.into_buffer().try_into().unwrap(); + + let output = &mut scope.take_rest(); + #[allow(deprecated)] + let call_result = ext::call( + CallFlags::empty(), + enc_callee, + 0u64, + 0u64, + None, + //ref_time_limit, + //proof_size_limit, + //storage_deposit_limit.as_deref(), + enc_value, + &[], + Some(output), + ); + match call_result { + Ok(()) | Err(ReturnErrorCode::CalleeReverted) => { + let decoded = scale::DecodeAll::decode_all(&mut &output[..])?; + Ok(decoded) + } + Err(actual_error) => Err(actual_error.into()), + } } fn weight_to_fee(&mut self, gas: u64) -> E::Balance { @@ -610,16 +653,11 @@ impl TypedEnvBackend for EnvInstance { ::from_le_bytes(result) } - fn is_contract(&mut self, account_id: &E::AccountId) -> bool - where - E: Environment, - { + fn is_contract(&mut self, addr: &H160) -> bool { let mut scope = self.scoped_buffer(); - let enc_account_id: &mut [u8; 20] = scope.take_encoded(account_id)[..20] - .as_mut() - .try_into() - .unwrap(); - ext::is_contract(enc_account_id) + let enc_addr: &mut [u8; 20] = + scope.take_encoded(addr)[..20].as_mut().try_into().unwrap(); + ext::is_contract(enc_addr) } fn caller_is_origin(&mut self) -> bool @@ -643,31 +681,25 @@ impl TypedEnvBackend for EnvInstance { } } - fn code_hash(&mut self, account_id: &E::AccountId) -> Result - where - E: Environment, - { + fn code_hash(&mut self, addr: &H160) -> Result { let mut scope = self.scoped_buffer(); - let enc_account_id: &mut [u8; 20] = scope.take_encoded(account_id)[..20] - .as_mut() - .try_into() - .unwrap(); + // todo can be simplified + let enc_addr: &mut [u8; 20] = + scope.take_encoded(addr)[..20].as_mut().try_into().unwrap(); let output: &mut [u8; 32] = - scope.take_max_encoded_len::().try_into().unwrap(); - // TODO - // ext::code_hash(enc_account_id, output)?; - ext::code_hash(enc_account_id, output); + scope.take_max_encoded_len::().try_into().unwrap(); + ext::code_hash(enc_addr, output); let hash = scale::Decode::decode(&mut &output[..])?; Ok(hash) } - fn own_code_hash(&mut self) -> Result + fn own_code_hash(&mut self) -> Result where E: Environment, { let output: &mut [u8; 32] = &mut self .scoped_buffer() - .take_max_encoded_len::() + .take_max_encoded_len::() .try_into() .unwrap(); ext::own_code_hash(output); @@ -685,7 +717,7 @@ impl TypedEnvBackend for EnvInstance { ext::call_runtime(enc_call).map_err(Into::into) } - fn lock_delegate_dependency(&mut self, code_hash: &E::Hash) + fn lock_delegate_dependency(&mut self, code_hash: &H256) where E: Environment, { @@ -695,7 +727,7 @@ impl TypedEnvBackend for EnvInstance { ext::lock_delegate_dependency(enc_code_hash) } - fn unlock_delegate_dependency(&mut self, code_hash: &E::Hash) + fn unlock_delegate_dependency(&mut self, code_hash: &H256) where E: Environment, { diff --git a/crates/env/src/lib.rs b/crates/env/src/lib.rs index 79bd71a2eef..93bb579f71d 100644 --- a/crates/env/src/lib.rs +++ b/crates/env/src/lib.rs @@ -51,10 +51,6 @@ #[const_env::from_env("INK_STATIC_BUFFER_SIZE")] pub const BUFFER_SIZE: usize = 16384; -#[cfg(all(not(feature = "std"), target_arch = "wasm32"))] -#[allow(unused_extern_crates)] -extern crate rlibc; - #[cfg(not(any(feature = "std", feature = "no-panic-handler")))] #[allow(unused_variables)] #[panic_handler] @@ -63,16 +59,14 @@ fn panic(info: &core::panic::PanicInfo) -> ! { debug_print!("{}\n", info); cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { - core::arch::wasm32::unreachable(); - } else if #[cfg(target_arch = "riscv32")] { + if #[cfg(target_arch = "riscv64")] { // Safety: The unimp instruction is guaranteed to trap unsafe { core::arch::asm!("unimp"); core::hint::unreachable_unchecked(); } } else { - core::compile_error!("ink! only supports wasm32 and riscv32"); + core::compile_error!("ink! only supports riscv64"); } } } diff --git a/crates/env/src/types.rs b/crates/env/src/types.rs index 0e26f9b29b1..7326c1bc082 100644 --- a/crates/env/src/types.rs +++ b/crates/env/src/types.rs @@ -32,10 +32,11 @@ //! the trait bounds on the `Environment` trait types. use super::arithmetic::AtLeast32BitUnsigned; -use ink_primitives::{ - AccountId, - Clear, - Hash, +use ink_primitives::{AccountId, Clear, Hash, H160, U256}; +use scale::{ + Decode, + Encode, + MaxEncodedLen, }; #[cfg(feature = "std")] use scale_info::TypeInfo; @@ -94,6 +95,38 @@ impl FromLittleEndian for u128 { } } +impl FromLittleEndian for U256 { + type Bytes = [u8; 32]; + + #[inline] + fn from_le_bytes(bytes: Self::Bytes) -> Self { + U256::from_little_endian(&bytes) + //U256::from_le_bytes(bytes) + } +} + +/* +impl FromLittleEndian for H160 { + type Bytes = [u8; 20]; + + #[inline] + fn from_le_bytes(bytes: Self::Bytes) -> Self { + //H160::from_le_bytes(bytes) + ink_primitives::H160::from_le_bytes(bytes) + } +} + +impl FromLittleEndian for H256 { + type Bytes = [u8; 32]; + + #[inline] + fn from_le_bytes(bytes: Self::Bytes) -> Self { + ink_primitives::H256::from_le_bytes(bytes) + } +} + */ + +/// todo remove /// A trait to enforce that a type should be an [`Environment::AccountId`]. /// /// If you have an [`Environment`] which uses an [`Environment::AccountId`] type other @@ -106,6 +139,8 @@ pub trait AccountIdGuard {} /// used in the [`DefaultEnvironment`]. impl AccountIdGuard for AccountId {} +impl AccountIdGuard for H160 {} + cfg_if::cfg_if! { if #[cfg(feature = "std")] { pub trait CodecAsType: scale_decode::DecodeAsType + scale_encode::EncodeAsType {} @@ -160,6 +195,7 @@ pub trait Environment: Clone { + Ord + AsRef<[u8]> + AsMut<[u8]>; + //+ frame_support::traits::IsType; /// The type of a timestamp. type Timestamp: 'static @@ -191,6 +227,9 @@ pub trait Environment: Clone { /// /// [chain_extension]: https://use-ink.github.io/ink/ink/attr.chain_extension.html type ChainExtension; + + /// TODO comment + type EventRecord: 'static + scale::Codec; } /// Placeholder for chains that have no defined chain extension. @@ -211,11 +250,28 @@ impl Environment for DefaultEnvironment { type Timestamp = Timestamp; type BlockNumber = BlockNumber; type ChainExtension = NoChainExtension; + type EventRecord = EventRecord; } /// The default balance type. pub type Balance = u128; +//pub type Balance = U256; + +//#[derive(codec::Encode, codec::Decode, Clone, PartialEq, Eq, Debug)] +//struct U256(scale_decode::ext::primitive_types::U256); +/* +impl num_traits::Saturating for U256 { + fn saturating_add(self, v: Self) -> Self { + ::saturating_add(self, v) + } + + fn saturating_sub(self, v: Self) -> Self { + ::saturating_sub(self, v) + } +} +*/ + /// The default timestamp type. pub type Timestamp = u64; @@ -224,3 +280,42 @@ pub type Gas = u64; /// The default block number type. pub type BlockNumber = u32; + +// todo replace with () +#[derive(Encode, Decode, MaxEncodedLen, Debug)] +pub struct RuntimeEvent(); + +/// The default event record type. +pub type EventRecord = EventRecordFoo; + +#[derive(Encode, Decode, Debug)] +#[cfg_attr(feature = "std", derive(TypeInfo))] +pub struct EventRecordFoo { + /// The phase of the block it happened in. + pub phase: Phase, + /// The event itself. + pub event: E, + /// The list of the topics this event has. + pub topics: ink_prelude::vec::Vec, +} + +/// A phase of a block's execution. +#[derive(Debug, Encode, Decode, MaxEncodedLen)] +//#[cfg_attr(feature = "std", derive(Serialize, PartialEq, Eq, Clone))] +#[cfg_attr(feature = "std", derive(PartialEq, Eq, Clone, TypeInfo))] +pub enum Phase { + /// Applying an extrinsic. + ApplyExtrinsic(u32), + /// Finalizing the block. + Finalization, + /// Initializing the block. + Initialization, +} + +/// The type of origins supported by `pallet-revive`. +#[derive(Clone, ::scale::Encode, ::scale::Decode, PartialEq)] +#[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] +pub enum Origin { + Root, + Signed(E::AccountId), +} diff --git a/crates/ink/Cargo.toml b/crates/ink/Cargo.toml index c1b07ea42c3..3b407f049e0 100644 --- a/crates/ink/Cargo.toml +++ b/crates/ink/Cargo.toml @@ -22,15 +22,14 @@ ink_primitives = { workspace = true } ink_metadata = { workspace = true, optional = true } ink_prelude = { workspace = true } ink_macro = { workspace = true } -pallet-contracts-uapi = { workspace = true } pallet-revive-uapi = { workspace = true } scale = { workspace = true } scale-info = { workspace = true, default-features = false, features = ["derive"], optional = true } derive_more = { workspace = true, features = ["from"] } # TODO add explainer -xcm = { workspace = true, default-features = false } -sp-io = { version = "38.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } +xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +sp-io = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } polkavm-derive = { workspace = true } @@ -65,8 +64,5 @@ no-allocator = [ "ink_env/no-allocator" ] # Disable the ink! provided panic handler. no-panic-handler = ["ink_env/no-panic-handler"] -revive = [ - "ink_env/revive", - "ink_storage/revive", - "ink_macro/revive" -] +# Just for the ui tests, which use this `Cargo.toml` +# ink-as-dependency = [] diff --git a/crates/ink/codegen/Cargo.toml b/crates/ink/codegen/Cargo.toml index bb05d9d94b2..9bd385502be 100644 --- a/crates/ink/codegen/Cargo.toml +++ b/crates/ink/codegen/Cargo.toml @@ -47,4 +47,3 @@ std = [ "serde/std", "derive_more/std" ] -revive = [ ] diff --git a/crates/ink/codegen/src/generator/as_dependency/call_builder.rs b/crates/ink/codegen/src/generator/as_dependency/call_builder.rs index 56475a391f2..bae12bcbcea 100644 --- a/crates/ink/codegen/src/generator/as_dependency/call_builder.rs +++ b/crates/ink/codegen/src/generator/as_dependency/call_builder.rs @@ -94,7 +94,7 @@ impl CallBuilder<'_> { )] #[::ink::scale_derive(Encode, Decode, TypeInfo)] pub struct #cb_ident { - account_id: AccountId, + addr: ::ink::H160, } const _: () = { @@ -117,29 +117,29 @@ impl CallBuilder<'_> { let span = self.contract.module().storage().span(); let cb_ident = Self::call_builder_ident(); quote_spanned!(span=> - impl ::ink::env::call::FromAccountId for #cb_ident { + impl ::ink::env::call::FromAddr for #cb_ident { #[inline] - fn from_account_id(account_id: AccountId) -> Self { - Self { account_id } + fn from_addr(addr: ::ink::H160) -> Self { + Self { addr } } } - impl ::ink::ToAccountId for #cb_ident { + impl ::ink::ToAddr for #cb_ident { #[inline] - fn to_account_id(&self) -> AccountId { - ::clone(&self.account_id) + fn to_addr(&self) -> ::ink::H160 { + <::ink::H160 as ::core::clone::Clone>::clone(&self.addr) } } - impl ::core::convert::AsRef for #cb_ident { - fn as_ref(&self) -> &AccountId { - &self.account_id + impl ::core::convert::AsRef<::ink::H160> for #cb_ident { + fn as_ref(&self) -> &::ink::H160 { + &self.addr } } - impl ::core::convert::AsMut for #cb_ident { - fn as_mut(&mut self) -> &mut AccountId { - &mut self.account_id + impl ::core::convert::AsMut<::ink::H160> for #cb_ident { + fn as_mut(&mut self) -> &mut ::ink::H160 { + &mut self.addr } } ) @@ -204,8 +204,9 @@ impl CallBuilder<'_> { // only an `AccountId` to a shared reference to another type of which // we know that it also thinly wraps an `AccountId`. // Furthermore both types use `repr(transparent)`. + // todo unsafe { - &*(&self.account_id as *const AccountId as *const Self::Forwarder) + &*(&self.addr as *const ::ink::H160 as *const Self::Forwarder) } } @@ -218,7 +219,7 @@ impl CallBuilder<'_> { // we know that it also thinly wraps an `AccountId`. // Furthermore both types use `repr(transparent)`. unsafe { - &mut *(&mut self.account_id as *mut AccountId as *mut Self::Forwarder) + &mut *(&mut self.addr as *mut ::ink::H160 as *mut Self::Forwarder) } } @@ -399,7 +400,7 @@ impl CallBuilder<'_> { #( , #input_bindings : #input_types )* ) -> #output_type { ::ink::env::call::build_call::() - .call(::ink::ToAccountId::to_account_id(self)) + .call(::ink::ToAddr::to_addr(self)) .exec_input( ::ink::env::call::ExecutionInput::new( ::ink::env::call::Selector::new([ #( #selector_bytes ),* ]) diff --git a/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs b/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs index 69ebceda761..0f874fdabc7 100644 --- a/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs +++ b/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs @@ -151,33 +151,33 @@ impl ContractRef<'_> { let storage_ident = self.contract.module().storage().ident(); let ref_ident = self.generate_contract_ref_ident(); quote_spanned!(span=> - impl ::ink::env::call::FromAccountId for #ref_ident { + impl ::ink::env::call::FromAddr for #ref_ident { #[inline] - fn from_account_id(account_id: AccountId) -> Self { + fn from_addr(addr: ::ink::H160) -> Self { Self { inner: <<#storage_ident as ::ink::codegen::ContractCallBuilder>::Type - as ::ink::env::call::FromAccountId>::from_account_id(account_id) + as ::ink::env::call::FromAddr>::from_addr(addr) } } } - impl ::ink::ToAccountId for #ref_ident { + impl ::ink::ToAddr for #ref_ident { #[inline] - fn to_account_id(&self) -> AccountId { + fn to_addr(&self) -> ::ink::H160 { <<#storage_ident as ::ink::codegen::ContractCallBuilder>::Type - as ::ink::ToAccountId>::to_account_id(&self.inner) + as ::ink::ToAddr>::to_addr(&self.inner) } } - impl ::core::convert::AsRef for #ref_ident { - fn as_ref(&self) -> &AccountId { - <_ as ::core::convert::AsRef>::as_ref(&self.inner) + impl ::core::convert::AsRef<::ink::H160> for #ref_ident { + fn as_ref(&self) -> &::ink::H160 { + <_ as ::core::convert::AsRef<::ink::H160>>::as_ref(&self.inner) } } - impl ::core::convert::AsMut for #ref_ident { - fn as_mut(&mut self) -> &mut AccountId { - <_ as ::core::convert::AsMut>::as_mut(&mut self.inner) + impl ::core::convert::AsMut<::ink::H160> for #ref_ident { + fn as_mut(&mut self) -> &mut ::ink::H160 { + <_ as ::core::convert::AsMut<::ink::H160>>::as_mut(&mut self.inner) } } ) @@ -459,7 +459,6 @@ impl ContractRef<'_> { ) -> ::ink::env::call::CreateBuilder< Environment, Self, - ::ink::env::call::utils::Unset, ::ink::env::call::utils::Set<::ink::env::call::LimitParamsV2<<#storage_ident as ::ink::env::ContractEnv>::Env>>, ::ink::env::call::utils::Unset, ::ink::env::call::utils::Set<::ink::env::call::ExecutionInput<#arg_list>>, diff --git a/crates/ink/codegen/src/generator/dispatch.rs b/crates/ink/codegen/src/generator/dispatch.rs index 21da1b1755a..374d731ad36 100644 --- a/crates/ink/codegen/src/generator/dispatch.rs +++ b/crates/ink/codegen/src/generator/dispatch.rs @@ -354,17 +354,15 @@ impl Dispatch<'_> { let any_message_accepts_payment = self.any_message_accepts_payment(messages); let fn_call: syn::ItemFn = syn::parse_quote! { - #[cfg(any(target_arch = "wasm32", target_arch = "riscv32"))] - #[cfg_attr(target_arch = "wasm32", no_mangle)] - #[ink::polkavm_export(abi = ink::polkavm_derive::default_abi)] + #[cfg(target_arch = "riscv64")] + #[::ink::polkavm_export(abi = ::ink::polkavm_derive::default_abi)] pub extern "C" fn call() { internal_call() } }; let fn_deploy: syn::ItemFn = syn::parse_quote! { - #[cfg(any(target_arch = "wasm32", target_arch = "riscv32"))] - #[cfg_attr(target_arch = "wasm32", no_mangle)] - #[ink::polkavm_export(abi = ink::polkavm_derive::default_abi)] + #[cfg(target_arch = "riscv64")] + #[::ink::polkavm_export(abi = ::ink::polkavm_derive::default_abi)] pub extern "C" fn deploy() { internal_deploy() } @@ -386,12 +384,12 @@ impl Dispatch<'_> { ::core::result::Result::Err(_decoding_error) => { let error = ::ink::ConstructorResult::Err(::ink::LangError::CouldNotReadInput); - // At this point we're unable to set the `Ok` variant to be the any "real" + // At this point we're unable to set the `Ok` variant to be the "real" // constructor output since we were unable to figure out what the caller wanted // to dispatch in the first place, so we set it to `()`. // // This is okay since we're going to only be encoding the `Err` variant - // into the output buffer anyways. + // into the output buffer anyway. ::ink::env::return_value::<::ink::ConstructorResult<()>>( ::ink::env::ReturnFlags::REVERT, &error, @@ -402,7 +400,7 @@ impl Dispatch<'_> { <<#storage_ident as ::ink::reflect::ContractConstructorDecoder>::Type as ::ink::reflect::ExecuteDispatchable>::execute_dispatchable(dispatchable) .unwrap_or_else(|error| { - ::core::panic!("dispatching ink! message failed: {}", error) + ::core::panic!("dispatching ink! constructor failed: {}", error) }) } @@ -413,21 +411,23 @@ impl Dispatch<'_> { .unwrap_or_else(|error| ::core::panic!("{}", error)) } + //::ink::env::debug_println!("before decode"); let dispatchable = match ::ink::env::decode_input::< <#storage_ident as ::ink::reflect::ContractMessageDecoder>::Type, >() { ::core::result::Result::Ok(decoded_dispatchable) => { + //::ink::env::debug_println!("in ok"); decoded_dispatchable } ::core::result::Result::Err(_decoding_error) => { let error = ::ink::MessageResult::Err(::ink::LangError::CouldNotReadInput); - // At this point we're unable to set the `Ok` variant to be the any "real" + // At this point we're unable to set the `Ok` variant to be the "real" // message output since we were unable to figure out what the caller wanted // to dispatch in the first place, so we set it to `()`. // // This is okay since we're going to only be encoding the `Err` variant - // into the output buffer anyways. + // into the output buffer anyway. ::ink::env::return_value::<::ink::MessageResult<()>>( ::ink::env::ReturnFlags::REVERT, &error, @@ -438,6 +438,7 @@ impl Dispatch<'_> { <<#storage_ident as ::ink::reflect::ContractMessageDecoder>::Type as ::ink::reflect::ExecuteDispatchable>::execute_dispatchable(dispatchable) .unwrap_or_else(|error| { + //::ink::env::debug_println!("dispatching failed"); ::core::panic!("dispatching ink! message failed: {}", error) }) } @@ -782,6 +783,22 @@ impl Dispatch<'_> { #( #cfg_attrs )* Self::#message_ident(input) => { if #any_message_accepts_payment && #deny_payment { + + /* + let bar = ::ink::reflect::DispatchError::UnknownSelector; + ::ink::env::debug_print!("bar: {:?}", bar); + //let foo = format_args!("{}", bar); + //let s = ::alloc::fmt::format(format_args!("{}", bar)); + let s = ::ink::env::format!("{}", ::ink::reflect::DispatchError::UnknownSelector); + if s.eq("encountered unknown selector") { + ink::env::debug_print!("TRUE"); + } else { + ink::env::debug_print!("FALSE"); + } + */ + + //let foo = Err(::ink::reflect::DispatchError::UnknownSelector); + //foo? ::ink::codegen::deny_payment::< <#storage_ident as ::ink::env::ContractEnv>::Env>()?; } diff --git a/crates/ink/codegen/src/generator/env.rs b/crates/ink/codegen/src/generator/env.rs index 76adad31c13..37ea1d6ec01 100644 --- a/crates/ink/codegen/src/generator/env.rs +++ b/crates/ink/codegen/src/generator/env.rs @@ -41,6 +41,7 @@ impl GenerateCode for Env<'_> { type BlockNumber = <<#storage_ident as ::ink::env::ContractEnv>::Env as ::ink::env::Environment>::BlockNumber; type ChainExtension = <<#storage_ident as ::ink::env::ContractEnv>::Env as ::ink::env::Environment>::ChainExtension; const MAX_EVENT_TOPICS: usize = <<#storage_ident as ::ink::env::ContractEnv>::Env as ::ink::env::Environment>::MAX_EVENT_TOPICS; + type EventRecord = <<#storage_ident as ::ink::env::ContractEnv>::Env as ::ink::env::Environment>::EventRecord; } } } diff --git a/crates/ink/codegen/src/generator/storage_item.rs b/crates/ink/codegen/src/generator/storage_item.rs index dc5a7e82d05..97f70d393b2 100644 --- a/crates/ink/codegen/src/generator/storage_item.rs +++ b/crates/ink/codegen/src/generator/storage_item.rs @@ -80,7 +80,7 @@ impl GenerateCode for StorageItem<'_> { } } -impl<'a> StorageItem<'a> { +impl StorageItem<'_> { fn generate_struct(&self, struct_item: DataStruct) -> TokenStream2 { let item = self.item; let struct_ident = item.ident(); diff --git a/crates/ink/codegen/src/generator/trait_def/call_builder.rs b/crates/ink/codegen/src/generator/trait_def/call_builder.rs index f111fb2e88b..33e7155d856 100644 --- a/crates/ink/codegen/src/generator/trait_def/call_builder.rs +++ b/crates/ink/codegen/src/generator/trait_def/call_builder.rs @@ -27,7 +27,7 @@ use quote::{ quote_spanned, }; -impl<'a> TraitDefinition<'a> { +impl TraitDefinition<'_> { /// Generates code for the global trait call builder for an ink! trait. /// /// # Note @@ -113,7 +113,8 @@ impl CallBuilder<'_> { where E: ::ink::env::Environment, { - account_id: ::AccountId, + addr: ::ink::H160, + marker: ::core::marker::PhantomData E>, } ) } @@ -134,7 +135,7 @@ impl CallBuilder<'_> { for #call_builder_ident where E: ::ink::env::Environment, - ::AccountId: ::ink::storage::traits::StorageLayout, + ::ink::H160: ::ink::storage::traits::StorageLayout, { fn layout( __key: &::ink::primitives::Key, @@ -144,8 +145,8 @@ impl CallBuilder<'_> { ::core::stringify!(#call_builder_ident), [ ::ink::metadata::layout::FieldLayout::new( - "account_id", - <::AccountId + "addr", + <::ink::H160 as ::ink::storage::traits::StorageLayout>::layout(__key) ) ] @@ -172,12 +173,13 @@ impl CallBuilder<'_> { impl ::core::clone::Clone for #call_builder_ident where E: ::ink::env::Environment, - ::AccountId: ::core::clone::Clone, + ::ink::H160: ::core::clone::Clone, { #[inline] fn clone(&self) -> Self { Self { - account_id: ::core::clone::Clone::clone(&self.account_id), + addr: ::core::clone::Clone::clone(&self.addr), + marker: self.marker, } } } @@ -186,26 +188,27 @@ impl CallBuilder<'_> { impl ::core::fmt::Debug for #call_builder_ident where E: ::ink::env::Environment, - ::AccountId: ::core::fmt::Debug, + ::ink::H160: ::core::fmt::Debug, { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct(::core::stringify!(#call_builder_ident)) - .field("account_id", &self.account_id) + .field("addr", &self.addr) .finish() } } #[cfg(feature = "std")] + // todo /// We require this manual implementation since the derive produces incorrect trait bounds. impl ::ink::scale_info::TypeInfo for #call_builder_ident where E: ::ink::env::Environment, - ::AccountId: ::ink::scale_info::TypeInfo + 'static, + ::ink::H160: ::ink::scale_info::TypeInfo + 'static, { - type Identity = ::AccountId; + type Identity = ::ink::H160; fn type_info() -> ::ink::scale_info::Type { - <::AccountId as ::ink::scale_info::TypeInfo>::type_info() + <::ink::H160 as ::ink::scale_info::TypeInfo>::type_info() } } ) @@ -222,52 +225,55 @@ impl CallBuilder<'_> { let span = self.span(); let call_builder_ident = self.ident(); quote_spanned!(span=> - impl ::ink::env::call::FromAccountId + impl ::ink::env::call::FromAddr for #call_builder_ident where E: ::ink::env::Environment, { #[inline] - fn from_account_id(account_id: ::AccountId) -> Self { - Self { account_id } + fn from_addr(addr: ::ink::H160) -> Self { + Self { + addr, + marker: ::core::default::Default::default(), + } } } - impl ::core::convert::From for #call_builder_ident + impl ::core::convert::From<::ink::H160> for #call_builder_ident where - E: ::ink::env::Environment, - AccountId: ::ink::env::AccountIdGuard, + E: ::ink::env::Environment, + ::ink::H160: ::ink::env::AccountIdGuard, { - fn from(value: AccountId) -> Self { - >::from_account_id(value) + fn from(value: ::ink::H160) -> Self { + ::from_addr(value) } } - impl ::ink::ToAccountId for #call_builder_ident + impl ::ink::ToAddr for #call_builder_ident where E: ::ink::env::Environment, { #[inline] - fn to_account_id(&self) -> ::AccountId { - <::AccountId as ::core::clone::Clone>::clone(&self.account_id) + fn to_addr(&self) -> ::ink::H160 { + <::ink::H160 as ::core::clone::Clone>::clone(&self.addr) } } - impl ::core::convert::AsRef for #call_builder_ident + impl ::core::convert::AsRef<::ink::H160> for #call_builder_ident where - E: ::ink::env::Environment, + E: ::ink::env::Environment, { - fn as_ref(&self) -> &AccountId { - &self.account_id + fn as_ref(&self) -> &::ink::H160 { + &self.addr } } - impl ::core::convert::AsMut for #call_builder_ident + impl ::core::convert::AsMut<::ink::H160> for #call_builder_ident where - E: ::ink::env::Environment, + E: ::ink::env::Environment, { - fn as_mut(&mut self) -> &mut AccountId { - &mut self.account_id + fn as_mut(&mut self) -> &mut ::ink::H160 { + &mut self.addr } } ) @@ -279,7 +285,7 @@ impl CallBuilder<'_> { /// # Note /// /// Through the implementation of this trait it is possible to refer to the - /// ink! trait messsage builder that is associated to this ink! trait call builder. + /// ink! trait message builder that is associated to this ink! trait call builder. fn generate_message_builder_trait_impl(&self) -> TokenStream2 { let span = self.trait_def.span(); let call_builder_ident = self.ident(); @@ -400,7 +406,7 @@ impl CallBuilder<'_> { )* ) ) - .call(::ink::ToAccountId::to_account_id(self)) + .call(::ink::ToAddr::to_addr(self)) } ) } diff --git a/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs b/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs index 9904ffbb478..96ac280e7d9 100644 --- a/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs +++ b/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs @@ -27,7 +27,7 @@ use quote::{ quote_spanned, }; -impl<'a> TraitDefinition<'a> { +impl TraitDefinition<'_> { /// Generates code for the global trait call forwarder for an ink! trait. /// /// # Note @@ -136,7 +136,7 @@ impl CallForwarder<'_> { for #call_forwarder_ident where E: ::ink::env::Environment, - ::AccountId: ::ink::storage::traits::StorageLayout, + ::ink::H160: ::ink::storage::traits::StorageLayout, { fn layout( __key: &::ink::primitives::Key, @@ -164,7 +164,7 @@ impl CallForwarder<'_> { impl ::core::clone::Clone for #call_forwarder_ident where E: ::ink::env::Environment, - ::AccountId: ::core::clone::Clone, + ::ink::H160: ::core::clone::Clone, { #[inline] fn clone(&self) -> Self { @@ -179,11 +179,11 @@ impl CallForwarder<'_> { impl ::core::fmt::Debug for #call_forwarder_ident where E: ::ink::env::Environment, - ::AccountId: ::core::fmt::Debug, + ::ink::H160: ::core::fmt::Debug, { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct(::core::stringify!(#call_forwarder_ident)) - .field("account_id", &self.builder.account_id) + .field("addr", &self.builder.addr) .finish() } } @@ -193,7 +193,7 @@ impl CallForwarder<'_> { impl ::ink::scale_info::TypeInfo for #call_forwarder_ident where E: ::ink::env::Environment, - ::AccountId: ::ink::scale_info::TypeInfo + 'static, + ::ink::H160: ::ink::scale_info::TypeInfo + 'static, { type Identity = < ::Builder as ::ink::scale_info::TypeInfo @@ -219,54 +219,53 @@ impl CallForwarder<'_> { let span = self.span(); let call_forwarder_ident = self.ident(); quote_spanned!(span=> - impl ::ink::env::call::FromAccountId + impl ::ink::env::call::FromAddr for #call_forwarder_ident where E: ::ink::env::Environment, { #[inline] - fn from_account_id(account_id: ::AccountId) -> Self { + fn from_addr(addr: ::ink::H160) -> Self { Self { builder: <::Builder - as ::ink::env::call::FromAccountId>::from_account_id(account_id) } + as ::ink::env::call::FromAddr>::from_addr(addr) } } } - impl ::core::convert::From for #call_forwarder_ident + impl ::core::convert::From<::ink::H160> for #call_forwarder_ident where - E: ::ink::env::Environment, - AccountId: ::ink::env::AccountIdGuard, + E: ::ink::env::Environment, { - fn from(value: AccountId) -> Self { - >::from_account_id(value) + fn from(addr: ::ink::H160) -> Self { + ::from_addr(addr) } } - impl ::ink::ToAccountId for #call_forwarder_ident + impl ::ink::ToAddr for #call_forwarder_ident where E: ::ink::env::Environment, { #[inline] - fn to_account_id(&self) -> ::AccountId { + fn to_addr(&self) -> ::ink::H160 { <::Builder - as ::ink::ToAccountId>::to_account_id(&self.builder) + as ::ink::ToAddr>::to_addr(&self.builder) } } - impl ::core::convert::AsRef for #call_forwarder_ident + impl ::core::convert::AsRef<::ink::H160> for #call_forwarder_ident where - E: ::ink::env::Environment, + E: ::ink::env::Environment, { - fn as_ref(&self) -> &AccountId { - <_ as ::core::convert::AsRef>::as_ref(&self.builder) + fn as_ref(&self) -> &::ink::H160 { + <_ as ::core::convert::AsRef<::ink::H160>>::as_ref(&self.builder) } } - impl ::core::convert::AsMut for #call_forwarder_ident + impl ::core::convert::AsMut<::ink::H160> for #call_forwarder_ident where - E: ::ink::env::Environment, + E: ::ink::env::Environment, { - fn as_mut(&mut self) -> &mut AccountId { - <_ as ::core::convert::AsMut>::as_mut(&mut self.builder) + fn as_mut(&mut self) -> &mut ::ink::H160 { + <_ as ::core::convert::AsMut<::ink::H160>>::as_mut(&mut self.builder) } } ) diff --git a/crates/ink/codegen/src/generator/trait_def/definition.rs b/crates/ink/codegen/src/generator/trait_def/definition.rs index 9ea66e1f65b..9b256e267dd 100644 --- a/crates/ink/codegen/src/generator/trait_def/definition.rs +++ b/crates/ink/codegen/src/generator/trait_def/definition.rs @@ -23,8 +23,8 @@ use quote::{ quote_spanned, }; -impl<'a> TraitDefinition<'a> { - fn generate_for_message(message: ir::InkTraitMessage<'a>) -> TokenStream2 { +impl TraitDefinition<'_> { + fn generate_for_message(message: ir::InkTraitMessage<'_>) -> TokenStream2 { let span = message.span(); let attrs = message.attrs(); let sig = message.sig(); diff --git a/crates/ink/codegen/src/generator/trait_def/message_builder.rs b/crates/ink/codegen/src/generator/trait_def/message_builder.rs index 1864e8aab1a..4547dc60204 100644 --- a/crates/ink/codegen/src/generator/trait_def/message_builder.rs +++ b/crates/ink/codegen/src/generator/trait_def/message_builder.rs @@ -27,7 +27,7 @@ use quote::{ quote_spanned, }; -impl<'a> TraitDefinition<'a> { +impl TraitDefinition<'_> { /// Generates code for the global trait call builder for an ink! trait. /// /// # Note diff --git a/crates/ink/codegen/src/generator/trait_def/mod.rs b/crates/ink/codegen/src/generator/trait_def/mod.rs index 378ad3d258c..449b6e54163 100644 --- a/crates/ink/codegen/src/generator/trait_def/mod.rs +++ b/crates/ink/codegen/src/generator/trait_def/mod.rs @@ -35,7 +35,7 @@ pub struct TraitDefinition<'a> { trait_def: &'a ir::InkTraitDefinition, } -impl<'a> TraitDefinition<'a> { +impl TraitDefinition<'_> { /// Appends the trait suffix to the string and forms an identifier. /// /// This appends the `_$NAME_$TRAIT_ID` string to the prefix string diff --git a/crates/ink/codegen/src/generator/trait_def/trait_registry.rs b/crates/ink/codegen/src/generator/trait_def/trait_registry.rs index 85267921f4d..310d57cb6c3 100644 --- a/crates/ink/codegen/src/generator/trait_def/trait_registry.rs +++ b/crates/ink/codegen/src/generator/trait_def/trait_registry.rs @@ -42,7 +42,7 @@ use syn::{ spanned::Spanned, }; -impl<'a> TraitDefinition<'a> { +impl TraitDefinition<'_> { /// Generates the code for the global trait registry implementation. /// /// This also generates the code for the global trait info object which diff --git a/crates/ink/ir/src/ir/item_impl/callable.rs b/crates/ink/ir/src/ir/item_impl/callable.rs index ea10d9230b9..9391c6809df 100644 --- a/crates/ink/ir/src/ir/item_impl/callable.rs +++ b/crates/ink/ir/src/ir/item_impl/callable.rs @@ -92,7 +92,7 @@ impl<'a, C> CallableWithSelector<'a, C> { } } -impl<'a, C> Callable for CallableWithSelector<'a, C> +impl Callable for CallableWithSelector<'_, C> where C: Callable, { @@ -141,7 +141,7 @@ where } } -impl<'a, C> ::core::ops::Deref for CallableWithSelector<'a, C> { +impl ::core::ops::Deref for CallableWithSelector<'_, C> { type Target = C; fn deref(&self) -> &Self::Target { @@ -539,7 +539,7 @@ impl<'a> Iterator for InputsIter<'a> { } } -impl<'a> ExactSizeIterator for InputsIter<'a> { +impl ExactSizeIterator for InputsIter<'_> { fn len(&self) -> usize { self.iter.len() } diff --git a/crates/ink/ir/src/ir/utils.rs b/crates/ink/ir/src/ir/utils.rs index 5854dbfdb9a..0c84742b5e9 100644 --- a/crates/ink/ir/src/ir/utils.rs +++ b/crates/ink/ir/src/ir/utils.rs @@ -92,7 +92,7 @@ impl WhitelistedAttributes { /// a correct format `"foo, bar"` then `foo`, `bar` will be included in /// the whitelist of attributes. Else error about parsing will be returned. pub fn parse_arg_value(&mut self, arg: &MetaNameValue) -> Result<(), syn::Error> { - return if let ast::MetaValue::Lit(syn::Lit::Str(attributes)) = &arg.value { + if let ast::MetaValue::Lit(syn::Lit::Str(attributes)) = &arg.value { attributes.value().split(',').for_each(|attribute| { self.0.insert(attribute.trim().to_string(), ()); }); diff --git a/crates/ink/macro/Cargo.toml b/crates/ink/macro/Cargo.toml index 678e8f84a57..b58c5843060 100644 --- a/crates/ink/macro/Cargo.toml +++ b/crates/ink/macro/Cargo.toml @@ -46,9 +46,3 @@ std = [ "scale/std", "scale-info/std" ] -revive = [ - "ink/revive", - "ink_env/revive", - "ink_codegen/revive", - "ink_storage/revive" -] diff --git a/crates/ink/macro/src/event/mod.rs b/crates/ink/macro/src/event/mod.rs index 7a7d53266a5..7c9fafe1749 100644 --- a/crates/ink/macro/src/event/mod.rs +++ b/crates/ink/macro/src/event/mod.rs @@ -136,6 +136,7 @@ pub fn event_derive(mut s: synstructure::Structure) -> TokenStream2 { } /// `Event` derive implementation for `struct` types. +#[allow(clippy::arithmetic_side_effects)] // todo fn event_derive_struct(mut s: synstructure::Structure) -> syn::Result { assert_eq!(s.variants().len(), 1, "can only operate on structs"); diff --git a/crates/ink/macro/src/lib.rs b/crates/ink/macro/src/lib.rs index b180506e5b1..1e20413687f 100644 --- a/crates/ink/macro/src/lib.rs +++ b/crates/ink/macro/src/lib.rs @@ -549,7 +549,7 @@ pub fn contract(attr: TokenStream, item: TokenStream) -> TokenStream { /// /// /// Transfers balance from the caller to the given address. /// #[ink(message)] -/// fn transfer(&mut self, amount: Balance, to: AccountId) -> bool; +/// fn transfer(&mut self, amount: Balance, to: ink::H160) -> bool; /// /// // etc. /// } @@ -571,7 +571,7 @@ pub fn contract(attr: TokenStream, item: TokenStream) -> TokenStream { /// # /// # /// Transfers balance from the caller to the given address. /// # #[ink(message)] -/// # fn transfer(&mut self, amount: Balance, to: AccountId) -> bool; +/// # fn transfer(&mut self, amount: Balance, to: H160) -> bool; /// # } /// # /// #[ink(storage)] @@ -594,7 +594,7 @@ pub fn contract(attr: TokenStream, item: TokenStream) -> TokenStream { /// } /// /// #[ink(message)] -/// fn transfer(&mut self, amount: Balance, to: AccountId) -> bool { +/// fn transfer(&mut self, amount: Balance, to: H160) -> bool { /// unimplemented!() /// } /// } diff --git a/crates/ink/src/codegen/dispatch/execution.rs b/crates/ink/src/codegen/dispatch/execution.rs index 17b9ed5b334..1ee7ad6ff99 100644 --- a/crates/ink/src/codegen/dispatch/execution.rs +++ b/crates/ink/src/codegen/dispatch/execution.rs @@ -14,6 +14,7 @@ use crate::reflect::DispatchError; use ink_env::Environment; +use ink_primitives::U256; /// Returns `Ok` if the caller did not transfer additional value to the callee. /// @@ -21,12 +22,15 @@ use ink_env::Environment; /// /// If the caller did send some amount of transferred value to the callee. #[inline] +// todo remove E pub fn deny_payment() -> Result<(), DispatchError> where E: Environment, { - let transferred = ink_env::transferred_value::(); - if transferred != ::Balance::from(0_u32) { + // todo + let transferred = ink_env::transferred_value(); + if transferred != U256::zero() { + //ink_env::debug_message("XXXXXXX"); return Err(DispatchError::PaidUnpayableMessage) } Ok(()) diff --git a/crates/ink/src/contract_ref.rs b/crates/ink/src/contract_ref.rs index 2af96cedd2c..23cb6e060be 100644 --- a/crates/ink/src/contract_ref.rs +++ b/crates/ink/src/contract_ref.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use ink_env::Environment; +use ink_primitives::H160; /// Generates a wrapper which can be used for interacting with the contract. /// @@ -31,16 +31,17 @@ use ink_env::Environment; /// #[ink::contract] /// mod trait_caller { /// use ink::contract_ref; +/// use ink::{H160, U256}; /// /// #[ink::trait_definition] /// pub trait Erc20 { /// /// Returns the total supply of the ERC-20 smart contract. /// #[ink(message)] -/// fn total_supply(&self) -> Balance; +/// fn total_supply(&self) -> U256; /// /// /// Transfers balance from the caller to the given address. /// #[ink(message)] -/// fn transfer(&mut self, amount: Balance, to: AccountId) -> bool; +/// fn transfer(&mut self, amount: U256, to: H160) -> bool; /// } /// /// #[ink(storage)] @@ -58,20 +59,20 @@ use ink_env::Environment; /// /// /// Example of converting `AccountId` into `contract_ref!` implicitly. /// #[ink(message)] -/// pub fn change_account_id_1(&mut self, new_erc20: AccountId) { +/// pub fn change_account_id_1(&mut self, new_erc20: H160) { /// self.erc20 = new_erc20.into(); /// } /// /// /// Example of converting `AccountId` into `contract_ref!` explicitly. /// #[ink(message)] -/// pub fn change_account_id_2(&mut self, new_erc20: AccountId) { +/// pub fn change_account_id_2(&mut self, new_erc20: H160) { /// let erc20: contract_ref!(Erc20) = new_erc20.into(); /// self.erc20 = erc20; /// } /// /// /// Example of converting `AccountId` into an alias from `contract_ref!`. /// #[ink(message)] -/// pub fn change_account_id_3(&mut self, new_erc20: AccountId) { +/// pub fn change_account_id_3(&mut self, new_erc20: H160) { /// type Erc20Wrapper = contract_ref!(Erc20); /// let erc20: Erc20Wrapper = new_erc20.into(); /// self.erc20 = erc20; @@ -79,29 +80,29 @@ use ink_env::Environment; /// /// /// Example of how to do common calls via fully qualified syntax. /// #[ink(message)] -/// pub fn total_supply_1(&self) -> Balance { +/// pub fn total_supply_1(&self) -> U256 { /// Erc20::total_supply(&self.erc20) /// } /// /// /// Example of how to do common calls without fully qualified syntax. /// #[ink(message)] -/// pub fn total_supply_2(&self) -> Balance { +/// pub fn total_supply_2(&self) -> U256 { /// self.erc20.total_supply() /// } /// /// /// Example of how to use the call builder with `contract_ref!`. /// #[ink(message)] -/// pub fn total_supply_3(&self) -> Balance { +/// pub fn total_supply_3(&self) -> U256 { /// use ink::codegen::TraitCallBuilder; /// // Returns the `CallBuilder` that implements `Erc20` trait. /// let erc20_builder = self.erc20.call(); -/// erc20_builder.total_supply().transferred_value(0).invoke() +/// erc20_builder.total_supply().transferred_value(U256::from(0)).invoke() /// } /// /// /// Example of how to do common calls and convert /// /// the `contract_ref!` into `AccountId`. /// #[ink(message)] -/// pub fn transfer_to_erc20(&mut self, amount: Balance) -> bool { +/// pub fn transfer_to_erc20(&mut self, amount: U256) -> bool { /// let erc20_as_account_id = self.erc20.as_ref().clone(); /// self.erc20.transfer(amount, erc20_as_account_id) /// } @@ -120,7 +121,7 @@ use ink_env::Environment; /// ```rust /// use ink::contract_ref; /// use ink_env::DefaultEnvironment; -/// use ink_primitives::AccountId; +/// use ink_primitives::H160; /// /// #[ink::trait_definition] /// pub trait Erc20 { @@ -130,7 +131,7 @@ use ink_env::Environment; /// /// /// Transfers balance from the caller to the given address. /// #[ink(message)] -/// fn transfer(&mut self, amount: u128, to: AccountId) -> bool; +/// fn transfer(&mut self, amount: u128, to: H160) -> bool; /// } /// /// #[derive(Clone)] @@ -144,6 +145,7 @@ use ink_env::Environment; /// type Timestamp = u64; /// type BlockNumber = u64; /// type ChainExtension = (); +/// type EventRecord = (); /// } /// /// type AliasWithDefaultEnv = contract_ref!(Erc20, DefaultEnvironment); @@ -152,7 +154,7 @@ use ink_env::Environment; /// /// fn default(mut contract: contract_ref!(Erc20, DefaultEnvironment)) { /// let total_supply = contract.total_supply(); -/// let to: AccountId = contract.as_ref().clone(); +/// let to: H160 = contract.as_ref().clone(); /// contract.transfer(total_supply, to); /// } /// @@ -162,8 +164,7 @@ use ink_env::Environment; /// /// fn custom(mut contract: contract_ref!(Erc20, CustomEnv)) { /// let total_supply = contract.total_supply(); -/// let to: [u8; 32] = contract.as_ref().clone(); -/// contract.transfer(total_supply, to.into()); +/// contract.transfer(total_supply, contract.as_ref().clone()); /// } /// /// fn custom_alias(mut contract: AliasWithCustomEnv) { @@ -173,7 +174,7 @@ use ink_env::Environment; /// fn generic(mut contract: contract_ref!(Erc20, E)) /// where /// E: ink_env::Environment, -/// A: Into + Clone, +/// A: Into + Clone, /// { /// let total_supply = contract.total_supply(); /// let to = contract.as_ref().clone(); @@ -183,7 +184,7 @@ use ink_env::Environment; /// fn generic_alias(mut contract: AliasWithGenericEnv) /// where /// E: ink_env::Environment, -/// A: Into + Clone, +/// A: Into + Clone, /// { /// generic(contract) /// } @@ -192,7 +193,7 @@ use ink_env::Environment; /// /// fn contract_ref_default_behaviour(mut contract: contract_ref!(Erc20)) { /// let total_supply = contract.total_supply(); -/// let to: AccountId = contract.as_ref().clone(); +/// let to: H160 = contract.as_ref().clone(); /// contract.transfer(total_supply, to); /// } /// ``` @@ -209,13 +210,11 @@ macro_rules! contract_ref { }; } +// todo remove FromAccountId + ToAccountId /// Implemented by contracts that are compiled as dependencies. /// /// Allows them to return their underlying account identifier. -pub trait ToAccountId -where - T: Environment, -{ +pub trait ToAddr { /// Returns the underlying account identifier of the instantiated contract. - fn to_account_id(&self) -> ::AccountId; + fn to_addr(&self) -> H160; } diff --git a/crates/ink/src/env_access.rs b/crates/ink/src/env_access.rs index cd0e564dd02..6c59eef7807 100644 --- a/crates/ink/src/env_access.rs +++ b/crates/ink/src/env_access.rs @@ -21,7 +21,7 @@ use ink_env::{ ConstructorReturnType, CreateParams, DelegateCall, - FromAccountId, + FromAddr, LimitParamsV2, }, hash::{ @@ -31,6 +31,7 @@ use ink_env::{ Environment, Result, }; +use ink_primitives::{H160, H256, U256}; use pallet_revive_uapi::ReturnErrorCode; /// The API behind the `self.env()` and `Self::env()` syntax in ink!. @@ -43,7 +44,7 @@ pub struct EnvAccess<'a, E> { marker: PhantomData &'a E>, } -impl<'a, E> Default for EnvAccess<'a, E> { +impl Default for EnvAccess<'_, E> { #[inline] fn default() -> Self { Self { @@ -52,13 +53,13 @@ impl<'a, E> Default for EnvAccess<'a, E> { } } -impl<'a, E> core::fmt::Debug for EnvAccess<'a, E> { +impl core::fmt::Debug for EnvAccess<'_, E> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { f.debug_struct("EnvAccess").finish() } } -impl<'a, E> EnvAccess<'a, E> +impl EnvAccess<'_, E> where E: Environment, ::ChainExtension: ChainExtensionInstance, @@ -71,7 +72,7 @@ where } } -impl<'a, E> EnvAccess<'a, E> +impl EnvAccess<'_, E> where E: Environment, { @@ -104,8 +105,8 @@ where /// # Note /// /// For more details visit: [`ink_env::caller`] - pub fn caller(self) -> E::AccountId { - ink_env::caller::() + pub fn caller(self) -> H160 { + ink_env::caller() } /// Returns the transferred value for the contract execution. @@ -143,8 +144,8 @@ where /// # Note /// /// For more details visit: [`ink_env::transferred_value`] - pub fn transferred_value(self) -> E::Balance { - ink_env::transferred_value::() + pub fn transferred_value(self) -> U256 { + ink_env::transferred_value() } /// Returns the price for the specified amount of gas. @@ -163,19 +164,22 @@ where /// # Self {} /// # } /// # - /// /// Returns a tuple of - /// /// - the result of adding the `rhs` to the `lhs` - /// /// - the gas costs of this addition operation - /// /// - the price for the gas /// #[ink(message)] - /// pub fn addition_gas_cost(&self, rhs: i32, lhs: i32) -> (i32, u64, Balance) { - /// let before = self.env().gas_left(); - /// let result = rhs + lhs; - /// let after = self.env().gas_left(); - /// let gas_used = after - before; - /// let gas_cost = self.env().weight_to_fee(gas_used); - /// (result, gas_used, gas_cost) - /// } + /// pub fn foo(&self) { } + /// + /// // /// Returns a tuple of + /// // /// - the result of adding the `rhs` to the `lhs` + /// // /// - the gas costs of this addition operation + /// // /// - the price for the gas + /// // #[ink(message)] + /// // pub fn addition_gas_cost(&self, rhs: i32, lhs: i32) -> (i32, u64, Balance) { + /// // let before = self.env().gas_left(); + /// // let result = rhs + lhs; + /// // let after = self.env().gas_left(); + /// // let gas_used = after - before; + /// // let gas_cost = self.env().weight_to_fee(gas_used); + /// // (result, gas_used, gas_cost) + /// //} /// # /// # } /// # } @@ -184,6 +188,7 @@ where /// # Note /// /// For more details visit: [`ink_env::weight_to_fee`] + /// todo: there is now also `gas_price` pub fn weight_to_fee(self, gas: u64) -> E::Balance { ink_env::weight_to_fee::(gas) } @@ -232,12 +237,13 @@ where /// /// # Example /// + /// todo this code example doesn't use `account_id()`. /// ``` /// #[ink::contract] /// pub mod only_owner { /// #[ink(storage)] /// pub struct OnlyOwner { - /// owner: AccountId, + /// owner: ink::H160, /// value: u32, /// } /// @@ -272,6 +278,13 @@ where ink_env::account_id::() } + /// Returns the address of the executed contract. + /// + /// For more details visit: [`ink_env::address`] + pub fn address(self) -> H160 { + ink_env::address() + } + /// Returns the balance of the executed contract. /// /// # Example @@ -423,7 +436,7 @@ where /// #[ink(message)] /// pub fn instantiate_contract(&self) -> MyContractRef { /// let create_params = build_create::() - /// .code_hash(Hash::from([0x42; 32])) + /// .code_hash(ink::H256::from([0x42; 32])) /// .ref_time_limit(500_000_000) /// .proof_size_limit(100_000) /// .storage_deposit_limit(500_000_000_000) @@ -467,7 +480,7 @@ where >, > where - ContractRef: FromAccountId, + ContractRef: FromAddr, Args: scale::Encode, Salt: AsRef<[u8]>, R: ConstructorReturnType, @@ -485,7 +498,6 @@ where /// use ink::env::{ /// call::{ /// build_call, - /// CallV1, /// ExecutionInput, /// Selector, /// }, @@ -506,7 +518,7 @@ where /// #[ink(message)] /// pub fn invoke_contract_v2(&self) -> i32 { /// let call_params = build_call::() - /// .call(AccountId::from([0x42; 32])) + /// .call(ink::H160::from([0x42; 20])) /// .ref_time_limit(500_000_000) /// .proof_size_limit(100_000) /// .storage_deposit_limit(1_000_000_000) @@ -579,7 +591,7 @@ where /// pub fn invoke_contract_delegate(&self) -> i32 { /// let call_params = build_call::() /// .call_type(DelegateCall::new( - /// ::Hash::CLEAR_HASH, + /// ink::H256::zero(), /// )) /// .exec_input( /// ExecutionInput::new(Selector::new([0xCA, 0xFE, 0xBA, 0xBE])) @@ -606,7 +618,7 @@ where /// For more details visit: [`ink_env::invoke_contract_delegate`] pub fn invoke_contract_delegate( self, - params: &CallParams, Args, R>, + params: &CallParams, ) -> Result> where Args: scale::Encode, @@ -634,6 +646,7 @@ where /// /// Terminates with the caller as beneficiary. /// #[ink(message)] /// pub fn terminate_me(&mut self) { + /// // todo check this example. if caller returns origin it's no longer possible. /// self.env().terminate_contract(self.env().caller()); /// } /// # @@ -644,43 +657,43 @@ where /// # Note /// /// For more details visit: [`ink_env::terminate_contract`] - pub fn terminate_contract(self, beneficiary: E::AccountId) -> ! { - ink_env::terminate_contract::(beneficiary) + pub fn terminate_contract(self, beneficiary: H160) -> ! { + ink_env::terminate_contract(beneficiary) } - /// Transfers value from the contract to the destination account ID. - /// - /// # Example - /// - /// ``` - /// # #[ink::contract] - /// # pub mod my_contract { - /// # #[ink(storage)] - /// # pub struct MyContract { } - /// # - /// # impl MyContract { - /// # #[ink(constructor)] - /// # pub fn new() -> Self { - /// # Self {} - /// # } - /// # - /// /// Transfers the token amount ten to the caller. - /// #[ink(message)] - /// pub fn give_me_ten(&mut self) { - /// let value: Balance = 10; - /// self.env() - /// .transfer(self.env().caller(), value) - /// .unwrap_or_else(|err| panic!("transfer failed: {:?}", err)); - /// } - /// # - /// # } - /// # } - /// ``` - /// - /// # Note - /// - /// For more details visit: [`ink_env::transfer`] - pub fn transfer(self, destination: E::AccountId, value: E::Balance) -> Result<()> { + // Transfers value from the current contract to the destination contract. + // + // # Example + // + // ``` + // # #[ink::contract] + // # pub mod my_contract { + // # #[ink(storage)] + // # pub struct MyContract { } + // # + // # impl MyContract { + // # #[ink(constructor)] + // # pub fn new() -> Self { + // # Self {} + // # } + // # + // /// Transfers the token amount ten to the caller. + // #[ink(message)] + // pub fn give_me_ten(&mut self) { + // let value: Balance = 10; + // self.env() + // .transfer(self.env().caller(), value) + // .unwrap_or_else(|err| panic!("transfer failed: {:?}", err)); + // } + // # + // # } + // # } + // ``` + // + // # Note + // + // For more details visit: [`ink_env::transfer`] + pub fn transfer(self, destination: H160, value: E::Balance) -> Result<()> { ink_env::transfer::(destination, value) } @@ -916,7 +929,8 @@ where .map_err(|_| ReturnErrorCode::Sr25519VerifyFailed.into()) } - /// Checks whether a specified account belongs to a contract. + /// Checks whether a contract lives under `addr`. + /// todo update comment /// /// # Example /// @@ -933,8 +947,8 @@ where /// # } /// # /// #[ink(message)] - /// pub fn is_contract(&mut self, account_id: AccountId) -> bool { - /// self.env().is_contract(&account_id) + /// pub fn is_contract(&mut self, addr: ink::H160) -> bool { + /// self.env().is_contract(&addr) /// } /// # } /// # } @@ -943,8 +957,8 @@ where /// # Note /// /// For more details visit: [`ink_env::is_contract`] - pub fn is_contract(self, account_id: &E::AccountId) -> bool { - ink_env::is_contract::(account_id) + pub fn is_contract(self, addr: &H160) -> bool { + ink_env::is_contract(addr) } /// Checks whether the caller of the current contract is the origin of the whole call @@ -1027,8 +1041,9 @@ where /// # } /// # /// #[ink(message)] - /// pub fn code_hash(&mut self, account_id: AccountId) -> Option { - /// self.env().code_hash(&account_id).ok() + /// // todo + /// pub fn code_hash(&mut self, addr: ink::H160) -> Option { + /// self.env().code_hash(&addr).ok() /// } /// # } /// # } @@ -1037,8 +1052,8 @@ where /// # Note /// /// For more details visit: [`ink_env::code_hash`] - pub fn code_hash(self, account_id: &E::AccountId) -> Result { - ink_env::code_hash::(account_id) + pub fn code_hash(self, addr: &H160) -> Result { + ink_env::code_hash(addr) } /// Returns the code hash of the contract at the given `account` id. @@ -1058,7 +1073,7 @@ where /// # } /// # /// #[ink(message)] - /// pub fn own_code_hash(&mut self) -> Hash { + /// pub fn own_code_hash(&mut self) -> ink::H256 { /// self.env() /// .own_code_hash() /// .unwrap_or_else(|err| panic!("contract should have a code hash: {:?}", err)) @@ -1070,7 +1085,7 @@ where /// # Note /// /// For more details visit: [`ink_env::own_code_hash`] - pub fn own_code_hash(self) -> Result { + pub fn own_code_hash(self) -> Result { ink_env::own_code_hash::() } @@ -1091,7 +1106,7 @@ where /// # } /// # /// #[ink(message)] - /// pub fn set_code_hash(&mut self, code_hash: Hash) { + /// pub fn set_code_hash(&mut self, code_hash: ink::H256) { /// self.env() /// .set_code_hash(&code_hash) /// .unwrap_or_else(|err| panic!("failed to set code hash: {:?}", err)) @@ -1103,7 +1118,7 @@ where /// # Note /// /// For more details visit: [`ink_env::set_code_hash`] - pub fn set_code_hash(self, code_hash: &E::Hash) -> Result<()> { + pub fn set_code_hash(self, code_hash: &H256) -> Result<()> { ink_env::set_code_hash::(code_hash) } @@ -1129,7 +1144,7 @@ where /// # } /// # /// #[ink(message)] - /// pub fn lock_delegate_dependency(&mut self, code_hash: Hash) { + /// pub fn lock_delegate_dependency(&mut self, code_hash: ink::H256) { /// self.env().lock_delegate_dependency(&code_hash) /// } /// # } @@ -1139,7 +1154,7 @@ where /// # Note /// /// For more details visit: [`ink_env::lock_delegate_dependency`] - pub fn lock_delegate_dependency(self, code_hash: &E::Hash) { + pub fn lock_delegate_dependency(self, code_hash: &H256) { ink_env::lock_delegate_dependency::(code_hash) } @@ -1160,7 +1175,7 @@ where /// # } /// # /// #[ink(message)] - /// pub fn unlock_delegate_dependency(&mut self, code_hash: Hash) { + /// pub fn unlock_delegate_dependency(&mut self, code_hash: ink::H256) { /// self.env().unlock_delegate_dependency(&code_hash) /// } /// # } @@ -1170,7 +1185,7 @@ where /// # Note /// /// For more details visit: [`ink_env::unlock_delegate_dependency`] - pub fn unlock_delegate_dependency(self, code_hash: &E::Hash) { + pub fn unlock_delegate_dependency(self, code_hash: &H256) { ink_env::unlock_delegate_dependency::(code_hash) } diff --git a/crates/ink/src/lib.rs b/crates/ink/src/lib.rs index d60d7972c0a..945228fb348 100644 --- a/crates/ink/src/lib.rs +++ b/crates/ink/src/lib.rs @@ -74,7 +74,7 @@ pub use self::{ Output, ValueReturned, }, - contract_ref::ToAccountId, + contract_ref::ToAddr, env_access::EnvAccess, prelude::IIP2_WILDCARD_COMPLEMENT_SELECTOR, }; @@ -96,4 +96,7 @@ pub use ink_primitives::{ ConstructorResult, LangError, MessageResult, + H160, + H256, + U256, }; diff --git a/crates/ink/src/message_builder.rs b/crates/ink/src/message_builder.rs index 53425eb4a09..a54602e94c3 100644 --- a/crates/ink/src/message_builder.rs +++ b/crates/ink/src/message_builder.rs @@ -46,6 +46,7 @@ /// use ink_primitives::{ /// AccountId, /// MessageResult, +/// H160, /// }; /// use scale::{ /// Decode, @@ -60,7 +61,7 @@ /// /// /// Transfers balance from the caller to the given address. /// #[ink(message)] -/// fn transfer(&mut self, amount: u128, to: AccountId) -> bool; +/// fn transfer(&mut self, amount: u128, to: H160) -> bool; /// } /// /// #[derive(Clone)] @@ -74,6 +75,7 @@ /// type Timestamp = u64; /// type BlockNumber = u64; /// type ChainExtension = (); +/// type EventRecord = (); /// } /// /// /// To demonstrate implementing an execution environment agnostic executor @@ -107,21 +109,21 @@ /// } /// } /// -/// fn default(to: AccountId) { +/// fn default(to: H160) { /// let executor = ExampleExecutor::::new(); /// let mut contract = message_builder!(Erc20); /// let total_supply = contract.total_supply().exec(&executor).unwrap().unwrap(); /// contract.transfer(total_supply, to).exec(&executor).unwrap(); /// } /// -/// fn custom(to: AccountId) { +/// fn custom(to: H160) { /// let executor = ExampleExecutor::::new(); /// let mut contract = message_builder!(Erc20, CustomEnv); /// let total_supply = contract.total_supply().exec(&executor).unwrap().unwrap(); /// contract.transfer(total_supply, to).exec(&executor).unwrap(); /// } /// -/// fn generic(to: AccountId) +/// fn generic(to: H160) /// where /// E: ink_env::Environment, /// { diff --git a/crates/ink/src/reflect/dispatch.rs b/crates/ink/src/reflect/dispatch.rs index a3155c7e26f..4f3d989abba 100644 --- a/crates/ink/src/reflect/dispatch.rs +++ b/crates/ink/src/reflect/dispatch.rs @@ -484,6 +484,7 @@ pub trait ExecuteDispatchable { } /// An error that can occur during dispatch of ink! dispatchables. +/// todo: add tests for other errors beside `PaidUnpayableMessage` #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum DispatchError { /// Failed to decode into a valid dispatch selector. @@ -507,7 +508,7 @@ impl Display for DispatchError { impl DispatchError { /// Returns a string representation of the error. #[inline] - fn as_str(&self) -> &'static str { + pub fn as_str(&self) -> &'static str { match self { Self::InvalidSelector => "unable to decode selector", Self::UnknownSelector => "encountered unknown selector", diff --git a/crates/ink/tests/return_type_metadata.rs b/crates/ink/tests/return_type_metadata.rs index 0bca2ffcf26..69c2236233e 100644 --- a/crates/ink/tests/return_type_metadata.rs +++ b/crates/ink/tests/return_type_metadata.rs @@ -13,6 +13,8 @@ // limitations under the License. #![cfg_attr(not(feature = "std"), no_std)] +//#![cfg_attr(not(feature = "std"), no_std, no_main)] + #[ink::contract] mod contract { #[ink::trait_definition] diff --git a/crates/ink/tests/ui/chain_extension/E-01-simple.rs b/crates/ink/tests/ui/chain_extension/E-01-simple.rs index fd732644a94..9d544f559c2 100644 --- a/crates/ink/tests/ui/chain_extension/E-01-simple.rs +++ b/crates/ink/tests/ui/chain_extension/E-01-simple.rs @@ -115,6 +115,7 @@ impl Environment for CustomEnvironment { type Hash = ::Hash; type BlockNumber = ::BlockNumber; type Timestamp = ::Timestamp; + type EventRecord = ::EventRecord; type ChainExtension = RuntimeReadWrite; } diff --git a/crates/ink/tests/ui/contract/fail/constructor-return-result-invalid.stderr b/crates/ink/tests/ui/contract/fail/constructor-return-result-invalid.stderr index 7df2f3bbc2d..5bd02c7af0f 100644 --- a/crates/ink/tests/ui/contract/fail/constructor-return-result-invalid.stderr +++ b/crates/ink/tests/ui/contract/fail/constructor-return-result-invalid.stderr @@ -24,14 +24,14 @@ error[E0277]: the trait bound `Result: ConstructorReturnTyp = help: the following other types implement trait `ConstructorReturnType`: `Result` implements `ConstructorReturnType` `Result` implements `ConstructorReturnType` -note: required by a bound in `CreateBuilder::>>::returns` +note: required by a bound in `CreateBuilder::>>::returns` --> $WORKSPACE/crates/env/src/call/create_builder.rs | | pub fn returns( | ------- required by a bound in this associated function ... | R: ConstructorReturnType, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `CreateBuilder::>>::returns` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `CreateBuilder::>>::returns` error[E0277]: the trait bound `ConstructorOutputValue>: ConstructorOutput` is not satisfied --> tests/ui/contract/fail/constructor-return-result-invalid.rs:4:16 diff --git a/crates/ink/tests/ui/contract/fail/constructor-return-result-non-codec-error.stderr b/crates/ink/tests/ui/contract/fail/constructor-return-result-non-codec-error.stderr index 3abf2659964..b6dca220c52 100644 --- a/crates/ink/tests/ui/contract/fail/constructor-return-result-non-codec-error.stderr +++ b/crates/ink/tests/ui/contract/fail/constructor-return-result-non-codec-error.stderr @@ -34,14 +34,14 @@ error[E0277]: the trait bound `contract::Error: WrapperTypeDecode` is not satisf sp_core::Bytes = note: required for `contract::Error` to implement `ink::parity_scale_codec::Decode` = note: required for `Result` to implement `ConstructorReturnType` -note: required by a bound in `CreateBuilder::>>::returns` +note: required by a bound in `CreateBuilder::>>::returns` --> $WORKSPACE/crates/env/src/call/create_builder.rs | | pub fn returns( | ------- required by a bound in this associated function ... | R: ConstructorReturnType, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `CreateBuilder::>>::returns` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `CreateBuilder::>>::returns` error[E0277]: the trait bound `contract::Error: TypeInfo` is not satisfied --> tests/ui/contract/fail/constructor-return-result-non-codec-error.rs:4:16 diff --git a/crates/ink/tests/ui/contract/pass/config-custom-env.rs b/crates/ink/tests/ui/contract/pass/config-custom-env.rs index d81a50ce30d..edae2384144 100644 --- a/crates/ink/tests/ui/contract/pass/config-custom-env.rs +++ b/crates/ink/tests/ui/contract/pass/config-custom-env.rs @@ -9,6 +9,7 @@ impl ink_env::Environment for CustomEnv { type Timestamp = u64; type BlockNumber = u64; type ChainExtension = (); + type EventRecord = (); } #[ink::contract(env = super::CustomEnv)] diff --git a/crates/ink/tests/ui/contract/pass/constructor-return-result-cross-contract.rs b/crates/ink/tests/ui/contract/pass/constructor-return-result-cross-contract.rs index fd1ed118173..ad2a367f8d2 100644 --- a/crates/ink/tests/ui/contract/pass/constructor-return-result-cross-contract.rs +++ b/crates/ink/tests/ui/contract/pass/constructor-return-result-cross-contract.rs @@ -44,7 +44,7 @@ fn main() { // fn new_self() -> Self let _: fn() -> CalleeRef = || { CalleeRef::new_self() - .code_hash(ink_primitives::Clear::CLEAR_HASH) + .code_hash(ink::primitives::H256::zero()) .endowment(25) .salt_bytes([0xDE, 0xAD, 0xBE, 0xEF]) .instantiate() @@ -53,7 +53,7 @@ fn main() { // fn new_storage_name() -> Callee let _: fn() -> CalleeRef = || { CalleeRef::new_storage_name() - .code_hash(ink_primitives::Clear::CLEAR_HASH) + .code_hash(ink::primitives::H256::zero()) .endowment(25) .salt_bytes([0xDE, 0xAD, 0xBE, 0xEF]) .instantiate() @@ -62,7 +62,7 @@ fn main() { // fn new_result_self() -> Result let _: fn() -> Result = || { CalleeRef::new_result_self() - .code_hash(ink_primitives::Clear::CLEAR_HASH) + .code_hash(ink::primitives::H256::zero()) .endowment(25) .salt_bytes([0xDE, 0xAD, 0xBE, 0xEF]) .instantiate() @@ -71,7 +71,7 @@ fn main() { // fn new_result_storage_name() -> Result let _: fn() -> Result = || { CalleeRef::new_result_self() - .code_hash(ink_primitives::Clear::CLEAR_HASH) + .code_hash(ink::primitives::H256::zero()) .endowment(25) .salt_bytes([0xDE, 0xAD, 0xBE, 0xEF]) .instantiate() diff --git a/crates/ink/tests/ui/contract/pass/env-access.rs b/crates/ink/tests/ui/contract/pass/env-access.rs index 0b8df9e09b3..81edda7f5c7 100644 --- a/crates/ink/tests/ui/contract/pass/env-access.rs +++ b/crates/ink/tests/ui/contract/pass/env-access.rs @@ -11,7 +11,6 @@ mod contract { let _ = Self::env().block_timestamp(); let _ = Self::env().block_number(); let _ = Self::env().caller(); - let _ = Self::env().gas_left(); let _ = Self::env().minimum_balance(); let _ = Self::env().transferred_value(); let _ = Self::env().weight_to_fee(0); @@ -25,7 +24,6 @@ mod contract { let _ = self.env().block_timestamp(); let _ = self.env().block_number(); let _ = self.env().caller(); - let _ = self.env().gas_left(); let _ = self.env().minimum_balance(); let _ = self.env().transferred_value(); let _ = self.env().weight_to_fee(0); diff --git a/crates/ink/tests/ui/contract/pass/event-config-more-topics.rs b/crates/ink/tests/ui/contract/pass/event-config-more-topics.rs index f12a25878ce..3944d83f2a3 100644 --- a/crates/ink/tests/ui/contract/pass/event-config-more-topics.rs +++ b/crates/ink/tests/ui/contract/pass/event-config-more-topics.rs @@ -15,6 +15,7 @@ impl ink_env::Environment for EnvironmentMoreTopics { type Timestamp = ::Timestamp; type BlockNumber = ::BlockNumber; type ChainExtension = (); + type EventRecord = ::EventRecord; } #[ink::contract(env = super::EnvironmentMoreTopics)] diff --git a/crates/ink/tests/ui/contract/pass/example-erc20-works.rs b/crates/ink/tests/ui/contract/pass/example-erc20-works.rs index ec3b35ee166..8af664034dd 100644 --- a/crates/ink/tests/ui/contract/pass/example-erc20-works.rs +++ b/crates/ink/tests/ui/contract/pass/example-erc20-works.rs @@ -1,6 +1,7 @@ #[ink::contract] mod erc20 { use ink_storage::Mapping; + use ink::H160; /// A simple ERC-20 contract. #[ink(storage)] @@ -9,19 +10,19 @@ mod erc20 { /// Total token supply. total_supply: Balance, /// Mapping from owner to number of owned token. - balances: Mapping, + balances: Mapping, /// Mapping of the token amount which an account is allowed to withdraw /// from another account. - allowances: Mapping<(AccountId, AccountId), Balance>, + allowances: Mapping<(H160, H160), Balance>, } /// Event emitted when a token transfer occurs. #[ink(event)] pub struct Transfer { #[ink(topic)] - from: Option, + from: Option, #[ink(topic)] - to: Option, + to: Option, value: Balance, } @@ -30,9 +31,9 @@ mod erc20 { #[ink(event)] pub struct Approval { #[ink(topic)] - owner: AccountId, + owner: H160, #[ink(topic)] - spender: AccountId, + spender: H160, value: Balance, } @@ -78,7 +79,7 @@ mod erc20 { /// /// Returns `0` if the account is non-existent. #[ink(message)] - pub fn balance_of(&self, owner: AccountId) -> Balance { + pub fn balance_of(&self, owner: H160) -> Balance { self.balance_of_impl(&owner) } @@ -91,7 +92,7 @@ mod erc20 { /// Prefer to call this method over `balance_of` since this /// works using references which are more efficient in Wasm. #[inline] - fn balance_of_impl(&self, owner: &AccountId) -> Balance { + fn balance_of_impl(&self, owner: &H160) -> Balance { self.balances.get(owner).unwrap_or_default() } @@ -99,7 +100,7 @@ mod erc20 { /// /// Returns `0` if no allowance has been set. #[ink(message)] - pub fn allowance(&self, owner: AccountId, spender: AccountId) -> Balance { + pub fn allowance(&self, owner: H160, spender: H160) -> Balance { self.allowance_impl(&owner, &spender) } @@ -112,7 +113,7 @@ mod erc20 { /// Prefer to call this method over `allowance` since this /// works using references which are more efficient in Wasm. #[inline] - fn allowance_impl(&self, owner: &AccountId, spender: &AccountId) -> Balance { + fn allowance_impl(&self, owner: &H160, spender: &H160) -> Balance { self.allowances.get((owner, spender)).unwrap_or_default() } @@ -125,7 +126,7 @@ mod erc20 { /// Returns `InsufficientBalance` error if there are not enough tokens on /// the caller's account balance. #[ink(message)] - pub fn transfer(&mut self, to: AccountId, value: Balance) -> Result<()> { + pub fn transfer(&mut self, to: H160, value: Balance) -> Result<()> { let from = self.env().caller(); self.transfer_from_to(&from, &to, value) } @@ -138,7 +139,7 @@ mod erc20 { /// /// An `Approval` event is emitted. #[ink(message)] - pub fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { + pub fn approve(&mut self, spender: H160, value: Balance) -> Result<()> { let owner = self.env().caller(); self.allowances.insert((&owner, &spender), &value); self.env().emit_event(Approval { @@ -166,8 +167,8 @@ mod erc20 { #[ink(message)] pub fn transfer_from( &mut self, - from: AccountId, - to: AccountId, + from: H160, + to: H160, value: Balance, ) -> Result<()> { let caller = self.env().caller(); @@ -191,8 +192,8 @@ mod erc20 { /// the caller's account balance. fn transfer_from_to( &mut self, - from: &AccountId, - to: &AccountId, + from: &H160, + to: &H160, value: Balance, ) -> Result<()> { let from_balance = self.balance_of_impl(from); diff --git a/crates/ink/tests/ui/contract/pass/example-erc721-works.rs b/crates/ink/tests/ui/contract/pass/example-erc721-works.rs index c948c2e3284..09c2f3b2725 100644 --- a/crates/ink/tests/ui/contract/pass/example-erc721-works.rs +++ b/crates/ink/tests/ui/contract/pass/example-erc721-works.rs @@ -1,6 +1,7 @@ #[ink::contract] mod erc721 { use ink_storage::Mapping; + use ink::H160; /// A token ID. pub type TokenId = u32; @@ -9,13 +10,13 @@ mod erc721 { #[derive(Default)] pub struct Erc721 { /// Mapping from token to owner. - token_owner: Mapping, + token_owner: Mapping, /// Mapping from token to approvals users. - token_approvals: Mapping, + token_approvals: Mapping, /// Mapping from owner to number of owned token. - owned_tokens_count: Mapping, + owned_tokens_count: Mapping, /// Mapping from owner to operator approvals. - operator_approvals: Mapping<(AccountId, AccountId), ()>, + operator_approvals: Mapping<(H160, H160), ()>, } #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -34,9 +35,9 @@ mod erc721 { #[ink(event)] pub struct Transfer { #[ink(topic)] - from: Option, + from: Option, #[ink(topic)] - to: Option, + to: Option, #[ink(topic)] id: TokenId, } @@ -45,9 +46,9 @@ mod erc721 { #[ink(event)] pub struct Approval { #[ink(topic)] - from: AccountId, + from: H160, #[ink(topic)] - to: AccountId, + to: H160, #[ink(topic)] id: TokenId, } @@ -57,9 +58,9 @@ mod erc721 { #[ink(event)] pub struct ApprovalForAll { #[ink(topic)] - owner: AccountId, + owner: H160, #[ink(topic)] - operator: AccountId, + operator: H160, approved: bool, } @@ -74,25 +75,25 @@ mod erc721 { /// /// This represents the amount of unique tokens the owner has. #[ink(message)] - pub fn balance_of(&self, owner: AccountId) -> u32 { + pub fn balance_of(&self, owner: H160) -> u32 { self.balance_of_or_zero(&owner) } /// Returns the owner of the token. #[ink(message)] - pub fn owner_of(&self, id: TokenId) -> Option { + pub fn owner_of(&self, id: TokenId) -> Option { self.token_owner.get(&id) } /// Returns the approved account ID for this token if any. #[ink(message)] - pub fn get_approved(&self, id: TokenId) -> Option { + pub fn get_approved(&self, id: TokenId) -> Option { self.token_approvals.get(&id) } /// Returns `true` if the operator is approved by the owner. #[ink(message)] - pub fn is_approved_for_all(&self, owner: AccountId, operator: AccountId) -> bool { + pub fn is_approved_for_all(&self, owner: H160, operator: H160) -> bool { self.approved_for_all(owner, operator) } @@ -100,7 +101,7 @@ mod erc721 { #[ink(message)] pub fn set_approval_for_all( &mut self, - to: AccountId, + to: H160, approved: bool, ) -> Result<(), Error> { self.approve_for_all(to, approved)?; @@ -109,7 +110,7 @@ mod erc721 { /// Approves the account to transfer the specified token on behalf of the caller. #[ink(message)] - pub fn approve(&mut self, to: AccountId, id: TokenId) -> Result<(), Error> { + pub fn approve(&mut self, to: H160, id: TokenId) -> Result<(), Error> { self.approve_for(&to, id)?; Ok(()) } @@ -118,7 +119,7 @@ mod erc721 { #[ink(message)] pub fn transfer( &mut self, - destination: AccountId, + destination: H160, id: TokenId, ) -> Result<(), Error> { let caller = self.env().caller(); @@ -130,8 +131,8 @@ mod erc721 { #[ink(message)] pub fn transfer_from( &mut self, - from: AccountId, - to: AccountId, + from: H160, + to: H160, id: TokenId, ) -> Result<(), Error> { self.transfer_token_from(&from, &to, id)?; @@ -144,7 +145,7 @@ mod erc721 { let caller = self.env().caller(); self.add_token_to(&caller, id)?; self.env().emit_event(Transfer { - from: Some(AccountId::from([0x0; 32])), + from: Some(H160::from([0x0; 20])), to: Some(caller), id, }); @@ -175,18 +176,18 @@ mod erc721 { self.env().emit_event(Transfer { from: Some(caller), - to: Some(AccountId::from([0x0; 32])), + to: Some(H160::from([0x0; 20])), id, }); Ok(()) } - /// Transfers token `id` `from` the sender to the `to` `AccountId`. + /// Transfers token `id` `from` the sender to the `to` `H160`. fn transfer_token_from( &mut self, - from: &AccountId, - to: &AccountId, + from: &H160, + to: &H160, id: TokenId, ) -> Result<(), Error> { let caller = self.env().caller(); @@ -210,7 +211,7 @@ mod erc721 { /// Removes token `id` from the owner. fn remove_token_from( &mut self, - from: &AccountId, + from: &H160, id: TokenId, ) -> Result<(), Error> { let Self { @@ -234,7 +235,7 @@ mod erc721 { } /// Adds the token `id` to the `to` AccountID. - fn add_token_to(&mut self, to: &AccountId, id: TokenId) -> Result<(), Error> { + fn add_token_to(&mut self, to: &H160, id: TokenId) -> Result<(), Error> { let Self { token_owner, owned_tokens_count, @@ -245,7 +246,7 @@ mod erc721 { return Err(Error::TokenExists) } - if *to == AccountId::from([0x0; 32]) { + if *to == H160::from([0x0; 20]) { return Err(Error::NotAllowed) }; @@ -260,7 +261,7 @@ mod erc721 { /// Approves or disapproves the operator to transfer all tokens of the caller. fn approve_for_all( &mut self, - to: AccountId, + to: H160, approved: bool, ) -> Result<(), Error> { let caller = self.env().caller(); @@ -282,18 +283,18 @@ mod erc721 { Ok(()) } - /// Approve the passed `AccountId` to transfer the specified token on behalf of + /// Approve the passed `H160` to transfer the specified token on behalf of /// the message's sender. - fn approve_for(&mut self, to: &AccountId, id: TokenId) -> Result<(), Error> { + fn approve_for(&mut self, to: &H160, id: TokenId) -> Result<(), Error> { let caller = self.env().caller(); let owner = self.owner_of(id); if !(owner == Some(caller) - || self.approved_for_all(owner.expect("Error with AccountId"), caller)) + || self.approved_for_all(owner.expect("Error with H160"), caller)) { return Err(Error::NotAllowed) }; - if *to == AccountId::from([0x0; 32]) { + if *to == H160::from([0x0; 20]) { return Err(Error::NotAllowed) }; @@ -318,25 +319,25 @@ mod erc721 { } // Returns the total number of tokens from an account. - fn balance_of_or_zero(&self, of: &AccountId) -> u32 { + fn balance_of_or_zero(&self, of: &H160) -> u32 { self.owned_tokens_count.get(of).unwrap_or(0) } /// Gets an operator on other Account's behalf. - fn approved_for_all(&self, owner: AccountId, operator: AccountId) -> bool { + fn approved_for_all(&self, owner: H160, operator: H160) -> bool { self.operator_approvals.get((&owner, &operator)).is_some() } - /// Returns true if the `AccountId` `from` is the owner of token `id` + /// Returns true if the `H160` `from` is the owner of token `id` /// or it has been approved on behalf of the token `id` owner. - fn approved_or_owner(&self, from: Option, id: TokenId) -> bool { + fn approved_or_owner(&self, from: Option, id: TokenId) -> bool { let owner = self.owner_of(id); - from != Some(AccountId::from([0x0; 32])) + from != Some(H160::from([0x0; 20])) && (from == owner || from == self.token_approvals.get(&id) || self.approved_for_all( - owner.expect("Error with AccountId"), - from.expect("Error with AccountId"), + owner.expect("Error with H160"), + from.expect("Error with H160"), )) } diff --git a/crates/ink/tests/ui/contract/pass/no-implicit-prelude.rs b/crates/ink/tests/ui/contract/pass/no-implicit-prelude.rs deleted file mode 100644 index 398ab402dfa..00000000000 --- a/crates/ink/tests/ui/contract/pass/no-implicit-prelude.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![no_implicit_prelude] - -#[::ink::contract] -mod contract { - #[ink(storage)] - pub struct Contract {} - - impl Contract { - #[ink(constructor)] - pub fn constructor() -> Self { - Self {} - } - - #[ink(constructor)] - pub fn constructor_result() -> ::core::result::Result { - ::core::result::Result::Ok(Self {}) - } - - #[ink(message)] - pub fn message(&self) {} - - #[ink(message)] - pub fn message_result(&self) -> ::core::result::Result<(), ()> { - ::core::result::Result::Ok(()) - } - } -} - -fn main() {} diff --git a/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr b/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr index 0d26b7f221c..a07f44d5bc2 100644 --- a/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr +++ b/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr @@ -67,10 +67,6 @@ note: required by a bound in `Execution::::new` ... | pub fn new(input: ExecutionInput) -> Self { | --- required by a bound in this associated function -help: consider removing this method call, as the receiver has type `ExecutionInput>` and `ExecutionInput>: Encode` trivially holds - | -6 | fn message(&self, input: NonCodec); - | error[E0599]: the method `try_invoke` exists for struct `CallBuilder>, Set, ArgumentList>>>, Set>>`, but its trait bounds were not satisfied --> tests/ui/trait_def/fail/message_input_non_codec.rs:5:5 diff --git a/crates/ink/tests/ui/trait_def/pass/no-implicit-prelude.rs b/crates/ink/tests/ui/trait_def/pass/no-implicit-prelude.rs deleted file mode 100644 index b8002dbbad0..00000000000 --- a/crates/ink/tests/ui/trait_def/pass/no-implicit-prelude.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![no_implicit_prelude] - -#[::ink::trait_definition] -pub trait TraitDefinition { - #[ink(message)] - fn message(&self); - #[ink(message)] - fn message_mut(&mut self); -} - -fn main() {} diff --git a/crates/metadata/src/specs.rs b/crates/metadata/src/specs.rs index 267a73a5921..56072273213 100644 --- a/crates/metadata/src/specs.rs +++ b/crates/metadata/src/specs.rs @@ -268,6 +268,7 @@ where TypeSpec: Default, { /// Finalizes construction of the contract specification. + #[allow(clippy::arithmetic_side_effects)] // todo pub fn done(self) -> ContractSpec { assert!( !self.spec.constructors.is_empty(), diff --git a/crates/metadata/src/utils.rs b/crates/metadata/src/utils.rs index 85a13d55dda..66125da6b05 100644 --- a/crates/metadata/src/utils.rs +++ b/crates/metadata/src/utils.rs @@ -34,7 +34,7 @@ where { struct Visitor; - impl<'b> serde::de::Visitor<'b> for Visitor { + impl serde::de::Visitor<'_> for Visitor { type Value = Vec; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 90c0292e887..8ac7803b2b6 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -18,20 +18,22 @@ include = ["/Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"] derive_more = { workspace = true, features = ["from", "display"] } ink_prelude = { workspace = true } scale = { workspace = true, features = ["max-encoded-len"] } -scale-decode = { workspace = true, features = ["derive"], optional = true } +scale-decode = { workspace = true, features = ["derive"] } scale-encode = { workspace = true, features = ["derive"], optional = true } +primitive-types = { version = "0.13.1", features = ["codec", "impl-codec"]} scale-info = { workspace = true, features = ["derive"], optional = true } xxhash-rust = { workspace = true, features = ["const_xxh32"] } +serde = { version = "1.0.215", features = ["derive"], default-features = false, optional = true } [features] default = [ "std" ] std = [ "ink_prelude/std", - "scale-decode", + "serde", + "scale-decode/std", "scale-encode", "scale-info/std", "scale/std", - "scale-decode?/std", "scale-encode?/std", "derive_more/std", "xxhash-rust/std" diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index f7832572f6a..0a8ab5d9f36 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -39,10 +39,13 @@ pub use self::{ types::{ AccountId, Clear, + DepositLimit, Hash, }, }; +pub use primitive_types::{H160, H256, U256}; + /// An error emitted by the smart contracting language. /// /// This is different than errors from: diff --git a/crates/primitives/src/types.rs b/crates/primitives/src/types.rs index ffb4a073af9..42243491a0b 100644 --- a/crates/primitives/src/types.rs +++ b/crates/primitives/src/types.rs @@ -163,3 +163,27 @@ impl Clear for Hash { <[u8; 32] as Clear>::is_clear(&self.0) } } + +// impl Clear for H256 { +// const CLEAR_HASH: Self = H256::CLEAR_HASH; +// +// fn is_clear(&self) -> bool { +// self.as_bytes().iter().all(|&byte| byte == 0x00) +// } +// } + +#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode)] +#[cfg_attr(feature = "std", derive(scale_info::TypeInfo, EncodeAsType, serde::Serialize, serde::Deserialize))] +pub enum DepositLimit { + /// Allows bypassing all balance transfer checks. + Unchecked, + + /// Specifies a maximum allowable balance for a deposit. + Balance(Balance), +} + +impl From for DepositLimit { + fn from(value: T) -> Self { + Self::Balance(value) + } +} diff --git a/crates/storage/Cargo.toml b/crates/storage/Cargo.toml index ad7d8b5a498..5db2a4f298b 100644 --- a/crates/storage/Cargo.toml +++ b/crates/storage/Cargo.toml @@ -20,7 +20,6 @@ ink_metadata = { workspace = true, optional = true } ink_primitives = { workspace = true } ink_storage_traits = { workspace = true } ink_prelude = { workspace = true } -pallet-contracts-uapi = { workspace = true} pallet-revive-uapi = { workspace = true} scale = { workspace = true } @@ -49,4 +48,3 @@ std = [ "derive_more/std" ] ink-fuzz-tests = [ "std" ] -revive = [ "ink_env/revive", "ink/revive"] diff --git a/crates/storage/traits/src/layout/impls.rs b/crates/storage/traits/src/layout/impls.rs index 83ee842d12c..e376b0079b8 100644 --- a/crates/storage/traits/src/layout/impls.rs +++ b/crates/storage/traits/src/layout/impls.rs @@ -36,11 +36,7 @@ use ink_prelude::{ string::String, vec::Vec, }; -use ink_primitives::{ - AccountId, - Hash, - Key, -}; +use ink_primitives::{AccountId, Hash, Key, H160, H256}; use scale_info::TypeInfo; macro_rules! impl_storage_layout_for_primitives { @@ -57,6 +53,7 @@ macro_rules! impl_storage_layout_for_primitives { #[rustfmt::skip] impl_storage_layout_for_primitives!( AccountId, Hash, String, + H160, H256, bool, char, (), u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, diff --git a/integration-tests/internal/call-builder-return-value/lib.rs b/integration-tests/internal/call-builder-return-value/lib.rs index 081c18d67ab..1f5ff9c87f1 100755 --- a/integration-tests/internal/call-builder-return-value/lib.rs +++ b/integration-tests/internal/call-builder-return-value/lib.rs @@ -6,6 +6,7 @@ #[ink::contract] mod call_builder { use ink::{ + H160, env::{ call::{ ExecutionInput, @@ -38,7 +39,7 @@ mod call_builder { /// Delegate a call to the given contract/selector and return the result. #[ink(message)] - pub fn delegate_call(&mut self, code_hash: Hash, selector: [u8; 4]) -> i32 { + pub fn delegate_call(&mut self, code_hash: ink::H256, selector: [u8; 4]) -> i32 { use ink::env::call::build_call; build_call::() @@ -53,7 +54,7 @@ mod call_builder { #[ink(message)] pub fn delegate_call_short_return_type( &mut self, - code_hash: Hash, + code_hash: ink::H256, selector: [u8; 4], ) -> Result { use ink::env::call::build_call; @@ -74,7 +75,7 @@ mod call_builder { /// Forward a call to the given contract/selector and return the result. #[ink(message)] - pub fn forward_call(&mut self, address: AccountId, selector: [u8; 4]) -> i32 { + pub fn forward_call(&mut self, address: H160, selector: [u8; 4]) -> i32 { use ink::env::call::build_call; build_call::() @@ -89,7 +90,7 @@ mod call_builder { #[ink(message)] pub fn forward_call_short_return_type( &mut self, - address: AccountId, + address: H160, selector: [u8; 4], ) -> Result { use ink::env::call::build_call; @@ -233,7 +234,7 @@ mod call_builder { .expect("instantiate failed"); let selector = ink::selector_bytes!("get"); - let call = call_builder.forward_call(incrementer.account_id, selector); + let call = call_builder.forward_call(incrementer.addr, selector); let call_result = client .call(&origin, &call) .submit() @@ -277,7 +278,7 @@ mod call_builder { let selector = ink::selector_bytes!("get"); let call = call_builder - .forward_call_short_return_type(incrementer.account_id, selector); + .forward_call_short_return_type(incrementer.addr, selector); let call_result: Result = client.call(&origin, &call).dry_run().await?.return_value(); diff --git a/integration-tests/internal/e2e-runtime-only-backend/lib.rs b/integration-tests/internal/e2e-runtime-only-backend/lib.rs index 65484ae4e14..71e385db724 100644 --- a/integration-tests/internal/e2e-runtime-only-backend/lib.rs +++ b/integration-tests/internal/e2e-runtime-only-backend/lib.rs @@ -121,7 +121,9 @@ pub mod flipper { // when let call_data = vec![ - Value::unnamed_variant("Id", [Value::from_bytes(contract.account_id)]), + // todo addr + Value::unnamed_variant("Id", [Value::from_bytes(contract.addr)]), + // todo check next line Value::u128(ENDOWMENT), ]; client diff --git a/integration-tests/internal/lang-err/call-builder-delegate/lib.rs b/integration-tests/internal/lang-err/call-builder-delegate/lib.rs index ce0c6e2def7..13d082aed0d 100755 --- a/integration-tests/internal/lang-err/call-builder-delegate/lib.rs +++ b/integration-tests/internal/lang-err/call-builder-delegate/lib.rs @@ -52,7 +52,7 @@ mod call_builder { #[ink(message)] pub fn delegate( &mut self, - code_hash: Hash, + code_hash: ink::H256, selector: [u8; 4], ) -> Option { let result = build_call::() @@ -80,7 +80,7 @@ mod call_builder { /// This message does not allow the caller to handle any `LangErrors`, for that /// use the `call` message instead. #[ink(message)] - pub fn invoke(&mut self, code_hash: Hash, selector: [u8; 4]) -> i32 { + pub fn invoke(&mut self, code_hash: ink::H256, selector: [u8; 4]) -> i32 { use ink::env::call::build_call; build_call::() diff --git a/integration-tests/internal/lang-err/call-builder/lib.rs b/integration-tests/internal/lang-err/call-builder/lib.rs index 9aee41f00e8..2612bcbb6b8 100755 --- a/integration-tests/internal/lang-err/call-builder/lib.rs +++ b/integration-tests/internal/lang-err/call-builder/lib.rs @@ -19,13 +19,17 @@ #[ink::contract] mod call_builder { use constructors_return_value::ConstructorsReturnValueRef; - use ink::env::{ - call::{ - build_call, - ExecutionInput, - Selector, + use ink::{ + env::{ + call::{ + build_call, + ExecutionInput, + Selector, + }, + DefaultEnvironment, }, - DefaultEnvironment, + H160, + H256, }; #[ink(storage)] @@ -49,7 +53,7 @@ mod call_builder { #[ink(message)] pub fn call( &mut self, - address: AccountId, + address: H160, selector: [u8; 4], ) -> Option { let result = build_call::() @@ -77,7 +81,7 @@ mod call_builder { /// This message does not allow the caller to handle any `LangErrors`, for that /// use the `call` message instead. #[ink(message)] - pub fn invoke(&mut self, address: AccountId, selector: [u8; 4]) { + pub fn invoke(&mut self, address: H160, selector: [u8; 4]) { use ink::env::call::build_call; build_call::() @@ -98,7 +102,7 @@ mod call_builder { #[ink(message)] pub fn call_instantiate( &mut self, - code_hash: Hash, + code_hash: H256, selector: [u8; 4], init_value: bool, ) -> Option { @@ -134,12 +138,12 @@ mod call_builder { #[ink(message)] pub fn call_instantiate_fallible( &mut self, - code_hash: Hash, + code_hash: H256, selector: [u8; 4], init_value: bool, ) -> Option< Result< - Result, + Result, ink::LangError, >, > { @@ -156,7 +160,7 @@ mod call_builder { .expect("Error from the Contracts pallet."); Some(lang_result.map(|contract_result| { - contract_result.map(|inner| ink::ToAccountId::to_account_id(&inner)) + contract_result.map(|inner| ink::ToAddr::to_addr(&inner)) })) } } @@ -204,7 +208,7 @@ mod call_builder { let initial_value = get_call_result.return_value(); let selector = ink::selector_bytes!("invalid_selector"); - let call = call_builder.call(flipper.account_id, selector); + let call = call_builder.call(flipper.addr, selector); let call_result = client .call(&origin, &call) .submit() @@ -252,7 +256,7 @@ mod call_builder { // Since `LangError`s can't be handled by the `CallBuilder::invoke()` method // we expect this to panic. let invalid_selector = [0x00, 0x00, 0x00, 0x00]; - let call = call_builder.invoke(flipper.account_id, invalid_selector); + let call = call_builder.invoke(flipper.addr, invalid_selector); let call_result = client.call(&origin, &call).dry_run().await; if let Err(ink_e2e::Error::CallDryRun(dry_run)) = call_result { diff --git a/integration-tests/internal/lang-err/constructors-return-value/lib.rs b/integration-tests/internal/lang-err/constructors-return-value/lib.rs index 8caf9dc298e..f1c1b3eaacf 100644 --- a/integration-tests/internal/lang-err/constructors-return-value/lib.rs +++ b/integration-tests/internal/lang-err/constructors-return-value/lib.rs @@ -8,6 +8,8 @@ pub use self::constructors_return_value::{ #[ink::contract] pub mod constructors_return_value { + use ink::H160; + #[ink(storage)] pub struct ConstructorsReturnValue { value: bool, @@ -38,9 +40,9 @@ pub mod constructors_return_value { /// encoded return value. #[ink(constructor)] pub fn revert_new(_init_value: bool) -> Self { - ink::env::return_value::>( + ink::env::return_value::>( ink::env::ReturnFlags::REVERT, - &Ok(AccountId::from([0u8; 32])), + &Ok(H160::from([0u8; 20])), ) } @@ -49,13 +51,13 @@ pub mod constructors_return_value { #[ink(constructor)] pub fn try_revert_new(init_value: bool) -> Result { let value = if init_value { - Ok(Ok(AccountId::from([0u8; 32]))) + Ok(Ok(H160::from([0u8; 20]))) } else { Err(ink::LangError::CouldNotReadInput) }; ink::env::return_value::< - ink::ConstructorResult>, + ink::ConstructorResult>, >(ink::env::ReturnFlags::REVERT, &value) } diff --git a/integration-tests/internal/lang-err/contract-ref/lib.rs b/integration-tests/internal/lang-err/contract-ref/lib.rs index 9c47e9c7e72..d059b98ac93 100755 --- a/integration-tests/internal/lang-err/contract-ref/lib.rs +++ b/integration-tests/internal/lang-err/contract-ref/lib.rs @@ -11,7 +11,7 @@ mod contract_ref { impl ContractRef { #[ink(constructor)] - pub fn new(version: u32, flipper_code_hash: Hash) -> Self { + pub fn new(version: u32, flipper_code_hash: ink::H256) -> Self { let salt = version.to_le_bytes(); let flipper = FlipperRef::new_default() .endowment(0) @@ -23,7 +23,7 @@ mod contract_ref { } #[ink(constructor)] - pub fn try_new(version: u32, flipper_code_hash: Hash, succeed: bool) -> Self { + pub fn try_new(version: u32, flipper_code_hash: ink::H256, succeed: bool) -> Self { let salt = version.to_le_bytes(); let flipper = FlipperRef::try_new(succeed) .endowment(0) diff --git a/integration-tests/internal/mother/lib.rs b/integration-tests/internal/mother/lib.rs index e70c6c69e21..837b400a060 100755 --- a/integration-tests/internal/mother/lib.rs +++ b/integration-tests/internal/mother/lib.rs @@ -18,6 +18,7 @@ #[ink::contract] mod mother { + use ink::H160; use ink::prelude::{ format, string::{ @@ -38,7 +39,7 @@ mod mother { #[derive(Default, PartialEq, Eq, Debug, Clone)] #[cfg_attr(feature = "std", derive(ink::storage::traits::StorageLayout))] #[ink::scale_derive(Encode, Decode, TypeInfo)] - pub struct Bids(Vec>>); + pub struct Bids(Vec>>); /// Auction outline. #[derive(PartialEq, Eq, Debug, Clone)] @@ -130,7 +131,7 @@ mod mother { #[derive(Default)] pub struct Mother { auction: Auction, - balances: Mapping, + balances: Mapping, log: StorageVec, } diff --git a/integration-tests/internal/storage-types/lib.rs b/integration-tests/internal/storage-types/lib.rs index fe405e533fa..c8a97bb606f 100755 --- a/integration-tests/internal/storage-types/lib.rs +++ b/integration-tests/internal/storage-types/lib.rs @@ -251,7 +251,7 @@ mod storage_types { } #[ink(message, payable)] - pub fn payable(&self) -> Result { + pub fn payable(&self) -> Result { Ok(self.env().transferred_value()) } } diff --git a/integration-tests/public/call-runtime/Cargo.toml b/integration-tests/public/call-runtime/Cargo.toml index 3573327039a..3c72c0d11ba 100644 --- a/integration-tests/public/call-runtime/Cargo.toml +++ b/integration-tests/public/call-runtime/Cargo.toml @@ -14,8 +14,8 @@ ink = { path = "../../../crates/ink", default-features = false } # (especially for global allocator). # # See also: https://substrate.stackexchange.com/questions/4733/error-when-compiling-a-contract-using-the-xcm-chain-extension. -sp-io = { version = "23.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } -sp-runtime = { version = "24.0.0", default-features = false } +sp-io = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } +sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } [dev-dependencies] ink_e2e = { path = "../../../crates/e2e" } diff --git a/integration-tests/public/call-runtime/README.md b/integration-tests/public/call-runtime/README.md index acf3c726f21..9a3c2cc2784 100644 --- a/integration-tests/public/call-runtime/README.md +++ b/integration-tests/public/call-runtime/README.md @@ -9,10 +9,10 @@ It demonstrates how to call a runtime dispatchable from an ink! contract. To integrate this example into Substrate you need to adjust pallet contracts configuration in your runtime: ```rust // In your node's runtime configuration file (runtime.rs) - impl pallet_contracts::Config for Runtime { + impl pallet_revive::Config for Runtime { … // `Everything` or anything that will allow for the `Balances::transfer` extrinsic. - type CallFilter = frame_support::traits::Everything; + type CallFilter = frame_support::traits::Everything; type UnsafeUnstableInterface = ConstBool; … } @@ -21,7 +21,7 @@ To integrate this example into Substrate you need to adjust pallet contracts con ## Comparison to `ChainExtension` Just as a chain extension, `call_runtime` API allows contracts for direct calling to the runtime. -You can trigger any extrinsic that is not forbidden by `pallet_contracts::Config::CallFilter`. +You can trigger any extrinsic that is not forbidden by `pallet_revive::Config::CallFilter`. Consider writing a chain extension if you need to perform one of the following tasks: - Return data. - Provide functionality **exclusively** to contracts. diff --git a/integration-tests/public/conditional-compilation/lib.rs b/integration-tests/public/conditional-compilation/lib.rs index 8619493b9d4..86bd55bd819 100755 --- a/integration-tests/public/conditional-compilation/lib.rs +++ b/integration-tests/public/conditional-compilation/lib.rs @@ -27,7 +27,7 @@ pub mod conditional_compilation { // attributing event field with `cfg` is not allowed new_value: bool, #[ink(topic)] - by: AccountId, + by: ink::H160, } /// Feature gated event @@ -37,7 +37,7 @@ pub mod conditional_compilation { // attributing event field with `cfg` is not allowed new_value: bool, #[ink(topic)] - by: AccountId, + by: ink::H160, when: BlockNumber, } diff --git a/integration-tests/public/contract-terminate/lib.rs b/integration-tests/public/contract-terminate/lib.rs index c2430bb8bfb..edae7a49f16 100644 --- a/integration-tests/public/contract-terminate/lib.rs +++ b/integration-tests/public/contract-terminate/lib.rs @@ -89,7 +89,7 @@ pub mod just_terminates { // then assert!(call_res.contains_event("System", "KilledAccount")); assert!(call_res.contains_event("Balances", "Withdraw")); - assert!(call_res.contains_event("Contracts", "Terminated")); + assert!(call_res.contains_event("Revive", "Terminated")); Ok(()) } diff --git a/integration-tests/public/contract-transfer/lib.rs b/integration-tests/public/contract-transfer/lib.rs index c175f7195f1..7f01fae1a2e 100644 --- a/integration-tests/public/contract-transfer/lib.rs +++ b/integration-tests/public/contract-transfer/lib.rs @@ -6,6 +6,7 @@ #[ink::contract] pub mod give_me { + use ink::primitives::U256; /// No storage is needed for this simple contract. #[ink(storage)] pub struct GiveMe {} @@ -51,17 +52,27 @@ pub mod give_me { /// allowed to receive value as part of the call. #[ink(message, payable, selector = 0xCAFEBABE)] pub fn was_it_ten(&self) { + let foo = ink::reflect::DispatchError::UnknownSelector; + ink::env::debug_println!("{:?}", foo); + ink::env::debug_println!("{}", foo.as_str()); ink::env::debug_println!( "received payment: {}", self.env().transferred_value() ); - assert!(self.env().transferred_value() == 10, "payment was not ten"); + assert!(self.env().transferred_value() == U256::from(10), "payment was not ten"); + } + + /// Addrj + #[ink(message)] + pub fn account_id(&mut self) -> AccountId { + self.env().account_id() } } #[cfg(test)] mod tests { use super::*; + use ink::H160; #[ink::test] fn transfer_works() { @@ -101,7 +112,7 @@ pub mod give_me { // given let accounts = default_accounts(); let give_me = create_contract(100); - let contract_account = give_me.env().account_id(); + let contract_account = give_me.env().address(); // when // Push the new execution context which sets initial balances and @@ -152,30 +163,31 @@ pub mod give_me { GiveMe::new() } - fn contract_id() -> AccountId { + fn contract_id() -> H160 { ink::env::test::callee::() } - fn set_sender(sender: AccountId) { - ink::env::test::set_caller::(sender); + fn set_sender(sender: H160) { + ink::env::test::set_caller(sender); } fn default_accounts( - ) -> ink::env::test::DefaultAccounts { - ink::env::test::default_accounts::() + ) -> ink::env::test::DefaultAccounts { + ink::env::test::default_accounts() } - fn set_balance(account_id: AccountId, balance: Balance) { + // todo change all to addr + fn set_balance(account_id: H160, balance: Balance) { ink::env::test::set_account_balance::( account_id, balance, ) } - fn get_balance(account_id: AccountId) -> Balance { + fn get_balance(account_id: H160) -> Balance { ink::env::test::get_account_balance::( account_id, ) - .expect("Cannot get account balance") + .expect("Cannot get contract balance") } } @@ -197,18 +209,18 @@ pub mod give_me { let mut constructor = GiveMeRef::new(); let contract = client .instantiate("contract_transfer", &ink_e2e::alice(), &mut constructor) - .value(1000) + .value(1000_000_000) .submit() .await .expect("instantiate failed"); let mut call_builder = contract.call_builder::(); // when - let transfer = call_builder.give_me(120); + let transfer = call_builder.give_me(120_000_000); let call_res = client .call(&ink_e2e::bob(), &transfer) - .value(10) + .value(10_000_000) .submit() .await; @@ -228,20 +240,29 @@ pub mod give_me { // given let mut constructor = GiveMeRef::new(); let contract = client + //.map_account(&ink_e2e::bob()) .instantiate("contract_transfer", &ink_e2e::bob(), &mut constructor) - .value(1337) + .value(1337_000_000) .submit() .await .expect("instantiate failed"); let mut call_builder = contract.call_builder::(); + let acc = call_builder.account_id(); + let call_res = client + .call(&ink_e2e::eve(), &acc) + .submit() + .await + .expect("call failed"); + let account_id: AccountId = call_res.return_value(); + let balance_before: Balance = client - .free_balance(contract.account_id.clone()) + .free_balance(account_id.clone()) .await .expect("getting balance failed"); // when - let transfer = call_builder.give_me(120); + let transfer = call_builder.give_me(120_000_000); let call_res = client .call(&ink_e2e::eve(), &transfer) @@ -250,10 +271,10 @@ pub mod give_me { .expect("call failed"); // then - assert!(call_res.debug_message().contains("requested value: 120\n")); + assert!(call_res.debug_message().contains("requested value: 120000000\n")); let balance_after: Balance = client - .free_balance(contract.account_id.clone()) + .free_balance(account_id) .await .expect("getting balance failed"); assert_eq!(balance_before - balance_after, 120); diff --git a/integration-tests/public/contract-xcm/Cargo.toml b/integration-tests/public/contract-xcm/Cargo.toml index 25d0bdbcd64..c60c690a815 100644 --- a/integration-tests/public/contract-xcm/Cargo.toml +++ b/integration-tests/public/contract-xcm/Cargo.toml @@ -7,8 +7,8 @@ publish = false [dependencies] ink = { path = "../../../crates/ink", default-features = false } -frame-support = { version = "38.0.0", default-features = false } -pallet-balances = { version = "39.0.0", default-features = false } +frame-support = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } [dev-dependencies] ink_e2e = { path = "../../../crates/e2e", features = ["sandbox"] } diff --git a/integration-tests/public/cross-contract-calls/lib.rs b/integration-tests/public/cross-contract-calls/lib.rs index 297c544d2a6..0dd7101d47d 100755 --- a/integration-tests/public/cross-contract-calls/lib.rs +++ b/integration-tests/public/cross-contract-calls/lib.rs @@ -16,7 +16,7 @@ mod cross_contract_calls { /// limits. #[ink(constructor)] pub fn new_v2_with_limits( - other_contract_code_hash: Hash, + other_contract_code_hash: ink::H256, ref_time_limit: u64, proof_size_limit: u64, storage_deposit_limit: Balance, @@ -36,7 +36,7 @@ mod cross_contract_calls { /// Initializes the contract by instantiating the code at the given code hash via /// the `instantiate_v2` host function with no weight or storage limits. #[ink(constructor)] - pub fn new_v2_no_limits(other_contract_code_hash: Hash) -> Self { + pub fn new_v2_no_limits(other_contract_code_hash: ink::H256) -> Self { let other_contract = OtherContractRef::new(true) .code_hash(other_contract_code_hash) .endowment(0) @@ -49,7 +49,7 @@ mod cross_contract_calls { /// Initializes the contract by instantiating the code at the given code hash via /// the original `instantiate` host function. #[ink(constructor)] - pub fn new_v1(other_contract_code_hash: Hash) -> Self { + pub fn new_v1(other_contract_code_hash: ink::H256) -> Self { let other_contract = OtherContractRef::new(true) .instantiate_v1() .code_hash(other_contract_code_hash) diff --git a/integration-tests/public/custom-environment/README.md b/integration-tests/public/custom-environment/README.md index 8bd35b4614e..237980c7809 100644 --- a/integration-tests/public/custom-environment/README.md +++ b/integration-tests/public/custom-environment/README.md @@ -11,8 +11,8 @@ To integrate this example into Substrate you need to adjust pallet contracts con ```rust // In your node's runtime configuration file (runtime.rs) parameter_types! { - pub Schedule: pallet_contracts::Schedule = pallet_contracts::Schedule:: { - limits: pallet_contracts::Limits { + pub Schedule: pallet_revive::Schedule = pallet_revive::Schedule:: { + limits: pallet_revive::Limits { event_topics: 6, ..Default::default() }, @@ -20,7 +20,7 @@ parameter_types! { }; } -impl pallet_contracts::Config for Runtime { +impl pallet_revive::Config for Runtime { … type Schedule = Schedule; … diff --git a/integration-tests/public/custom-environment/lib.rs b/integration-tests/public/custom-environment/lib.rs index f78f2c239b9..4bb5b6e4cd7 100644 --- a/integration-tests/public/custom-environment/lib.rs +++ b/integration-tests/public/custom-environment/lib.rs @@ -109,7 +109,7 @@ mod runtime_call { .expect("call failed"); // then - call_res.contains_event("Contracts", "ContractEmitted"); + call_res.contains_event("Revive", "ContractEmitted"); Ok(()) } diff --git a/integration-tests/public/dns/lib.rs b/integration-tests/public/dns/lib.rs index a46cdb6e9ea..0bf7477a4c1 100644 --- a/integration-tests/public/dns/lib.rs +++ b/integration-tests/public/dns/lib.rs @@ -191,12 +191,12 @@ mod dns { use super::*; fn default_accounts( - ) -> ink::env::test::DefaultAccounts { - ink::env::test::default_accounts::() + ) -> ink::env::test::DefaultAccounts { + ink::env::test::default_accounts() } fn set_next_caller(caller: AccountId) { - ink::env::test::set_caller::(caller); + ink::env::test::set_caller(caller); } #[ink::test] diff --git a/integration-tests/public/erc20/lib.rs b/integration-tests/public/erc20/lib.rs index 82a4c438b5d..ef5c9e5c9b6 100644 --- a/integration-tests/public/erc20/lib.rs +++ b/integration-tests/public/erc20/lib.rs @@ -11,19 +11,19 @@ mod erc20 { /// Total token supply. total_supply: Balance, /// Mapping from owner to number of owned token. - balances: Mapping, + balances: Mapping, /// Mapping of the token amount which an account is allowed to withdraw /// from another account. - allowances: Mapping<(AccountId, AccountId), Balance>, + allowances: Mapping<(H160, H160), Balance>, } /// Event emitted when a token transfer occurs. #[ink(event)] pub struct Transfer { #[ink(topic)] - from: Option, + from: Option, #[ink(topic)] - to: Option, + to: Option, value: Balance, } @@ -32,9 +32,9 @@ mod erc20 { #[ink(event)] pub struct Approval { #[ink(topic)] - owner: AccountId, + owner: H160, #[ink(topic)] - spender: AccountId, + spender: H160, value: Balance, } @@ -80,7 +80,7 @@ mod erc20 { /// /// Returns `0` if the account is non-existent. #[ink(message)] - pub fn balance_of(&self, owner: AccountId) -> Balance { + pub fn balance_of(&self, owner: H160) -> Balance { self.balance_of_impl(&owner) } @@ -93,7 +93,7 @@ mod erc20 { /// Prefer to call this method over `balance_of` since this /// works using references which are more efficient in Wasm. #[inline] - fn balance_of_impl(&self, owner: &AccountId) -> Balance { + fn balance_of_impl(&self, owner: &H160) -> Balance { self.balances.get(owner).unwrap_or_default() } @@ -101,7 +101,7 @@ mod erc20 { /// /// Returns `0` if no allowance has been set. #[ink(message)] - pub fn allowance(&self, owner: AccountId, spender: AccountId) -> Balance { + pub fn allowance(&self, owner: H160, spender: H160) -> Balance { self.allowance_impl(&owner, &spender) } @@ -114,7 +114,7 @@ mod erc20 { /// Prefer to call this method over `allowance` since this /// works using references which are more efficient in Wasm. #[inline] - fn allowance_impl(&self, owner: &AccountId, spender: &AccountId) -> Balance { + fn allowance_impl(&self, owner: &H160, spender: &H160) -> Balance { self.allowances.get((owner, spender)).unwrap_or_default() } @@ -127,7 +127,7 @@ mod erc20 { /// Returns `InsufficientBalance` error if there are not enough tokens on /// the caller's account balance. #[ink(message)] - pub fn transfer(&mut self, to: AccountId, value: Balance) -> Result<()> { + pub fn transfer(&mut self, to: H160, value: Balance) -> Result<()> { let from = self.env().caller(); self.transfer_from_to(&from, &to, value) } @@ -140,7 +140,7 @@ mod erc20 { /// /// An `Approval` event is emitted. #[ink(message)] - pub fn approve(&mut self, spender: AccountId, value: Balance) -> Result<()> { + pub fn approve(&mut self, spender: H160, value: Balance) -> Result<()> { let owner = self.env().caller(); self.allowances.insert((&owner, &spender), &value); self.env().emit_event(Approval { @@ -168,8 +168,8 @@ mod erc20 { #[ink(message)] pub fn transfer_from( &mut self, - from: AccountId, - to: AccountId, + from: H160, + to: H160, value: Balance, ) -> Result<()> { let caller = self.env().caller(); @@ -195,8 +195,8 @@ mod erc20 { /// the caller's account balance. fn transfer_from_to( &mut self, - from: &AccountId, - to: &AccountId, + from: &H160, + to: &H160, value: Balance, ) -> Result<()> { let from_balance = self.balance_of_impl(from); @@ -229,8 +229,8 @@ mod erc20 { fn assert_transfer_event( event: &ink::env::test::EmittedEvent, - expected_from: Option, - expected_to: Option, + expected_from: Option, + expected_to: Option, expected_value: Balance, ) { let decoded_event = @@ -243,7 +243,7 @@ mod erc20 { let mut expected_topics = Vec::new(); expected_topics.push( - ink::blake2x256!("Transfer(Option,Option,Balance)") + ink::blake2x256!("Transfer(Option,Option,Balance)") .into(), ); if let Some(from) = expected_from { @@ -286,7 +286,7 @@ mod erc20 { assert_transfer_event( &emitted_events[0], None, - Some(AccountId::from([0x01; 32])), + Some(H160::from([0x01; 32])), 100, ); } @@ -301,7 +301,7 @@ mod erc20 { assert_transfer_event( &emitted_events[0], None, - Some(AccountId::from([0x01; 32])), + Some(H160::from([0x01; 32])), 100, ); // Get the token total supply. @@ -318,7 +318,7 @@ mod erc20 { assert_transfer_event( &emitted_events[0], None, - Some(AccountId::from([0x01; 32])), + Some(H160::from([0x01; 32])), 100, ); let accounts = @@ -349,14 +349,14 @@ mod erc20 { assert_transfer_event( &emitted_events[0], None, - Some(AccountId::from([0x01; 32])), + Some(H160::from([0x01; 32])), 100, ); // Check the second transfer event relating to the actual trasfer. assert_transfer_event( &emitted_events[1], - Some(AccountId::from([0x01; 32])), - Some(AccountId::from([0x02; 32])), + Some(H160::from([0x01; 32])), + Some(H160::from([0x02; 32])), 10, ); } @@ -391,7 +391,7 @@ mod erc20 { assert_transfer_event( &emitted_events[0], None, - Some(AccountId::from([0x01; 32])), + Some(H160::from([0x01; 32])), 100, ); } @@ -434,15 +434,15 @@ mod erc20 { assert_transfer_event( &emitted_events[0], None, - Some(AccountId::from([0x01; 32])), + Some(H160::from([0x01; 32])), 100, ); // The second event `emitted_events[1]` is an Approve event that we skip // checking. assert_transfer_event( &emitted_events[2], - Some(AccountId::from([0x01; 32])), - Some(AccountId::from([0x05; 32])), + Some(H160::from([0x01; 32])), + Some(H160::from([0x05; 32])), 10, ); } @@ -537,7 +537,7 @@ mod erc20 { .dry_run() .await?; - let bob_account = ink_e2e::account_id(ink_e2e::AccountKeyring::Bob); + let bob_account = ink_e2e::account_id(ink_e2e::Sr25519Keyring::Bob); let transfer_to_bob = 500_000_000u128; let transfer = call_builder.transfer(bob_account, transfer_to_bob); let _transfer_res = client @@ -577,8 +577,8 @@ mod erc20 { // when - let bob_account = ink_e2e::account_id(ink_e2e::AccountKeyring::Bob); - let charlie_account = ink_e2e::account_id(ink_e2e::AccountKeyring::Charlie); + let bob_account = ink_e2e::account_id(ink_e2e::Sr25519Keyring::Bob); + let charlie_account = ink_e2e::account_id(ink_e2e::Sr25519Keyring::Charlie); let amount = 500_000_000u128; // tx diff --git a/integration-tests/public/flipper/Cargo.toml b/integration-tests/public/flipper/Cargo.toml index 3211be6eb7f..f2afe5abd39 100644 --- a/integration-tests/public/flipper/Cargo.toml +++ b/integration-tests/public/flipper/Cargo.toml @@ -22,4 +22,3 @@ std = [ ] ink-as-dependency = [] e2e-tests = [] -revive = ["ink/revive", "ink_e2e/revive"] diff --git a/integration-tests/public/flipper/lib.rs b/integration-tests/public/flipper/lib.rs index 3730b8e2261..0190037b047 100644 --- a/integration-tests/public/flipper/lib.rs +++ b/integration-tests/public/flipper/lib.rs @@ -144,11 +144,12 @@ pub mod flipper { mut client: Client, ) -> E2EResult<()> { // given + use ink::H160; let addr = std::env::var("CONTRACT_ADDR_HEX") .unwrap() .replace("0x", ""); - let acc_id = hex::decode(addr).unwrap(); - let acc_id = AccountId::try_from(&acc_id[..]).unwrap(); + let addr_bytes: Vec = hex::decode(addr).unwrap(); + let addr = H160::from_slice(&addr_bytes[..]); use std::str::FromStr; let suri = ink_e2e::subxt_signer::SecretUri::from_str("//Alice").unwrap(); @@ -156,7 +157,7 @@ pub mod flipper { // when // Invoke `Flipper::get()` from `caller`'s account - let call_builder = ink_e2e::create_call_builder::(acc_id); + let call_builder = ink_e2e::create_call_builder::(addr); let get = call_builder.get(); let get_res = client.call(&caller, &get).dry_run().await?; diff --git a/integration-tests/public/multi-contract-caller/lib.rs b/integration-tests/public/multi-contract-caller/lib.rs index bab0f4f858f..6c24480c280 100644 --- a/integration-tests/public/multi-contract-caller/lib.rs +++ b/integration-tests/public/multi-contract-caller/lib.rs @@ -52,9 +52,9 @@ mod multi_contract_caller { pub fn new( init_value: i32, version: u32, - accumulator_code_hash: Hash, - adder_code_hash: Hash, - subber_code_hash: Hash, + accumulator_code_hash: ink::H256, + adder_code_hash: ink::H256, + subber_code_hash: ink::H256, ) -> Self { let total_balance = Self::env().balance(); let salt = version.to_le_bytes(); diff --git a/integration-tests/public/multisig/lib.rs b/integration-tests/public/multisig/lib.rs index f7c0bf62146..a0cbb9d8341 100755 --- a/integration-tests/public/multisig/lib.rs +++ b/integration-tests/public/multisig/lib.rs @@ -118,7 +118,7 @@ mod multisig { #[ink::scale_derive(Encode, Decode, TypeInfo)] pub struct Transaction { /// The `AccountId` of the contract that is called in this transaction. - pub callee: AccountId, + pub callee: H160, /// The selector bytes that identifies the function of the callee that should be /// called. pub selector: [u8; 4], @@ -754,7 +754,7 @@ mod multisig { // Multisig::change_requirement() Self { - callee: AccountId::from(WALLET), + callee: H160::from(WALLET), selector: ink::selector_bytes!("change_requirement"), input: call_args.encode(), transferred_value: 0, @@ -789,7 +789,7 @@ mod multisig { fn build_contract() -> Multisig { // Set the contract's address as `WALLET`. - let callee: AccountId = AccountId::from(WALLET); + let callee: H160 = H160::from(WALLET); ink::env::test::set_callee::(callee); let accounts = default_accounts(); diff --git a/integration-tests/public/payment-channel/lib.rs b/integration-tests/public/payment-channel/lib.rs index 877d039370a..e9ab8d9722e 100755 --- a/integration-tests/public/payment-channel/lib.rs +++ b/integration-tests/public/payment-channel/lib.rs @@ -293,12 +293,12 @@ mod payment_channel { }; fn default_accounts( - ) -> ink::env::test::DefaultAccounts { - ink::env::test::default_accounts::() + ) -> ink::env::test::DefaultAccounts { + ink::env::test::default_accounts() } fn set_next_caller(caller: AccountId) { - ink::env::test::set_caller::(caller); + ink::env::test::set_caller(caller); } fn set_account_balance(account: AccountId, balance: Balance) { diff --git a/integration-tests/public/psp22-extension/README.md b/integration-tests/public/psp22-extension/README.md index feab477a852..40f77bb7363 100644 --- a/integration-tests/public/psp22-extension/README.md +++ b/integration-tests/public/psp22-extension/README.md @@ -27,9 +27,9 @@ To integrate this example into Substrate you need to do two things: You can just copy/paste that file as a new module, e.g. `runtime/src/chain_extension.rs`. * In your runtime, use the implementation as the associated type `ChainExtension` of the - trait `pallet_contracts::Config`: + trait `pallet_revive::Config`: ```rust - impl pallet_contracts::Config for Runtime { + impl pallet_revive::Config for Runtime { … type ChainExtension = Psp22Extension; … diff --git a/integration-tests/public/psp22-extension/runtime/psp22-extension-example.rs b/integration-tests/public/psp22-extension/runtime/psp22-extension-example.rs index aa11d819cdb..d0e5b2e9630 100644 --- a/integration-tests/public/psp22-extension/runtime/psp22-extension-example.rs +++ b/integration-tests/public/psp22-extension/runtime/psp22-extension-example.rs @@ -24,7 +24,7 @@ use pallet_assets::{ self, WeightInfo, }; -use pallet_contracts::chain_extension::{ +use pallet_revive::chain_extension::{ ChainExtension, Environment, Ext, @@ -151,7 +151,7 @@ fn metadata( env: Environment, ) -> Result<(), DispatchError> where - T: pallet_assets::Config + pallet_contracts::Config, + T: pallet_assets::Config + pallet_revive::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, E: Ext, { @@ -187,7 +187,7 @@ fn query( env: Environment, ) -> Result<(), DispatchError> where - T: pallet_assets::Config + pallet_contracts::Config, + T: pallet_assets::Config + pallet_revive::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, E: Ext, { @@ -225,7 +225,7 @@ where fn transfer(env: Environment) -> Result<(), DispatchError> where - T: pallet_assets::Config + pallet_contracts::Config, + T: pallet_assets::Config + pallet_revive::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, E: Ext, { @@ -234,7 +234,7 @@ where // debug_message weight is a good approximation of the additional overhead of going // from contract layer to substrate layer. let overhead = Weight::from_ref_time( - ::Schedule::get() + ::Schedule::get() .host_fn_weights .debug_message, ); @@ -267,7 +267,7 @@ where fn transfer_from(env: Environment) -> Result<(), DispatchError> where - T: pallet_assets::Config + pallet_contracts::Config, + T: pallet_assets::Config + pallet_revive::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, E: Ext, { @@ -276,7 +276,7 @@ where // debug_message weight is a good approximation of the additional overhead of going // from contract layer to substrate layer. let overhead = Weight::from_ref_time( - ::Schedule::get() + ::Schedule::get() .host_fn_weights .debug_message, ); @@ -308,7 +308,7 @@ where fn approve(env: Environment) -> Result<(), DispatchError> where - T: pallet_assets::Config + pallet_contracts::Config, + T: pallet_assets::Config + pallet_revive::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, E: Ext, { @@ -317,7 +317,7 @@ where // debug_message weight is a good approximation of the additional overhead of going // from contract layer to substrate layer. let overhead = Weight::from_ref_time( - ::Schedule::get() + ::Schedule::get() .host_fn_weights .debug_message, ); @@ -346,7 +346,7 @@ where fn decrease_allowance(env: Environment) -> Result<(), DispatchError> where - T: pallet_assets::Config + pallet_contracts::Config, + T: pallet_assets::Config + pallet_revive::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, E: Ext, { @@ -361,7 +361,7 @@ where // debug_message weight is a good approximation of the additional overhead of going // from contract layer to substrate layer. let overhead = Weight::from_ref_time( - ::Schedule::get() + ::Schedule::get() .host_fn_weights .debug_message, ); @@ -417,7 +417,7 @@ where impl ChainExtension for Psp22Extension where - T: pallet_assets::Config + pallet_contracts::Config, + T: pallet_assets::Config + pallet_revive::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, { fn call( diff --git a/integration-tests/public/rand-extension/README.md b/integration-tests/public/rand-extension/README.md index 19d4cc48c7a..f3e75b31d14 100644 --- a/integration-tests/public/rand-extension/README.md +++ b/integration-tests/public/rand-extension/README.md @@ -21,9 +21,9 @@ To integrate this example into Substrate you need to do two things: You can just copy/paste the content of that file into e.g. your `runtime/src/lib.rs`. * Use the implementation as the associated type `ChainExtension` of the trait - `pallet_contracts::Config`: + `pallet_revive::Config`: ```rust - impl pallet_contracts::Config for Runtime { + impl pallet_revive::Config for Runtime { … type ChainExtension = FetchRandomExtension; … diff --git a/integration-tests/public/rand-extension/runtime/chain-extension-example.rs b/integration-tests/public/rand-extension/runtime/chain-extension-example.rs index 4d4a4a9bcbe..9cbd865ad55 100644 --- a/integration-tests/public/rand-extension/runtime/chain-extension-example.rs +++ b/integration-tests/public/rand-extension/runtime/chain-extension-example.rs @@ -3,7 +3,7 @@ use frame_support::log::{ error, trace, }; -use pallet_contracts::chain_extension::{ +use pallet_revive::chain_extension::{ ChainExtension, Environment, Ext, diff --git a/integration-tests/public/runtime-call-contract/Cargo.toml b/integration-tests/public/runtime-call-contract/Cargo.toml index d1166af5c16..8af0eb7083e 100644 --- a/integration-tests/public/runtime-call-contract/Cargo.toml +++ b/integration-tests/public/runtime-call-contract/Cargo.toml @@ -10,10 +10,11 @@ license = "Apache-2.0" repository = "https://github.com/use-ink/ink" [workspace.dependencies] -frame-support = { version = "38.0.0", default-features = false } -frame-system = { version = "38.0.0", default-features = false } -pallet-contracts = { version = "38.0.0", default-features = false } -sp-runtime = { version = "39.0.2", default-features = false } +frame-support = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +frame-system = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +pallet-revive = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false } scale-info = { version = "2.11.1", default-features = false } @@ -34,7 +35,7 @@ sandbox-runtime = { path = "sandbox-runtime", default-features = false } scale-value = "0.18.0" # can't use workspace dependency because of `cargo-contract` build not # working with workspace dependencies -frame-support = { version = "38.0.0", default-features = false } +frame-support = { git = "https://github.com/paritytech/polkadot-sdk", rev = "cbeb66fbf4c7a950ed90a979373bbcca412dc63c", default-features = false } [lib] path = "lib.rs" diff --git a/integration-tests/public/runtime-call-contract/e2e_tests.rs b/integration-tests/public/runtime-call-contract/e2e_tests.rs index 13055cf947a..f690334f5f0 100644 --- a/integration-tests/public/runtime-call-contract/e2e_tests.rs +++ b/integration-tests/public/runtime-call-contract/e2e_tests.rs @@ -1,3 +1,4 @@ +use ink::primitives::DepositLimit; use super::{ Flipper, FlipperRef, @@ -29,6 +30,7 @@ async fn instantiate_and_get(mut client: Client) -> E2EResul .dry_run() .await?; let gas_required = flip_dry_run.exec_result.gas_required; + // todo do same thing as above with storage_deposit_limit // call pallet dispatchable client @@ -37,7 +39,7 @@ async fn instantiate_and_get(mut client: Client) -> E2EResul "ContractCaller", "contract_call_flip", vec![ - ink_e2e::subxt::dynamic::Value::from_bytes(contract.account_id), + ink_e2e::subxt::dynamic::Value::from_bytes(contract.addr), ink_e2e::subxt::ext::scale_value::serde::to_value( frame_support::weights::Weight::from_parts( gas_required.ref_time(), @@ -45,7 +47,14 @@ async fn instantiate_and_get(mut client: Client) -> E2EResul ), ) .unwrap(), - ink_e2e::subxt::ext::scale_value::serde::to_value(None::).unwrap(), + //ink_e2e::subxt::dynamic::Value::from_bytes(contract.addr), + // todo + //ink_e2e::subxt::ext::scale_value::serde::to_value(None::).unwrap(), + ink_e2e::subxt::ext::scale_value::serde::to_value(0u128).unwrap(), + //ink_e2e::subxt::ext::scale_value::serde::to_value(DepositLimit::::Unchecked).unwrap(), + //ink_e2e::subxt::ext::scale_value::serde::to_value(0u128).unwrap(), + + //ink_e2e::subxt::ext::scale_value::serde::to_value(DepositLimit::::Unchecked).unwrap(), ], ) .await diff --git a/integration-tests/public/runtime-call-contract/sandbox-runtime/Cargo.toml b/integration-tests/public/runtime-call-contract/sandbox-runtime/Cargo.toml index fabffd81120..771e6192431 100644 --- a/integration-tests/public/runtime-call-contract/sandbox-runtime/Cargo.toml +++ b/integration-tests/public/runtime-call-contract/sandbox-runtime/Cargo.toml @@ -10,7 +10,7 @@ repository.workspace = true [dependencies] ink_sandbox = { path = "../../../../crates/e2e/sandbox" } -pallet-contract-caller = { path = "pallet-contract-caller", default-features = false } +pallet-revive-caller = { path = "pallet-revive-caller", default-features = false } frame-support = { workspace = true } frame-system = { workspace = true } codec = { workspace = true } @@ -19,5 +19,5 @@ scale-info = { workspace = true } [features] default = ["std"] std = [ - "pallet-contract-caller/std", + "pallet-revive-caller/std", ] diff --git a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/executor.rs b/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/executor.rs deleted file mode 100644 index 214cf5fda91..00000000000 --- a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/executor.rs +++ /dev/null @@ -1,59 +0,0 @@ -use crate::{ - AccountIdOf, - BalanceOf, -}; -use frame_support::pallet_prelude::Weight; -use ink::env::{ - call::{ - ExecutionInput, - Executor, - }, - Environment, -}; - -pub struct PalletContractsExecutor { - pub origin: AccountIdOf, - pub contract: AccountIdOf, - pub value: BalanceOf, - pub gas_limit: Weight, - pub storage_deposit_limit: Option>, - pub marker: core::marker::PhantomData, -} - -impl Executor for PalletContractsExecutor -where - E: Environment, - R: pallet_contracts::Config, -{ - type Error = sp_runtime::DispatchError; - - fn exec( - &self, - input: &ExecutionInput, - ) -> Result, Self::Error> - where - Args: codec::Encode, - Output: codec::Decode, - { - let data = codec::Encode::encode(&input); - - let result = pallet_contracts::Pallet::::bare_call( - self.origin.clone(), - self.contract.clone(), - self.value, - self.gas_limit, - self.storage_deposit_limit, - data, - pallet_contracts::DebugInfo::UnsafeDebug, - pallet_contracts::CollectEvents::Skip, - pallet_contracts::Determinism::Enforced, - ); - - let output = result.result?.data; - let result = codec::Decode::decode(&mut &output[..]).map_err(|_| { - sp_runtime::DispatchError::Other("Failed to decode contract output") - })?; - - Ok(result) - } -} diff --git a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-contract-caller/Cargo.toml b/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/Cargo.toml similarity index 88% rename from integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-contract-caller/Cargo.toml rename to integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/Cargo.toml index bf1ea87a95a..76470b751d9 100644 --- a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-contract-caller/Cargo.toml +++ b/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pallet-contract-caller" +name = "pallet-revive-caller" version = "0.1.0" description = "Demonstrate calling an ink! contract from a pallet" authors = ["Use Ink "] @@ -19,7 +19,7 @@ frame-support = { workspace = true, default-features = false, features = ["try-r frame-system = { workspace = true, default-features = false } sp-runtime = { workspace = true, default-features = false } -pallet-contracts = { workspace = true, default-features = false } +pallet-revive = { workspace = true, default-features = false, features = ["try-runtime"] } flipper-traits = { path = "../../traits", default-features = false } ink = { path = "../../../../../crates/ink", features = ["no-panic-handler", "no-allocator"] } @@ -31,7 +31,7 @@ std = [ "frame-system/std", "sp-runtime/std", "scale-info/std", - "pallet-contracts/std", + "pallet-revive/std", "ink/std" ] try-runtime = [] diff --git a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/executor.rs b/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/executor.rs new file mode 100644 index 00000000000..cae439442bb --- /dev/null +++ b/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/executor.rs @@ -0,0 +1,74 @@ +use crate::{ + AccountIdOf, + BalanceOf, +}; +use frame_support::pallet_prelude::Weight; +use frame_support::traits::IsType; +use frame_system::pallet_prelude::OriginFor; +use pallet_revive::{DepositLimit, MomentOf}; +use sp_runtime::app_crypto::sp_core; +use sp_runtime::traits::{Bounded, Dispatchable}; +use ink::env::{ + call::{ + ExecutionInput, + Executor, + }, + Environment, +}; +use ink::H160; +use ink::primitives::{AccountId, U256}; +use pallet_revive::AddressMapper; + +pub struct PalletReviveExecutor { + //pub origin: AccountIdOf, + pub origin: OriginFor, + pub contract: H160, + pub value: BalanceOf, + pub gas_limit: Weight, + //pub storage_deposit_limit: Option>, + pub storage_deposit_limit: u128, + pub marker: core::marker::PhantomData, +} + +impl Executor for PalletReviveExecutor +where + E: Environment, + R: pallet_revive::Config, + + BalanceOf: Into + TryFrom + Bounded, + MomentOf: Into, + ::Hash: IsType +{ + type Error = sp_runtime::DispatchError; + + fn exec( + &self, + input: &ExecutionInput, + ) -> Result, Self::Error> + where + Args: codec::Encode, + Output: codec::Decode, + { + let data = codec::Encode::encode(&input); + + let result = pallet_revive::Pallet::::bare_call( + self.origin.clone(), + // ::AddressMapper::to_account_id(&self.contract), + self.contract.clone(), + self.value, + self.gas_limit, + // self.storage_deposit_limit, + DepositLimit::Unchecked, // todo + data, + pallet_revive::DebugInfo::UnsafeDebug, + pallet_revive::CollectEvents::Skip, + ); + + let output = result.result?.data; + let result = codec::Decode::decode(&mut &output[..]).map_err(|_| { + sp_runtime::DispatchError::Other("Failed to decode contract output") + })?; + + Ok(result) + } +} diff --git a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/lib.rs b/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/lib.rs similarity index 58% rename from integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/lib.rs rename to integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/lib.rs index cf7abdd411a..0f3ce6ede8e 100644 --- a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/lib.rs +++ b/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/lib.rs @@ -13,7 +13,7 @@ use frame_support::{ pub use pallet::*; type AccountIdOf = ::AccountId; -type BalanceOf = <::Currency as Inspect< +type BalanceOf = <::Currency as Inspect< ::AccountId, >>::Balance; @@ -26,12 +26,16 @@ pub mod pallet { traits::fungible::Inspect, }; use frame_system::pallet_prelude::*; + use pallet_revive::evm::*; + use pallet_revive::MomentOf; + use pallet_revive::AddressMapper; + use sp_runtime::traits::Bounded; #[pallet::pallet] pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + pallet_contracts::Config {} + pub trait Config: frame_system::Config + pallet_revive::Config {} #[pallet::error] pub enum Error {} @@ -40,25 +44,33 @@ pub mod pallet { impl Pallet where [u8; 32]: From<::AccountId>, - <::Currency as Inspect< + <::Currency as Inspect< ::AccountId, >>::Balance: From, + + BalanceOf: Into + TryFrom + Bounded, + MomentOf: Into, + ::Hash: IsType { /// Call the flip method on the contract at the given `contract` account. #[pallet::call_index(0)] - #[pallet::weight(::call().saturating_add(*gas_limit))] + #[pallet::weight(::call().saturating_add(*gas_limit))] pub fn contract_call_flip( origin: OriginFor, - contract: AccountIdOf, + contract: H160, gas_limit: Weight, - storage_deposit_limit: Option>, + // todo + storage_deposit_limit: u128, + //storage_deposit_limit: Option>, ) -> DispatchResult { - let who = ensure_signed(origin)?; + let who = ensure_signed(origin.clone())?; let executor = - executor::PalletContractsExecutor:: { - origin: who.clone(), - contract: contract.clone(), + executor::PalletReviveExecutor:: { + //origin: who.clone(), + origin: origin.clone(), + //contract: ::AddressMapper::to_address(&contract), + contract, value: 0.into(), gas_limit, storage_deposit_limit, diff --git a/integration-tests/public/runtime-call-contract/sandbox-runtime/src/lib.rs b/integration-tests/public/runtime-call-contract/sandbox-runtime/src/lib.rs index 78a39d89705..65feb89bc0c 100644 --- a/integration-tests/public/runtime-call-contract/sandbox-runtime/src/lib.rs +++ b/integration-tests/public/runtime-call-contract/sandbox-runtime/src/lib.rs @@ -5,7 +5,7 @@ #![cfg_attr(not(feature = "std"), no_std)] ink_sandbox::create_sandbox!(ContractCallerSandbox, ContractCallerSandboxRuntime, (), (), { - ContractCaller: pallet_contract_caller, + ContractCaller: pallet_revive_caller, }); -impl pallet_contract_caller::Config for ContractCallerSandboxRuntime {} +impl pallet_revive_caller::Config for ContractCallerSandboxRuntime {} diff --git a/integration-tests/public/static-buffer/lib.rs b/integration-tests/public/static-buffer/lib.rs index 9f813f46551..05846a68663 100644 --- a/integration-tests/public/static-buffer/lib.rs +++ b/integration-tests/public/static-buffer/lib.rs @@ -30,7 +30,7 @@ pub mod static_buffer { /// Returns the caller of the contract. /// Should panic if the buffer size is less than 32 bytes. #[ink(message)] - pub fn get_caller(&self) -> AccountId { + pub fn get_caller(&self) -> ink::H160 { self.env().caller() } diff --git a/integration-tests/public/trait-dyn-cross-contract-calls/lib.rs b/integration-tests/public/trait-dyn-cross-contract-calls/lib.rs index d49911ba522..877eb62591e 100644 --- a/integration-tests/public/trait-dyn-cross-contract-calls/lib.rs +++ b/integration-tests/public/trait-dyn-cross-contract-calls/lib.rs @@ -21,7 +21,7 @@ pub mod caller { impl Caller { /// Creates a new caller smart contract around the `incrementer` account id. #[ink(constructor)] - pub fn new(incrementer: AccountId) -> Self { + pub fn new(incrementer: ink::H160) -> Self { Self { incrementer: incrementer.into(), } diff --git a/integration-tests/public/trait-flipper/lib.rs b/integration-tests/public/trait-flipper/lib.rs index 7be1ac641ed..1f179082d5d 100644 --- a/integration-tests/public/trait-flipper/lib.rs +++ b/integration-tests/public/trait-flipper/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] #![allow(clippy::new_without_default)] -#[ink::trait_definition] +#[::ink::trait_definition] pub trait Flip { /// Flips the current value of the Flipper's boolean. #[ink(message)] @@ -12,7 +12,7 @@ pub trait Flip { fn get(&self) -> bool; } -#[ink::contract] +#[::ink::contract] pub mod flipper { use super::Flip; @@ -26,7 +26,7 @@ pub mod flipper { #[ink(constructor)] pub fn new() -> Self { Self { - value: Default::default(), + value: true, } } } @@ -47,13 +47,13 @@ pub mod flipper { mod tests { use super::*; - #[ink::test] + #[::ink::test] fn default_works() { let flipper = Flipper::new(); assert!(!flipper.get()); } - #[ink::test] + #[::ink::test] fn it_works() { let mut flipper = Flipper::new(); // Can call using universal call syntax using the trait. diff --git a/integration-tests/public/upgradeable-contracts/delegator/delegatee/lib.rs b/integration-tests/public/upgradeable-contracts/delegator/delegatee/lib.rs index af761b5bd55..f6791982eed 100644 --- a/integration-tests/public/upgradeable-contracts/delegator/delegatee/lib.rs +++ b/integration-tests/public/upgradeable-contracts/delegator/delegatee/lib.rs @@ -2,13 +2,14 @@ #[ink::contract] pub mod delegatee { + use ink::H160; use ink::storage::{ traits::ManualKey, Mapping, }; #[ink(storage)] pub struct Delegatee { - addresses: Mapping>, + addresses: Mapping>, counter: i32, // Uncommenting below line will break storage compatibility. // flag: bool, diff --git a/integration-tests/public/upgradeable-contracts/delegator/delegatee2/lib.rs b/integration-tests/public/upgradeable-contracts/delegator/delegatee2/lib.rs index 447db46e00f..38e099bc678 100644 --- a/integration-tests/public/upgradeable-contracts/delegator/delegatee2/lib.rs +++ b/integration-tests/public/upgradeable-contracts/delegator/delegatee2/lib.rs @@ -2,13 +2,14 @@ #[ink::contract] pub mod delegatee2 { + use ink::H160; use ink::storage::{ traits::ManualKey, Mapping, }; #[ink(storage)] pub struct Delegatee2 { - addresses: Mapping>, + addresses: Mapping>, counter: i32, } diff --git a/integration-tests/public/upgradeable-contracts/delegator/lib.rs b/integration-tests/public/upgradeable-contracts/delegator/lib.rs index 75b43bb04ea..d169c150a4d 100644 --- a/integration-tests/public/upgradeable-contracts/delegator/lib.rs +++ b/integration-tests/public/upgradeable-contracts/delegator/lib.rs @@ -17,13 +17,15 @@ pub mod delegator { Lazy, Mapping, }, + H160, + primitives::H256, }; #[ink(storage)] pub struct Delegator { - addresses: Mapping>, + addresses: Mapping>, counter: i32, - delegate_to: Lazy, + delegate_to: Lazy, } impl Delegator { @@ -33,7 +35,7 @@ pub mod delegator { /// Additionally, this code hash will be locked to prevent its deletion, since /// this contract depends on it. #[ink(constructor)] - pub fn new(init_value: i32, hash: Hash) -> Self { + pub fn new(init_value: i32, hash: H256) -> Self { let v = Mapping::new(); // Initialize the hash of the contract to delegate to. @@ -56,7 +58,7 @@ pub mod delegator { /// - Adds a new delegate dependency lock, ensuring that the new delegated to code /// cannot be removed. #[ink(message)] - pub fn update_delegate_to(&mut self, hash: Hash) { + pub fn update_delegate_to(&mut self, hash: H256) { if let Some(old_hash) = self.delegate_to.get() { self.env().unlock_delegate_dependency(&old_hash) } @@ -105,11 +107,11 @@ pub mod delegator { /// Returns the current value of the address. #[ink(message)] - pub fn get_value(&self, address: AccountId) -> (AccountId, Option) { + pub fn get_value(&self, address: H160) -> (H160, Option) { (self.env().caller(), self.addresses.get(address)) } - fn delegate_to(&self) -> Hash { + fn delegate_to(&self) -> H256 { self.delegate_to .get() .expect("delegate_to always has a value") @@ -214,7 +216,9 @@ pub mod delegator { // assigned to Alice. let expected_value = 10; // Alice's address - let address = AccountId::from(origin.public_key().to_account_id().0); + // todo + let foo = origin.public_key().to_account_id().0; + let address = H160::from_slice(&foo[0..20]); let call_get_value = call_builder.get_value(address); let call_get_result = client diff --git a/integration-tests/public/upgradeable-contracts/set-code-hash-migration/lib.rs b/integration-tests/public/upgradeable-contracts/set-code-hash-migration/lib.rs index ea67cf199aa..b63399913fb 100644 --- a/integration-tests/public/upgradeable-contracts/set-code-hash-migration/lib.rs +++ b/integration-tests/public/upgradeable-contracts/set-code-hash-migration/lib.rs @@ -56,7 +56,7 @@ pub mod incrementer { /// /// In a production contract you would do some authorization here! #[ink(message)] - pub fn set_code(&mut self, code_hash: Hash) { + pub fn set_code(&mut self, code_hash: ink::H256) { self.env().set_code_hash(&code_hash).unwrap_or_else(|err| { panic!("Failed to `set_code_hash` to {code_hash:?} due to {err:?}") }); diff --git a/integration-tests/public/upgradeable-contracts/set-code-hash-migration/migration/lib.rs b/integration-tests/public/upgradeable-contracts/set-code-hash-migration/migration/lib.rs index 93d13cc6f19..18d84567132 100644 --- a/integration-tests/public/upgradeable-contracts/set-code-hash-migration/migration/lib.rs +++ b/integration-tests/public/upgradeable-contracts/set-code-hash-migration/migration/lib.rs @@ -49,7 +49,7 @@ pub mod incrementer { /// would be implicitly written to storage following the function execution, /// overwriting the migrated storage. #[ink(message)] - pub fn migrate(&self, inc_by: u8, code_hash: Hash) { + pub fn migrate(&self, inc_by: u8, code_hash: ink::H256) { let incrementer_new = IncrementerNew { count: self.count as u64, inc_by, diff --git a/integration-tests/public/upgradeable-contracts/set-code-hash-migration/updated-incrementer/lib.rs b/integration-tests/public/upgradeable-contracts/set-code-hash-migration/updated-incrementer/lib.rs index 7ac05c80e3d..ea272193e34 100644 --- a/integration-tests/public/upgradeable-contracts/set-code-hash-migration/updated-incrementer/lib.rs +++ b/integration-tests/public/upgradeable-contracts/set-code-hash-migration/updated-incrementer/lib.rs @@ -65,7 +65,7 @@ pub mod incrementer { /// /// In a production contract you would do some authorization here! #[ink(message)] - pub fn set_code(&mut self, code_hash: Hash) { + pub fn set_code(&mut self, code_hash: ink::H256) { self.env().set_code_hash(&code_hash).unwrap_or_else(|err| { panic!("Failed to `set_code_hash` to {code_hash:?} due to {err:?}") }); diff --git a/integration-tests/public/upgradeable-contracts/set-code-hash/lib.rs b/integration-tests/public/upgradeable-contracts/set-code-hash/lib.rs index c7f9993bea6..868cceccae2 100644 --- a/integration-tests/public/upgradeable-contracts/set-code-hash/lib.rs +++ b/integration-tests/public/upgradeable-contracts/set-code-hash/lib.rs @@ -57,7 +57,7 @@ pub mod incrementer { /// /// In a production contract you would do some authorization here! #[ink(message)] - pub fn set_code(&mut self, code_hash: Hash) { + pub fn set_code(&mut self, code_hash: ink::H256) { self.env().set_code_hash(&code_hash).unwrap_or_else(|err| { panic!("Failed to `set_code_hash` to {code_hash:?} due to {err:?}") }); diff --git a/integration-tests/public/upgradeable-contracts/set-code-hash/updated-incrementer/lib.rs b/integration-tests/public/upgradeable-contracts/set-code-hash/updated-incrementer/lib.rs index 7741181a20e..c44d59ca794 100644 --- a/integration-tests/public/upgradeable-contracts/set-code-hash/updated-incrementer/lib.rs +++ b/integration-tests/public/upgradeable-contracts/set-code-hash/updated-incrementer/lib.rs @@ -59,7 +59,7 @@ pub mod incrementer { /// /// In a production contract you would do some authorization here! #[ink(message)] - pub fn set_code(&mut self, code_hash: Hash) { + pub fn set_code(&mut self, code_hash: ink::H256) { self.env().set_code_hash(&code_hash).unwrap_or_else(|err| { panic!("Failed to `set_code_hash` to {code_hash:?} due to {err:?}") }); diff --git a/integration-tests/public/wildcard-selector/lib.rs b/integration-tests/public/wildcard-selector/lib.rs index 1e99545ba34..adbe6c69d39 100644 --- a/integration-tests/public/wildcard-selector/lib.rs +++ b/integration-tests/public/wildcard-selector/lib.rs @@ -49,7 +49,7 @@ pub mod wildcard_selector { type Environment = ::Env; fn build_message( - account_id: AccountId, + addr: ink::H160, selector: [u8; 4], message: String, ) -> ink_e2e::CallBuilderFinal< @@ -58,7 +58,7 @@ pub mod wildcard_selector { (), > { ink::env::call::build_call::() - .call(account_id) + .call(addr) .exec_input( ink::env::call::ExecutionInput::new(ink::env::call::Selector::new( selector, diff --git a/linting/extra/Cargo.toml b/linting/extra/Cargo.toml index 0fd19323e4e..65958c946be 100644 --- a/linting/extra/Cargo.toml +++ b/linting/extra/Cargo.toml @@ -89,8 +89,3 @@ std = [ "scale-info/std", ] ink-as-dependency = [] -revive = [ - "ink/revive", - "ink_env/revive", - "ink_storage/revive" -]