Closed 0xekez closed 1 year ago
Thanks for bringing this up. Good point. Last time I debugged something like this the problem was a formatter function that was eventually unused and was kicked out by rust-optimizer but not the simple Rust production build.
But using u64 or u32 explicitly makes sense in most places. With usize
you get different sizes between unit tests (64 bit dev machine) and Wasm (32 bit).
@webmaster128 thanks for the response. I actually didn't even know that webassembly had a 32 bit VM so I'm already learning something :)
Do you think there are steps that we might take (for example: docs updates) to make these things a little more clear? I don't see anywhere that pops out to me after a skim but you might have better ideas. It might also be fine to just let this issue document the solution.
This is solved by https://github.com/CosmWasm/cosmwasm/issues/1845 which will be shipped as part of CosmWasm 1.5.
Generating the starter cosmwasm contract by running:
Then, modifying the default code to add a
Foo
member with ausize
parameter as follows:Causes floating point instructions to be outputted when compiled which will prevent the contract from being uploaded. This is unexpected as using
u64
instead will work. An example upload and error message:The floating point instructions are generated by
cargo wasm
and not the rust optimizer so I don't think this is necessarily a bug with cosmwasm but it might be nice to somehow warn about this in either documentation or in the optimizer. Seems like a pretty subtle footgun. I'm happy to work on this if people have thoughts on how this might be resolved.