Skip to content

Commit 8d16762

Browse files
authored
refactor: replace undefined scopes with 'ALL_SCOPES' string literal (#20448)
## Summary - Replace `undefined` with the `'ALL_SCOPES'` string literal across the scopes type (`'ALL_SCOPES' | AztecAddress[]`) to make the "all accounts" semantic explicit rather than relying on `undefined` - Update all call sites across `pxe`, `txe`, `wallet-sdk`, `wallets`, `cli-wallet`, `end-to-end`
2 parents f793699 + 0fe5b83 commit 8d16762

File tree

29 files changed

+189
-108
lines changed

29 files changed

+189
-108
lines changed

boxes/boxes/vanilla/app/embedded-wallet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ export class EmbeddedWallet extends BaseWallet {
366366
skipTxValidation: true,
367367
skipFeeEnforcement: true,
368368
overrides: { contracts: contractOverrides },
369+
scopes: this.scopesFor(opts.from)
369370
});
370371
}
371372
}

yarn-project/cli-wallet/src/cmds/check_tx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async function inspectTx(wallet: CLIWallet, aztecNode: AztecNode, txHash: TxHash
8888
for (const nullifier of effects.nullifiers) {
8989
const deployed = deployNullifiers[nullifier.toString()];
9090
const note = deployed
91-
? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed }))[0]
91+
? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed, scopes: 'ALL_SCOPES' }))[0]
9292
: undefined;
9393
const initialized = initNullifiers[nullifier.toString()];
9494
const registered = classNullifiers[nullifier.toString()];

yarn-project/cli-wallet/src/utils/wallet.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec
1313
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
1414
import { Fr } from '@aztec/foundation/curves/bn254';
1515
import type { LogFn } from '@aztec/foundation/log';
16+
import type { AccessScopes } from '@aztec/pxe/client/lazy';
1617
import type { PXEConfig } from '@aztec/pxe/config';
1718
import type { PXE } from '@aztec/pxe/server';
1819
import { createPXE, getPXEConfig } from '@aztec/pxe/server';
1920
import { AztecAddress } from '@aztec/stdlib/aztec-address';
2021
import { deriveSigningKey } from '@aztec/stdlib/keys';
21-
import { NoteDao } from '@aztec/stdlib/note';
2222
import type { NotesFilter } from '@aztec/stdlib/note';
23+
import { NoteDao } from '@aztec/stdlib/note';
2324
import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
2425
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
2526
import { BaseWallet, type FeeOptions } from '@aztec/wallet-sdk/base-wallet';
@@ -226,11 +227,19 @@ export class CLIWallet extends BaseWallet {
226227
executionPayload: ExecutionPayload,
227228
from: AztecAddress,
228229
feeOptions: FeeOptions,
230+
scopes: AccessScopes,
229231
skipTxValidation?: boolean,
230232
skipFeeEnforcement?: boolean,
231233
): Promise<TxSimulationResult> {
232234
if (from.equals(AztecAddress.ZERO)) {
233-
return super.simulateViaEntrypoint(executionPayload, from, feeOptions, skipTxValidation, skipFeeEnforcement);
235+
return super.simulateViaEntrypoint(
236+
executionPayload,
237+
from,
238+
feeOptions,
239+
scopes,
240+
skipTxValidation,
241+
skipFeeEnforcement,
242+
);
234243
}
235244

236245
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
@@ -258,6 +267,7 @@ export class CLIWallet extends BaseWallet {
258267
overrides: {
259268
contracts: { [from.toString()]: { instance, artifact } },
260269
},
270+
scopes,
261271
});
262272
}
263273

