diff --git a/vite-hardhat/components/index.tsx b/vite-hardhat/components/index.tsx index 3bf17d0..5234562 100644 --- a/vite-hardhat/components/index.tsx +++ b/vite-hardhat/components/index.tsx @@ -1,9 +1,6 @@ import { useState, useEffect, - SetStateAction, - ReactEventHandler, - FormEvent, ChangeEvent, } from 'react'; @@ -11,22 +8,32 @@ 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> { + 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; +} + +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() { @@ -86,7 +93,7 @@ function Component() { if (proof) { write?.({ - args: [bytesToHex(proof.proof), flattenPublicInputs(proof.publicInputs)], + args: [bytesToHex(proof.proof), proof.publicInputs], }); } }; diff --git a/vite-hardhat/index.tsx b/vite-hardhat/index.tsx index e950a1c..4e17335 100644 --- a/vite-hardhat/index.tsx +++ b/vite-hardhat/index.tsx @@ -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'; @@ -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(), diff --git a/vite-hardhat/utils/addresses.json b/vite-hardhat/utils/addresses.json index ffedda6..5c56775 100644 --- a/vite-hardhat/utils/addresses.json +++ b/vite-hardhat/utils/addresses.json @@ -1 +1 @@ -{"chainId":31337,"verifier":"0x959922be3caee4b8cd9a407cc3ac1c251c2007b1"} \ No newline at end of file +{"chainId":31337,"verifier":"0x5fc8d32690cc91d4c39d9d3abcbd16989f875707"} \ No newline at end of file