Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for using floats in contracts #198

Open
Bargsteen opened this issue Apr 8, 2022 · 1 comment
Open

Improve error message for using floats in contracts #198

Bargsteen opened this issue Apr 8, 2022 · 1 comment
Labels
[Type] Change Request Some visible functionality should be change.

Comments

@Bargsteen
Copy link
Contributor

Bargsteen commented Apr 8, 2022

Description

Floating-point numbers are not supported in smart contracts, but if you don't know that and you try to use them (or you use a library that uses floats), the error message when building with cargo concordium is very cryptic.

Steps to Reproduce

  1. Use floating-point numbers in your contract.
    Make sure that the compiler doesn't optimize the floats away.
    Something like this worked for me with 1.53.0:
    fn g() {
        if f(f(1.)) < 2. {
            println!("hello");
        }
    }
    
    #[inline(never)]
    fn f(x: f64) -> f64 {
        if x < 1. {
            x + 1.
        } else {
            x + 2.
        }
    }
  2. Compile the contract with cargo concordium build

Expected Result

An error message saying: Floating point numbers are not allowed.

Actual Result

Error: Could not build smart contract.

Caused by:
    0: Could not validate resulting smart contract module as a V1 contract.
    1: Unknown value type byte 0x7c

(0x7c is the encoding of the f64 type in https://webassembly.github.io/spec/core/binary/types.html#number-types.)

Versions

  • Software Version: cargo concordium v. 2.0.0
  • OS: macOS
@Bargsteen Bargsteen added the [Type] Change Request Some visible functionality should be change. label Apr 8, 2022
@abizjak
Copy link
Contributor

abizjak commented Apr 8, 2022

Indeed. Although this will be substantially easier to do after #203 since right now errors are not easy to match on.

@abizjak abizjak transferred this issue from Concordium/concordium-wasm-smart-contracts Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Change Request Some visible functionality should be change.
Projects
None yet
Development

No branches or pull requests

2 participants