antouhou / rs-merkle

The most advanced Merkle tree library for Rust
MIT License
168 stars 45 forks source link

Use of Floats is not supported in CosmWasm #19

Closed sashaduke closed 1 year ago

sashaduke commented 1 year ago

The use of a Float32 type in src/utils/indices.rs results in the crate not compiling on CosmWasm's WASM VM. A fix has been proposed on this pull request.

matthiasgoergens commented 1 year ago

To be more precise WebAssembly supports floats just fine by itself, but Sasha has an application that only supports a subset of WASM that doesn't include floating point operations.

matthiasgoergens commented 1 year ago

Also addressed in https://github.com/antouhou/rs-merkle/pull/16

antouhou commented 1 year ago

I've added a comment to #16. Although this does remove the use of the float, this makes this incompatible with the no-std. I'll try to come up with a way to do this without using floats and std. Being able to use this in the CosmWasm definitely an important feature. Thank you for the report!

matthiasgoergens commented 1 year ago

Thanks for having a look.

You can always use a loop to count how many right shifts you need until the number turns to 0?

There was another PR with the same aim as mine that did something like this.

sashaduke commented 1 year ago

no_std compatibility can be maintained by using core::mem::sizeof instead of std::mem::sizeof

antouhou commented 1 year ago

Hi @matthiasgoergens @sashaduke! I've merged your PRs and added one additional check for no-std targets. The changes are included in v1.3.0. Thank you! Please close this issue if that works for you, or I'll close it myself in some time :)

Thank you!

matthiasgoergens commented 1 year ago

Awesome, thanks!