@aztec/pxe 0.87.5 → 0.87.7
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/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +37 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
- package/dest/contract_function_simulator/contract_function_simulator.js +117 -0
- package/dest/contract_function_simulator/execution_data_provider.d.ts +301 -0
- package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_data_provider.js +14 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts +93 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_note_cache.js +180 -0
- package/dest/contract_function_simulator/hashed_values_cache.d.ts +28 -0
- package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
- package/dest/contract_function_simulator/index.d.ts +10 -0
- package/dest/contract_function_simulator/index.d.ts.map +1 -0
- package/dest/contract_function_simulator/index.js +8 -0
- package/dest/contract_function_simulator/oracle/index.d.ts +14 -0
- package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/index.js +2 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +19 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +24 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +53 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/oracle.js +317 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +24 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/private_execution.js +100 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +187 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +325 -0
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +83 -0
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/typed_oracle.js +138 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +163 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +257 -0
- package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
- package/dest/contract_function_simulator/pick_notes.js +51 -0
- package/dest/contract_function_simulator/proxied_node.d.ts +9 -0
- package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/proxied_node.js +27 -0
- package/dest/{pxe_oracle_interface → contract_function_simulator}/pxe_oracle_interface.d.ts +5 -4
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -0
- package/dest/{pxe_oracle_interface → contract_function_simulator}/pxe_oracle_interface.js +16 -15
- package/dest/contract_function_simulator/tagging_utils.d.ts.map +1 -0
- package/dest/entrypoints/client/bundle/index.d.ts +1 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +1 -1
- 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 +10 -4
- package/dest/entrypoints/client/lazy/index.d.ts +1 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +1 -1
- 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 +10 -4
- package/dest/entrypoints/{client/pxe_creation_options.d.ts → pxe_creation_options.d.ts} +4 -1
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -0
- package/dest/entrypoints/server/index.d.ts +1 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -1
- package/dest/entrypoints/server/utils.d.ts +6 -6
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +26 -18
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +6 -5
- package/dest/pxe_service/pxe_service.d.ts +2 -2
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +58 -28
- package/dest/storage/note_data_provider/note_dao.d.ts +1 -1
- package/dest/storage/note_data_provider/note_dao.d.ts.map +1 -1
- package/package.json +17 -15
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +193 -0
- package/src/contract_function_simulator/execution_data_provider.ts +391 -0
- package/src/contract_function_simulator/execution_note_cache.ts +217 -0
- package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
- package/src/contract_function_simulator/index.ts +9 -0
- package/src/contract_function_simulator/oracle/index.ts +16 -0
- package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
- package/src/contract_function_simulator/oracle/oracle.ts +541 -0
- package/src/contract_function_simulator/oracle/private_execution.ts +171 -0
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +518 -0
- package/src/contract_function_simulator/oracle/typed_oracle.ts +273 -0
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +384 -0
- package/src/contract_function_simulator/pick_notes.ts +141 -0
- package/src/contract_function_simulator/proxied_node.ts +33 -0
- package/src/{pxe_oracle_interface → contract_function_simulator}/pxe_oracle_interface.ts +18 -21
- package/src/entrypoints/client/bundle/index.ts +1 -1
- package/src/entrypoints/client/bundle/utils.ts +24 -16
- package/src/entrypoints/client/lazy/index.ts +1 -1
- package/src/entrypoints/client/lazy/utils.ts +25 -12
- package/src/entrypoints/{client/pxe_creation_options.ts → pxe_creation_options.ts} +4 -1
- package/src/entrypoints/server/index.ts +1 -1
- package/src/entrypoints/server/utils.ts +44 -26
- package/src/private_kernel/private_kernel_execution_prover.ts +6 -4
- package/src/pxe_service/pxe_service.ts +86 -45
- package/src/storage/note_data_provider/note_dao.ts +2 -1
- package/dest/entrypoints/client/pxe_creation_options.d.ts.map +0 -1
- package/dest/pxe_oracle_interface/pxe_oracle_interface.d.ts.map +0 -1
- package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
- /package/dest/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.d.ts +0 -0
- /package/dest/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.js +0 -0
- /package/dest/entrypoints/{client/pxe_creation_options.js → pxe_creation_options.js} +0 -0
- /package/src/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.ts +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { Comparator, type Note } from '@aztec/stdlib/note';
|
|
3
|
+
|
|
4
|
+
export interface PropertySelector {
|
|
5
|
+
index: number;
|
|
6
|
+
offset: number;
|
|
7
|
+
length: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for selecting values.
|
|
12
|
+
*/
|
|
13
|
+
export interface Select {
|
|
14
|
+
/**
|
|
15
|
+
* Selector of the field to select and match.
|
|
16
|
+
*/
|
|
17
|
+
selector: PropertySelector;
|
|
18
|
+
/**
|
|
19
|
+
* Required value of the field.
|
|
20
|
+
*/
|
|
21
|
+
value: Fr;
|
|
22
|
+
/**
|
|
23
|
+
* The comparator to use
|
|
24
|
+
*/
|
|
25
|
+
comparator: Comparator;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The order to sort an array.
|
|
30
|
+
*/
|
|
31
|
+
export enum SortOrder {
|
|
32
|
+
NADA = 0,
|
|
33
|
+
DESC = 1,
|
|
34
|
+
ASC = 2,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Configuration for sorting values.
|
|
39
|
+
*/
|
|
40
|
+
export interface Sort {
|
|
41
|
+
/**
|
|
42
|
+
* Selector of the field to sort.
|
|
43
|
+
*/
|
|
44
|
+
selector: PropertySelector;
|
|
45
|
+
/**
|
|
46
|
+
* Order to sort the field.
|
|
47
|
+
*/
|
|
48
|
+
order: SortOrder;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Options for picking items from an array of BasicNoteData.
|
|
53
|
+
*/
|
|
54
|
+
interface GetOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Configurations for selecting items.
|
|
57
|
+
* Default: empty array.
|
|
58
|
+
*/
|
|
59
|
+
selects?: Select[];
|
|
60
|
+
/**
|
|
61
|
+
* Configurations for sorting items.
|
|
62
|
+
* Default: empty array.
|
|
63
|
+
*/
|
|
64
|
+
sorts?: Sort[];
|
|
65
|
+
/**
|
|
66
|
+
* The number of items to retrieve per query.
|
|
67
|
+
* Default: 0. No limit.
|
|
68
|
+
*/
|
|
69
|
+
limit?: number;
|
|
70
|
+
/**
|
|
71
|
+
* The starting index for pagination.
|
|
72
|
+
* Default: 0.
|
|
73
|
+
*/
|
|
74
|
+
offset?: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Data needed from to perform sort.
|
|
79
|
+
*/
|
|
80
|
+
interface ContainsNote {
|
|
81
|
+
/**
|
|
82
|
+
* The note.
|
|
83
|
+
*/
|
|
84
|
+
note: Note;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const selectPropertyFromPackedNoteContent = (noteData: Fr[], selector: PropertySelector): Fr => {
|
|
88
|
+
const noteValueBuffer = noteData[selector.index].toBuffer();
|
|
89
|
+
const noteValue = noteValueBuffer.subarray(selector.offset, selector.offset + selector.length);
|
|
90
|
+
return Fr.fromBuffer(noteValue);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const selectNotes = <T extends ContainsNote>(noteDatas: T[], selects: Select[]): T[] =>
|
|
94
|
+
noteDatas.filter(noteData =>
|
|
95
|
+
selects.every(({ selector, value, comparator }) => {
|
|
96
|
+
const noteValueFr = selectPropertyFromPackedNoteContent(noteData.note.items, selector);
|
|
97
|
+
const comparatorSelector = {
|
|
98
|
+
[Comparator.EQ]: () => noteValueFr.equals(value),
|
|
99
|
+
[Comparator.NEQ]: () => !noteValueFr.equals(value),
|
|
100
|
+
[Comparator.LT]: () => noteValueFr.lt(value),
|
|
101
|
+
[Comparator.LTE]: () => noteValueFr.lt(value) || noteValueFr.equals(value),
|
|
102
|
+
[Comparator.GT]: () => !noteValueFr.lt(value) && !noteValueFr.equals(value),
|
|
103
|
+
[Comparator.GTE]: () => !noteValueFr.lt(value),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return comparatorSelector[comparator]();
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const sortNotes = (a: Fr[], b: Fr[], sorts: Sort[], level = 0): number => {
|
|
111
|
+
if (sorts[level] === undefined) {
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const { selector, order } = sorts[level];
|
|
116
|
+
if (order === (0 as SortOrder)) {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const aValue = selectPropertyFromPackedNoteContent(a, selector);
|
|
121
|
+
const bValue = selectPropertyFromPackedNoteContent(b, selector);
|
|
122
|
+
|
|
123
|
+
const dir = order === (1 as SortOrder) ? [-1, 1] : [1, -1];
|
|
124
|
+
return aValue.toBigInt() === bValue.toBigInt()
|
|
125
|
+
? sortNotes(a, b, sorts, level + 1)
|
|
126
|
+
: aValue.toBigInt() > bValue.toBigInt()
|
|
127
|
+
? dir[0]
|
|
128
|
+
: dir[1];
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Pick from a note array a number of notes that meet the criteria.
|
|
133
|
+
*/
|
|
134
|
+
export function pickNotes<T extends ContainsNote>(
|
|
135
|
+
noteDatas: T[],
|
|
136
|
+
{ selects = [], sorts = [], limit = 0, offset = 0 }: GetOptions,
|
|
137
|
+
): T[] {
|
|
138
|
+
return selectNotes(noteDatas, selects)
|
|
139
|
+
.sort((a, b) => sortNotes(a.note.items, b.note.items, sorts))
|
|
140
|
+
.slice(offset, limit ? offset + limit : undefined);
|
|
141
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
2
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
3
|
+
import type { NodeStats } from '@aztec/stdlib/tx';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Proxy for an AztecNode that tracks the time taken for each RPC call.
|
|
7
|
+
*/
|
|
8
|
+
export type ProxiedNode = AztecNode & { getStats(): NodeStats };
|
|
9
|
+
|
|
10
|
+
export class ProxiedNodeFactory {
|
|
11
|
+
static create(node: AztecNode) {
|
|
12
|
+
const stats: Partial<Record<keyof AztecNode, { times: number[] }>> = {};
|
|
13
|
+
return new Proxy(node, {
|
|
14
|
+
get(target, prop: keyof ProxiedNode) {
|
|
15
|
+
if (prop === 'getStats') {
|
|
16
|
+
return () => {
|
|
17
|
+
return stats;
|
|
18
|
+
};
|
|
19
|
+
} else {
|
|
20
|
+
return async function (...args: any[]) {
|
|
21
|
+
if (!stats[prop]) {
|
|
22
|
+
stats[prop] = { times: [] };
|
|
23
|
+
}
|
|
24
|
+
const timer = new Timer();
|
|
25
|
+
const result = await (target[prop] as any).apply(target, args);
|
|
26
|
+
stats[prop].times.push(timer.ms());
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
}) as ProxiedNode;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -3,7 +3,6 @@ import { timesParallel } from '@aztec/foundation/collection';
|
|
|
3
3
|
import { Fr, Point } from '@aztec/foundation/fields';
|
|
4
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import type { KeyStore } from '@aztec/key-store';
|
|
6
|
-
import { type ExecutionDataProvider, MessageLoadOracleInputs } from '@aztec/simulator/client';
|
|
7
6
|
import {
|
|
8
7
|
EventSelector,
|
|
9
8
|
type FunctionArtifactWithContractName,
|
|
@@ -31,6 +30,8 @@ import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from
|
|
|
31
30
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
32
31
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
33
32
|
|
|
33
|
+
import type { ExecutionDataProvider, ExecutionStats } from '../contract_function_simulator/execution_data_provider.js';
|
|
34
|
+
import { MessageLoadOracleInputs } from '../contract_function_simulator/oracle/message_load_oracle_inputs.js';
|
|
34
35
|
import type { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
|
|
35
36
|
import type { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
|
|
36
37
|
import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
|
|
@@ -39,6 +40,7 @@ import type { NoteDataProvider } from '../storage/note_data_provider/note_data_p
|
|
|
39
40
|
import type { PrivateEventDataProvider } from '../storage/private_event_data_provider/private_event_data_provider.js';
|
|
40
41
|
import type { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
|
|
41
42
|
import type { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
|
|
43
|
+
import type { ProxiedNode } from './proxied_node.js';
|
|
42
44
|
import { WINDOW_HALF_SIZE, getIndexedTaggingSecretsForTheWindow, getInitialIndexesMap } from './tagging_utils.js';
|
|
43
45
|
|
|
44
46
|
/**
|
|
@@ -46,7 +48,7 @@ import { WINDOW_HALF_SIZE, getIndexedTaggingSecretsForTheWindow, getInitialIndex
|
|
|
46
48
|
*/
|
|
47
49
|
export class PXEOracleInterface implements ExecutionDataProvider {
|
|
48
50
|
constructor(
|
|
49
|
-
private aztecNode: AztecNode,
|
|
51
|
+
private aztecNode: AztecNode | ProxiedNode,
|
|
50
52
|
private keyStore: KeyStore,
|
|
51
53
|
private contractDataProvider: ContractDataProvider,
|
|
52
54
|
private noteDataProvider: NoteDataProvider,
|
|
@@ -151,16 +153,6 @@ export class PXEOracleInterface implements ExecutionDataProvider {
|
|
|
151
153
|
return new MessageLoadOracleInputs(messageIndex, siblingPath);
|
|
152
154
|
}
|
|
153
155
|
|
|
154
|
-
// Only used in public.
|
|
155
|
-
public getL1ToL2MessageHash(_leafIndex: bigint): Promise<Fr | undefined> {
|
|
156
|
-
throw new Error('Unimplemented in private!');
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// We need this in public as part of the EXISTS calls - but isn't used in private
|
|
160
|
-
public getNoteHash(_leafIndex: bigint): Promise<Fr | undefined> {
|
|
161
|
-
throw new Error('Unimplemented in private!');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
156
|
async getNullifierIndex(nullifier: Fr) {
|
|
165
157
|
return await this.#findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier);
|
|
166
158
|
}
|
|
@@ -649,12 +641,13 @@ export class PXEOracleInterface implements ExecutionDataProvider {
|
|
|
649
641
|
const siloedNullifier = await siloNullifier(contractAddress, nullifier);
|
|
650
642
|
|
|
651
643
|
// We store notes by their index in the global note hash tree, which has the convenient side effect of validating
|
|
652
|
-
// note existence in said tree.
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
MerkleTreeId.NOTE_HASH_TREE,
|
|
656
|
-
[
|
|
657
|
-
);
|
|
644
|
+
// note existence in said tree. We concurrently also check if the note's nullifier exists, performing all node
|
|
645
|
+
// queries in a single round-trip.
|
|
646
|
+
const [[uniqueNoteHashTreeIndexInBlock], [nullifierIndex]] = await Promise.all([
|
|
647
|
+
this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NOTE_HASH_TREE, [uniqueNoteHash]),
|
|
648
|
+
this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [siloedNullifier]),
|
|
649
|
+
]);
|
|
650
|
+
|
|
658
651
|
if (uniqueNoteHashTreeIndexInBlock === undefined) {
|
|
659
652
|
throw new Error(
|
|
660
653
|
`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present on the tree at block ${syncedBlockNumber} (from tx ${txHash})`,
|
|
@@ -684,9 +677,6 @@ export class PXEOracleInterface implements ExecutionDataProvider {
|
|
|
684
677
|
nullifier: noteDao.siloedNullifier.toString(),
|
|
685
678
|
});
|
|
686
679
|
|
|
687
|
-
const [nullifierIndex] = await this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [
|
|
688
|
-
siloedNullifier,
|
|
689
|
-
]);
|
|
690
680
|
if (nullifierIndex !== undefined) {
|
|
691
681
|
const { data: _, ...blockHashAndNum } = nullifierIndex;
|
|
692
682
|
await this.noteDataProvider.removeNullifiedNotes([{ data: siloedNullifier, ...blockHashAndNum }], recipient);
|
|
@@ -832,4 +822,11 @@ export class PXEOracleInterface implements ExecutionDataProvider {
|
|
|
832
822
|
blockNumber,
|
|
833
823
|
);
|
|
834
824
|
}
|
|
825
|
+
|
|
826
|
+
getStats(): ExecutionStats {
|
|
827
|
+
const nodeRPCCalls =
|
|
828
|
+
typeof (this.aztecNode as ProxiedNode).getStats === 'function' ? (this.aztecNode as ProxiedNode).getStats() : {};
|
|
829
|
+
|
|
830
|
+
return { nodeRPCCalls };
|
|
831
|
+
}
|
|
835
832
|
}
|
|
@@ -2,4 +2,4 @@ export * from '../../../pxe_service/index.js';
|
|
|
2
2
|
export * from '../../../config/index.js';
|
|
3
3
|
export * from '../../../storage/index.js';
|
|
4
4
|
export * from './utils.js';
|
|
5
|
-
export { PXEOracleInterface } from '../../../
|
|
5
|
+
export { PXEOracleInterface } from '../../../contract_function_simulator/pxe_oracle_interface.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BBWASMBundlePrivateKernelProver } from '@aztec/bb-prover/client/wasm/bundle';
|
|
2
|
+
import { randomBytes } from '@aztec/foundation/crypto';
|
|
2
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { createStore } from '@aztec/kv-store/indexeddb';
|
|
4
5
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
@@ -7,7 +8,7 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
|
7
8
|
|
|
8
9
|
import type { PXEServiceConfig } from '../../../config/index.js';
|
|
9
10
|
import { PXEService } from '../../../pxe_service/pxe_service.js';
|
|
10
|
-
import type { PXECreationOptions } from '
|
|
11
|
+
import type { PXECreationOptions } from '../../pxe_creation_options.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Create and start an PXEService instance with the given AztecNode.
|
|
@@ -24,6 +25,15 @@ export async function createPXEService(
|
|
|
24
25
|
config: PXEServiceConfig,
|
|
25
26
|
options: PXECreationOptions = { loggers: {} },
|
|
26
27
|
) {
|
|
28
|
+
const logSuffix =
|
|
29
|
+
typeof options.useLogSuffix === 'boolean'
|
|
30
|
+
? options.useLogSuffix
|
|
31
|
+
? randomBytes(3).toString('hex')
|
|
32
|
+
: undefined
|
|
33
|
+
: options.useLogSuffix;
|
|
34
|
+
|
|
35
|
+
const loggers = options.loggers ?? {};
|
|
36
|
+
|
|
27
37
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
28
38
|
const configWithContracts = {
|
|
29
39
|
...config,
|
|
@@ -31,29 +41,27 @@ export async function createPXEService(
|
|
|
31
41
|
l2BlockBatchSize: 200,
|
|
32
42
|
} as PXEServiceConfig;
|
|
33
43
|
|
|
34
|
-
const
|
|
35
|
-
'pxe_data',
|
|
36
|
-
configWithContracts,
|
|
37
|
-
options.loggers.store ?? createLogger('pxe:data:indexeddb'),
|
|
38
|
-
);
|
|
44
|
+
const storeLogger = loggers.store ? loggers.store : createLogger('pxe:data:idb' + (logSuffix ? `:${logSuffix}` : ''));
|
|
39
45
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const store = options.store ?? (await createStore('pxe_data', configWithContracts, storeLogger));
|
|
47
|
+
|
|
48
|
+
const simulator = new WASMSimulator();
|
|
49
|
+
const proverLogger = loggers.prover
|
|
50
|
+
? loggers.prover
|
|
51
|
+
: createLogger('pxe:bb:wasm:bundle' + (logSuffix ? `:${logSuffix}` : ''));
|
|
52
|
+
|
|
53
|
+
const prover = options.prover ?? new BBWASMBundlePrivateKernelProver(simulator, 16, proverLogger);
|
|
48
54
|
const protocolContractsProvider = new BundledProtocolContractsProvider();
|
|
55
|
+
|
|
56
|
+
const pxeLogger = loggers.pxe ? loggers.pxe : createLogger('pxe:service' + (logSuffix ? `:${logSuffix}` : ''));
|
|
49
57
|
const pxe = await PXEService.create(
|
|
50
58
|
aztecNode,
|
|
51
59
|
store,
|
|
52
60
|
prover,
|
|
53
|
-
|
|
61
|
+
simulator,
|
|
54
62
|
protocolContractsProvider,
|
|
55
63
|
config,
|
|
56
|
-
|
|
64
|
+
pxeLogger,
|
|
57
65
|
);
|
|
58
66
|
return pxe;
|
|
59
67
|
}
|
|
@@ -2,4 +2,4 @@ export * from '../../../pxe_service/index.js';
|
|
|
2
2
|
export * from '../../../config/index.js';
|
|
3
3
|
export * from '../../../storage/index.js';
|
|
4
4
|
export * from './utils.js';
|
|
5
|
-
export { PXEOracleInterface } from '../../../
|
|
5
|
+
export { PXEOracleInterface } from '../../../contract_function_simulator/pxe_oracle_interface.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BBWASMLazyPrivateKernelProver } from '@aztec/bb-prover/client/wasm/lazy';
|
|
2
|
+
import { randomBytes } from '@aztec/foundation/crypto';
|
|
2
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { createStore } from '@aztec/kv-store/indexeddb';
|
|
4
5
|
import { LazyProtocolContractsProvider } from '@aztec/protocol-contracts/providers/lazy';
|
|
@@ -7,7 +8,7 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
|
7
8
|
|
|
8
9
|
import type { PXEServiceConfig } from '../../../config/index.js';
|
|
9
10
|
import { PXEService } from '../../../pxe_service/pxe_service.js';
|
|
10
|
-
import type { PXECreationOptions } from '
|
|
11
|
+
import type { PXECreationOptions } from '../../pxe_creation_options.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Create and start an PXEService instance with the given AztecNode.
|
|
@@ -23,6 +24,13 @@ export async function createPXEService(
|
|
|
23
24
|
config: PXEServiceConfig,
|
|
24
25
|
options: PXECreationOptions = { loggers: {} },
|
|
25
26
|
) {
|
|
27
|
+
const logSuffix =
|
|
28
|
+
typeof options.useLogSuffix === 'boolean'
|
|
29
|
+
? options.useLogSuffix
|
|
30
|
+
? randomBytes(3).toString('hex')
|
|
31
|
+
: undefined
|
|
32
|
+
: options.useLogSuffix;
|
|
33
|
+
|
|
26
34
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
27
35
|
const configWithContracts = {
|
|
28
36
|
...config,
|
|
@@ -30,25 +38,30 @@ export async function createPXEService(
|
|
|
30
38
|
l1Contracts,
|
|
31
39
|
} as PXEServiceConfig;
|
|
32
40
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
);
|
|
41
|
+
const loggers = options.loggers ?? {};
|
|
42
|
+
|
|
43
|
+
const storeLogger = loggers.store ? loggers.store : createLogger('pxe:data:idb' + (logSuffix ? `:${logSuffix}` : ''));
|
|
44
|
+
|
|
45
|
+
const store = options.store ?? (await createStore('pxe_data', configWithContracts, storeLogger));
|
|
46
|
+
|
|
47
|
+
const simulator = new WASMSimulator();
|
|
48
|
+
const proverLogger = loggers.prover
|
|
49
|
+
? loggers.prover
|
|
50
|
+
: createLogger('pxe:bb:wasm:bundle' + (logSuffix ? `:${logSuffix}` : ''));
|
|
51
|
+
|
|
52
|
+
const prover = options.prover ?? new BBWASMLazyPrivateKernelProver(simulator, 16, proverLogger);
|
|
38
53
|
|
|
39
|
-
const simulationProvider = new WASMSimulator();
|
|
40
|
-
const prover =
|
|
41
|
-
options.prover ??
|
|
42
|
-
new BBWASMLazyPrivateKernelProver(simulationProvider, 16, options.loggers.prover ?? createLogger('bb:wasm:lazy'));
|
|
43
54
|
const protocolContractsProvider = new LazyProtocolContractsProvider();
|
|
55
|
+
|
|
56
|
+
const pxeLogger = loggers.pxe ? loggers.pxe : createLogger('pxe:service' + (logSuffix ? `:${logSuffix}` : ''));
|
|
44
57
|
const pxe = await PXEService.create(
|
|
45
58
|
aztecNode,
|
|
46
59
|
store,
|
|
47
60
|
prover,
|
|
48
|
-
|
|
61
|
+
simulator,
|
|
49
62
|
protocolContractsProvider,
|
|
50
63
|
config,
|
|
51
|
-
|
|
64
|
+
pxeLogger,
|
|
52
65
|
);
|
|
53
66
|
return pxe;
|
|
54
67
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
3
|
import type { PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
|
|
3
4
|
|
|
4
5
|
export type PXECreationOptions = {
|
|
5
|
-
loggers
|
|
6
|
+
loggers?: { store?: Logger; pxe?: Logger; prover?: Logger };
|
|
7
|
+
useLogSuffix?: boolean | string;
|
|
6
8
|
prover?: PrivateKernelProver;
|
|
9
|
+
store?: AztecAsyncKVStore;
|
|
7
10
|
};
|
|
@@ -3,4 +3,4 @@ export * from '../../pxe_http/index.js';
|
|
|
3
3
|
export * from '../../config/index.js';
|
|
4
4
|
export * from '../../storage/index.js';
|
|
5
5
|
export * from './utils.js';
|
|
6
|
-
export { PXEOracleInterface } from '../../
|
|
6
|
+
export { PXEOracleInterface } from '../../contract_function_simulator/pxe_oracle_interface.js';
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { BBNativePrivateKernelProver } from '@aztec/bb-prover/client/native';
|
|
2
2
|
import { BBWASMBundlePrivateKernelProver } from '@aztec/bb-prover/client/wasm/bundle';
|
|
3
3
|
import { randomBytes } from '@aztec/foundation/crypto';
|
|
4
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
4
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
5
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
7
|
-
import {
|
|
8
|
-
|
|
6
|
+
import {
|
|
7
|
+
type CircuitSimulator,
|
|
8
|
+
MemoryCircuitRecorder,
|
|
9
|
+
SimulatorRecorderWrapper,
|
|
10
|
+
WASMSimulator,
|
|
11
|
+
} from '@aztec/simulator/client';
|
|
12
|
+
import { FileCircuitRecorder } from '@aztec/simulator/testing';
|
|
9
13
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
10
14
|
|
|
11
15
|
import type { PXEServiceConfig } from '../../config/index.js';
|
|
12
16
|
import { PXEService } from '../../pxe_service/pxe_service.js';
|
|
13
17
|
import { PXE_DATA_SCHEMA_VERSION } from '../../storage/index.js';
|
|
18
|
+
import type { PXECreationOptions } from '../pxe_creation_options.js';
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
21
|
* Create and start an PXEService instance with the given AztecNode and config.
|
|
@@ -23,32 +28,38 @@ import { PXE_DATA_SCHEMA_VERSION } from '../../storage/index.js';
|
|
|
23
28
|
export function createPXEService(
|
|
24
29
|
aztecNode: AztecNode,
|
|
25
30
|
config: PXEServiceConfig,
|
|
26
|
-
|
|
27
|
-
store?: AztecAsyncKVStore,
|
|
31
|
+
options: PXECreationOptions = { loggers: {} },
|
|
28
32
|
) {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
33
|
+
const simulator = new WASMSimulator();
|
|
34
|
+
const recorder = process.env.CIRCUIT_RECORD_DIR
|
|
35
|
+
? new FileCircuitRecorder(process.env.CIRCUIT_RECORD_DIR)
|
|
36
|
+
: new MemoryCircuitRecorder();
|
|
37
|
+
const simulatorWithRecorder = new SimulatorRecorderWrapper(simulator, recorder);
|
|
38
|
+
return createPXEServiceWithSimulator(aztecNode, simulatorWithRecorder, config, options);
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
/**
|
|
35
|
-
* Create and start an PXEService instance with the given AztecNode,
|
|
42
|
+
* Create and start an PXEService instance with the given AztecNode, Simulator and config.
|
|
36
43
|
*
|
|
37
44
|
* @param aztecNode - The AztecNode instance to be used by the server.
|
|
38
|
-
* @param
|
|
45
|
+
* @param simulator - The Simulator to use
|
|
39
46
|
* @param config - The PXE Service Config to use
|
|
40
47
|
* @param useLogSuffix - Whether to add a randomly generated suffix to the PXE debug logs.
|
|
41
48
|
* @returns A Promise that resolves to the started PXEService instance.
|
|
42
49
|
*/
|
|
43
|
-
export async function
|
|
50
|
+
export async function createPXEServiceWithSimulator(
|
|
44
51
|
aztecNode: AztecNode,
|
|
45
|
-
|
|
52
|
+
simulator: CircuitSimulator,
|
|
46
53
|
config: PXEServiceConfig,
|
|
47
|
-
|
|
48
|
-
store?: AztecAsyncKVStore,
|
|
54
|
+
options: PXECreationOptions = { loggers: {} },
|
|
49
55
|
) {
|
|
50
56
|
const logSuffix =
|
|
51
|
-
typeof useLogSuffix === 'boolean'
|
|
57
|
+
typeof options.useLogSuffix === 'boolean'
|
|
58
|
+
? options.useLogSuffix
|
|
59
|
+
? randomBytes(3).toString('hex')
|
|
60
|
+
: undefined
|
|
61
|
+
: options.useLogSuffix;
|
|
62
|
+
const loggers = options.loggers ?? {};
|
|
52
63
|
|
|
53
64
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
54
65
|
const configWithContracts = {
|
|
@@ -57,34 +68,41 @@ export async function createPXEServiceWithSimulationProvider(
|
|
|
57
68
|
l2BlockBatchSize: 200,
|
|
58
69
|
} as PXEServiceConfig;
|
|
59
70
|
|
|
60
|
-
if (!store) {
|
|
71
|
+
if (!options.store) {
|
|
61
72
|
// TODO once https://github.com/AztecProtocol/aztec-packages/issues/13656 is fixed, we can remove this and always
|
|
62
73
|
// import the lmdb-v2 version
|
|
63
74
|
const { createStore } = await import('@aztec/kv-store/lmdb-v2');
|
|
64
|
-
|
|
75
|
+
const storeLogger = loggers.store
|
|
76
|
+
? loggers.store
|
|
77
|
+
: createLogger('pxe:data:lmdb' + (logSuffix ? `:${logSuffix}` : ''));
|
|
78
|
+
options.store = await createStore('pxe_data', PXE_DATA_SCHEMA_VERSION, configWithContracts, storeLogger);
|
|
65
79
|
}
|
|
80
|
+
const proverLogger = loggers.prover
|
|
81
|
+
? loggers.prover
|
|
82
|
+
: createLogger('pxe:bb:native' + (logSuffix ? `:${logSuffix}` : ''));
|
|
66
83
|
|
|
67
|
-
const prover = await createProver(config,
|
|
84
|
+
const prover = await createProver(config, simulator, proverLogger);
|
|
68
85
|
const protocolContractsProvider = new BundledProtocolContractsProvider();
|
|
86
|
+
|
|
87
|
+
const pxeLogger = loggers.pxe ? loggers.pxe : createLogger('pxe:service' + (logSuffix ? `:${logSuffix}` : ''));
|
|
69
88
|
const pxe = await PXEService.create(
|
|
70
89
|
aztecNode,
|
|
71
|
-
store,
|
|
90
|
+
options.store,
|
|
72
91
|
prover,
|
|
73
|
-
|
|
92
|
+
simulator,
|
|
74
93
|
protocolContractsProvider,
|
|
75
94
|
config,
|
|
76
|
-
|
|
95
|
+
pxeLogger,
|
|
77
96
|
);
|
|
78
97
|
return pxe;
|
|
79
98
|
}
|
|
80
99
|
|
|
81
|
-
function createProver(config: PXEServiceConfig,
|
|
100
|
+
function createProver(config: PXEServiceConfig, simulator: CircuitSimulator, logger?: Logger) {
|
|
82
101
|
if (!config.bbBinaryPath || !config.bbWorkingDirectory) {
|
|
83
|
-
return new BBWASMBundlePrivateKernelProver(
|
|
102
|
+
return new BBWASMBundlePrivateKernelProver(simulator, 16, logger);
|
|
84
103
|
} else {
|
|
85
104
|
const bbConfig = config as Required<Pick<PXEServiceConfig, 'bbBinaryPath' | 'bbWorkingDirectory'>> &
|
|
86
105
|
PXEServiceConfig;
|
|
87
|
-
|
|
88
|
-
return BBNativePrivateKernelProver.new({ bbSkipCleanup: false, ...bbConfig }, simulationProvider, log);
|
|
106
|
+
return BBNativePrivateKernelProver.new({ bbSkipCleanup: false, ...bbConfig }, simulator, logger);
|
|
89
107
|
}
|
|
90
108
|
}
|
|
@@ -115,8 +115,8 @@ export class PrivateKernelExecutionProver {
|
|
|
115
115
|
validationRequestsSplitCounter,
|
|
116
116
|
);
|
|
117
117
|
while (resetBuilder.needsReset()) {
|
|
118
|
-
const privateInputs = await resetBuilder.build(this.oracle, noteHashLeafIndexMap);
|
|
119
118
|
const witgenTimer = new Timer();
|
|
119
|
+
const privateInputs = await resetBuilder.build(this.oracle, noteHashLeafIndexMap);
|
|
120
120
|
output = generateWitnesses
|
|
121
121
|
? await this.proofCreator.generateResetOutput(privateInputs)
|
|
122
122
|
: await this.proofCreator.simulateReset(privateInputs);
|
|
@@ -154,12 +154,15 @@ export class PrivateKernelExecutionProver {
|
|
|
154
154
|
vk: currentExecution.vk,
|
|
155
155
|
timings: {
|
|
156
156
|
witgen: currentExecution.profileResult?.timings.witgen ?? 0,
|
|
157
|
+
oracles: currentExecution.profileResult?.timings.oracles,
|
|
157
158
|
},
|
|
158
159
|
});
|
|
159
160
|
|
|
160
161
|
const privateCallData = await this.createPrivateCallData(currentExecution);
|
|
161
162
|
|
|
162
163
|
if (firstIteration) {
|
|
164
|
+
const witgenTimer = new Timer();
|
|
165
|
+
|
|
163
166
|
const proofInput = new PrivateKernelInitCircuitPrivateInputs(
|
|
164
167
|
txRequest,
|
|
165
168
|
getVKTreeRoot(),
|
|
@@ -174,7 +177,6 @@ export class PrivateKernelExecutionProver {
|
|
|
174
177
|
|
|
175
178
|
pushTestData('private-kernel-inputs-init', proofInput);
|
|
176
179
|
|
|
177
|
-
const witgenTimer = new Timer();
|
|
178
180
|
output = generateWitnesses
|
|
179
181
|
? await this.proofCreator.generateInitOutput(proofInput)
|
|
180
182
|
: await this.proofCreator.simulateInit(proofInput);
|
|
@@ -189,6 +191,7 @@ export class PrivateKernelExecutionProver {
|
|
|
189
191
|
},
|
|
190
192
|
});
|
|
191
193
|
} else {
|
|
194
|
+
const witgenTimer = new Timer();
|
|
192
195
|
const previousVkMembershipWitness = await this.oracle.getVkMembershipWitness(
|
|
193
196
|
output.verificationKey.keyAsFields,
|
|
194
197
|
);
|
|
@@ -201,7 +204,6 @@ export class PrivateKernelExecutionProver {
|
|
|
201
204
|
const proofInput = new PrivateKernelInnerCircuitPrivateInputs(previousKernelData, privateCallData);
|
|
202
205
|
|
|
203
206
|
pushTestData('private-kernel-inputs-inner', proofInput);
|
|
204
|
-
const witgenTimer = new Timer();
|
|
205
207
|
output = generateWitnesses
|
|
206
208
|
? await this.proofCreator.generateInnerOutput(proofInput)
|
|
207
209
|
: await this.proofCreator.simulateInner(proofInput);
|
|
@@ -227,8 +229,8 @@ export class PrivateKernelExecutionProver {
|
|
|
227
229
|
validationRequestsSplitCounter,
|
|
228
230
|
);
|
|
229
231
|
while (resetBuilder.needsReset()) {
|
|
230
|
-
const privateInputs = await resetBuilder.build(this.oracle, noteHashLeafIndexMap);
|
|
231
232
|
const witgenTimer = new Timer();
|
|
233
|
+
const privateInputs = await resetBuilder.build(this.oracle, noteHashLeafIndexMap);
|
|
232
234
|
output = generateWitnesses
|
|
233
235
|
? await this.proofCreator.generateResetOutput(privateInputs)
|
|
234
236
|
: await this.proofCreator.simulateReset(privateInputs);
|