diff --git a/noir/Cargo.lock b/noir/Cargo.lock index 65737d7cfd2..1ac88d8d6e3 100644 --- a/noir/Cargo.lock +++ b/noir/Cargo.lock @@ -2458,6 +2458,15 @@ dependencies = [ "redox_syscall", ] +[[package]] +name = "line_check_circuit" +version = "0.1.0" +dependencies = [ + "noir_rs 0.19.4 (git+https://github.com/visoftsolutions/noir_rs.git?branch=latest)", + "serde", + "serde_json", +] + [[package]] name = "linux-raw-sys" version = "0.4.12" diff --git a/noir/Cargo.toml b/noir/Cargo.toml index fc25ec513c3..6a2492fd90e 100644 --- a/noir/Cargo.toml +++ b/noir/Cargo.toml @@ -28,6 +28,7 @@ members = [ "tooling/noir_rs/blackbox_solver", "tooling/noir_rs/acvm_runtime", "tooling/noir_rs/examples/poly_check_circuit", + "tooling/noir_rs/examples/line_check_circuit", "tooling/noir_rs", # ACVM "acvm-repo/acir_field", diff --git a/noir/tooling/noir_rs/examples/line_check_circuit/Cargo.toml b/noir/tooling/noir_rs/examples/line_check_circuit/Cargo.toml new file mode 100644 index 00000000000..fef012a102c --- /dev/null +++ b/noir/tooling/noir_rs/examples/line_check_circuit/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "line_check_circuit" +version = "0.1.0" +edition = "2021" +authors = ["Bartosz Nowak https://github.com/Okm165"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +noir_rs = { git = "https://github.com/visoftsolutions/noir_rs.git", branch = "latest", package = "noir_rs" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" \ No newline at end of file diff --git a/noir/tooling/noir_rs/examples/line_check_circuit/Nargo.toml b/noir/tooling/noir_rs/examples/line_check_circuit/Nargo.toml new file mode 100644 index 00000000000..2c632391e30 --- /dev/null +++ b/noir/tooling/noir_rs/examples/line_check_circuit/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "line_check_circuit" +type = "bin" +authors = ["Bartosz Nowak https://github.com/Okm165"] +compiler_version = ">=0.19.4" + +[dependencies] \ No newline at end of file diff --git a/noir/tooling/noir_rs/examples/line_check_circuit/src/main.nr b/noir/tooling/noir_rs/examples/line_check_circuit/src/main.nr new file mode 100644 index 00000000000..d64248523d0 --- /dev/null +++ b/noir/tooling/noir_rs/examples/line_check_circuit/src/main.nr @@ -0,0 +1,15 @@ +mod structs; +use structs::{Point, Line}; + +fn main(point: Point, line: pub Line) { + assert(line.a * point.x + line.b - point.y == 0); +} + +#[test] +fn test_main() { + let line = Line { a: 5, b: 7 }; + let point = Point { x: 1, y: 12 }; + main(point, line); + // Uncomment to make test fail + // main(1, 1); +} diff --git a/noir/tooling/noir_rs/examples/line_check_circuit/src/main.rs b/noir/tooling/noir_rs/examples/line_check_circuit/src/main.rs new file mode 100644 index 00000000000..3f9c087ba41 --- /dev/null +++ b/noir/tooling/noir_rs/examples/line_check_circuit/src/main.rs @@ -0,0 +1,28 @@ +use noir_rs::{ + native_types::{Witness, WitnessMap}, + FieldElement, +}; +use serde_json::Value; +use std::fs; + +static PACKAGE_NAME: &str = env!("CARGO_PKG_NAME"); + +fn main() { + let data = + fs::read_to_string(format!("target/{}.json", PACKAGE_NAME)).expect("Unable to read file"); + let json: Value = serde_json::from_str(&data).expect("Unable to parse JSON"); + let bytecode: &str = json["bytecode"].as_str().expect("Unable to extract bytecode"); + + println!("Initializing witness..."); + let mut initial_witness = WitnessMap::new(); + initial_witness.insert(Witness(1), FieldElement::from(1_i128)); + initial_witness.insert(Witness(2), FieldElement::from(12_i128)); + initial_witness.insert(Witness(3), FieldElement::from(5_i128)); + initial_witness.insert(Witness(4), FieldElement::from(7_i128)); + println!("Generating proof..."); + let (proof, vk) = noir_rs::prove(String::from(bytecode), initial_witness).unwrap(); + println!("Verifying proof..."); + let verdict = noir_rs::verify(String::from(bytecode), proof, vk).unwrap(); + assert!(verdict); + println!("Proof correct"); +} diff --git a/noir/tooling/noir_rs/examples/line_check_circuit/src/structs.nr b/noir/tooling/noir_rs/examples/line_check_circuit/src/structs.nr new file mode 100644 index 00000000000..523235113fa --- /dev/null +++ b/noir/tooling/noir_rs/examples/line_check_circuit/src/structs.nr @@ -0,0 +1,9 @@ +struct Line { + a: u64, + b: u64, +} + +struct Point { + x: u64, + y: u64, +}