yarn-project/end-to-end/src/test-wallet/test_wallet.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { AccountManager, type SendOptions } from '@aztec/aztec.js/wallet';
1616
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
1717
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
1818
import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
19+
import type { AccessScopes } from '@aztec/pxe/client/lazy';
1920
import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
2021
import { PXE, type PXECreationOptions, createPXE } from '@aztec/pxe/server';
2122
import { AuthWitness } from '@aztec/stdlib/auth-witness';
@@ -227,18 +228,18 @@ export class TestWallet extends BaseWallet {
227228
executionPayload: ExecutionPayload,
228229
from: AztecAddress,
229230
feeOptions: FeeOptions,
231+
scopes: AccessScopes,
230232
skipTxValidation?: boolean,
231233
skipFeeEnforcement?: boolean,
232-
scopes?: AztecAddress[],
233234
): Promise<TxSimulationResult> {
234235
if (!this.simulatedSimulations) {
235236
return super.simulateViaEntrypoint(
236237
executionPayload,
237238
from,
238239
feeOptions,
240+
scopes,
239241
skipTxValidation,
240242
skipFeeEnforcement,
241-
scopes,
242243
);
243244
}
244245

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2+
3+
/**
4+
* Controls which accounts' private state and keys are accessible during execution.
5+
* - `'ALL_SCOPES'`: All registered accounts' private state and keys are accessible.
6+
* - `AztecAddress[]` with entries: Only the specified accounts' private state and keys are accessible.
7+
* - `[]` (empty array): Deny-all. No private state is visible and no keys are accessible.
8+
*/
9+
export type AccessScopes = 'ALL_SCOPES' | AztecAddress[];

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import {
8787
getFinalMinRevertibleSideEffectCounter,
8888
} from '@aztec/stdlib/tx';
8989

90+
import type { AccessScopes } from '../access_scopes.js';
9091
import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
9192
import type { AddressStore } from '../storage/address_store/address_store.js';
9293
import type { CapsuleStore } from '../storage/capsule_store/capsule_store.js';
@@ -117,8 +118,8 @@ export type ContractSimulatorRunOpts = {
117118
anchorBlockHeader: BlockHeader;
118119
/** The address used as a tagging sender when emitting private logs. */
119120
senderForTags?: AztecAddress;
120-
/** The accounts whose notes we can access in this call. Defaults to all. */
121-
scopes?: AztecAddress[];
121+
/** The accounts whose notes we can access in this call. */
122+
scopes: AccessScopes;
122123
/** The job ID for staged writes. */
123124
jobId: string;
124125
};
@@ -311,7 +312,7 @@ export class ContractFunctionSimulator {
311312
call: FunctionCall,
312313
authwits: AuthWitness[],
313314
anchorBlockHeader: BlockHeader,
314-
scopes: AztecAddress[] | undefined,
315+
scopes: AccessScopes,
315316
jobId: string,
316317
): Promise<Fr[]> {
317318
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ describe('Oracle Version Check test suite', () => {
146146
anchorBlockHeader,
147147
senderForTags,
148148
jobId: 'test',
149+
scopes: 'ALL_SCOPES',
149150
});
150151

151152
expect(utilityAssertCompatibleOracleVersionSpy).toHaveBeenCalledTimes(1);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ describe('Private Execution test suite', () => {
222222
anchorBlockHeader,
223223
senderForTags,
224224
jobId: TEST_JOB_ID,
225+
scopes: 'ALL_SCOPES',
225226
});
226227
};
227228

@@ -330,11 +331,12 @@ describe('Private Execution test suite', () => {
330331
contractAddress,
331332
contractStore,
332333
functionToInvokeAfterSync,
333-
call => utilityExecutor(call, undefined),
334+
utilityExecutor,
334335
noteStore,
335336
aztecNode,
336337
anchorBlockHeader,
337338
jobId,
339+
'ALL_SCOPES',
338340
);
339341
},
340342
);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
type TxContext,
2626
} from '@aztec/stdlib/tx';
2727

28+
import type { AccessScopes } from '../../access_scopes.js';
2829
import type { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
2930
import { NoteService } from '../../notes/note_service.js';
3031
import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
@@ -43,7 +44,7 @@ export type PrivateExecutionOracleArgs = Omit<UtilityExecutionOracleArgs, 'contr
4344
txContext: TxContext;
4445
callContext: CallContext;
4546
/** Needed to trigger contract synchronization before nested calls */
46-
utilityExecutor: (call: FunctionCall, scopes: undefined | AztecAddress[]) => Promise<void>;
47+
utilityExecutor: (call: FunctionCall, scopes: AccessScopes) => Promise<void>;
4748
executionCache: HashedValuesCache;
4849
noteCache: ExecutionNoteCache;
4950
taggingIndexCache: ExecutionTaggingIndexCache;
@@ -78,7 +79,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
7879
private readonly argsHash: Fr;
7980
private readonly txContext: TxContext;
8081
private readonly callContext: CallContext;
81-
private readonly utilityExecutor: (call: FunctionCall, scopes: undefined | AztecAddress[]) => Promise<void>;
82+
private readonly utilityExecutor: (call: FunctionCall, scopes: AccessScopes) => Promise<void>;
8283
private readonly executionCache: HashedValuesCache;
8384
private readonly noteCache: ExecutionNoteCache;
8485
private readonly taggingIndexCache: ExecutionTaggingIndexCache;
@@ -531,7 +532,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
531532
// We only expand for registered accounts because the log service needs the recipient's keys to derive
532533
// tagging secrets, which are only available for registered accounts.
533534
const expandedScopes =
534-
this.scopes && (await this.keyStore.hasAccount(targetContractAddress))
535+
this.scopes !== 'ALL_SCOPES' && (await this.keyStore.hasAccount(targetContractAddress))
535536
? [...this.scopes, targetContractAddress]
536537
: this.scopes;
537538

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ describe('Utility Execution test suite', () => {
220220
capsuleStore,
221221
privateEventStore,
222222
jobId: 'test-job-id',
223+
scopes: 'ALL_SCOPES',
223224
});
224225
});
225226

0 commit comments

Comments
 (0)