Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove default export for noir contracts js #10762

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ keywords: [sandbox, aztec, notes, migration, updating, upgrading]

Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them.

## 0.68.0

### Noir contracts package no longer exposes artifacts as default export

To reduce loading times, the package `@aztec/noir-contracts.js` no longer exposes all artifacts as its default export. Instead, it exposes a `ContractNames` variable with the list of all contract names available. To import a given artifact, use the corresponding export, such as `@aztec/noir-contracts.js/FPC`.

## 0.67.0

### L2 Gas limit of 6M enforced for public portion of TX
Expand All @@ -24,10 +30,11 @@ The `Header` struct has been renamed to `BlockHeader`, and the `get_header()` fa
### Outgoing Events removed

Previously, every event which was emitted included:

- Incoming Header (to convey the app contract address to the recipient)
- Incoming Ciphertext (to convey the note contents to the recipient)
- Outgoing Header (served as a backup, to convey the app contract address to the "outgoing viewer" - most likely the sender)
- Outgoing Ciphertext (served as a backup, encrypting the summetric key of the incoming ciphertext to the "outgoing viewer" - most likely the sender)
- Outgoing Ciphertext (served as a backup, encrypting the symmetric key of the incoming ciphertext to the "outgoing viewer" - most likely the sender)

The latter two have been removed from the `.emit()` functions, so now only an Incoming Header and Incoming Ciphertext will be emitted.

Expand All @@ -43,6 +50,7 @@ The `getOutgoingNotes` function is removed from the PXE interface.
Some aztec.nr library methods' arguments are simplified to remove an `outgoing_viewer` parameter. E.g. `ValueNote::increment`, `ValueNote::decrement`, `ValueNote::decrement_by_at_most`, `EasyPrivateUint::add`, `EasyPrivateUint::sub`.

Further changes are planned, so that:

- Outgoing ciphertexts (or any kind of abstract ciphertext) can be emitted by a contract, and on the other side discovered and then processed by the contract.
- Headers will be removed, due to the new tagging scheme.

Expand Down
3 changes: 2 additions & 1 deletion yarn-project/archiver/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { createLogger } from '@aztec/foundation/log';
import { type Maybe } from '@aztec/foundation/types';
import { type DataStoreConfig } from '@aztec/kv-store/config';
import { createStore } from '@aztec/kv-store/lmdb';
import { TokenBridgeContractArtifact, TokenContractArtifact } from '@aztec/noir-contracts.js';
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
import { TokenBridgeContractArtifact } from '@aztec/noir-contracts.js/TokenBridge';
import { getCanonicalProtocolContract, protocolContractNames } from '@aztec/protocol-contracts';
import { type TelemetryClient } from '@aztec/telemetry-client';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/bot/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
import { type AztecNode, type FunctionCall, type PXE } from '@aztec/circuit-types';
import { Gas } from '@aztec/circuits.js';
import { times } from '@aztec/foundation/collection';
import { type EasyPrivateTokenContract, type TokenContract } from '@aztec/noir-contracts.js';
import { type EasyPrivateTokenContract } from '@aztec/noir-contracts.js/EasyPrivateToken';
import { type TokenContract } from '@aztec/noir-contracts.js/Token';

import { type BotConfig } from './config.js';
import { BotFactory } from './factory.js';
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/bot/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@aztec/aztec.js';
import { type AztecNode, type FunctionCall, type PXE } from '@aztec/circuit-types';
import { Fr, deriveSigningKey } from '@aztec/circuits.js';
import { EasyPrivateTokenContract } from '@aztec/noir-contracts.js';
import { EasyPrivateTokenContract } from '@aztec/noir-contracts.js/EasyPrivateToken';
import { TokenContract } from '@aztec/noir-contracts.js/Token';

import { type BotConfig, SupportedTokenContracts } from './config.js';
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/bot/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type AztecAddress } from '@aztec/circuits.js';
import { type EasyPrivateTokenContract } from '@aztec/noir-contracts.js';
import { type EasyPrivateTokenContract } from '@aztec/noir-contracts.js/EasyPrivateToken';
import { type TokenContract } from '@aztec/noir-contracts.js/Token';

