Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with latest cargo-contract PR #2393

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .config/cargo_spellcheck.dic
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ RLP
SHA
UI/S
URI
Wasm
Wasm32
WebAssembly
adjunctive
bitvector
bitmask
Expand Down
2 changes: 2 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-name>.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-name>.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
Expand Down Expand Up @@ -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 `<contract-name>.json` is created.
It contains information about e.g. what methods the contract provides for others to call.

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions crates/allocator/src/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize> {
Some(self.upper_limit)
Expand Down
14 changes: 7 additions & 7 deletions crates/e2e/sandbox/src/api/revive_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {

/// 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
Expand Down
29 changes: 20 additions & 9 deletions crates/e2e/src/client_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
let wasm_path = self
let contract_binary_path = self
.contracts
.get(&contract.replace('-', "_"))
.unwrap_or_else(||
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions crates/e2e/src/contract_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ fn build_contracts(contract_manifests: &[PathBuf]) -> Vec<PathBuf> {

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
}
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/src/contract_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct ContractResult<R, Balance> {
/// The debug message is never generated during on-chain execution. It is reserved
/// for RPC calls.
pub debug_message: Vec<u8>,
/// The execution result of the Wasm code.
/// The execution result of the code.
pub result: Result<R, DispatchError>,
}

Expand Down
6 changes: 3 additions & 3 deletions crates/e2e/src/xts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ struct RpcCallRequest<C: subxt::Config, E: Environment> {
input_data: Vec<u8>,
}

/// 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<u8>),
#[allow(unused)]
/// The code hash of an on-chain Wasm blob.
/// The code hash of an on-chain contract blob.
Existing(H256),
}

Expand Down
2 changes: 1 addition & 1 deletion crates/env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I, ContractRef, R>(
instantiate_result: EnvResult<()>,
Expand Down
4 changes: 2 additions & 2 deletions crates/ink/ir/src/ir/item_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions crates/ink/tests/ui/contract/pass/example-erc20-works.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions crates/metadata/outer_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
]
},
"source": {
"description": "Information about the contract's Wasm code.",
"description": "Information about the contract's binary.",
"allOf": [
{
"$ref": "#/definitions/Source"
Expand Down Expand Up @@ -103,7 +103,7 @@
}
},
"Source": {
"description": "Information about the contract's Wasm code.",
"description": "Information about the contract's binary.",
"type": "object",
"required": [
"compiler",
Expand All @@ -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"
Expand All @@ -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",
Expand All @@ -159,4 +159,4 @@
"additionalProperties": true
}
}
}
}
4 changes: 2 additions & 2 deletions integration-tests/public/erc20/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/public/trait-erc20/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Loading
Loading