Skip to content
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
6 changes: 3 additions & 3 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
import { RunningPromise } from '@aztec/foundation/running-promise';
import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer';
import { getCanonicalClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer';
import {
ContractClassPublic,
ContractDataSource,
Expand Down Expand Up @@ -287,8 +287,8 @@ export class Archiver implements ArchiveSource {
* @param allLogs - All logs emitted in a bunch of blocks.
*/
private async storeRegisteredContractClasses(allLogs: UnencryptedL2Log[], blockNum: number) {
const contractClasses = ContractClassRegisteredEvent.fromLogs(allLogs, ClassRegistererAddress).map(e =>
e.toContractClassPublic(),
const contractClasses = ContractClassRegisteredEvent.fromLogs(allLogs, getCanonicalClassRegistererAddress()).map(
e => e.toContractClassPublic(),
);
if (contractClasses.length > 0) {
contractClasses.forEach(c => this.log(`Registering contract class ${c.id.toString()}`));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { computeContractAddressFromInstance, getContractClassFromArtifact } from '@aztec/circuits.js';

import { ClassRegistererAddress, getCanonicalClassRegisterer } from './index.js';
import { getCanonicalClassRegisterer, getCanonicalClassRegistererAddress } from './index.js';

describe('ClassRegisterer', () => {
it('returns canonical protocol contract', () => {
const contract = getCanonicalClassRegisterer();
expect(computeContractAddressFromInstance(contract.instance)).toEqual(contract.address);
expect(getContractClassFromArtifact(contract.artifact).id).toEqual(contract.contractClass.id);
expect(contract.address.toString()).toEqual(ClassRegistererAddress.toString());
expect(contract.address.toString()).toEqual(getCanonicalClassRegistererAddress().toString());
});
});
16 changes: 9 additions & 7 deletions yarn-project/protocol-contracts/src/class-registerer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ export function getCanonicalClassRegisterer(): ProtocolContract {
return getCanonicalProtocolContract(ContractClassRegistererArtifact, 1);
}

/**
* Address of the canonical class registerer.
* @remarks This should not change often, hence we hardcode it to save from having to recompute it every time.
*/
export const ClassRegistererAddress = AztecAddress.fromString(
'0x2140db629d95644ef26140fa5ae87749ae28d373176af9a2e458052ced96c7b3',
);
let address: AztecAddress | undefined = undefined;

/** Returns the address for the canonical deployment of the class registerer */
export function getCanonicalClassRegistererAddress() {
if (!address) {
address = getCanonicalClassRegisterer().address;
}
return address;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@aztec/circuits.js';
import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
import { createDebugLogger } from '@aztec/foundation/log';
import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer';
import { getCanonicalClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer';
import { CommitmentsDB, MessageLoadOracleInputs, PublicContractsDB, PublicStateDB } from '@aztec/simulator';
import { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/types/contracts';
import { MerkleTreeOperations } from '@aztec/world-state';
Expand All @@ -43,7 +43,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
public addNewContracts(tx: Tx): Promise<void> {
// Extract contract class and instance data from logs and add to cache for this block
const logs = tx.unencryptedLogs.unrollLogs().map(UnencryptedL2Log.fromBuffer);
ContractClassRegisteredEvent.fromLogs(logs, ClassRegistererAddress).forEach(e => {
ContractClassRegisteredEvent.fromLogs(logs, getCanonicalClassRegistererAddress()).forEach(e => {
this.log(`Adding class ${e.contractClassId.toString()} to public execution contract cache`);
this.classCache.set(e.contractClassId.toString(), e.toContractClassPublic());
});
Expand All @@ -66,7 +66,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
// Let's say we have two txs adding the same contract on the same block. If the 2nd one reverts,
// wouldn't that accidentally remove the contract added on the first one?
const logs = tx.unencryptedLogs.unrollLogs().map(UnencryptedL2Log.fromBuffer);
ContractClassRegisteredEvent.fromLogs(logs, ClassRegistererAddress).forEach(e =>
ContractClassRegisteredEvent.fromLogs(logs, getCanonicalClassRegistererAddress()).forEach(e =>
this.classCache.delete(e.contractClassId.toString()),
);
ContractInstanceDeployedEvent.fromLogs(logs).forEach(e => this.instanceCache.delete(e.address.toString()));
Expand Down