Files
pezkuwi-subxt/substrate/frame/contracts
dependabot[bot] 1517eb8dd4 Bump the known_good_semver group with 2 updates (#1620)
[//]: # (dependabot-start)
⚠️  **Dependabot is rebasing this PR** ⚠️ 

Rebasing might not happen immediately, so don't worry if this takes some
time.

Note: if you make any changes to this PR yourself, they will take
precedence over the rebase.

---

[//]: # (dependabot-end)

Bumps the known_good_semver group with 2 updates:
[clap](https://github.com/clap-rs/clap) and
[syn](https://github.com/dtolnay/syn).

Updates `clap` from 4.4.3 to 4.4.4
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/clap-rs/clap/releases">clap's
releases</a>.</em></p>
<blockquote>
<h2>v4.4.4</h2>
<h2>[4.4.4] - 2023-09-18</h2>
<h3>Internal</h3>
<ul>
<li>Update <code>terminal_size</code> to 0.3</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/clap-rs/clap/blob/master/CHANGELOG.md">clap's
changelog</a>.</em></p>
<blockquote>
<h2>[4.4.4] - 2023-09-18</h2>
<h3>Internal</h3>
<ul>
<li>Update <code>terminal_size</code> to 0.3</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/clap-rs/clap/commit/e6e539660f36487e3521ab6835ef1381a21785a4"><code>e6e5396</code></a>
chore: Release</li>
<li><a
href="https://github.com/clap-rs/clap/commit/acbb60c11389d362e3b2d23a7b2a0a0523bd2fa8"><code>acbb60c</code></a>
docs: Update changelog</li>
<li><a
href="https://github.com/clap-rs/clap/commit/f09d521450c50f56153f7246489666c71e3b4739"><code>f09d521</code></a>
Merge pull request <a
href="https://redirect.github.com/clap-rs/clap/issues/5129">#5129</a>
from cgwalters/widen-terminal-size</li>
<li><a
href="https://github.com/clap-rs/clap/commit/84f99ff979d58e3fe94716144b1800fd81723ed7"><code>84f99ff</code></a>
chore(builder): Bump terminal_size to 0.3</li>
<li><a
href="https://github.com/clap-rs/clap/commit/7f8df272d90afde89e40de086492e1c9f5749897"><code>7f8df27</code></a>
Merge pull request <a
href="https://redirect.github.com/clap-rs/clap/issues/5124">#5124</a>
from devinherron/master</li>
<li><a
href="https://github.com/clap-rs/clap/commit/4dff87386a950d8dfa8e89906e9bf54d180d13de"><code>4dff873</code></a>
fix(doc): Fix typo in 03_04_subcommands.md</li>
<li>See full diff in <a
href="https://github.com/clap-rs/clap/compare/v4.4.3...v4.4.4">compare
view</a></li>
</ul>
</details>
<br />

Updates `syn` from 2.0.36 to 2.0.37
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/dtolnay/syn/releases">syn's
releases</a>.</em></p>
<blockquote>
<h2>2.0.37</h2>
<ul>
<li>Work around incorrect future compatibility warning in rustc
1.74.0-nightly</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/dtolnay/syn/commit/96810880f3acbb63415cf4684ab42c82edc31e2a"><code>9681088</code></a>
Release 2.0.37</li>
<li><a
href="https://github.com/dtolnay/syn/commit/fbe3bc2ddcee4192f95697a953330d031030f5a1"><code>fbe3bc2</code></a>
Work around unknown_lints warning on rustc older than 1.64</li>
<li><a
href="https://github.com/dtolnay/syn/commit/75cf912e061ef5a1d97c003f4988f43d7639f5a8"><code>75cf912</code></a>
Ignore more repr_transparent_external_private_fields</li>
<li><a
href="https://github.com/dtolnay/syn/commit/299c782439823b868de4aea3682b41d03351d978"><code>299c782</code></a>
Ignore false repr_transparent_external_private_fields FCW in generated
code</li>
<li>See full diff in <a
href="https://github.com/dtolnay/syn/compare/2.0.36...2.0.37">compare
view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-20 15:56:40 +02:00
..
2023-09-04 12:02:32 +03:00
2023-09-04 12:02:32 +03:00
2023-09-11 22:45:18 +02:00
2023-09-12 12:41:34 +02:00
2023-09-04 12:02:32 +03:00
2023-09-04 12:02:32 +03:00

Contracts Module

The Contracts module provides functionality for the runtime to deploy and execute WebAssembly smart-contracts.

Overview

This module extends accounts based on the [frame_support::traits::fungible] traits to have smart-contract functionality. It can be used with other modules that implement accounts based on [frame_support::traits::fungible]. These "smart-contract accounts" have the ability to instantiate smart-contracts and make calls to other contract and non-contract accounts.

The smart-contract code is stored once, and later retrievable via its code_hash. This means that multiple smart-contracts can be instantiated from the same code, without replicating the code each time.

When a smart-contract is called, its associated code is retrieved via the code hash and gets executed. This call can alter the storage entries of the smart-contract account, instantiate new smart-contracts, or call other smart-contracts.

Finally, when an account is reaped, its associated code and storage of the smart-contract account will also be deleted.

Weight

Senders must specify a Weight limit with every call, as all instructions invoked by the smart-contract require weight. Unused weight is refunded after the call, regardless of the execution outcome.

If the weight limit is reached, then all calls and state changes (including balance transfers) are only reverted at the current call's contract level. For example, if contract A calls B and B runs out of weight mid-call, then all of B's calls are reverted. Assuming correct error handling by contract A, A's other calls and state changes still persist.

One ref_time Weight is defined as one picosecond of execution time on the runtime's reference machine.

Revert Behaviour

Contract call failures are not cascading. When failures occur in a sub-call, they do not "bubble up", and the call will only revert at the specific contract level. For example, if contract A calls contract B, and B fails, A can decide how to handle that failure, either proceeding or reverting A's changes.

Off-chain Execution

In general, a contract execution needs to be deterministic so that all nodes come to the same conclusion when executing it. To that end we disallow any instructions that could cause indeterminism. Most notable are any floating point arithmetic. That said, sometimes contracts are executed off-chain and hence are not subject to consensus. If code is only executed by a single node and implicitly trusted by other actors is such a case. Trusted execution environments come to mind. To that end we allow the execution of indeterminstic code for off-chain usages with the following constraints:

  1. No contract can ever be instantiated from an indeterministic code. The only way to execute the code is to use a delegate call from a deterministic contract.
  2. The code that wants to use this feature needs to depend on pallet-contracts and use bare_call() directly. This makes sure that by default pallet-contracts does not expose any indeterminism.

How to use

An indeterministic code can be deployed on-chain by passing Determinism::Relaxed to upload_code(). A deterministic contract can then delegate call into it if and only if it is ran by using bare_call() and passing Determinism::Relaxed to it. Never use this argument when the contract is called from an on-chain transaction.

Interface

Dispatchable functions

Those are documented in the reference documentation.

Interface exposed to contracts

Each contract is one WebAssembly module that looks like this:

(module
    ;; Invoked by pallet-contracts when a contract is instantiated.
    ;; No arguments and empty return type.
    (func (export "deploy"))

    ;; Invoked by pallet-contracts when a contract is called.
    ;; No arguments and empty return type.
    (func (export "call"))

    ;; If a contract uses memory it must be imported. Memory is optional.
    ;; The maximum allowed memory size depends on the pallet-contracts configuration.
    (import "env" "memory" (memory 1 1))

    ;; This is one of many functions that can be imported and is implemented by pallet-contracts.
    ;; This function is used to copy the result buffer and flags back to the caller.
    (import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
)

The documentation of all importable functions can be found here.

Usage

This module executes WebAssembly smart contracts. These can potentially be written in any language that compiles to Wasm. However, using a language that specifically targets this module will make things a lot easier. One such language is ink!. It enables writing WebAssembly-based smart-contracts in the Rust programming language.

Debugging

Contracts can emit messages to the client when called as RPC through the debug_message API. This is exposed in ink! via ink_env::debug_message().

Those messages are gathered into an internal buffer and sent to the RPC client. It is up the the individual client if and how those messages are presented to the user.

This buffer is also printed as a debug message. In order to see these messages on the node console the log level for the runtime::contracts target needs to be raised to at least the debug level. However, those messages are easy to overlook because of the noise generated by block production. A good starting point for observing them on the console is using this command line in the root directory of the Substrate repository:

cargo run --release -- --dev -lerror,runtime::contracts=debug

This raises the log level of runtime::contracts to debug and all other targets to error in order to prevent them from spamming the console.

--dev: Use a dev chain spec --tmp: Use temporary storage for chain data (the chain state is deleted on exit)

Host function tracing

For contract authors, it can be a helpful debugging tool to see which host functions are called, with which arguments, and what the result was.

In order to see these messages on the node console, the log level for the runtime::contracts::strace target needs to be raised to the trace level.

Example:

cargo run --release -- --dev -lerror,runtime::contracts::strace=trace,runtime::contracts=debug

Unstable Interfaces

Driven by the desire to have an iterative approach in developing new contract interfaces this pallet contains the concept of an unstable interface. Akin to the rust nightly compiler it allows us to add new interfaces but mark them as unstable so that contract languages can experiment with them and give feedback before we stabilize those.

In order to access interfaces marked as #[unstable] in runtime.rs one need to set pallet_contracts::Config::UnsafeUnstableInterface to ConstU32<true>. It should be obvious that any production runtime should never be compiled with this feature: In addition to be subject to change or removal those interfaces might not have proper weights associated with them and are therefore considered unsafe.

New interfaces are generally added as unstable and might go through several iterations before they are promoted to a stable interface.

License: Apache-2.0