forked from AztecProtocol/aztec-packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
noir/tooling/noir_rs/examples/line_check_circuit/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
noir/tooling/noir_rs/examples/line_check_circuit/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
noir/tooling/noir_rs/examples/line_check_circuit/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
9 changes: 9 additions & 0 deletions
9
noir/tooling/noir_rs/examples/line_check_circuit/src/structs.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |