Skip to content

Commit

Permalink
Merge branch 'master' into mm/pg-perturbator
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Oct 7, 2023
2 parents dd258af + 4881414 commit d94de65
Show file tree
Hide file tree
Showing 61 changed files with 772 additions and 731 deletions.
19 changes: 19 additions & 0 deletions barretenberg/cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@
}
},
{
"name": "gcc13",
"displayName": "Build with GCC-13",
"description": "Build with globally installed GCC-13",
"inherits": "default",
"environment": {
"CC": "gcc-13",
"CXX": "g++-13"
}
}, {
"name": "bench",
"displayName": "Build benchmarks",
"description": "Build default preset but with a special benchmark directory",
Expand Down Expand Up @@ -212,6 +221,11 @@
"inherits": "default",
"configurePreset": "gcc10"
},
{
"name": "gcc13",
"inherits": "default",
"configurePreset": "gcc13"
},
{
"name": "bench",
"inherits": "clang16",
Expand Down Expand Up @@ -297,6 +311,11 @@
"inherits": "default",
"configurePreset": "gcc10"
},
{
"name": "gcc13",
"inherits": "default",
"configurePreset": "gcc13"
},
{
"name": "bench",
"inherits": "clang16",
Expand Down
15 changes: 15 additions & 0 deletions scripts/ci/aggregate_e2e_benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const {
CIRCUIT_OUTPUT_SIZE,
CIRCUIT_INPUT_SIZE,
CIRCUIT_SIMULATED,
NOTE_SUCCESSFUL_DECRYPTING_TIME,
NOTE_TRIAL_DECRYPTING_TIME,
NOTE_PROCESSOR_CAUGHT_UP,
ROLLUP_SIZES,
BENCHMARK_FILE_JSON,
} = require("./benchmark_shared.js");
Expand Down Expand Up @@ -75,6 +78,16 @@ function processCircuitSimulation(entry, results) {
append(results, CIRCUIT_OUTPUT_SIZE, bucket, entry.outputSize);
}

// Processes an entry with event name 'note-processor-caught-up' and updates results
// Buckets are rollup sizes
function processNoteProcessorCaughtUp(entry, results) {
const { seen, decrypted } = entry;
if (ROLLUP_SIZES.includes(decrypted))
append(results, NOTE_SUCCESSFUL_DECRYPTING_TIME, decrypted, entry.duration);
if (ROLLUP_SIZES.includes(seen) && decrypted === 0)
append(results, NOTE_TRIAL_DECRYPTING_TIME, seen, entry.duration);
}

// Processes a parsed entry from a logfile and updates results
function processEntry(entry, results) {
switch (entry.eventName) {
Expand All @@ -84,6 +97,8 @@ function processEntry(entry, results) {
return processRollupBlockSynced(entry, results);
case CIRCUIT_SIMULATED:
return processCircuitSimulation(entry, results);
case NOTE_PROCESSOR_CAUGHT_UP:
return processNoteProcessorCaughtUp(entry, results);
default:
return;
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/ci/benchmark_shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ module.exports = {
CIRCUIT_SIMULATION_TIME: "circuit_simulation_time_in_ms",
CIRCUIT_INPUT_SIZE: "circuit_input_size_in_bytes",
CIRCUIT_OUTPUT_SIZE: "circuit_output_size_in_bytes",
NOTE_SUCCESSFUL_DECRYPTING_TIME: "note_successful_decrypting_time",
NOTE_TRIAL_DECRYPTING_TIME: "note_unsuccessful_decrypting_time",
// Events to track
L2_BLOCK_PUBLISHED_TO_L1: "rollup-published-to-l1",
L2_BLOCK_SYNCED: "l2-block-handled",
CIRCUIT_SIMULATED: "circuit-simulation",
NOTE_PROCESSOR_CAUGHT_UP: "note-processor-caught-up",
// Other
ROLLUP_SIZES,
BENCHMARK_FILE_JSON,
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec-nr/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.nr linguist-language=Rust
3 changes: 0 additions & 3 deletions yarn-project/aztec-nr/authwit/src/account.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
mod entrypoint;
mod auth;

use dep::aztec::context::{PrivateContext, PublicContext, Context};
use dep::aztec::selector::compute_selector;
use dep::aztec::state_vars::{map::Map, public_state::PublicState};
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/aztec-sandbox/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project AS yarn-project

ARG COMMIT_TAG=""

# Start a new image as we need arch specific.
FROM node:18-alpine as builder
ARG COMMIT_TAG=""
RUN apk add jq
COPY --from=yarn-project /usr/src/ /usr/src/

Expand Down
10 changes: 3 additions & 7 deletions yarn-project/aztec-sandbox/src/examples/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@ export async function deployAndInitializeNonNativeL2TokenContracts(
});

// deploy l2 contract and attach to portal
const tx = NonNativeTokenContract.deploy(wallet, initialBalance, owner).send({
portalContract: tokenPortalAddress,
});
await tx.isMined({ interval: 0.1 });
const receipt = await tx.getReceipt();
const l2Contract = await NonNativeTokenContract.at(receipt.contractAddress!, wallet);
await l2Contract.attach(tokenPortalAddress);
const l2Contract = await NonNativeTokenContract.deploy(wallet, initialBalance, owner)
.send({ portalContract: tokenPortalAddress })
.deployed();
const l2TokenAddress = l2Contract.address.toString() as `0x${string}`;

// initialize portal
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/aztec.js/src/abis/ecdsa_account_contract.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions yarn-project/aztec.js/src/abis/schnorr_account_contract.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions yarn-project/aztec.js/src/account/manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { PublicKey, getContractDeploymentInfo } from '@aztec/circuits.js';
import { Fr } from '@aztec/foundation/fields';
import { CompleteAddress, GrumpkinPrivateKey, PXE } from '@aztec/types';

import { AccountWallet, ContractDeployer, DeployMethod, WaitOpts, generatePublicKey } from '../../index.js';
import {
AccountWalletWithPrivateKey,
ContractDeployer,
DeployMethod,
WaitOpts,
generatePublicKey,
} from '../../index.js';
import { AccountContract, Salt } from '../index.js';
import { AccountInterface } from '../interface.js';
import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
Expand Down Expand Up @@ -73,9 +79,9 @@ export class AccountManager {
* instances to be interacted with from this account.
* @returns A Wallet instance.
*/
public async getWallet(): Promise<AccountWallet> {
public async getWallet(): Promise<AccountWalletWithPrivateKey> {
const entrypoint = await this.getAccount();
return new AccountWallet(this.pxe, entrypoint);
return new AccountWalletWithPrivateKey(this.pxe, entrypoint, this.encryptionPrivateKey);
}

/**
Expand All @@ -84,7 +90,7 @@ export class AccountManager {
* Use the returned wallet to create Contract instances to be interacted with from this account.
* @returns A Wallet instance.
*/
public async register(): Promise<AccountWallet> {
public async register(): Promise<AccountWalletWithPrivateKey> {
const completeAddress = await this.getCompleteAddress();
await this.pxe.registerAccount(this.encryptionPrivateKey, completeAddress.partialAddress);
return this.getWallet();
Expand Down Expand Up @@ -132,7 +138,7 @@ export class AccountManager {
* @param opts - Options to wait for the tx to be mined.
* @returns A Wallet instance.
*/
public async waitDeploy(opts: WaitOpts = {}): Promise<AccountWallet> {
public async waitDeploy(opts: WaitOpts = {}): Promise<AccountWalletWithPrivateKey> {
await this.deploy().then(tx => tx.wait(opts));
return this.getWallet();
}
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec.js/src/account/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { CompleteAddress, GrumpkinScalar } from '@aztec/circuits.js';
import { PXE } from '@aztec/types';

import { getSchnorrAccount } from '../index.js';
import { AccountWallet } from '../wallet/account_wallet.js';
import { AccountWalletWithPrivateKey } from '../wallet/account_wallet.js';

/**
* Deploys and registers a new account using random private keys and returns the associated Schnorr account wallet. Useful for testing.
* @param pxe - PXE.
* @returns - A wallet for a fresh account.
*/
export function createAccount(pxe: PXE): Promise<AccountWallet> {
export function createAccount(pxe: PXE): Promise<AccountWalletWithPrivateKey> {
return getSchnorrAccount(pxe, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy();
}

Expand All @@ -30,7 +30,7 @@ export async function createRecipient(pxe: PXE): Promise<CompleteAddress> {
* @param numberOfAccounts - How many accounts to create.
* @returns The created account wallets.
*/
export async function createAccounts(pxe: PXE, numberOfAccounts = 1): Promise<AccountWallet[]> {
export async function createAccounts(pxe: PXE, numberOfAccounts = 1): Promise<AccountWalletWithPrivateKey[]> {
const accounts = [];

// Prepare deployments
Expand Down
35 changes: 1 addition & 34 deletions yarn-project/aztec.js/src/contract/contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { AztecAddress, CompleteAddress, EthAddress } from '@aztec/circuits.js';
import { L1ContractAddresses } from '@aztec/ethereum';
import { ABIParameterVisibility, ContractAbi, FunctionType } from '@aztec/foundation/abi';
import {
DeployedContract,
ExtendedContractData,
NodeInfo,
Tx,
TxExecutionRequest,
TxHash,
TxReceipt,
randomContractAbi,
randomDeployedContract,
} from '@aztec/types';
import { ExtendedContractData, NodeInfo, Tx, TxExecutionRequest, TxHash, TxReceipt } from '@aztec/types';

import { MockProxy, mock } from 'jest-mock-extended';

Expand Down Expand Up @@ -155,27 +145,4 @@ describe('Contract Class', () => {
expect(() => fooContract.methods.bar().view()).toThrow();
expect(() => fooContract.methods.baz().view()).toThrow();
});

it('should add contract and dependencies to PXE', async () => {
const entry: DeployedContract = {
abi: randomContractAbi(),
completeAddress: resolvedExtendedContractData.getCompleteAddress(),
portalContract: EthAddress.random(),
};
const contract = await Contract.at(entry.completeAddress.address, entry.abi, wallet);

{
await contract.attach(entry.portalContract);
expect(wallet.addContracts).toHaveBeenCalledTimes(1);
expect(wallet.addContracts).toHaveBeenCalledWith([entry]);
wallet.addContracts.mockClear();
}

{
const dependencies = [await randomDeployedContract(), await randomDeployedContract()];
await contract.attach(entry.portalContract, dependencies);
expect(wallet.addContracts).toHaveBeenCalledTimes(1);
expect(wallet.addContracts).toHaveBeenCalledWith([entry, ...dependencies]);
}
});
});
8 changes: 7 additions & 1 deletion yarn-project/aztec.js/src/contract/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ export class Contract extends ContractBase {
* @param address - The deployed contract's address.
* @param abi - The Application Binary Interface for the contract.
* @param wallet - The wallet to use when interacting with the contract.
* @param portalContract - The portal contract address on L1, if any.
* @returns A promise that resolves to a new Contract instance.
*/
public static async at(address: AztecAddress, abi: ContractAbi, wallet: Wallet): Promise<Contract> {
const extendedContractData = await wallet.getExtendedContractData(address);
if (extendedContractData === undefined) {
throw new Error('Contract ' + address.toString() + ' is not deployed');
}
return new Contract(extendedContractData.getCompleteAddress(), abi, wallet);
return new Contract(
extendedContractData.getCompleteAddress(),
abi,
wallet,
extendedContractData.contractData.portalContractAddress,
);
}

/**
Expand Down
36 changes: 7 additions & 29 deletions yarn-project/aztec.js/src/contract/contract_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,21 @@ export type ContractMethod = ((...args: any[]) => ContractFunctionInteraction) &
/**
* Abstract implementation of a contract extended by the Contract class and generated contract types.
*/
export class ContractBase {
export class ContractBase implements DeployedContract {
/**
* An object containing contract methods mapped to their respective names.
*/
public methods: { [name: string]: ContractMethod } = {};

protected constructor(
/**
* The deployed contract's complete address.
*/
/** The deployed contract's complete address. */
public readonly completeAddress: CompleteAddress,
/**
* The Application Binary Interface for the contract.
*/
/** The Application Binary Interface for the contract. */
public readonly abi: ContractAbi,
/**
* The wallet.
*/
/** The wallet used for interacting with this contract. */
protected wallet: Wallet,
/** The portal contract address on L1, if any. */
public readonly portalContract: EthAddress,
) {
abi.functions.forEach((f: FunctionAbi) => {
const interactionFunction = (...args: any[]) => {
Expand Down Expand Up @@ -69,24 +65,6 @@ export class ContractBase {
* @returns A new contract instance.
*/
public withWallet(wallet: Wallet): this {
return new ContractBase(this.completeAddress, this.abi, wallet) as this;
}

/**
* Attach the current contract instance to a portal contract and optionally add its dependencies.
* The function will return a promise that resolves when all contracts have been added to the PXE.
* This is useful when you need to interact with a deployed contract that has multiple nested contracts.
*
* @param portalContract - The Ethereum address of the portal contract.
* @param dependencies - An optional array of additional DeployedContract instances to be attached.
* @returns A promise that resolves when all contracts are successfully added to the PXE.
*/
public attach(portalContract: EthAddress, dependencies: DeployedContract[] = []) {
const deployedContract: DeployedContract = {
abi: this.abi,
completeAddress: this.completeAddress,
portalContract,
};
return this.wallet.addContracts([deployedContract, ...dependencies]);
return new ContractBase(this.completeAddress, this.abi, wallet, this.portalContract) as this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type DeployTxReceipt<TContract extends ContractBase = Contract> = FieldsO
/**
* A contract deployment transaction sent to the network, extending SentTx with methods to create a contract instance.
*/
export class DeploySentTx<TContract extends ContractBase = Contract> extends SentTx {
export class DeploySentTx<TContract extends Contract = Contract> extends SentTx {
constructor(private abi: ContractAbi, wallet: PXE | Wallet, txHashPromise: Promise<TxHash>) {
super(wallet, txHashPromise);
}
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { sleep } from '@aztec/foundation/sleep';
import zip from 'lodash.zip';

import SchnorrAccountContractAbi from '../abis/schnorr_account_contract.json' assert { type: 'json' };
import { AccountWallet, PXE, createPXEClient, getSchnorrAccount } from '../index.js';
import { AccountWalletWithPrivateKey, PXE, createPXEClient, getSchnorrAccount } from '../index.js';

export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [
GrumpkinScalar.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'),
Expand All @@ -25,7 +25,7 @@ export const { PXE_URL = 'http://localhost:8080' } = process.env;
* @param pxe - PXE instance.
* @returns A set of AccountWallet implementations for each of the initial accounts.
*/
export function getSandboxAccountsWallets(pxe: PXE): Promise<AccountWallet[]> {
export function getSandboxAccountsWallets(pxe: PXE): Promise<AccountWalletWithPrivateKey[]> {
return Promise.all(
zip(INITIAL_SANDBOX_ENCRYPTION_KEYS, INITIAL_SANDBOX_SIGNING_KEYS, INITIAL_SANDBOX_SALTS).map(
([encryptionKey, signingKey, salt]) => getSchnorrAccount(pxe, encryptionKey!, signingKey!, salt).getWallet(),
Expand Down
18 changes: 17 additions & 1 deletion yarn-project/aztec.js/src/wallet/account_wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fr } from '@aztec/circuits.js';
import { Fr, GrumpkinPrivateKey } from '@aztec/circuits.js';
import { ABIParameterVisibility, FunctionAbiHeader, FunctionType } from '@aztec/foundation/abi';
import { AuthWitness, FunctionCall, PXE, TxExecutionRequest } from '@aztec/types';

Expand Down Expand Up @@ -68,3 +68,19 @@ export class AccountWallet extends BaseWallet {
};
}
}

/**
* Extends {@link AccountWallet} with the encryption private key. Not required for
* implementing the wallet interface but useful for testing purposes or exporting
* an account to another pxe.
*/
export class AccountWalletWithPrivateKey extends AccountWallet {
constructor(pxe: PXE, account: AccountInterface, private encryptionPrivateKey: GrumpkinPrivateKey) {
super(pxe, account);
}

/** Returns the encryption private key associated with this account. */
public getEncryptionPrivateKey() {
return this.encryptionPrivateKey;
}
}
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export abstract class BaseWallet implements Wallet {

abstract createAuthWitness(message: Fr): Promise<AuthWitness>;

registerAccount(privKey: GrumpkinPrivateKey, partialAddress: PartialAddress): Promise<void> {
registerAccount(privKey: GrumpkinPrivateKey, partialAddress: PartialAddress): Promise<CompleteAddress> {
return this.pxe.registerAccount(privKey, partialAddress);
}
registerRecipient(account: CompleteAddress): Promise<void> {
Expand Down
Loading

0 comments on commit d94de65

Please sign in to comment.