Skip to content

Commit 102bfdd

Browse files
authored
feat: merge-train/fairies (#22048)
BEGIN_COMMIT_OVERRIDE chore: rename pxe-side oracle implementations (#22044) END_COMMIT_OVERRIDE
2 parents 264c3cc + 53014a8 commit 102bfdd

17 files changed

Lines changed: 212 additions & 193 deletions

yarn-project/pxe/src/contract_function_simulator/contract_function_simulator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export class ContractFunctionSimulator {
284284
);
285285
const publicFunctionsCalldata = await Promise.all(
286286
publicCallRequests.map(async r => {
287-
const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
287+
const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
288288
return new HashedValues(calldata, r.calldataHash);
289289
}),
290290
);

yarn-project/pxe/src/contract_function_simulator/oracle/interfaces.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export interface IUtilityExecutionOracle {
8686
nullifier: Fr,
8787
): Promise<NullifierMembershipWitness | undefined>;
8888
getBlockHeader(blockNumber: BlockNumber): Promise<BlockHeader | undefined>;
89-
tryGetPublicKeysAndPartialAddress(
89+
getPublicKeysAndPartialAddress(
9090
account: AztecAddress,
9191
): Promise<{ publicKeys: PublicKeys; partialAddress: PartialAddress } | undefined>;
9292
getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined>;
@@ -107,19 +107,19 @@ export interface IUtilityExecutionOracle {
107107
offset: number,
108108
status: NoteStatus,
109109
): Promise<NoteData[]>;
110-
checkNullifierExists(innerNullifier: Fr): Promise<boolean>;
110+
doesNullifierExist(innerNullifier: Fr): Promise<boolean>;
111111
getL1ToL2MembershipWitness(
112112
contractAddress: AztecAddress,
113113
messageHash: Fr,
114114
secret: Fr,
115115
): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>>;
116-
storageRead(
116+
getFromPublicStorage(
117117
anchorBlockHash: BlockHash,
118118
contractAddress: AztecAddress,
119119
startStorageSlot: Fr,
120120
numberOfElements: number,
121121
): Promise<Fr[]>;
122-
fetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr, scope: AztecAddress): Promise<void>;
122+
getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr, scope: AztecAddress): Promise<void>;
123123
validateAndStoreEnqueuedNotesAndEvents(
124124
contractAddress: AztecAddress,
125125
noteValidationRequestsArrayBaseSlot: Fr,
@@ -128,20 +128,20 @@ export interface IUtilityExecutionOracle {
128128
maxEventSerializedLen: number,
129129
scope: AztecAddress,
130130
): Promise<void>;
131-
bulkRetrieveLogs(
131+
getLogsByTag(
132132
contractAddress: AztecAddress,
133133
logRetrievalRequestsArrayBaseSlot: Fr,
134134
logRetrievalResponsesArrayBaseSlot: Fr,
135135
scope: AztecAddress,
136136
): Promise<void>;
137-
utilityResolveMessageContexts(
137+
getMessageContextsByTxHash(
138138
contractAddress: AztecAddress,
139139
messageContextRequestsArrayBaseSlot: Fr,
140140
messageContextResponsesArrayBaseSlot: Fr,
141141
scope: AztecAddress,
142142
): Promise<void>;
143-
storeCapsule(contractAddress: AztecAddress, key: Fr, capsule: Fr[], scope: AztecAddress): void;
144-
loadCapsule(contractAddress: AztecAddress, key: Fr, scope: AztecAddress): Promise<Fr[] | null>;
143+
setCapsule(contractAddress: AztecAddress, key: Fr, capsule: Fr[], scope: AztecAddress): void;
144+
getCapsule(contractAddress: AztecAddress, key: Fr, scope: AztecAddress): Promise<Fr[] | null>;
145145
deleteCapsule(contractAddress: AztecAddress, key: Fr, scope: AztecAddress): void;
146146
copyCapsule(
147147
contractAddress: AztecAddress,
@@ -150,9 +150,9 @@ export interface IUtilityExecutionOracle {
150150
numEntries: number,
151151
scope: AztecAddress,
152152
): Promise<void>;
153-
aes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer>;
153+
decryptAes128(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer>;
154154
getSharedSecret(address: AztecAddress, ephPk: Point, contractAddress: AztecAddress): Promise<Fr>;
155-
invalidateContractSyncCache(contractAddress: AztecAddress, scopes: AztecAddress[]): void;
155+
setContractSyncCacheInvalid(contractAddress: AztecAddress, scopes: AztecAddress[]): void;
156156
emitOffchainEffect(data: Fr[]): Promise<void>;
157157
}
158158

@@ -163,8 +163,8 @@ export interface IUtilityExecutionOracle {
163163
export interface IPrivateExecutionOracle {
164164
isPrivate: true;
165165

166-
storeInExecutionCache(values: Fr[], hash: Fr): void;
167-
loadFromExecutionCache(hash: Fr): Promise<Fr[]>;
166+
setHashPreimage(values: Fr[], hash: Fr): void;
167+
getHashPreimage(hash: Fr): Promise<Fr[]>;
168168
notifyCreatedNote(
169169
owner: AztecAddress,
170170
storageSlot: Fr,
@@ -185,9 +185,9 @@ export interface IPrivateExecutionOracle {
185185
sideEffectCounter: number,
186186
isStaticCall: boolean,
187187
): Promise<{ endSideEffectCounter: Fr; returnsHash: Fr }>;
188-
validatePublicCalldata(calldataHash: Fr): Promise<void>;
188+
assertValidPublicCalldata(calldataHash: Fr): Promise<void>;
189189
notifyRevertiblePhaseStart(minRevertibleSideEffectCounter: number): Promise<void>;
190-
inRevertiblePhase(sideEffectCounter: number): Promise<boolean>;
190+
isExecutionInRevertiblePhase(sideEffectCounter: number): Promise<boolean>;
191191
getSenderForTags(): Promise<AztecAddress | undefined>;
192192
setSenderForTags(senderForTags: AztecAddress): Promise<void>;
193193
getNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<Tag>;

yarn-project/pxe/src/contract_function_simulator/oracle/oracle.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ export class UnavailableOracleError extends Error {
2727

2828
/**
2929
* A data source that has all the apis required by Aztec.nr.
30+
*
31+
* ## Oracle naming conventions
32+
*
33+
* We try to keep oracle naming consistent, please see below the conventions we adhere to.
34+
*
35+
* Each oracle method name has the form `aztec_{scope}_{verb}{Object}`, where:
36+
*
37+
* - **Scope prefix** indicates the execution context required:
38+
* - `aztec_prv_` — available only during private function execution.
39+
* - `aztec_utl_` — available during both utility and private execution.
40+
*
41+
* - **Verb** signals the operation's semantics (verb-first, then object):
42+
* - `get` — read / lookup / get data from oracle into contract.
43+
* - `does`/`is`/`has` — predicate (returns boolean).
44+
* - `emit`/`notify` — propagate data from contract to oracle.
45+
* - `set` — contract driven oracle state mutation (capsules, execution cache, tagging, etc).
46+
* - `call` — trigger nested execution (control flow).
47+
* - `assert` — validate a condition, throw on failure.
48+
* - Standalone verbs (`delete`, `copy`, `decrypt`, `log`, etc) are used when no generic verb fits.
3049
*/
3150
export class Oracle {
3251
constructor(private handler: IMiscOracle | IUtilityExecutionOracle | IPrivateExecutionOracle) {}
@@ -109,13 +128,13 @@ export class Oracle {
109128

110129
// eslint-disable-next-line camelcase
111130
aztec_prv_setHashPreimage(values: ACVMField[], [hash]: ACVMField[]): Promise<ACVMField[]> {
112-
this.handlerAsPrivate().storeInExecutionCache(values.map(Fr.fromString), Fr.fromString(hash));
131+
this.handlerAsPrivate().setHashPreimage(values.map(Fr.fromString), Fr.fromString(hash));
113132
return Promise.resolve([]);
114133
}
115134

116135
// eslint-disable-next-line camelcase
117136
async aztec_prv_getHashPreimage([returnsHash]: ACVMField[]): Promise<ACVMField[][]> {
118-
const values = await this.handlerAsPrivate().loadFromExecutionCache(Fr.fromString(returnsHash));
137+
const values = await this.handlerAsPrivate().getHashPreimage(Fr.fromString(returnsHash));
119138
return [values.map(toACVMField)];
120139
}
121140

@@ -254,7 +273,7 @@ export class Oracle {
254273
// eslint-disable-next-line camelcase
255274
async aztec_utl_getPublicKeysAndPartialAddress([address]: ACVMField[]): Promise<(ACVMField | ACVMField[])[]> {
256275
const parsedAddress = AztecAddress.fromField(Fr.fromString(address));
257-
const result = await this.handlerAsUtility().tryGetPublicKeysAndPartialAddress(parsedAddress);
276+
const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(parsedAddress);
258277

259278
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
260279
// with two fields: `some` (a boolean) and `value` (a field array in this case).
@@ -381,7 +400,7 @@ export class Oracle {
381400

382401
// eslint-disable-next-line camelcase
383402
async aztec_utl_doesNullifierExist([innerNullifier]: ACVMField[]): Promise<ACVMField[]> {
384-
const exists = await this.handlerAsUtility().checkNullifierExists(Fr.fromString(innerNullifier));
403+
const exists = await this.handlerAsUtility().doesNullifierExist(Fr.fromString(innerNullifier));
385404
return [toACVMField(exists)];
386405
}
387406

@@ -406,7 +425,7 @@ export class Oracle {
406425
[startStorageSlot]: ACVMField[],
407426
[numberOfElements]: ACVMField[],
408427
): Promise<ACVMField[][]> {
409-
const values = await this.handlerAsUtility().storageRead(
428+
const values = await this.handlerAsUtility().getFromPublicStorage(
410429
BlockHash.fromString(blockHash),
411430
new AztecAddress(Fr.fromString(contractAddress)),
412431
Fr.fromString(startStorageSlot),
@@ -465,7 +484,7 @@ export class Oracle {
465484

466485
// eslint-disable-next-line camelcase
467486
async aztec_prv_assertValidPublicCalldata([calldataHash]: ACVMField[]): Promise<ACVMField[]> {
468-
await this.handlerAsPrivate().validatePublicCalldata(Fr.fromString(calldataHash));
487+
await this.handlerAsPrivate().assertValidPublicCalldata(Fr.fromString(calldataHash));
469488
return [];
470489
}
471490

@@ -477,7 +496,9 @@ export class Oracle {
477496

478497
// eslint-disable-next-line camelcase
479498
async aztec_prv_isExecutionInRevertiblePhase([sideEffectCounter]: ACVMField[]): Promise<ACVMField[]> {
480-
const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(Fr.fromString(sideEffectCounter).toNumber());
499+
const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(
500+
Fr.fromString(sideEffectCounter).toNumber(),
501+
);
481502
return Promise.resolve([toACVMField(isRevertible)]);
482503
}
483504

@@ -495,7 +516,7 @@ export class Oracle {
495516
[pendingTaggedLogArrayBaseSlot]: ACVMField[],
496517
[scope]: ACVMField[],
497518
): Promise<ACVMField[]> {
498-
await this.handlerAsUtility().fetchTaggedLogs(
519+
await this.handlerAsUtility().getPendingTaggedLogs(
499520
Fr.fromString(pendingTaggedLogArrayBaseSlot),
500521
AztecAddress.fromString(scope),
501522
);
@@ -530,7 +551,7 @@ export class Oracle {
530551
[logRetrievalResponsesArrayBaseSlot]: ACVMField[],
531552
[scope]: ACVMField[],
532553
): Promise<ACVMField[]> {
533-
await this.handlerAsUtility().bulkRetrieveLogs(
554+
await this.handlerAsUtility().getLogsByTag(
534555
AztecAddress.fromString(contractAddress),
535556
Fr.fromString(logRetrievalRequestsArrayBaseSlot),
536557
Fr.fromString(logRetrievalResponsesArrayBaseSlot),
@@ -546,7 +567,7 @@ export class Oracle {
546567
[messageContextResponsesArrayBaseSlot]: ACVMField[],
547568
[scope]: ACVMField[],
548569
): Promise<ACVMField[]> {
549-
await this.handlerAsUtility().utilityResolveMessageContexts(
570+
await this.handlerAsUtility().getMessageContextsByTxHash(
550571
AztecAddress.fromString(contractAddress),
551572
Fr.fromString(messageContextRequestsArrayBaseSlot),
552573
Fr.fromString(messageContextResponsesArrayBaseSlot),
@@ -562,7 +583,7 @@ export class Oracle {
562583
capsule: ACVMField[],
563584
[scope]: ACVMField[],
564585
): Promise<ACVMField[]> {
565-
this.handlerAsUtility().storeCapsule(
586+
this.handlerAsUtility().setCapsule(
566587
AztecAddress.fromField(Fr.fromString(contractAddress)),
567588
Fr.fromString(slot),
568589
capsule.map(Fr.fromString),
@@ -578,7 +599,7 @@ export class Oracle {
578599
[tSize]: ACVMField[],
579600
[scope]: ACVMField[],
580601
): Promise<(ACVMField | ACVMField[])[]> {
581-
const values = await this.handlerAsUtility().loadCapsule(
602+
const values = await this.handlerAsUtility().getCapsule(
582603
AztecAddress.fromField(Fr.fromString(contractAddress)),
583604
Fr.fromString(slot),
584605
AztecAddress.fromField(Fr.fromString(scope)),
@@ -640,7 +661,7 @@ export class Oracle {
640661

641662
// Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
642663
try {
643-
const plaintext = await this.handlerAsUtility().aes128Decrypt(ciphertext, ivBuffer, symKeyBuffer);
664+
const plaintext = await this.handlerAsUtility().decryptAes128(ciphertext, ivBuffer, symKeyBuffer);
644665
const [storage, length] = bufferToBoundedVec(plaintext, ciphertextBVecStorage.length);
645666
return [toACVMField(1), storage, length];
646667
} catch {
@@ -672,7 +693,7 @@ export class Oracle {
672693
[scopeCount]: ACVMField[],
673694
): Promise<ACVMField[]> {
674695
const scopeAddresses = scopes.slice(0, +scopeCount).map(s => AztecAddress.fromField(Fr.fromString(s)));
675-
this.handlerAsUtility().invalidateContractSyncCache(
696+
this.handlerAsUtility().setContractSyncCacheInvalid(
676697
AztecAddress.fromField(Fr.fromString(contractAddress)),
677698
scopeAddresses,
678699
);

yarn-project/pxe/src/contract_function_simulator/oracle/oracle_version_is_checked.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('Oracle Version Check test suite', () => {
6666

6767
aztecNode.getPublicStorageAt.mockResolvedValue(Fr.ZERO);
6868
anchorBlockHeader = BlockHeader.random();
69-
capsuleStore.loadCapsule.mockImplementation((_, __) => Promise.resolve(null));
69+
capsuleStore.getCapsule.mockImplementation((_, __) => Promise.resolve(null));
7070
capsuleStore.readCapsuleArray.mockResolvedValue([]);
7171
senderTaggingStore.getLastFinalizedIndex.mockResolvedValue(undefined);
7272
senderTaggingStore.getLastUsedIndex.mockResolvedValue(undefined);

yarn-project/pxe/src/contract_function_simulator/oracle/private_execution.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ describe('Private Execution test suite', () => {
286286
senderAddressBookStore = mock<SenderAddressBookStore>();
287287
contractSyncService = mock<ContractSyncService>();
288288
messageContextService = mock<MessageContextService>();
289-
messageContextService.resolveMessageContexts.mockResolvedValue([]);
289+
messageContextService.getMessageContextsByTxHash.mockResolvedValue([]);
290290
// Configure mock to actually perform sync_state calls (needed for nested call tests)
291291
contractSyncService.ensureContractSynced.mockImplementation(
292292
async (contractAddress, functionToInvokeAfterSync, utilityExecutor, anchorBlockHeader, jobId, scopes) => {
@@ -436,7 +436,7 @@ describe('Private Execution test suite', () => {
436436
});
437437
});
438438

439-
capsuleStore.loadCapsule.mockImplementation((_, __) => Promise.resolve(null));
439+
capsuleStore.getCapsule.mockImplementation((_, __) => Promise.resolve(null));
440440

441441
aztecNode.getPublicStorageAt.mockImplementation(
442442
(_block: BlockParameter, _address: AztecAddress, _storageSlot: Fr) => {

yarn-project/pxe/src/contract_function_simulator/oracle/private_execution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export async function executePrivateFunction(
7676

7777
const contractClassLogs = privateExecutionOracle.getContractClassLogs();
7878

79-
const rawReturnValues = await privateExecutionOracle.loadFromExecutionCache(publicInputs.returnsHash);
79+
const rawReturnValues = await privateExecutionOracle.getHashPreimage(publicInputs.returnsHash);
8080

8181
const newNotes = privateExecutionOracle.getNewNotes();
8282
const noteHashNullifierCounterMap = privateExecutionOracle.getNoteHashNullifierCounterMap();

yarn-project/pxe/src/contract_function_simulator/oracle/private_execution_oracle.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
265265
* @param values - Values to store.
266266
* @returns The hash of the values.
267267
*/
268-
public storeInExecutionCache(values: Fr[], hash: Fr) {
268+
public setHashPreimage(values: Fr[], hash: Fr) {
269269
return this.executionCache.store(values, hash);
270270
}
271271

@@ -274,15 +274,15 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
274274
* @param hash - Hash of the values.
275275
* @returns The values.
276276
*/
277-
public loadFromExecutionCache(hash: Fr): Promise<Fr[]> {
277+
public getHashPreimage(hash: Fr): Promise<Fr[]> {
278278
const preimage = this.executionCache.getPreimage(hash);
279279
if (!preimage) {
280280
throw new Error(`Preimage for hash ${hash.toString()} not found in cache`);
281281
}
282282
return Promise.resolve(preimage);
283283
}
284284

285-
override async checkNullifierExists(innerNullifier: Fr): Promise<boolean> {
285+
override async doesNullifierExist(innerNullifier: Fr): Promise<boolean> {
286286
// This oracle must be overridden because while utility execution can only meaningfully check if a nullifier exists
287287
// in the synched block, during private execution there's also the possibility of it being pending, i.e. created
288288
// in the current transaction.
@@ -295,7 +295,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
295295

296296
return (
297297
this.noteCache.getNullifiers(this.contractAddress).has(nullifier) ||
298-
(await super.checkNullifierExists(innerNullifier))
298+
(await super.doesNullifierExist(innerNullifier))
299299
);
300300
}
301301

@@ -598,7 +598,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
598598
}
599599

600600
/** Validates the calldata preimage exists in the cache and checks cumulative calldata size is within limits. */
601-
public validatePublicCalldata(calldataHash: Fr) {
601+
public assertValidPublicCalldata(calldataHash: Fr) {
602602
const calldata = this.executionCache.getPreimage(calldataHash);
603603
if (!calldata) {
604604
throw new Error('Calldata for public call not found in cache');
@@ -615,7 +615,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
615615
return this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
616616
}
617617

618-
public inRevertiblePhase(sideEffectCounter: number): Promise<boolean> {
618+
public isExecutionInRevertiblePhase(sideEffectCounter: number): Promise<boolean> {
619619
return Promise.resolve(this.noteCache.isSideEffectCounterRevertible(sideEffectCounter));
620620
}
621621

0 commit comments

Comments
 (0)