From 076dc945364bb1c43b72f58e9e8a328439a81e4c Mon Sep 17 00:00:00 2001 From: Alejandro Date: Thu, 26 Sep 2024 10:52:37 -0300 Subject: [PATCH] build-proof util --- .../src/tasks/play-level.js | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/packages/ethernaut-zeronaut/src/tasks/play-level.js b/packages/ethernaut-zeronaut/src/tasks/play-level.js index eecb3d7..a9a95ef 100644 --- a/packages/ethernaut-zeronaut/src/tasks/play-level.js +++ b/packages/ethernaut-zeronaut/src/tasks/play-level.js @@ -3,6 +3,7 @@ const output = require('ethernaut-common/src/ui/output') const { getChainId } = require('ethernaut-common/src/util/network') const { connect, getLevelContract } = require('../internal/connect') const { prompt } = require('ethernaut-common/src/ui/prompt') +const { buildProof } = require('zeronaut/utils/build-proof') require('../scopes/zeronaut') .task('play-level', 'Plays a level') @@ -36,11 +37,12 @@ require('../scopes/zeronaut') // console.log('publicInputs', publicInputs) // Build the proof - const proof = await _buildProof(circuit, inputs) + const proof = await buildProof(circuit, inputs) // console.log('proof', proof) // Check the proof const success = await level.check(proof, publicInputs) + console.log('success', success) // Submit the proof const tx = await contract.solveLevel(levelId, proof, publicInputs) @@ -52,32 +54,6 @@ require('../scopes/zeronaut') } }) -async function _buildProof(circuit, inputs) { - const { Noir } = await import('@noir-lang/noir_js') - const { BarretenbergBackend } = await import( - '@noir-lang/backend_barretenberg' - ) - const noirFrontend = new Noir(circuit) - const noirBackend = new BarretenbergBackend(circuit) - - // Generate a witness for the circuit - const { witness } = await noirFrontend.execute(inputs) - // console.log('Witness:', witness); - - // Generate a proof for the witness - const proofData = await noirBackend.generateProof(witness) - // console.log('Proof:', proofData); - - // Verify the proof - const verification = await noirBackend.verifyProof(proofData) - if (!verification) { - throw new Error('Proof verification failed') - } - // console.log('Verification:', verification) - - return '0x' + Buffer.from(proofData.proof).toString('hex') -} - async function _collectInputs(abi) { // console.log(JSON.stringify(abi, null, 2))