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: Split up protocol contract artifacts #10765

Merged
merged 1 commit into from
Dec 17, 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
4 changes: 2 additions & 2 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import { elapsed } from '@aztec/foundation/timer';
import { InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
import {
ContractClassRegisteredEvent,
ContractInstanceDeployedEvent,
PrivateFunctionBroadcastedEvent,
UnconstrainedFunctionBroadcastedEvent,
} from '@aztec/protocol-contracts';
} from '@aztec/protocol-contracts/class-registerer';
import { ContractInstanceDeployedEvent } from '@aztec/protocol-contracts/instance-deployer';
import { Attributes, type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';

import groupBy from 'lodash.groupby';
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 @@ -10,7 +10,8 @@ import { type DataStoreConfig } from '@aztec/kv-store/config';
import { createStore } from '@aztec/kv-store/lmdb';
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
import { TokenBridgeContractArtifact } from '@aztec/noir-contracts.js/TokenBridge';
import { getCanonicalProtocolContract, protocolContractNames } from '@aztec/protocol-contracts';
import { protocolContractNames } from '@aztec/protocol-contracts';
import { getCanonicalProtocolContract } from '@aztec/protocol-contracts/bundle';
import { type TelemetryClient } from '@aztec/telemetry-client';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { type FunctionCall } from '@aztec/circuit-types';
import { type AztecAddress, Fr, FunctionSelector } from '@aztec/circuits.js';
import { FunctionType } from '@aztec/foundation/abi';
import { ProtocolContractAddress, ProtocolContractArtifact } from '@aztec/protocol-contracts';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice';

import { type L2AmountClaim } from '../utils/portal_manager.js';
import { FeeJuicePaymentMethod } from './fee_juice_payment_method.js';
Expand All @@ -23,7 +24,7 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod {
*/
override getFunctionCalls(): Promise<FunctionCall[]> {
const selector = FunctionSelector.fromNameAndParameters(
ProtocolContractArtifact.FeeJuice.functions.find(f => f.name === 'claim')!,
getCanonicalFeeJuice().artifact.functions.find(f => f.name === 'claim')!,
);

return Promise.resolve([
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
import { fileURLToPath } from '@aztec/aztec.js';
import { injectCommands as injectBuilderCommands } from '@aztec/builder';
import { injectCommands as injectWalletCommands } from '@aztec/cli-wallet';
import { injectCommands as injectContractCommands } from '@aztec/cli/contracts';
Expand All @@ -9,6 +8,7 @@ import { injectCommands as injectL1Commands } from '@aztec/cli/l1';
import { injectCommands as injectMiscCommands } from '@aztec/cli/misc';
import { injectCommands as injectPXECommands } from '@aztec/cli/pxe';
import { createConsoleLogger, createLogger } from '@aztec/foundation/log';
import { fileURLToPath } from '@aztec/foundation/url';

import { Command } from 'commander';
import { readFileSync } from 'fs';
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/protocol-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"type": "module",
"exports": {
".": "./dest/index.js",
"./bundle": "./dest/bundle/index.js",
"./*": "./dest/*/index.js"
},
"typedocOptions": {
Expand Down Expand Up @@ -99,4 +100,4 @@
"engines": {
"node": ">=18"
}
}
}
16 changes: 14 additions & 2 deletions yarn-project/protocol-contracts/src/auth-registry/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js';
import { loadContractArtifact } from '@aztec/types/abi';
import { type NoirCompiledContract } from '@aztec/types/noir';

import AuthRegistryJson from '../../artifacts/AuthRegistry.json' assert { type: 'json' };
import { makeProtocolContract } from '../make_protocol_contract.js';
import { type ProtocolContract } from '../protocol_contract.js';

let protocolContract: ProtocolContract;

export const AuthRegistryArtifact = loadContractArtifact(AuthRegistryJson as NoirCompiledContract);

/** Returns the canonical deployment of the auth registry. */
export function getCanonicalAuthRegistry(): ProtocolContract {
return getCanonicalProtocolContract('AuthRegistry');
if (!protocolContract) {
protocolContract = makeProtocolContract('AuthRegistry', AuthRegistryArtifact);
}
return protocolContract;
}
36 changes: 36 additions & 0 deletions yarn-project/protocol-contracts/src/bundle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { getContractClassFromArtifact, getContractInstanceFromDeployParams } from '@aztec/circuits.js';
import { type ContractArtifact } from '@aztec/foundation/abi';

import { AuthRegistryArtifact } from '../auth-registry/index.js';
import { ContractClassRegistererArtifact } from '../class-registerer/index.js';
import { FeeJuiceArtifact } from '../fee-juice/index.js';
import { ContractInstanceDeployerArtifact } from '../instance-deployer/index.js';
import { MultiCallEntrypointArtifact } from '../multi-call-entrypoint/index.js';
import { type ProtocolContract } from '../protocol_contract.js';
import { ProtocolContractAddress, type ProtocolContractName, ProtocolContractSalt } from '../protocol_contract_data.js';
import { RouterArtifact } from '../router/index.js';

/** Returns the canonical deployment a given artifact. */
export function getCanonicalProtocolContract(name: ProtocolContractName): ProtocolContract {
const artifact = ProtocolContractArtifact[name];
const address = ProtocolContractAddress[name];
const salt = ProtocolContractSalt[name];
// TODO(@spalladino): This computes the contract class from the artifact twice.
const contractClass = getContractClassFromArtifact(artifact);
const instance = getContractInstanceFromDeployParams(artifact, { salt });
return {
instance: { ...instance, address },
contractClass,
artifact,
address,
};
}

export const ProtocolContractArtifact: Record<ProtocolContractName, ContractArtifact> = {
AuthRegistry: AuthRegistryArtifact,
ContractInstanceDeployer: ContractInstanceDeployerArtifact,
ContractClassRegisterer: ContractClassRegistererArtifact,
MultiCallEntrypoint: MultiCallEntrypointArtifact,
FeeJuice: FeeJuiceArtifact,
Router: RouterArtifact,
};
21 changes: 18 additions & 3 deletions yarn-project/protocol-contracts/src/class-registerer/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js';
import { loadContractArtifact } from '@aztec/types/abi';
import { type NoirCompiledContract } from '@aztec/types/noir';

import ContractClassRegistererJson from '../../artifacts/ContractClassRegisterer.json' assert { type: 'json' };
import { makeProtocolContract } from '../make_protocol_contract.js';
import { type ProtocolContract } from '../protocol_contract.js';

export * from './contract_class_registered_event.js';
export * from './private_function_broadcasted_event.js';
export * from './unconstrained_function_broadcasted_event.js';

/** Returns the canonical deployment of the class registerer contract. */
export const ContractClassRegistererArtifact = loadContractArtifact(
ContractClassRegistererJson as NoirCompiledContract,
);

let protocolContract: ProtocolContract;

/** Returns the canonical deployment of the contract. */
export function getCanonicalClassRegisterer(): ProtocolContract {
return getCanonicalProtocolContract('ContractClassRegisterer');
if (!protocolContract) {
const artifact = ContractClassRegistererArtifact;
protocolContract = makeProtocolContract('ContractClassRegisterer', artifact);
}
return protocolContract;
}
18 changes: 15 additions & 3 deletions yarn-project/protocol-contracts/src/fee-juice/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js';
import { loadContractArtifact } from '@aztec/types/abi';
import { type NoirCompiledContract } from '@aztec/types/noir';

/** Returns the canonical deployment of the Fee Juice. */
import FeeJuiceJson from '../../artifacts/FeeJuice.json' assert { type: 'json' };
import { makeProtocolContract } from '../make_protocol_contract.js';
import { type ProtocolContract } from '../protocol_contract.js';

export const FeeJuiceArtifact = loadContractArtifact(FeeJuiceJson as NoirCompiledContract);

let protocolContract: ProtocolContract;

/** Returns the canonical deployment of the contract. */
export function getCanonicalFeeJuice(): ProtocolContract {
return getCanonicalProtocolContract('FeeJuice');
if (!protocolContract) {
protocolContract = makeProtocolContract('FeeJuice', FeeJuiceArtifact);
}
return protocolContract;
}
5 changes: 0 additions & 5 deletions yarn-project/protocol-contracts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
export * from './auth-registry/index.js';
export * from './class-registerer/index.js';
export * from './fee-juice/index.js';
export * from './instance-deployer/index.js';
export * from './multi-call-entrypoint/index.js';
export * from './protocol_contract.js';
export * from './protocol_contract_data.js';
export * from './protocol_contract_tree.js';
20 changes: 17 additions & 3 deletions yarn-project/protocol-contracts/src/instance-deployer/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js';
import { loadContractArtifact } from '@aztec/types/abi';
import { type NoirCompiledContract } from '@aztec/types/noir';

import ContractInstanceDeployerJson from '../../artifacts/ContractInstanceDeployer.json' assert { type: 'json' };
import { makeProtocolContract } from '../make_protocol_contract.js';
import { type ProtocolContract } from '../protocol_contract.js';

export * from './contract_instance_deployed_event.js';

/** Returns the canonical deployment of the instance deployer contract. */
export const ContractInstanceDeployerArtifact = loadContractArtifact(
ContractInstanceDeployerJson as NoirCompiledContract,
);

let protocolContract: ProtocolContract;

/** Returns the canonical deployment of the contract. */
export function getCanonicalInstanceDeployer(): ProtocolContract {
return getCanonicalProtocolContract('ContractInstanceDeployer');
if (!protocolContract) {
protocolContract = makeProtocolContract('ContractInstanceDeployer', ContractInstanceDeployerArtifact);
}
return protocolContract;
}
23 changes: 23 additions & 0 deletions yarn-project/protocol-contracts/src/make_protocol_contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { getContractClassFromArtifact, getContractInstanceFromDeployParams } from '@aztec/circuits.js';
import { type ContractArtifact } from '@aztec/foundation/abi';

import { type ProtocolContract } from './protocol_contract.js';
import { ProtocolContractAddress, type ProtocolContractName, ProtocolContractSalt } from './protocol_contract_data.js';

/**
* Returns the canonical deployment given its name and artifact.
* To be used internally within the protocol-contracts package.
*/
export function makeProtocolContract(name: ProtocolContractName, artifact: ContractArtifact): ProtocolContract {
const address = ProtocolContractAddress[name];
const salt = ProtocolContractSalt[name];
// TODO(@spalladino): This computes the contract class from the artifact twice.
const contractClass = getContractClassFromArtifact(artifact);
const instance = getContractInstanceFromDeployParams(artifact, { salt });
return {
instance: { ...instance, address },
contractClass,
artifact,
address,
};
}
19 changes: 16 additions & 3 deletions yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js';
import { loadContractArtifact } from '@aztec/types/abi';
import { type NoirCompiledContract } from '@aztec/types/noir';

export function getCanonicalMultiCallEntrypointContract(): ProtocolContract {
return getCanonicalProtocolContract('MultiCallEntrypoint');
import MultiCallEntrypointJson from '../../artifacts/MultiCallEntrypoint.json' assert { type: 'json' };
import { makeProtocolContract } from '../make_protocol_contract.js';
import { type ProtocolContract } from '../protocol_contract.js';

export const MultiCallEntrypointArtifact = loadContractArtifact(MultiCallEntrypointJson as NoirCompiledContract);

let protocolContract: ProtocolContract;

/** Returns the canonical deployment of the contract. */
export function getCanonicalMultiCallEntrypoint(): ProtocolContract {
if (!protocolContract) {
protocolContract = makeProtocolContract('MultiCallEntrypoint', MultiCallEntrypointArtifact);
}
return protocolContract;
}
25 changes: 1 addition & 24 deletions yarn-project/protocol-contracts/src/protocol_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ import {
type ContractClassIdPreimage,
type ContractClassWithId,
type ContractInstanceWithAddress,
getContractClassFromArtifact,
getContractInstanceFromDeployParams,
} from '@aztec/circuits.js';
import { type ContractArtifact } from '@aztec/foundation/abi';

import {
ProtocolContractAddress,
ProtocolContractArtifact,
type ProtocolContractName,
ProtocolContractSalt,
} from './protocol_contract_data.js';
import { ProtocolContractAddress } from './protocol_contract_data.js';

/** Represents a canonical contract in the protocol. */
export interface ProtocolContract {
Expand All @@ -27,22 +20,6 @@ export interface ProtocolContract {
address: AztecAddress;
}

/** Returns the canonical deployment a given artifact. */
export function getCanonicalProtocolContract(name: ProtocolContractName): ProtocolContract {
const artifact = ProtocolContractArtifact[name];
const address = ProtocolContractAddress[name];
const salt = ProtocolContractSalt[name];
// TODO(@spalladino): This computes the contract class from the artifact twice.
const contractClass = getContractClassFromArtifact(artifact);
const instance = getContractInstanceFromDeployParams(artifact, { salt });
return {
instance: { ...instance, address },
contractClass,
artifact,
address,
};
}

export function isProtocolContract(address: AztecAddress) {
return Object.values(ProtocolContractAddress).some(a => a.equals(address));
}
18 changes: 15 additions & 3 deletions yarn-project/protocol-contracts/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js';
import { loadContractArtifact } from '@aztec/types/abi';
import { type NoirCompiledContract } from '@aztec/types/noir';

/** Returns the canonical deployment of the router. */
import RouterJson from '../../artifacts/Router.json' assert { type: 'json' };
import { makeProtocolContract } from '../make_protocol_contract.js';
import { type ProtocolContract } from '../protocol_contract.js';

export const RouterArtifact = loadContractArtifact(RouterJson as NoirCompiledContract);

let protocolContract: ProtocolContract;

/** Returns the canonical deployment of the contract. */
export function getCanonicalRouter(): ProtocolContract {
return getCanonicalProtocolContract('Router');
if (!protocolContract) {
protocolContract = makeProtocolContract('Router', RouterArtifact);
}
return protocolContract;
}
25 changes: 0 additions & 25 deletions yarn-project/protocol-contracts/src/scripts/generate_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,6 @@ function generateNames(names: string[]) {
`;
}

function generateArtifacts(names: string[]) {
const imports = names
.map(name => {
return `
import ${name}Json from '../artifacts/${name}.json' assert { type: 'json' };
`;
})
.join('\n');

const exports = names.map(name => `${name}: loadContractArtifact(${name}Json as NoirCompiledContract)`).join(',\n');

return `
${imports}

export const ProtocolContractArtifact: Record<ProtocolContractName, ContractArtifact> = {
${exports}
};
`;
}

function generateSalts(names: string[]) {
return `
export const ProtocolContractSalt: Record<ProtocolContractName, Fr> = {
Expand Down Expand Up @@ -165,14 +145,9 @@ async function generateOutputFile(names: string[], leaves: Fr[]) {
const content = `
// GENERATED FILE - DO NOT EDIT. RUN \`yarn generate\` or \`yarn generate:data\`
import { AztecAddress, Fr } from '@aztec/circuits.js';
import { type ContractArtifact } from '@aztec/foundation/abi';
import { loadContractArtifact } from '@aztec/types/abi';
import { type NoirCompiledContract } from '@aztec/types/noir';

${generateNames(names)}

${generateArtifacts(names)}

${generateSalts(names)}

${generateContractAddresses(names)}
Expand Down
7 changes: 2 additions & 5 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ import { Fr, type Point } from '@aztec/foundation/fields';
import { type Logger, createLogger } from '@aztec/foundation/log';
import { type KeyStore } from '@aztec/key-store';
import { type L2TipsStore } from '@aztec/kv-store/stores';
import {
ProtocolContractAddress,
getCanonicalProtocolContract,
protocolContractNames,
} from '@aztec/protocol-contracts';
import { ProtocolContractAddress, protocolContractNames } from '@aztec/protocol-contracts';
import { getCanonicalProtocolContract } from '@aztec/protocol-contracts/bundle';
import { type AcirSimulator } from '@aztec/simulator/client';

import { inspect } from 'util';
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/simulator/src/public/fee_payment.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { computePublicDataTreeLeafSlot, deriveStorageSlotInMap } from '@aztec/circuits.js/hash';
import { type AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';
import { ProtocolContractAddress, ProtocolContractArtifact } from '@aztec/protocol-contracts';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
import { FeeJuiceArtifact } from '@aztec/protocol-contracts/fee-juice';

/**
* Computes the storage slot within the Fee Juice contract for the balance of the fee payer.
*/
export function computeFeePayerBalanceStorageSlot(feePayer: AztecAddress) {
return deriveStorageSlotInMap(ProtocolContractArtifact.FeeJuice.storageLayout.balances.slot, feePayer);
return deriveStorageSlotInMap(FeeJuiceArtifact.storageLayout.balances.slot, feePayer);
}

/**
Expand Down
Loading
Loading