-
Notifications
You must be signed in to change notification settings - Fork 35
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
12 changed files
with
100 additions
and
48 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "simple" | ||
type = "lib" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.26.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,30 @@ | ||
#[recursive] | ||
fn main(n: Field) -> pub u8 { | ||
// not_odd(n); | ||
n as u8 | ||
} | ||
|
||
// fn main(x: Field, y: Field) -> pub bool { | ||
// not_odd(x) & not_odd(y) & not_equal(x, y); | ||
// } | ||
|
||
fn not_equal(x: Field, y: Field) -> bool { | ||
x != y | ||
} | ||
|
||
fn not_odd(n: Field) -> bool { | ||
(n as u8) & 1 == 0 | ||
} | ||
|
||
#[test] | ||
fn test_not_equal() { | ||
assert(not_equal(1, 2)); | ||
// Uncomment to make test fail | ||
// assert(not_equal(1, 1)); | ||
} | ||
|
||
fn test_not_odd() { | ||
assert(not_odd(2)); | ||
// Uncomment to make test fail | ||
// assert(not_odd(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 |
---|---|---|
|
@@ -5,4 +5,3 @@ authors = [""] | |
compiler_version = ">=0.26.0" | ||
|
||
[dependencies] | ||
simple = { path = "../simple" } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
use dep::std; | ||
use dep::simple; | ||
// use dep::simple; | ||
|
||
#[export] | ||
fn main_call(x: Field, y: Field) -> bool { | ||
let mut res = simple::not_odd(x); | ||
res &= simple::not_odd(y); | ||
res &= simple::not_equal(x, y); | ||
res | ||
} | ||
|
||
// #[recursive] | ||
// #[export] | ||
// fn main(x: Field, y: Field) -> pub bool {} | ||
// fn main_call(x: Field, y: Field) -> bool { | ||
// let mut res = simple::not_odd(x); | ||
// res &= simple::not_odd(y); | ||
// res &= simple::not_equal(x, y); | ||
// res | ||
// } | ||
|
||
#[test] | ||
fn test_not_equal() { | ||
assert(main_call(2, 4)); | ||
// Uncomment to make test fail | ||
// assert(not_equal(1, 1)); | ||
#[export] | ||
fn main(x: Field, y: Field) -> pub bool { | ||
// Hash public inputs together | ||
//TODO: take proofs | ||
x != y | ||
} | ||
|
||
// #[test] | ||
// fn test_not_equal() { | ||
// assert(main_call(2, 4)); | ||
// // Uncomment to make test fail | ||
// // assert(not_equal(1, 1)); | ||
// } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,43 @@ | ||
import { CompiledCircuit } from '@noir-lang/types'; | ||
import { not_equal, not_odd, main_call, main } from './codegen'; | ||
import { main } from './codegen'; | ||
import { setTimeout } from "timers/promises"; | ||
|
||
import { Noir } from '@noir-lang/noir_js'; | ||
import { BarretenbergBackend } from '@noir-lang/backend_barretenberg'; | ||
import { join, resolve } from 'path'; | ||
import { compile, createFileManager } from '@noir-lang/noir_wasm'; | ||
|
||
import { ProofData } from '@noir-lang/types'; | ||
|
||
async function getCircuit(name: string) { | ||
const basePath = resolve(join('./circuits', name)); | ||
const fm = createFileManager(basePath); | ||
const compiled = await compile(fm, basePath); | ||
console.log(compiled.program.abi); | ||
if (!('program' in compiled)) { | ||
throw new Error('Compilation failed'); | ||
} | ||
return compiled.program; | ||
} | ||
|
||
const input1 = { n: 2 }; | ||
const input2 = { n: 4 }; | ||
|
||
async function start() { | ||
let res = await main_call("02", "04"); | ||
console.log(res); | ||
let simpleCircuit: CompiledCircuit = await getCircuit('not_odd'); | ||
let simpleBackend: BarretenbergBackend = new BarretenbergBackend(simpleCircuit, { threads: 8 }); | ||
let simpleNoir: Noir = new Noir(simpleCircuit, simpleBackend); | ||
|
||
const witness1 = (await simpleNoir.execute(input1)).witness; | ||
let proof1: ProofData = await simpleBackend.generateProof(witness1); | ||
|
||
const witness2 = (await simpleNoir.execute(input2)).witness; | ||
let proof2: ProofData = await simpleBackend.generateProof(witness2); | ||
|
||
// let res = await main(/* intermediate proofs */); | ||
// console.log(res); | ||
|
||
simpleBackend.destroy(); | ||
} | ||
|
||
start(); |
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
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 |
---|---|---|
|
@@ -56,6 +56,14 @@ | |
"@noir-lang/noirc_abi" "0.26.0" | ||
"@noir-lang/types" "0.26.0" | ||
|
||
"@noir-lang/noir_wasm@^0.26.0": | ||
version "0.26.0" | ||
resolved "https://registry.yarnpkg.com/@noir-lang/noir_wasm/-/noir_wasm-0.26.0.tgz#1c634932f53580022998e6811fee6077c47501d1" | ||
integrity sha512-PmVyd/HE0fSxL6UU3XzCwpf9JyoR2Ql6V8odq3LFndosx5/FDWZtpxe1o7aNLdjebK2l4KmGJPN3eMh9JaiRoQ== | ||
dependencies: | ||
"@noir-lang/types" "0.26.0" | ||
pako "^2.1.0" | ||
|
||
"@noir-lang/[email protected]": | ||
version "0.26.0" | ||
resolved "https://registry.yarnpkg.com/@noir-lang/noirc_abi/-/noirc_abi-0.26.0.tgz#5052ab7a55228cc04d77cebf8753ea42636963ff" | ||
|
@@ -330,6 +338,11 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" | ||
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== | ||
|
||
pako@^2.1.0: | ||
version "2.1.0" | ||
resolved "https://registry.yarnpkg.com/pako/-/pako-2.1.0.tgz#266cc37f98c7d883545d11335c00fbd4062c9a86" | ||
integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug== | ||
|
||
path-key@^3.1.0: | ||
version "3.1.1" | ||
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" | ||
|