This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Bartosz Nowak
committed
Nov 28, 2023
1 parent
bcb4062
commit ecd9386
Showing
7 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -8,6 +8,10 @@ members = [ | |
"noir_rs", | ||
] | ||
|
||
exclude = [ | ||
"examples" | ||
] | ||
|
||
resolver = "2" | ||
|
||
[workspace.package] | ||
|
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 @@ | ||
/target |
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,11 @@ | ||
[package] | ||
name = "poly_check_circuit" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# 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" } | ||
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 = "poly_check_circuit" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = "0.10.5" | ||
|
||
[dependencies] |
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,29 @@ | ||
# `noir_rs`: Polynomial Value Check Circuit Example | ||
|
||
## Introduction | ||
|
||
Welcome to the `noir_rs` library, a Rust-based library designed for creating and working with zero-knowledge proofs. This example demonstrates the use of `noir_rs` in conjunction with `nargo`, showcasing a single project structure. | ||
|
||
The Polynomial Value Check Circuit example illustrates how to construct and verify a circuit that checks the value of a polynomial at a given point. | ||
|
||
## Running the Example | ||
|
||
To run the Polynomial Value Check Circuit example, follow these steps: | ||
|
||
1. **Compile the Circuit** | ||
|
||
Use `nargo` to compile the circuit: | ||
|
||
```bash | ||
nargo compile | ||
``` | ||
|
||
2. **Run the Circuit** | ||
|
||
Once compiled, you can run the circuit using Cargo: (compiles barretenberg backend will take a while) | ||
|
||
```bash | ||
cargo run | ||
``` | ||
|
||
This will execute the example, demonstrating the functionality of the `noir_rs` library in a practical scenario. |
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,13 @@ | ||
fn main(y : Field, x : pub Field) { | ||
// y <= 4x^3 + 7x + 1 | ||
let x_3 = x * x * x; | ||
assert(y as u32 <= (4 * x_3 + 7 * x + 1) as u32); | ||
} | ||
|
||
#[test] | ||
fn test_main() { | ||
main(39, 2); | ||
|
||
// Uncomment to make test fail | ||
// main(1, 1); | ||
} |
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,18 @@ | ||
use std::fs; | ||
use serde_json::Value; | ||
use noir_rs::{native_types::{Witness, WitnessMap}, FieldElement}; | ||
|
||
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"); | ||
|
||
let mut initial_witness = WitnessMap::new(); | ||
initial_witness.insert(Witness(1), FieldElement::from(47_i128)); | ||
initial_witness.insert(Witness(2), FieldElement::from(2_i128)); | ||
let (proof, vk) = noir_rs::prove(String::from(bytecode), initial_witness).unwrap(); | ||
let verdict = noir_rs::verify(String::from(bytecode), proof, vk).unwrap(); | ||
assert!(verdict); | ||
} |