From 86f1f52d4ca3dadff5e0763f466c4e8d2b923ecd Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 7 May 2024 16:30:24 +0000 Subject: [PATCH 1/6] Enable client proof tests --- .github/workflows/ci.yml | 16 ++++++++ .../client_prover_integration.test.ts | 8 ++-- .../bb_prover/bb_native_proof_creator.ts | 41 ++++++++++--------- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d6db808cf3d..c1a1bc4db237 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -244,6 +244,22 @@ jobs: timeout-minutes: 25 run: earthly-ci --no-output ./yarn-project/+prover-client-test + client-proof-tests: + needs: build + runs-on: ${{ github.actor }}-x86 + steps: + - { + uses: actions/checkout@v4, + with: { ref: "${{ github.event.pull_request.head.sha }}" }, + } + - uses: ./.github/ci-setup-action + with: + dockerhub_password: "${{ secrets.DOCKERHUB_PASSWORD }}" + concurrency_key: client-proof-tests-${{ github.actor }}-x86 + - name: "Client Proof Tests" + timeout-minutes: 25 + run: earthly-ci --no-output ./yarn-project/+run-e2e --test=client_prover_integration/client_prover_integration.test.ts + build-acir-tests: needs: build runs-on: ${{ github.actor }}-x86 diff --git a/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts b/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts index ec6c32d11a6c..b1469d3d005f 100644 --- a/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts +++ b/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts @@ -6,11 +6,9 @@ import { ClientProverTest } from './client_prover_test.js'; const TIMEOUT = 300_000; -async function verifyProof(_1: ClientProtocolArtifact, _2: Tx, _3: BBNativeProofCreator) { - // TODO(@PhilWindle): Will verify proof once the circuits are fixed - await Promise.resolve(); - //const result = await proofCreator.verifyProof(circuitType, tx.proof); - expect(true).toBeTruthy(); +async function verifyProof(circuitType: ClientProtocolArtifact, tx: Tx, proofCreator: BBNativeProofCreator) { + const result = await proofCreator.verifyProof(circuitType, tx.proof); + expect(result).toBeTruthy(); } describe('client_prover_integration', () => { diff --git a/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts b/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts index 7f4fba37064c..79e1e4b9e676 100644 --- a/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts +++ b/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts @@ -24,8 +24,8 @@ import { convertPrivateKernelInnerOutputsFromWitnessMap, convertPrivateKernelTailForPublicOutputsFromWitnessMap, convertPrivateKernelTailOutputsFromWitnessMap, - executeTail, - executeTailForPublic, + convertPrivateKernelTailInputsToWitnessMap, + convertPrivateKernelTailToPublicInputsToWitnessMap, } from '@aztec/noir-protocol-circuits-types'; import { type ACVMField, WASMSimulator } from '@aztec/simulator'; import { type NoirCompiledCircuit } from '@aztec/types/noir'; @@ -294,8 +294,9 @@ export async function generateKeyForNoirCircuit( await fs.writeFile(bytecodePath, bytecode); // args are the output path and the input bytecode path - const args = ['-o', outputPath, '-b', bytecodePath]; + const args = ['-o', `${outputPath}/${VK_FILENAME}`, '-b', bytecodePath]; const timer = new Timer(); + log(`Writing verification key: args ${args.join()}`); let result = await executeBB(pathToBB, `write_${key}`, args, log); // If we succeeded and the type of key if verification, have bb write the 'fields' version too if (result == BB_RESULT.SUCCESS && key === 'vk') { @@ -468,25 +469,25 @@ export class BBNativeProofCreator implements ProofCreator { public async createProofTail( inputs: PrivateKernelTailCircuitPrivateInputs, ): Promise> { - // if (!inputs.isForPublic()) { - // const witnessMap = convertPrivateKernelTailInputsToWitnessMap(inputs); - // return await this.createSafeProof(witnessMap, 'PrivateKernelTailArtifact'); - // } - if (!inputs.isForPublic()) { - const result = await executeTail(inputs); - return { - publicInputs: result, - proof: makeEmptyProof(), - }; + const witnessMap = convertPrivateKernelTailInputsToWitnessMap(inputs); + return await this.createSafeProof(witnessMap, 'PrivateKernelTailArtifact'); } - // const witnessMap = convertPrivateKernelTailToPublicInputsToWitnessMap(inputs); - // return await this.createSafeProof(witnessMap, 'PrivateKernelTailToPublicArtifact'); - const result = await executeTailForPublic(inputs); - return { - publicInputs: result, - proof: makeEmptyProof(), - }; + + // if (!inputs.isForPublic()) { + // const result = await executeTail(inputs); + // return { + // publicInputs: result, + // proof: makeEmptyProof(), + // }; + // } + const witnessMap = convertPrivateKernelTailToPublicInputsToWitnessMap(inputs); + return await this.createSafeProof(witnessMap, 'PrivateKernelTailToPublicArtifact'); + // const result = await executeTailForPublic(inputs); + // return { + // publicInputs: result, + // proof: makeEmptyProof(), + // }; } public async createAppCircuitProof(partialWitness: Map, bytecode: Buffer): Promise { From 451842786e41cc29693bdf14a3637fb2fe335757 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 7 May 2024 18:24:17 +0000 Subject: [PATCH 2/6] Fixes --- .../client_prover_integration.test.ts | 5 ++--- .../bb_prover/bb_native_proof_creator.ts | 13 ------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts b/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts index b1469d3d005f..91e49843e3ce 100644 --- a/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts +++ b/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts @@ -7,8 +7,7 @@ import { ClientProverTest } from './client_prover_test.js'; const TIMEOUT = 300_000; async function verifyProof(circuitType: ClientProtocolArtifact, tx: Tx, proofCreator: BBNativeProofCreator) { - const result = await proofCreator.verifyProof(circuitType, tx.proof); - expect(result).toBeTruthy(); + await expect(proofCreator.verifyProof(circuitType, tx.proof)).resolves.not.toThrow(); } describe('client_prover_integration', () => { @@ -61,7 +60,7 @@ describe('client_prover_integration', () => { const balance0 = await provenAsset.methods.balance_of_public(accounts[0].address).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); - const interaction = provenAsset.methods.transfer(accounts[0].address, accounts[1].address, amount, 0); + const interaction = provenAsset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, 0); const provenTx = await interaction.prove(); // This will recursively verify all app and kernel circuits involved in the private stage of this transaction! diff --git a/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts b/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts index 79e1e4b9e676..37dab504c69d 100644 --- a/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts +++ b/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts @@ -473,21 +473,8 @@ export class BBNativeProofCreator implements ProofCreator { const witnessMap = convertPrivateKernelTailInputsToWitnessMap(inputs); return await this.createSafeProof(witnessMap, 'PrivateKernelTailArtifact'); } - - // if (!inputs.isForPublic()) { - // const result = await executeTail(inputs); - // return { - // publicInputs: result, - // proof: makeEmptyProof(), - // }; - // } const witnessMap = convertPrivateKernelTailToPublicInputsToWitnessMap(inputs); return await this.createSafeProof(witnessMap, 'PrivateKernelTailToPublicArtifact'); - // const result = await executeTailForPublic(inputs); - // return { - // publicInputs: result, - // proof: makeEmptyProof(), - // }; } public async createAppCircuitProof(partialWitness: Map, bytecode: Buffer): Promise { From e304c7bf608dce75dcf139d4bf083daa212a5774 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 7 May 2024 20:30:59 +0000 Subject: [PATCH 3/6] WIP --- .../pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts b/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts index 37dab504c69d..12b1be9a6623 100644 --- a/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts +++ b/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts @@ -23,8 +23,8 @@ import { convertPrivateKernelInnerInputsToWitnessMap, convertPrivateKernelInnerOutputsFromWitnessMap, convertPrivateKernelTailForPublicOutputsFromWitnessMap, - convertPrivateKernelTailOutputsFromWitnessMap, convertPrivateKernelTailInputsToWitnessMap, + convertPrivateKernelTailOutputsFromWitnessMap, convertPrivateKernelTailToPublicInputsToWitnessMap, } from '@aztec/noir-protocol-circuits-types'; import { type ACVMField, WASMSimulator } from '@aztec/simulator'; @@ -296,7 +296,6 @@ export async function generateKeyForNoirCircuit( // args are the output path and the input bytecode path const args = ['-o', `${outputPath}/${VK_FILENAME}`, '-b', bytecodePath]; const timer = new Timer(); - log(`Writing verification key: args ${args.join()}`); let result = await executeBB(pathToBB, `write_${key}`, args, log); // If we succeeded and the type of key if verification, have bb write the 'fields' version too if (result == BB_RESULT.SUCCESS && key === 'vk') { From af5a94ff3e779adcbc17e1c0dcda7bcb7c46a3df Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 7 May 2024 21:39:09 +0000 Subject: [PATCH 4/6] Update ci --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02e61c8761eb..e92f513a0236 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -477,6 +477,7 @@ jobs: barretenberg-acir-tests-sol, noir-test, noir-packages-test, + client-proof-tests, ] if: always() steps: From e540f1851564ac9f945772df5bfbb95d7ca52db4 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 7 May 2024 21:41:49 +0000 Subject: [PATCH 5/6] Remove test local timeout --- .../client_prover_integration.test.ts | 70 ++++++++----------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts b/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts index 91e49843e3ce..ed244b2da643 100644 --- a/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts +++ b/yarn-project/end-to-end/src/client_prover_integration/client_prover_integration.test.ts @@ -4,8 +4,6 @@ import { type BBNativeProofCreator } from '@aztec/pxe'; import { ClientProverTest } from './client_prover_test.js'; -const TIMEOUT = 300_000; - async function verifyProof(circuitType: ClientProtocolArtifact, tx: Tx, proofCreator: BBNativeProofCreator) { await expect(proofCreator.verifyProof(circuitType, tx.proof)).resolves.not.toThrow(); } @@ -29,47 +27,39 @@ describe('client_prover_integration', () => { await t.tokenSim.check(); }); - it( - 'private transfer less than balance', - async () => { - logger.info( - `Starting test using function: ${provenAsset.address}:${provenAsset.methods.balance_of_private.selector}`, - ); - const balance0 = await provenAsset.methods.balance_of_private(accounts[0].address).simulate(); - const amount = balance0 / 2n; - expect(amount).toBeGreaterThan(0n); - const interaction = provenAsset.methods.transfer(accounts[0].address, accounts[1].address, amount, 0); - const provenTx = await interaction.prove(); + it('private transfer less than balance', async () => { + logger.info( + `Starting test using function: ${provenAsset.address}:${provenAsset.methods.balance_of_private.selector}`, + ); + const balance0 = await provenAsset.methods.balance_of_private(accounts[0].address).simulate(); + const amount = balance0 / 2n; + expect(amount).toBeGreaterThan(0n); + const interaction = provenAsset.methods.transfer(accounts[0].address, accounts[1].address, amount, 0); + const provenTx = await interaction.prove(); - // This will recursively verify all app and kernel circuits involved in the private stage of this transaction! - logger.info(`Verifying kernel tail proof`); - await verifyProof('PrivateKernelTailArtifact', provenTx, proofCreator!); + // This will recursively verify all app and kernel circuits involved in the private stage of this transaction! + logger.info(`Verifying kernel tail proof`); + await verifyProof('PrivateKernelTailArtifact', provenTx, proofCreator!); - await interaction.send().wait(); - tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount); - }, - TIMEOUT, - ); + await interaction.send().wait(); + tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount); + }); - it( - 'public transfer less than balance', - async () => { - logger.info( - `Starting test using function: ${provenAsset.address}:${provenAsset.methods.balance_of_public.selector}`, - ); - const balance0 = await provenAsset.methods.balance_of_public(accounts[0].address).simulate(); - const amount = balance0 / 2n; - expect(amount).toBeGreaterThan(0n); - const interaction = provenAsset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, 0); - const provenTx = await interaction.prove(); + it('public transfer less than balance', async () => { + logger.info( + `Starting test using function: ${provenAsset.address}:${provenAsset.methods.balance_of_public.selector}`, + ); + const balance0 = await provenAsset.methods.balance_of_public(accounts[0].address).simulate(); + const amount = balance0 / 2n; + expect(amount).toBeGreaterThan(0n); + const interaction = provenAsset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, 0); + const provenTx = await interaction.prove(); - // This will recursively verify all app and kernel circuits involved in the private stage of this transaction! - logger.info(`Verifying kernel tail to public proof`); - await verifyProof('PrivateKernelTailToPublicArtifact', provenTx, proofCreator!); + // This will recursively verify all app and kernel circuits involved in the private stage of this transaction! + logger.info(`Verifying kernel tail to public proof`); + await verifyProof('PrivateKernelTailToPublicArtifact', provenTx, proofCreator!); - await interaction.send().wait(); - tokenSim.transferPublic(accounts[0].address, accounts[1].address, amount); - }, - TIMEOUT, - ); + await interaction.send().wait(); + tokenSim.transferPublic(accounts[0].address, accounts[1].address, amount); + }); }); From e89543f88b5796ac67e71d7161f7320dc40b6262 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Wed, 8 May 2024 07:42:41 +0000 Subject: [PATCH 6/6] Formatting --- .../pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts b/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts index 12b1be9a6623..15eed0996a9c 100644 --- a/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts +++ b/yarn-project/pxe/src/kernel_prover/bb_prover/bb_native_proof_creator.ts @@ -8,7 +8,6 @@ import { type PrivateKernelTailCircuitPublicInputs, Proof, type VERIFICATION_KEY_LENGTH_IN_FIELDS, - makeEmptyProof, } from '@aztec/circuits.js'; import { siloNoteHash } from '@aztec/circuits.js/hash'; import { randomBytes, sha256 } from '@aztec/foundation/crypto';