From 689027b7878cb5cd99fb0f89a53f452bd0be3d20 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 6 May 2022 15:58:17 +0200 Subject: [PATCH 01/27] Bump serde-json-wasm to 0.4.1 --- Cargo.lock | 4 ++-- contracts/burner/Cargo.lock | 4 ++-- contracts/crypto-verify/Cargo.lock | 4 ++-- contracts/floaty/Cargo.lock | 4 ++-- contracts/hackatom/Cargo.lock | 4 ++-- contracts/ibc-reflect-send/Cargo.lock | 4 ++-- contracts/ibc-reflect/Cargo.lock | 4 ++-- contracts/queue/Cargo.lock | 4 ++-- contracts/reflect/Cargo.lock | 4 ++-- contracts/staking/Cargo.lock | 4 ++-- packages/std/Cargo.toml | 2 +- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b9ad236586..3d6dc2cb7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1569,9 +1569,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd1e2bc04a6b848717fd51368c98e09bb22a27082804b2e33b4c75cda4d7b07" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" dependencies = [ "serde", ] diff --git a/contracts/burner/Cargo.lock b/contracts/burner/Cargo.lock index aa778fd38a..bcfd3f658d 100644 --- a/contracts/burner/Cargo.lock +++ b/contracts/burner/Cargo.lock @@ -1211,9 +1211,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd1e2bc04a6b848717fd51368c98e09bb22a27082804b2e33b4c75cda4d7b07" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" dependencies = [ "serde", ] diff --git a/contracts/crypto-verify/Cargo.lock b/contracts/crypto-verify/Cargo.lock index 5276139bf8..9d9e08296c 100644 --- a/contracts/crypto-verify/Cargo.lock +++ b/contracts/crypto-verify/Cargo.lock @@ -1266,9 +1266,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd1e2bc04a6b848717fd51368c98e09bb22a27082804b2e33b4c75cda4d7b07" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" dependencies = [ "serde", ] diff --git a/contracts/floaty/Cargo.lock b/contracts/floaty/Cargo.lock index a7351c9b5b..382e2bcc70 100644 --- a/contracts/floaty/Cargo.lock +++ b/contracts/floaty/Cargo.lock @@ -1222,9 +1222,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd1e2bc04a6b848717fd51368c98e09bb22a27082804b2e33b4c75cda4d7b07" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" dependencies = [ "serde", ] diff --git a/contracts/hackatom/Cargo.lock b/contracts/hackatom/Cargo.lock index 99a9cee917..cef78ba2c9 100644 --- a/contracts/hackatom/Cargo.lock +++ b/contracts/hackatom/Cargo.lock @@ -1264,9 +1264,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd1e2bc04a6b848717fd51368c98e09bb22a27082804b2e33b4c75cda4d7b07" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" dependencies = [ "serde", ] diff --git a/contracts/ibc-reflect-send/Cargo.lock b/contracts/ibc-reflect-send/Cargo.lock index 72fbbaebf6..e846450cba 100644 --- a/contracts/ibc-reflect-send/Cargo.lock +++ b/contracts/ibc-reflect-send/Cargo.lock @@ -1220,9 +1220,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd1e2bc04a6b848717fd51368c98e09bb22a27082804b2e33b4c75cda4d7b07" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" dependencies = [ "serde", ] diff --git a/contracts/ibc-reflect/Cargo.lock b/contracts/ibc-reflect/Cargo.lock index 55a5da204d..fe3d2dfa13 100644 --- a/contracts/ibc-reflect/Cargo.lock +++ b/contracts/ibc-reflect/Cargo.lock @@ -1220,9 +1220,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd1e2bc04a6b848717fd51368c98e09bb22a27082804b2e33b4c75cda4d7b07" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" dependencies = [ "serde", ] diff --git a/contracts/queue/Cargo.lock b/contracts/queue/Cargo.lock index 826333438d..d7b8b89704 100644 --- a/contracts/queue/Cargo.lock +++ b/contracts/queue/Cargo.lock @@ -1211,9 +1211,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd1e2bc04a6b848717fd51368c98e09bb22a27082804b2e33b4c75cda4d7b07" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" dependencies = [ "serde", ] diff --git a/contracts/reflect/Cargo.lock b/contracts/reflect/Cargo.lock index bcc0834e5e..5f3ac9b374 100644 --- a/contracts/reflect/Cargo.lock +++ b/contracts/reflect/Cargo.lock @@ -1221,9 +1221,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd1e2bc04a6b848717fd51368c98e09bb22a27082804b2e33b4c75cda4d7b07" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" dependencies = [ "serde", ] diff --git a/contracts/staking/Cargo.lock b/contracts/staking/Cargo.lock index 1db29abed8..f8fc2f561e 100644 --- a/contracts/staking/Cargo.lock +++ b/contracts/staking/Cargo.lock @@ -1214,9 +1214,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd1e2bc04a6b848717fd51368c98e09bb22a27082804b2e33b4c75cda4d7b07" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" dependencies = [ "serde", ] diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml index 9da2ebab5a..254d1a3f3b 100644 --- a/packages/std/Cargo.toml +++ b/packages/std/Cargo.toml @@ -34,7 +34,7 @@ stargate = [] base64 = "0.13.0" cosmwasm-derive = { path = "../derive", version = "1.0.0-rc.0" } uint = "0.9.3" -serde-json-wasm = { version = "0.4.0" } +serde-json-wasm = { version = "0.4.1" } schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] } thiserror = "1.0" From d80892e5d8301dabdcd81e49c94ff17c17d291fa Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 6 May 2022 23:45:55 +0200 Subject: [PATCH 02/27] Fix link in markdown [ci skip] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 286d4da24c..9fa21556e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,7 +45,7 @@ and this project adheres to - cosmwasm-std: Remove `Pair` which was previously deprecated. Use `Record` instead. ([#1282]) -[#1282] : https://github.com/CosmWasm/cosmwasm/issues/1282 +[#1282]: https://github.com/CosmWasm/cosmwasm/issues/1282 ## [1.0.0-beta8] - 2022-04-06 From 5e04c3c1aa7e278626196de43aa18e9bedbc6000 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 7 May 2022 11:13:56 +0200 Subject: [PATCH 03/27] Add initial abort implementation --- contracts/hackatom/src/contract.rs | 26 ++++++++++++++++++++++++-- packages/std/src/imports.rs | 9 +++++++++ packages/std/src/lib.rs | 2 +- packages/vm/src/compatibility.rs | 1 + packages/vm/src/errors/vm_error.rs | 14 ++++++++++++++ packages/vm/src/imports.rs | 13 +++++++++++++ packages/vm/src/instance.rs | 7 ++++++- 7 files changed, 68 insertions(+), 4 deletions(-) diff --git a/contracts/hackatom/src/contract.rs b/contracts/hackatom/src/contract.rs index f0dca04246..123d6a1c5a 100644 --- a/contracts/hackatom/src/contract.rs +++ b/contracts/hackatom/src/contract.rs @@ -1,4 +1,5 @@ use sha2::{Digest, Sha256}; +use std::panic; use cosmwasm_std::{ entry_point, from_slice, to_binary, to_vec, Addr, AllBalanceResponse, Api, BankMsg, @@ -13,6 +14,20 @@ use crate::msg::{ }; use crate::state::{State, CONFIG_KEY}; +fn install_panic_handler() { + panic::set_hook(Box::new(|info| { + // E.g. "panicked at 'oh no (a = 3)', src/contract.rs:51:5" + let full_message = info.to_string(); + println!("Message: {}", &full_message); + if let Some(loc) = info.location() { + println!("File: {}", loc.file()); + println!("Line: {}", loc.line()); + } + #[cfg(target_arch = "wasm32")] + cosmwasm_std::handle_panic(&full_message); + })); +} + #[entry_point] pub fn instantiate( deps: DepsMut, @@ -20,7 +35,9 @@ pub fn instantiate( info: MessageInfo, msg: InstantiateMsg, ) -> Result { - deps.api.debug("here we go 🚀"); + install_panic_handler(); + + // deps.api.debug("here we go 🚀"); deps.storage.set( CONFIG_KEY, @@ -31,8 +48,13 @@ pub fn instantiate( })?, ); + let a = 3; + panic!("oh no (a = {a})"); + + println!("Now what?"); + // This adds some unrelated event attribute for testing purposes - Ok(Response::new().add_attribute("Let the", "hacking begin")) + // Ok(Response::new().add_attribute("Let the", "hacking begin")) } #[entry_point] diff --git a/packages/std/src/imports.rs b/packages/std/src/imports.rs index f5aec89958..c78a9b1e3b 100644 --- a/packages/std/src/imports.rs +++ b/packages/std/src/imports.rs @@ -69,6 +69,8 @@ extern "C" { /// In production environments it is expected that those messages are discarded. fn debug(source_ptr: u32); + fn abort(source_ptr: u32); + /// Executes a query on the chain (import). Not to be confused with the /// query export, which queries the state of the contract. fn query_chain(request: u32) -> u32; @@ -395,3 +397,10 @@ impl Querier for ExternalQuerier { }) } } + +pub fn handle_panic(message: &str) { + // keep the boxes in scope, so we free it at the end (don't cast to pointers same line as build_region) + let region = build_region(message.as_bytes()); + let region_ptr = region.as_ref() as *const Region as u32; + unsafe { abort(region_ptr) }; +} diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index be52ed8396..3833a22671 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -89,7 +89,7 @@ pub use crate::exports::{ do_ibc_packet_receive, do_ibc_packet_timeout, }; #[cfg(target_arch = "wasm32")] -pub use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage}; +pub use crate::imports::{handle_panic, ExternalApi, ExternalQuerier, ExternalStorage}; // Exposed for testing only // Both unit tests and integration tests are compiled to native code, so everything in here does not need to compile to Wasm. diff --git a/packages/vm/src/compatibility.rs b/packages/vm/src/compatibility.rs index e381ff438f..f8c894ac11 100644 --- a/packages/vm/src/compatibility.rs +++ b/packages/vm/src/compatibility.rs @@ -10,6 +10,7 @@ use crate::static_analysis::{deserialize_wasm, ExportInfo}; /// Lists all imports we provide upon instantiating the instance in Instance::from_module() /// This should be updated when new imports are added const SUPPORTED_IMPORTS: &[&str] = &[ + "env.abort", "env.db_read", "env.db_write", "env.db_remove", diff --git a/packages/vm/src/errors/vm_error.rs b/packages/vm/src/errors/vm_error.rs index 7da6b00a85..863a27ebd3 100644 --- a/packages/vm/src/errors/vm_error.rs +++ b/packages/vm/src/errors/vm_error.rs @@ -11,6 +11,12 @@ use crate::backend::BackendError; #[derive(Error, Debug)] #[non_exhaustive] pub enum VmError { + #[error("Aborted: {}", msg)] + Aborted { + msg: String, + #[cfg(feature = "backtraces")] + backtrace: Backtrace, + }, #[error("Error calling into the VM's backend: {}", source)] BackendErr { source: BackendError, @@ -142,6 +148,14 @@ pub enum VmError { } impl VmError { + pub(crate) fn aborted(msg: impl Into) -> Self { + VmError::Aborted { + msg: msg.into(), + #[cfg(feature = "backtraces")] + backtrace: Backtrace::capture(), + } + } + pub(crate) fn backend_err(original: BackendError) -> Self { VmError::BackendErr { source: original, diff --git a/packages/vm/src/imports.rs b/packages/vm/src/imports.rs index c183f2511d..73d5acad74 100644 --- a/packages/vm/src/imports.rs +++ b/packages/vm/src/imports.rs @@ -54,6 +54,9 @@ const MAX_COUNT_ED25519_BATCH: usize = 256; /// Max length for a debug message const MAX_LENGTH_DEBUG: usize = 2 * MI; +/// Max length for an abort message +const MAX_LENGTH_ABORT: usize = 2 * MI; + // Import implementations // // This block of do_* prefixed functions is tailored for Wasmer's @@ -359,6 +362,16 @@ pub fn do_debug( Ok(()) } +/// Aborts the contract and shows the given error message +pub fn do_abort( + env: &Environment, + message_ptr: u32, +) -> VmResult<()> { + let message_data = read_region(&env.memory(), message_ptr, MAX_LENGTH_ABORT)?; + let msg = String::from_utf8_lossy(&message_data); + Err(VmError::aborted(msg)) +} + /// Creates a Region in the contract, writes the given data to it and returns the memory location fn write_to_contract( env: &Environment, diff --git a/packages/vm/src/instance.rs b/packages/vm/src/instance.rs index 8110455a76..9279cde553 100644 --- a/packages/vm/src/instance.rs +++ b/packages/vm/src/instance.rs @@ -10,7 +10,7 @@ use crate::environment::Environment; use crate::errors::{CommunicationError, VmError, VmResult}; use crate::features::required_features_from_module; use crate::imports::{ - do_addr_canonicalize, do_addr_humanize, do_addr_validate, do_db_read, do_db_remove, + do_abort, do_addr_canonicalize, do_addr_humanize, do_addr_validate, do_db_read, do_db_remove, do_db_write, do_debug, do_ed25519_batch_verify, do_ed25519_verify, do_query_chain, do_secp256k1_recover_pubkey, do_secp256k1_verify, }; @@ -180,6 +180,11 @@ where Function::new_native_with_env(store, env.clone(), do_debug), ); + env_imports.insert( + "abort", + Function::new_native_with_env(store, env.clone(), do_abort), + ); + env_imports.insert( "query_chain", Function::new_native_with_env(store, env.clone(), do_query_chain), From 4ef28ddede707f41da1593394f521170ce72a454 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 7 May 2022 12:09:35 +0200 Subject: [PATCH 04/27] Add multiple panic cases --- contracts/hackatom/src/contract.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/contracts/hackatom/src/contract.rs b/contracts/hackatom/src/contract.rs index 123d6a1c5a..18f02fe9a6 100644 --- a/contracts/hackatom/src/contract.rs +++ b/contracts/hackatom/src/contract.rs @@ -48,13 +48,25 @@ pub fn instantiate( })?, ); - let a = 3; - panic!("oh no (a = {a})"); + // Uncomment your favourite panic case - println!("Now what?"); + // panicked at 'Now what?', src/contract.rs:53:5 + panic!("Now what?"); + + // panicked at 'oh no (a = 3)', src/contract.rs:56:5 + // let a = 3; + // panic!("oh no (a = {a})"); + + // panicked at 'attempt to subtract with overflow', src/contract.rs:59:13 + // #[allow(arithmetic_overflow)] + // let _ = 5u32 - 8u32; + + // panicked at 'no entry found for key', src/contract.rs:62:13 + // let map = std::collections::HashMap::::new(); + // let _ = map["foo"]; // This adds some unrelated event attribute for testing purposes - // Ok(Response::new().add_attribute("Let the", "hacking begin")) + Ok(Response::new().add_attribute("Let the", "hacking begin")) } #[entry_point] From dd145c5bc98f5a74f0efcc7b8bd7c6b23b565e78 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 7 May 2022 13:13:06 +0200 Subject: [PATCH 05/27] Move install_panic_handler to cosmwasm_std --- contracts/hackatom/src/contract.rs | 20 +++----------------- packages/std/src/lib.rs | 4 +++- packages/std/src/panic.rs | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 packages/std/src/panic.rs diff --git a/contracts/hackatom/src/contract.rs b/contracts/hackatom/src/contract.rs index 18f02fe9a6..d0d8b25d90 100644 --- a/contracts/hackatom/src/contract.rs +++ b/contracts/hackatom/src/contract.rs @@ -2,9 +2,9 @@ use sha2::{Digest, Sha256}; use std::panic; use cosmwasm_std::{ - entry_point, from_slice, to_binary, to_vec, Addr, AllBalanceResponse, Api, BankMsg, - CanonicalAddr, Deps, DepsMut, Env, Event, MessageInfo, QueryRequest, QueryResponse, Response, - StdError, StdResult, WasmMsg, WasmQuery, + entry_point, from_slice, install_panic_handler, to_binary, to_vec, Addr, AllBalanceResponse, + Api, BankMsg, CanonicalAddr, Deps, DepsMut, Env, Event, MessageInfo, QueryRequest, + QueryResponse, Response, StdError, StdResult, WasmMsg, WasmQuery, }; use crate::errors::HackError; @@ -14,20 +14,6 @@ use crate::msg::{ }; use crate::state::{State, CONFIG_KEY}; -fn install_panic_handler() { - panic::set_hook(Box::new(|info| { - // E.g. "panicked at 'oh no (a = 3)', src/contract.rs:51:5" - let full_message = info.to_string(); - println!("Message: {}", &full_message); - if let Some(loc) = info.location() { - println!("File: {}", loc.file()); - println!("Line: {}", loc.line()); - } - #[cfg(target_arch = "wasm32")] - cosmwasm_std::handle_panic(&full_message); - })); -} - #[entry_point] pub fn instantiate( deps: DepsMut, diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index 3833a22671..62fb08d09d 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -14,6 +14,7 @@ mod import_helpers; #[cfg(feature = "iterator")] mod iterator; mod math; +mod panic; mod query; mod results; mod sections; @@ -44,6 +45,7 @@ pub use crate::math::{ Decimal, Decimal256, Decimal256RangeExceeded, DecimalRangeExceeded, Fraction, Isqrt, Uint128, Uint256, Uint512, Uint64, }; +pub use crate::panic::install_panic_handler; pub use crate::query::{ AllBalanceResponse, BalanceResponse, BankQuery, ContractInfoResponse, CustomQuery, QueryRequest, WasmQuery, @@ -89,7 +91,7 @@ pub use crate::exports::{ do_ibc_packet_receive, do_ibc_packet_timeout, }; #[cfg(target_arch = "wasm32")] -pub use crate::imports::{handle_panic, ExternalApi, ExternalQuerier, ExternalStorage}; +pub use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage}; // Exposed for testing only // Both unit tests and integration tests are compiled to native code, so everything in here does not need to compile to Wasm. diff --git a/packages/std/src/panic.rs b/packages/std/src/panic.rs new file mode 100644 index 0000000000..dda65da6f7 --- /dev/null +++ b/packages/std/src/panic.rs @@ -0,0 +1,14 @@ +/// When compiled to Wasm, this installs a panic handler that aborts the +/// contract in case of a panic. +/// For other targets, this is a noop. +pub fn install_panic_handler() { + #[cfg(target_arch = "wasm32")] + { + use super::imports::handle_panic; + std::panic::set_hook(Box::new(|info| { + // E.g. "panicked at 'oh no (a = 3)', src/contract.rs:51:5" + let full_message = info.to_string(); + handle_panic(&full_message); + })); + } +} From 21f8449781916517ec34f4bc12b08b814c77290d Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 7 May 2022 13:22:25 +0200 Subject: [PATCH 06/27] Install panic handler automatically for all entry points --- contracts/hackatom/src/contract.rs | 9 +++------ packages/std/src/exports.rs | 13 +++++++++++++ packages/std/src/panic.rs | 5 ++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/contracts/hackatom/src/contract.rs b/contracts/hackatom/src/contract.rs index d0d8b25d90..36c9d06196 100644 --- a/contracts/hackatom/src/contract.rs +++ b/contracts/hackatom/src/contract.rs @@ -1,10 +1,9 @@ use sha2::{Digest, Sha256}; -use std::panic; use cosmwasm_std::{ - entry_point, from_slice, install_panic_handler, to_binary, to_vec, Addr, AllBalanceResponse, - Api, BankMsg, CanonicalAddr, Deps, DepsMut, Env, Event, MessageInfo, QueryRequest, - QueryResponse, Response, StdError, StdResult, WasmMsg, WasmQuery, + entry_point, from_slice, to_binary, to_vec, Addr, AllBalanceResponse, Api, BankMsg, + CanonicalAddr, Deps, DepsMut, Env, Event, MessageInfo, QueryRequest, QueryResponse, Response, + StdError, StdResult, WasmMsg, WasmQuery, }; use crate::errors::HackError; @@ -21,8 +20,6 @@ pub fn instantiate( info: MessageInfo, msg: InstantiateMsg, ) -> Result { - install_panic_handler(); - // deps.api.debug("here we go 🚀"); deps.storage.set( diff --git a/packages/std/src/exports.rs b/packages/std/src/exports.rs index f1a06a9a31..e09f9b390e 100644 --- a/packages/std/src/exports.rs +++ b/packages/std/src/exports.rs @@ -20,6 +20,7 @@ use crate::ibc::{ }; use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage}; use crate::memory::{alloc, consume_region, release_buffer, Region}; +use crate::panic::install_panic_handler; use crate::query::CustomQuery; use crate::results::{ContractResult, QueryResponse, Reply, Response}; use crate::serde::{from_slice, to_vec}; @@ -93,6 +94,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_instantiate( instantiate_fn, env_ptr as *mut Region, @@ -121,6 +123,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_execute( execute_fn, env_ptr as *mut Region, @@ -148,6 +151,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_migrate(migrate_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); release_buffer(v) as u32 @@ -170,6 +174,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_sudo(sudo_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); release_buffer(v) as u32 @@ -191,6 +196,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_reply(reply_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); release_buffer(v) as u32 @@ -211,6 +217,7 @@ where M: DeserializeOwned, E: ToString, { + install_panic_handler(); let res = _do_query(query_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); release_buffer(v) as u32 @@ -232,6 +239,7 @@ where Q: CustomQuery, E: ToString, { + install_panic_handler(); let res = _do_ibc_channel_open(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); release_buffer(v) as u32 @@ -255,6 +263,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_ibc_channel_connect(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); release_buffer(v) as u32 @@ -278,6 +287,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_ibc_channel_close(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); release_buffer(v) as u32 @@ -302,6 +312,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_ibc_packet_receive(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); release_buffer(v) as u32 @@ -326,6 +337,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_ibc_packet_ack(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); release_buffer(v) as u32 @@ -351,6 +363,7 @@ where C: CustomMsg, E: ToString, { + install_panic_handler(); let res = _do_ibc_packet_timeout(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); release_buffer(v) as u32 diff --git a/packages/std/src/panic.rs b/packages/std/src/panic.rs index dda65da6f7..413c0e38ce 100644 --- a/packages/std/src/panic.rs +++ b/packages/std/src/panic.rs @@ -1,6 +1,9 @@ /// When compiled to Wasm, this installs a panic handler that aborts the -/// contract in case of a panic. +/// contract execution and sends the panic message and location to the host. /// For other targets, this is a noop. +/// +/// This overrides any previous panic handler. See +/// for details. pub fn install_panic_handler() { #[cfg(target_arch = "wasm32")] { From c5ec801a7923818c8fec7671850e6ce23bb4cef5 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 7 May 2022 14:21:58 +0200 Subject: [PATCH 07/27] Add abort feature --- .circleci/config.yml | 8 ++++---- contracts/hackatom/Cargo.toml | 2 +- contracts/hackatom/tests/integration.rs | 3 ++- devtools/check_workspace.sh | 6 +++--- packages/std/Cargo.toml | 1 + packages/std/src/exports.rs | 17 +++++++++++++++++ packages/std/src/imports.rs | 6 ++++-- packages/std/src/lib.rs | 1 - packages/std/src/panic.rs | 1 + packages/vm/examples/check_contract.rs | 2 +- packages/vm/examples/multi_threaded_cache.rs | 2 +- packages/vm/src/cache.rs | 6 ++++-- packages/vm/src/testing/instance.rs | 2 +- 13 files changed, 40 insertions(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c701dafe39..7fbee3bedb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -218,15 +218,15 @@ jobs: - run: name: Build library for native target (all features) working_directory: ~/project/packages/std - command: cargo build --locked --features iterator,staking,stargate + command: cargo build --locked --features abort,iterator,staking,stargate - run: name: Build library for wasm target (all features) working_directory: ~/project/packages/std - command: cargo wasm --locked --features iterator,staking,stargate + command: cargo wasm --locked --features abort,iterator,staking,stargate - run: name: Run unit tests (all features) working_directory: ~/project/packages/std - command: cargo test --locked --features iterator,staking,stargate + command: cargo test --locked --features abort,iterator,staking,stargate - run: name: Build and run schema generator working_directory: ~/project/packages/std @@ -945,7 +945,7 @@ jobs: - run: name: Clippy linting on std (all feature flags) working_directory: ~/project/packages/std - command: cargo clippy --all-targets --features iterator,staking,stargate -- -D warnings + command: cargo clippy --all-targets --features abort,iterator,staking,stargate -- -D warnings - run: name: Clippy linting on storage (no feature flags) working_directory: ~/project/packages/storage diff --git a/contracts/hackatom/Cargo.toml b/contracts/hackatom/Cargo.toml index 9231cad19b..2b91ed1308 100644 --- a/contracts/hackatom/Cargo.toml +++ b/contracts/hackatom/Cargo.toml @@ -31,7 +31,7 @@ cranelift = ["cosmwasm-vm/cranelift"] backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"] [dependencies] -cosmwasm-std = { path = "../../packages/std", default-features = false } +cosmwasm-std = { path = "../../packages/std", default-features = false, features = ["abort"] } rust-argon2 = "0.8" schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } diff --git a/contracts/hackatom/tests/integration.rs b/contracts/hackatom/tests/integration.rs index 0035900872..66182ecee8 100644 --- a/contracts/hackatom/tests/integration.rs +++ b/contracts/hackatom/tests/integration.rs @@ -54,7 +54,8 @@ fn make_init_msg() -> (InstantiateMsg, String) { #[test] fn proper_initialization() { let mut deps = mock_instance(WASM, &[]); - assert_eq!(deps.required_features().len(), 0); + assert_eq!(deps.required_features().len(), 1); + assert!(deps.required_features().contains("abort")); let verifier = String::from("verifies"); let beneficiary = String::from("benefits"); diff --git a/devtools/check_workspace.sh b/devtools/check_workspace.sh index bf04f90bb8..b0949434c2 100755 --- a/devtools/check_workspace.sh +++ b/devtools/check_workspace.sh @@ -9,10 +9,10 @@ cargo fmt ( cd packages/std cargo check - cargo check --features iterator,staking,stargate + cargo check --features abort,iterator,staking,stargate cargo wasm-debug - cargo wasm-debug --features iterator,staking,stargate - cargo clippy --all-targets --features iterator,staking,stargate -- -D warnings + cargo wasm-debug --features abort,iterator,staking,stargate + cargo clippy --all-targets --features abort,iterator,staking,stargate -- -D warnings cargo schema ) (cd packages/storage && cargo build && cargo clippy --all-targets --features iterator -- -D warnings) diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml index 254d1a3f3b..6092377a57 100644 --- a/packages/std/Cargo.toml +++ b/packages/std/Cargo.toml @@ -13,6 +13,7 @@ features = ["stargate", "staking"] [features] default = ["iterator"] +abort = [] # iterator allows us to iterate over all DB items in a given range # optional as some merkle stores (like tries) don't support this # given Ethereum 1.0, 2.0, Substrate, and other major projects use Tries diff --git a/packages/std/src/exports.rs b/packages/std/src/exports.rs index e09f9b390e..03bb8da858 100644 --- a/packages/std/src/exports.rs +++ b/packages/std/src/exports.rs @@ -20,6 +20,7 @@ use crate::ibc::{ }; use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage}; use crate::memory::{alloc, consume_region, release_buffer, Region}; +#[cfg(feature = "abort")] use crate::panic::install_panic_handler; use crate::query::CustomQuery; use crate::results::{ContractResult, QueryResponse, Reply, Response}; @@ -27,6 +28,10 @@ use crate::serde::{from_slice, to_vec}; use crate::types::Env; use crate::{CustomMsg, Deps, DepsMut, MessageInfo}; +#[cfg(feature = "abort")] +#[no_mangle] +extern "C" fn requires_abort() -> () {} + #[cfg(feature = "iterator")] #[no_mangle] extern "C" fn requires_iterator() -> () {} @@ -94,6 +99,7 @@ where C: CustomMsg, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_instantiate( instantiate_fn, @@ -123,6 +129,7 @@ where C: CustomMsg, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_execute( execute_fn, @@ -151,6 +158,7 @@ where C: CustomMsg, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_migrate(migrate_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); @@ -174,6 +182,7 @@ where C: CustomMsg, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_sudo(sudo_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); @@ -196,6 +205,7 @@ where C: CustomMsg, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_reply(reply_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); @@ -217,6 +227,7 @@ where M: DeserializeOwned, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_query(query_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); @@ -239,6 +250,7 @@ where Q: CustomQuery, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_channel_open(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); @@ -263,6 +275,7 @@ where C: CustomMsg, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_channel_connect(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); @@ -287,6 +300,7 @@ where C: CustomMsg, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_channel_close(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); @@ -312,6 +326,7 @@ where C: CustomMsg, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_packet_receive(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); @@ -337,6 +352,7 @@ where C: CustomMsg, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_packet_ack(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); @@ -363,6 +379,7 @@ where C: CustomMsg, E: ToString, { + #[cfg(feature = "abort")] install_panic_handler(); let res = _do_ibc_packet_timeout(contract_fn, env_ptr as *mut Region, msg_ptr as *mut Region); let v = to_vec(&res).unwrap(); diff --git a/packages/std/src/imports.rs b/packages/std/src/imports.rs index c78a9b1e3b..df03d1d640 100644 --- a/packages/std/src/imports.rs +++ b/packages/std/src/imports.rs @@ -26,6 +26,9 @@ 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; fn db_write(key: u32, value: u32); fn db_remove(key: u32); @@ -69,8 +72,6 @@ extern "C" { /// In production environments it is expected that those messages are discarded. fn debug(source_ptr: u32); - fn abort(source_ptr: u32); - /// Executes a query on the chain (import). Not to be confused with the /// query export, which queries the state of the contract. fn query_chain(request: u32) -> u32; @@ -398,6 +399,7 @@ impl Querier for ExternalQuerier { } } +#[cfg(feature = "abort")] pub fn handle_panic(message: &str) { // keep the boxes in scope, so we free it at the end (don't cast to pointers same line as build_region) let region = build_region(message.as_bytes()); diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index 62fb08d09d..8b695fedaa 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -45,7 +45,6 @@ pub use crate::math::{ Decimal, Decimal256, Decimal256RangeExceeded, DecimalRangeExceeded, Fraction, Isqrt, Uint128, Uint256, Uint512, Uint64, }; -pub use crate::panic::install_panic_handler; pub use crate::query::{ AllBalanceResponse, BalanceResponse, BankQuery, ContractInfoResponse, CustomQuery, QueryRequest, WasmQuery, diff --git a/packages/std/src/panic.rs b/packages/std/src/panic.rs index 413c0e38ce..1497caf816 100644 --- a/packages/std/src/panic.rs +++ b/packages/std/src/panic.rs @@ -4,6 +4,7 @@ /// /// This overrides any previous panic handler. See /// for details. +#[cfg(feature = "abort")] pub fn install_panic_handler() { #[cfg(target_arch = "wasm32")] { diff --git a/packages/vm/examples/check_contract.rs b/packages/vm/examples/check_contract.rs index 6473e27e38..a0165089b7 100644 --- a/packages/vm/examples/check_contract.rs +++ b/packages/vm/examples/check_contract.rs @@ -6,7 +6,7 @@ use clap::{App, Arg}; use cosmwasm_vm::features_from_csv; use cosmwasm_vm::internals::{check_wasm, compile}; -const DEFAULT_SUPPORTED_FEATURES: &str = "iterator,staking,stargate"; +const DEFAULT_SUPPORTED_FEATURES: &str = "abort,iterator,staking,stargate"; pub fn main() { let matches = App::new("Contract checking") diff --git a/packages/vm/examples/multi_threaded_cache.rs b/packages/vm/examples/multi_threaded_cache.rs index 7c1375f82e..3609072775 100644 --- a/packages/vm/examples/multi_threaded_cache.rs +++ b/packages/vm/examples/multi_threaded_cache.rs @@ -27,7 +27,7 @@ const THREADS: usize = SAVE_WASM_THREADS + INSTANTIATION_THREADS; pub fn main() { let options = CacheOptions { base_dir: TempDir::new().unwrap().into_path(), - supported_features: features_from_csv("iterator,staking"), + supported_features: features_from_csv("abort,iterator,staking"), memory_cache_size: MEMORY_CACHE_SIZE, instance_memory_limit: DEFAULT_MEMORY_LIMIT, }; diff --git a/packages/vm/src/cache.rs b/packages/vm/src/cache.rs index da765e0cd2..11eb1ab6cd 100644 --- a/packages/vm/src/cache.rs +++ b/packages/vm/src/cache.rs @@ -389,7 +389,7 @@ mod tests { static IBC_CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm"); fn default_features() -> HashSet { - features_from_csv("iterator,staking") + features_from_csv("abort,iterator,staking") } fn make_testing_options() -> CacheOptions { @@ -402,9 +402,11 @@ mod tests { } fn make_stargate_testing_options() -> CacheOptions { + let mut feature = default_features(); + feature.insert("stargate".into()); CacheOptions { base_dir: TempDir::new().unwrap().into_path(), - supported_features: features_from_csv("iterator,staking,stargate"), + supported_features: feature, memory_cache_size: TESTING_MEMORY_CACHE_SIZE, instance_memory_limit: TESTING_MEMORY_LIMIT, } diff --git a/packages/vm/src/testing/instance.rs b/packages/vm/src/testing/instance.rs index 2bba244eeb..617c53220b 100644 --- a/packages/vm/src/testing/instance.rs +++ b/packages/vm/src/testing/instance.rs @@ -95,7 +95,7 @@ pub struct MockInstanceOptions<'a> { impl MockInstanceOptions<'_> { fn default_features() -> HashSet { #[allow(unused_mut)] - let mut out = features_from_csv("iterator,staking"); + let mut out = features_from_csv("abort,iterator,staking"); #[cfg(feature = "stargate")] out.insert("stargate".to_string()); out From cda75f4fb98823f4721a48e16430994563123ec0 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 10 May 2022 22:01:18 +0200 Subject: [PATCH 08/27] Export DelegationResponse from cosmwasm-std/lib.rs --- packages/std/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index be52ed8396..5b34514bd0 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -50,8 +50,8 @@ pub use crate::query::{ }; #[cfg(feature = "staking")] pub use crate::query::{ - AllDelegationsResponse, AllValidatorsResponse, BondedDenomResponse, Delegation, FullDelegation, - StakingQuery, Validator, ValidatorResponse, + AllDelegationsResponse, AllValidatorsResponse, BondedDenomResponse, Delegation, + DelegationResponse, FullDelegation, StakingQuery, Validator, ValidatorResponse, }; #[cfg(feature = "stargate")] pub use crate::query::{ChannelResponse, IbcQuery, ListChannelsResponse, PortIdResponse}; From c1dd6c5e19d2055f92e311a673e4df995eafffe9 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 11 May 2022 19:49:26 +0200 Subject: [PATCH 09/27] Create FEATURES.md --- docs/FEATURES.md | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 docs/FEATURES.md diff --git a/docs/FEATURES.md b/docs/FEATURES.md new file mode 100644 index 0000000000..e6fcce6410 --- /dev/null +++ b/docs/FEATURES.md @@ -0,0 +1,100 @@ +# Features + +Features are a mechanism to negotiate functionality between a contract and an +environment (i.e. the chain that embeds cosmwasm-vm/[wasmvm]) in a very +primitive way. The contract defines required features. The environment defines +supported features. If the required features are all supported, the contract can +be used. Doing this check when the contract is first stored ensures missing +features are detected early and not when a user tries to execute a certain code +path. + +## Disambiguation + +This document is about app level features in the CosmWasm VM. Features should +not be confused with Cargo's build system features, even when connected. +Features can be implemented in any language that compiles to Wasm. + +## Required features + +The contract defines required features using a marker export function that takes +no arguments and returns no value. The name of the export needs to start with +"requires\_" followed by the name of the feature. Do yourself a favor and keep +the name all lower ASCII alphanumerical. + +An example of such markers in cosmwasm-std are those: + +```rust +#[cfg(feature = "iterator")] +#[no_mangle] +extern "C" fn requires_iterator() -> () {} + +#[cfg(feature = "staking")] +#[no_mangle] +extern "C" fn requires_staking() -> () {} + +#[cfg(feature = "stargate")] +#[no_mangle] +extern "C" fn requires_stargate() -> () {} +``` + +which in Wasm compile to this: + +``` +# ... + (export "requires_staking" (func 181)) + (export "requires_stargate" (func 181)) + (export "requires_iterator" (func 181)) +# ... + (func (;181;) (type 12) + nop) +# ... + (type (;12;) (func)) +``` + +As mentioned above, the Cargo features are independent of the features we talk +about and it is perfectly fine to have a requires\_\* export that is +unconditional in a library or a contract. + +The marker export functions can be executed, but the VM does not require such a +call to succeed. So a contract can use no-op implementation or crashing +implementation. + +## Supported features + +An instance of the main `Cache` has `supported_features` in its `CacheOptions`. +This value is set in the caller, such as +[here](https://github.com/CosmWasm/wasmvm/blob/v1.0.0-rc.0/libwasmvm/src/cache.rs#L75) +and +[here](https://github.com/CosmWasm/wasmvm/blob/v1.0.0-rc.0/libwasmvm/src/cache.rs#L62). +`features_from_csv` takes a comma separated list and returns a set of features. +This features list is set +[in keeper.go](https://github.com/CosmWasm/wasmd/blob/v0.27.0-rc0/x/wasm/keeper/keeper.go#L100) +and +[in app.go](https://github.com/CosmWasm/wasmd/blob/v0.27.0-rc0/app/app.go#L475-L496). + +## Common features + +Here is a list of features created in the past. Since features can be created +between contract and environment, we don't know them all in the VM. + +- `iterator` is for storage backends that allow range queries. Not all types of + databases do that. There are trees that don't allow it and Secret Network does + not support iterators for other technical reasons. +- `stargate` is for messages and queries that came with the Cosmos SDK upgrade + "Stargate". It primarily includes protobuf messages and IBC support. +- `staking` is for chains with the Cosmos SDK staking module. There are Cosmos + chains that don't use this (e.g. Tgrade). + +## What's a good feature? + +A good feature makes sense to be disabled. The examples above explain why the +feature is not present in some environments. + +When functionality is always present in the VM (such as a new import implemented +directly in the VM, see [#1299]), we should not use features. They just create +fragmentation in the CosmWasm ecosystem and increase the barrier for adoption. +Instead the `check_wasm_imports` check is used to validate this when the +contract is stored. + +[wasmvm]: https://github.com/CosmWasm/wasmvm +[#1299]: https://github.com/CosmWasm/cosmwasm/pull/1299 From d37cc828e03f98a921a857507688a2b50498df8b Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 11 May 2022 19:54:18 +0200 Subject: [PATCH 10/27] Remove abort feature --- .circleci/config.yml | 8 ++++---- contracts/hackatom/tests/integration.rs | 3 +-- devtools/check_workspace.sh | 6 +++--- packages/std/src/exports.rs | 4 ---- packages/vm/examples/check_contract.rs | 2 +- packages/vm/examples/multi_threaded_cache.rs | 2 +- packages/vm/src/cache.rs | 2 +- packages/vm/src/testing/instance.rs | 2 +- 8 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7fbee3bedb..c701dafe39 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -218,15 +218,15 @@ jobs: - run: name: Build library for native target (all features) working_directory: ~/project/packages/std - command: cargo build --locked --features abort,iterator,staking,stargate + command: cargo build --locked --features iterator,staking,stargate - run: name: Build library for wasm target (all features) working_directory: ~/project/packages/std - command: cargo wasm --locked --features abort,iterator,staking,stargate + command: cargo wasm --locked --features iterator,staking,stargate - run: name: Run unit tests (all features) working_directory: ~/project/packages/std - command: cargo test --locked --features abort,iterator,staking,stargate + command: cargo test --locked --features iterator,staking,stargate - run: name: Build and run schema generator working_directory: ~/project/packages/std @@ -945,7 +945,7 @@ jobs: - run: name: Clippy linting on std (all feature flags) working_directory: ~/project/packages/std - command: cargo clippy --all-targets --features abort,iterator,staking,stargate -- -D warnings + command: cargo clippy --all-targets --features iterator,staking,stargate -- -D warnings - run: name: Clippy linting on storage (no feature flags) working_directory: ~/project/packages/storage diff --git a/contracts/hackatom/tests/integration.rs b/contracts/hackatom/tests/integration.rs index 66182ecee8..0035900872 100644 --- a/contracts/hackatom/tests/integration.rs +++ b/contracts/hackatom/tests/integration.rs @@ -54,8 +54,7 @@ fn make_init_msg() -> (InstantiateMsg, String) { #[test] fn proper_initialization() { let mut deps = mock_instance(WASM, &[]); - assert_eq!(deps.required_features().len(), 1); - assert!(deps.required_features().contains("abort")); + assert_eq!(deps.required_features().len(), 0); let verifier = String::from("verifies"); let beneficiary = String::from("benefits"); diff --git a/devtools/check_workspace.sh b/devtools/check_workspace.sh index b0949434c2..bf04f90bb8 100755 --- a/devtools/check_workspace.sh +++ b/devtools/check_workspace.sh @@ -9,10 +9,10 @@ cargo fmt ( cd packages/std cargo check - cargo check --features abort,iterator,staking,stargate + cargo check --features iterator,staking,stargate cargo wasm-debug - cargo wasm-debug --features abort,iterator,staking,stargate - cargo clippy --all-targets --features abort,iterator,staking,stargate -- -D warnings + cargo wasm-debug --features iterator,staking,stargate + cargo clippy --all-targets --features iterator,staking,stargate -- -D warnings cargo schema ) (cd packages/storage && cargo build && cargo clippy --all-targets --features iterator -- -D warnings) diff --git a/packages/std/src/exports.rs b/packages/std/src/exports.rs index 03bb8da858..b04b89c580 100644 --- a/packages/std/src/exports.rs +++ b/packages/std/src/exports.rs @@ -28,10 +28,6 @@ use crate::serde::{from_slice, to_vec}; use crate::types::Env; use crate::{CustomMsg, Deps, DepsMut, MessageInfo}; -#[cfg(feature = "abort")] -#[no_mangle] -extern "C" fn requires_abort() -> () {} - #[cfg(feature = "iterator")] #[no_mangle] extern "C" fn requires_iterator() -> () {} diff --git a/packages/vm/examples/check_contract.rs b/packages/vm/examples/check_contract.rs index a0165089b7..6473e27e38 100644 --- a/packages/vm/examples/check_contract.rs +++ b/packages/vm/examples/check_contract.rs @@ -6,7 +6,7 @@ use clap::{App, Arg}; use cosmwasm_vm::features_from_csv; use cosmwasm_vm::internals::{check_wasm, compile}; -const DEFAULT_SUPPORTED_FEATURES: &str = "abort,iterator,staking,stargate"; +const DEFAULT_SUPPORTED_FEATURES: &str = "iterator,staking,stargate"; pub fn main() { let matches = App::new("Contract checking") diff --git a/packages/vm/examples/multi_threaded_cache.rs b/packages/vm/examples/multi_threaded_cache.rs index 3609072775..7c1375f82e 100644 --- a/packages/vm/examples/multi_threaded_cache.rs +++ b/packages/vm/examples/multi_threaded_cache.rs @@ -27,7 +27,7 @@ const THREADS: usize = SAVE_WASM_THREADS + INSTANTIATION_THREADS; pub fn main() { let options = CacheOptions { base_dir: TempDir::new().unwrap().into_path(), - supported_features: features_from_csv("abort,iterator,staking"), + supported_features: features_from_csv("iterator,staking"), memory_cache_size: MEMORY_CACHE_SIZE, instance_memory_limit: DEFAULT_MEMORY_LIMIT, }; diff --git a/packages/vm/src/cache.rs b/packages/vm/src/cache.rs index 11eb1ab6cd..d3f50777c3 100644 --- a/packages/vm/src/cache.rs +++ b/packages/vm/src/cache.rs @@ -389,7 +389,7 @@ mod tests { static IBC_CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm"); fn default_features() -> HashSet { - features_from_csv("abort,iterator,staking") + features_from_csv("iterator,staking") } fn make_testing_options() -> CacheOptions { diff --git a/packages/vm/src/testing/instance.rs b/packages/vm/src/testing/instance.rs index 617c53220b..2bba244eeb 100644 --- a/packages/vm/src/testing/instance.rs +++ b/packages/vm/src/testing/instance.rs @@ -95,7 +95,7 @@ pub struct MockInstanceOptions<'a> { impl MockInstanceOptions<'_> { fn default_features() -> HashSet { #[allow(unused_mut)] - let mut out = features_from_csv("abort,iterator,staking"); + let mut out = features_from_csv("iterator,staking"); #[cfg(feature = "stargate")] out.insert("stargate".to_string()); out From 95f2528cbf75cf73b102f6c4a19fed3b2208feb7 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 11 May 2022 20:19:09 +0200 Subject: [PATCH 11/27] Remove install_panic_handler from non-wasm32 builds --- packages/std/src/panic.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/std/src/panic.rs b/packages/std/src/panic.rs index 1497caf816..7ca619e31a 100644 --- a/packages/std/src/panic.rs +++ b/packages/std/src/panic.rs @@ -1,18 +1,14 @@ -/// When compiled to Wasm, this installs a panic handler that aborts the -/// contract execution and sends the panic message and location to the host. -/// For other targets, this is a noop. +/// Installs a panic handler that aborts the contract execution +/// and sends the panic message and location to the host. /// /// This overrides any previous panic handler. See /// for details. -#[cfg(feature = "abort")] +#[cfg(all(feature = "abort", target_arch = "wasm32"))] pub fn install_panic_handler() { - #[cfg(target_arch = "wasm32")] - { - use super::imports::handle_panic; - std::panic::set_hook(Box::new(|info| { - // E.g. "panicked at 'oh no (a = 3)', src/contract.rs:51:5" - let full_message = info.to_string(); - handle_panic(&full_message); - })); - } + use super::imports::handle_panic; + std::panic::set_hook(Box::new(|info| { + // E.g. "panicked at 'oh no (a = 3)', src/contract.rs:51:5" + let full_message = info.to_string(); + handle_panic(&full_message); + })); } From 2ba4f848ea2fb3de196b5d71fda0c5473ed770cc Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 11 May 2022 20:19:18 +0200 Subject: [PATCH 12/27] Fix hackatom testing --- contracts/hackatom/src/contract.rs | 34 ++++++++++++------------- contracts/hackatom/tests/integration.rs | 2 +- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/contracts/hackatom/src/contract.rs b/contracts/hackatom/src/contract.rs index 36c9d06196..9bc34efe7e 100644 --- a/contracts/hackatom/src/contract.rs +++ b/contracts/hackatom/src/contract.rs @@ -20,7 +20,7 @@ pub fn instantiate( info: MessageInfo, msg: InstantiateMsg, ) -> Result { - // deps.api.debug("here we go 🚀"); + deps.api.debug("here we go 🚀"); deps.storage.set( CONFIG_KEY, @@ -31,23 +31,6 @@ pub fn instantiate( })?, ); - // Uncomment your favourite panic case - - // panicked at 'Now what?', src/contract.rs:53:5 - panic!("Now what?"); - - // panicked at 'oh no (a = 3)', src/contract.rs:56:5 - // let a = 3; - // panic!("oh no (a = {a})"); - - // panicked at 'attempt to subtract with overflow', src/contract.rs:59:13 - // #[allow(arithmetic_overflow)] - // let _ = 5u32 - 8u32; - - // panicked at 'no entry found for key', src/contract.rs:62:13 - // let map = std::collections::HashMap::::new(); - // let _ = map["foo"]; - // This adds some unrelated event attribute for testing purposes Ok(Response::new().add_attribute("Let the", "hacking begin")) } @@ -206,7 +189,22 @@ fn do_allocate_large_memory(pages: u32) -> Result { } fn do_panic() -> Result { + // Uncomment your favourite panic case + + // panicked at 'This page intentionally faulted', src/contract.rs:53:5 panic!("This page intentionally faulted"); + + // panicked at 'oh no (a = 3)', src/contract.rs:56:5 + // let a = 3; + // panic!("oh no (a = {a})"); + + // panicked at 'attempt to subtract with overflow', src/contract.rs:59:13 + // #[allow(arithmetic_overflow)] + // let _ = 5u32 - 8u32; + + // panicked at 'no entry found for key', src/contract.rs:62:13 + // let map = std::collections::HashMap::::new(); + // let _ = map["foo"]; } fn do_user_errors_in_api_calls(api: &dyn Api) -> Result { diff --git a/contracts/hackatom/tests/integration.rs b/contracts/hackatom/tests/integration.rs index 0035900872..a9dcef713a 100644 --- a/contracts/hackatom/tests/integration.rs +++ b/contracts/hackatom/tests/integration.rs @@ -484,7 +484,7 @@ fn execute_panic() { ); match execute_res.unwrap_err() { VmError::RuntimeErr { msg, .. } => { - assert_eq!(msg, "Wasmer runtime error: RuntimeError: unreachable") + assert_eq!(msg, "Wasmer runtime error: RuntimeError: Aborted: panicked at 'This page intentionally faulted', src/contract.rs:195:5") } err => panic!("Unexpected error: {:?}", err), } From 76e94685cdeafa2828653938b1add01573014d82 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 11 May 2022 20:35:07 +0200 Subject: [PATCH 13/27] Add note to "abort" import --- packages/vm/src/instance.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/vm/src/instance.rs b/packages/vm/src/instance.rs index 9279cde553..c507b055e5 100644 --- a/packages/vm/src/instance.rs +++ b/packages/vm/src/instance.rs @@ -180,6 +180,9 @@ where Function::new_native_with_env(store, env.clone(), do_debug), ); + // Aborts the contract execution with an error message provided by the contract. + // Takes a pointer argument of a memory region that must contain an UTF-8 encoded string. + // Ownership of both input and output pointer is not transferred to the host. env_imports.insert( "abort", Function::new_native_with_env(store, env.clone(), do_abort), From 758138ceafaf4b57bc6ceb2609e9b7ed9bc7b4ed Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 11 May 2022 22:33:41 +0200 Subject: [PATCH 14/27] Make panic error test more stable --- contracts/hackatom/tests/integration.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contracts/hackatom/tests/integration.rs b/contracts/hackatom/tests/integration.rs index a9dcef713a..06d40d8e40 100644 --- a/contracts/hackatom/tests/integration.rs +++ b/contracts/hackatom/tests/integration.rs @@ -484,7 +484,11 @@ fn execute_panic() { ); match execute_res.unwrap_err() { VmError::RuntimeErr { msg, .. } => { - assert_eq!(msg, "Wasmer runtime error: RuntimeError: Aborted: panicked at 'This page intentionally faulted', src/contract.rs:195:5") + assert!( + msg.contains("Aborted: panicked at 'This page intentionally faulted'"), + "Must contain panic message" + ); + assert!(msg.contains("contract.rs:"), "Must contain file and line"); } err => panic!("Unexpected error: {:?}", err), } From 693693c9944d4f85bc217b6ba2de004fa12b4bc9 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 11 May 2022 22:35:51 +0200 Subject: [PATCH 15/27] Add abort feature to std tests --- .circleci/config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c701dafe39..7fbee3bedb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -218,15 +218,15 @@ jobs: - run: name: Build library for native target (all features) working_directory: ~/project/packages/std - command: cargo build --locked --features iterator,staking,stargate + command: cargo build --locked --features abort,iterator,staking,stargate - run: name: Build library for wasm target (all features) working_directory: ~/project/packages/std - command: cargo wasm --locked --features iterator,staking,stargate + command: cargo wasm --locked --features abort,iterator,staking,stargate - run: name: Run unit tests (all features) working_directory: ~/project/packages/std - command: cargo test --locked --features iterator,staking,stargate + command: cargo test --locked --features abort,iterator,staking,stargate - run: name: Build and run schema generator working_directory: ~/project/packages/std @@ -945,7 +945,7 @@ jobs: - run: name: Clippy linting on std (all feature flags) working_directory: ~/project/packages/std - command: cargo clippy --all-targets --features iterator,staking,stargate -- -D warnings + command: cargo clippy --all-targets --features abort,iterator,staking,stargate -- -D warnings - run: name: Clippy linting on storage (no feature flags) working_directory: ~/project/packages/storage From 2eea236c507a42f4ce4c5ad30edd35fcd026f58f Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 11 May 2022 22:43:28 +0200 Subject: [PATCH 16/27] Create CHANGELOG entry --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fa21556e7..9cfb63fdc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,18 @@ and this project adheres to ## [Unreleased] +### Added + +- cosmwasm-std: When the new `abort` feature is enabled, cosmwasm-std installs a + panic handler that aborts the contract and passes the panic message to the + host. The `abort` feature can only be used when deploying to chains that + implement the import. For this reason, it's not yet enabled by default. + ([#1299]) +- cosmwasm-vm: A new import `abort` is created to abort contract execution when + requested by the contract. ([#1299]) + +[#1299]: https://github.com/CosmWasm/cosmwasm/pull/1299 + ## [1.0.0-rc.0] - 2022-05-05 ### Fixed From 3dca0da20f233cfa46178b3f5c9ea836480fe067 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 10 May 2022 22:27:50 +0200 Subject: [PATCH 17/27] Add ibcv3 feature, where connect returns version string --- packages/std/Cargo.toml | 5 ++++- packages/std/src/exports.rs | 9 +++++---- packages/std/src/ibc.rs | 14 ++++++++++++++ packages/std/src/lib.rs | 5 +++-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml index 6092377a57..8e7edf3042 100644 --- a/packages/std/Cargo.toml +++ b/packages/std/Cargo.toml @@ -9,7 +9,7 @@ license = "Apache-2.0" readme = "README.md" [package.metadata.docs.rs] -features = ["stargate", "staking"] +features = ["stargate", "staking", "ibcv3"] [features] default = ["iterator"] @@ -30,6 +30,9 @@ backtraces = [] # stargate enables stargate-dependent messages and queries, like raw protobuf messages # as well as ibc-related functionality stargate = [] +# ibcv3 extends ibc messages with ibcv3 only features. This should only be enabled on contracts +# that require these types. Without this, they get the smaller ibcv1 API. +ibcv3 = ["stargate"] [dependencies] base64 = "0.13.0" diff --git a/packages/std/src/exports.rs b/packages/std/src/exports.rs index b04b89c580..544a85963a 100644 --- a/packages/std/src/exports.rs +++ b/packages/std/src/exports.rs @@ -15,8 +15,9 @@ use serde::de::DeserializeOwned; use crate::deps::OwnedDeps; #[cfg(feature = "stargate")] use crate::ibc::{ - IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcPacketAckMsg, - IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, + IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, + IbcChannelOpenResponse, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, + IbcReceiveResponse, }; use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage}; use crate::memory::{alloc, consume_region, release_buffer, Region}; @@ -238,7 +239,7 @@ where /// - `E`: error type for responses #[cfg(feature = "stargate")] pub fn do_ibc_channel_open( - contract_fn: &dyn Fn(DepsMut, Env, IbcChannelOpenMsg) -> Result<(), E>, + contract_fn: &dyn Fn(DepsMut, Env, IbcChannelOpenMsg) -> Result, env_ptr: u32, msg_ptr: u32, ) -> u32 @@ -514,7 +515,7 @@ where #[cfg(feature = "stargate")] fn _do_ibc_channel_open( - contract_fn: &dyn Fn(DepsMut, Env, IbcChannelOpenMsg) -> Result<(), E>, + contract_fn: &dyn Fn(DepsMut, Env, IbcChannelOpenMsg) -> Result, env_ptr: *mut Region, msg_ptr: *mut Region, ) -> ContractResult<()> diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 11c1973a4a..7b049ce7f0 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -119,6 +119,7 @@ pub struct IbcChannel { pub endpoint: IbcEndpoint, pub counterparty_endpoint: IbcEndpoint, pub order: IbcOrder, + /// Note: in ibcv3 this may be "", in the IbcOpenChannel handshake messages pub version: String, /// The connection upon which this channel was created. If this is a multi-hop /// channel, we only expose the first hop. @@ -296,6 +297,19 @@ impl From for IbcChannel { } } +/// Note that this serializes as "null" +#[cfg(not(feature = "ibcv3"))] +pub type IbcChannelOpenResponse = (); + +/// This serializes as a JSON object, the parser should treat as Option to handle both v1 and v3 +#[cfg(feature = "ibcv3")] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct IbcChannelOpenResponse { + /// We can set the channel version to a different one than we were called with + /// TODO: remove option?? + pub version: Option, +} + /// The message that is passed into `ibc_channel_connect` #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index 6f23bf0fb6..dfae51275f 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -36,8 +36,9 @@ pub use crate::errors::{ #[cfg(feature = "stargate")] pub use crate::ibc::{ IbcAcknowledgement, IbcBasicResponse, IbcChannel, IbcChannelCloseMsg, IbcChannelConnectMsg, - IbcChannelOpenMsg, IbcEndpoint, IbcMsg, IbcOrder, IbcPacket, IbcPacketAckMsg, - IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, IbcTimeout, IbcTimeoutBlock, + IbcChannelOpenMsg, IbcChannelOpenResponse, IbcEndpoint, IbcMsg, IbcOrder, IbcPacket, + IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, IbcTimeout, + IbcTimeoutBlock, }; #[cfg(feature = "iterator")] pub use crate::iterator::{Order, Record}; From 525ae95aa1449e411819109f903972c372070f05 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 10 May 2022 22:35:46 +0200 Subject: [PATCH 18/27] ibcv3: Expose relayer in various IbcPacket***Msg types --- packages/std/src/ibc.rs | 34 +++++++++++++++++++++++++++ packages/std/src/mock.rs | 50 +++++++++++++++++++++++++--------------- 2 files changed, 66 insertions(+), 18 deletions(-) diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 7b049ce7f0..99a058e609 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -6,6 +6,8 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::cmp::{Ord, Ordering, PartialOrd}; +#[cfg(feature = "ibcv3")] +use crate::addresses::Addr; use crate::binary::Binary; use crate::coins::Coin; use crate::errors::StdResult; @@ -405,12 +407,20 @@ impl From for IbcChannel { #[non_exhaustive] pub struct IbcPacketReceiveMsg { pub packet: IbcPacket, + #[cfg(feature = "ibcv3")] + pub relayer: Addr, } impl IbcPacketReceiveMsg { + #[cfg(not(feature = "ibcv3"))] pub fn new(packet: IbcPacket) -> Self { Self { packet } } + + #[cfg(feature = "ibcv3")] + pub fn new(packet: IbcPacket, relayer: Addr) -> Self { + Self { packet, relayer } + } } /// The message that is passed into `ibc_packet_ack` @@ -419,15 +429,31 @@ impl IbcPacketReceiveMsg { pub struct IbcPacketAckMsg { pub acknowledgement: IbcAcknowledgement, pub original_packet: IbcPacket, + #[cfg(feature = "ibcv3")] + pub relayer: Addr, } impl IbcPacketAckMsg { + #[cfg(not(feature = "ibcv3"))] pub fn new(acknowledgement: IbcAcknowledgement, original_packet: IbcPacket) -> Self { Self { acknowledgement, original_packet, } } + + #[cfg(feature = "ibcv3")] + pub fn new( + acknowledgement: IbcAcknowledgement, + original_packet: IbcPacket, + relayer: Addr, + ) -> Self { + Self { + acknowledgement, + original_packet, + relayer, + } + } } /// The message that is passed into `ibc_packet_timeout` @@ -435,12 +461,20 @@ impl IbcPacketAckMsg { #[non_exhaustive] pub struct IbcPacketTimeoutMsg { pub packet: IbcPacket, + #[cfg(feature = "ibcv3")] + pub relayer: Addr, } impl IbcPacketTimeoutMsg { + #[cfg(not(feature = "ibcv3"))] pub fn new(packet: IbcPacket) -> Self { Self { packet } } + + #[cfg(feature = "ibcv3")] + pub fn new(packet: IbcPacket, relayer: Addr) -> Self { + Self { packet, relayer } + } } /// This is the return value for the majority of the ibc handlers. diff --git a/packages/std/src/mock.rs b/packages/std/src/mock.rs index f38e1544c0..ece337e433 100644 --- a/packages/std/src/mock.rs +++ b/packages/std/src/mock.rs @@ -330,23 +330,27 @@ pub fn mock_ibc_packet_recv( my_channel_id: &str, data: &impl Serialize, ) -> StdResult { - Ok(IbcPacketReceiveMsg::new(IbcPacket { - data: to_binary(data)?, - src: IbcEndpoint { - port_id: "their-port".to_string(), - channel_id: "channel-1234".to_string(), - }, - dest: IbcEndpoint { - port_id: "our-port".to_string(), - channel_id: my_channel_id.into(), + Ok(IbcPacketReceiveMsg::new( + IbcPacket { + data: to_binary(data)?, + src: IbcEndpoint { + port_id: "their-port".to_string(), + channel_id: "channel-1234".to_string(), + }, + dest: IbcEndpoint { + port_id: "our-port".to_string(), + channel_id: my_channel_id.into(), + }, + sequence: 27, + timeout: IbcTimeoutBlock { + revision: 1, + height: 12345678, + } + .into(), }, - sequence: 27, - timeout: IbcTimeoutBlock { - revision: 1, - height: 12345678, - } - .into(), - })) + #[cfg(feature = "ibcv3")] + Addr::unchecked("relayer"), + )) } /// Creates a IbcPacket for testing ibc_packet_{ack,timeout}. You set a few key parameters that are @@ -384,7 +388,12 @@ pub fn mock_ibc_packet_ack( ) -> StdResult { let packet = mock_ibc_packet(my_channel_id, data)?; - Ok(IbcPacketAckMsg::new(ack, packet)) + Ok(IbcPacketAckMsg::new( + ack, + packet, + #[cfg(feature = "ibcv3")] + Addr::unchecked("relayer"), + )) } /// Creates a IbcPacketTimeoutMsg for testing ibc_packet_timeout. You set a few key parameters that are @@ -395,7 +404,12 @@ pub fn mock_ibc_packet_timeout( my_channel_id: &str, data: &impl Serialize, ) -> StdResult { - mock_ibc_packet(my_channel_id, data).map(IbcPacketTimeoutMsg::new) + let packet = mock_ibc_packet(my_channel_id, data)?; + Ok(IbcPacketTimeoutMsg::new( + packet, + #[cfg(feature = "ibcv3")] + Addr::unchecked("relayer"), + )) } /// The same type as cosmwasm-std's QuerierResult, but easier to reuse in From 274c12f9375f60ecadea3b50e7ce6d442111ed03 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 10 May 2022 22:49:51 +0200 Subject: [PATCH 19/27] Properly build ibcv3 wasm contract --- contracts/ibc-reflect/Cargo.toml | 4 ++-- contracts/ibc-reflect/src/contract.rs | 25 ++++++++++++++----------- packages/std/src/exports.rs | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/contracts/ibc-reflect/Cargo.toml b/contracts/ibc-reflect/Cargo.toml index 7a9a760a60..0fd398c6c5 100644 --- a/contracts/ibc-reflect/Cargo.toml +++ b/contracts/ibc-reflect/Cargo.toml @@ -32,11 +32,11 @@ cranelift = ["cosmwasm-vm/cranelift"] backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"] [dependencies] -cosmwasm-std = { path = "../../packages/std", features = ["iterator", "staking", "stargate"] } +cosmwasm-std = { path = "../../packages/std", features = ["iterator", "ibcv3"] } cosmwasm-storage = { path = "../../packages/storage", features = ["iterator"] } schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } [dev-dependencies] -cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator", "stargate"] } +cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator", "ibcv3"] } cosmwasm-schema = { path = "../../packages/schema" } diff --git a/contracts/ibc-reflect/src/contract.rs b/contracts/ibc-reflect/src/contract.rs index db2b6d5cb3..f4f3c51f11 100644 --- a/contracts/ibc-reflect/src/contract.rs +++ b/contracts/ibc-reflect/src/contract.rs @@ -1,9 +1,9 @@ use cosmwasm_std::{ entry_point, from_slice, to_binary, wasm_execute, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, Event, IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, - IbcChannelOpenMsg, IbcOrder, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, - IbcReceiveResponse, MessageInfo, Order, QueryResponse, Reply, Response, StdError, StdResult, - SubMsg, SubMsgResponse, SubMsgResult, WasmMsg, + IbcChannelOpenMsg, IbcChannelOpenResponse, IbcOrder, IbcPacketAckMsg, IbcPacketReceiveMsg, + IbcPacketTimeoutMsg, IbcReceiveResponse, MessageInfo, Order, QueryResponse, Reply, Response, + StdError, StdResult, SubMsg, SubMsgResponse, SubMsgResult, WasmMsg, }; use crate::msg::{ @@ -116,19 +116,19 @@ pub fn query_list_accounts(deps: Deps) -> StdResult { #[entry_point] /// enforces ordering and versioing constraints -pub fn ibc_channel_open(_deps: DepsMut, _env: Env, msg: IbcChannelOpenMsg) -> StdResult<()> { +pub fn ibc_channel_open( + _deps: DepsMut, + _env: Env, + msg: IbcChannelOpenMsg, +) -> StdResult { let channel = msg.channel(); if channel.order != IbcOrder::Ordered { return Err(StdError::generic_err("Only supports ordered channels")); } - if channel.version.as_str() != IBC_VERSION { - return Err(StdError::generic_err(format!( - "Must set version to `{}`", - IBC_VERSION - ))); - } + // In ibcv3 we ignore the version string passed in the message + // just check the counterparty message if let Some(counter_version) = msg.counterparty_version() { if counter_version != IBC_VERSION { return Err(StdError::generic_err(format!( @@ -138,7 +138,10 @@ pub fn ibc_channel_open(_deps: DepsMut, _env: Env, msg: IbcChannelOpenMsg) -> St } } - Ok(()) + // and then return what we want + Ok(IbcChannelOpenResponse { + version: Some(IBC_VERSION.to_string()), + }) } #[entry_point] diff --git a/packages/std/src/exports.rs b/packages/std/src/exports.rs index 544a85963a..90f1880da4 100644 --- a/packages/std/src/exports.rs +++ b/packages/std/src/exports.rs @@ -518,7 +518,7 @@ fn _do_ibc_channel_open( contract_fn: &dyn Fn(DepsMut, Env, IbcChannelOpenMsg) -> Result, env_ptr: *mut Region, msg_ptr: *mut Region, -) -> ContractResult<()> +) -> ContractResult where Q: CustomQuery, E: ToString, From 2e7478f5c9e791e060f60628620b251d13d66128 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 10 May 2022 22:55:39 +0200 Subject: [PATCH 20/27] Update cosmwasm-vm to support ibcv3 types --- packages/vm/Cargo.toml | 2 ++ packages/vm/src/calls.rs | 9 +++++---- packages/vm/src/testing/calls.rs | 7 ++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/vm/Cargo.toml b/packages/vm/Cargo.toml index fc98a9c33f..fcf2c254e5 100644 --- a/packages/vm/Cargo.toml +++ b/packages/vm/Cargo.toml @@ -22,6 +22,8 @@ iterator = ["cosmwasm-std/iterator"] staking = ["cosmwasm-std/staking"] # this enables all stargate-related functionality, including the ibc entry points stargate = ["cosmwasm-std/stargate"] +# extend stargate with ibcv3 extra functionality +ibcv3 = ["cosmwasm-std/ibcv3", "stargate"] # Use cranelift backend instead of singlepass. This is required for development on Windows. cranelift = ["wasmer/cranelift"] # It's a bit unclear if interface_version_7 (CosmWasm 0.16) contracts are fully compatible diff --git a/packages/vm/src/calls.rs b/packages/vm/src/calls.rs index 7b2d6dfa2f..0989406376 100644 --- a/packages/vm/src/calls.rs +++ b/packages/vm/src/calls.rs @@ -4,8 +4,9 @@ use wasmer::Val; use cosmwasm_std::{ContractResult, CustomMsg, Env, MessageInfo, QueryResponse, Reply, Response}; #[cfg(feature = "stargate")] use cosmwasm_std::{ - IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcPacketAckMsg, - IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, + IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, + IbcChannelOpenResponse, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, + IbcReceiveResponse, }; use crate::backend::{BackendApi, Querier, Storage}; @@ -218,7 +219,7 @@ pub fn call_ibc_channel_open( instance: &mut Instance, env: &Env, msg: &IbcChannelOpenMsg, -) -> VmResult> +) -> VmResult> where A: BackendApi + 'static, S: Storage + 'static, @@ -227,7 +228,7 @@ where let env = to_vec(env)?; let msg = to_vec(msg)?; let data = call_ibc_channel_open_raw(instance, &env, &msg)?; - let result: ContractResult<()> = + let result: ContractResult = from_slice(&data, deserialization_limits::RESULT_IBC_CHANNEL_OPEN)?; Ok(result) } diff --git a/packages/vm/src/testing/calls.rs b/packages/vm/src/testing/calls.rs index 286241b590..bd3874d623 100644 --- a/packages/vm/src/testing/calls.rs +++ b/packages/vm/src/testing/calls.rs @@ -7,8 +7,9 @@ use serde::{de::DeserializeOwned, Serialize}; use cosmwasm_std::{ContractResult, CustomMsg, Env, MessageInfo, QueryResponse, Reply, Response}; #[cfg(feature = "stargate")] use cosmwasm_std::{ - IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcPacketAckMsg, - IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, + IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, + IbcChannelOpenResponse, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, + IbcReceiveResponse, }; use crate::calls::{ @@ -144,7 +145,7 @@ pub fn ibc_channel_open( instance: &mut Instance, env: Env, msg: IbcChannelOpenMsg, -) -> ContractResult<()> +) -> ContractResult where A: BackendApi + 'static, S: Storage + 'static, From f1b6c4bd6be6c7b014ce022e339725f81ca6d265 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 11 May 2022 10:02:35 +0200 Subject: [PATCH 21/27] Update schema --- contracts/ibc-reflect/schema/packet_msg.json | 157 ------------------- 1 file changed, 157 deletions(-) diff --git a/contracts/ibc-reflect/schema/packet_msg.json b/contracts/ibc-reflect/schema/packet_msg.json index d32112a8b6..1517ce5597 100644 --- a/contracts/ibc-reflect/schema/packet_msg.json +++ b/contracts/ibc-reflect/schema/packet_msg.json @@ -153,30 +153,6 @@ }, "additionalProperties": false }, - { - "type": "object", - "required": [ - "staking" - ], - "properties": { - "staking": { - "$ref": "#/definitions/StakingMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "distribution" - ], - "properties": { - "distribution": { - "$ref": "#/definitions/DistributionMsg" - } - }, - "additionalProperties": false - }, { "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", "type": "object", @@ -240,55 +216,6 @@ } ] }, - "DistributionMsg": { - "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", - "oneOf": [ - { - "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "set_withdraw_address" - ], - "properties": { - "set_withdraw_address": { - "type": "object", - "required": [ - "address" - ], - "properties": { - "address": { - "description": "The `withdraw_address`", - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "withdraw_delegator_reward" - ], - "properties": { - "withdraw_delegator_reward": { - "type": "object", - "required": [ - "validator" - ], - "properties": { - "validator": { - "description": "The `validator_address`", - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, "Empty": { "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", "type": "object" @@ -477,90 +404,6 @@ } } }, - "StakingMsg": { - "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", - "oneOf": [ - { - "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "delegate" - ], - "properties": { - "delegate": { - "type": "object", - "required": [ - "amount", - "validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "undelegate" - ], - "properties": { - "undelegate": { - "type": "object", - "required": [ - "amount", - "validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "redelegate" - ], - "properties": { - "redelegate": { - "type": "object", - "required": [ - "amount", - "dst_validator", - "src_validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "dst_validator": { - "type": "string" - }, - "src_validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, "Timestamp": { "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", "allOf": [ From 3bf67e713fa048bd8f3dcb522993032a1c8d9eca Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 11 May 2022 10:36:18 +0200 Subject: [PATCH 22/27] Unify VM parsing for ibcv3 and ibcv1 into one option struct --- contracts/ibc-reflect/src/contract.rs | 11 ++++++----- packages/std/src/ibc.rs | 9 +++++---- packages/std/src/lib.rs | 2 +- packages/vm/src/calls.rs | 9 ++++----- packages/vm/src/testing/calls.rs | 7 +++---- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/contracts/ibc-reflect/src/contract.rs b/contracts/ibc-reflect/src/contract.rs index f4f3c51f11..037c8b4b47 100644 --- a/contracts/ibc-reflect/src/contract.rs +++ b/contracts/ibc-reflect/src/contract.rs @@ -2,8 +2,9 @@ use cosmwasm_std::{ entry_point, from_slice, to_binary, wasm_execute, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, Event, IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcOrder, IbcPacketAckMsg, IbcPacketReceiveMsg, - IbcPacketTimeoutMsg, IbcReceiveResponse, MessageInfo, Order, QueryResponse, Reply, Response, - StdError, StdResult, SubMsg, SubMsgResponse, SubMsgResult, WasmMsg, + IbcPacketTimeoutMsg, IbcReceiveResponse, IbcV3ChannelOpenResponse, MessageInfo, Order, + QueryResponse, Reply, Response, StdError, StdResult, SubMsg, SubMsgResponse, SubMsgResult, + WasmMsg, }; use crate::msg::{ @@ -139,9 +140,9 @@ pub fn ibc_channel_open( } // and then return what we want - Ok(IbcChannelOpenResponse { - version: Some(IBC_VERSION.to_string()), - }) + Ok(Some(IbcV3ChannelOpenResponse { + version: IBC_VERSION.to_string(), + })) } #[entry_point] diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 99a058e609..0d796fb4b3 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -302,14 +302,15 @@ impl From for IbcChannel { /// Note that this serializes as "null" #[cfg(not(feature = "ibcv3"))] pub type IbcChannelOpenResponse = (); +/// This serializes either as "null" +#[cfg(feature = "ibcv3")] +pub type IbcChannelOpenResponse = Option; /// This serializes as a JSON object, the parser should treat as Option to handle both v1 and v3 -#[cfg(feature = "ibcv3")] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct IbcChannelOpenResponse { +pub struct IbcV3ChannelOpenResponse { /// We can set the channel version to a different one than we were called with - /// TODO: remove option?? - pub version: Option, + pub version: String, } /// The message that is passed into `ibc_channel_connect` diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index dfae51275f..d8cd62c497 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -38,7 +38,7 @@ pub use crate::ibc::{ IbcAcknowledgement, IbcBasicResponse, IbcChannel, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcEndpoint, IbcMsg, IbcOrder, IbcPacket, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, IbcTimeout, - IbcTimeoutBlock, + IbcTimeoutBlock, IbcV3ChannelOpenResponse, }; #[cfg(feature = "iterator")] pub use crate::iterator::{Order, Record}; diff --git a/packages/vm/src/calls.rs b/packages/vm/src/calls.rs index 0989406376..4f22b47482 100644 --- a/packages/vm/src/calls.rs +++ b/packages/vm/src/calls.rs @@ -4,9 +4,8 @@ use wasmer::Val; use cosmwasm_std::{ContractResult, CustomMsg, Env, MessageInfo, QueryResponse, Reply, Response}; #[cfg(feature = "stargate")] use cosmwasm_std::{ - IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, - IbcChannelOpenResponse, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, - IbcReceiveResponse, + IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcPacketAckMsg, + IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, IbcV3ChannelOpenResponse, }; use crate::backend::{BackendApi, Querier, Storage}; @@ -219,7 +218,7 @@ pub fn call_ibc_channel_open( instance: &mut Instance, env: &Env, msg: &IbcChannelOpenMsg, -) -> VmResult> +) -> VmResult>> where A: BackendApi + 'static, S: Storage + 'static, @@ -228,7 +227,7 @@ where let env = to_vec(env)?; let msg = to_vec(msg)?; let data = call_ibc_channel_open_raw(instance, &env, &msg)?; - let result: ContractResult = + let result: ContractResult> = from_slice(&data, deserialization_limits::RESULT_IBC_CHANNEL_OPEN)?; Ok(result) } diff --git a/packages/vm/src/testing/calls.rs b/packages/vm/src/testing/calls.rs index bd3874d623..57deb6f73c 100644 --- a/packages/vm/src/testing/calls.rs +++ b/packages/vm/src/testing/calls.rs @@ -7,9 +7,8 @@ use serde::{de::DeserializeOwned, Serialize}; use cosmwasm_std::{ContractResult, CustomMsg, Env, MessageInfo, QueryResponse, Reply, Response}; #[cfg(feature = "stargate")] use cosmwasm_std::{ - IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, - IbcChannelOpenResponse, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, - IbcReceiveResponse, + IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcPacketAckMsg, + IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, IbcV3ChannelOpenResponse, }; use crate::calls::{ @@ -145,7 +144,7 @@ pub fn ibc_channel_open( instance: &mut Instance, env: Env, msg: IbcChannelOpenMsg, -) -> ContractResult +) -> ContractResult> where A: BackendApi + 'static, S: Storage + 'static, From 02c5138bfc31dd105abe928ab5ca52eddf03eb72 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 12 May 2022 13:30:11 +0200 Subject: [PATCH 23/27] Contract cleanup --- contracts/ibc-reflect-send/src/ibc.rs | 20 ++++++------ .../ibc-reflect-send/tests/integration.rs | 11 ++++--- contracts/ibc-reflect/src/contract.rs | 31 ++++++++++--------- contracts/ibc-reflect/tests/integration.rs | 16 +++++----- packages/std/src/ibc.rs | 5 ++- 5 files changed, 45 insertions(+), 38 deletions(-) diff --git a/contracts/ibc-reflect-send/src/ibc.rs b/contracts/ibc-reflect-send/src/ibc.rs index c6d395a0d3..dca8cbf78c 100644 --- a/contracts/ibc-reflect-send/src/ibc.rs +++ b/contracts/ibc-reflect-send/src/ibc.rs @@ -9,7 +9,7 @@ use crate::ibc_msg::{ }; use crate::state::{accounts, AccountData}; -pub const IBC_VERSION: &str = "ibc-reflect-v1"; +pub const IBC_APP_VERSION: &str = "ibc-reflect-v1"; // TODO: make configurable? /// packets live one hour @@ -23,18 +23,18 @@ pub fn ibc_channel_open(_deps: DepsMut, _env: Env, msg: IbcChannelOpenMsg) -> St if channel.order != IbcOrder::Ordered { return Err(StdError::generic_err("Only supports ordered channels")); } - if channel.version.as_str() != IBC_VERSION { + if channel.version.as_str() != IBC_APP_VERSION { return Err(StdError::generic_err(format!( "Must set version to `{}`", - IBC_VERSION + IBC_APP_VERSION ))); } if let Some(counter_version) = msg.counterparty_version() { - if counter_version != IBC_VERSION { + if counter_version != IBC_APP_VERSION { return Err(StdError::generic_err(format!( "Counterparty version must be `{}`", - IBC_VERSION + IBC_APP_VERSION ))); } } @@ -249,13 +249,14 @@ mod tests { // connect will run through the entire handshake to set up a proper connect and // save the account (tested in detail in `proper_handshake_flow`) fn connect(mut deps: DepsMut, channel_id: &str) { - let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_VERSION); + let handshake_open = + mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); // first we try to open with a valid handshake ibc_channel_open(deps.branch(), mock_env(), handshake_open).unwrap(); // then we connect (with counter-party version set) let handshake_connect = - mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_VERSION); + mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); let res = ibc_channel_connect(deps.branch(), mock_env(), handshake_connect).unwrap(); // this should send a WhoAmI request, which is received some blocks later @@ -284,14 +285,15 @@ mod tests { fn enforce_version_in_handshake() { let mut deps = setup(); - let wrong_order = mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_VERSION); + let wrong_order = + mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_APP_VERSION); ibc_channel_open(deps.as_mut(), mock_env(), wrong_order).unwrap_err(); let wrong_version = mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, "reflect"); ibc_channel_open(deps.as_mut(), mock_env(), wrong_version).unwrap_err(); let valid_handshake = - mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_VERSION); + mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_APP_VERSION); ibc_channel_open(deps.as_mut(), mock_env(), valid_handshake).unwrap(); } diff --git a/contracts/ibc-reflect-send/tests/integration.rs b/contracts/ibc-reflect-send/tests/integration.rs index 79d9860112..c0c2977b83 100644 --- a/contracts/ibc-reflect-send/tests/integration.rs +++ b/contracts/ibc-reflect-send/tests/integration.rs @@ -31,7 +31,7 @@ use cosmwasm_vm::testing::{ }; use cosmwasm_vm::{from_slice, Instance}; -use ibc_reflect_send::ibc::IBC_VERSION; +use ibc_reflect_send::ibc::IBC_APP_VERSION; use ibc_reflect_send::ibc_msg::{AcknowledgementMsg, PacketMsg, WhoAmIResponse}; use ibc_reflect_send::msg::{AccountResponse, AdminResponse, ExecuteMsg, InstantiateMsg, QueryMsg}; @@ -56,13 +56,13 @@ fn setup() -> Instance { // save the account (tested in detail in `proper_handshake_flow`) fn connect(deps: &mut Instance, channel_id: &str) { // open packet has no counterparty version, connect does - let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_VERSION); + let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); // first we try to open with a valid handshake ibc_channel_open(deps, mock_env(), handshake_open).unwrap(); // then we connect (with counter-party version set) let handshake_connect = - mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_VERSION); + mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); let res: IbcBasicResponse = ibc_channel_connect(deps, mock_env(), handshake_connect).unwrap(); // this should send a WhoAmI request, which is received some blocks later @@ -103,13 +103,14 @@ fn instantiate_works() { fn enforce_version_in_handshake() { let mut deps = setup(); - let wrong_order = mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_VERSION); + let wrong_order = mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_APP_VERSION); ibc_channel_open(&mut deps, mock_env(), wrong_order).unwrap_err(); let wrong_version = mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, "reflect"); ibc_channel_open(&mut deps, mock_env(), wrong_version).unwrap_err(); - let valid_handshake = mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_VERSION); + let valid_handshake = + mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_APP_VERSION); ibc_channel_open(&mut deps, mock_env(), valid_handshake).unwrap(); } diff --git a/contracts/ibc-reflect/src/contract.rs b/contracts/ibc-reflect/src/contract.rs index 037c8b4b47..d377e3afea 100644 --- a/contracts/ibc-reflect/src/contract.rs +++ b/contracts/ibc-reflect/src/contract.rs @@ -13,7 +13,7 @@ use crate::msg::{ }; use crate::state::{accounts, accounts_read, config, pending_channel, Config}; -pub const IBC_VERSION: &str = "ibc-reflect-v1"; +pub const IBC_APP_VERSION: &str = "ibc-reflect-v1"; pub const RECEIVE_DISPATCH_ID: u64 = 1234; pub const INIT_CALLBACK_ID: u64 = 7890; @@ -128,20 +128,20 @@ pub fn ibc_channel_open( return Err(StdError::generic_err("Only supports ordered channels")); } - // In ibcv3 we ignore the version string passed in the message - // just check the counterparty message + // In ibcv3 we don't check the version string passed in the message + // and only check the counterparty version. if let Some(counter_version) = msg.counterparty_version() { - if counter_version != IBC_VERSION { + if counter_version != IBC_APP_VERSION { return Err(StdError::generic_err(format!( "Counterparty version must be `{}`", - IBC_VERSION + IBC_APP_VERSION ))); } } - // and then return what we want + // We return the version we need (which could be different than the counterparty version) Ok(Some(IbcV3ChannelOpenResponse { - version: IBC_VERSION.to_string(), + version: IBC_APP_VERSION.to_string(), })) } @@ -369,13 +369,14 @@ mod tests { fn connect(mut deps: DepsMut, channel_id: &str, account: impl Into) { let account: String = account.into(); - let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_VERSION); + let handshake_open = + mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); // first we try to open with a valid handshake ibc_channel_open(deps.branch(), mock_env(), handshake_open).unwrap(); // then we connect (with counter-party version set) let handshake_connect = - mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_VERSION); + mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); let res = ibc_channel_connect(deps.branch(), mock_env(), handshake_connect).unwrap(); assert_eq!(1, res.messages.len()); assert_eq!(1, res.events.len()); @@ -412,14 +413,15 @@ mod tests { fn enforce_version_in_handshake() { let mut deps = setup(); - let wrong_order = mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_VERSION); + let wrong_order = + mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_APP_VERSION); ibc_channel_open(deps.as_mut(), mock_env(), wrong_order).unwrap_err(); let wrong_version = mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, "reflect"); ibc_channel_open(deps.as_mut(), mock_env(), wrong_version).unwrap_err(); let valid_handshake = - mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_VERSION); + mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_APP_VERSION); ibc_channel_open(deps.as_mut(), mock_env(), valid_handshake).unwrap(); } @@ -429,12 +431,13 @@ mod tests { let channel_id = "channel-1234"; // first we try to open with a valid handshake - let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_VERSION); + let handshake_open = + mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); ibc_channel_open(deps.as_mut(), mock_env(), handshake_open).unwrap(); // then we connect (with counter-party version set) let handshake_connect = - mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_VERSION); + mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); let res = ibc_channel_connect(deps.as_mut(), mock_env(), handshake_connect).unwrap(); // and set up a reflect account assert_eq!(1, res.messages.len()); @@ -597,7 +600,7 @@ mod tests { assert_eq!(funds, balance); // close the channel - let channel = mock_ibc_channel_close_init(channel_id, IbcOrder::Ordered, IBC_VERSION); + let channel = mock_ibc_channel_close_init(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); let res = ibc_channel_close(deps.as_mut(), mock_env(), channel).unwrap(); // it pulls out all money from the reflect contract diff --git a/contracts/ibc-reflect/tests/integration.rs b/contracts/ibc-reflect/tests/integration.rs index f1a793ce7c..d28e3369a4 100644 --- a/contracts/ibc-reflect/tests/integration.rs +++ b/contracts/ibc-reflect/tests/integration.rs @@ -31,7 +31,7 @@ use cosmwasm_vm::testing::{ }; use cosmwasm_vm::{from_slice, Instance}; -use ibc_reflect::contract::{IBC_VERSION, RECEIVE_DISPATCH_ID}; +use ibc_reflect::contract::{IBC_APP_VERSION, RECEIVE_DISPATCH_ID}; use ibc_reflect::msg::{ AccountInfo, AccountResponse, AcknowledgementMsg, DispatchResponse, InstantiateMsg, ListAccountsResponse, PacketMsg, QueryMsg, ReflectExecuteMsg, @@ -77,12 +77,12 @@ fn connect( ) { let account: String = account.into(); // first we try to open with a valid handshake - let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_VERSION); + let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); ibc_channel_open(deps, mock_env(), handshake_open).unwrap(); // then we connect (with counter-party version set) let handshake_connect = - mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_VERSION); + mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); let res: IbcBasicResponse = ibc_channel_connect(deps, mock_env(), handshake_connect).unwrap(); assert_eq!(1, res.messages.len()); assert_eq!(1, res.events.len()); @@ -120,13 +120,15 @@ fn instantiate_works() { fn enforce_version_in_handshake() { let mut deps = setup(); - let wrong_order = mock_ibc_channel_open_try("channel-1234", IbcOrder::Unordered, IBC_VERSION); + let wrong_order = + mock_ibc_channel_open_try("channel-1234", IbcOrder::Unordered, IBC_APP_VERSION); ibc_channel_open(&mut deps, mock_env(), wrong_order).unwrap_err(); let wrong_version = mock_ibc_channel_open_try("channel-1234", IbcOrder::Ordered, "reflect"); ibc_channel_open(&mut deps, mock_env(), wrong_version).unwrap_err(); - let valid_handshake = mock_ibc_channel_open_try("channel-1234", IbcOrder::Ordered, IBC_VERSION); + let valid_handshake = + mock_ibc_channel_open_try("channel-1234", IbcOrder::Ordered, IBC_APP_VERSION); ibc_channel_open(&mut deps, mock_env(), valid_handshake).unwrap(); } @@ -136,12 +138,12 @@ fn proper_handshake_flow() { let channel_id = "channel-432"; // first we try to open with a valid handshake - let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_VERSION); + let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); ibc_channel_open(&mut deps, mock_env(), handshake_open).unwrap(); // then we connect (with counter-party version set) let handshake_connect = - mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_VERSION); + mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_APP_VERSION); let res: IbcBasicResponse = ibc_channel_connect(&mut deps, mock_env(), handshake_connect).unwrap(); // and set up a reflect account diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 0d796fb4b3..c648473906 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -299,14 +299,13 @@ impl From for IbcChannel { } } -/// Note that this serializes as "null" +/// Note that this serializes as "null". #[cfg(not(feature = "ibcv3"))] pub type IbcChannelOpenResponse = (); -/// This serializes either as "null" +/// This serializes either as "null" or a JSON object. #[cfg(feature = "ibcv3")] pub type IbcChannelOpenResponse = Option; -/// This serializes as a JSON object, the parser should treat as Option to handle both v1 and v3 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct IbcV3ChannelOpenResponse { /// We can set the channel version to a different one than we were called with From 86a654f0c4ce0fa800e0c8c273a8664ba239c984 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 12 May 2022 13:34:44 +0200 Subject: [PATCH 24/27] Change feature flag to ibc3, no extra feature in vm --- contracts/ibc-reflect/Cargo.toml | 4 ++-- packages/std/Cargo.toml | 8 ++++---- packages/std/src/ibc.rs | 24 ++++++++++++------------ packages/std/src/mock.rs | 6 +++--- packages/vm/Cargo.toml | 4 +--- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/contracts/ibc-reflect/Cargo.toml b/contracts/ibc-reflect/Cargo.toml index 0fd398c6c5..0622414f35 100644 --- a/contracts/ibc-reflect/Cargo.toml +++ b/contracts/ibc-reflect/Cargo.toml @@ -32,11 +32,11 @@ cranelift = ["cosmwasm-vm/cranelift"] backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"] [dependencies] -cosmwasm-std = { path = "../../packages/std", features = ["iterator", "ibcv3"] } +cosmwasm-std = { path = "../../packages/std", features = ["iterator", "ibc3"] } cosmwasm-storage = { path = "../../packages/storage", features = ["iterator"] } schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } [dev-dependencies] -cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator", "ibcv3"] } +cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator", "stargate"] } cosmwasm-schema = { path = "../../packages/schema" } diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml index 8e7edf3042..7893a98046 100644 --- a/packages/std/Cargo.toml +++ b/packages/std/Cargo.toml @@ -9,7 +9,7 @@ license = "Apache-2.0" readme = "README.md" [package.metadata.docs.rs] -features = ["stargate", "staking", "ibcv3"] +features = ["stargate", "staking", "ibc3"] [features] default = ["iterator"] @@ -30,9 +30,9 @@ backtraces = [] # stargate enables stargate-dependent messages and queries, like raw protobuf messages # as well as ibc-related functionality stargate = [] -# ibcv3 extends ibc messages with ibcv3 only features. This should only be enabled on contracts -# that require these types. Without this, they get the smaller ibcv1 API. -ibcv3 = ["stargate"] +# ibc3 extends ibc messages with ibc-v3 only features. This should only be enabled on contracts +# that require these types. Without this, they get the smaller ibc-v1 API. +ibc3 = ["stargate"] [dependencies] base64 = "0.13.0" diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index c648473906..a421e3f195 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -6,7 +6,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::cmp::{Ord, Ordering, PartialOrd}; -#[cfg(feature = "ibcv3")] +#[cfg(feature = "ibc3")] use crate::addresses::Addr; use crate::binary::Binary; use crate::coins::Coin; @@ -300,10 +300,10 @@ impl From for IbcChannel { } /// Note that this serializes as "null". -#[cfg(not(feature = "ibcv3"))] +#[cfg(not(feature = "ibc3"))] pub type IbcChannelOpenResponse = (); /// This serializes either as "null" or a JSON object. -#[cfg(feature = "ibcv3")] +#[cfg(feature = "ibc3")] pub type IbcChannelOpenResponse = Option; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] @@ -407,17 +407,17 @@ impl From for IbcChannel { #[non_exhaustive] pub struct IbcPacketReceiveMsg { pub packet: IbcPacket, - #[cfg(feature = "ibcv3")] + #[cfg(feature = "ibc3")] pub relayer: Addr, } impl IbcPacketReceiveMsg { - #[cfg(not(feature = "ibcv3"))] + #[cfg(not(feature = "ibc3"))] pub fn new(packet: IbcPacket) -> Self { Self { packet } } - #[cfg(feature = "ibcv3")] + #[cfg(feature = "ibc3")] pub fn new(packet: IbcPacket, relayer: Addr) -> Self { Self { packet, relayer } } @@ -429,12 +429,12 @@ impl IbcPacketReceiveMsg { pub struct IbcPacketAckMsg { pub acknowledgement: IbcAcknowledgement, pub original_packet: IbcPacket, - #[cfg(feature = "ibcv3")] + #[cfg(feature = "ibc3")] pub relayer: Addr, } impl IbcPacketAckMsg { - #[cfg(not(feature = "ibcv3"))] + #[cfg(not(feature = "ibc3"))] pub fn new(acknowledgement: IbcAcknowledgement, original_packet: IbcPacket) -> Self { Self { acknowledgement, @@ -442,7 +442,7 @@ impl IbcPacketAckMsg { } } - #[cfg(feature = "ibcv3")] + #[cfg(feature = "ibc3")] pub fn new( acknowledgement: IbcAcknowledgement, original_packet: IbcPacket, @@ -461,17 +461,17 @@ impl IbcPacketAckMsg { #[non_exhaustive] pub struct IbcPacketTimeoutMsg { pub packet: IbcPacket, - #[cfg(feature = "ibcv3")] + #[cfg(feature = "ibc3")] pub relayer: Addr, } impl IbcPacketTimeoutMsg { - #[cfg(not(feature = "ibcv3"))] + #[cfg(not(feature = "ibc3"))] pub fn new(packet: IbcPacket) -> Self { Self { packet } } - #[cfg(feature = "ibcv3")] + #[cfg(feature = "ibc3")] pub fn new(packet: IbcPacket, relayer: Addr) -> Self { Self { packet, relayer } } diff --git a/packages/std/src/mock.rs b/packages/std/src/mock.rs index ece337e433..3b0db5c1c6 100644 --- a/packages/std/src/mock.rs +++ b/packages/std/src/mock.rs @@ -348,7 +348,7 @@ pub fn mock_ibc_packet_recv( } .into(), }, - #[cfg(feature = "ibcv3")] + #[cfg(feature = "ibc3")] Addr::unchecked("relayer"), )) } @@ -391,7 +391,7 @@ pub fn mock_ibc_packet_ack( Ok(IbcPacketAckMsg::new( ack, packet, - #[cfg(feature = "ibcv3")] + #[cfg(feature = "ibc3")] Addr::unchecked("relayer"), )) } @@ -407,7 +407,7 @@ pub fn mock_ibc_packet_timeout( let packet = mock_ibc_packet(my_channel_id, data)?; Ok(IbcPacketTimeoutMsg::new( packet, - #[cfg(feature = "ibcv3")] + #[cfg(feature = "ibc3")] Addr::unchecked("relayer"), )) } diff --git a/packages/vm/Cargo.toml b/packages/vm/Cargo.toml index fcf2c254e5..d606602243 100644 --- a/packages/vm/Cargo.toml +++ b/packages/vm/Cargo.toml @@ -21,9 +21,7 @@ backtraces = [] iterator = ["cosmwasm-std/iterator"] staking = ["cosmwasm-std/staking"] # this enables all stargate-related functionality, including the ibc entry points -stargate = ["cosmwasm-std/stargate"] -# extend stargate with ibcv3 extra functionality -ibcv3 = ["cosmwasm-std/ibcv3", "stargate"] +stargate = ["cosmwasm-std/stargate", "cosmwasm-std/ibc3"] # Use cranelift backend instead of singlepass. This is required for development on Windows. cranelift = ["wasmer/cranelift"] # It's a bit unclear if interface_version_7 (CosmWasm 0.16) contracts are fully compatible From c380f49b55e6476c8434deca1ccf7e276df602cc Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 12 May 2022 15:38:42 +0200 Subject: [PATCH 25/27] Change struct name and add changelog entry --- CHANGELOG.md | 5 +++++ contracts/ibc-reflect/src/contract.rs | 8 ++++---- packages/std/src/ibc.rs | 4 ++-- packages/std/src/lib.rs | 8 ++++---- packages/vm/src/calls.rs | 9 +++++---- packages/vm/src/testing/calls.rs | 7 ++++--- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cfb63fdc3..0711a3955b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,11 @@ and this project adheres to - cosmwasm-std: Implement `Div`/`DivAssign` for `Decimal`/`Decimal256`. - cosmwasm-vm: Add feature `allow_interface_version_7` to run CosmWasm 0.16 contracts in modern hosts. Be careful if you consider using this! +- cosmwasm-std: Add new `ibc3` feature that allows to use IBC-Go V3 features, + like version negotiation and exposing relayer address to the contract. + Requires a compatible wasmd runtime (v0.27.0+) ([#1297]) + +[#1302]: https://github.com/CosmWasm/cosmwasm/pull/1302 ### Changed diff --git a/contracts/ibc-reflect/src/contract.rs b/contracts/ibc-reflect/src/contract.rs index d377e3afea..a43e581461 100644 --- a/contracts/ibc-reflect/src/contract.rs +++ b/contracts/ibc-reflect/src/contract.rs @@ -1,8 +1,8 @@ use cosmwasm_std::{ entry_point, from_slice, to_binary, wasm_execute, BankMsg, Binary, CosmosMsg, Deps, DepsMut, - Empty, Env, Event, IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, - IbcChannelOpenMsg, IbcChannelOpenResponse, IbcOrder, IbcPacketAckMsg, IbcPacketReceiveMsg, - IbcPacketTimeoutMsg, IbcReceiveResponse, IbcV3ChannelOpenResponse, MessageInfo, Order, + Empty, Env, Event, Ibc3ChannelOpenResponse, IbcBasicResponse, IbcChannelCloseMsg, + IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcOrder, IbcPacketAckMsg, + IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, MessageInfo, Order, QueryResponse, Reply, Response, StdError, StdResult, SubMsg, SubMsgResponse, SubMsgResult, WasmMsg, }; @@ -140,7 +140,7 @@ pub fn ibc_channel_open( } // We return the version we need (which could be different than the counterparty version) - Ok(Some(IbcV3ChannelOpenResponse { + Ok(Some(Ibc3ChannelOpenResponse { version: IBC_APP_VERSION.to_string(), })) } diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index a421e3f195..8f2505a4ec 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -304,10 +304,10 @@ impl From for IbcChannel { pub type IbcChannelOpenResponse = (); /// This serializes either as "null" or a JSON object. #[cfg(feature = "ibc3")] -pub type IbcChannelOpenResponse = Option; +pub type IbcChannelOpenResponse = Option; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct IbcV3ChannelOpenResponse { +pub struct Ibc3ChannelOpenResponse { /// We can set the channel version to a different one than we were called with pub version: String, } diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index d8cd62c497..b3072e677b 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -35,10 +35,10 @@ pub use crate::errors::{ }; #[cfg(feature = "stargate")] pub use crate::ibc::{ - IbcAcknowledgement, IbcBasicResponse, IbcChannel, IbcChannelCloseMsg, IbcChannelConnectMsg, - IbcChannelOpenMsg, IbcChannelOpenResponse, IbcEndpoint, IbcMsg, IbcOrder, IbcPacket, - IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, IbcTimeout, - IbcTimeoutBlock, IbcV3ChannelOpenResponse, + Ibc3ChannelOpenResponse, IbcAcknowledgement, IbcBasicResponse, IbcChannel, IbcChannelCloseMsg, + IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcEndpoint, IbcMsg, IbcOrder, + IbcPacket, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, + IbcTimeout, IbcTimeoutBlock, }; #[cfg(feature = "iterator")] pub use crate::iterator::{Order, Record}; diff --git a/packages/vm/src/calls.rs b/packages/vm/src/calls.rs index 4f22b47482..55ec230e5f 100644 --- a/packages/vm/src/calls.rs +++ b/packages/vm/src/calls.rs @@ -4,8 +4,9 @@ use wasmer::Val; use cosmwasm_std::{ContractResult, CustomMsg, Env, MessageInfo, QueryResponse, Reply, Response}; #[cfg(feature = "stargate")] use cosmwasm_std::{ - IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcPacketAckMsg, - IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, IbcV3ChannelOpenResponse, + Ibc3ChannelOpenResponse, IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, + IbcChannelOpenMsg, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, + IbcReceiveResponse, }; use crate::backend::{BackendApi, Querier, Storage}; @@ -218,7 +219,7 @@ pub fn call_ibc_channel_open( instance: &mut Instance, env: &Env, msg: &IbcChannelOpenMsg, -) -> VmResult>> +) -> VmResult>> where A: BackendApi + 'static, S: Storage + 'static, @@ -227,7 +228,7 @@ where let env = to_vec(env)?; let msg = to_vec(msg)?; let data = call_ibc_channel_open_raw(instance, &env, &msg)?; - let result: ContractResult> = + let result: ContractResult> = from_slice(&data, deserialization_limits::RESULT_IBC_CHANNEL_OPEN)?; Ok(result) } diff --git a/packages/vm/src/testing/calls.rs b/packages/vm/src/testing/calls.rs index 57deb6f73c..4c11640ed9 100644 --- a/packages/vm/src/testing/calls.rs +++ b/packages/vm/src/testing/calls.rs @@ -7,8 +7,9 @@ use serde::{de::DeserializeOwned, Serialize}; use cosmwasm_std::{ContractResult, CustomMsg, Env, MessageInfo, QueryResponse, Reply, Response}; #[cfg(feature = "stargate")] use cosmwasm_std::{ - IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcPacketAckMsg, - IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, IbcV3ChannelOpenResponse, + Ibc3ChannelOpenResponse, IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, + IbcChannelOpenMsg, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, + IbcReceiveResponse, }; use crate::calls::{ @@ -144,7 +145,7 @@ pub fn ibc_channel_open( instance: &mut Instance, env: Env, msg: IbcChannelOpenMsg, -) -> ContractResult> +) -> ContractResult> where A: BackendApi + 'static, S: Storage + 'static, From ada176ffe6230dd62f528cb8a1f9c071d092ec80 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 12 May 2022 17:28:39 +0200 Subject: [PATCH 26/27] Move changelog entry to Unreleased section --- CHANGELOG.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0711a3955b..0028a4fa0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,12 @@ and this project adheres to ([#1299]) - cosmwasm-vm: A new import `abort` is created to abort contract execution when requested by the contract. ([#1299]) +- cosmwasm-std: Add new `ibc3` feature that allows to use IBC-Go V3 features, + like version negotiation and exposing relayer address to the contract. + Requires a compatible wasmd runtime (v0.27.0+) ([#1302]) [#1299]: https://github.com/CosmWasm/cosmwasm/pull/1299 +[#1302]: https://github.com/CosmWasm/cosmwasm/pull/1302 ## [1.0.0-rc.0] - 2022-05-05 @@ -35,11 +39,6 @@ and this project adheres to - cosmwasm-std: Implement `Div`/`DivAssign` for `Decimal`/`Decimal256`. - cosmwasm-vm: Add feature `allow_interface_version_7` to run CosmWasm 0.16 contracts in modern hosts. Be careful if you consider using this! -- cosmwasm-std: Add new `ibc3` feature that allows to use IBC-Go V3 features, - like version negotiation and exposing relayer address to the contract. - Requires a compatible wasmd runtime (v0.27.0+) ([#1297]) - -[#1302]: https://github.com/CosmWasm/cosmwasm/pull/1302 ### Changed From a776d9a19bbfd4af49f81105e764b93de634d904 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 14 May 2022 10:29:17 +0200 Subject: [PATCH 27/27] Set version: 1.0.0 --- CHANGELOG.md | 4 ++++ Cargo.lock | 12 ++++++------ MIGRATING.md | 8 +++++--- contracts/burner/Cargo.lock | 10 +++++----- contracts/crypto-verify/Cargo.lock | 12 ++++++------ contracts/floaty/Cargo.lock | 12 ++++++------ contracts/hackatom/Cargo.lock | 12 ++++++------ contracts/ibc-reflect-send/Cargo.lock | 12 ++++++------ contracts/ibc-reflect/Cargo.lock | 12 ++++++------ contracts/queue/Cargo.lock | 10 +++++----- contracts/reflect/Cargo.lock | 12 ++++++------ contracts/staking/Cargo.lock | 12 ++++++------ packages/crypto/Cargo.toml | 2 +- packages/derive/Cargo.toml | 2 +- packages/schema/Cargo.toml | 2 +- packages/std/Cargo.toml | 6 +++--- packages/storage/Cargo.toml | 4 ++-- packages/vm/Cargo.toml | 6 +++--- 18 files changed, 78 insertions(+), 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0028a4fa0c..2d31802c44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,11 @@ and this project adheres to ## [Unreleased] +## [1.0.0] - 2022-05-14 + ### Added +- cosmwasm-std: Export `DelegationResponse` ([#1301]). - cosmwasm-std: When the new `abort` feature is enabled, cosmwasm-std installs a panic handler that aborts the contract and passes the panic message to the host. The `abort` feature can only be used when deploying to chains that @@ -20,6 +23,7 @@ and this project adheres to Requires a compatible wasmd runtime (v0.27.0+) ([#1302]) [#1299]: https://github.com/CosmWasm/cosmwasm/pull/1299 +[#1301]: https://github.com/CosmWasm/cosmwasm/pull/1301 [#1302]: https://github.com/CosmWasm/cosmwasm/pull/1302 ## [1.0.0-rc.0] - 2022-05-05 diff --git a/Cargo.lock b/Cargo.lock index 3d6dc2cb7e..3b81566731 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -242,7 +242,7 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "cosmwasm-crypto" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "base64", "criterion", @@ -261,7 +261,7 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "cosmwasm-std", "syn", @@ -284,7 +284,7 @@ dependencies = [ [[package]] name = "cosmwasm-schema" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "schemars", "serde_json", @@ -292,7 +292,7 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "base64", "chrono", @@ -311,7 +311,7 @@ dependencies = [ [[package]] name = "cosmwasm-storage" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "cosmwasm-std", "serde", @@ -319,7 +319,7 @@ dependencies = [ [[package]] name = "cosmwasm-vm" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "clap", "clru", diff --git a/MIGRATING.md b/MIGRATING.md index 9fc6acea5a..335b034ad8 100644 --- a/MIGRATING.md +++ b/MIGRATING.md @@ -4,10 +4,12 @@ This guide explains what is needed to upgrade contracts when migrating over major releases of `cosmwasm`. Note that you can also view the [complete CHANGELOG](./CHANGELOG.md) to understand the differences. -## 1.0.0-beta -> 1.0.0 (unreleased) +## 1.0.0-beta -> 1.0.0 -- The minimum Rust supported version is 1.54.0. Verify your Rust version is >= - 1.54.0 with: `rustc --version`. +- The minimum Rust supported version is 1.56.1. Verify your Rust version is >= + 1.56.1 with: `rustc --version`. Please note that the required Rust version + changes over time and we have little control over that due to the dependencies + that are used. - Simplify `mock_dependencies` calls with empty balance: diff --git a/contracts/burner/Cargo.lock b/contracts/burner/Cargo.lock index bcfd3f658d..1483697b83 100644 --- a/contracts/burner/Cargo.lock +++ b/contracts/burner/Cargo.lock @@ -152,7 +152,7 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "cosmwasm-crypto" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "digest", "ed25519-zebra", @@ -163,14 +163,14 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "syn", ] [[package]] name = "cosmwasm-schema" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "schemars", "serde_json", @@ -178,7 +178,7 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "base64", "cosmwasm-crypto", @@ -193,7 +193,7 @@ dependencies = [ [[package]] name = "cosmwasm-vm" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "clru", "cosmwasm-crypto", diff --git a/contracts/crypto-verify/Cargo.lock b/contracts/crypto-verify/Cargo.lock index 9d9e08296c..cc6ba28579 100644 --- a/contracts/crypto-verify/Cargo.lock +++ b/contracts/crypto-verify/Cargo.lock @@ -154,7 +154,7 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "cosmwasm-crypto" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "digest", "ed25519-zebra", @@ -165,14 +165,14 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "syn", ] [[package]] name = "cosmwasm-schema" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "schemars", "serde_json", @@ -180,7 +180,7 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "base64", "cosmwasm-crypto", @@ -195,7 +195,7 @@ dependencies = [ [[package]] name = "cosmwasm-storage" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "cosmwasm-std", "serde", @@ -203,7 +203,7 @@ dependencies = [ [[package]] name = "cosmwasm-vm" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "clru", "cosmwasm-crypto", diff --git a/contracts/floaty/Cargo.lock b/contracts/floaty/Cargo.lock index 382e2bcc70..14447bbd5c 100644 --- a/contracts/floaty/Cargo.lock +++ b/contracts/floaty/Cargo.lock @@ -141,7 +141,7 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "cosmwasm-crypto" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "digest", "ed25519-zebra", @@ -152,14 +152,14 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "syn", ] [[package]] name = "cosmwasm-schema" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "schemars", "serde_json", @@ -167,7 +167,7 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "base64", "cosmwasm-crypto", @@ -182,7 +182,7 @@ dependencies = [ [[package]] name = "cosmwasm-storage" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "cosmwasm-std", "serde", @@ -190,7 +190,7 @@ dependencies = [ [[package]] name = "cosmwasm-vm" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "clru", "cosmwasm-crypto", diff --git a/contracts/hackatom/Cargo.lock b/contracts/hackatom/Cargo.lock index cef78ba2c9..0c0ef23ff8 100644 --- a/contracts/hackatom/Cargo.lock +++ b/contracts/hackatom/Cargo.lock @@ -170,7 +170,7 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "cosmwasm-crypto" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "digest", "ed25519-zebra", @@ -181,14 +181,14 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "syn", ] [[package]] name = "cosmwasm-schema" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "schemars", "serde_json", @@ -196,7 +196,7 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "base64", "cosmwasm-crypto", @@ -211,7 +211,7 @@ dependencies = [ [[package]] name = "cosmwasm-storage" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "cosmwasm-std", "serde", @@ -219,7 +219,7 @@ dependencies = [ [[package]] name = "cosmwasm-vm" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "clru", "cosmwasm-crypto", diff --git a/contracts/ibc-reflect-send/Cargo.lock b/contracts/ibc-reflect-send/Cargo.lock index e846450cba..f2cb138d08 100644 --- a/contracts/ibc-reflect-send/Cargo.lock +++ b/contracts/ibc-reflect-send/Cargo.lock @@ -141,7 +141,7 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "cosmwasm-crypto" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "digest", "ed25519-zebra", @@ -152,14 +152,14 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "syn", ] [[package]] name = "cosmwasm-schema" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "schemars", "serde_json", @@ -167,7 +167,7 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "base64", "cosmwasm-crypto", @@ -182,7 +182,7 @@ dependencies = [ [[package]] name = "cosmwasm-storage" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "cosmwasm-std", "serde", @@ -190,7 +190,7 @@ dependencies = [ [[package]] name = "cosmwasm-vm" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "clru", "cosmwasm-crypto", diff --git a/contracts/ibc-reflect/Cargo.lock b/contracts/ibc-reflect/Cargo.lock index fe3d2dfa13..5385c885d1 100644 --- a/contracts/ibc-reflect/Cargo.lock +++ b/contracts/ibc-reflect/Cargo.lock @@ -141,7 +141,7 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "cosmwasm-crypto" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "digest", "ed25519-zebra", @@ -152,14 +152,14 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "syn", ] [[package]] name = "cosmwasm-schema" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "schemars", "serde_json", @@ -167,7 +167,7 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "base64", "cosmwasm-crypto", @@ -182,7 +182,7 @@ dependencies = [ [[package]] name = "cosmwasm-storage" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "cosmwasm-std", "serde", @@ -190,7 +190,7 @@ dependencies = [ [[package]] name = "cosmwasm-vm" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "clru", "cosmwasm-crypto", diff --git a/contracts/queue/Cargo.lock b/contracts/queue/Cargo.lock index d7b8b89704..fbcb7239be 100644 --- a/contracts/queue/Cargo.lock +++ b/contracts/queue/Cargo.lock @@ -141,7 +141,7 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "cosmwasm-crypto" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "digest", "ed25519-zebra", @@ -152,14 +152,14 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "syn", ] [[package]] name = "cosmwasm-schema" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "schemars", "serde_json", @@ -167,7 +167,7 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "base64", "cosmwasm-crypto", @@ -182,7 +182,7 @@ dependencies = [ [[package]] name = "cosmwasm-vm" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "clru", "cosmwasm-crypto", diff --git a/contracts/reflect/Cargo.lock b/contracts/reflect/Cargo.lock index 5f3ac9b374..95d7f4f142 100644 --- a/contracts/reflect/Cargo.lock +++ b/contracts/reflect/Cargo.lock @@ -141,7 +141,7 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "cosmwasm-crypto" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "digest", "ed25519-zebra", @@ -152,14 +152,14 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "syn", ] [[package]] name = "cosmwasm-schema" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "schemars", "serde_json", @@ -167,7 +167,7 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "base64", "cosmwasm-crypto", @@ -182,7 +182,7 @@ dependencies = [ [[package]] name = "cosmwasm-storage" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "cosmwasm-std", "serde", @@ -190,7 +190,7 @@ dependencies = [ [[package]] name = "cosmwasm-vm" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "clru", "cosmwasm-crypto", diff --git a/contracts/staking/Cargo.lock b/contracts/staking/Cargo.lock index f8fc2f561e..2d30056b3d 100644 --- a/contracts/staking/Cargo.lock +++ b/contracts/staking/Cargo.lock @@ -141,7 +141,7 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "cosmwasm-crypto" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "digest", "ed25519-zebra", @@ -152,14 +152,14 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "syn", ] [[package]] name = "cosmwasm-schema" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "schemars", "serde_json", @@ -167,7 +167,7 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "base64", "cosmwasm-crypto", @@ -182,7 +182,7 @@ dependencies = [ [[package]] name = "cosmwasm-storage" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "cosmwasm-std", "serde", @@ -190,7 +190,7 @@ dependencies = [ [[package]] name = "cosmwasm-vm" -version = "1.0.0-rc.0" +version = "1.0.0" dependencies = [ "clru", "cosmwasm-crypto", diff --git a/packages/crypto/Cargo.toml b/packages/crypto/Cargo.toml index 4cbe1679ad..2645aabcd4 100644 --- a/packages/crypto/Cargo.toml +++ b/packages/crypto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cosmwasm-crypto" -version = "1.0.0-rc.0" +version = "1.0.0" authors = ["Mauro Lacy "] edition = "2021" description = "Crypto bindings for cosmwasm contracts" diff --git a/packages/derive/Cargo.toml b/packages/derive/Cargo.toml index aff3ef50b6..e39bd6296b 100644 --- a/packages/derive/Cargo.toml +++ b/packages/derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cosmwasm-derive" -version = "1.0.0-rc.0" +version = "1.0.0" authors = ["Simon Warta "] edition = "2021" description = "A package for auto-generated code used for CosmWasm contract development. This is shipped as part of cosmwasm-std. Do not use directly." diff --git a/packages/schema/Cargo.toml b/packages/schema/Cargo.toml index c49e096228..39757d8cf0 100644 --- a/packages/schema/Cargo.toml +++ b/packages/schema/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cosmwasm-schema" -version = "1.0.0-rc.0" +version = "1.0.0" authors = ["Simon Warta ", "Ethan Frey "] edition = "2021" description = "A dev-dependency for CosmWasm contracts to generate JSON Schema files." diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml index 7893a98046..5c5f99f62e 100644 --- a/packages/std/Cargo.toml +++ b/packages/std/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cosmwasm-std" -version = "1.0.0-rc.0" +version = "1.0.0" authors = ["Ethan Frey "] edition = "2021" description = "Standard library for Wasm based smart contracts on Cosmos blockchains" @@ -36,7 +36,7 @@ ibc3 = ["stargate"] [dependencies] base64 = "0.13.0" -cosmwasm-derive = { path = "../derive", version = "1.0.0-rc.0" } +cosmwasm-derive = { path = "../derive", version = "1.0.0" } uint = "0.9.3" serde-json-wasm = { version = "0.4.1" } schemars = "0.8.1" @@ -45,7 +45,7 @@ thiserror = "1.0" forward_ref = "1" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -cosmwasm-crypto = { path = "../crypto", version = "1.0.0-rc.0" } +cosmwasm-crypto = { path = "../crypto", version = "1.0.0" } [dev-dependencies] cosmwasm-schema = { path = "../schema" } diff --git a/packages/storage/Cargo.toml b/packages/storage/Cargo.toml index 8fe2832614..f695237284 100644 --- a/packages/storage/Cargo.toml +++ b/packages/storage/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cosmwasm-storage" -version = "1.0.0-rc.0" +version = "1.0.0" authors = ["Ethan Frey "] edition = "2021" description = "CosmWasm library with useful helpers for Storage patterns" @@ -16,5 +16,5 @@ iterator = ["cosmwasm-std/iterator"] [dependencies] # Uses the path when built locally; uses the given version from crates.io when published -cosmwasm-std = { path = "../std", version = "1.0.0-rc.0", default-features = false } +cosmwasm-std = { path = "../std", version = "1.0.0", default-features = false } serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] } diff --git a/packages/vm/Cargo.toml b/packages/vm/Cargo.toml index d606602243..42d8f8a92d 100644 --- a/packages/vm/Cargo.toml +++ b/packages/vm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cosmwasm-vm" -version = "1.0.0-rc.0" +version = "1.0.0" authors = ["Ethan Frey "] edition = "2021" description = "VM bindings to run cosmwams contracts" @@ -41,8 +41,8 @@ required-features = ["iterator"] [dependencies] clru = "0.4.0" # Uses the path when built locally; uses the given version from crates.io when published -cosmwasm-std = { path = "../std", version = "1.0.0-rc.0", default-features = false } -cosmwasm-crypto = { path = "../crypto", version = "1.0.0-rc.0" } +cosmwasm-std = { path = "../std", version = "1.0.0", default-features = false } +cosmwasm-crypto = { path = "../crypto", version = "1.0.0" } hex = "0.4" parity-wasm = "0.42" schemars = "0.8.1"