/**
Expand Down
16 changes: 12 additions & 4 deletions yarn-project/cli/src/cmds/contracts/inspect_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ export async function inspectContract(contractArtifactFile: string, debugLogger:
log(`\tprivate function tree root: ${contractClass.privateFunctionsRoot.toString()}`);
log(`\tpublic bytecode commitment: ${contractClass.publicBytecodeCommitment.toString()}`);
log(`\tpublic bytecode length: ${contractClass.packedBytecode.length} bytes (${bytecodeLengthInFields} fields)`);
log(`\nExternal functions:`);
contractFns.filter(f => !f.isInternal).forEach(f => logFunction(f, log));
log(`\nInternal functions:`);
contractFns.filter(f => f.isInternal).forEach(f => logFunction(f, log));

const externalFunctions = contractFns.filter(f => !f.isInternal);
if (externalFunctions.length > 0) {
log(`\nExternal functions:`);
externalFunctions.forEach(f => logFunction(f, log));
}

const internalFunctions = contractFns.filter(f => f.isInternal);
if (internalFunctions.length > 0) {
log(`\nInternal functions:`);
internalFunctions.forEach(f => logFunction(f, log));
}
}

function logFunction(fn: FunctionArtifact, log: LogFn) {
Expand Down
14 changes: 10 additions & 4 deletions yarn-project/cli/src/cmds/devnet/bootstrap_network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ async function deployToken(
): Promise<{ token: ContractDeploymentInfo; bridge: ContractDeploymentInfo }> {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment
const { TokenContract, TokenBridgeContract } = await import('@aztec/noir-contracts.js');
const { TokenContract } = await import('@aztec/noir-contracts.js/Token');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment
const { TokenBridgeContract } = await import('@aztec/noir-contracts.js/TokenBridge');
const devCoin = await TokenContract.deploy(wallet, wallet.getAddress(), 'DevCoin', 'DEV', 18)
.send({ universalDeploy: true })
.deployed(waitOpts);
Expand Down Expand Up @@ -223,7 +226,7 @@ async function deployFPC(
): Promise<ContractDeploymentInfo> {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment
const { FPCContract } = await import('@aztec/noir-contracts.js');
const { FPCContract } = await import('@aztec/noir-contracts.js/FPC');
const fpc = await FPCContract.deploy(wallet, tokenAddress, feeRecipient)
.send({ universalDeploy: true })
.deployed(waitOpts);
Expand All @@ -238,7 +241,7 @@ async function deployFPC(
async function deployCounter(wallet: Wallet): Promise<ContractDeploymentInfo> {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment
const { CounterContract } = await import('@aztec/noir-contracts.js');
const { CounterContract } = await import('@aztec/noir-contracts.js/Counter');
const counter = await CounterContract.deploy(wallet, 1, wallet.getAddress())
.send({ universalDeploy: true })
.deployed(waitOpts);
Expand All @@ -260,7 +263,10 @@ async function fundFPC(
) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment
const { FeeJuiceContract, CounterContract } = await import('@aztec/noir-contracts.js');
const { FeeJuiceContract } = await import('@aztec/noir-contracts.js/FeeJuice');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment
const { CounterContract } = await import('@aztec/noir-contracts.js/Counter');
const {
protocolContractAddresses: { feeJuice },
} = await wallet.getPXEInfo();
Expand Down
11 changes: 7 additions & 4 deletions yarn-project/cli/src/cmds/misc/example_contracts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { type LogFn } from '@aztec/foundation/log';

import { getExampleContractArtifacts } from '../../utils/aztec.js';
import { getExampleContractNames } from '../../utils/aztec.js';

export async function exampleContracts(log: LogFn) {
const abisList = await getExampleContractArtifacts();
const names = Object.keys(abisList).filter(name => name !== 'AvmTestContractArtifact');
names.forEach(name => log(name));
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment
return (await getExampleContractNames())
.filter(name => name !== 'AvmTest')
.sort()
.forEach(name => log(name));
}
2 changes: 1 addition & 1 deletion yarn-project/cli/src/cmds/misc/setup_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function setupCanonicalL2FeeJuice(
) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment
const { FeeJuiceContract } = await import('@aztec/noir-contracts.js');
const { FeeJuiceContract } = await import('@aztec/noir-contracts.js/FeeJuice');

const feeJuiceContract = await FeeJuiceContract.at(ProtocolContractAddress.FeeJuice, deployer);

Expand Down
29 changes: 14 additions & 15 deletions yarn-project/cli/src/utils/aztec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ import {

import { encodeArgs } from './encoding.js';

/**
* Helper type to dynamically import contracts.
*/
interface ArtifactsType {
[key: string]: ContractArtifact;
}

