Honro
April 8, 2022, 12:59pm
1
Hello
We have developed a smart contract, however we get the following error when running cargo concordium build.
Error: Could not build smart contract.
Caused by:
0: Could not validate resulting smart contract module.
1: Unknown value type byte 0x7c
What does this error mean? We are able to build the piggy bank example. We thought it might be because of our dependencies, but we dont know.
1 Like
Kasper
April 8, 2022, 2:12pm
2
Hi Honro,
And welcome to the Concordium support forum!
I understand your confusion. It is not the easiest error message to decipher. 0x7c
is the byte code for the f64
type in WASM . So your contract uses floating-point numbers, which are not allowed in Concordium smart contracts. This limitation is explained in our documenation .
I hope that you can find a way around using floats in your contract. If not, let us know, and we can try to help you out.
Best regards,
Kasper
2 Likes
Kasper
April 11, 2022, 8:52am
3
I’ve created an issue, so we can improve the error message when using floats in the future
opened 02:35PM - 08 Apr 22 UTC
[Type] Change Request
**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:
```rust
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](WASM).)
**Versions**
- Software Version: cargo concordium v. 2.0.0
- OS: macOS
1 Like
Honro
April 15, 2022, 2:05pm
4
Thanks for the reply Kasper.
We don’t use floats, however one of our libraries might. So I guess we have to look them through and find which one does.
Good idea improving the error message hehe.
Honro
April 18, 2022, 8:37am
5
Hello again.
So we have found that the crate ‘curv kzen’ is causing the problem. We are using it to implement elliptic curve cryptograhpy. Is there some sort of workaround, or do you know any other crates for cryptography that are compatible?
Thanks
How can I find the library that is using f64 easily? Any tips on that one? Thanks
You cannot. Floating point operations are not allowed on the chain due to determinism issues.
I know. What I tried to convey: is there an easy way to find out where floating point variables are used in your libraries?
Right.
I think none of our libraries (concordium-std, concordium-cis2) use floating points. So it’d have to be some other dependency that you added.
I don’t have concrete advice on how you would go about this other than removing one dependency at a time and seeing if it compiles.
If you can share a bit more details perhaps we can help more concretely.