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
13 changes: 13 additions & 0 deletions yarn-project/protocol-contracts/src/protocol_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,17 @@ export function isProtocolContract(address: AztecAddress) {
return Object.values(ProtocolContractAddress).some(a => a.equals(address));
}

/** Returns true if the address is one of the ACTUAL protocol contracts (ContractInstanceRegistry,
* ContractClassRegistry or FeeJuice).
*
* TODO(F-416): Drop this function when protocol contracts are redeployed.
*/
export function isActualProtocolContract(address: AztecAddress) {
return (
address.equals(ProtocolContractAddress.ContractInstanceRegistry) ||
address.equals(ProtocolContractAddress.ContractClassRegistry) ||
address.equals(ProtocolContractAddress.FeeJuice)
);
}

export { type ProtocolContractsProvider } from './provider/protocol_contracts_provider.js';
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,28 @@ export class Oracle {
});

// Build callback object and return it
return oracleNames.reduce((acc, name) => {
const callback = oracleNames.reduce((acc, name) => {
const method = this[name as keyof Omit<Oracle, (typeof excludedProps)[number]>];
acc[name] = method.bind(this);
return acc;
}, {} as ACIRCallback);

// Legacy oracle names used by alpha payload protocol contracts (ContractInstanceRegistry,
// ContractClassRegistry, FeeJuice). Their bytecode is committed and cannot be changed.
// TODO(F-416): Remove these aliases on v5 when protocol contracts are redeployed.
const legacyOracles: ACIRCallback = {
utilityLog: this.aztec_utl_log.bind(this),
utilityAssertCompatibleOracleVersion: this.aztec_utl_assertCompatibleOracleVersion.bind(this),
utilityLoadCapsule: this.aztec_utl_loadCapsule.bind(this),
privateStoreInExecutionCache: this.aztec_prv_storeInExecutionCache.bind(this),
privateLoadFromExecutionCache: this.aztec_prv_loadFromExecutionCache.bind(this),
};

return { ...callback, ...legacyOracles };
}

// TODO(F-416): This oracle must never change its signature - it is called by the pinned alpha payload protocol
// contracts (ContractInstanceRegistry, ContractClassRegistry, FeeJuice) which cannot be redeployed.
// eslint-disable-next-line camelcase
aztec_utl_assertCompatibleOracleVersion([version]: ACVMField[]) {
this.handlerAsMisc().assertCompatibleOracleVersion(Fr.fromString(version).toNumber());
Expand All @@ -104,12 +119,16 @@ export class Oracle {
return Promise.resolve([toACVMField(val)]);
}

// TODO(F-416): This oracle must never change its signature - it is called by the pinned alpha payload protocol
// contracts (ContractInstanceRegistry, ContractClassRegistry, FeeJuice) which cannot be redeployed.
// eslint-disable-next-line camelcase
aztec_prv_storeInExecutionCache(values: ACVMField[], [hash]: ACVMField[]): Promise<ACVMField[]> {
this.handlerAsPrivate().storeInExecutionCache(values.map(Fr.fromString), Fr.fromString(hash));
return Promise.resolve([]);
}

// TODO(F-416): This oracle must never change its signature - it is called by the pinned alpha payload protocol
// contracts (ContractInstanceRegistry, ContractClassRegistry, FeeJuice) which cannot be redeployed.
// eslint-disable-next-line camelcase
async aztec_prv_loadFromExecutionCache([returnsHash]: ACVMField[]): Promise<ACVMField[][]> {
const values = await this.handlerAsPrivate().loadFromExecutionCache(Fr.fromString(returnsHash));
Expand Down Expand Up @@ -426,6 +445,8 @@ export class Oracle {
return Promise.resolve([]);
}

// TODO(F-416): This oracle must never change its signature - it is called by the pinned alpha payload protocol
// contracts (ContractInstanceRegistry, ContractClassRegistry, FeeJuice) which cannot be redeployed.
// eslint-disable-next-line camelcase
async aztec_utl_log(
level: ACVMField[],
Expand Down Expand Up @@ -540,6 +561,8 @@ export class Oracle {
return [];
}

// TODO(F-416): This oracle must never change its signature - it is called by the pinned alpha payload protocol
// contracts (ContractInstanceRegistry, ContractClassRegistry, FeeJuice) which cannot be redeployed.
// eslint-disable-next-line camelcase
async aztec_utl_loadCapsule(
[contractAddress]: ACVMField[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Point } from '@aztec/foundation/curves/grumpkin';
import { LogLevels, type Logger, createLogger } from '@aztec/foundation/log';
import type { MembershipWitness } from '@aztec/foundation/trees';
import type { KeyStore } from '@aztec/key-store';
import { isActualProtocolContract } from '@aztec/protocol-contracts';
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { BlockHash } from '@aztec/stdlib/block';
Expand Down Expand Up @@ -109,6 +110,12 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
}

public assertCompatibleOracleVersion(version: number): void {
// Alpha payload protocol contracts (ContractInstanceRegistry, ContractClassRegistry, FeeJuice) shipped with
// committed bytecode that cannot be changed. Skip the version check for these contracts.
// TODO(F-416): Remove this hack on v5 when protocol contracts are redeployed.
if (isActualProtocolContract(this.contractAddress)) {
return;
}
if (version !== ORACLE_VERSION) {
throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
}
Expand Down
Loading