/**
* Helper to get an ABI function or throw error if it doesn't exist.
* @param artifact - Contract's build artifact in JSON format.
Expand Down Expand Up @@ -98,13 +91,13 @@ export async function setAssumeProvenThrough(

/**
* Gets all contracts available in \@aztec/noir-contracts.js.
* @returns The contract ABIs.
* @returns The contract names.
*/
export async function getExampleContractArtifacts(): Promise<ArtifactsType> {
export async function getExampleContractNames(): Promise<string[]> {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment
const imports = await import('@aztec/noir-contracts.js');
return Object.fromEntries(Object.entries(imports).filter(([key]) => key.endsWith('Artifact'))) as any;
const { ContractNames } = await import('@aztec/noir-contracts.js');
return ContractNames;
}

/**
Expand All @@ -114,11 +107,17 @@ export async function getExampleContractArtifacts(): Promise<ArtifactsType> {
*/
export async function getContractArtifact(fileDir: string, log: LogFn) {
// first check if it's a noir-contracts example
const artifacts = await getExampleContractArtifacts();
for (const key of [fileDir, fileDir + 'Artifact', fileDir + 'ContractArtifact']) {
if (artifacts[key]) {
return artifacts[key] as ContractArtifact;
const allNames = await getExampleContractNames();
const contractName = fileDir.replace(/Contract(Artifact)?$/, '');
if (allNames.includes(contractName)) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment
const imported = await import(`@aztec/noir-contracts.js/${contractName}`);
const artifact = imported[`${contractName}ContractArtifact`] as ContractArtifact;
if (!artifact) {
throw Error(`Could not import ${contractName}ContractArtifact from @aztec/noir-contracts.js/${contractName}`);
}
return artifact;
}

let contents: string;
Expand Down
5 changes: 4 additions & 1 deletion yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { PublicFeePaymentMethod, TxStatus, sleep } from '@aztec/aztec.js';
import { type AccountWallet } from '@aztec/aztec.js/wallet';
import { BBCircuitVerifier } from '@aztec/bb-prover';
import { CompleteAddress, FEE_FUNDING_FOR_TESTER_ACCOUNT, Fq, Fr, GasSettings } from '@aztec/circuits.js';
import { FPCContract, FeeJuiceContract, TestContract, TokenContract } from '@aztec/noir-contracts.js';
import { FPCContract } from '@aztec/noir-contracts.js/FPC';
import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice';
import { TestContract } from '@aztec/noir-contracts.js/Test';
import { TokenContract } from '@aztec/noir-contracts.js/Token';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
import { type PXEService, type PXEServiceConfig, createPXEService } from '@aztec/pxe';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
TxStatus,
} from '@aztec/aztec.js';
import { FEE_FUNDING_FOR_TESTER_ACCOUNT, GasSettings } from '@aztec/circuits.js';
import { FPCContract, FeeJuiceContract, TokenContract } from '@aztec/noir-contracts.js';
import { FPCContract } from '@aztec/noir-contracts.js/FPC';
import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice';
import { TokenContract } from '@aztec/noir-contracts.js/Token';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';

import { jest } from '@jest/globals';
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/devnet/e2e_smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { deriveSigningKey } from '@aztec/circuits.js';
import { createNamespacedSafeJsonRpcServer, startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
import { type Logger } from '@aztec/foundation/log';
import { promiseWithResolvers } from '@aztec/foundation/promise';
import { FeeJuiceContract, TestContract } from '@aztec/noir-contracts.js';
import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice';
import { TestContract } from '@aztec/noir-contracts.js/Test';

import getPort from 'get-port';
import { exec } from 'node:child_process';
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/end-to-end/src/e2e_2_pxes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
type Wallet,
sleep,
} from '@aztec/aztec.js';
import { ChildContract, TestContract, TokenContract } from '@aztec/noir-contracts.js';
import { ChildContract } from '@aztec/noir-contracts.js/Child';
import { TestContract } from '@aztec/noir-contracts.js/Test';
import { TokenContract } from '@aztec/noir-contracts.js/Token';

import { expect, jest } from '@jest/globals';

Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/e2e_amm.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type AccountWallet, Fr, type Logger, type Wallet } from '@aztec/aztec.js';
import { AMMContract, type TokenContract } from '@aztec/noir-contracts.js';
import { AMMContract } from '@aztec/noir-contracts.js/AMM';
import { type TokenContract } from '@aztec/noir-contracts.js/Token';

import { jest } from '@jest/globals';

Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/e2e_authwit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type AccountWallet, Fr, computeAuthWitMessageHash, computeInnerAuthWitHash } from '@aztec/aztec.js';
import { AuthRegistryContract, AuthWitTestContract } from '@aztec/noir-contracts.js';
import { AuthRegistryContract } from '@aztec/noir-contracts.js/AuthRegistry';
import { AuthWitTestContract } from '@aztec/noir-contracts.js/AuthWitTest';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';

