@aztec/pxe 0.87.4 → 0.87.6
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.js +3 -3
- 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.js +3 -3
- 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 +4 -4
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +12 -12
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +4 -4
- 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 +46 -21
- 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 +3 -3
- package/src/entrypoints/client/lazy/index.ts +1 -1
- package/src/entrypoints/client/lazy/utils.ts +3 -3
- package/src/entrypoints/server/index.ts +1 -1
- package/src/entrypoints/server/utils.ts +14 -14
- package/src/private_kernel/private_kernel_execution_prover.ts +5 -4
- package/src/pxe_service/pxe_service.ts +75 -39
- package/src/storage/note_data_provider/note_dao.ts +2 -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/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';
|
|
@@ -45,12 +45,12 @@ export async function createPXEService(
|
|
|
45
45
|
|
|
46
46
|
const store = options.store ?? (await createStore('pxe_data', configWithContracts, storeLogger));
|
|
47
47
|
|
|
48
|
-
const
|
|
48
|
+
const simulator = new WASMSimulator();
|
|
49
49
|
const proverLogger = loggers.prover
|
|
50
50
|
? loggers.prover
|
|
51
51
|
: createLogger('pxe:bb:wasm:bundle' + (logSuffix ? `:${logSuffix}` : ''));
|
|
52
52
|
|
|
53
|
-
const prover = options.prover ?? new BBWASMBundlePrivateKernelProver(
|
|
53
|
+
const prover = options.prover ?? new BBWASMBundlePrivateKernelProver(simulator, 16, proverLogger);
|
|
54
54
|
const protocolContractsProvider = new BundledProtocolContractsProvider();
|
|
55
55
|
|
|
56
56
|
const pxeLogger = loggers.pxe ? loggers.pxe : createLogger('pxe:service' + (logSuffix ? `:${logSuffix}` : ''));
|
|
@@ -58,7 +58,7 @@ export async function createPXEService(
|
|
|
58
58
|
aztecNode,
|
|
59
59
|
store,
|
|
60
60
|
prover,
|
|
61
|
-
|
|
61
|
+
simulator,
|
|
62
62
|
protocolContractsProvider,
|
|
63
63
|
config,
|
|
64
64
|
pxeLogger,
|
|
@@ -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';
|
|
@@ -44,12 +44,12 @@ export async function createPXEService(
|
|
|
44
44
|
|
|
45
45
|
const store = options.store ?? (await createStore('pxe_data', configWithContracts, storeLogger));
|
|
46
46
|
|
|
47
|
-
const
|
|
47
|
+
const simulator = new WASMSimulator();
|
|
48
48
|
const proverLogger = loggers.prover
|
|
49
49
|
? loggers.prover
|
|
50
50
|
: createLogger('pxe:bb:wasm:bundle' + (logSuffix ? `:${logSuffix}` : ''));
|
|
51
51
|
|
|
52
|
-
const prover = options.prover ?? new BBWASMLazyPrivateKernelProver(
|
|
52
|
+
const prover = options.prover ?? new BBWASMLazyPrivateKernelProver(simulator, 16, proverLogger);
|
|
53
53
|
|
|
54
54
|
const protocolContractsProvider = new LazyProtocolContractsProvider();
|
|
55
55
|
|
|
@@ -58,7 +58,7 @@ export async function createPXEService(
|
|
|
58
58
|
aztecNode,
|
|
59
59
|
store,
|
|
60
60
|
prover,
|
|
61
|
-
|
|
61
|
+
simulator,
|
|
62
62
|
protocolContractsProvider,
|
|
63
63
|
config,
|
|
64
64
|
pxeLogger,
|
|
@@ -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';
|
|
@@ -4,9 +4,9 @@ import { randomBytes } from '@aztec/foundation/crypto';
|
|
|
4
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
6
6
|
import {
|
|
7
|
+
type CircuitSimulator,
|
|
7
8
|
MemoryCircuitRecorder,
|
|
8
|
-
|
|
9
|
-
SimulationProviderRecorderWrapper,
|
|
9
|
+
SimulatorRecorderWrapper,
|
|
10
10
|
WASMSimulator,
|
|
11
11
|
} from '@aztec/simulator/client';
|
|
12
12
|
import { FileCircuitRecorder } from '@aztec/simulator/testing';
|
|
@@ -30,26 +30,26 @@ export function createPXEService(
|
|
|
30
30
|
config: PXEServiceConfig,
|
|
31
31
|
options: PXECreationOptions = { loggers: {} },
|
|
32
32
|
) {
|
|
33
|
-
const
|
|
33
|
+
const simulator = new WASMSimulator();
|
|
34
34
|
const recorder = process.env.CIRCUIT_RECORD_DIR
|
|
35
35
|
? new FileCircuitRecorder(process.env.CIRCUIT_RECORD_DIR)
|
|
36
36
|
: new MemoryCircuitRecorder();
|
|
37
|
-
const
|
|
38
|
-
return
|
|
37
|
+
const simulatorWithRecorder = new SimulatorRecorderWrapper(simulator, recorder);
|
|
38
|
+
return createPXEServiceWithSimulator(aztecNode, simulatorWithRecorder, config, options);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
* Create and start an PXEService instance with the given AztecNode,
|
|
42
|
+
* Create and start an PXEService instance with the given AztecNode, Simulator and config.
|
|
43
43
|
*
|
|
44
44
|
* @param aztecNode - The AztecNode instance to be used by the server.
|
|
45
|
-
* @param
|
|
45
|
+
* @param simulator - The Simulator to use
|
|
46
46
|
* @param config - The PXE Service Config to use
|
|
47
47
|
* @param useLogSuffix - Whether to add a randomly generated suffix to the PXE debug logs.
|
|
48
48
|
* @returns A Promise that resolves to the started PXEService instance.
|
|
49
49
|
*/
|
|
50
|
-
export async function
|
|
50
|
+
export async function createPXEServiceWithSimulator(
|
|
51
51
|
aztecNode: AztecNode,
|
|
52
|
-
|
|
52
|
+
simulator: CircuitSimulator,
|
|
53
53
|
config: PXEServiceConfig,
|
|
54
54
|
options: PXECreationOptions = { loggers: {} },
|
|
55
55
|
) {
|
|
@@ -81,7 +81,7 @@ export async function createPXEServiceWithSimulationProvider(
|
|
|
81
81
|
? loggers.prover
|
|
82
82
|
: createLogger('pxe:bb:native' + (logSuffix ? `:${logSuffix}` : ''));
|
|
83
83
|
|
|
84
|
-
const prover = await createProver(config,
|
|
84
|
+
const prover = await createProver(config, simulator, proverLogger);
|
|
85
85
|
const protocolContractsProvider = new BundledProtocolContractsProvider();
|
|
86
86
|
|
|
87
87
|
const pxeLogger = loggers.pxe ? loggers.pxe : createLogger('pxe:service' + (logSuffix ? `:${logSuffix}` : ''));
|
|
@@ -89,7 +89,7 @@ export async function createPXEServiceWithSimulationProvider(
|
|
|
89
89
|
aztecNode,
|
|
90
90
|
options.store,
|
|
91
91
|
prover,
|
|
92
|
-
|
|
92
|
+
simulator,
|
|
93
93
|
protocolContractsProvider,
|
|
94
94
|
config,
|
|
95
95
|
pxeLogger,
|
|
@@ -97,12 +97,12 @@ export async function createPXEServiceWithSimulationProvider(
|
|
|
97
97
|
return pxe;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
function createProver(config: PXEServiceConfig,
|
|
100
|
+
function createProver(config: PXEServiceConfig, simulator: CircuitSimulator, logger?: Logger) {
|
|
101
101
|
if (!config.bbBinaryPath || !config.bbWorkingDirectory) {
|
|
102
|
-
return new BBWASMBundlePrivateKernelProver(
|
|
102
|
+
return new BBWASMBundlePrivateKernelProver(simulator, 16, logger);
|
|
103
103
|
} else {
|
|
104
104
|
const bbConfig = config as Required<Pick<PXEServiceConfig, 'bbBinaryPath' | 'bbWorkingDirectory'>> &
|
|
105
105
|
PXEServiceConfig;
|
|
106
|
-
return BBNativePrivateKernelProver.new({ bbSkipCleanup: false, ...bbConfig },
|
|
106
|
+
return BBNativePrivateKernelProver.new({ bbSkipCleanup: false, ...bbConfig }, simulator, logger);
|
|
107
107
|
}
|
|
108
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);
|
|
@@ -161,6 +161,8 @@ export class PrivateKernelExecutionProver {
|
|
|
161
161
|
const privateCallData = await this.createPrivateCallData(currentExecution);
|
|
162
162
|
|
|
163
163
|
if (firstIteration) {
|
|
164
|
+
const witgenTimer = new Timer();
|
|
165
|
+
|
|
164
166
|
const proofInput = new PrivateKernelInitCircuitPrivateInputs(
|
|
165
167
|
txRequest,
|
|
166
168
|
getVKTreeRoot(),
|
|
@@ -175,7 +177,6 @@ export class PrivateKernelExecutionProver {
|
|
|
175
177
|
|
|
176
178
|
pushTestData('private-kernel-inputs-init', proofInput);
|
|
177
179
|
|
|
178
|
-
const witgenTimer = new Timer();
|
|
179
180
|
output = generateWitnesses
|
|
180
181
|
? await this.proofCreator.generateInitOutput(proofInput)
|
|
181
182
|
: await this.proofCreator.simulateInit(proofInput);
|
|
@@ -190,6 +191,7 @@ export class PrivateKernelExecutionProver {
|
|
|
190
191
|
},
|
|
191
192
|
});
|
|
192
193
|
} else {
|
|
194
|
+
const witgenTimer = new Timer();
|
|
193
195
|
const previousVkMembershipWitness = await this.oracle.getVkMembershipWitness(
|
|
194
196
|
output.verificationKey.keyAsFields,
|
|
195
197
|
);
|
|
@@ -202,7 +204,6 @@ export class PrivateKernelExecutionProver {
|
|
|
202
204
|
const proofInput = new PrivateKernelInnerCircuitPrivateInputs(previousKernelData, privateCallData);
|
|
203
205
|
|
|
204
206
|
pushTestData('private-kernel-inputs-inner', proofInput);
|
|
205
|
-
const witgenTimer = new Timer();
|
|
206
207
|
output = generateWitnesses
|
|
207
208
|
? await this.proofCreator.generateInnerOutput(proofInput)
|
|
208
209
|
: await this.proofCreator.simulateInner(proofInput);
|
|
@@ -228,8 +229,8 @@ export class PrivateKernelExecutionProver {
|
|
|
228
229
|
validationRequestsSplitCounter,
|
|
229
230
|
);
|
|
230
231
|
while (resetBuilder.needsReset()) {
|
|
231
|
-
const privateInputs = await resetBuilder.build(this.oracle, noteHashLeafIndexMap);
|
|
232
232
|
const witgenTimer = new Timer();
|
|
233
|
+
const privateInputs = await resetBuilder.build(this.oracle, noteHashLeafIndexMap);
|
|
233
234
|
output = generateWitnesses
|
|
234
235
|
? await this.proofCreator.generateResetOutput(privateInputs)
|
|
235
236
|
: await this.proofCreator.simulateReset(privateInputs);
|