Skip to content

Commit

Permalink
fixed f32/f64 issue in cosmwasm contracts validation (#4003)
Browse files Browse the repository at this point in the history
Some explanation is here informalsystems/ibc-rs#803

So wasmd validation in cosmos will not find reference to code (which
never executes) it fails like floats anymore and will success upload.
Any attempt to strip float code failed (likely it anticipates input
which may contain floats in some case, which is not case to handle at
all).

Also had hard times with std because of centauri repo, added CI checks
to ensure we always good.

May be fixes #3952 too.

Required for merge:
- [x] `pr-workflow-check / draft-release-check` is ✅ success
- Other rules GitHub shows you, or can be read in
[configuration](../terraform/github.com/branches.tf)

Makes review faster:
- [x] PR title is my best effort to provide summary of changes and has
clear text to be part of release notes
- [x] I marked PR by `misc` label if it should not be in release notes
- [x] Linked Zenhub/Github/Slack/etc reference if one exists
- [x] I was clear on what type of deployment required to release my
changes (node, runtime, contract, indexer, on chain operation, frontend,
infrastructure) if any in PR title or description
- [x] Added reviewer into `Reviewers`
- [x] I tagged(`@`) or used other form of notification of one person who
I think can handle best review of this PR
- [x] I have proved that PR has no general regressions of relevant
features and processes required to release into production
- [x] Any dependency updates made, was done according guides from
relevant dependency
- Clicking all checkboxes 
- Adding detailed description of changes when it feels appropriate (for
example when PR is big)
  • Loading branch information
dzmitry-lahoda authored Aug 1, 2023
1 parent 45b3587 commit 7a9975d
Show file tree
Hide file tree
Showing 34 changed files with 383 additions and 278 deletions.
198 changes: 129 additions & 69 deletions code/Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,11 @@ orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-modu
orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "a0751540591c88ccc2d4029464de887933727183", default-features = false }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "a0751540591c88ccc2d4029464de887933727183", default-features = false }

ibc = { git = "https://github.com/ComposableFi/centauri", rev = "fd0a4911d86a531513547bbcc1f98df0a276fa79", default-features = false }
ibc-rpc = { git = "https://github.com/ComposableFi/centauri", rev = "fd0a4911d86a531513547bbcc1f98df0a276fa79", default-features = false }
ibc-primitives = { git = "https://github.com/ComposableFi/centauri", rev = "fd0a4911d86a531513547bbcc1f98df0a276fa79", default-features = false }
ibc-runtime-api = { git = "https://github.com/ComposableFi/centauri", rev = "fd0a4911d86a531513547bbcc1f98df0a276fa79", default-features = false }
pallet-ibc = { git = "https://github.com/ComposableFi/centauri", rev = "fd0a4911d86a531513547bbcc1f98df0a276fa79", default-features = false }
pallet-ibc-ping = { git = "https://github.com/ComposableFi/centauri", rev = "fd0a4911d86a531513547bbcc1f98df0a276fa79", default-features = false }
ibc = { git = "https://github.com/ComposableFi/centauri", rev = "ae2730ecb7ac0aee674cc06e7fa039f3766fd933", default-features = false }
ibc-rpc = { git = "https://github.com/ComposableFi/centauri", rev = "ae2730ecb7ac0aee674cc06e7fa039f3766fd933", default-features = false }
ibc-primitives = { git = "https://github.com/ComposableFi/centauri", rev = "ae2730ecb7ac0aee674cc06e7fa039f3766fd933", default-features = false }
ibc-runtime-api = { git = "https://github.com/ComposableFi/centauri", rev = "ae2730ecb7ac0aee674cc06e7fa039f3766fd933", default-features = false }
pallet-ibc = { git = "https://github.com/ComposableFi/centauri", rev = "ae2730ecb7ac0aee674cc06e7fa039f3766fd933", default-features = false }

