1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
ZoKrates/zokrates_core/tests/out_of_range.rs

32 lines
873 B
Rust

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