1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00
ZoKrates/zokrates_core/tests/out_of_range.rs

40 lines
1 KiB
Rust

extern crate zokrates_common;
extern crate zokrates_core;
extern crate zokrates_field;
use std::io;
use zokrates_common::Resolver;
use zokrates_core::{
compile::{compile, CompilationArtifacts, CompileConfig},
ir::Interpreter,
};
use zokrates_field::Bn128Field;
#[test]
fn out_of_range() {
let source = r#"
def main(private field a) -> (field):
field x = if a < 5555 then 3333 else 4444 fi
assert(x == 3333)
return 1
"#
.to_string();
// let's try to prove that "10000 < 5555" is true by exploiting
// the fact that `2*10000 - 2*5555` has two distinct bit decompositions
// we chose the one which is out of range, ie the sum check features an overflow
let res: CompilationArtifacts<Bn128Field> = compile(
source,
"./path/to/file".into(),
None::<&dyn Resolver<io::Error>>,
&CompileConfig::default(),
)
.unwrap();
let interpreter = Interpreter::try_out_of_range();
assert!(interpreter
.execute(&res.prog(), &vec![Bn128Field::from(10000)])
.is_err());
}