a16z / jolt

The simplest and most extensible zkVM. Fast and fully open source from a16z crypto and friends. ⚡
https://jolt.a16zcrypto.com
MIT License
619 stars 123 forks source link

Casting to float can produce invalid proofs #411

Closed jswalens closed 1 month ago

jswalens commented 1 month ago

I execute the following program:

#[jolt::provable]
fn cast(n: u32) -> f64 {
    n as f64
}

This produces an invalid proof:

pub fn main() {
    let (prove, verify) = guest::build_cast();
    let (result, proof) = prove(15);
    println!("Result: {:?}", result);
    println!("valid: {}", verify(proof));

This prints the correct result, but verification fails. In other words, the program compiles and is executed correctly, a proof is generated, but the proof is invalid.

Note: I get the same result for n.into(). The problem does not appear for casting u32 to u64, but I didn't try other combinations.