xcm-builder = { git = "https://github.com/paritytech/polkadot", rev = "c22e1c4173bf6966f5d1980f4299f7abe836f0c1", default-features = false }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", rev = "c22e1c4173bf6966f5d1980f4299f7abe836f0c1", default-features = false }
Expand All @@ -134,7 +133,7 @@ pallet-xcm = { git = "https://github.com/paritytech/polkadot", rev = "c22e1c4173

log = { version = "0.4.14", default-features = false }

ibc-rs-scale = { package = "ibc", git = "https://github.com/dzmitry-lahoda-forks/ibc-rs.git", rev = "3589353927cef8a52f610d842bd0f5ab8a2e1a1e", default-features = false }
ibc-rs-scale = { package = "ibc", git = "https://github.com/dzmitry-lahoda-forks/ibc-rs.git", rev = "c305fb9a7f3750e6daa0d9aefa84d53d64cd4fee", default-features = false }
democracy = { package = "pallet-democracy", git = "https://github.com/ComposableFi/substrate", rev = "c74d73bfe1e4f725b3f7d81c997ba9c940bf6005", default-features = false }
executive = { package = "frame-executive", git = "https://github.com/ComposableFi/substrate", rev = "c74d73bfe1e4f725b3f7d81c997ba9c940bf6005", default-features = false }
indices = { package = "pallet-indices", git = "https://github.com/ComposableFi/substrate", rev = "c74d73bfe1e4f725b3f7d81c997ba9c940bf6005", default-features = false }
Expand Down Expand Up @@ -352,6 +351,7 @@ cosmwasm-vm = { git = "https://github.com/ComposableFi/cosmwasm-vm", rev = "1cc4
cosmwasm-vm-wasmi = { git = "https://github.com/ComposableFi/cosmwasm-vm", rev = "1cc47415577d67448ff483ad530b889cceafde77", default-features = false }
cosmwasm-orchestrate = { git = "https://github.com/ComposableFi/cosmwasm-vm", rev = "1cc47415577d67448ff483ad530b889cceafde77" }
serde-json-wasm = { git = "https://github.com/dzmitry-lahoda-forks/serde-json-wasm", rev = "8a7e522c0e4de36a6dfb535766f26a9941017d81", default-features = false }
serde-cw-value = { git = "https://github.com/dzmitry-lahoda-forks/serde-cw-value", rev = "fe16466caee886908645de5a8e0518dbac6d98df", default-features = false }
cw-storage-plus = { git = "https://github.com/dzmitry-lahoda-forks/cw-storage-plus", rev = "d0a2cf126cae3e3960c787ebcfc9baa54f59f71c", default-features = false }
cosmwasm-schema = { git = "https://github.com/dzmitry-lahoda-forks/cosmwasm", rev = "1277597cbf380a8d04dbe676d9cb344ca31634b6", default-features = false}
cw-utils = { git = "https://github.com/dzmitry-lahoda-forks/cw-plus", rev = "458e2eb014253d2131219e518c64475a8348c5a3", default-features = false}
Expand Down
27 changes: 12 additions & 15 deletions code/parachain/frame/composable-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ plotters = { version = "0.3.1", optional = true }
scale-info = { version = "2.1.1", default-features = false, features = [
"derive",
] }
serde = { workspace = true, default-features = false }
pallet-ibc = { workspace = true, default-features = false }

cosmwasm-std = { workspace = true, default-features = false, features = [
Expand All @@ -38,10 +37,7 @@ cosmwasm-std = { workspace = true, default-features = false, features = [
"stargate",
] }

serde_json = { workspace = true, default-features = false, features = [
"alloc",
] }

serde = { workspace = true, default-features = false, features = ["alloc"]}

sha2 = { workspace = true, default-features = false }

Expand All @@ -51,38 +47,39 @@ cosmwasm-schema = { workspace = true, default-features = false, optional = true}

thiserror = { workspace = true, default-features = false }

[dev-dependencies]
proptest = { version = "1.0.0" }

[dependencies.codec]
default-features = false
features = ["derive"]
package = "parity-scale-codec"
version = "3.0.0"

[dev-dependencies]
proptest = { version = "1.0.0" }

[features]
default = ["std"]
default = ["std", "centauri"]
std = [
"codec/std",
"composable-support/std",
"cosmwasm-schema",
"cosmwasm-std/std",
"frame-support/std",
"frame-system/std",
"serde_json/std",
"pallet-ibc/std",
"polkadot-parachain/std",
"proxy/std",
"scale-info/std",
"schemars",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"xcm/std",
"xc-core/std",
"cosmwasm-std/std",
"pallet-ibc/std",
"cosmwasm-schema",
"schemars",
"xcm/std",
]
test-utils = []
visualization = ["plotters"]
centauri = []

[package.metadata.cargo-udeps.ignore]
normal = ["plotters"]
normal = ["plotters"]
2 changes: 1 addition & 1 deletion code/parachain/frame/composable-traits/src/centauri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Map {
channel: value.channel.map(|x| x.to_string()),
timeout: value.timeout,
retries: value.retries.map(Into::into),
para_id: value.substrate.map(|x| x.para_id).flatten(),
para_id: value.substrate.and_then(|x| x.para_id),
substrate: value.substrate.map(|_| true),
next,
};
Expand Down
1 change: 1 addition & 0 deletions code/parachain/frame/composable-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod airdrop;
pub mod assets;
pub mod bonded_finance;
pub mod bounded;
#[cfg(feature = "centauri")]
pub mod centauri;
pub mod cosmwasm;
pub mod currency;
Expand Down
4 changes: 2 additions & 2 deletions code/parachain/frame/cosmwasm/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl<T: Config + Send + Sync> IbcModule for Router<T> {
) -> Result<(), IbcError> {
let address = Self::port_to_address(port_id)?;

let message = ibc_to_cw_channel_open::<T>(
let message = ibc_to_cw_channel_open(
channel_id,
port_id,
counterparty,
Expand Down Expand Up @@ -475,7 +475,7 @@ impl<T: Config + Send + Sync> IbcModule for Router<T> {
) -> Result<IbcVersion, IbcError> {
let address = Self::port_to_address(port_id)?;

let message = ibc_open_try_to_cw_open::<T>(
let message = ibc_open_try_to_cw_open(
channel_id,
port_id,
counterparty,
Expand Down
4 changes: 2 additions & 2 deletions code/parachain/frame/cosmwasm/src/instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn calculate_weight<T: Config>(weight_fn: WeightFn, n_additional_instrs: u32) ->

/// Calculates a weight that is dependent on other weight. Eg. `else` because it cannot
/// exist without an `if`
fn calculate_weight_custom<T: Config>(weight_fn: WeightFn, custom_fn: WeightFn) -> u32 {
fn calculate_weight_custom(weight_fn: WeightFn, custom_fn: WeightFn) -> u32 {
(weight_fn(1)
.saturating_sub(weight_fn(0))
.saturating_sub(custom_fn(1).saturating_sub(custom_fn(0)).saturating_div(2)))
Expand Down Expand Up @@ -204,7 +204,7 @@ impl<T: Config> Default for CostRules<T> {
f64copysign: calculate_weight::<T>(T::WeightInfo::instruction_F64Copysign, 3),
select: calculate_weight::<T>(T::WeightInfo::instruction_Select, 4),
if_: calculate_weight::<T>(T::WeightInfo::instruction_If, 2),
else_: calculate_weight_custom::<T>(
else_: calculate_weight_custom(
T::WeightInfo::instruction_Else,
T::WeightInfo::instruction_If,
),
Expand Down
38 changes: 19 additions & 19 deletions code/parachain/frame/cosmwasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@ impl<T: Config> Pallet<T> {

/// Read an entry from the executing contract storage, charging the according gas prior to
/// actually reading the entry.
pub(crate) fn do_db_read<'a>(
vm: &'a mut DefaultCosmwasmVM<T>,
pub(crate) fn do_db_read(
vm: &mut DefaultCosmwasmVM<T>,
key: &[u8],
) -> Result<Option<Vec<u8>>, CosmwasmVMError<T>> {
let price = Self::do_db_read_gas(&vm.contract_info.trie_id, key);
Expand All @@ -1193,8 +1193,8 @@ impl<T: Config> Pallet<T> {

/// Read an entry from an arbitrary contract, charging the according gas prior to actually
/// reading the entry.
pub(crate) fn do_db_read_other_contract<'a>(
vm: &'a mut DefaultCosmwasmVM<T>,
pub(crate) fn do_db_read_other_contract(
vm: &mut DefaultCosmwasmVM<T>,
trie_id: &ContractTrieIdOf<T>,
key: &[u8],
) -> Result<Option<Vec<u8>>, CosmwasmVMError<T>> {
Expand All @@ -1221,8 +1221,8 @@ impl<T: Config> Pallet<T> {

/// Write an entry from the executing contract, charging the according gas prior to actually
/// writing the entry.
pub(crate) fn do_db_write<'a>(
vm: &'a mut DefaultCosmwasmVM<T>,
pub(crate) fn do_db_write(
vm: &mut DefaultCosmwasmVM<T>,
key: &[u8],
value: &[u8],
) -> Result<(), CosmwasmVMError<T>> {
Expand Down Expand Up @@ -1267,7 +1267,7 @@ impl<T: Config> Pallet<T> {
}

/// Remove an entry from the executing contract, no gas is charged for this operation.
pub(crate) fn do_db_remove<'a>(vm: &'a mut DefaultCosmwasmVM<T>, key: &[u8]) {
pub(crate) fn do_db_remove(vm: &mut DefaultCosmwasmVM<T>, key: &[u8]) {
let trie_id = &vm.contract_info.trie_id;
Self::with_db_entry(trie_id, key, |child_trie, entry| {
storage::child::kill(&child_trie, &entry)
Expand Down Expand Up @@ -1311,8 +1311,8 @@ impl<T: Config> Pallet<T> {
}
Ok(())
}
pub(crate) fn do_continue_instantiate<'a>(
vm: &'a mut DefaultCosmwasmVM<T>,
pub(crate) fn do_continue_instantiate(
vm: &mut DefaultCosmwasmVM<T>,
CosmwasmContractMeta { code_id, admin, label }: CosmwasmContractMeta<CosmwasmAccount<T>>,
funds: Vec<Coin>,
salt: &[u8],
Expand All @@ -1334,8 +1334,8 @@ impl<T: Config> Pallet<T> {
.sub_call(vm.shared, funds, message, event_handler)
}

pub(crate) fn do_continue_execute<'a>(
vm: &'a mut DefaultCosmwasmVM<T>,
pub(crate) fn do_continue_execute(
vm: &mut DefaultCosmwasmVM<T>,
contract: AccountIdOf<T>,
funds: Vec<Coin>,
message: &[u8],
Expand All @@ -1349,8 +1349,8 @@ impl<T: Config> Pallet<T> {
)
}

pub(crate) fn do_continue_reply<'a>(
vm: &'a mut DefaultCosmwasmVM<T>,
pub(crate) fn do_continue_reply(
vm: &mut DefaultCosmwasmVM<T>,
reply: cosmwasm_std::Reply,
event_handler: &mut dyn FnMut(cosmwasm_std::Event),
) -> Result<Option<cosmwasm_std::Binary>, CosmwasmVMError<T>> {
Expand All @@ -1366,8 +1366,8 @@ impl<T: Config> Pallet<T> {
)
}

pub(crate) fn do_continue_migrate<'a>(
vm: &'a mut DefaultCosmwasmVM<T>,
pub(crate) fn do_continue_migrate(
vm: &mut DefaultCosmwasmVM<T>,
contract: AccountIdOf<T>,
message: &[u8],
event_handler: &mut dyn FnMut(cosmwasm_std::Event),
Expand Down Expand Up @@ -1428,8 +1428,8 @@ impl<T: Config> Pallet<T> {
Ok(code_info_response)
}

pub(crate) fn do_continue_query<'a>(
vm: &'a mut DefaultCosmwasmVM<T>,
pub(crate) fn do_continue_query(
vm: &mut DefaultCosmwasmVM<T>,
contract: AccountIdOf<T>,
message: &[u8],
) -> Result<cosmwasm_vm::executor::QueryResult, CosmwasmVMError<T>> {
Expand All @@ -1451,8 +1451,8 @@ impl<T: Config> Pallet<T> {
result
}

pub(crate) fn do_query_raw<'a>(
vm: &'a mut DefaultCosmwasmVM<T>,
pub(crate) fn do_query_raw(
vm: &mut DefaultCosmwasmVM<T>,
address: AccountIdOf<T>,
key: &[u8],
) -> Result<Option<Vec<u8>>, CosmwasmVMError<T>> {
Expand Down
6 changes: 3 additions & 3 deletions code/parachain/frame/cosmwasm/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use ibc::core::{
ics24_host::identifier::{ChannelId, ConnectionId, PortId},
};

use crate::{prelude::*, Config};
use crate::prelude::*;

pub fn ibc_to_cw_channel_open<T: Config + Send + Sync>(
pub fn ibc_to_cw_channel_open(
channel_id: &ChannelId,
port_id: &PortId,
counterparty: &Counterparty,
Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn to_cosmwasm_timestamp(timestamp: ibc::timestamp::Timestamp) -> cosmwasm_s
cosmwasm_std::Timestamp::from_nanos(timestamp.nanoseconds())
}

pub fn ibc_open_try_to_cw_open<T: Config + Send + Sync>(
pub fn ibc_open_try_to_cw_open(
channel_id: &ChannelId,
port_id: &PortId,
counterparty: &Counterparty,
Expand Down
4 changes: 2 additions & 2 deletions code/parachain/frame/cosmwasm/src/runtimes/abstraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Gas {
}

fn current_mut(&mut self) -> &mut u64 {
self.checkpoints.last_mut().unwrap()
self.checkpoints.last_mut().expect("account by external caller")
}

/// Pushes a new gas checkpoint.
Expand Down Expand Up @@ -148,7 +148,7 @@ impl Gas {
if self.checkpoints.len() < 2 {
return Err(NoCheckpointToPop)
}
let child = self.checkpoints.pop().unwrap();
let child = self.checkpoints.pop().expect("account by external caller");
let parent = self.current_mut();
*parent += child;
Ok(())
Expand Down
7 changes: 1 addition & 6 deletions code/parachain/frame/pallet-multihop-xcm-ibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ version = "3.0.0"
bech32-no_std = { workspace = true, default-features = false, features = [
"strict",
] }
composable-traits = { path = "../composable-traits", default-features = false }
composable-traits = { path = "../composable-traits", default-features = false, features = ["centauri"]}
xc-core = { path = "../../../xcvm/lib/core", default-features = false }
hex = { version = "0.4.3", default-features = false }
composable-support = { default-features = false, path = "../composable-support" }
Expand All @@ -44,10 +44,6 @@ scale-info = { version = "2.1.1", default-features = false, features = [
] }
primitives = { path = "../../runtime/primitives", default-features = false }

serde = { version = "1.0.136", features = ["derive"], optional = true }
serde_json = { workspace = true, default-features = false, features = [
"alloc",
] }
orml-xtokens = { workspace = true, default-features = false }

ibc-rs-scale = { workspace = true, default-features = false, features = [
Expand Down Expand Up @@ -77,7 +73,6 @@ std = [
"pallet-ibc/std",
"primitives/std",
"scale-info/std",
"serde",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
Expand Down
Loading

0 comments on commit 7a9975d

Please sign in to comment.