@aztec/pxe 0.41.0 → 0.43.0
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/index.d.ts.map +1 -1
- package/dest/config/index.js +5 -2
- package/dest/contract_data_oracle/index.d.ts +1 -0
- package/dest/contract_data_oracle/index.d.ts.map +1 -1
- package/dest/contract_data_oracle/index.js +7 -1
- package/dest/contract_data_oracle/private_functions_tree.d.ts.map +1 -1
- package/dest/contract_data_oracle/private_functions_tree.js +2 -2
- package/dest/database/deferred_note_dao.d.ts +2 -2
- package/dest/database/deferred_note_dao.d.ts.map +1 -1
- package/dest/database/deferred_note_dao.js +2 -2
- package/dest/database/incoming_note_dao.d.ts +73 -0
- package/dest/database/incoming_note_dao.d.ts.map +1 -0
- package/dest/database/incoming_note_dao.js +92 -0
- package/dest/database/kv_pxe_database.d.ts +10 -7
- package/dest/database/kv_pxe_database.d.ts.map +1 -1
- package/dest/database/kv_pxe_database.js +149 -78
- package/dest/database/{note_dao.d.ts → outgoing_note_dao.d.ts} +7 -12
- package/dest/database/outgoing_note_dao.d.ts.map +1 -0
- package/dest/database/outgoing_note_dao.js +83 -0
- package/dest/database/pxe_database.d.ts +21 -9
- package/dest/database/pxe_database.d.ts.map +1 -1
- package/dest/database/pxe_database_test_suite.d.ts.map +1 -1
- package/dest/database/pxe_database_test_suite.js +71 -24
- package/dest/kernel_oracle/index.d.ts +4 -4
- package/dest/kernel_oracle/index.d.ts.map +1 -1
- package/dest/kernel_oracle/index.js +6 -17
- package/dest/kernel_prover/kernel_prover.d.ts +3 -0
- package/dest/kernel_prover/kernel_prover.d.ts.map +1 -1
- package/dest/kernel_prover/kernel_prover.js +44 -8
- package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.d.ts +2 -1
- package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.d.ts.map +1 -1
- package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.js +32 -12
- package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_outputs.d.ts +1 -1
- package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_outputs.d.ts.map +1 -1
- package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_outputs.js +9 -7
- package/dest/kernel_prover/private_inputs_builders/build_private_kernel_tail_hints.d.ts.map +1 -1
- package/dest/kernel_prover/private_inputs_builders/build_private_kernel_tail_hints.js +7 -3
- package/dest/kernel_prover/proving_data_oracle.d.ts +6 -6
- package/dest/kernel_prover/proving_data_oracle.d.ts.map +1 -1
- package/dest/note_processor/note_processor.d.ts +23 -20
- package/dest/note_processor/note_processor.d.ts.map +1 -1
- package/dest/note_processor/note_processor.js +123 -76
- package/dest/note_processor/produce_note_dao.d.ts +13 -4
- package/dest/note_processor/produce_note_dao.d.ts.map +1 -1
- package/dest/note_processor/produce_note_dao.js +88 -31
- package/dest/pxe_http/pxe_http_server.js +3 -3
- package/dest/pxe_service/create_pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/create_pxe_service.js +4 -2
- package/dest/pxe_service/pxe_service.d.ts +14 -6
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +139 -87
- package/dest/pxe_service/test/pxe_test_suite.d.ts.map +1 -1
- package/dest/pxe_service/test/pxe_test_suite.js +3 -16
- package/dest/simulator_oracle/index.d.ts +1 -0
- package/dest/simulator_oracle/index.d.ts.map +1 -1
- package/dest/simulator_oracle/index.js +5 -2
- package/dest/synchronizer/synchronizer.d.ts +9 -2
- package/dest/synchronizer/synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/synchronizer.js +43 -34
- package/package.json +14 -14
- package/src/config/index.ts +11 -1
- package/src/contract_data_oracle/index.ts +7 -0
- package/src/contract_data_oracle/private_functions_tree.ts +3 -1
- package/src/database/deferred_note_dao.ts +1 -1
- package/src/database/{note_dao.ts → incoming_note_dao.ts} +10 -7
- package/src/database/kv_pxe_database.ts +127 -29
- package/src/database/outgoing_note_dao.ts +90 -0
- package/src/database/pxe_database.ts +23 -9
- package/src/database/pxe_database_test_suite.ts +93 -29
- package/src/kernel_oracle/index.ts +4 -17
- package/src/kernel_prover/kernel_prover.ts +76 -16
- package/src/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.ts +79 -8
- package/src/kernel_prover/private_inputs_builders/build_private_kernel_reset_outputs.ts +9 -5
- package/src/kernel_prover/private_inputs_builders/build_private_kernel_tail_hints.ts +13 -1
- package/src/kernel_prover/proving_data_oracle.ts +5 -6
- package/src/note_processor/note_processor.ts +191 -121
- package/src/note_processor/produce_note_dao.ts +164 -50
- package/src/pxe_http/pxe_http_server.ts +2 -2
- package/src/pxe_service/create_pxe_service.ts +3 -1
- package/src/pxe_service/pxe_service.ts +210 -149
- package/src/pxe_service/test/pxe_test_suite.ts +0 -20
- package/src/simulator_oracle/index.ts +5 -1
- package/src/synchronizer/synchronizer.ts +55 -50
- package/dest/database/note_dao.d.ts.map +0 -1
- package/dest/database/note_dao.js +0 -89
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type IncomingNotesFilter,
|
|
3
|
+
MerkleTreeId,
|
|
4
|
+
NoteStatus,
|
|
5
|
+
type OutgoingNotesFilter,
|
|
6
|
+
type PublicKey,
|
|
7
|
+
} from '@aztec/circuit-types';
|
|
2
8
|
import { AztecAddress, CompleteAddress, Header } from '@aztec/circuits.js';
|
|
3
9
|
import { type ContractArtifact } from '@aztec/foundation/abi';
|
|
4
10
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
@@ -14,7 +20,8 @@ import { contractArtifactFromBuffer, contractArtifactToBuffer } from '@aztec/typ
|
|
|
14
20
|
import { type ContractInstanceWithAddress, SerializableContractInstance } from '@aztec/types/contracts';
|
|
15
21
|
|
|
16
22
|
import { DeferredNoteDao } from './deferred_note_dao.js';
|
|
17
|
-
import {
|
|
23
|
+
import { IncomingNoteDao } from './incoming_note_dao.js';
|
|
24
|
+
import { OutgoingNoteDao } from './outgoing_note_dao.js';
|
|
18
25
|
import { type PxeDatabase } from './pxe_database.js';
|
|
19
26
|
|
|
20
27
|
/**
|
|
@@ -32,11 +39,11 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
32
39
|
#notesByContract: AztecMultiMap<string, string>;
|
|
33
40
|
#notesByStorageSlot: AztecMultiMap<string, string>;
|
|
34
41
|
#notesByTxHash: AztecMultiMap<string, string>;
|
|
35
|
-
#
|
|
42
|
+
#notesByIvpkM: AztecMultiMap<string, string>;
|
|
36
43
|
#nullifiedNotesByContract: AztecMultiMap<string, string>;
|
|
37
44
|
#nullifiedNotesByStorageSlot: AztecMultiMap<string, string>;
|
|
38
45
|
#nullifiedNotesByTxHash: AztecMultiMap<string, string>;
|
|
39
|
-
#
|
|
46
|
+
#nullifiedNotesByIvpkM: AztecMultiMap<string, string>;
|
|
40
47
|
#deferredNotes: AztecArray<Buffer | null>;
|
|
41
48
|
#deferredNotesByContract: AztecMultiMap<string, number>;
|
|
42
49
|
#syncedBlockPerPublicKey: AztecMap<string, number>;
|
|
@@ -44,6 +51,12 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
44
51
|
#contractInstances: AztecMap<string, Buffer>;
|
|
45
52
|
#db: AztecKVStore;
|
|
46
53
|
|
|
54
|
+
#outgoingNotes: AztecMap<string, Buffer>;
|
|
55
|
+
#outgoingNotesByContract: AztecMultiMap<string, string>;
|
|
56
|
+
#outgoingNotesByStorageSlot: AztecMultiMap<string, string>;
|
|
57
|
+
#outgoingNotesByTxHash: AztecMultiMap<string, string>;
|
|
58
|
+
#outgoingNotesByOvpkM: AztecMultiMap<string, string>;
|
|
59
|
+
|
|
47
60
|
constructor(private db: AztecKVStore) {
|
|
48
61
|
this.#db = db;
|
|
49
62
|
|
|
@@ -66,15 +79,21 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
66
79
|
this.#notesByContract = db.openMultiMap('notes_by_contract');
|
|
67
80
|
this.#notesByStorageSlot = db.openMultiMap('notes_by_storage_slot');
|
|
68
81
|
this.#notesByTxHash = db.openMultiMap('notes_by_tx_hash');
|
|
69
|
-
this.#
|
|
82
|
+
this.#notesByIvpkM = db.openMultiMap('notes_by_ivpk_m');
|
|
70
83
|
|
|
71
84
|
this.#nullifiedNotesByContract = db.openMultiMap('nullified_notes_by_contract');
|
|
72
85
|
this.#nullifiedNotesByStorageSlot = db.openMultiMap('nullified_notes_by_storage_slot');
|
|
73
86
|
this.#nullifiedNotesByTxHash = db.openMultiMap('nullified_notes_by_tx_hash');
|
|
74
|
-
this.#
|
|
87
|
+
this.#nullifiedNotesByIvpkM = db.openMultiMap('nullified_notes_by_ivpk_m');
|
|
75
88
|
|
|
76
89
|
this.#deferredNotes = db.openArray('deferred_notes');
|
|
77
90
|
this.#deferredNotesByContract = db.openMultiMap('deferred_notes_by_contract');
|
|
91
|
+
|
|
92
|
+
this.#outgoingNotes = db.openMap('outgoing_notes');
|
|
93
|
+
this.#outgoingNotesByContract = db.openMultiMap('outgoing_notes_by_contract');
|
|
94
|
+
this.#outgoingNotesByStorageSlot = db.openMultiMap('outgoing_notes_by_storage_slot');
|
|
95
|
+
this.#outgoingNotesByTxHash = db.openMultiMap('outgoing_notes_by_tx_hash');
|
|
96
|
+
this.#outgoingNotesByOvpkM = db.openMultiMap('outgoing_notes_by_ovpk_m');
|
|
78
97
|
}
|
|
79
98
|
|
|
80
99
|
public async getContract(
|
|
@@ -135,13 +154,13 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
135
154
|
return val?.map(b => Fr.fromBuffer(b));
|
|
136
155
|
}
|
|
137
156
|
|
|
138
|
-
async addNote(note:
|
|
139
|
-
await this.addNotes([note]);
|
|
157
|
+
async addNote(note: IncomingNoteDao): Promise<void> {
|
|
158
|
+
await this.addNotes([note], []);
|
|
140
159
|
}
|
|
141
160
|
|
|
142
|
-
addNotes(
|
|
161
|
+
addNotes(incomingNotes: IncomingNoteDao[], outgoingNotes: OutgoingNoteDao[]): Promise<void> {
|
|
143
162
|
return this.db.transaction(() => {
|
|
144
|
-
for (const dao of
|
|
163
|
+
for (const dao of incomingNotes) {
|
|
145
164
|
// store notes by their index in the notes hash tree
|
|
146
165
|
// this provides the uniqueness we need to store individual notes
|
|
147
166
|
// and should also return notes in the order that they were created.
|
|
@@ -152,7 +171,16 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
152
171
|
void this.#notesByContract.set(dao.contractAddress.toString(), noteIndex);
|
|
153
172
|
void this.#notesByStorageSlot.set(dao.storageSlot.toString(), noteIndex);
|
|
154
173
|
void this.#notesByTxHash.set(dao.txHash.toString(), noteIndex);
|
|
155
|
-
void this.#
|
|
174
|
+
void this.#notesByIvpkM.set(dao.ivpkM.toString(), noteIndex);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
for (const dao of outgoingNotes) {
|
|
178
|
+
const noteIndex = toBufferBE(dao.index, 32).toString('hex');
|
|
179
|
+
void this.#outgoingNotes.set(noteIndex, dao.toBuffer());
|
|
180
|
+
void this.#outgoingNotesByContract.set(dao.contractAddress.toString(), noteIndex);
|
|
181
|
+
void this.#outgoingNotesByStorageSlot.set(dao.storageSlot.toString(), noteIndex);
|
|
182
|
+
void this.#outgoingNotesByTxHash.set(dao.txHash.toString(), noteIndex);
|
|
183
|
+
void this.#outgoingNotesByOvpkM.set(dao.ovpkM.toString(), noteIndex);
|
|
156
184
|
}
|
|
157
185
|
});
|
|
158
186
|
}
|
|
@@ -207,7 +235,7 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
207
235
|
});
|
|
208
236
|
}
|
|
209
237
|
|
|
210
|
-
|
|
238
|
+
getIncomingNotes(filter: IncomingNotesFilter): Promise<IncomingNoteDao[]> {
|
|
211
239
|
const publicKey: PublicKey | undefined = filter.owner
|
|
212
240
|
? this.#getCompleteAddress(filter.owner)?.publicKeys.masterIncomingViewingPublicKey
|
|
213
241
|
: undefined;
|
|
@@ -218,7 +246,7 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
218
246
|
|
|
219
247
|
candidateNoteSources.push({
|
|
220
248
|
ids: publicKey
|
|
221
|
-
? this.#
|
|
249
|
+
? this.#notesByIvpkM.getValues(publicKey.toString())
|
|
222
250
|
: filter.txHash
|
|
223
251
|
? this.#notesByTxHash.getValues(filter.txHash.toString())
|
|
224
252
|
: filter.contractAddress
|
|
@@ -232,7 +260,7 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
232
260
|
if (filter.status == NoteStatus.ACTIVE_OR_NULLIFIED) {
|
|
233
261
|
candidateNoteSources.push({
|
|
234
262
|
ids: publicKey
|
|
235
|
-
? this.#
|
|
263
|
+
? this.#nullifiedNotesByIvpkM.getValues(publicKey.toString())
|
|
236
264
|
: filter.txHash
|
|
237
265
|
? this.#nullifiedNotesByTxHash.getValues(filter.txHash.toString())
|
|
238
266
|
: filter.contractAddress
|
|
@@ -244,7 +272,7 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
244
272
|
});
|
|
245
273
|
}
|
|
246
274
|
|
|
247
|
-
const result:
|
|
275
|
+
const result: IncomingNoteDao[] = [];
|
|
248
276
|
for (const { ids, notes } of candidateNoteSources) {
|
|
249
277
|
for (const id of ids) {
|
|
250
278
|
const serializedNote = notes.get(id);
|
|
@@ -252,7 +280,7 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
252
280
|
continue;
|
|
253
281
|
}
|
|
254
282
|
|
|
255
|
-
const note =
|
|
283
|
+
const note = IncomingNoteDao.fromBuffer(serializedNote);
|
|
256
284
|
if (filter.contractAddress && !note.contractAddress.equals(filter.contractAddress)) {
|
|
257
285
|
continue;
|
|
258
286
|
}
|
|
@@ -265,7 +293,11 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
265
293
|
continue;
|
|
266
294
|
}
|
|
267
295
|
|
|
268
|
-
if (publicKey && !note.
|
|
296
|
+
if (publicKey && !note.ivpkM.equals(publicKey)) {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (filter.siloedNullifier && !note.siloedNullifier.equals(filter.siloedNullifier)) {
|
|
269
301
|
continue;
|
|
270
302
|
}
|
|
271
303
|
|
|
@@ -273,20 +305,66 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
273
305
|
}
|
|
274
306
|
}
|
|
275
307
|
|
|
276
|
-
return result;
|
|
308
|
+
return Promise.resolve(result);
|
|
277
309
|
}
|
|
278
310
|
|
|
279
|
-
|
|
280
|
-
|
|
311
|
+
getOutgoingNotes(filter: OutgoingNotesFilter): Promise<OutgoingNoteDao[]> {
|
|
312
|
+
const ovpkM: PublicKey | undefined = filter.owner
|
|
313
|
+
? this.#getCompleteAddress(filter.owner)?.publicKeys.masterOutgoingViewingPublicKey
|
|
314
|
+
: undefined;
|
|
315
|
+
|
|
316
|
+
// Check if ovpkM is truthy
|
|
317
|
+
const ids = ovpkM
|
|
318
|
+
? this.#outgoingNotesByOvpkM.getValues(ovpkM.toString())
|
|
319
|
+
: // If ovpkM is falsy, check if filter.txHash is truthy
|
|
320
|
+
filter.txHash
|
|
321
|
+
? this.#outgoingNotesByTxHash.getValues(filter.txHash.toString())
|
|
322
|
+
: // If both ovpkM and filter.txHash are falsy, check if filter.contractAddress is truthy
|
|
323
|
+
filter.contractAddress
|
|
324
|
+
? this.#outgoingNotesByContract.getValues(filter.contractAddress.toString())
|
|
325
|
+
: // If ovpkM, filter.txHash, and filter.contractAddress are all falsy, check if filter.storageSlot is truthy
|
|
326
|
+
filter.storageSlot
|
|
327
|
+
? this.#outgoingNotesByStorageSlot.getValues(filter.storageSlot.toString())
|
|
328
|
+
: // If none of the above conditions are met, retrieve all keys from this.#outgoingNotes
|
|
329
|
+
this.#outgoingNotes.keys();
|
|
330
|
+
|
|
331
|
+
const notes: OutgoingNoteDao[] = [];
|
|
332
|
+
for (const id of ids) {
|
|
333
|
+
const serializedNote = this.#outgoingNotes.get(id);
|
|
334
|
+
if (!serializedNote) {
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const note = OutgoingNoteDao.fromBuffer(serializedNote);
|
|
339
|
+
if (filter.contractAddress && !note.contractAddress.equals(filter.contractAddress)) {
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (filter.txHash && !note.txHash.equals(filter.txHash)) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (filter.storageSlot && !note.storageSlot.equals(filter.storageSlot!)) {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (ovpkM && !note.ovpkM.equals(ovpkM)) {
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
notes.push(note);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return Promise.resolve(notes);
|
|
281
359
|
}
|
|
282
360
|
|
|
283
|
-
removeNullifiedNotes(nullifiers: Fr[], account: PublicKey): Promise<
|
|
361
|
+
removeNullifiedNotes(nullifiers: Fr[], account: PublicKey): Promise<IncomingNoteDao[]> {
|
|
284
362
|
if (nullifiers.length === 0) {
|
|
285
363
|
return Promise.resolve([]);
|
|
286
364
|
}
|
|
287
365
|
|
|
288
366
|
return this.#db.transaction(() => {
|
|
289
|
-
const nullifiedNotes:
|
|
367
|
+
const nullifiedNotes: IncomingNoteDao[] = [];
|
|
290
368
|
|
|
291
369
|
for (const nullifier of nullifiers) {
|
|
292
370
|
const noteIndex = this.#nullifierToNoteId.get(nullifier.toString());
|
|
@@ -301,8 +379,8 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
301
379
|
continue;
|
|
302
380
|
}
|
|
303
381
|
|
|
304
|
-
const note =
|
|
305
|
-
if (!note.
|
|
382
|
+
const note = IncomingNoteDao.fromBuffer(noteBuffer);
|
|
383
|
+
if (!note.ivpkM.equals(account)) {
|
|
306
384
|
// tried to nullify someone else's note
|
|
307
385
|
continue;
|
|
308
386
|
}
|
|
@@ -310,7 +388,7 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
310
388
|
nullifiedNotes.push(note);
|
|
311
389
|
|
|
312
390
|
void this.#notes.delete(noteIndex);
|
|
313
|
-
void this.#
|
|
391
|
+
void this.#notesByIvpkM.deleteValue(account.toString(), noteIndex);
|
|
314
392
|
void this.#notesByTxHash.deleteValue(note.txHash.toString(), noteIndex);
|
|
315
393
|
void this.#notesByContract.deleteValue(note.contractAddress.toString(), noteIndex);
|
|
316
394
|
void this.#notesByStorageSlot.deleteValue(note.storageSlot.toString(), noteIndex);
|
|
@@ -319,7 +397,7 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
319
397
|
void this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
|
|
320
398
|
void this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
|
|
321
399
|
void this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
|
|
322
|
-
void this.#
|
|
400
|
+
void this.#nullifiedNotesByIvpkM.set(note.ivpkM.toString(), noteIndex);
|
|
323
401
|
|
|
324
402
|
void this.#nullifierToNoteId.delete(nullifier.toString());
|
|
325
403
|
}
|
|
@@ -328,6 +406,18 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
328
406
|
});
|
|
329
407
|
}
|
|
330
408
|
|
|
409
|
+
async addNullifiedNote(note: IncomingNoteDao): Promise<void> {
|
|
410
|
+
const noteIndex = toBufferBE(note.index, 32).toString('hex');
|
|
411
|
+
|
|
412
|
+
await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
|
|
413
|
+
await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
|
|
414
|
+
await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
|
|
415
|
+
await this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
|
|
416
|
+
await this.#nullifiedNotesByIvpkM.set(note.ivpkM.toString(), noteIndex);
|
|
417
|
+
|
|
418
|
+
return Promise.resolve();
|
|
419
|
+
}
|
|
420
|
+
|
|
331
421
|
async setHeader(header: Header): Promise<void> {
|
|
332
422
|
await this.#synchronizedBlock.set(header.toBuffer());
|
|
333
423
|
}
|
|
@@ -401,8 +491,16 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
401
491
|
return this.#syncedBlockPerPublicKey.set(publicKey.toString(), blockNumber);
|
|
402
492
|
}
|
|
403
493
|
|
|
404
|
-
estimateSize(): number {
|
|
405
|
-
const
|
|
494
|
+
async estimateSize(): Promise<number> {
|
|
495
|
+
const incomingNotesSize = Array.from(await this.getIncomingNotes({})).reduce(
|
|
496
|
+
(sum, note) => sum + note.getSize(),
|
|
497
|
+
0,
|
|
498
|
+
);
|
|
499
|
+
const outgoingNotesSize = Array.from(await this.getOutgoingNotes({})).reduce(
|
|
500
|
+
(sum, note) => sum + note.getSize(),
|
|
501
|
+
0,
|
|
502
|
+
);
|
|
503
|
+
|
|
406
504
|
const authWitsSize = Array.from(this.#authWitnesses.values()).reduce(
|
|
407
505
|
(sum, value) => sum + value.length * Fr.SIZE_IN_BYTES,
|
|
408
506
|
0,
|
|
@@ -410,6 +508,6 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
410
508
|
const addressesSize = this.#addresses.length * CompleteAddress.SIZE_IN_BYTES;
|
|
411
509
|
const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES;
|
|
412
510
|
|
|
413
|
-
return
|
|
511
|
+
return incomingNotesSize + outgoingNotesSize + treeRootsSize + authWitsSize + addressesSize;
|
|
414
512
|
}
|
|
415
513
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Note, TxHash } from '@aztec/circuit-types';
|
|
2
|
+
import { AztecAddress, Fr, Point, type PublicKey } from '@aztec/circuits.js';
|
|
3
|
+
import { toBigIntBE } from '@aztec/foundation/bigint-buffer';
|
|
4
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A note with contextual data which was decrypted as outgoing.
|
|
8
|
+
*/
|
|
9
|
+
export class OutgoingNoteDao {
|
|
10
|
+
constructor(
|
|
11
|
+
/** The note as emitted from the Noir contract. */
|
|
12
|
+
public note: Note,
|
|
13
|
+
/** The contract address this note is created in. */
|
|
14
|
+
public contractAddress: AztecAddress,
|
|
15
|
+
/** The specific storage location of the note on the contract. */
|
|
16
|
+
public storageSlot: Fr,
|
|
17
|
+
/** The note type identifier for the contract. */
|
|
18
|
+
public noteTypeId: Fr,
|
|
19
|
+
/** The hash of the tx the note was created in. */
|
|
20
|
+
public txHash: TxHash,
|
|
21
|
+
/** The nonce of the note. */
|
|
22
|
+
public nonce: Fr,
|
|
23
|
+
/**
|
|
24
|
+
* Inner note hash of the note. This is customizable by the app circuit.
|
|
25
|
+
* We can use this value to compute siloedNoteHash and uniqueSiloedNoteHash.
|
|
26
|
+
*/
|
|
27
|
+
public innerNoteHash: Fr,
|
|
28
|
+
/** The location of the relevant note in the note hash tree. */
|
|
29
|
+
public index: bigint,
|
|
30
|
+
/** The public key with which the note was encrypted. */
|
|
31
|
+
public ovpkM: PublicKey,
|
|
32
|
+
) {}
|
|
33
|
+
|
|
34
|
+
toBuffer(): Buffer {
|
|
35
|
+
return serializeToBuffer([
|
|
36
|
+
this.note,
|
|
37
|
+
this.contractAddress,
|
|
38
|
+
this.storageSlot,
|
|
39
|
+
this.noteTypeId,
|
|
40
|
+
this.txHash.buffer,
|
|
41
|
+
this.nonce,
|
|
42
|
+
this.innerNoteHash,
|
|
43
|
+
this.index,
|
|
44
|
+
this.ovpkM,
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
48
|
+
const reader = BufferReader.asReader(buffer);
|
|
49
|
+
|
|
50
|
+
const note = Note.fromBuffer(reader);
|
|
51
|
+
const contractAddress = AztecAddress.fromBuffer(reader);
|
|
52
|
+
const storageSlot = Fr.fromBuffer(reader);
|
|
53
|
+
const noteTypeId = Fr.fromBuffer(reader);
|
|
54
|
+
const txHash = new TxHash(reader.readBytes(TxHash.SIZE));
|
|
55
|
+
const nonce = Fr.fromBuffer(reader);
|
|
56
|
+
const innerNoteHash = Fr.fromBuffer(reader);
|
|
57
|
+
const index = toBigIntBE(reader.readBytes(32));
|
|
58
|
+
const publicKey = Point.fromBuffer(reader);
|
|
59
|
+
|
|
60
|
+
return new OutgoingNoteDao(
|
|
61
|
+
note,
|
|
62
|
+
contractAddress,
|
|
63
|
+
storageSlot,
|
|
64
|
+
noteTypeId,
|
|
65
|
+
txHash,
|
|
66
|
+
nonce,
|
|
67
|
+
innerNoteHash,
|
|
68
|
+
index,
|
|
69
|
+
publicKey,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
toString() {
|
|
74
|
+
return '0x' + this.toBuffer().toString('hex');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static fromString(str: string) {
|
|
78
|
+
const hex = str.replace(/^0x/, '');
|
|
79
|
+
return OutgoingNoteDao.fromBuffer(Buffer.from(hex, 'hex'));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Returns the size in bytes of the Note Dao.
|
|
84
|
+
* @returns - Its size in bytes.
|
|
85
|
+
*/
|
|
86
|
+
public getSize() {
|
|
87
|
+
const noteSize = 4 + this.note.items.length * Fr.SIZE_IN_BYTES;
|
|
88
|
+
return noteSize + AztecAddress.SIZE_IN_BYTES + Fr.SIZE_IN_BYTES * 2 + TxHash.SIZE + Point.SIZE_IN_BYTES;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type IncomingNotesFilter, type OutgoingNotesFilter } from '@aztec/circuit-types';
|
|
2
2
|
import { type CompleteAddress, type Header, type PublicKey } from '@aztec/circuits.js';
|
|
3
3
|
import { type ContractArtifact } from '@aztec/foundation/abi';
|
|
4
4
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
@@ -8,7 +8,8 @@ import { type ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
|
8
8
|
import { type ContractArtifactDatabase } from './contracts/contract_artifact_db.js';
|
|
9
9
|
import { type ContractInstanceDatabase } from './contracts/contract_instance_db.js';
|
|
10
10
|
import { type DeferredNoteDao } from './deferred_note_dao.js';
|
|
11
|
-
import { type
|
|
11
|
+
import { type IncomingNoteDao } from './incoming_note_dao.js';
|
|
12
|
+
import { type OutgoingNoteDao } from './outgoing_note_dao.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* A database interface that provides methods for retrieving, adding, and removing transactional data related to Aztec
|
|
@@ -46,26 +47,39 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
|
|
|
46
47
|
popCapsule(): Promise<Fr[] | undefined>;
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
|
-
* Gets notes based on the provided filter.
|
|
50
|
+
* Gets incoming notes based on the provided filter.
|
|
50
51
|
* @param filter - The filter to apply to the notes.
|
|
51
52
|
* @returns The requested notes.
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
|
+
getIncomingNotes(filter: IncomingNotesFilter): Promise<IncomingNoteDao[]>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Gets outgoing notes.
|
|
58
|
+
* @returns The outgoing notes.
|
|
59
|
+
*/
|
|
60
|
+
getOutgoingNotes(filter: OutgoingNotesFilter): Promise<OutgoingNoteDao[]>;
|
|
54
61
|
|
|
55
62
|
/**
|
|
56
63
|
* Adds a note to DB.
|
|
57
64
|
* @param note - The note to add.
|
|
58
65
|
*/
|
|
59
|
-
addNote(note:
|
|
66
|
+
addNote(note: IncomingNoteDao): Promise<void>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Adds a nullified note to DB.
|
|
70
|
+
* @param note - The note to add.
|
|
71
|
+
*/
|
|
72
|
+
addNullifiedNote(note: IncomingNoteDao): Promise<void>;
|
|
60
73
|
|
|
61
74
|
/**
|
|
62
75
|
* Adds an array of notes to DB.
|
|
63
76
|
* This function is used to insert multiple notes to the database at once,
|
|
64
77
|
* which can improve performance when dealing with large numbers of transactions.
|
|
65
78
|
*
|
|
66
|
-
* @param
|
|
79
|
+
* @param incomingNotes - An array of notes which were decrypted as incoming.
|
|
80
|
+
* @param outgoingNotes - An array of notes which were decrypted as outgoing.
|
|
67
81
|
*/
|
|
68
|
-
addNotes(
|
|
82
|
+
addNotes(incomingNotes: IncomingNoteDao[], outgoingNotes: OutgoingNoteDao[]): Promise<void>;
|
|
69
83
|
|
|
70
84
|
/**
|
|
71
85
|
* Add notes to the database that are intended for us, but we don't yet have the contract.
|
|
@@ -93,7 +107,7 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
|
|
|
93
107
|
* @param account - A PublicKey instance representing the account for which the records are being removed.
|
|
94
108
|
* @returns Removed notes.
|
|
95
109
|
*/
|
|
96
|
-
removeNullifiedNotes(nullifiers: Fr[], account: PublicKey): Promise<
|
|
110
|
+
removeNullifiedNotes(nullifiers: Fr[], account: PublicKey): Promise<IncomingNoteDao[]>;
|
|
97
111
|
|
|
98
112
|
/**
|
|
99
113
|
* Gets the most recently processed block number.
|
|
@@ -162,5 +176,5 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
|
|
|
162
176
|
* Returns the estimated size in bytes of this db.
|
|
163
177
|
* @returns The estimated size in bytes of this db.
|
|
164
178
|
*/
|
|
165
|
-
estimateSize(): number
|
|
179
|
+
estimateSize(): Promise<number>;
|
|
166
180
|
}
|