@aztec/pxe 0.0.1-commit.d1f2d6c → 0.0.1-commit.e6bd8901
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/bin/check_oracle_version.js +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +2 -2
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +3 -22
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +0 -46
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +2 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +3 -3
- package/dest/contract_sync/index.d.ts +23 -0
- package/dest/contract_sync/index.d.ts.map +1 -0
- package/dest/contract_sync/index.js +56 -0
- package/dest/debug/pxe_debug_utils.js +1 -1
- package/dest/entrypoints/server/index.d.ts +2 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -0
- package/dest/events/event_service.d.ts +2 -2
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +1 -1
- package/dest/notes/note_service.d.ts +2 -2
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +1 -1
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/pxe.js +1 -1
- package/dest/storage/contract_store/contract_store.d.ts +1 -2
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +0 -12
- package/dest/storage/note_store/note_store.d.ts +1 -1
- package/dest/storage/note_store/note_store.js +2 -2
- package/package.json +16 -16
- package/src/bin/check_oracle_version.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
- package/src/contract_function_simulator/oracle/oracle.ts +2 -2
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -79
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +2 -1
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +3 -3
- package/src/contract_sync/index.ts +100 -0
- package/src/debug/pxe_debug_utils.ts +1 -1
- package/src/entrypoints/server/index.ts +1 -0
- package/src/events/event_service.ts +1 -1
- package/src/notes/note_service.ts +1 -1
- package/src/oracle_version.ts +2 -2
- package/src/pxe.ts +1 -1
- package/src/storage/contract_store/contract_store.ts +0 -20
- package/src/storage/note_store/note_store.ts +2 -2
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ProtocolContractAddress, isProtocolContract } from '@aztec/protocol-contracts';
|
|
2
|
+
import type { FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
5
|
+
import type { ContractInstance } from '@aztec/stdlib/contract';
|
|
6
|
+
import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
|
|
7
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
8
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
9
|
+
|
|
10
|
+
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Read the current class id of a contract from the execution data provider or AztecNode. If not found, class id
|
|
14
|
+
* from the instance is used.
|
|
15
|
+
* @param contractAddress - The address of the contract to read the class id for.
|
|
16
|
+
* @param instance - The instance of the contract.
|
|
17
|
+
* @param aztecNode - The Aztec node to query for storage.
|
|
18
|
+
* @param header - The header of the block at which to load the DelayedPublicMutable storing the class id.
|
|
19
|
+
* @returns The current class id.
|
|
20
|
+
*/
|
|
21
|
+
export async function readCurrentClassId(
|
|
22
|
+
contractAddress: AztecAddress,
|
|
23
|
+
instance: ContractInstance,
|
|
24
|
+
aztecNode: AztecNode,
|
|
25
|
+
header: BlockHeader,
|
|
26
|
+
) {
|
|
27
|
+
const blockHashFr = await header.hash();
|
|
28
|
+
const blockHash = L2BlockHash.fromField(blockHashFr);
|
|
29
|
+
const timestamp = header.globalVariables.timestamp;
|
|
30
|
+
const { delayedPublicMutableSlot } = await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(contractAddress);
|
|
31
|
+
const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(delayedPublicMutableSlot, slot =>
|
|
32
|
+
aztecNode.getPublicStorageAt(blockHash, ProtocolContractAddress.ContractInstanceRegistry, slot),
|
|
33
|
+
);
|
|
34
|
+
let currentClassId = delayedPublicMutableValues.svc.getCurrentAt(timestamp)[0];
|
|
35
|
+
if (currentClassId.isZero()) {
|
|
36
|
+
currentClassId = instance.originalContractClassId;
|
|
37
|
+
}
|
|
38
|
+
return currentClassId;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function syncState(
|
|
42
|
+
contractAddress: AztecAddress,
|
|
43
|
+
contractStore: ContractStore,
|
|
44
|
+
functionToInvokeAfterSync: FunctionSelector | null,
|
|
45
|
+
utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>,
|
|
46
|
+
) {
|
|
47
|
+
// Protocol contracts don't have private state to sync
|
|
48
|
+
if (!isProtocolContract(contractAddress)) {
|
|
49
|
+
const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [], contractAddress);
|
|
50
|
+
if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncStateFunctionCall.selector)) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
'Forbidden `sync_state` invocation. `sync_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return utilityExecutor(syncStateFunctionCall);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Verify that the current class id of a contract obtained from AztecNode is the same as the one in contract data
|
|
62
|
+
* provider (i.e. PXE's own storage).
|
|
63
|
+
* @param header - The header of the block at which to verify the current class id.
|
|
64
|
+
*/
|
|
65
|
+
async function verifyCurrentClassId(
|
|
66
|
+
contractAddress: AztecAddress,
|
|
67
|
+
aztecNode: AztecNode,
|
|
68
|
+
contractStore: ContractStore,
|
|
69
|
+
header: BlockHeader,
|
|
70
|
+
) {
|
|
71
|
+
const instance = await contractStore.getContractInstance(contractAddress);
|
|
72
|
+
if (!instance) {
|
|
73
|
+
throw new Error(`No contract instance found for address ${contractAddress.toString()}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const currentClassId = await readCurrentClassId(contractAddress, instance, aztecNode, header);
|
|
77
|
+
if (!instance.currentContractClassId.equals(currentClassId)) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`Contract ${contractAddress} is outdated, current class id is ${currentClassId}, local class id is ${instance.currentContractClassId}`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Ensures the contract's private state is synchronized and that the PXE holds the current class artifact for
|
|
86
|
+
* the contract.
|
|
87
|
+
*/
|
|
88
|
+
export async function ensureContractSynced(
|
|
89
|
+
contractAddress: AztecAddress,
|
|
90
|
+
functionToInvokeAfterSync: FunctionSelector | null,
|
|
91
|
+
utilityExecutor: (call: FunctionCall) => Promise<any>,
|
|
92
|
+
aztecNode: AztecNode,
|
|
93
|
+
contractStore: ContractStore,
|
|
94
|
+
header: BlockHeader,
|
|
95
|
+
): Promise<void> {
|
|
96
|
+
await Promise.all([
|
|
97
|
+
syncState(contractAddress, contractStore, functionToInvokeAfterSync, utilityExecutor),
|
|
98
|
+
verifyCurrentClassId(contractAddress, aztecNode, contractStore, header),
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
@@ -41,7 +41,7 @@ export class PXEDebugUtils {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// We need to manually trigger private state sync to have a guarantee that all the notes are available.
|
|
44
|
-
const call = await this.contractStore.getFunctionCall('
|
|
44
|
+
const call = await this.contractStore.getFunctionCall('sync_state', [], filter.contractAddress);
|
|
45
45
|
await this.#pxe.simulateUtility(call);
|
|
46
46
|
|
|
47
47
|
return this.noteStore.getNotes(filter, randomBytes(8).toString('hex'));
|
|
@@ -7,3 +7,4 @@ export { NoteService } from '../../notes/note_service.js';
|
|
|
7
7
|
export { ORACLE_VERSION } from '../../oracle_version.js';
|
|
8
8
|
export { type PXECreationOptions } from '../pxe_creation_options.js';
|
|
9
9
|
export { JobCoordinator } from '../../job_coordinator/job_coordinator.js';
|
|
10
|
+
export { syncState } from '../../contract_sync/index.js';
|
|
@@ -112,7 +112,7 @@ export class NoteService {
|
|
|
112
112
|
await this.noteStore.applyNullifiers(foundNullifiers, this.jobId);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
public async
|
|
115
|
+
public async validateAndStoreNote(
|
|
116
116
|
contractAddress: AztecAddress,
|
|
117
117
|
owner: AztecAddress,
|
|
118
118
|
storageSlot: Fr,
|
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 `utilityAssertCompatibleOracleVersion` 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 = 9;
|
|
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 = '9866cc52510acaef75a3d47a0ed501fd9ff92b9d53b2c8a88c8a3ffd04ced81f';
|
package/src/pxe.ts
CHANGED
|
@@ -59,8 +59,8 @@ import {
|
|
|
59
59
|
ContractFunctionSimulator,
|
|
60
60
|
generateSimulatedProvingResult,
|
|
61
61
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
62
|
-
import { ensureContractSynced, readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
|
|
63
62
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
63
|
+
import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
|
|
64
64
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
65
65
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
66
66
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
@@ -3,7 +3,6 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
4
4
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
5
5
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
6
|
-
import { isProtocolContract } from '@aztec/protocol-contracts';
|
|
7
6
|
import {
|
|
8
7
|
type ContractArtifact,
|
|
9
8
|
type FunctionAbi,
|
|
@@ -317,23 +316,4 @@ export class ContractStore {
|
|
|
317
316
|
returnTypes: functionDao.returnTypes,
|
|
318
317
|
};
|
|
319
318
|
}
|
|
320
|
-
|
|
321
|
-
// Synchronize target contract data
|
|
322
|
-
public async syncPrivateState(
|
|
323
|
-
contractAddress: AztecAddress,
|
|
324
|
-
functionToInvokeAfterSync: FunctionSelector | null,
|
|
325
|
-
utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>,
|
|
326
|
-
) {
|
|
327
|
-
// Protocol contracts don't have private state to sync
|
|
328
|
-
if (!isProtocolContract(contractAddress)) {
|
|
329
|
-
const syncPrivateStateFunctionCall = await this.getFunctionCall('sync_private_state', [], contractAddress);
|
|
330
|
-
if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncPrivateStateFunctionCall.selector)) {
|
|
331
|
-
throw new Error(
|
|
332
|
-
'Forbidden `sync_private_state` invocation. `sync_private_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return utilityExecutor(syncPrivateStateFunctionCall);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
319
|
}
|
|
@@ -173,7 +173,7 @@ export class NoteStore implements StagedStore {
|
|
|
173
173
|
* The operation is atomic - if any nullifier is not found, the entire operation fails and no notes are modified.
|
|
174
174
|
*
|
|
175
175
|
* applyNullifiers is idempotent: the same nullifier can be applied multiple times without error.
|
|
176
|
-
* This relaxes constraints on usage of NoteService#
|
|
176
|
+
* This relaxes constraints on usage of NoteService#validateAndStoreNote, which can then be run concurrently in a Promise.all
|
|
177
177
|
* context without risking unnecessarily defensive checks failing.
|
|
178
178
|
*
|
|
179
179
|
* @param nullifiers - Array of nullifiers with their block numbers to process
|
|
@@ -339,7 +339,7 @@ export class NoteStore implements StagedStore {
|
|
|
339
339
|
/**
|
|
340
340
|
* Functions run withJobLock are forced to wait for each other, i.e. if they share a `jobId`, they run serially
|
|
341
341
|
* instead of concurrently. This is needed because staged data is stored in memory, and concurrent async operations
|
|
342
|
-
* (e.g., Promise.all in `
|
|
342
|
+
* (e.g., Promise.all in `validateAndStoreNote`) could otherwise interleave and corrupt state.
|
|
343
343
|
*/
|
|
344
344
|
async #withJobLock<T>(jobId: string, fn: () => Promise<T>): Promise<T> {
|
|
345
345
|
let lock = this.#jobLocks.get(jobId);
|