Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating for noir 1.0.0-beta.0 #13

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 noir-lang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file added bun.lockb
Binary file not shown.
5 changes: 1 addition & 4 deletions circuit/Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

[package]
name = "circuit"
type = "bin"
authors = [""]
compiler_version = ">=0.31.0"

[dependencies]
11 changes: 2 additions & 9 deletions circuit/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
fn main(x: Field, y: pub Field) {
assert(x != y);
}

#[test]
fn test_main() {
main(1, 2);

// Uncomment to make test fail
// main(1, 1);
fn main(age: u8) {
assert(age >= 18);
}
9 changes: 5 additions & 4 deletions vite-project/index.html → index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<!DOCTYPE html>
<head>
<style>
Expand All @@ -15,15 +16,15 @@
</style>
</head>
<body>
<script type="module" src="/main.js"></script>
<script type="module" src="/index.js"></script>
<h1>Noir app</h1>
<div class="input-area">
<input id="guessInput" type="number" placeholder="Enter your guess" />
<button id="submitGuess">Submit Guess</button>
<input id="age" type="number" placeholder="Enter age" />
<button id="submit">Submit Age</button>
</div>
<div class="outer">
<div id="logs" class="inner"><h2>Logs</h2></div>
<div id="results" class="inner"><h2>Proof</h2></div>
</div>
</body>
</html>
</html>
49 changes: 49 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { compile, createFileManager } from "@noir-lang/noir_wasm";
import { UltraHonkBackend } from "@aztec/bb.js";
import { Noir } from "@noir-lang/noir_js";
import initNoirC from "@noir-lang/noirc_abi";
import initACVM from "@noir-lang/acvm_js";
import acvm from "@noir-lang/acvm_js/web/acvm_js_bg.wasm?url";
import noirc from "@noir-lang/noirc_abi/web/noirc_abi_wasm_bg.wasm?url";
await Promise.all([initACVM(fetch(acvm)), initNoirC(fetch(noirc))]);

import main from "./circuit/src/main.nr?url";
import nargoToml from "./circuit/Nargo.toml?url";

export async function getCircuit() {
const fm = createFileManager("/");
const { body } = await fetch(main);
const { body: nargoTomlBody } = await fetch(nargoToml);

fm.writeFile("./src/main.nr", body);
fm.writeFile("./Nargo.toml", nargoTomlBody);
return await compile(fm);
}
const show = (id, content) => {
const container = document.getElementById(id);
container.appendChild(document.createTextNode(content));
container.appendChild(document.createElement("br"));
};

document.getElementById("submit").addEventListener("click", async () => {
try {
// noir goes here
const { program } = await getCircuit();
const noir = new Noir(program);
const backend = new UltraHonkBackend(program.bytecode);
const age = document.getElementById("age").value;
show("logs", "Generating witness... ⏳");
const { witness } = await noir.execute({ age });
show("logs", "Generated witness... ✅");
show("logs", "Generating proof... ⏳");
const proof = await backend.generateProof(witness);
show("logs", "Generated proof... ✅");
show("results", proof.proof);
show("logs", "Verifying proof... ⌛");
const isValid = await backend.verifyProof(proof);
show("logs", `Proof is ${isValid ? "valid" : "invalid"}... ✅`);
} catch (err) {
console.error(err);
show("logs", "Oh 💔");
}
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "dependencies": { "@aztec/bb.js": "0.63.1", "@noir-lang/noir_js": "1.0.0-beta.0", "@noir-lang/noir_wasm": "1.0.0-beta.0" } }
24 changes: 0 additions & 24 deletions vite-project/.gitignore

This file was deleted.

34 changes: 0 additions & 34 deletions vite-project/main.js

This file was deleted.

Loading