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: 0 additions & 13 deletions yarn-project/protocol-contracts/src/protocol_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,4 @@ 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
@@ -0,0 +1,77 @@
import { Fr } from '@aztec/foundation/curves/bn254';
import type { ACIRCallback, ACVMField } from '@aztec/simulator/client';

import type { Oracle } from './oracle.js';

/**
* Builds legacy oracle name callbacks for pinned protocol contracts whose artifacts are committed and cannot be
* changed.
* TODO(F-416): Remove these aliases on v5 when protocol contracts are redeployed.
*/
export function buildLegacyOracleCallbacks(oracle: Oracle): ACIRCallback {
return {
// Simple prefix renames (privateXxx/utilityXxx → aztec_prv_/aztec_utl_)
utilityLog: (...args: ACVMField[][]) => oracle.aztec_utl_log(args[0], args[1], args[2], args[3]),
utilityAssertCompatibleOracleVersion: (...args: ACVMField[][]) =>
oracle.aztec_utl_assertCompatibleOracleVersion(args[0]),
utilityLoadCapsule: (...args: ACVMField[][]) => oracle.aztec_utl_loadCapsule(args[0], args[1], args[2]),
privateStoreInExecutionCache: (...args: ACVMField[][]) => oracle.aztec_prv_storeInExecutionCache(args[0], args[1]),
privateLoadFromExecutionCache: (...args: ACVMField[][]) => oracle.aztec_prv_loadFromExecutionCache(args[0]),
privateCallPrivateFunction: (...args: ACVMField[][]) =>
oracle.aztec_prv_callPrivateFunction(args[0], args[1], args[2], args[3], args[4]),
privateIsNullifierPending: (...args: ACVMField[][]) => oracle.aztec_prv_isNullifierPending(args[0], args[1]),
privateNotifyCreatedNullifier: (...args: ACVMField[][]) => oracle.aztec_prv_notifyCreatedNullifier(args[0]),
privateNotifyCreatedContractClassLog: (...args: ACVMField[][]) =>
oracle.aztec_prv_notifyCreatedContractClassLog(args[0], args[1], args[2], args[3]),
privateGetNextAppTagAsSender: (...args: ACVMField[][]) => oracle.aztec_prv_getNextAppTagAsSender(args[0], args[1]),
privateGetSenderForTags: () => oracle.aztec_prv_getSenderForTags(),
privateSetSenderForTags: (...args: ACVMField[][]) => oracle.aztec_prv_setSenderForTags(args[0]),
utilityGetUtilityContext: () => oracle.aztec_utl_getUtilityContext(),
utilityStorageRead: (...args: ACVMField[][]) => oracle.aztec_utl_storageRead(args[0], args[1], args[2], args[3]),
utilityStoreCapsule: (...args: ACVMField[][]) => oracle.aztec_utl_storeCapsule(args[0], args[1], args[2]),
utilityCopyCapsule: (...args: ACVMField[][]) => oracle.aztec_utl_copyCapsule(args[0], args[1], args[2], args[3]),
utilityDeleteCapsule: (...args: ACVMField[][]) => oracle.aztec_utl_deleteCapsule(args[0], args[1]),
utilityAes128Decrypt: (...args: ACVMField[][]) =>
oracle.aztec_utl_aes128Decrypt(args[0], args[1], args[2], args[3]),
utilityGetSharedSecret: (...args: ACVMField[][]) =>
oracle.aztec_utl_getSharedSecret(args[0], args[1], args[2], args[3]),
utilityFetchTaggedLogs: (...args: ACVMField[][]) => oracle.aztec_utl_fetchTaggedLogs(args[0]),
utilityBulkRetrieveLogs: (...args: ACVMField[][]) => oracle.aztec_utl_bulkRetrieveLogs(args[0], args[1], args[2]),
// Adapter: old 3-param signature → new 5-param with injected constants.
// Values derived from: MAX_MESSAGE_CONTENT_LEN(11) - RESERVED_FIELDS (3 for notes, 1 for events).
utilityValidateAndStoreEnqueuedNotesAndEvents: (
contractAddress: ACVMField[],
noteValidationRequestsArrayBaseSlot: ACVMField[],
eventValidationRequestsArrayBaseSlot: ACVMField[],
) =>
oracle.aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
contractAddress,
noteValidationRequestsArrayBaseSlot,
eventValidationRequestsArrayBaseSlot,
[new Fr(8).toString()],
[new Fr(10).toString()],
),
utilityGetL1ToL2MembershipWitness: (...args: ACVMField[][]) =>
oracle.aztec_utl_getL1ToL2MembershipWitness(args[0], args[1], args[2]),
utilityCheckNullifierExists: (...args: ACVMField[][]) => oracle.aztec_utl_checkNullifierExists(args[0]),
utilityGetRandomField: () => oracle.aztec_utl_getRandomField(),
utilityEmitOffchainEffect: (...args: ACVMField[][]) => oracle.aztec_utl_emitOffchainEffect(args[0]),
// Renames (same signature, different oracle name)
privateNotifySetMinRevertibleSideEffectCounter: (...args: ACVMField[][]) =>
oracle.aztec_prv_notifyRevertiblePhaseStart(args[0]),
privateIsSideEffectCounterRevertible: (...args: ACVMField[][]) => oracle.aztec_prv_inRevertiblePhase(args[0]),
// Signature changes: old 4-param oracles → new 1-param validatePublicCalldata
privateNotifyEnqueuedPublicFunctionCall: (
[_contractAddress]: ACVMField[],
[calldataHash]: ACVMField[],
[_sideEffectCounter]: ACVMField[],
[_isStaticCall]: ACVMField[],
) => oracle.aztec_prv_validatePublicCalldata([calldataHash]),
privateNotifySetPublicTeardownFunctionCall: (
[_contractAddress]: ACVMField[],
[calldataHash]: ACVMField[],
[_sideEffectCounter]: ACVMField[],
[_isStaticCall]: ACVMField[],
) => oracle.aztec_prv_validatePublicCalldata([calldataHash]),
};
}
24 changes: 2 additions & 22 deletions yarn-project/pxe/src/contract_function_simulator/oracle/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { BlockHash } from '@aztec/stdlib/block';
import { ContractClassLog, ContractClassLogFields } from '@aztec/stdlib/logs';

