parent
5f3c4bbd15
commit
519cbc9373
@ -1,41 +1,42 @@ |
|||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const { expect } = require('chai') |
const { expect } = require('chai') |
||||||
import { compile, createFileManager } from '@noir-lang/noir_wasm' |
import { compile, createFileManager } from '@noir-lang/noir_wasm' |
||||||
import { Noir } from '@noir-lang/noir_js' |
import { Noir } from '@noir-lang/noir_js' |
||||||
import { UltraPlonkBackend } from '@aztec/bb.js' |
import { UltraPlonkBackend } from '@aztec/bb.js' |
||||||
|
|
||||||
async function getCircuit() { |
async function getCircuit() { |
||||||
const fm = createFileManager('/') |
const fm = createFileManager('/') |
||||||
|
|
||||||
const circuit = await remix.call('fileManager', 'readFile', 'src/main.nr') |
const circuit = await remix.call('fileManager', 'readFile', 'src/main.nr') |
||||||
const nargoToml = await remix.call('fileManager', 'readFile', 'Nargo.toml') |
const nargoToml = await remix.call('fileManager', 'readFile', 'Nargo.toml') |
||||||
const tomlBytes = new TextEncoder().encode(nargoToml) |
const tomlBytes = new TextEncoder().encode(nargoToml) |
||||||
const mainBytes = new TextEncoder().encode(circuit) |
const mainBytes = new TextEncoder().encode(circuit) |
||||||
await fm.writeFile('./src/main.nr', new Blob([mainBytes]).stream()) |
await fm.writeFile('./src/main.nr', new Blob([mainBytes]).stream()) |
||||||
await fm.writeFile('Nargo.toml', new Blob([tomlBytes]).stream()) |
await fm.writeFile('Nargo.toml', new Blob([tomlBytes]).stream()) |
||||||
|
|
||||||
const result = await compile(fm) |
const result = await compile(fm) |
||||||
if (!('program' in result)) { |
if (!('program' in result)) { |
||||||
throw new Error('Compilation failed') |
throw new Error('Compilation failed') |
||||||
} |
} |
||||||
|
|
||||||
return result.program |
return result.program |
||||||
} |
} |
||||||
|
|
||||||
describe('Noir Program Test', () => { |
describe('Noir Program Test', () => { |
||||||
it('should compile, execute, prove, and verify', async () => { |
it('should compile, execute, prove, and verify', async () => { |
||||||
const noir_program = await getCircuit() |
const noir_program = await getCircuit() |
||||||
|
|
||||||
const inputs = { a: 20, b: 40 } |
const inputs = { a: 20, b: 40 } |
||||||
|
|
||||||
// JS Proving
|
// JS Proving
|
||||||
const program = new Noir(noir_program) |
const program = new Noir(noir_program) |
||||||
const { witness } = await program.execute(inputs) |
const { witness } = await program.execute(inputs) |
||||||
|
|
||||||
const backend = new UltraPlonkBackend(noir_program.bytecode) |
const backend = new UltraPlonkBackend(noir_program.bytecode) |
||||||
const proof = await backend.generateProof(witness) |
const proof = await backend.generateProof(witness) |
||||||
|
|
||||||
// JS verification
|
// JS verification
|
||||||
const verified = await backend.verifyProof(proof) |
const verified = await backend.verifyProof(proof) |
||||||
expect(verified, 'Proof fails verification in JS').to.be.true |
expect(verified, 'Proof fails verification in JS').to.be.true |
||||||
}) |
}) |
||||||
}) |
}) |
@ -1,51 +1,52 @@ |
|||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const { expect } = require('chai') |
const { expect } = require('chai') |
||||||
import { compile, createFileManager } from '@noir-lang/noir_wasm' |
import { compile, createFileManager } from '@noir-lang/noir_wasm' |
||||||
import { Noir } from '@noir-lang/noir_js' |
import { Noir } from '@noir-lang/noir_js' |
||||||
import { UltraPlonkBackend } from '@aztec/bb.js' |
import { UltraPlonkBackend } from '@aztec/bb.js' |
||||||
|
|
||||||
async function getCircuit() { |
async function getCircuit() { |
||||||
const fm = createFileManager('/') |
const fm = createFileManager('/') |
||||||
|
|
||||||
const circuit = await remix.call('fileManager', 'readFile', 'src/main.nr') |
const circuit = await remix.call('fileManager', 'readFile', 'src/main.nr') |
||||||
const nargoToml = await remix.call('fileManager', 'readFile', 'Nargo.toml') |
const nargoToml = await remix.call('fileManager', 'readFile', 'Nargo.toml') |
||||||
const tomlBytes = new TextEncoder().encode(nargoToml) |
const tomlBytes = new TextEncoder().encode(nargoToml) |
||||||
const mainBytes = new TextEncoder().encode(circuit) |
const mainBytes = new TextEncoder().encode(circuit) |
||||||
await fm.writeFile('./src/main.nr', new Blob([mainBytes]).stream()) |
await fm.writeFile('./src/main.nr', new Blob([mainBytes]).stream()) |
||||||
await fm.writeFile('Nargo.toml', new Blob([tomlBytes]).stream()) |
await fm.writeFile('Nargo.toml', new Blob([tomlBytes]).stream()) |
||||||
|
|
||||||
const result = await compile(fm) |
|
||||||
if (!('program' in result)) { |
|
||||||
throw new Error('Compilation failed') |
|
||||||
} |
|
||||||
|
|
||||||
return result.program |
const result = await compile(fm) |
||||||
|
if (!('program' in result)) { |
||||||
|
throw new Error('Compilation failed') |
||||||
|
} |
||||||
|
|
||||||
|
return result.program |
||||||
} |
} |
||||||
|
|
||||||
describe('Noir Program Test', () => { |
describe('Noir Program Test', () => { |
||||||
it('should compile, execute, prove, and verify', async () => { |
it('should compile, execute, prove, and verify', async () => { |
||||||
const noir_program = await getCircuit() |
const noir_program = await getCircuit() |
||||||
|
|
||||||
const inputs = {
|
const inputs = { |
||||||
pub_key: '', |
pub_key: '', |
||||||
signature: '', |
signature: '', |
||||||
hashed_message: '', |
hashed_message: '', |
||||||
nullifier: '', |
nullifier: '', |
||||||
merkle_path: '', |
merkle_path: '', |
||||||
index: '', |
index: '', |
||||||
merkle_root: '', |
merkle_root: '', |
||||||
claimer_priv: '', |
claimer_priv: '', |
||||||
claimer_pub: '' |
claimer_pub: '' |
||||||
} |
} |
||||||
|
|
||||||
// JS Proving
|
// JS Proving
|
||||||
const program = new Noir(noir_program) |
const program = new Noir(noir_program) |
||||||
const { witness } = await program.execute(inputs) |
const { witness } = await program.execute(inputs) |
||||||
|
|
||||||
const backend = new UltraPlonkBackend(noir_program.bytecode) |
const backend = new UltraPlonkBackend(noir_program.bytecode) |
||||||
const proof = await backend.generateProof(witness) |
const proof = await backend.generateProof(witness) |
||||||
|
|
||||||
// JS verification
|
// JS verification
|
||||||
const verified = await backend.verifyProof(proof) |
const verified = await backend.verifyProof(proof) |
||||||
expect(verified, 'Proof fails verification in JS').to.be.true |
expect(verified, 'Proof fails verification in JS').to.be.true |
||||||
}) |
}) |
||||||
}) |
}) |
Loading…
Reference in new issue