diff --git a/.config/cargo_spellcheck.dic b/.config/cargo_spellcheck.dic index c4cc6aa283..30ba9ec337 100644 --- a/.config/cargo_spellcheck.dic +++ b/.config/cargo_spellcheck.dic @@ -23,9 +23,6 @@ RLP SHA UI/S URI -Wasm -Wasm32 -WebAssembly adjunctive bitvector bitmask diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 158bc8176b..a62993adc6 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -1,5 +1,7 @@ # ink!ternals +todo: rework this doc + This document describes the architecture of ink!. The information here targets those who want to understand or modify the inner workings of this project. diff --git a/Cargo.toml b/Cargo.toml index 33d5d0a566..229827809b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = { git = "https://github.com/use-ink/cargo-contract", branch = "cmichi-remove-wasm-default-to-revive" } +contract-build = { git = "https://github.com/use-ink/cargo-contract", branch = "master" } darling = { version = "0.20.10" } derive_more = { version = "1.0.0", default-features = false } either = { version = "1.13", default-features = false } diff --git a/README.md b/README.md index dfa3ea8c7d..1c723efabd 100644 --- a/README.md +++ b/README.md @@ -115,8 +115,8 @@ In order to build the contract just execute this command in the `flipper` folder cargo contract build ``` -As a result you'll get a `target/flipper.wasm` file, a `flipper.json` file and a `.contract` file in the `target` folder of your contract. -The `.contract` file combines the Wasm and metadata into one file and needs to be used when instantiating the contract. +As a result you'll get a `target/flipper.polkavm` file, a `flipper.json` file and a `.contract` file in the `target` folder of your contract. +The `.contract` file combines the contract's binary and metadata into one file and needs to be used when instantiating the contract. ## Hello, World! ‒ The Flipper @@ -210,9 +210,9 @@ For information on how to upload this file to a chain, please have a look at the * Substrate's [Framework for Runtime Aggregation of Modularized Entities (FRAME)](https://docs.substrate.io/v3/runtime/frame) contains a module which implements an API for typical functions smart contracts need (storage,querying information about accounts, …). This module is called the `contracts` pallet, -* The `contracts` pallet requires smart contracts to be uploaded to the blockchain as a Wasm blob. -* ink! is a smart contract language which targets the API exposed by `contracts`. -Hence ink! contracts are compiled to Wasm. +* The `contracts` pallet requires smart contracts to be uploaded to the blockchain as a binary blob. +* ink! is a smart contract language which targets the API exposed by [`pallet-revive`](https://github.com/paritytech/polkadot-sdk/tree/master/substrate/frame/revive/src). +Hence ink! contracts are compiled to [PolkaVM](https://github.com/paritytech/polkavm) bytecode. * When executing `cargo contract build` an additional file `.json` is created. It contains information about e.g. what methods the contract provides for others to call. @@ -258,7 +258,7 @@ the relevant links: |:--|:--|:--| `ink` | [![][j1]][j2] | Language features exposed by ink!. See [here](https://use-ink.github.io/ink/ink/attr.contract.html) for a detailed description of attributes which you can use in an `#[ink::contract]`. | `ink_storage` | [![][f1]][f2] | Data structures available in ink!. | -`ink_env` | [![][g1]][g2] | Low-level interface for interacting with the smart contract Wasm executor. Contains [the off-chain testing API](https://use-ink.github.io/ink/ink_env/test/index.html) as well. | +`ink_env` | [![][g1]][g2] | Low-level interface for interacting with the smart contract executor. Contains [the off-chain testing API](https://use-ink.github.io/ink/ink_env/test/index.html) as well. | `ink_prelude` | [![][i1]][i2] | Common API for no_std and std to access alloc crate types. | ## Community Badges diff --git a/crates/allocator/src/bump.rs b/crates/allocator/src/bump.rs index 6b9431eec0..c3c97c5818 100644 --- a/crates/allocator/src/bump.rs +++ b/crates/allocator/src/bump.rs @@ -98,8 +98,7 @@ impl InnerAlloc { /// /// Returns `None` if a page is not available. /// - /// This implementation is only meant to be used for testing, since we cannot (easily) - /// test the `wasm32` implementation. + /// This implementation is only meant to be used for testing. #[allow(dead_code)] fn request_pages(&mut self, _pages: usize) -> Option { Some(self.upper_limit) diff --git a/crates/e2e/sandbox/src/api/revive_api.rs b/crates/e2e/sandbox/src/api/revive_api.rs index 7c3e355481..c225c7b338 100644 --- a/crates/e2e/sandbox/src/api/revive_api.rs +++ b/crates/e2e/sandbox/src/api/revive_api.rs @@ -295,18 +295,18 @@ mod tests { #[test] fn can_upload_code() { let mut sandbox = DefaultSandbox::default(); - let wasm_binary = compile_module("dummy"); + let contract_binary = compile_module("dummy"); use sha3::{ Digest, Keccak256, }; - let hash = Keccak256::digest(wasm_binary.as_slice()); + let hash = Keccak256::digest(contract_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); + let result = sandbox.upload_contract(contract_binary, origin, 100000000000000); assert!(result.is_ok()); assert_eq!(hash, result.unwrap().code_hash); @@ -315,7 +315,7 @@ mod tests { #[test] fn can_deploy_contract() { let mut sandbox = DefaultSandbox::default(); - let wasm_binary = compile_module("dummy"); + let contract_binary = compile_module("dummy"); let events_before = sandbox.events(); assert!(events_before.is_empty()); @@ -324,7 +324,7 @@ mod tests { DefaultSandbox::convert_account_to_origin(DefaultSandbox::default_actor()); sandbox.map_account(origin.clone()).expect("cannot map"); let result = sandbox.deploy_contract( - wasm_binary, + contract_binary, 0, vec![], None, @@ -357,13 +357,13 @@ mod tests { fn can_call_contract() { let mut sandbox = DefaultSandbox::default(); let _actor = DefaultSandbox::default_actor(); - let wasm_binary = compile_module("dummy"); + let contract_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, + contract_binary, 0, vec![], None, diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index 82746b9360..b62b6e54ea 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -253,7 +253,7 @@ pub trait BuilderClient: ContractsBackend { /// Uploads the contract call. /// - /// This function extracts the Wasm of the contract for the specified contract. + /// This function extracts the binary of the contract for the specified contract. /// /// Calling this function multiple times should be idempotent, the contract is /// newly instantiated each time using a unique salt. No existing contract diff --git a/crates/e2e/src/client_utils.rs b/crates/e2e/src/client_utils.rs index 4ee60916ea..93c3084571 100644 --- a/crates/e2e/src/client_utils.rs +++ b/crates/e2e/src/client_utils.rs @@ -45,20 +45,27 @@ impl ContractsRegistry { let contracts = contracts .into_iter() .map(|path| { - let wasm_path: PathBuf = path.into(); - let contract_name = wasm_path.file_stem().unwrap_or_else(|| { - panic!("Invalid contract wasm path '{}'", wasm_path.display(),) - }); - (contract_name.to_string_lossy().to_string(), wasm_path) + let contract_binary_path: PathBuf = path.into(); + let contract_name = + contract_binary_path.file_stem().unwrap_or_else(|| { + panic!( + "Invalid contract binary path `{}`", + contract_binary_path.display(), + ) + }); + ( + contract_name.to_string_lossy().to_string(), + contract_binary_path, + ) }) .collect(); Self { contracts } } - /// Load the Wasm code for the given contract. + /// Load the binary code for the given contract. pub fn load_code(&self, contract: &str) -> Vec { - let wasm_path = self + let contract_binary_path = self .contracts .get(&contract.replace('-', "_")) .unwrap_or_else(|| @@ -68,8 +75,12 @@ impl ContractsRegistry { self.contracts.keys() ) ); - let code = std::fs::read(wasm_path).unwrap_or_else(|err| { - panic!("Error loading '{}': {:?}", wasm_path.display(), err) + let code = std::fs::read(contract_binary_path).unwrap_or_else(|err| { + panic!( + "Error loading '{}': {:?}", + contract_binary_path.display(), + err + ) }); log_info(&format!("{:?} has {} KiB", contract, code.len() / 1024)); code diff --git a/crates/e2e/src/contract_build.rs b/crates/e2e/src/contract_build.rs index ae06036549..d9ec25cd3a 100644 --- a/crates/e2e/src/contract_build.rs +++ b/crates/e2e/src/contract_build.rs @@ -139,15 +139,15 @@ fn build_contracts(contract_manifests: &[PathBuf]) -> Vec { let mut blob_paths = Vec::new(); for manifest in contract_manifests { - let wasm_path = match contract_build_jobs.entry(manifest.clone()) { + let contract_binary_path = match contract_build_jobs.entry(manifest.clone()) { Entry::Occupied(entry) => entry.get().clone(), Entry::Vacant(entry) => { - let wasm_path = build_contract(manifest); - entry.insert(wasm_path.clone()); - wasm_path + let contract_binary_path = build_contract(manifest); + entry.insert(contract_binary_path.clone()); + contract_binary_path } }; - blob_paths.push(wasm_path); + blob_paths.push(contract_binary_path); } blob_paths } @@ -179,7 +179,7 @@ fn build_contract(path_to_cargo_toml: &Path) -> PathBuf { match contract_build::execute(args) { Ok(build_result) => { build_result - .dest_wasm + .dest_binary .expect("PolkaVM 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 e9b6209f8c..2a0735ab9e 100644 --- a/crates/e2e/src/contract_results.rs +++ b/crates/e2e/src/contract_results.rs @@ -94,7 +94,7 @@ pub struct ContractResult { /// 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. + /// The execution result of the code. pub result: Result, } diff --git a/crates/e2e/src/xts.rs b/crates/e2e/src/xts.rs index 067955a135..c464f52d40 100644 --- a/crates/e2e/src/xts.rs +++ b/crates/e2e/src/xts.rs @@ -186,14 +186,14 @@ struct RpcCallRequest { input_data: Vec, } -/// Reference to an existing code hash or a new Wasm module. +/// Reference to an existing code hash or a new contract binary. #[derive(serde::Serialize, scale::Encode)] #[serde(rename_all = "camelCase")] enum Code { - /// A Wasm module as raw bytes. + /// A contract binary as raw bytes. Upload(Vec), #[allow(unused)] - /// The code hash of an on-chain Wasm blob. + /// The code hash of an on-chain contract blob. Existing(H256), } diff --git a/crates/env/Cargo.toml b/crates/env/Cargo.toml index b0be46249a..aa4ddcc4bb 100644 --- a/crates/env/Cargo.toml +++ b/crates/env/Cargo.toml @@ -10,7 +10,7 @@ readme = "README.md" repository.workspace = true documentation = "https://docs.rs/ink_env/" homepage.workspace = true -description = "[ink!] Low-level interface for interacting with the smart contract Wasm executor." +description = "[ink!] Low-level interface for interacting with the smart contract executor." keywords.workspace = true categories.workspace = true include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"] diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index 1ce5601b2a..9dd159f080 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! The public raw interface towards the host Wasm engine. +//! The public raw interface towards the host engine. use crate::{ backend::{ diff --git a/crates/env/src/engine/mod.rs b/crates/env/src/engine/mod.rs index a701e37903..52a60735f9 100644 --- a/crates/env/src/engine/mod.rs +++ b/crates/env/src/engine/mod.rs @@ -68,7 +68,7 @@ cfg_if! { } } -// We only use this function when 1) compiling to Wasm 2) compiling for tests. +// We only use this function when 1) compiling for PolkaVM 2) compiling for tests. #[cfg_attr(all(feature = "std", not(test)), allow(dead_code))] pub(crate) fn decode_instantiate_result( instantiate_result: EnvResult<()>, diff --git a/crates/ink/ir/src/ir/item_mod.rs b/crates/ink/ir/src/ir/item_mod.rs index 8bf1fe36d8..18b9302722 100644 --- a/crates/ink/ir/src/ir/item_mod.rs +++ b/crates/ink/ir/src/ir/item_mod.rs @@ -245,10 +245,10 @@ impl ItemMod { /// /// This restriction was added to prevent contract developers from /// adding public constructors/messages that don't show up in the - /// ink! metadata, but are compiled into the Wasm. + /// ink! metadata, but are compiled into the contract binary. /// /// Or formulated differently: we allow only `#[cfg(…)]`'s that don't - /// allow differentiating between compiling for Wasm vs. native. + /// allow differentiating between compiling for PolkaVM vs. native. /// /// Without this restriction users that view the metadata can be /// deceived as to what functions the contract provides to the public. 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 22913acaf6..4f9cba8ffc 100644 --- a/crates/ink/tests/ui/contract/pass/example-erc20-works.rs +++ b/crates/ink/tests/ui/contract/pass/example-erc20-works.rs @@ -92,7 +92,7 @@ mod erc20 { /// # Note /// /// Prefer to call this method over `balance_of` since this - /// works using references which are more efficient in Wasm. + /// works using references which are more efficient. #[inline] fn balance_of_impl(&self, owner: &H160) -> Balance { self.balances.get(owner).unwrap_or_default() @@ -113,7 +113,7 @@ mod erc20 { /// # Note /// /// Prefer to call this method over `allowance` since this - /// works using references which are more efficient in Wasm. + /// works using references which are more efficient. #[inline] fn allowance_impl(&self, owner: &H160, spender: &H160) -> Balance { self.allowances.get((owner, spender)).unwrap_or_default() diff --git a/crates/metadata/outer_schema.json b/crates/metadata/outer_schema.json index 3d60d16a8e..a77b4279d7 100644 --- a/crates/metadata/outer_schema.json +++ b/crates/metadata/outer_schema.json @@ -17,7 +17,7 @@ ] }, "source": { - "description": "Information about the contract's Wasm code.", + "description": "Information about the contract's binary.", "allOf": [ { "$ref": "#/definitions/Source" @@ -103,7 +103,7 @@ } }, "Source": { - "description": "Information about the contract's Wasm code.", + "description": "Information about the contract's binary.", "type": "object", "required": [ "compiler", @@ -124,18 +124,18 @@ "type": "string" }, "hash": { - "description": "The hash of the contract's Wasm code.", + "description": "The hash of the contract's binary.", "type": "string" }, "language": { "description": "The language used to write the contract.", "type": "string" }, - "wasm": { - "description": "The actual Wasm code of the contract, for optionally bundling the code with the metadata.", + "contract_bytecode": { + "description": "The bytecode of the contract compiled for PolkaVM, for optionally bundling the code with the metadata.", "anyOf": [ { - "$ref": "#/definitions/SourceWasm" + "$ref": "#/definitions/SourcePolkavm" }, { "type": "null" @@ -144,8 +144,8 @@ } } }, - "SourceWasm": { - "description": "The bytes of the compiled Wasm smart contract.", + "SourcePolkavm": { + "description": "The PolkaVM bytecode of the compiled smart contract.", "type": "array", "items": { "type": "integer", @@ -159,4 +159,4 @@ "additionalProperties": true } } -} \ No newline at end of file +} diff --git a/integration-tests/public/erc20/lib.rs b/integration-tests/public/erc20/lib.rs index 2368cd294f..c3add71b9a 100644 --- a/integration-tests/public/erc20/lib.rs +++ b/integration-tests/public/erc20/lib.rs @@ -95,7 +95,7 @@ mod erc20 { /// # Note /// /// Prefer to call this method over `balance_of` since this - /// works using references which are more efficient in Wasm. + /// works using references which are more efficient. #[inline] fn balance_of_impl(&self, owner: &H160) -> U256 { self.balances.get(owner).unwrap_or_default() @@ -116,7 +116,7 @@ mod erc20 { /// # Note /// /// Prefer to call this method over `allowance` since this - /// works using references which are more efficient in Wasm. + /// works using references which are more efficient. #[inline] fn allowance_impl(&self, owner: &H160, spender: &H160) -> U256 { self.allowances.get((owner, spender)).unwrap_or_default() diff --git a/integration-tests/public/trait-erc20/lib.rs b/integration-tests/public/trait-erc20/lib.rs index 594647b4f9..c599c18470 100644 --- a/integration-tests/public/trait-erc20/lib.rs +++ b/integration-tests/public/trait-erc20/lib.rs @@ -201,7 +201,7 @@ mod erc20 { /// # Note /// /// Prefer to call this method over `balance_of` since this - /// works using references which are more efficient in Wasm. + /// works using references which are more efficient. #[inline] fn balance_of_impl(&self, owner: &H160) -> U256 { self.balances.get(owner).unwrap_or_default() @@ -214,7 +214,7 @@ mod erc20 { /// # Note /// /// Prefer to call this method over `allowance` since this - /// works using references which are more efficient in Wasm. + /// works using references which are more efficient. #[inline] fn allowance_impl(&self, owner: &H160, spender: &H160) -> U256 { self.allowances.get((owner, spender)).unwrap_or_default() diff --git a/scripts/contract_size.sh b/scripts/contract_size.sh index 2cfd85e055..2e6d6dd4b1 100755 --- a/scripts/contract_size.sh +++ b/scripts/contract_size.sh @@ -31,9 +31,9 @@ build_result=$(cargo +nightly contract build --manifest-path "$manifest_path" -- if [ $? -eq 0 ]; then # only print the contract name and size if the build was successful - dest_wasm=$(echo "$build_result" | jq -r .dest_wasm) + dest_binary=$(echo "$build_result" | jq -r .dest_binary) contract_dir=$(dirname "$manifest_path") - contract_size=$(stat -c %s "$dest_wasm") + contract_size=$(stat -c %s "$dest_binary") echo "$contract_dir" "$contract_size" exit 0