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 to 0.23.0 #73

Merged
merged 19 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
33 changes: 20 additions & 13 deletions vite-hardhat/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
import {
useState,
useEffect,
SetStateAction,
ReactEventHandler,
FormEvent,
ChangeEvent,
} from 'react';

import { toast } from 'react-toastify';
import React from 'react';

import { Noir } from '@noir-lang/noir_js';
import { BarretenbergBackend, flattenPublicInputs } from '@noir-lang/backend_barretenberg';
import { BarretenbergBackend } from '@noir-lang/backend_barretenberg';
import { CompiledCircuit, ProofData } from '@noir-lang/types';
import { compile, PathToFileSourceMap } from '@noir-lang/noir_wasm';
import { compile, createFileManager } from '@noir-lang/noir_wasm';

import { useAccount, useConnect, useContractWrite } from 'wagmi';
import { contractCallConfig } from '../utils/wagmi.jsx';
import { bytesToHex } from 'viem';

async function getCircuit(name: string) {
const res = await fetch(new URL('../circuits/src/main.nr', import.meta.url));
const noirSource = await res.text();
export async function getFile(file_path: string): Promise<ReadableStream<Uint8Array>> {
const file_url = new URL(file_path, import.meta.url);
const response = await fetch(file_url);

if (!response.ok) throw new Error('Network response was not OK');

const sourceMap = new PathToFileSourceMap();
sourceMap.add_source_code('main.nr', noirSource);
const compiled = compile('main.nr', undefined, undefined, sourceMap);
return compiled;
return response.body as ReadableStream<Uint8Array>;
}

async function getCircuit(name: string) {
const fm = createFileManager('/');
fm.writeFile('./src/main.nr', await getFile(`../circuits/${name}/src/${name}.nr`));
fm.writeFile('./Nargo.toml', await getFile(`../circuits/${name}/Nargo.toml`));
const result = await compile(fm);
if (!('program' in result)) {
throw new Error('Compilation failed');
}
return result.program as CompiledCircuit;
}

function Component() {
Expand Down Expand Up @@ -86,7 +93,7 @@ function Component() {

if (proof) {
write?.({
args: [bytesToHex(proof.proof), flattenPublicInputs(proof.publicInputs)],
args: [bytesToHex(proof.proof), proof.publicInputs],
});
}
};
Expand Down
5 changes: 0 additions & 5 deletions vite-hardhat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import './App.css';
import 'react-toastify/dist/ReactToastify.css';
import { ToastContainer } from 'react-toastify';
import Component from './components/index';

import initNoirWasm from '@noir-lang/noir_wasm';
import initNoirC from '@noir-lang/noirc_abi';
import initACVM from '@noir-lang/acvm_js';
import { WagmiConfig } from 'wagmi';
Expand All @@ -16,9 +14,6 @@ const InitWasm = ({ children }) => {
useEffect(() => {
(async () => {
await Promise.all([
initNoirWasm(
new URL('@noir-lang/noir_wasm/web/noir_wasm_bg.wasm', import.meta.url).toString(),
),
initACVM(new URL('@noir-lang/acvm_js/web/acvm_js_bg.wasm', import.meta.url).toString()),
initNoirC(
new URL('@noir-lang/noirc_abi/web/noirc_abi_wasm_bg.wasm', import.meta.url).toString(),
Expand Down
8 changes: 4 additions & 4 deletions vite-hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"test": "NODE_OPTIONS='--experimental-loader ts-node/esm/transpile-only' hardhat test"
},
"dependencies": {
"@noir-lang/backend_barretenberg": "0.22.0",
"@noir-lang/noir_js": "0.22.0",
"@noir-lang/noir_wasm": "0.22.0",
"@noir-lang/types": "0.22.0",
"@noir-lang/backend_barretenberg": "0.23.0",
"@noir-lang/noir_js": "0.23.0",
"@noir-lang/noir_wasm": "0.23.0",
"@noir-lang/types": "0.23.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox-viem": "1.0.0",
"@nomicfoundation/hardhat-viem": "1.0.0",
Expand Down
32 changes: 16 additions & 16 deletions vite-hardhat/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ import hre from 'hardhat';
import { Noir } from '@noir-lang/noir_js';
import { BarretenbergBackend } from '@noir-lang/backend_barretenberg';

import { compile, PathToFileSourceMap } from '@noir-lang/noir_wasm';
import { join } from 'path';
import { ProofData } from '@noir-lang/types';
import { readFileSync } from 'fs';

const getCircuit = async (name: string) => {
const sourcePath = new URL('../circuits/src/main.nr', import.meta.url);
const sourceMap = new PathToFileSourceMap();

sourceMap.add_source_code(sourcePath.pathname, readFileSync(join(sourcePath.pathname), 'utf-8'));
const compiled = compile(sourcePath.pathname, undefined, undefined, sourceMap);
return compiled;
};
import { compile, createFileManager } from '@noir-lang/noir_wasm';
import { CompiledCircuit, ProofData } from '@noir-lang/types';
import { join, resolve } from 'path';

async function getCircuit() {
const basePath = resolve(join('./circuits'));
const fm = createFileManager(basePath);
const result = await compile(fm);
if (!('program' in result)) {
throw new Error('Compilation failed');
}
return result.program as CompiledCircuit;
}

describe('It compiles noir program code, receiving circuit bytes and abi object.', () => {
let noir: Noir;
let correctProof: ProofData;

before(async () => {
const compiled = await getCircuit('main');
const compiled = await getCircuit();
const verifierContract = await hre.viem.deployContract('UltraVerifier');

const verifierAddr = verifierContract.address;
console.log(`Verifier deployed to ${verifierAddr}`);

// @ts-ignore
const backend = new BarretenbergBackend(compiled.program);
const backend = new BarretenbergBackend(compiled);
// @ts-ignore
noir = new Noir(compiled.program, backend);
noir = new Noir(compiled, backend);
});

it('Should generate valid proof for correct input', async () => {
Expand Down
2 changes: 1 addition & 1 deletion vite-hardhat/utils/addresses.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"chainId":31337,"verifier":"0x4ed7c70f96b99c776995fb64377f0d4ab3b0e1c1"}
{"chainId":31337,"verifier":"0x5fc8d32690cc91d4c39d9d3abcbd16989f875707"}
5 changes: 5 additions & 0 deletions vite-hardhat/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';

export default defineConfig({
optimizeDeps: {
esbuildOptions: {
target: 'esnext'
}
},
build: {
target: 'esnext',
},
Expand Down
75 changes: 41 additions & 34 deletions vite-hardhat/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.9.4.tgz#aae21cb858bbb0411949d5b7b3051f4209043f62"
integrity sha512-UK0bHA7hh9cR39V+4gl2/NnBBjoXIxkuWAPCaY4X7fbH4L/azIi7ilWOCjMUYfpJgraLUAqkRi2BqrjME8Rynw==

"@aztec/bb.js@0.16.0":
version "0.16.0"
resolved "https://registry.yarnpkg.com/@aztec/bb.js/-/bb.js-0.16.0.tgz#b99632ee378f4154111a865195ea88817f5e79d3"
integrity sha512-RWx0Oiml+bgOA+cqdh+/jynLIUOFHKFsPpk7L9gWz8Di0UZg9AoTSSOG+pR3il5EGWA4cJp5Wp3ikOSq62gC7g==
"@aztec/bb.js@0.19.0":
version "0.19.0"
resolved "https://registry.yarnpkg.com/@aztec/bb.js/-/bb.js-0.19.0.tgz#1c9c1d386954398e99c024425d9f282955389d59"
integrity sha512-I28AdggGl/5FjOEdOCYXviH0TnQUjEl2B95sux1kVJj8MiwD1rmx/tuaQBvUwRKe3hg/4C1KQRYWFn4vwlhg3A==
dependencies:
comlink "^4.4.1"
commander "^10.0.1"
Expand Down Expand Up @@ -756,45 +756,47 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@noir-lang/acvm_js@0.38.0":
version "0.38.0"
resolved "https://registry.yarnpkg.com/@noir-lang/acvm_js/-/acvm_js-0.38.0.tgz#c51da3d42c969fffa19d567f187763ff165cb83e"
integrity sha512-bf5RcE7KmcjZ86j9Esm/KoHQhW3EEIv/qvKFy15jfgqPjTrXsUC7s9vif7/ZXpJKUMxu55zluNTTJtIGoNwy+A==
"@noir-lang/acvm_js@0.39.0":
version "0.39.0"
resolved "https://registry.yarnpkg.com/@noir-lang/acvm_js/-/acvm_js-0.39.0.tgz#8d05c0fee40b378beeede6f68e6e243e43bd74d2"
integrity sha512-Y77qyfamkYSIzzKFkewTwExzTvxYcRd1XBqo950ti4uKMdu18GthkOssqC7CGacwx5PdrdOGFGRJbVtjoXeKIg==

"@noir-lang/backend_barretenberg@0.22.0":
version "0.22.0"
resolved "https://registry.yarnpkg.com/@noir-lang/backend_barretenberg/-/backend_barretenberg-0.22.0.tgz#3eda26b4275dfd73ec7c47af984860efff600eb8"
integrity sha512-jS8AEajl+h3Bfa2JS2yANb4/i31LKqDOGvr4eE/86ffM5dt+GXbDmWPRfaEoACUQkDZ7RpNbCBRtujqLNU5RtQ==
"@noir-lang/backend_barretenberg@0.23.0":
version "0.23.0"
resolved "https://registry.yarnpkg.com/@noir-lang/backend_barretenberg/-/backend_barretenberg-0.23.0.tgz#19a85be2c4f83b87e8b4c03eb4e8f3e108304d51"
integrity sha512-amehMEE8kEMEbuxvPT1H9BwVQyEFFip6ajHWhgJjw/PkNB8tBzP+ekVrcEvxVerAKNikfzCEWS/kV7CEWcQNzA==
dependencies:
"@aztec/bb.js" "0.16.0"
"@noir-lang/types" "0.22.0"
"@aztec/bb.js" "0.19.0"
"@noir-lang/types" "0.23.0"
fflate "^0.8.0"

"@noir-lang/noir_js@0.22.0":
version "0.22.0"
resolved "https://registry.yarnpkg.com/@noir-lang/noir_js/-/noir_js-0.22.0.tgz#ef7e7533d7042c321cd033cd9b1b97ddcccdad99"
integrity sha512-Wnh/015ehPCa2OgOo/URcrTzaeYI0Lmm+i5GKNYtZzoPWgsaHBoK0hDtEPkg7s5NSVwX5iVAcV4V5HUgxLBUpw==
"@noir-lang/noir_js@0.23.0":
version "0.23.0"
resolved "https://registry.yarnpkg.com/@noir-lang/noir_js/-/noir_js-0.23.0.tgz#fd85e4b3f1434b8ff811ec4ceb19a5814474289f"
integrity sha512-eblqgm0PjgptYG+TkK2Dmp/Y2fEhjM5sqMam+QUQHn/2WmC+8/LO2a0FQU0t1432BGCII6/TfojQzgQobuXJAw==
dependencies:
"@noir-lang/acvm_js" "0.38.0"
"@noir-lang/noirc_abi" "0.22.0"
"@noir-lang/types" "0.22.0"
"@noir-lang/acvm_js" "0.39.0"
"@noir-lang/noirc_abi" "0.23.0"
"@noir-lang/types" "0.23.0"

"@noir-lang/[email protected]":
version "0.22.0"
resolved "https://registry.yarnpkg.com/@noir-lang/noir_wasm/-/noir_wasm-0.22.0.tgz#a5dff8b2674b7df252d3c75097e1a323297297a2"
integrity sha512-5x9XNdTqMGWnuqSa/C+YwvkSJHTigaJev8DLcpN1KfENwhboXG1nCN9A9fAKWelVwfSHjtuv+dR4TJo2x964xQ==
"@noir-lang/[email protected]":
version "0.23.0"
resolved "https://registry.yarnpkg.com/@noir-lang/noir_wasm/-/noir_wasm-0.23.0.tgz#5fe49f31d7fd67963d166439f7402a09668aec95"
integrity sha512-HL78frUo60bKrUaxOAJQtyrmBWUyiQbSp4yQkh9A/vFAnEhxehDwd8peCGKMZKX66JpRccClv52zyb5O/ECE4g==
dependencies:
pako "^2.1.0"

"@noir-lang/noirc_abi@0.22.0":
version "0.22.0"
resolved "https://registry.yarnpkg.com/@noir-lang/noirc_abi/-/noirc_abi-0.22.0.tgz#f6dd2d8440d8026d50a8df89b1dcadbbd184fb5d"
integrity sha512-Rxt0qX6IexMeDiytDAg5z2AvlUe3MOOmeUCi9d1ovqF/Cj9ZUZc+LVOdkR5r11bgAMApURFXZo3idvz3v/MO0g==
"@noir-lang/noirc_abi@0.23.0":
version "0.23.0"
resolved "https://registry.yarnpkg.com/@noir-lang/noirc_abi/-/noirc_abi-0.23.0.tgz#47dcfd724e205eadc3a6d4ebab9b11355cb0d0cb"
integrity sha512-MYBkj6hSpiimlcBmX6n/hY+y2Kk39Qh8qre5c41GZPvmC88f7MqhAdDTSsfrFnNg1pvpY5UX6/G1D8jEkT11qA==

"@noir-lang/types@0.22.0":
version "0.22.0"
resolved "https://registry.yarnpkg.com/@noir-lang/types/-/types-0.22.0.tgz#9566b105dd3ccf6a3c42e28cac12388d10c66a12"
integrity sha512-0xiQru499ZCK04Fs26eHpk5IP0f38VNKgIrVCnyjMKYQ0XTtVJQxUt/hqZV0cmqOEuCtfPcSYu2pzv1p50yNig==
"@noir-lang/types@0.23.0":
version "0.23.0"
resolved "https://registry.yarnpkg.com/@noir-lang/types/-/types-0.23.0.tgz#a99c7bc6eaffbf9e1209d1cb2ca7ecd0f047f62f"
integrity sha512-jgA4thao714WHiXVE3KS7Y2vQnH3gvsVM1cO1kQsihgmqX5VO+Kk6bI3Yck9HUvAqgcjJgSeOeBtbdTYSzjzkw==
dependencies:
"@noir-lang/noirc_abi" "0.22.0"
"@noir-lang/noirc_abi" "0.23.0"

"@nomicfoundation/[email protected]":
version "5.0.2"
Expand Down Expand Up @@ -5100,6 +5102,11 @@ p-try@^2.0.0:
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==

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==

parse-cache-control@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parse-cache-control/-/parse-cache-control-1.0.1.tgz#8eeab3e54fa56920fe16ba38f77fa21aacc2d74e"
Expand Down
Loading