Skip to content

Commit

Permalink
line_check_example
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Dec 17, 2023
1 parent 6a3db6d commit d089c38
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 0 deletions.
9 changes: 9 additions & 0 deletions noir/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions noir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions noir/tooling/noir_rs/examples/line_check_circuit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 7 additions & 0 deletions noir/tooling/noir_rs/examples/line_check_circuit/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "line_check_circuit"
type = "bin"
authors = ["Bartosz Nowak https://github.com/Okm165"]
compiler_version = ">=0.19.4"

[dependencies]
15 changes: 15 additions & 0 deletions noir/tooling/noir_rs/examples/line_check_circuit/src/main.nr
Original file line number Diff line number Diff line change
@@ -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);
}
28 changes: 28 additions & 0 deletions noir/tooling/noir_rs/examples/line_check_circuit/src/main.rs
Original file line number Diff line number Diff line change
@@ -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");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct Line {
a: u64,
b: u64,
}

struct Point {
x: u64,
y: u64,
}

0 comments on commit d089c38

Please sign in to comment.