import { jest } from '@jest/globals';
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/e2e_avm_simulator.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type AccountWallet, AztecAddress, BatchCall, Fr, TxStatus } from '@aztec/aztec.js';
import { AvmInitializerTestContract, AvmTestContract } from '@aztec/noir-contracts.js';
import { AvmInitializerTestContract } from '@aztec/noir-contracts.js/AvmInitializerTest';
import { AvmTestContract } from '@aztec/noir-contracts.js/AvmTest';

import { jest } from '@jest/globals';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
computeSecretHash,
createLogger,
} from '@aztec/aztec.js';
import { DocsExampleContract, TokenBlacklistContract, type TokenContract } from '@aztec/noir-contracts.js';
import { DocsExampleContract } from '@aztec/noir-contracts.js/DocsExample';
import { type TokenContract } from '@aztec/noir-contracts.js/Token';
import { TokenBlacklistContract } from '@aztec/noir-contracts.js/TokenBlacklist';

import { jest } from '@jest/globals';

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_block_building.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { getL1ContractsConfigEnvVars } from '@aztec/ethereum';
import { times } from '@aztec/foundation/collection';
import { poseidon2Hash } from '@aztec/foundation/crypto';
import { StatefulTestContract, StatefulTestContractArtifact } from '@aztec/noir-contracts.js';
import { StatefulTestContract, StatefulTestContractArtifact } from '@aztec/noir-contracts.js/StatefulTest';
import { TestContract } from '@aztec/noir-contracts.js/Test';
import { TokenContract } from '@aztec/noir-contracts.js/Token';

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_cheat_codes.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type AztecAddress, type CheatCodes, EthAddress, Fr, type Wallet } from '@aztec/aztec.js';
import { RollupAbi } from '@aztec/l1-artifacts';
import { TokenContract } from '@aztec/noir-contracts.js';
import { TokenContract } from '@aztec/noir-contracts.js/Token';

import {
type Account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
} from '@aztec/aztec.js';
import { createL1Clients } from '@aztec/ethereum';
import { InboxAbi, OutboxAbi, RollupAbi } from '@aztec/l1-artifacts';
import { TokenBridgeContract, TokenContract } from '@aztec/noir-contracts.js';
import { TokenContract } from '@aztec/noir-contracts.js/Token';
import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';

import { type Chain, type HttpTransport, type PublicClient, getContract } from 'viem';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type AztecAddress, Fr, generateClaimSecret } from '@aztec/aztec.js';
import { TestContract } from '@aztec/noir-contracts.js';
import { TestContract } from '@aztec/noir-contracts.js/Test';

import { sendL1ToL2Message } from '../fixtures/l1_to_l2_messaging.js';
import { CrossChainMessagingTest } from './cross_chain_messaging_test.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Fr } from '@aztec/aztec.js';
import { sha256ToField } from '@aztec/foundation/crypto';
import { OutboxAbi } from '@aztec/l1-artifacts';
import { TestContract } from '@aztec/noir-contracts.js';
import { TestContract } from '@aztec/noir-contracts.js/Test';

import { type Hex, decodeEventLog, getContract } from 'viem';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
deriveKeys,
} from '@aztec/aztec.js';
import { GasSettings, TxContext, computePartialAddress } from '@aztec/circuits.js';
import { InclusionProofsContract } from '@aztec/noir-contracts.js';
import { ClaimContract } from '@aztec/noir-contracts.js/Claim';
import { CrowdfundingContract } from '@aztec/noir-contracts.js/Crowdfunding';
import { InclusionProofsContract } from '@aztec/noir-contracts.js/InclusionProofs';
import { TokenContract } from '@aztec/noir-contracts.js/Token';

import { jest } from '@jest/globals';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import {
import { type ContractClassIdPreimage, PublicKeys, computeContractClassId } from '@aztec/circuits.js';
import { FunctionSelector, FunctionType } from '@aztec/foundation/abi';
import { writeTestData } from '@aztec/foundation/testing';
import { StatefulTestContract, TokenContractArtifact } from '@aztec/noir-contracts.js';
import { StatefulTestContract } from '@aztec/noir-contracts.js/StatefulTest';
import { TestContract } from '@aztec/noir-contracts.js/Test';
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';

import { DUPLICATE_NULLIFIER_ERROR } from '../fixtures/fixtures.js';
import { DeployTest, type StatefulContractCtorArgs } from './deploy_test.js';
Expand Down
Loading
Loading