import type { IMiscOracle, IPrivateExecutionOracle, IUtilityExecutionOracle } from './interfaces.js';
import { buildLegacyOracleCallbacks } from './legacy_oracle_mappings.js';
import { packAsHintedNote } from './note_packing_utils.js';

export class UnavailableOracleError extends Error {
Expand Down Expand Up @@ -91,22 +92,9 @@ export class Oracle {
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 };
return { ...callback, ...buildLegacyOracleCallbacks(this) };
}

// 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 @@ -119,16 +107,12 @@ 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 @@ -445,8 +429,6 @@ 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 @@ -575,8 +557,6 @@ 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,7 +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 { isProtocolContract } 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 @@ -115,12 +115,21 @@ 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)) {
// Protocol contracts/canonical contracts shipped with committed bytecode that cannot be changed. Assert they use
// the expected pinned version or the current one. We want to allow for both the pinned and the current versions
// because we want this code to work with both the pinned and unpinned version since some branches do not have the
// pinned contracts (like e.g. next)
const LEGACY_ORACLE_VERSION = 12;
if (isProtocolContract(this.contractAddress)) {
if (version !== LEGACY_ORACLE_VERSION && version !== ORACLE_VERSION) {
throw new Error(
`Expected legacy oracle version ${LEGACY_ORACLE_VERSION} or current oracle version ${ORACLE_VERSION} for alpha payload contract at ${this.contractAddress}, got ${version}.`,
);
}
return;
}

if (version !== ORACLE_VERSION) {
throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
}
Expand Down
Loading