Skip to content

Commit

Permalink
fixing noir_wasm complains
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello committed Feb 6, 2024
1 parent 9011ca0 commit 7a34af1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
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
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":"0x959922be3caee4b8cd9a407cc3ac1c251c2007b1"}
{"chainId":31337,"verifier":"0x5fc8d32690cc91d4c39d9d3abcbd16989f875707"}

0 comments on commit 7a34af1

Please sign in to comment.