@aztec/pxe 0.0.1-commit.3fd054f6 → 0.0.1-commit.42ee6df9b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/block_synchronizer/block_synchronizer.d.ts +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +6 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +3 -4
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +4 -3
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -3
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +2 -5
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -3
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +2 -5
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +19 -19
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +18 -22
- package/dest/contract_function_simulator/oracle/oracle.d.ts +38 -19
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +60 -39
- package/dest/contract_function_simulator/oracle/private_execution.js +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +7 -8
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +16 -7
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +30 -29
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +115 -79
- package/dest/contract_logging.d.ts +9 -4
- package/dest/contract_logging.d.ts.map +1 -1
- package/dest/contract_logging.js +21 -6
- package/dest/contract_sync/contract_sync_service.d.ts +3 -4
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +12 -22
- package/dest/contract_sync/helpers.d.ts +2 -3
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +7 -2
- package/dest/debug/pxe_debug_utils.d.ts +3 -3
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.d.ts +1 -2
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +0 -1
- package/dest/entrypoints/client/lazy/index.d.ts +1 -2
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +0 -1
- package/dest/entrypoints/server/index.d.ts +1 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +0 -1
- package/dest/events/event_service.d.ts +3 -2
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +16 -4
- package/dest/logs/log_service.d.ts +6 -7
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +32 -30
- package/dest/messages/message_context_service.d.ts +3 -3
- package/dest/messages/message_context_service.d.ts.map +1 -1
- package/dest/messages/message_context_service.js +3 -3
- package/dest/notes/note_service.d.ts +4 -5
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +14 -5
- package/dest/notes_filter.d.ts +2 -3
- package/dest/notes_filter.d.ts.map +1 -1
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/pxe.d.ts +4 -5
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +6 -4
- package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +33 -28
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +1 -1
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +2 -2
- package/package.json +16 -16
- package/src/block_synchronizer/block_synchronizer.ts +6 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +6 -6
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +0 -3
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +0 -3
- package/src/contract_function_simulator/oracle/interfaces.ts +26 -17
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +13 -50
- package/src/contract_function_simulator/oracle/oracle.ts +79 -33
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -1
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +19 -10
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +204 -91
- package/src/contract_logging.ts +18 -5
- package/src/contract_sync/contract_sync_service.ts +32 -43
- package/src/contract_sync/helpers.ts +4 -4
- package/src/debug/pxe_debug_utils.ts +3 -3
- package/src/entrypoints/client/bundle/index.ts +0 -1
- package/src/entrypoints/client/lazy/index.ts +0 -1
- package/src/entrypoints/server/index.ts +0 -1
- package/src/events/event_service.ts +17 -4
- package/src/logs/log_service.ts +63 -48
- package/src/messages/message_context_service.ts +3 -4
- package/src/notes/note_service.ts +18 -8
- package/src/notes_filter.ts +1 -3
- package/src/oracle_version.ts +2 -2
- package/src/pxe.ts +11 -10
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +34 -26
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +2 -5
- package/dest/access_scopes.d.ts +0 -9
- package/dest/access_scopes.d.ts.map +0 -1
- package/dest/access_scopes.js +0 -6
- package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts +0 -16
- package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +0 -1
- package/dest/contract_function_simulator/noir-structs/message_tx_context.js +0 -57
- package/src/access_scopes.ts +0 -9
- package/src/contract_function_simulator/noir-structs/message_tx_context.ts +0 -55
package/src/contract_logging.ts
CHANGED
|
@@ -5,18 +5,22 @@ import type { DebugLog } from '@aztec/stdlib/logs';
|
|
|
5
5
|
|
|
6
6
|
/** Resolves a contract address to a human-readable name, if available. */
|
|
7
7
|
export type ContractNameResolver = (address: AztecAddress) => Promise<string | undefined>;
|
|
8
|
+
export type CONTRACT_LOG_KIND = 'aztecnr' | 'user';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
|
-
* Creates a logger whose output is prefixed with `
|
|
11
|
+
* Creates a logger whose output is prefixed with `contract:<name>(<addrAbbrev>)`.
|
|
11
12
|
*/
|
|
12
13
|
export async function createContractLogger(
|
|
13
14
|
contractAddress: AztecAddress,
|
|
14
15
|
getContractName: ContractNameResolver,
|
|
16
|
+
kind: CONTRACT_LOG_KIND,
|
|
15
17
|
options?: { instanceId?: string },
|
|
16
18
|
): Promise<Logger> {
|
|
17
19
|
const addrAbbrev = contractAddress.toString().slice(0, 10);
|
|
18
20
|
const name = await getContractName(contractAddress);
|
|
19
|
-
|
|
21
|
+
|
|
22
|
+
const prefix = kind == 'aztecnr' ? 'aztecnr' : 'contract';
|
|
23
|
+
const module = name ? `${prefix}:${name}(${addrAbbrev})` : `${prefix}:Unknown(${addrAbbrev})`;
|
|
20
24
|
return createLogger(module, options);
|
|
21
25
|
}
|
|
22
26
|
|
|
@@ -29,11 +33,20 @@ export function logContractMessage(logger: Logger, level: LogLevel, message: str
|
|
|
29
33
|
|
|
30
34
|
/**
|
|
31
35
|
* Displays debug logs collected during public function simulation,
|
|
32
|
-
* using the `
|
|
36
|
+
* using the `contract:` prefixed logger format.
|
|
33
37
|
*/
|
|
34
38
|
export async function displayDebugLogs(debugLogs: DebugLog[], getContractName: ContractNameResolver): Promise<void> {
|
|
35
39
|
for (const log of debugLogs) {
|
|
36
|
-
const
|
|
37
|
-
|
|
40
|
+
const { kind, message } = stripAztecnrLogPrefix(log.message);
|
|
41
|
+
const logger = await createContractLogger(log.contractAddress, getContractName, kind);
|
|
42
|
+
logContractMessage(logger, log.level, message, log.fields);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function stripAztecnrLogPrefix(message: string): { kind: CONTRACT_LOG_KIND; message: string } {
|
|
47
|
+
if (message.startsWith('[aztec-nr] ')) {
|
|
48
|
+
return { kind: 'aztecnr', message: message.slice('[aztec-nr] '.length) };
|
|
49
|
+
} else {
|
|
50
|
+
return { kind: 'user', message };
|
|
38
51
|
}
|
|
39
52
|
}
|
|
@@ -4,7 +4,6 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
4
4
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
5
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
6
6
|
|
|
7
|
-
import type { AccessScopes } from '../access_scopes.js';
|
|
8
7
|
import type { StagedStore } from '../job_coordinator/job_coordinator.js';
|
|
9
8
|
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
10
9
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
@@ -51,10 +50,10 @@ export class ContractSyncService implements StagedStore {
|
|
|
51
50
|
async ensureContractSynced(
|
|
52
51
|
contractAddress: AztecAddress,
|
|
53
52
|
functionToInvokeAfterSync: FunctionSelector | null,
|
|
54
|
-
utilityExecutor: (call: FunctionCall, scopes:
|
|
53
|
+
utilityExecutor: (call: FunctionCall, scopes: AztecAddress[]) => Promise<any>,
|
|
55
54
|
anchorBlockHeader: BlockHeader,
|
|
56
55
|
jobId: string,
|
|
57
|
-
scopes:
|
|
56
|
+
scopes: AztecAddress[],
|
|
58
57
|
): Promise<void> {
|
|
59
58
|
if (this.#shouldSkipSync(jobId, contractAddress)) {
|
|
60
59
|
return;
|
|
@@ -74,36 +73,42 @@ export class ContractSyncService implements StagedStore {
|
|
|
74
73
|
await this.#awaitSync(contractAddress, scopes);
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
/** Clears sync cache entries for the given scopes of a contract.
|
|
76
|
+
/** Clears sync cache entries for the given scopes of a contract. */
|
|
78
77
|
invalidateContractForScopes(contractAddress: AztecAddress, scopes: AztecAddress[]): void {
|
|
79
78
|
if (scopes.length === 0) {
|
|
80
79
|
return;
|
|
81
80
|
}
|
|
82
81
|
scopes.forEach(scope => this.syncedContracts.delete(toKey(contractAddress, scope)));
|
|
83
|
-
this.syncedContracts.delete(toKey(contractAddress, 'ALL_SCOPES'));
|
|
84
82
|
}
|
|
85
83
|
|
|
86
84
|
async #syncContract(
|
|
87
85
|
contractAddress: AztecAddress,
|
|
88
86
|
functionToInvokeAfterSync: FunctionSelector | null,
|
|
89
|
-
utilityExecutor: (call: FunctionCall, scopes:
|
|
87
|
+
utilityExecutor: (call: FunctionCall, scopes: AztecAddress[]) => Promise<any>,
|
|
90
88
|
anchorBlockHeader: BlockHeader,
|
|
91
89
|
jobId: string,
|
|
92
|
-
scopes:
|
|
90
|
+
scopes: AztecAddress[],
|
|
93
91
|
): Promise<void> {
|
|
94
92
|
this.log.debug(`Syncing contract ${contractAddress}`);
|
|
93
|
+
|
|
95
94
|
await Promise.all([
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
95
|
+
// Call sync_state sequentially for each scope address — each invocation synchronizes one account's private
|
|
96
|
+
// state using scoped capsule arrays.
|
|
97
|
+
(async () => {
|
|
98
|
+
for (const scope of scopes) {
|
|
99
|
+
await syncState(
|
|
100
|
+
contractAddress,
|
|
101
|
+
this.contractStore,
|
|
102
|
+
functionToInvokeAfterSync,
|
|
103
|
+
utilityExecutor,
|
|
104
|
+
this.noteStore,
|
|
105
|
+
this.aztecNode,
|
|
106
|
+
anchorBlockHeader,
|
|
107
|
+
jobId,
|
|
108
|
+
scope,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
})(),
|
|
107
112
|
verifyCurrentClassId(contractAddress, this.aztecNode, this.contractStore, anchorBlockHeader),
|
|
108
113
|
]);
|
|
109
114
|
this.log.debug(`Contract ${contractAddress} synced`);
|
|
@@ -136,11 +141,11 @@ export class ContractSyncService implements StagedStore {
|
|
|
136
141
|
/** If there are unsynced scopes, starts sync and stores the promise in cache with error cleanup. */
|
|
137
142
|
#startSyncIfNeeded(
|
|
138
143
|
contractAddress: AztecAddress,
|
|
139
|
-
scopes:
|
|
140
|
-
syncFn: (scopesToSync:
|
|
144
|
+
scopes: AztecAddress[],
|
|
145
|
+
syncFn: (scopesToSync: AztecAddress[]) => Promise<void>,
|
|
141
146
|
): void {
|
|
142
|
-
const scopesToSync = this
|
|
143
|
-
const keys =
|
|
147
|
+
const scopesToSync = scopes.filter(scope => !this.syncedContracts.has(toKey(contractAddress, scope)));
|
|
148
|
+
const keys = scopesToSync.map(scope => toKey(contractAddress, scope));
|
|
144
149
|
if (keys.length === 0) {
|
|
145
150
|
return;
|
|
146
151
|
}
|
|
@@ -151,31 +156,15 @@ export class ContractSyncService implements StagedStore {
|
|
|
151
156
|
keys.forEach(key => this.syncedContracts.set(key, promise));
|
|
152
157
|
}
|
|
153
158
|
|
|
154
|
-
/** Filters out scopes that are already cached, returning only those that still need syncing. */
|
|
155
|
-
#getScopesToSync(contractAddress: AztecAddress, scopes: AccessScopes): AccessScopes {
|
|
156
|
-
if (this.syncedContracts.has(toKey(contractAddress, 'ALL_SCOPES'))) {
|
|
157
|
-
// If we are already syncing all scopes, then return an empty list
|
|
158
|
-
return [];
|
|
159
|
-
}
|
|
160
|
-
if (scopes === 'ALL_SCOPES') {
|
|
161
|
-
return 'ALL_SCOPES';
|
|
162
|
-
}
|
|
163
|
-
return scopes.filter(scope => !this.syncedContracts.has(toKey(contractAddress, scope)));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
159
|
/** Collects all relevant scope promises (including in-flight ones from concurrent calls) and awaits them. */
|
|
167
|
-
async #awaitSync(contractAddress: AztecAddress, scopes:
|
|
168
|
-
const promises =
|
|
169
|
-
.map(
|
|
160
|
+
async #awaitSync(contractAddress: AztecAddress, scopes: AztecAddress[]): Promise<void> {
|
|
161
|
+
const promises = scopes
|
|
162
|
+
.map(scope => this.syncedContracts.get(toKey(contractAddress, scope)))
|
|
170
163
|
.filter(p => p !== undefined);
|
|
171
164
|
await Promise.all(promises);
|
|
172
165
|
}
|
|
173
166
|
}
|
|
174
167
|
|
|
175
|
-
function
|
|
176
|
-
return
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function toKey(contract: AztecAddress, scope: AztecAddress | 'ALL_SCOPES') {
|
|
180
|
-
return scope === 'ALL_SCOPES' ? `${contract.toString()}:*` : `${contract.toString()}:${scope.toString()}`;
|
|
168
|
+
function toKey(contract: AztecAddress, scope: AztecAddress) {
|
|
169
|
+
return `${contract.toString()}:${scope.toString()}`;
|
|
181
170
|
}
|
|
@@ -6,7 +6,6 @@ import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '
|
|
|
6
6
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
7
7
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
8
8
|
|
|
9
|
-
import type { AccessScopes } from '../access_scopes.js';
|
|
10
9
|
import { NoteService } from '../notes/note_service.js';
|
|
11
10
|
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
12
11
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
@@ -43,16 +42,16 @@ export async function syncState(
|
|
|
43
42
|
contractAddress: AztecAddress,
|
|
44
43
|
contractStore: ContractStore,
|
|
45
44
|
functionToInvokeAfterSync: FunctionSelector | null,
|
|
46
|
-
utilityExecutor: (privateSyncCall: FunctionCall, scopes:
|
|
45
|
+
utilityExecutor: (privateSyncCall: FunctionCall, scopes: AztecAddress[]) => Promise<any>,
|
|
47
46
|
noteStore: NoteStore,
|
|
48
47
|
aztecNode: AztecNode,
|
|
49
48
|
anchorBlockHeader: BlockHeader,
|
|
50
49
|
jobId: string,
|
|
51
|
-
|
|
50
|
+
scope: AztecAddress,
|
|
52
51
|
) {
|
|
53
52
|
// Protocol contracts don't have private state to sync
|
|
54
53
|
if (!isProtocolContract(contractAddress)) {
|
|
55
|
-
const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [], contractAddress);
|
|
54
|
+
const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [scope], contractAddress);
|
|
56
55
|
if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncStateFunctionCall.selector)) {
|
|
57
56
|
throw new Error(
|
|
58
57
|
'Forbidden `sync_state` invocation. `sync_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
|
|
@@ -60,6 +59,7 @@ export async function syncState(
|
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
const noteService = new NoteService(noteStore, aztecNode, anchorBlockHeader, jobId);
|
|
62
|
+
const scopes: AztecAddress[] = [scope];
|
|
63
63
|
|
|
64
64
|
// Both sync_state and syncNoteNullifiers interact with the note store, but running them in parallel is safe
|
|
65
65
|
// because note store is designed to handle concurrent operations.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { FunctionCall } from '@aztec/stdlib/abi';
|
|
2
2
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
4
|
import type { NoteDao } from '@aztec/stdlib/note';
|
|
4
5
|
import type { ContractOverrides } from '@aztec/stdlib/tx';
|
|
5
6
|
|
|
6
|
-
import type { AccessScopes } from '../access_scopes.js';
|
|
7
7
|
import type { BlockSynchronizer } from '../block_synchronizer/block_synchronizer.js';
|
|
8
8
|
import type { ContractFunctionSimulator } from '../contract_function_simulator/contract_function_simulator.js';
|
|
9
9
|
import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
|
|
@@ -22,7 +22,7 @@ export class PXEDebugUtils {
|
|
|
22
22
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
23
23
|
call: FunctionCall,
|
|
24
24
|
authWitnesses: AuthWitness[] | undefined,
|
|
25
|
-
scopes:
|
|
25
|
+
scopes: AztecAddress[],
|
|
26
26
|
jobId: string,
|
|
27
27
|
) => Promise<any>;
|
|
28
28
|
|
|
@@ -41,7 +41,7 @@ export class PXEDebugUtils {
|
|
|
41
41
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
42
42
|
call: FunctionCall,
|
|
43
43
|
authWitnesses: AuthWitness[] | undefined,
|
|
44
|
-
scopes:
|
|
44
|
+
scopes: AztecAddress[],
|
|
45
45
|
jobId: string,
|
|
46
46
|
) => Promise<any>,
|
|
47
47
|
) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import type { EventSelector } from '@aztec/stdlib/abi';
|
|
3
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
5
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
@@ -13,6 +14,7 @@ export class EventService {
|
|
|
13
14
|
private readonly aztecNode: AztecNode,
|
|
14
15
|
private readonly privateEventStore: PrivateEventStore,
|
|
15
16
|
private readonly jobId: string,
|
|
17
|
+
private readonly log = createLogger('pxe:event_service'),
|
|
16
18
|
) {}
|
|
17
19
|
|
|
18
20
|
public async validateAndStoreEvent(
|
|
@@ -36,19 +38,30 @@ export class EventService {
|
|
|
36
38
|
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
37
39
|
|
|
38
40
|
if (!txEffect) {
|
|
39
|
-
|
|
41
|
+
// We error out instead of just logging a warning and skipping the event because this would indicate a bug. This
|
|
42
|
+
// is because the node has already served info about this tx either when obtaining the log (TxScopedL2Log contain
|
|
43
|
+
// tx info) or when getting metadata for the offchain message (before the message got passed to `process_log`).
|
|
44
|
+
throw new Error(`Could not find tx effect for tx hash ${txHash} when processing an event.`);
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
if (txEffect.l2BlockNumber > anchorBlockNumber) {
|
|
43
|
-
|
|
48
|
+
// We should never process a message from a tx past the anchor block. If we got here, a preprocessing step made
|
|
49
|
+
// a mistake.
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Obtained a newer tx effect for ${txHash} for an event validation request than the anchor block ${anchorBlockNumber}. This is a bug as smart contracts should not issue event validation requests for events from blocks newer than the anchor block.`,
|
|
52
|
+
);
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
// Find the index of the event commitment in the nullifiers array to determine event ordering within the tx
|
|
47
56
|
const eventIndexInTx = txEffect.data.nullifiers.findIndex(n => n.equals(siloedEventCommitment));
|
|
48
57
|
if (eventIndexInTx === -1) {
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
// Unlike in NoteService, this might not be a bug since the commitment hasn't been verified yet in the message
|
|
59
|
+
// processing pipeline. A malformed or malicious message could trigger this condition. Because of this we don't
|
|
60
|
+
// error out and we just show a warning.
|
|
61
|
+
this.log.warn(
|
|
62
|
+
`Skipping event whose commitment is not present in its tx. siloedEventCommitment=${siloedEventCommitment}, contract=${contractAddress}, selector=${selector}, eventCommitment=${eventCommitment}, txHash=${txHash}`,
|
|
51
63
|
);
|
|
64
|
+
return;
|
|
52
65
|
}
|
|
53
66
|
|
|
54
67
|
return this.privateEventStore.storePrivateEventLog(
|
package/src/logs/log_service.ts
CHANGED
|
@@ -12,11 +12,10 @@ import {
|
|
|
12
12
|
} from '@aztec/stdlib/logs';
|
|
13
13
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
14
14
|
|
|
15
|
-
import type { AccessScopes } from '../access_scopes.js';
|
|
16
15
|
import type { LogRetrievalRequest } from '../contract_function_simulator/noir-structs/log_retrieval_request.js';
|
|
17
16
|
import { LogRetrievalResponse } from '../contract_function_simulator/noir-structs/log_retrieval_response.js';
|
|
18
17
|
import { AddressStore } from '../storage/address_store/address_store.js';
|
|
19
|
-
import {
|
|
18
|
+
import type { CapsuleService } from '../storage/capsule_store/capsule_service.js';
|
|
20
19
|
import type { RecipientTaggingStore } from '../storage/tagging_store/recipient_tagging_store.js';
|
|
21
20
|
import type { SenderAddressBookStore } from '../storage/tagging_store/sender_address_book_store.js';
|
|
22
21
|
import {
|
|
@@ -32,7 +31,7 @@ export class LogService {
|
|
|
32
31
|
private readonly aztecNode: AztecNode,
|
|
33
32
|
private readonly anchorBlockHeader: BlockHeader,
|
|
34
33
|
private readonly keyStore: KeyStore,
|
|
35
|
-
private readonly
|
|
34
|
+
private readonly capsuleService: CapsuleService,
|
|
36
35
|
private readonly recipientTaggingStore: RecipientTaggingStore,
|
|
37
36
|
private readonly senderAddressBookStore: SenderAddressBookStore,
|
|
38
37
|
private readonly addressStore: AddressStore,
|
|
@@ -42,7 +41,16 @@ export class LogService {
|
|
|
42
41
|
this.log = createLogger('pxe:log_service', bindings);
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
public async
|
|
44
|
+
public async fetchLogsByTag(
|
|
45
|
+
contractAddress: AztecAddress,
|
|
46
|
+
logRetrievalRequests: LogRetrievalRequest[],
|
|
47
|
+
): Promise<(LogRetrievalResponse | null)[]> {
|
|
48
|
+
for (const request of logRetrievalRequests) {
|
|
49
|
+
if (!contractAddress.equals(request.contractAddress)) {
|
|
50
|
+
throw new Error(`Got a log retrieval request from ${request.contractAddress}, expected ${contractAddress}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
46
54
|
return await Promise.all(
|
|
47
55
|
logRetrievalRequests.map(async request => {
|
|
48
56
|
const [publicLog, privateLog] = await Promise.all([
|
|
@@ -51,8 +59,8 @@ export class LogService {
|
|
|
51
59
|
]);
|
|
52
60
|
|
|
53
61
|
if (publicLog !== null && privateLog !== null) {
|
|
54
|
-
|
|
55
|
-
`Found both a public and private log
|
|
62
|
+
this.log.warn(
|
|
63
|
+
`Found both a public and private log for tag ${request.tag} from contract ${request.contractAddress}. This may indicate a contract bug. Returning the public log.`,
|
|
56
64
|
);
|
|
57
65
|
}
|
|
58
66
|
|
|
@@ -74,9 +82,8 @@ export class LogService {
|
|
|
74
82
|
if (logsForTag.length === 0) {
|
|
75
83
|
return null;
|
|
76
84
|
} else if (logsForTag.length > 1) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
`Got ${logsForTag.length} logs for tag ${tag} and contract ${contractAddress.toString()}. getPublicLogByTag currently only supports a single log per tag`,
|
|
85
|
+
this.log.warn(
|
|
86
|
+
`Expected at most 1 public log for tag ${tag} and contract ${contractAddress.toString()}, got ${logsForTag.length}. This may indicate a contract bug. Returning the first log.`,
|
|
80
87
|
);
|
|
81
88
|
}
|
|
82
89
|
|
|
@@ -98,9 +105,8 @@ export class LogService {
|
|
|
98
105
|
if (logsForTag.length === 0) {
|
|
99
106
|
return null;
|
|
100
107
|
} else if (logsForTag.length > 1) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
`Got ${logsForTag.length} logs for tag ${siloedTag}. getPrivateLogByTag currently only supports a single log per tag`,
|
|
108
|
+
this.log.warn(
|
|
109
|
+
`Expected at most 1 private log for tag ${siloedTag}, got ${logsForTag.length}. This may indicate a contract bug. Returning the first log.`,
|
|
104
110
|
);
|
|
105
111
|
}
|
|
106
112
|
|
|
@@ -114,46 +120,40 @@ export class LogService {
|
|
|
114
120
|
);
|
|
115
121
|
}
|
|
116
122
|
|
|
117
|
-
public async fetchTaggedLogs(
|
|
123
|
+
public async fetchTaggedLogs(
|
|
124
|
+
contractAddress: AztecAddress,
|
|
125
|
+
pendingTaggedLogArrayBaseSlot: Fr,
|
|
126
|
+
recipient: AztecAddress,
|
|
127
|
+
) {
|
|
118
128
|
this.log.verbose(`Fetching tagged logs for ${contractAddress.toString()}`);
|
|
119
129
|
|
|
120
130
|
// We only load logs from block up to and including the anchor block number
|
|
121
131
|
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
122
132
|
const anchorBlockHash = await this.anchorBlockHeader.hash();
|
|
123
133
|
|
|
124
|
-
//
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
this.recipientTaggingStore,
|
|
141
|
-
anchorBlockNumber,
|
|
142
|
-
anchorBlockHash,
|
|
143
|
-
this.jobId,
|
|
144
|
-
),
|
|
145
|
-
),
|
|
146
|
-
);
|
|
134
|
+
// Get all secrets for this recipient (one per sender)
|
|
135
|
+
const secrets = await this.#getSecretsForSenders(contractAddress, recipient);
|
|
136
|
+
|
|
137
|
+
// Load logs for all sender-recipient pairs in parallel
|
|
138
|
+
const logArrays = await Promise.all(
|
|
139
|
+
secrets.map(secret =>
|
|
140
|
+
loadPrivateLogsForSenderRecipientPair(
|
|
141
|
+
secret,
|
|
142
|
+
this.aztecNode,
|
|
143
|
+
this.recipientTaggingStore,
|
|
144
|
+
anchorBlockNumber,
|
|
145
|
+
anchorBlockHash,
|
|
146
|
+
this.jobId,
|
|
147
|
+
),
|
|
148
|
+
),
|
|
149
|
+
);
|
|
147
150
|
|
|
148
|
-
|
|
149
|
-
|
|
151
|
+
// Flatten all logs from all secrets
|
|
152
|
+
const allLogs = logArrays.flat();
|
|
150
153
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
}),
|
|
156
|
-
);
|
|
154
|
+
if (allLogs.length > 0) {
|
|
155
|
+
await this.#storePendingTaggedLogs(contractAddress, pendingTaggedLogArrayBaseSlot, recipient, allLogs);
|
|
156
|
+
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
async #getSecretsForSenders(
|
|
@@ -176,14 +176,24 @@ export class LogService {
|
|
|
176
176
|
);
|
|
177
177
|
|
|
178
178
|
return Promise.all(
|
|
179
|
-
deduplicatedSenders.map(sender => {
|
|
180
|
-
|
|
179
|
+
deduplicatedSenders.map(async sender => {
|
|
180
|
+
const secret = await ExtendedDirectionalAppTaggingSecret.compute(
|
|
181
181
|
recipientCompleteAddress,
|
|
182
182
|
recipientIvsk,
|
|
183
183
|
sender,
|
|
184
184
|
contractAddress,
|
|
185
185
|
recipient,
|
|
186
186
|
);
|
|
187
|
+
|
|
188
|
+
if (!secret) {
|
|
189
|
+
// Note that all senders originate from either the SenderAddressBookStore or the KeyStore.
|
|
190
|
+
// TODO(F-512): make sure we actually prevent registering invalid senders.
|
|
191
|
+
throw new Error(
|
|
192
|
+
`Failed to compute a tagging secret for sender ${sender} - this implies this is an invalid address, which should not happen as they have been previously registered in PXE.`,
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return secret;
|
|
187
197
|
}),
|
|
188
198
|
);
|
|
189
199
|
}
|
|
@@ -201,13 +211,18 @@ export class LogService {
|
|
|
201
211
|
scopedLog.txHash,
|
|
202
212
|
scopedLog.noteHashes,
|
|
203
213
|
scopedLog.firstNullifier,
|
|
204
|
-
recipient,
|
|
205
214
|
);
|
|
206
215
|
|
|
207
216
|
return pendingTaggedLog.toFields();
|
|
208
217
|
});
|
|
209
218
|
|
|
210
219
|
// TODO: This looks like it could belong more at the oracle interface level
|
|
211
|
-
return this.
|
|
220
|
+
return this.capsuleService.appendToCapsuleArray(
|
|
221
|
+
contractAddress,
|
|
222
|
+
capsuleArrayBaseSlot,
|
|
223
|
+
pendingTaggedLogs,
|
|
224
|
+
this.jobId,
|
|
225
|
+
recipient,
|
|
226
|
+
);
|
|
212
227
|
}
|
|
213
228
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
|
+
import { MessageContext } from '@aztec/stdlib/logs';
|
|
3
4
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
4
5
|
|
|
5
|
-
import { MessageTxContext } from '../contract_function_simulator/noir-structs/message_tx_context.js';
|
|
6
|
-
|
|
7
6
|
/** Resolves transaction hashes into the context needed to process messages. */
|
|
8
7
|
export class MessageContextService {
|
|
9
8
|
constructor(private readonly aztecNode: AztecNode) {}
|
|
@@ -15,7 +14,7 @@ export class MessageContextService {
|
|
|
15
14
|
* process messages that originated from that transaction. Returns `null` for tx hashes that are zero, not yet
|
|
16
15
|
* available, or in blocks beyond the anchor block.
|
|
17
16
|
*/
|
|
18
|
-
|
|
17
|
+
getMessageContextsByTxHash(txHashes: Fr[], anchorBlockNumber: number): Promise<(MessageContext | null)[]> {
|
|
19
18
|
// TODO: optimize, we might be hitting the node to get the same txHash repeatedly
|
|
20
19
|
return Promise.all(
|
|
21
20
|
txHashes.map(async txHashField => {
|
|
@@ -38,7 +37,7 @@ export class MessageContextService {
|
|
|
38
37
|
throw new Error(`Tx effect for ${txHash} has no nullifiers`);
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
return new
|
|
40
|
+
return new MessageContext(data.txHash, data.noteHashes, data.nullifiers[0]);
|
|
42
41
|
}),
|
|
43
42
|
);
|
|
44
43
|
}
|
|
@@ -7,7 +7,6 @@ import { Note, NoteDao, NoteStatus } from '@aztec/stdlib/note';
|
|
|
7
7
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
8
8
|
import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
|
|
9
9
|
|
|
10
|
-
import type { AccessScopes } from '../access_scopes.js';
|
|
11
10
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
12
11
|
|
|
13
12
|
export class NoteService {
|
|
@@ -32,7 +31,7 @@ export class NoteService {
|
|
|
32
31
|
owner: AztecAddress | undefined,
|
|
33
32
|
storageSlot: Fr,
|
|
34
33
|
status: NoteStatus,
|
|
35
|
-
scopes:
|
|
34
|
+
scopes: AztecAddress[],
|
|
36
35
|
) {
|
|
37
36
|
const noteDaos = await this.noteStore.getNotes(
|
|
38
37
|
{
|
|
@@ -71,7 +70,7 @@ export class NoteService {
|
|
|
71
70
|
*
|
|
72
71
|
* @param contractAddress - The contract whose notes should be checked and nullified.
|
|
73
72
|
*/
|
|
74
|
-
public async syncNoteNullifiers(contractAddress: AztecAddress, scopes:
|
|
73
|
+
public async syncNoteNullifiers(contractAddress: AztecAddress, scopes: AztecAddress[]): Promise<void> {
|
|
75
74
|
const anchorBlockHash = await this.anchorBlockHeader.hash();
|
|
76
75
|
|
|
77
76
|
const contractNotes = await this.noteStore.getNotes({ contractAddress, scopes }, this.jobId);
|
|
@@ -121,7 +120,7 @@ export class NoteService {
|
|
|
121
120
|
noteHash: Fr,
|
|
122
121
|
nullifier: Fr,
|
|
123
122
|
txHash: TxHash,
|
|
124
|
-
|
|
123
|
+
scope: AztecAddress,
|
|
125
124
|
): Promise<void> {
|
|
126
125
|
// We are going to store the new note in the NoteStore, which will let us later return it via `getNotes`.
|
|
127
126
|
// There's two things we need to check before we do this however:
|
|
@@ -155,16 +154,28 @@ export class NoteService {
|
|
|
155
154
|
this.aztecNode.findLeavesIndexes(anchorBlockHash, MerkleTreeId.NULLIFIER_TREE, [siloedNullifier]),
|
|
156
155
|
]);
|
|
157
156
|
if (!txEffect) {
|
|
158
|
-
|
|
157
|
+
// We error out instead of just logging a warning and skipping the note because this would indicate a bug. This
|
|
158
|
+
// is because the node has already served info about this tx either when obtaining the log (TxScopedL2Log contain
|
|
159
|
+
// tx info) or when getting metadata for the offchain message (before the message got passed to `process_log`).
|
|
160
|
+
throw new Error(`Could not find tx effect for tx hash ${txHash} when processing a note.`);
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
if (txEffect.l2BlockNumber > anchorBlockNumber) {
|
|
162
|
-
|
|
164
|
+
// If the message was delivered onchain, this would indicate a bug: log sync should never load logs from blocks
|
|
165
|
+
// newer than the anchor block. If the note came via an offchain message, it would likely also be a bug, since we
|
|
166
|
+
// sync a new anchor block before calling `process_message`. For this not to be a bug, the message would need to
|
|
167
|
+
// come from a newer block than the anchor served by the node, implying the node isn't properly synced.
|
|
168
|
+
// We therefore error out here rather than assuming the offchain message was constructed by a malicious
|
|
169
|
+
// sender with the intention of bricking recipient's PXE (if we assumed that we would just ignore the message).
|
|
170
|
+
throw new Error(
|
|
171
|
+
`Obtained a newer tx effect for ${txHash} for a note validation request than the anchor block ${anchorBlockNumber}. This is a bug as we should not ever be processing a note from a newer block than the anchor block.`,
|
|
172
|
+
);
|
|
163
173
|
}
|
|
164
174
|
|
|
165
175
|
// Find the index of the note hash in the noteHashes array to determine note ordering within the tx
|
|
166
176
|
const noteIndexInTx = txEffect.data.noteHashes.findIndex(nh => nh.equals(uniqueNoteHash));
|
|
167
177
|
if (noteIndexInTx === -1) {
|
|
178
|
+
// Similar to the comment above - we error out as this would indicate a bug in nonce discovery.
|
|
168
179
|
throw new Error(`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present in tx ${txHash}`);
|
|
169
180
|
}
|
|
170
181
|
|
|
@@ -184,8 +195,7 @@ export class NoteService {
|
|
|
184
195
|
noteIndexInTx,
|
|
185
196
|
);
|
|
186
197
|
|
|
187
|
-
|
|
188
|
-
await this.noteStore.addNotes([noteDao], recipient, this.jobId);
|
|
198
|
+
await this.noteStore.addNotes([noteDao], scope, this.jobId);
|
|
189
199
|
|
|
190
200
|
if (nullifierIndex !== undefined) {
|
|
191
201
|
// We found nullifier index which implies that the note has already been nullified.
|
package/src/notes_filter.ts
CHANGED
|
@@ -2,8 +2,6 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
4
4
|
|
|
5
|
-
import type { AccessScopes } from './access_scopes.js';
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* A filter used to fetch notes.
|
|
9
7
|
* @remarks This filter is applied as an intersection of all its params.
|
|
@@ -22,5 +20,5 @@ export type NotesFilter = {
|
|
|
22
20
|
status?: NoteStatus;
|
|
23
21
|
/** The siloed nullifier for the note. */
|
|
24
22
|
siloedNullifier?: Fr;
|
|
25
|
-
scopes:
|
|
23
|
+
scopes: AztecAddress[];
|
|
26
24
|
};
|
package/src/oracle_version.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
///
|
|
5
5
|
/// @dev Whenever a contract function or Noir test is run, the `aztec_utl_assertCompatibleOracleVersion` oracle is called
|
|
6
6
|
/// and if the oracle version is incompatible an error is thrown.
|
|
7
|
-
export const ORACLE_VERSION =
|
|
7
|
+
export const ORACLE_VERSION = 22;
|
|
8
8
|
|
|
9
9
|
/// This hash is computed as by hashing the Oracle interface and it is used to detect when the Oracle interface changes,
|
|
10
10
|
/// which in turn implies that you need to update the ORACLE_VERSION constant in this file and in
|
|
11
11
|
/// `noir-projects/aztec-nr/aztec/src/oracle/version.nr`.
|
|
12
|
-
export const ORACLE_INTERFACE_HASH = '
|
|
12
|
+
export const ORACLE_INTERFACE_HASH = '83f1de1a9741a34916fd58cf12b857d0bac90f74bf00751b20304301a3f5c8eb';
|