Skip to content

Commit

Permalink
fix: Enable client proof tests (#6249)
Browse files Browse the repository at this point in the history
This PR enables the client side proving integration test.
  • Loading branch information
PhilWindle authored May 8, 2024
1 parent ce2d43c commit 6d3a800
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 66 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,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
Expand Down Expand Up @@ -461,6 +477,7 @@ jobs:
barretenberg-acir-tests-sol,
noir-test,
noir-packages-test,
client-proof-tests,
]
if: always()
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ import { type BBNativeProofCreator } from '@aztec/pxe';

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) {
await expect(proofCreator.verifyProof(circuitType, tx.proof)).resolves.not.toThrow();
}

describe('client_prover_integration', () => {
Expand All @@ -32,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(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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -23,9 +22,9 @@ import {
convertPrivateKernelInnerInputsToWitnessMap,
convertPrivateKernelInnerOutputsFromWitnessMap,
convertPrivateKernelTailForPublicOutputsFromWitnessMap,
convertPrivateKernelTailInputsToWitnessMap,
convertPrivateKernelTailOutputsFromWitnessMap,
executeTail,
executeTailForPublic,
convertPrivateKernelTailToPublicInputsToWitnessMap,
} from '@aztec/noir-protocol-circuits-types';
import { type ACVMField, WASMSimulator } from '@aztec/simulator';
import { type NoirCompiledCircuit } from '@aztec/types/noir';
Expand Down Expand Up @@ -294,7 +293,7 @@ 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();
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
Expand Down Expand Up @@ -468,25 +467,12 @@ export class BBNativeProofCreator implements ProofCreator {
public async createProofTail(
inputs: PrivateKernelTailCircuitPrivateInputs,
): Promise<ProofOutput<PrivateKernelTailCircuitPublicInputs>> {
// 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(),
};
const witnessMap = convertPrivateKernelTailToPublicInputsToWitnessMap(inputs);
return await this.createSafeProof(witnessMap, 'PrivateKernelTailToPublicArtifact');
}

public async createAppCircuitProof(partialWitness: Map<number, ACVMField>, bytecode: Buffer): Promise<Proof> {
Expand Down

0 comments on commit 6d3a800

Please sign in to comment.