From f44f0574f518cfc872b4980239beafbf5107a302 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 13 Jan 2025 11:05:33 +0100 Subject: [PATCH 1/7] Disable abort feature (cherry picked from commit 7c4e518afdf574b7b10cebc04478d644073e19de) # Conflicts: # README.md --- README.md | 8 ++++++++ devtools/check_workspace.sh | 2 +- docs/USING_COSMWASM_STD.md | 27 +++++++++++++-------------- packages/std/Cargo.toml | 4 +++- packages/std/src/exports.rs | 16 ---------------- packages/std/src/imports.rs | 3 +-- packages/std/src/lib.rs | 12 +++++++++++- packages/std/src/panic.rs | 2 +- 8 files changed, 38 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 8c4da83754..99211f8b5b 100644 --- a/README.md +++ b/README.md @@ -190,10 +190,18 @@ extern "C" fn ibc_packet_ack(env_ptr: u32, msg_ptr: u32) -> u32; extern "C" fn ibc_packet_timeout(env_ptr: u32, msg_ptr: u32) -> u32; ``` +<<<<<<< HEAD `allocate`/`deallocate` allow the host to manage data within the Wasm VM. If you're using Rust, you can implement them by simply [re-exporting them from cosmwasm::exports](https://github.com/CosmWasm/cosmwasm/blob/v0.6.3/contracts/hackatom/src/lib.rs#L5). `instantiate`, `execute` and `query` must be defined by your contract. +======= +`allocate` and `deallocate` allow the host to manage data within the Wasm VM. If +you're using Rust, you get them automatically by using the `cosmwasm-std` crate. +Your contract can define the other entrypoints using the +`cosmwasm_std::entry_point` macro to get strong typing instead of raw memory +offsets. +>>>>>>> 7c4e518a (Disable abort feature) ### Imports diff --git a/devtools/check_workspace.sh b/devtools/check_workspace.sh index 34aba0bfdd..f9c72e2f79 100755 --- a/devtools/check_workspace.sh +++ b/devtools/check_workspace.sh @@ -10,7 +10,7 @@ cargo fmt # default, min, all cargo check cargo check --no-default-features --features std - cargo check --features std,abort,iterator,staking,stargate,cosmwasm_1_2 + cargo check --features std,iterator,staking,stargate,cosmwasm_1_2 cargo wasm-debug cargo wasm-debug --features std,iterator,staking,stargate cargo clippy --all-targets --features std,iterator,staking,stargate -- -D warnings diff --git a/docs/USING_COSMWASM_STD.md b/docs/USING_COSMWASM_STD.md index 500a232a01..2365007881 100644 --- a/docs/USING_COSMWASM_STD.md +++ b/docs/USING_COSMWASM_STD.md @@ -16,7 +16,6 @@ extern "C" fn deallocate(pointer: u32) { /* ... */ } // Imports extern "C" { - #[cfg(feature = "abort")] fn abort(source_ptr: u32); fn db_read(key: u32) -> u32; @@ -34,16 +33,16 @@ in the dependency tree. Otherwise conflicting C exports are created. The library comes with the following features: -| Feature | Enabled by default | Description | -| ------------ | ------------------ | ------------------------------------------------------------------------- | -| iterator | x | Storage iterators | -| abort | x | A panic handler that aborts the contract execution with a helpful message | -| stargate | | Cosmos SDK 0.40+ features and IBC | -| staking | | Access to the staking module | -| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain | -| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain | -| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain | -| cosmwasm_1_4 | | Features that require CosmWasm 1.4+ on the chain | +| Feature | Enabled by default | Description | +| ------------ | ------------------ | ------------------------------------------------------------------------------------ | +| iterator | x | Storage iterators | +| abort | x | DEPRECATED A panic handler that aborts the contract execution with a helpful message | +| stargate | | Cosmos SDK 0.40+ features and IBC | +| staking | | Access to the staking module | +| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain | +| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain | +| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain | +| cosmwasm_1_4 | | Features that require CosmWasm 1.4+ on the chain | ## The cosmwasm-std dependency for contract developers @@ -71,9 +70,9 @@ cosmwasm-std = { version = "1.2.0", features = ["stargate", "cosmwasm_1_2"] } When you are creating a library that uses cosmwasm-std, you should be incredibly careful with which features you require. The moment you add e.g. `cosmwasm_1_2` there it becomes impossible to use the contract in chains with lower CosmWasm -versions. If you add `abort`, it becomes impossible for the contract developer -to opt out of the abort feature due to your library. Since this affects the -default features `abort` and `iterator`, you should always disable default +versions. If you add `iterator`, it becomes impossible for the contract +developer to opt out of the iterator feature due to your library. Since this +affects the default feature `iterator`, you should always disable default features. However, you should make sure to keep the `std` feature enabled, as we might move certain existing functionality to that feature in the future. diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml index 66305afdf0..0f33b68d67 100644 --- a/packages/std/Cargo.toml +++ b/packages/std/Cargo.toml @@ -12,7 +12,9 @@ readme = "README.md" features = ["abort", "cosmwasm_2_2", "staking", "stargate"] [features] -default = ["abort", "iterator", "std"] +default = ["iterator", "std"] +# abort used to enable the panic handler that hands a nice error message back to the host. +# The feature is now deprecated and the panic handler is always enabled. abort = [] std = [] # iterator allows us to iterate over all DB items in a given range diff --git a/packages/std/src/exports.rs b/packages/std/src/exports.rs index b8057298e5..6dbf72e15a 100644 --- a/packages/std/src/exports.rs +++ b/packages/std/src/exports.rs @@ -22,7 +22,6 @@ use crate::ibc::{ use crate::ibc::{IbcChannelOpenMsg, IbcChannelOpenResponse}; use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage}; use crate::memory::{Owned, Region}; -#[cfg(feature = "abort")] use crate::panic::install_panic_handler; use crate::query::CustomQuery; use crate::results::{ContractResult, QueryResponse, Reply, Response}; @@ -128,7 +127,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_instantiate( instantiate_fn, @@ -158,7 +156,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_execute( execute_fn, @@ -187,7 +184,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_migrate( migrate_fn, @@ -218,7 +214,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_migrate_with_info( migrate_with_info_fn, @@ -247,7 +242,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_sudo( sudo_fn, @@ -274,7 +268,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_reply( reply_fn, @@ -300,7 +293,6 @@ where M: DeserializeOwned, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_query( query_fn, @@ -327,7 +319,6 @@ where Q: CustomQuery, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_channel_open( contract_fn, @@ -356,7 +347,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_channel_connect( contract_fn, @@ -385,7 +375,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_channel_close( contract_fn, @@ -415,7 +404,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_packet_receive( contract_fn, @@ -445,7 +433,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_packet_ack( contract_fn, @@ -476,7 +463,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_packet_timeout( contract_fn, @@ -497,7 +483,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_source_callback( contract_fn, @@ -522,7 +507,6 @@ where C: CustomMsg, E: ToString, { - #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_destination_callback( contract_fn, diff --git a/packages/std/src/imports.rs b/packages/std/src/imports.rs index 1ac223acdf..43a87f6560 100644 --- a/packages/std/src/imports.rs +++ b/packages/std/src/imports.rs @@ -27,7 +27,7 @@ const HUMAN_ADDRESS_BUFFER_LENGTH: usize = 90; // A complete documentation those functions is available in the VM that provides them: // https://github.com/CosmWasm/cosmwasm/blob/v1.0.0-beta/packages/vm/src/instance.rs#L89-L206 extern "C" { - #[cfg(feature = "abort")] + fn abort(source_ptr: u32); fn db_read(key: u32) -> u32; @@ -744,7 +744,6 @@ impl Querier for ExternalQuerier { } } -#[cfg(feature = "abort")] pub fn handle_panic(message: &str) { let region = Region::from_slice(message.as_bytes()); let region_ptr = region.as_ptr() as u32; diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index fc628693f3..1823413a3b 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -118,8 +118,18 @@ pub use crate::timestamp::Timestamp; pub use crate::traits::{Api, HashFunction, Querier, QuerierResult, QuerierWrapper, Storage}; pub use crate::types::{BlockInfo, ContractInfo, Env, MessageInfo, MigrateInfo, TransactionInfo}; -// Exposed in wasm build only +#[cfg(feature = "abort")] +mod _warning { + #[must_use = "cosmwasm-std feature `abort` is deprecated and will be removed in the next release. You can just remove the feature as this functionality is now the default"] + struct CompileWarning; + + #[allow(dead_code)] + fn trigger_warning() { + CompileWarning; + } +} +// Exposed in wasm build only #[cfg(target_arch = "wasm32")] mod exports; #[cfg(target_arch = "wasm32")] diff --git a/packages/std/src/panic.rs b/packages/std/src/panic.rs index 7ca619e31a..862f2c0ff2 100644 --- a/packages/std/src/panic.rs +++ b/packages/std/src/panic.rs @@ -3,7 +3,7 @@ /// /// This overrides any previous panic handler. See /// for details. -#[cfg(all(feature = "abort", target_arch = "wasm32"))] +#[cfg(target_arch = "wasm32")] pub fn install_panic_handler() { use super::imports::handle_panic; std::panic::set_hook(Box::new(|info| { From a27b5ac602961002072c7d683cca3d28f091a34d Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 13 Jan 2025 11:27:53 +0100 Subject: [PATCH 2/7] Don't use abort in contracts (cherry picked from commit 7a0e036f9ba2f186c3e92ac2fd1d2666889234c1) --- contracts/cyberpunk/Cargo.toml | 1 - contracts/hackatom/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/contracts/cyberpunk/Cargo.toml b/contracts/cyberpunk/Cargo.toml index 54e469f1c2..e16fb8dbdd 100644 --- a/contracts/cyberpunk/Cargo.toml +++ b/contracts/cyberpunk/Cargo.toml @@ -23,7 +23,6 @@ overflow-checks = true [dependencies] cosmwasm-schema = { path = "../../packages/schema" } cosmwasm-std = { path = "../../packages/std", default-features = false, features = [ - "abort", "cosmwasm_1_3", "std", ] } diff --git a/contracts/hackatom/Cargo.toml b/contracts/hackatom/Cargo.toml index 94738c61c7..9876876e83 100644 --- a/contracts/hackatom/Cargo.toml +++ b/contracts/hackatom/Cargo.toml @@ -25,7 +25,6 @@ overflow-checks = true [dependencies] cosmwasm-schema = { path = "../../packages/schema" } cosmwasm-std = { path = "../../packages/std", default-features = false, features = [ - "abort", "cosmwasm_2_2", "std", ] } From 086c06e724990dc50a979deabd4e5ff9c76b749e Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 13 Jan 2025 11:53:43 +0100 Subject: [PATCH 3/7] Fix CI clippy run (cherry picked from commit d3538f48c049849fc35b7754423b963fe71edf17) --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 780665783a..724c6386d7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1090,7 +1090,8 @@ jobs: - run: name: Clippy linting on std (all feature flags) working_directory: ~/project/packages/std - command: cargo clippy --all-targets --tests --all-features -- -D warnings + # change to --all-features once `abort` is removed + command: cargo clippy --all-targets --tests --features staking,stargate,cosmwasm_2_2 -- -D warnings - run: name: Clippy linting on vm (no feature flags) working_directory: ~/project/packages/vm From 1d9e80203a50e99438465fb846817c175034a6bc Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 13 Jan 2025 11:59:23 +0100 Subject: [PATCH 4/7] Specify abort warning (cherry picked from commit 3cb2841ad582fe13680a09eaef98e59f27dd4a0a) --- packages/std/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index 1823413a3b..eede5242a0 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -120,7 +120,7 @@ pub use crate::types::{BlockInfo, ContractInfo, Env, MessageInfo, MigrateInfo, T #[cfg(feature = "abort")] mod _warning { - #[must_use = "cosmwasm-std feature `abort` is deprecated and will be removed in the next release. You can just remove the feature as this functionality is now the default"] + #[must_use = "cosmwasm-std feature `abort` is deprecated and will be removed in the next major release. You can just remove the feature as this functionality is now the default"] struct CompileWarning; #[allow(dead_code)] From 2512572c28d7d68d67a45f3f318f143200b25a1a Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 19 Feb 2025 12:36:47 +0000 Subject: [PATCH 5/7] [autofix.ci] apply automated fixes --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 99211f8b5b..e2f95d7e77 100644 --- a/README.md +++ b/README.md @@ -190,18 +190,17 @@ extern "C" fn ibc_packet_ack(env_ptr: u32, msg_ptr: u32) -> u32; extern "C" fn ibc_packet_timeout(env_ptr: u32, msg_ptr: u32) -> u32; ``` -<<<<<<< HEAD -`allocate`/`deallocate` allow the host to manage data within the Wasm VM. If -you're using Rust, you can implement them by simply +<<<<<<< HEAD `allocate`/`deallocate` allow the host to manage data within the +Wasm VM. If you're using Rust, you can implement them by simply [re-exporting them from cosmwasm::exports](https://github.com/CosmWasm/cosmwasm/blob/v0.6.3/contracts/hackatom/src/lib.rs#L5). -`instantiate`, `execute` and `query` must be defined by your contract. -======= +`instantiate`, `execute` and `query` must be defined by your contract. ======= `allocate` and `deallocate` allow the host to manage data within the Wasm VM. If you're using Rust, you get them automatically by using the `cosmwasm-std` crate. Your contract can define the other entrypoints using the `cosmwasm_std::entry_point` macro to get strong typing instead of raw memory offsets. ->>>>>>> 7c4e518a (Disable abort feature) + +> > > > > > > 7c4e518a (Disable abort feature) ### Imports From f800ae69681ff1d15bdfdf60ed68cb03567caa35 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 19 Feb 2025 14:07:27 +0100 Subject: [PATCH 6/7] Resolve conflict --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index e2f95d7e77..379a3a882e 100644 --- a/README.md +++ b/README.md @@ -190,18 +190,12 @@ extern "C" fn ibc_packet_ack(env_ptr: u32, msg_ptr: u32) -> u32; extern "C" fn ibc_packet_timeout(env_ptr: u32, msg_ptr: u32) -> u32; ``` -<<<<<<< HEAD `allocate`/`deallocate` allow the host to manage data within the -Wasm VM. If you're using Rust, you can implement them by simply -[re-exporting them from cosmwasm::exports](https://github.com/CosmWasm/cosmwasm/blob/v0.6.3/contracts/hackatom/src/lib.rs#L5). -`instantiate`, `execute` and `query` must be defined by your contract. ======= `allocate` and `deallocate` allow the host to manage data within the Wasm VM. If you're using Rust, you get them automatically by using the `cosmwasm-std` crate. Your contract can define the other entrypoints using the `cosmwasm_std::entry_point` macro to get strong typing instead of raw memory offsets. -> > > > > > > 7c4e518a (Disable abort feature) - ### Imports The imports provided to give the contract access to the environment are: From 14580c692d38b0c5ba54546ca234cc7ebed7034e Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 19 Feb 2025 14:14:27 +0100 Subject: [PATCH 7/7] Add changelog entry --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cd5d31075..185f29f7ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ and this project adheres to ## [Unreleased] +### Changed + +- cosmwasm-std: Deprecate `abort` feature. The panic handler is now always + enabled. ([#2384]) + +[#2384]: https://github.com/CosmWasm/cosmwasm/pull/2384 + ## [2.2.1] - 2025-02-04 ## Added