@aztec/pxe 0.0.1-commit.87a0206 → 0.0.1-commit.8f9871590
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/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +53 -29
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +168 -64
- 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 +3 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +35 -36
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +71 -18
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +31 -11
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +49 -31
- package/dest/contract_sync/contract_sync_service.d.ts +4 -2
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +34 -19
- package/dest/contract_sync/helpers.d.ts +3 -2
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +3 -3
- package/dest/debug/pxe_debug_utils.d.ts +5 -4
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +1 -1
- package/dest/entrypoints/client/bundle/index.d.ts +3 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +9 -1
- package/dest/entrypoints/client/lazy/index.d.ts +3 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +2 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +9 -1
- package/dest/entrypoints/server/index.d.ts +3 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -0
- package/dest/entrypoints/server/utils.js +9 -1
- package/dest/logs/log_service.d.ts +3 -2
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +5 -10
- package/dest/notes/note_service.d.ts +4 -3
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +3 -2
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +6 -6
- package/dest/pxe.d.ts +57 -22
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +42 -35
- package/dest/storage/note_store/note_store.d.ts +3 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +3 -4
- package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +4 -4
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/package.json +16 -16
- package/src/access_scopes.ts +9 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +315 -121
- package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
- package/src/contract_function_simulator/oracle/oracle.ts +3 -3
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +92 -93
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +89 -30
- package/src/contract_sync/contract_sync_service.ts +49 -26
- package/src/contract_sync/helpers.ts +7 -2
- package/src/debug/pxe_debug_utils.ts +8 -6
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/index.ts +2 -0
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/logs/log_service.ts +7 -19
- package/src/notes/note_service.ts +4 -3
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +2 -2
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/private_kernel_execution_prover.ts +6 -6
- package/src/pxe.ts +104 -74
- package/src/storage/note_store/note_store.ts +8 -5
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +4 -4
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
|
@@ -52,6 +52,14 @@ export async function createPXE(
|
|
|
52
52
|
const protocolContractsProvider = new BundledProtocolContractsProvider();
|
|
53
53
|
|
|
54
54
|
const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
|
|
55
|
-
const pxe = await PXE.create(
|
|
55
|
+
const pxe = await PXE.create({
|
|
56
|
+
node: aztecNode,
|
|
57
|
+
store,
|
|
58
|
+
proofCreator: prover,
|
|
59
|
+
simulator,
|
|
60
|
+
protocolContractsProvider,
|
|
61
|
+
config,
|
|
62
|
+
loggerOrSuffix: pxeLogger,
|
|
63
|
+
});
|
|
56
64
|
return pxe;
|
|
57
65
|
}
|
|
@@ -52,6 +52,14 @@ export async function createPXE(
|
|
|
52
52
|
const protocolContractsProvider = new LazyProtocolContractsProvider();
|
|
53
53
|
|
|
54
54
|
const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
|
|
55
|
-
const pxe = await PXE.create(
|
|
55
|
+
const pxe = await PXE.create({
|
|
56
|
+
node: aztecNode,
|
|
57
|
+
store,
|
|
58
|
+
proofCreator: prover,
|
|
59
|
+
simulator,
|
|
60
|
+
protocolContractsProvider,
|
|
61
|
+
config,
|
|
62
|
+
loggerOrSuffix: pxeLogger,
|
|
63
|
+
});
|
|
56
64
|
return pxe;
|
|
57
65
|
}
|
|
@@ -58,14 +58,14 @@ export async function createPXE(
|
|
|
58
58
|
const protocolContractsProvider = new BundledProtocolContractsProvider();
|
|
59
59
|
|
|
60
60
|
const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
|
|
61
|
-
const pxe = await PXE.create(
|
|
62
|
-
aztecNode,
|
|
63
|
-
options.store,
|
|
64
|
-
prover,
|
|
61
|
+
const pxe = await PXE.create({
|
|
62
|
+
node: aztecNode,
|
|
63
|
+
store: options.store,
|
|
64
|
+
proofCreator: prover,
|
|
65
65
|
simulator,
|
|
66
66
|
protocolContractsProvider,
|
|
67
|
-
configWithContracts,
|
|
68
|
-
pxeLogger,
|
|
69
|
-
);
|
|
67
|
+
config: configWithContracts,
|
|
68
|
+
loggerOrSuffix: pxeLogger,
|
|
69
|
+
});
|
|
70
70
|
return pxe;
|
|
71
71
|
}
|
package/src/logs/log_service.ts
CHANGED
|
@@ -2,11 +2,11 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
2
2
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import type { KeyStore } from '@aztec/key-store';
|
|
4
4
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import type { CompleteAddress } from '@aztec/stdlib/contract';
|
|
6
5
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
7
6
|
import { DirectionalAppTaggingSecret, PendingTaggedLog, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
8
7
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
9
8
|
|
|
9
|
+
import type { AccessScopes } from '../access_scopes.js';
|
|
10
10
|
import type { LogRetrievalRequest } from '../contract_function_simulator/noir-structs/log_retrieval_request.js';
|
|
11
11
|
import { LogRetrievalResponse } from '../contract_function_simulator/noir-structs/log_retrieval_response.js';
|
|
12
12
|
import { AddressStore } from '../storage/address_store/address_store.js';
|
|
@@ -108,11 +108,7 @@ export class LogService {
|
|
|
108
108
|
);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
public async fetchTaggedLogs(
|
|
112
|
-
contractAddress: AztecAddress,
|
|
113
|
-
pendingTaggedLogArrayBaseSlot: Fr,
|
|
114
|
-
scopes?: AztecAddress[],
|
|
115
|
-
) {
|
|
111
|
+
public async fetchTaggedLogs(contractAddress: AztecAddress, pendingTaggedLogArrayBaseSlot: Fr, scopes: AccessScopes) {
|
|
116
112
|
this.log.verbose(`Fetching tagged logs for ${contractAddress.toString()}`);
|
|
117
113
|
|
|
118
114
|
// We only load logs from block up to and including the anchor block number
|
|
@@ -120,7 +116,7 @@ export class LogService {
|
|
|
120
116
|
const anchorBlockHash = await this.anchorBlockHeader.hash();
|
|
121
117
|
|
|
122
118
|
// Determine recipients: use scopes if provided, otherwise get all accounts
|
|
123
|
-
const recipients = scopes && scopes.length > 0 ? scopes : await this.keyStore.getAccounts();
|
|
119
|
+
const recipients = scopes !== 'ALL_SCOPES' && scopes.length > 0 ? scopes : await this.keyStore.getAccounts();
|
|
124
120
|
|
|
125
121
|
// For each recipient, fetch secrets, load logs, and store them.
|
|
126
122
|
// We run these per-recipient tasks in parallel so that logs are loaded for all recipients concurrently.
|
|
@@ -159,7 +155,10 @@ export class LogService {
|
|
|
159
155
|
contractAddress: AztecAddress,
|
|
160
156
|
recipient: AztecAddress,
|
|
161
157
|
): Promise<DirectionalAppTaggingSecret[]> {
|
|
162
|
-
const recipientCompleteAddress = await this
|
|
158
|
+
const recipientCompleteAddress = await this.addressStore.getCompleteAddress(recipient);
|
|
159
|
+
if (!recipientCompleteAddress) {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
163
162
|
const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
|
|
164
163
|
|
|
165
164
|
// We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves
|
|
@@ -206,15 +205,4 @@ export class LogService {
|
|
|
206
205
|
// TODO: This looks like it could belong more at the oracle interface level
|
|
207
206
|
return this.capsuleStore.appendToCapsuleArray(contractAddress, capsuleArrayBaseSlot, pendingTaggedLogs, this.jobId);
|
|
208
207
|
}
|
|
209
|
-
|
|
210
|
-
async #getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
|
|
211
|
-
const completeAddress = await this.addressStore.getCompleteAddress(account);
|
|
212
|
-
if (!completeAddress) {
|
|
213
|
-
throw new Error(
|
|
214
|
-
`No public key registered for address ${account}.
|
|
215
|
-
Register it by calling pxe.addAccount(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
return completeAddress;
|
|
219
|
-
}
|
|
220
208
|
}
|
|
@@ -7,6 +7,7 @@ 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';
|
|
10
11
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
11
12
|
|
|
12
13
|
export class NoteService {
|
|
@@ -31,7 +32,7 @@ export class NoteService {
|
|
|
31
32
|
owner: AztecAddress | undefined,
|
|
32
33
|
storageSlot: Fr,
|
|
33
34
|
status: NoteStatus,
|
|
34
|
-
scopes
|
|
35
|
+
scopes: AccessScopes,
|
|
35
36
|
) {
|
|
36
37
|
const noteDaos = await this.noteStore.getNotes(
|
|
37
38
|
{
|
|
@@ -70,10 +71,10 @@ export class NoteService {
|
|
|
70
71
|
*
|
|
71
72
|
* @param contractAddress - The contract whose notes should be checked and nullified.
|
|
72
73
|
*/
|
|
73
|
-
public async syncNoteNullifiers(contractAddress: AztecAddress): Promise<void> {
|
|
74
|
+
public async syncNoteNullifiers(contractAddress: AztecAddress, scopes: AccessScopes): Promise<void> {
|
|
74
75
|
const anchorBlockHash = await this.anchorBlockHeader.hash();
|
|
75
76
|
|
|
76
|
-
const contractNotes = await this.noteStore.getNotes({ contractAddress }, this.jobId);
|
|
77
|
+
const contractNotes = await this.noteStore.getNotes({ contractAddress, scopes }, this.jobId);
|
|
77
78
|
|
|
78
79
|
if (contractNotes.length === 0) {
|
|
79
80
|
return;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
4
|
+
|
|
5
|
+
import type { AccessScopes } from './access_scopes.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A filter used to fetch notes.
|
|
9
|
+
* @remarks This filter is applied as an intersection of all its params.
|
|
10
|
+
*/
|
|
11
|
+
export type NotesFilter = {
|
|
12
|
+
/**
|
|
13
|
+
* The contract address the note belongs to.
|
|
14
|
+
* @remarks Providing a contract address is required as we need that information to trigger private state sync.
|
|
15
|
+
*/
|
|
16
|
+
contractAddress: AztecAddress;
|
|
17
|
+
/** The owner of the note. */
|
|
18
|
+
owner?: AztecAddress;
|
|
19
|
+
/** The specific storage location of the note on the contract. */
|
|
20
|
+
storageSlot?: Fr;
|
|
21
|
+
/** The status of the note. Defaults to 'ACTIVE'. */
|
|
22
|
+
status?: NoteStatus;
|
|
23
|
+
/** The siloed nullifier for the note. */
|
|
24
|
+
siloedNullifier?: Fr;
|
|
25
|
+
scopes: AccessScopes;
|
|
26
|
+
};
|
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 = 12;
|
|
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 = '666a8a7fc697f72b29dbf0ae7464db269cf5afa019acac8861f814543147dbb4';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_TX_LIFETIME } from '@aztec/constants';
|
|
2
2
|
import type { PrivateKernelCircuitPublicInputs } from '@aztec/stdlib/kernel';
|
|
3
3
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
4
4
|
|
|
@@ -8,12 +8,12 @@ const ROUNDED_DURATIONS = [
|
|
|
8
8
|
1, // 1 second
|
|
9
9
|
];
|
|
10
10
|
|
|
11
|
-
function roundTimestamp(blockTimestamp: bigint,
|
|
11
|
+
function roundTimestamp(blockTimestamp: bigint, expirationTimestamp: bigint): UInt64 {
|
|
12
12
|
return ROUNDED_DURATIONS.reduce((timestamp, duration) => {
|
|
13
13
|
if (timestamp <= blockTimestamp) {
|
|
14
14
|
// The timestamp must be greater than the block timestamp.
|
|
15
15
|
// If it is too small, round it down again using a smaller duration.
|
|
16
|
-
const totalDuration =
|
|
16
|
+
const totalDuration = expirationTimestamp - blockTimestamp;
|
|
17
17
|
const roundedDuration = totalDuration - (totalDuration % BigInt(duration));
|
|
18
18
|
return blockTimestamp + roundedDuration;
|
|
19
19
|
}
|
|
@@ -21,36 +21,36 @@ function roundTimestamp(blockTimestamp: bigint, includeByTimestamp: bigint): UIn
|
|
|
21
21
|
}, 0n);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function
|
|
24
|
+
export function computeTxExpirationTimestamp(
|
|
25
25
|
previousKernel: PrivateKernelCircuitPublicInputs,
|
|
26
|
-
|
|
26
|
+
txLifetime = MAX_TX_LIFETIME,
|
|
27
27
|
): UInt64 {
|
|
28
|
-
if (
|
|
28
|
+
if (txLifetime > MAX_TX_LIFETIME) {
|
|
29
29
|
throw new Error(
|
|
30
|
-
`Custom
|
|
30
|
+
`Custom tx lifetime cannot be greater than the max allowed. Max allowed: ${MAX_TX_LIFETIME}. Custom value: ${txLifetime}.`,
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const anchorBlockTimestamp = previousKernel.constants.anchorBlockHeader.globalVariables.timestamp;
|
|
35
|
-
const maxTimestamp = anchorBlockTimestamp + BigInt(
|
|
36
|
-
const
|
|
35
|
+
const maxTimestamp = anchorBlockTimestamp + BigInt(txLifetime);
|
|
36
|
+
const expirationTimestamp = previousKernel.expirationTimestamp;
|
|
37
37
|
|
|
38
|
-
// If the
|
|
38
|
+
// If the expirationTimestamp set during the tx execution is greater than or equal to the max allowed duration,
|
|
39
39
|
// use the maximum allowed timestamp.
|
|
40
40
|
// Note: It shouldn't be larger than the max allowed duration, but we check for it anyway.
|
|
41
|
-
if (
|
|
41
|
+
if (expirationTimestamp >= maxTimestamp) {
|
|
42
42
|
return maxTimestamp;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// Round it down to the nearest hour/min/second to reduce precision and avoid revealing the exact value.
|
|
46
46
|
// This makes it harder for others to infer what function calls may have been used to produce a specific timestamp.
|
|
47
|
-
const roundedTimestamp = roundTimestamp(anchorBlockTimestamp,
|
|
47
|
+
const roundedTimestamp = roundTimestamp(anchorBlockTimestamp, expirationTimestamp);
|
|
48
48
|
|
|
49
49
|
// The tx can't be published if the timestamp is the same or less than the anchor block's timestamp.
|
|
50
50
|
// Future blocks will have a greater timestamp, so the tx would never be included.
|
|
51
51
|
if (roundedTimestamp <= anchorBlockTimestamp) {
|
|
52
52
|
throw new Error(
|
|
53
|
-
`Include-by timestamp must be greater than the anchor block timestamp. Anchor block timestamp: ${anchorBlockTimestamp}. Include-by timestamp: ${
|
|
53
|
+
`Include-by timestamp must be greater than the anchor block timestamp. Anchor block timestamp: ${anchorBlockTimestamp}. Include-by timestamp: ${expirationTimestamp}.`,
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './private_kernel_reset_private_inputs_builder.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './compute_tx_expiration_timestamp.js';
|
|
@@ -260,20 +260,20 @@ export class PrivateKernelExecutionProver {
|
|
|
260
260
|
// TODO: Enable padding once we better understand the final amounts to pad to.
|
|
261
261
|
const paddedSideEffectAmounts = PaddedSideEffectAmounts.empty();
|
|
262
262
|
|
|
263
|
-
// Use the aggregated
|
|
264
|
-
// TODO: Call `
|
|
265
|
-
const
|
|
263
|
+
// Use the aggregated expirationTimestamp set throughout the tx execution.
|
|
264
|
+
// TODO: Call `computeTxExpirationTimestamp` to round the value down and reduce precision, improving privacy.
|
|
265
|
+
const expirationTimestampUpperBound = previousKernelData.publicInputs.expirationTimestamp;
|
|
266
266
|
const anchorBlockTimestamp = previousKernelData.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp;
|
|
267
|
-
if (
|
|
267
|
+
if (expirationTimestampUpperBound <= anchorBlockTimestamp) {
|
|
268
268
|
throw new Error(
|
|
269
|
-
`Include-by timestamp must be greater than the anchor block timestamp. Anchor block timestamp: ${anchorBlockTimestamp}. Include-by timestamp: ${
|
|
269
|
+
`Include-by timestamp must be greater than the anchor block timestamp. Anchor block timestamp: ${anchorBlockTimestamp}. Include-by timestamp: ${expirationTimestampUpperBound}.`,
|
|
270
270
|
);
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
const privateInputs = new PrivateKernelTailCircuitPrivateInputs(
|
|
274
274
|
previousKernelData,
|
|
275
275
|
paddedSideEffectAmounts,
|
|
276
|
-
|
|
276
|
+
expirationTimestampUpperBound,
|
|
277
277
|
);
|
|
278
278
|
|
|
279
279
|
const witgenTimer = new Timer();
|
package/src/pxe.ts
CHANGED
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
|
|
53
53
|
import { inspect } from 'util';
|
|
54
54
|
|
|
55
|
+
import type { AccessScopes } from './access_scopes.js';
|
|
55
56
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
56
57
|
import type { PXEConfig } from './config/index.js';
|
|
57
58
|
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
@@ -86,6 +87,56 @@ export type PackedPrivateEvent = InTx & {
|
|
|
86
87
|
eventSelector: EventSelector;
|
|
87
88
|
};
|
|
88
89
|
|
|
90
|
+
/** Options for PXE.profileTx. */
|
|
91
|
+
export type ProfileTxOpts = {
|
|
92
|
+
/** The profiling mode to use. */
|
|
93
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
94
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
95
|
+
skipProofGeneration?: boolean;
|
|
96
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
97
|
+
scopes: AccessScopes;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** Options for PXE.simulateTx. */
|
|
101
|
+
export type SimulateTxOpts = {
|
|
102
|
+
/** Whether to simulate the public part of the transaction. */
|
|
103
|
+
simulatePublic: boolean;
|
|
104
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
105
|
+
skipTxValidation?: boolean;
|
|
106
|
+
/** If false, fees are enforced. */
|
|
107
|
+
skipFeeEnforcement?: boolean;
|
|
108
|
+
/** State overrides for the simulation, such as contract instances and artifacts. */
|
|
109
|
+
overrides?: SimulationOverrides;
|
|
110
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
111
|
+
scopes: AccessScopes;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** Options for PXE.simulateUtility. */
|
|
115
|
+
export type SimulateUtilityOpts = {
|
|
116
|
+
/** The authentication witnesses required for the function call. */
|
|
117
|
+
authwits?: AuthWitness[];
|
|
118
|
+
/** The accounts whose notes we can access in this call */
|
|
119
|
+
scopes: AccessScopes;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/** Args for PXE.create. */
|
|
123
|
+
export type PXECreateArgs = {
|
|
124
|
+
/** The Aztec node to connect to. */
|
|
125
|
+
node: AztecNode;
|
|
126
|
+
/** The key-value store for persisting PXE state. */
|
|
127
|
+
store: AztecAsyncKVStore;
|
|
128
|
+
/** The prover for generating private kernel proofs. */
|
|
129
|
+
proofCreator: PrivateKernelProver;
|
|
130
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
131
|
+
simulator: CircuitSimulator;
|
|
132
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
133
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
134
|
+
/** PXE configuration options. */
|
|
135
|
+
config: PXEConfig;
|
|
136
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
137
|
+
loggerOrSuffix?: string | Logger;
|
|
138
|
+
};
|
|
139
|
+
|
|
89
140
|
/**
|
|
90
141
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
91
142
|
* manage private state of users.
|
|
@@ -122,15 +173,15 @@ export class PXE {
|
|
|
122
173
|
*
|
|
123
174
|
* @returns A promise that resolves PXE is ready to be used.
|
|
124
175
|
*/
|
|
125
|
-
public static async create(
|
|
126
|
-
node
|
|
127
|
-
store
|
|
128
|
-
proofCreator
|
|
129
|
-
simulator
|
|
130
|
-
protocolContractsProvider
|
|
131
|
-
config
|
|
132
|
-
loggerOrSuffix
|
|
133
|
-
) {
|
|
176
|
+
public static async create({
|
|
177
|
+
node,
|
|
178
|
+
store,
|
|
179
|
+
proofCreator,
|
|
180
|
+
simulator,
|
|
181
|
+
protocolContractsProvider,
|
|
182
|
+
config,
|
|
183
|
+
loggerOrSuffix,
|
|
184
|
+
}: PXECreateArgs) {
|
|
134
185
|
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
135
186
|
const bindings: LoggerBindings | undefined =
|
|
136
187
|
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
@@ -140,7 +191,9 @@ export class PXE {
|
|
|
140
191
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
141
192
|
: loggerOrSuffix;
|
|
142
193
|
|
|
143
|
-
const
|
|
194
|
+
const info = await node.getNodeInfo();
|
|
195
|
+
|
|
196
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
144
197
|
const addressStore = new AddressStore(store);
|
|
145
198
|
const privateEventStore = new PrivateEventStore(store);
|
|
146
199
|
const contractStore = new ContractStore(store);
|
|
@@ -217,7 +270,6 @@ export class PXE {
|
|
|
217
270
|
pxe.jobQueue.start();
|
|
218
271
|
|
|
219
272
|
await pxe.#registerProtocolContracts();
|
|
220
|
-
const info = await node.getNodeInfo();
|
|
221
273
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
222
274
|
return pxe;
|
|
223
275
|
}
|
|
@@ -227,20 +279,20 @@ export class PXE {
|
|
|
227
279
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
228
280
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
229
281
|
|
|
230
|
-
return new ContractFunctionSimulator(
|
|
231
|
-
proxyContractStore,
|
|
232
|
-
this.noteStore,
|
|
233
|
-
this.keyStore,
|
|
234
|
-
this.addressStore,
|
|
235
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
236
|
-
this.senderTaggingStore,
|
|
237
|
-
this.recipientTaggingStore,
|
|
238
|
-
this.senderAddressBookStore,
|
|
239
|
-
this.capsuleStore,
|
|
240
|
-
this.privateEventStore,
|
|
241
|
-
this.simulator,
|
|
242
|
-
this.contractSyncService,
|
|
243
|
-
);
|
|
282
|
+
return new ContractFunctionSimulator({
|
|
283
|
+
contractStore: proxyContractStore,
|
|
284
|
+
noteStore: this.noteStore,
|
|
285
|
+
keyStore: this.keyStore,
|
|
286
|
+
addressStore: this.addressStore,
|
|
287
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
288
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
289
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
290
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
291
|
+
capsuleStore: this.capsuleStore,
|
|
292
|
+
privateEventStore: this.privateEventStore,
|
|
293
|
+
simulator: this.simulator,
|
|
294
|
+
contractSyncService: this.contractSyncService,
|
|
295
|
+
});
|
|
244
296
|
}
|
|
245
297
|
|
|
246
298
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -306,7 +358,7 @@ export class PXE {
|
|
|
306
358
|
async #executePrivate(
|
|
307
359
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
308
360
|
txRequest: TxExecutionRequest,
|
|
309
|
-
scopes:
|
|
361
|
+
scopes: AccessScopes,
|
|
310
362
|
jobId: string,
|
|
311
363
|
): Promise<PrivateExecutionResult> {
|
|
312
364
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
@@ -317,23 +369,20 @@ export class PXE {
|
|
|
317
369
|
await this.contractSyncService.ensureContractSynced(
|
|
318
370
|
contractAddress,
|
|
319
371
|
functionSelector,
|
|
320
|
-
|
|
372
|
+
(privateSyncCall, execScopes) =>
|
|
373
|
+
this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
321
374
|
anchorBlockHeader,
|
|
322
375
|
jobId,
|
|
376
|
+
scopes,
|
|
323
377
|
);
|
|
324
378
|
|
|
325
|
-
const result = await contractFunctionSimulator.run(
|
|
326
|
-
txRequest,
|
|
379
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
327
380
|
contractAddress,
|
|
328
|
-
functionSelector,
|
|
329
|
-
undefined,
|
|
381
|
+
selector: functionSelector,
|
|
330
382
|
anchorBlockHeader,
|
|
331
|
-
// The sender for tags is set by contracts, typically by an account
|
|
332
|
-
// contract entrypoint
|
|
333
|
-
undefined, // senderForTags
|
|
334
383
|
scopes,
|
|
335
384
|
jobId,
|
|
336
|
-
);
|
|
385
|
+
});
|
|
337
386
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
338
387
|
return result;
|
|
339
388
|
} catch (err) {
|
|
@@ -358,7 +407,7 @@ export class PXE {
|
|
|
358
407
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
359
408
|
call: FunctionCall,
|
|
360
409
|
authWitnesses: AuthWitness[] | undefined,
|
|
361
|
-
scopes:
|
|
410
|
+
scopes: AccessScopes,
|
|
362
411
|
jobId: string,
|
|
363
412
|
) {
|
|
364
413
|
try {
|
|
@@ -657,11 +706,12 @@ export class PXE {
|
|
|
657
706
|
* (where validators prove the public portion).
|
|
658
707
|
*
|
|
659
708
|
* @param txRequest - An authenticated tx request ready for proving
|
|
709
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
660
710
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
661
711
|
* @throws If contract code not found, or public simulation reverts.
|
|
662
712
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
663
713
|
*/
|
|
664
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
714
|
+
public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
|
|
665
715
|
let privateExecutionResult: PrivateExecutionResult;
|
|
666
716
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
667
717
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
@@ -672,7 +722,7 @@ export class PXE {
|
|
|
672
722
|
await this.blockStateSynchronizer.sync();
|
|
673
723
|
const syncTime = syncTimer.ms();
|
|
674
724
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
675
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest,
|
|
725
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
676
726
|
|
|
677
727
|
const {
|
|
678
728
|
publicInputs,
|
|
@@ -736,17 +786,13 @@ export class PXE {
|
|
|
736
786
|
|
|
737
787
|
/**
|
|
738
788
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
739
|
-
*
|
|
740
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
741
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
742
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
789
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
743
790
|
* @returns A trace of the program execution with gate counts.
|
|
744
791
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
745
792
|
*/
|
|
746
793
|
public profileTx(
|
|
747
794
|
txRequest: TxExecutionRequest,
|
|
748
|
-
profileMode
|
|
749
|
-
skipProofGeneration: boolean = true,
|
|
795
|
+
{ profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
|
|
750
796
|
): Promise<TxProfileResult> {
|
|
751
797
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
752
798
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -769,12 +815,7 @@ export class PXE {
|
|
|
769
815
|
const syncTime = syncTimer.ms();
|
|
770
816
|
|
|
771
817
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
772
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
773
|
-
contractFunctionSimulator,
|
|
774
|
-
txRequest,
|
|
775
|
-
undefined,
|
|
776
|
-
jobId,
|
|
777
|
-
);
|
|
818
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
778
819
|
|
|
779
820
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
780
821
|
txRequest,
|
|
@@ -831,12 +872,7 @@ export class PXE {
|
|
|
831
872
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
832
873
|
*
|
|
833
874
|
*
|
|
834
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
835
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
836
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
837
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
838
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
839
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
875
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
840
876
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
841
877
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
842
878
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -845,11 +881,7 @@ export class PXE {
|
|
|
845
881
|
*/
|
|
846
882
|
public simulateTx(
|
|
847
883
|
txRequest: TxExecutionRequest,
|
|
848
|
-
simulatePublic:
|
|
849
|
-
skipTxValidation: boolean = false,
|
|
850
|
-
skipFeeEnforcement: boolean = false,
|
|
851
|
-
overrides?: SimulationOverrides,
|
|
852
|
-
scopes?: AztecAddress[],
|
|
884
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
853
885
|
): Promise<TxSimulationResult> {
|
|
854
886
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
855
887
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -896,6 +928,7 @@ export class PXE {
|
|
|
896
928
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
897
929
|
privateExecutionResult,
|
|
898
930
|
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
931
|
+
this.node,
|
|
899
932
|
));
|
|
900
933
|
} else {
|
|
901
934
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -973,25 +1006,19 @@ export class PXE {
|
|
|
973
1006
|
inspect(txRequest),
|
|
974
1007
|
`simulatePublic=${simulatePublic}`,
|
|
975
1008
|
`skipTxValidation=${skipTxValidation}`,
|
|
976
|
-
`scopes=${scopes
|
|
1009
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
977
1010
|
);
|
|
978
1011
|
}
|
|
979
1012
|
});
|
|
980
1013
|
}
|
|
981
1014
|
|
|
982
1015
|
/**
|
|
983
|
-
*
|
|
984
|
-
*
|
|
1016
|
+
* Simulates the execution of a contract utility function.
|
|
985
1017
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
986
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
987
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
988
|
-
* default to all.
|
|
989
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
990
1018
|
*/
|
|
991
1019
|
public simulateUtility(
|
|
992
1020
|
call: FunctionCall,
|
|
993
|
-
authwits
|
|
994
|
-
scopes?: AztecAddress[],
|
|
1021
|
+
{ authwits, scopes }: SimulateUtilityOpts = { scopes: 'ALL_SCOPES' },
|
|
995
1022
|
): Promise<UtilitySimulationResult> {
|
|
996
1023
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
997
1024
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -1009,9 +1036,11 @@ export class PXE {
|
|
|
1009
1036
|
await this.contractSyncService.ensureContractSynced(
|
|
1010
1037
|
call.to,
|
|
1011
1038
|
call.selector,
|
|
1012
|
-
|
|
1039
|
+
(privateSyncCall, execScopes) =>
|
|
1040
|
+
this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1013
1041
|
anchorBlockHeader,
|
|
1014
1042
|
jobId,
|
|
1043
|
+
scopes,
|
|
1015
1044
|
);
|
|
1016
1045
|
|
|
1017
1046
|
const executionResult = await this.#simulateUtility(
|
|
@@ -1042,7 +1071,7 @@ export class PXE {
|
|
|
1042
1071
|
throw this.#contextualizeError(
|
|
1043
1072
|
err,
|
|
1044
1073
|
`simulateUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1045
|
-
`scopes=${scopes
|
|
1074
|
+
`scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
|
|
1046
1075
|
);
|
|
1047
1076
|
}
|
|
1048
1077
|
});
|
|
@@ -1078,10 +1107,11 @@ export class PXE {
|
|
|
1078
1107
|
await this.contractSyncService.ensureContractSynced(
|
|
1079
1108
|
filter.contractAddress,
|
|
1080
1109
|
null,
|
|
1081
|
-
async privateSyncCall =>
|
|
1082
|
-
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [],
|
|
1110
|
+
async (privateSyncCall, execScopes) =>
|
|
1111
|
+
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1083
1112
|
anchorBlockHeader,
|
|
1084
1113
|
jobId,
|
|
1114
|
+
filter.scopes,
|
|
1085
1115
|
);
|
|
1086
1116
|
});
|
|
1087
1117
|
|