Closed dzmitry-lahoda closed 1 year ago
I am trying to strip contract, if that works. UPDATE: did not helped
Okey, it was PrefixedDenom
pub(crate) fn calculate_block_delay(
delay_period_time: &Duration,
max_expected_time_per_block: &Duration,
) -> u64 {
if max_expected_time_per_block.is_zero() {
return 0;
}
FloatCore::ceil(delay_period_time.as_secs_f64() / max_expected_time_per_block.as_secs_f64())
as u64
}
So such code if it runs in ics wasm-08 likely will not work.
I stably reproduce on my contact, but failed to repro on small contract. When I copy paste PrefixedDenom instead of ref, check passes.
All contracts (1) passed checks!
bash-5.1$ nix run github:informalsystems/cosmos.nix#cosmwasm-check /home/dz/github.com/ComposableFi/composable/code/target/wasm32-unknown-unknown/cosmwasm-contracts/cw_xc_gateway.wasm
Available capabilities: {"stargate", "cosmwasm_1_1", "iterator", "staking", "cosmwasm_1_2"}
/home/dz/github.com/ComposableFi/composable/code/target/wasm32-unknown-unknown/cosmwasm-contracts/cw_xc_gateway.wasm: failure
Error compiling Wasm: Could not compile: WebAssembly translation error: Error in middleware Gatekeeper: Float operator detected: F64Load { memarg: MemoryImmediate { align: 3, offset: 8, memory: 0 } }. The use of floats is not supported.
Passes: 0, failures: 1
bash-5.1$ nix run github:informalsystems/cosmos.nix#cosmwasm-check /home/dz/github.com/ComposableFi/composable/code/target/wasm32-unknown-unknown/cosmwasm-contracts/cw_xc_gateway.wasm
Available capabilities: {"stargate", "cosmwasm_1_2", "iterator", "staking", "cosmwasm_1_1"}
/home/dz/github.com/ComposableFi/composable/code/target/wasm32-unknown-unknown/cosmwasm-contracts/cw_xc_gateway.wasm: pass
All contracts (1) passed checks!
The only differnece, I copied PrefixedDenom
to our code. We use Channel/Port/Connect-Id, but when adding PrefixedDenom ref it breaks wasm.... Magic.
Added cw-check example https://github.com/dzmitry-lahoda-forks/ibc-rs/tree/dz/9/ci/cw-check . It still may be usefull to do this to ensure it can run in wasm hosts with no floats support (blockchains).
so ideally ibc-rs and its deps not to use usize
Thank you for bringing this to our attention! Very subtle...
I fixed thing, it works for me now.
this so works only on wasm https://github.com/chipshort/wasm-float-transpiler, not riskv or bpf or native float free. but it may be alfa version, and having yet another layer of compilation can be buggy.
Fixed in #894
Feature Summary
CosmWasm(wasmd), and hence IBC WASM-08 fail to upload wasm file if it has code with f32/f64. Unfortunately some things have usize which sometimes handled with floats (crazy but fact https://medium.com/cosmwasm/debugging-floating-point-generation-in-rust-wasm-smart-contract-f47d833b5fba ).
Given these things and that ibc-rs to support many runtime (near, solana, aptos, ic) which also may dislike these floats (as constraint and blockchain enviroments in general) preventing usage of this with linter is good.
Usize, except for some reason some crates use floats to handle it (now sure why), is of variable size, which may lead to bugs, e.g. when target would be wasm64.
Proposal
Remove all f64/f32/usize usage and lint that from repo.
LEGACY
Proposal
I used ibc-rs, and in latest version I get
when it is part of contract.
I see old Cargo.lock
new
Also I found
f64
usage in this repo when not needed.So I do not use any things changed directly, and yet get issues.
Run https://github.com/CosmWasm/cosmwasm/blob/main/packages/check/README.md in CI.
I did not yet found root cause so.
Thing happend from 0.41 release inclusive and before 0.43. I was able to upload contract.
I think not only cw wasmd will be such, but wasm-08 too.