Skip to content

Commit

Permalink
Merge branch 'master' into lh/5899-body-ciphertext
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind authored May 8, 2024
2 parents 9723426 + 1c74387 commit 14f79c5
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 67 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
31 changes: 31 additions & 0 deletions noir-projects/aztec-nr/aztec/src/context/interface.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use dep::protocol_types::{abis::function_selector::FunctionSelector, address::{AztecAddress, EthAddress}, traits::Deserialize};

use crate::hash::hash_args;
use crate::context::private_context::PrivateContext;
use crate::context::public_context::PublicContext;
use crate::context::avm_context::AvmContext;
Expand Down Expand Up @@ -229,6 +230,21 @@ impl<T> AvmCallInterface<T> {
let returns = context.delegate_call_public_function(self.target_contract, self.selector, self.args);
returns.deserialize_into()
}

pub fn enqueue(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
context.call_public_function_with_packed_args(self.target_contract, self.selector, args_hash, false, false)
}

pub fn static_enqueue(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
context.call_public_function_with_packed_args(self.target_contract, self.selector, args_hash, true, false)
}

pub fn delegate_enqueue(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
context.call_public_function_with_packed_args(self.target_contract, self.selector, args_hash, false, true)
}
}

struct AvmVoidCallInterface {
Expand Down Expand Up @@ -258,4 +274,19 @@ impl AvmVoidCallInterface {
let returns = context.delegate_call_public_function(self.target_contract, self.selector, self.args);
returns.assert_empty()
}

pub fn enqueue(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
context.call_public_function_with_packed_args(self.target_contract, self.selector, args_hash, false, false)
}

pub fn static_enqueue(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
context.call_public_function_with_packed_args(self.target_contract, self.selector, args_hash, true, false)
}

pub fn delegate_enqueue(self, context: &mut PrivateContext) {
let args_hash = hash_args(self.args);
context.call_public_function_with_packed_args(self.target_contract, self.selector, args_hash, false, true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract AvmAcvmInteropTest {
}

#[aztec(public)]
fn new_nullifier_acvm(nullifier: Field) -> pub Field {
fn new_nullifier_acvm(nullifier: Field) {
context.push_new_nullifier(nullifier, 0);
}

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 14f79c5

Please sign in to comment.