@aztec/pxe 0.66.0 → 0.67.1-devnet
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bin/index.js +5 -6
- package/dest/config/index.d.ts +0 -9
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -17
- package/dest/config/package_info.d.ts +5 -0
- package/dest/config/package_info.d.ts.map +1 -0
- package/dest/config/package_info.js +4 -0
- package/dest/contract_data_oracle/index.js +2 -2
- package/dest/database/incoming_note_dao.d.ts +1 -1
- package/dest/database/incoming_note_dao.d.ts.map +1 -1
- package/dest/database/incoming_note_dao.js +2 -2
- package/dest/database/kv_pxe_database.d.ts +10 -13
- package/dest/database/kv_pxe_database.d.ts.map +1 -1
- package/dest/database/kv_pxe_database.js +153 -230
- package/dest/database/outgoing_note_dao.js +2 -2
- package/dest/database/pxe_database.d.ts +7 -25
- 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 +18 -59
- package/dest/index.d.ts +2 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -1
- package/dest/kernel_oracle/index.d.ts.map +1 -1
- package/dest/kernel_oracle/index.js +4 -4
- package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +2 -2
- package/dest/kernel_prover/index.d.ts +1 -0
- package/dest/kernel_prover/index.d.ts.map +1 -1
- package/dest/kernel_prover/index.js +2 -1
- package/dest/kernel_prover/kernel_prover.d.ts +1 -0
- package/dest/kernel_prover/kernel_prover.d.ts.map +1 -1
- package/dest/kernel_prover/kernel_prover.js +42 -5
- package/dest/kernel_prover/test/test_circuit_prover.d.ts +1 -2
- package/dest/kernel_prover/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/kernel_prover/test/test_circuit_prover.js +7 -13
- package/dest/note_decryption_utils/add_public_values_to_payload.js +2 -2
- package/dest/note_decryption_utils/brute_force_note_info.d.ts +3 -3
- package/dest/note_decryption_utils/brute_force_note_info.d.ts.map +1 -1
- package/dest/note_decryption_utils/brute_force_note_info.js +8 -8
- package/dest/note_decryption_utils/produce_note_daos.d.ts +3 -6
- package/dest/note_decryption_utils/produce_note_daos.d.ts.map +1 -1
- package/dest/note_decryption_utils/produce_note_daos.js +5 -19
- package/dest/note_decryption_utils/produce_note_daos_for_key.d.ts +1 -1
- package/dest/note_decryption_utils/produce_note_daos_for_key.d.ts.map +1 -1
- package/dest/pxe_service/error_enriching.d.ts +3 -3
- package/dest/pxe_service/error_enriching.d.ts.map +1 -1
- package/dest/pxe_service/error_enriching.js +10 -10
- package/dest/pxe_service/index.d.ts +0 -1
- package/dest/pxe_service/index.d.ts.map +1 -1
- package/dest/pxe_service/index.js +1 -2
- package/dest/pxe_service/pxe_service.d.ts +2 -16
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +74 -96
- package/dest/pxe_service/test/pxe_test_suite.d.ts.map +1 -1
- package/dest/pxe_service/test/pxe_test_suite.js +1 -3
- package/dest/simulator/index.d.ts +1 -1
- package/dest/simulator/index.d.ts.map +1 -1
- package/dest/simulator/index.js +2 -2
- package/dest/simulator_oracle/index.d.ts +14 -11
- package/dest/simulator_oracle/index.d.ts.map +1 -1
- package/dest/simulator_oracle/index.js +170 -140
- package/dest/simulator_oracle/tagging_utils.d.ts +15 -0
- package/dest/simulator_oracle/tagging_utils.d.ts.map +1 -0
- package/dest/simulator_oracle/tagging_utils.js +23 -0
- package/dest/synchronizer/synchronizer.d.ts +10 -40
- package/dest/synchronizer/synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/synchronizer.js +35 -69
- package/dest/{pxe_service → utils}/create_pxe_service.d.ts +1 -1
- package/dest/utils/create_pxe_service.d.ts.map +1 -0
- package/dest/utils/create_pxe_service.js +52 -0
- package/package.json +31 -19
- package/src/bin/index.ts +4 -5
- package/src/config/index.ts +0 -21
- package/src/config/package_info.ts +3 -0
- package/src/contract_data_oracle/index.ts +1 -1
- package/src/database/incoming_note_dao.ts +2 -2
- package/src/database/kv_pxe_database.ts +214 -309
- package/src/database/outgoing_note_dao.ts +1 -1
- package/src/database/pxe_database.ts +7 -28
- package/src/database/pxe_database_test_suite.ts +20 -75
- package/src/index.ts +2 -0
- package/src/kernel_oracle/index.ts +3 -3
- package/src/kernel_prover/hints/build_private_kernel_reset_private_inputs.ts +1 -1
- package/src/kernel_prover/index.ts +2 -0
- package/src/kernel_prover/kernel_prover.ts +72 -3
- package/src/kernel_prover/test/test_circuit_prover.ts +11 -25
- package/src/note_decryption_utils/add_public_values_to_payload.ts +1 -1
- package/src/note_decryption_utils/brute_force_note_info.ts +9 -9
- package/src/note_decryption_utils/produce_note_daos.ts +5 -48
- package/src/note_decryption_utils/produce_note_daos_for_key.ts +1 -1
- package/src/pxe_service/error_enriching.ts +14 -12
- package/src/pxe_service/index.ts +0 -1
- package/src/pxe_service/pxe_service.ts +127 -174
- package/src/pxe_service/test/pxe_test_suite.ts +0 -3
- package/src/simulator/index.ts +1 -1
- package/src/simulator_oracle/index.ts +201 -188
- package/src/simulator_oracle/tagging_utils.ts +28 -0
- package/src/synchronizer/synchronizer.ts +37 -77
- package/src/{pxe_service → utils}/create_pxe_service.ts +16 -13
- package/dest/pxe_service/create_pxe_service.d.ts.map +0 -1
- package/dest/pxe_service/create_pxe_service.js +0 -49
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type InBlock, type IncomingNotesFilter
|
|
1
|
+
import { type InBlock, type IncomingNotesFilter } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
|
+
type BlockHeader,
|
|
3
4
|
type CompleteAddress,
|
|
4
5
|
type ContractInstanceWithAddress,
|
|
5
|
-
type Header,
|
|
6
6
|
type IndexedTaggingSecret,
|
|
7
7
|
type PublicKey,
|
|
8
8
|
} from '@aztec/circuits.js';
|
|
@@ -13,7 +13,6 @@ import { type Fr } from '@aztec/foundation/fields';
|
|
|
13
13
|
import { type ContractArtifactDatabase } from './contracts/contract_artifact_db.js';
|
|
14
14
|
import { type ContractInstanceDatabase } from './contracts/contract_instance_db.js';
|
|
15
15
|
import { type IncomingNoteDao } from './incoming_note_dao.js';
|
|
16
|
-
import { type OutgoingNoteDao } from './outgoing_note_dao.js';
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* A database interface that provides methods for retrieving, adding, and removing transactional data related to Aztec
|
|
@@ -57,12 +56,6 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
|
|
|
57
56
|
*/
|
|
58
57
|
getIncomingNotes(filter: IncomingNotesFilter): Promise<IncomingNoteDao[]>;
|
|
59
58
|
|
|
60
|
-
/**
|
|
61
|
-
* Gets outgoing notes.
|
|
62
|
-
* @returns The outgoing notes.
|
|
63
|
-
*/
|
|
64
|
-
getOutgoingNotes(filter: OutgoingNotesFilter): Promise<OutgoingNoteDao[]>;
|
|
65
|
-
|
|
66
59
|
/**
|
|
67
60
|
* Adds a note to DB.
|
|
68
61
|
* @param note - The note to add.
|
|
@@ -83,11 +76,10 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
|
|
|
83
76
|
* which can improve performance when dealing with large numbers of transactions.
|
|
84
77
|
*
|
|
85
78
|
* @param incomingNotes - An array of notes which were decrypted as incoming.
|
|
86
|
-
* @param outgoingNotes - An array of notes which were decrypted as outgoing.
|
|
87
79
|
* @param scope - The scope to add the notes under. Currently optional.
|
|
88
80
|
* @remark - Will create a database for the scope if it does not already exist.
|
|
89
81
|
*/
|
|
90
|
-
addNotes(incomingNotes: IncomingNoteDao[],
|
|
82
|
+
addNotes(incomingNotes: IncomingNoteDao[], scope?: AztecAddress): Promise<void>;
|
|
91
83
|
|
|
92
84
|
/**
|
|
93
85
|
* Remove nullified notes associated with the given account and nullifiers.
|
|
@@ -102,7 +94,7 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
|
|
|
102
94
|
* Gets the most recently processed block number.
|
|
103
95
|
* @returns The most recently processed block number or undefined if never synched.
|
|
104
96
|
*/
|
|
105
|
-
getBlockNumber(): number | undefined
|
|
97
|
+
getBlockNumber(): Promise<number | undefined>;
|
|
106
98
|
|
|
107
99
|
/**
|
|
108
100
|
* Retrieve the stored Block Header from the database.
|
|
@@ -115,7 +107,7 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
|
|
|
115
107
|
* @returns The Block Header.
|
|
116
108
|
* @throws If no block have been processed yet.
|
|
117
109
|
*/
|
|
118
|
-
|
|
110
|
+
getBlockHeader(): Promise<BlockHeader>;
|
|
119
111
|
|
|
120
112
|
/**
|
|
121
113
|
* Set the latest Block Header.
|
|
@@ -124,7 +116,7 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
|
|
|
124
116
|
* @param header - An object containing the most recent block header.
|
|
125
117
|
* @returns A Promise that resolves when the hash has been successfully updated in the database.
|
|
126
118
|
*/
|
|
127
|
-
setHeader(header:
|
|
119
|
+
setHeader(header: BlockHeader): Promise<void>;
|
|
128
120
|
|
|
129
121
|
/**
|
|
130
122
|
* Adds contact address to the database.
|
|
@@ -137,7 +129,7 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
|
|
|
137
129
|
* Retrieves the list of contact addresses in the address book.
|
|
138
130
|
* @returns An array of Aztec addresses.
|
|
139
131
|
*/
|
|
140
|
-
getContactAddresses(): AztecAddress[]
|
|
132
|
+
getContactAddresses(): Promise<AztecAddress[]>;
|
|
141
133
|
|
|
142
134
|
/**
|
|
143
135
|
* Removes a contact address from the database.
|
|
@@ -168,19 +160,6 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD
|
|
|
168
160
|
*/
|
|
169
161
|
getCompleteAddresses(): Promise<CompleteAddress[]>;
|
|
170
162
|
|
|
171
|
-
/**
|
|
172
|
-
* Updates up to which block number we have processed notes for a given public key.
|
|
173
|
-
* @param account - The account to set the synched block number for.
|
|
174
|
-
* @param blockNumber - The block number to set.
|
|
175
|
-
*/
|
|
176
|
-
setSynchedBlockNumberForAccount(account: AztecAddress, blockNumber: number): Promise<void>;
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Get the synched block number for a given public key.
|
|
180
|
-
* @param account - The account to get the synched block number for.
|
|
181
|
-
*/
|
|
182
|
-
getSynchedBlockNumberForAccount(account: AztecAddress): number | undefined;
|
|
183
|
-
|
|
184
163
|
/**
|
|
185
164
|
* Returns the estimated size in bytes of this db.
|
|
186
165
|
* @returns The estimated size in bytes of this db.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type IncomingNotesFilter, NoteStatus,
|
|
1
|
+
import { type IncomingNotesFilter, NoteStatus, randomTxHash } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
3
|
AztecAddress,
|
|
4
4
|
CompleteAddress,
|
|
@@ -14,7 +14,6 @@ import { BenchmarkingContractArtifact } from '@aztec/noir-contracts.js/Benchmark
|
|
|
14
14
|
import { TestContractArtifact } from '@aztec/noir-contracts.js/Test';
|
|
15
15
|
|
|
16
16
|
import { IncomingNoteDao } from './incoming_note_dao.js';
|
|
17
|
-
import { OutgoingNoteDao } from './outgoing_note_dao.js';
|
|
18
17
|
import { type PxeDatabase } from './pxe_database.js';
|
|
19
18
|
|
|
20
19
|
/**
|
|
@@ -135,7 +134,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
|
|
|
135
134
|
});
|
|
136
135
|
|
|
137
136
|
it.each(filteringTests)('stores notes in bulk and retrieves notes', async (getFilter, getExpected) => {
|
|
138
|
-
await database.addNotes(notes
|
|
137
|
+
await database.addNotes(notes);
|
|
139
138
|
const returnedNotes = await database.getIncomingNotes(getFilter());
|
|
140
139
|
|
|
141
140
|
expect(returnedNotes.sort()).toEqual(getExpected().sort());
|
|
@@ -152,7 +151,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
|
|
|
152
151
|
});
|
|
153
152
|
|
|
154
153
|
it.each(filteringTests)('retrieves nullified notes', async (getFilter, getExpected) => {
|
|
155
|
-
await database.addNotes(notes
|
|
154
|
+
await database.addNotes(notes);
|
|
156
155
|
|
|
157
156
|
// Nullify all notes and use the same filter as other test cases
|
|
158
157
|
for (const owner of owners) {
|
|
@@ -173,7 +172,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
|
|
|
173
172
|
});
|
|
174
173
|
|
|
175
174
|
it('skips nullified notes by default or when requesting active', async () => {
|
|
176
|
-
await database.addNotes(notes
|
|
175
|
+
await database.addNotes(notes);
|
|
177
176
|
|
|
178
177
|
const notesToNullify = notes.filter(note => note.addressPoint.equals(owners[0].address.toAddressPoint()));
|
|
179
178
|
const nullifiers = notesToNullify.map(note => ({
|
|
@@ -194,7 +193,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
|
|
|
194
193
|
|
|
195
194
|
it('handles note unnullification', async () => {
|
|
196
195
|
await database.setHeader(makeHeader(randomInt(1000), 100, 0 /** slot number */));
|
|
197
|
-
await database.addNotes(notes
|
|
196
|
+
await database.addNotes(notes);
|
|
198
197
|
|
|
199
198
|
const notesToNullify = notes.filter(note => note.addressPoint.equals(owners[0].address.toAddressPoint()));
|
|
200
199
|
const nullifiers = notesToNullify.map(note => ({
|
|
@@ -213,7 +212,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
|
|
|
213
212
|
});
|
|
214
213
|
|
|
215
214
|
it('returns active and nullified notes when requesting either', async () => {
|
|
216
|
-
await database.addNotes(notes
|
|
215
|
+
await database.addNotes(notes);
|
|
217
216
|
|
|
218
217
|
const notesToNullify = notes.filter(note => note.addressPoint.equals(owners[0].address.toAddressPoint()));
|
|
219
218
|
const nullifiers = notesToNullify.map(note => ({
|
|
@@ -303,7 +302,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
|
|
|
303
302
|
});
|
|
304
303
|
|
|
305
304
|
it('removes notes after a given block', async () => {
|
|
306
|
-
await database.addNotes(notes,
|
|
305
|
+
await database.addNotes(notes, owners[0].address);
|
|
307
306
|
|
|
308
307
|
await database.removeNotesAfter(5);
|
|
309
308
|
const result = await database.getIncomingNotes({ scopes: [owners[0].address] });
|
|
@@ -311,80 +310,16 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
|
|
|
311
310
|
});
|
|
312
311
|
});
|
|
313
312
|
|
|
314
|
-
describe('outgoing notes', () => {
|
|
315
|
-
let owners: CompleteAddress[];
|
|
316
|
-
let contractAddresses: AztecAddress[];
|
|
317
|
-
let storageSlots: Fr[];
|
|
318
|
-
let notes: OutgoingNoteDao[];
|
|
319
|
-
|
|
320
|
-
const filteringTests: [() => OutgoingNotesFilter, () => OutgoingNoteDao[]][] = [
|
|
321
|
-
[() => ({}), () => notes],
|
|
322
|
-
|
|
323
|
-
[
|
|
324
|
-
() => ({ contractAddress: contractAddresses[0] }),
|
|
325
|
-
() => notes.filter(note => note.contractAddress.equals(contractAddresses[0])),
|
|
326
|
-
],
|
|
327
|
-
[() => ({ contractAddress: AztecAddress.random() }), () => []],
|
|
328
|
-
|
|
329
|
-
[
|
|
330
|
-
() => ({ storageSlot: storageSlots[0] }),
|
|
331
|
-
() => notes.filter(note => note.storageSlot.equals(storageSlots[0])),
|
|
332
|
-
],
|
|
333
|
-
[() => ({ storageSlot: Fr.random() }), () => []],
|
|
334
|
-
|
|
335
|
-
[() => ({ txHash: notes[0].txHash }), () => [notes[0]]],
|
|
336
|
-
[() => ({ txHash: randomTxHash() }), () => []],
|
|
337
|
-
|
|
338
|
-
[
|
|
339
|
-
() => ({ owner: owners[0].address }),
|
|
340
|
-
() => notes.filter(note => note.ovpkM.equals(owners[0].publicKeys.masterOutgoingViewingPublicKey)),
|
|
341
|
-
],
|
|
342
|
-
|
|
343
|
-
[
|
|
344
|
-
() => ({ contractAddress: contractAddresses[0], storageSlot: storageSlots[0] }),
|
|
345
|
-
() =>
|
|
346
|
-
notes.filter(
|
|
347
|
-
note => note.contractAddress.equals(contractAddresses[0]) && note.storageSlot.equals(storageSlots[0]),
|
|
348
|
-
),
|
|
349
|
-
],
|
|
350
|
-
[() => ({ contractAddress: contractAddresses[0], storageSlot: storageSlots[1] }), () => []],
|
|
351
|
-
];
|
|
352
|
-
|
|
353
|
-
beforeEach(async () => {
|
|
354
|
-
owners = Array.from({ length: 2 }).map(() => CompleteAddress.random());
|
|
355
|
-
contractAddresses = Array.from({ length: 2 }).map(() => AztecAddress.random());
|
|
356
|
-
storageSlots = Array.from({ length: 2 }).map(() => Fr.random());
|
|
357
|
-
|
|
358
|
-
notes = Array.from({ length: 10 }).map((_, i) =>
|
|
359
|
-
OutgoingNoteDao.random({
|
|
360
|
-
contractAddress: contractAddresses[i % contractAddresses.length],
|
|
361
|
-
storageSlot: storageSlots[i % storageSlots.length],
|
|
362
|
-
ovpkM: owners[i % owners.length].publicKeys.masterOutgoingViewingPublicKey,
|
|
363
|
-
index: BigInt(i),
|
|
364
|
-
}),
|
|
365
|
-
);
|
|
366
|
-
|
|
367
|
-
for (const owner of owners) {
|
|
368
|
-
await database.addCompleteAddress(owner);
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
it.each(filteringTests)('stores notes in bulk and retrieves notes', async (getFilter, getExpected) => {
|
|
373
|
-
await database.addNotes([], notes);
|
|
374
|
-
await expect(database.getOutgoingNotes(getFilter())).resolves.toEqual(getExpected());
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
|
|
378
313
|
describe('block header', () => {
|
|
379
314
|
it('stores and retrieves the block header', async () => {
|
|
380
315
|
const header = makeHeader(randomInt(1000), INITIAL_L2_BLOCK_NUM, 0 /** slot number */);
|
|
381
316
|
|
|
382
317
|
await database.setHeader(header);
|
|
383
|
-
expect(database.
|
|
318
|
+
await expect(database.getBlockHeader()).resolves.toEqual(header);
|
|
384
319
|
});
|
|
385
320
|
|
|
386
|
-
it('rejects getting header if no block set', () => {
|
|
387
|
-
expect(() => database.
|
|
321
|
+
it('rejects getting header if no block set', async () => {
|
|
322
|
+
await expect(() => database.getBlockHeader()).rejects.toThrow();
|
|
388
323
|
});
|
|
389
324
|
});
|
|
390
325
|
|
|
@@ -423,6 +358,16 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {
|
|
|
423
358
|
expect(result).toEqual(expect.arrayContaining(addresses));
|
|
424
359
|
});
|
|
425
360
|
|
|
361
|
+
it('returns a single address', async () => {
|
|
362
|
+
const addresses = Array.from({ length: 10 }).map(() => CompleteAddress.random());
|
|
363
|
+
for (const address of addresses) {
|
|
364
|
+
await database.addCompleteAddress(address);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const result = await database.getCompleteAddress(addresses[3].address);
|
|
368
|
+
expect(result).toEqual(addresses[3]);
|
|
369
|
+
});
|
|
370
|
+
|
|
426
371
|
it("returns an empty array if it doesn't have addresses", async () => {
|
|
427
372
|
expect(await database.getCompleteAddresses()).toEqual([]);
|
|
428
373
|
});
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './pxe_service/index.js';
|
|
2
2
|
export * from './pxe_http/index.js';
|
|
3
3
|
export * from './config/index.js';
|
|
4
|
+
export * from './utils/create_pxe_service.js';
|
|
4
5
|
|
|
5
6
|
export { Tx, TxHash } from '@aztec/circuit-types';
|
|
6
7
|
|
|
@@ -12,3 +13,4 @@ export * from '@aztec/key-store';
|
|
|
12
13
|
export * from './database/index.js';
|
|
13
14
|
export { ContractDataOracle } from './contract_data_oracle/index.js';
|
|
14
15
|
export { PrivateFunctionsTree } from './contract_data_oracle/private_functions_tree.js';
|
|
16
|
+
export { SimulatorOracle } from './simulator_oracle/index.js';
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
computeContractClassIdPreimage,
|
|
13
13
|
computeSaltedInitializationHash,
|
|
14
14
|
} from '@aztec/circuits.js';
|
|
15
|
-
import {
|
|
15
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
16
16
|
import { type Tuple } from '@aztec/foundation/serialize';
|
|
17
17
|
import { type KeyStore } from '@aztec/key-store';
|
|
18
|
-
import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
|
|
18
|
+
import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/client';
|
|
19
19
|
|
|
20
20
|
import { type ContractDataOracle } from '../contract_data_oracle/index.js';
|
|
21
21
|
import { type ProvingDataOracle } from './../kernel_prover/proving_data_oracle.js';
|
|
@@ -31,7 +31,7 @@ export class KernelOracle implements ProvingDataOracle {
|
|
|
31
31
|
private keyStore: KeyStore,
|
|
32
32
|
private node: AztecNode,
|
|
33
33
|
private blockNumber: L2BlockNumber = 'latest',
|
|
34
|
-
private log =
|
|
34
|
+
private log = createLogger('pxe:kernel_oracle'),
|
|
35
35
|
) {}
|
|
36
36
|
|
|
37
37
|
public async getContractAddressPreimage(address: AztecAddress) {
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
import { makeTuple } from '@aztec/foundation/array';
|
|
38
38
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
39
39
|
import { type Tuple, assertLength } from '@aztec/foundation/serialize';
|
|
40
|
-
import { privateKernelResetDimensionsConfig } from '@aztec/noir-protocol-circuits-types';
|
|
40
|
+
import { privateKernelResetDimensionsConfig } from '@aztec/noir-protocol-circuits-types/client';
|
|
41
41
|
|
|
42
42
|
import { type ProvingDataOracle } from '../proving_data_oracle.js';
|
|
43
43
|
|
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
PrivateKernelInnerCircuitPrivateInputs,
|
|
20
20
|
PrivateKernelTailCircuitPrivateInputs,
|
|
21
21
|
type PrivateKernelTailCircuitPublicInputs,
|
|
22
|
+
type PrivateLog,
|
|
23
|
+
type ScopedPrivateLogData,
|
|
22
24
|
type TxRequest,
|
|
23
25
|
VK_TREE_HEIGHT,
|
|
24
26
|
VerificationKeyAsFields,
|
|
@@ -26,10 +28,11 @@ import {
|
|
|
26
28
|
import { hashVK } from '@aztec/circuits.js/hash';
|
|
27
29
|
import { makeTuple } from '@aztec/foundation/array';
|
|
28
30
|
import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto';
|
|
29
|
-
import {
|
|
31
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
30
32
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
31
33
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
32
|
-
import {
|
|
34
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
35
|
+
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/client';
|
|
33
36
|
import {
|
|
34
37
|
getProtocolContractSiblingPath,
|
|
35
38
|
isProtocolContract,
|
|
@@ -37,10 +40,48 @@ import {
|
|
|
37
40
|
} from '@aztec/protocol-contracts';
|
|
38
41
|
|
|
39
42
|
import { type WitnessMap } from '@noir-lang/types';
|
|
43
|
+
import { strict as assert } from 'assert';
|
|
40
44
|
|
|
41
45
|
import { PrivateKernelResetPrivateInputsBuilder } from './hints/build_private_kernel_reset_private_inputs.js';
|
|
42
46
|
import { type ProvingDataOracle } from './proving_data_oracle.js';
|
|
43
47
|
|
|
48
|
+
// TODO(#10592): Temporary workaround to check that the private logs are correctly split into non-revertible set and revertible set.
|
|
49
|
+
// This should be done in TailToPublicOutputValidator in private kernel tail.
|
|
50
|
+
function checkPrivateLogs(
|
|
51
|
+
privateLogs: ScopedPrivateLogData[],
|
|
52
|
+
nonRevertiblePrivateLogs: PrivateLog[],
|
|
53
|
+
revertiblePrivateLogs: PrivateLog[],
|
|
54
|
+
splitCounter: number,
|
|
55
|
+
) {
|
|
56
|
+
let numNonRevertible = 0;
|
|
57
|
+
let numRevertible = 0;
|
|
58
|
+
privateLogs
|
|
59
|
+
.filter(privateLog => privateLog.inner.counter !== 0)
|
|
60
|
+
.forEach(privateLog => {
|
|
61
|
+
if (privateLog.inner.counter < splitCounter) {
|
|
62
|
+
assert(
|
|
63
|
+
privateLog.inner.log.toBuffer().equals(nonRevertiblePrivateLogs[numNonRevertible].toBuffer()),
|
|
64
|
+
`mismatch non-revertible private logs at index ${numNonRevertible}`,
|
|
65
|
+
);
|
|
66
|
+
numNonRevertible++;
|
|
67
|
+
} else {
|
|
68
|
+
assert(
|
|
69
|
+
privateLog.inner.log.toBuffer().equals(revertiblePrivateLogs[numRevertible].toBuffer()),
|
|
70
|
+
`mismatch revertible private logs at index ${numRevertible}`,
|
|
71
|
+
);
|
|
72
|
+
numRevertible++;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
assert(
|
|
76
|
+
nonRevertiblePrivateLogs.slice(numNonRevertible).every(l => l.isEmpty()),
|
|
77
|
+
'Unexpected non-empty private log in non-revertible set.',
|
|
78
|
+
);
|
|
79
|
+
assert(
|
|
80
|
+
revertiblePrivateLogs.slice(numRevertible).every(l => l.isEmpty()),
|
|
81
|
+
'Unexpected non-empty private log in revertible set.',
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
44
85
|
const NULL_PROVE_OUTPUT: PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs> = {
|
|
45
86
|
publicInputs: PrivateKernelCircuitPublicInputs.empty(),
|
|
46
87
|
verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS),
|
|
@@ -55,7 +96,7 @@ const NULL_PROVE_OUTPUT: PrivateKernelSimulateOutput<PrivateKernelCircuitPublicI
|
|
|
55
96
|
* constructs private call data based on the execution results.
|
|
56
97
|
*/
|
|
57
98
|
export class KernelProver {
|
|
58
|
-
private log =
|
|
99
|
+
private log = createLogger('pxe:kernel-prover');
|
|
59
100
|
|
|
60
101
|
constructor(private oracle: ProvingDataOracle, private proofCreator: PrivateKernelProver) {}
|
|
61
102
|
|
|
@@ -78,6 +119,10 @@ export class KernelProver {
|
|
|
78
119
|
profile: boolean = false,
|
|
79
120
|
dryRun: boolean = false,
|
|
80
121
|
): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
122
|
+
const timer = new Timer();
|
|
123
|
+
|
|
124
|
+
const isPrivateOnlyTx = this.isPrivateOnly(executionResult);
|
|
125
|
+
|
|
81
126
|
const executionStack = [executionResult];
|
|
82
127
|
let firstIteration = true;
|
|
83
128
|
|
|
@@ -153,8 +198,11 @@ export class KernelProver {
|
|
|
153
198
|
getVKTreeRoot(),
|
|
154
199
|
protocolContractTreeRoot,
|
|
155
200
|
privateCallData,
|
|
201
|
+
isPrivateOnlyTx,
|
|
156
202
|
);
|
|
203
|
+
|
|
157
204
|
pushTestData('private-kernel-inputs-init', proofInput);
|
|
205
|
+
|
|
158
206
|
output = await this.proofCreator.simulateProofInit(proofInput);
|
|
159
207
|
|
|
160
208
|
acirs.push(output.bytecode);
|
|
@@ -171,7 +219,9 @@ export class KernelProver {
|
|
|
171
219
|
assertLength<Fr, typeof VK_TREE_HEIGHT>(previousVkMembershipWitness.siblingPath, VK_TREE_HEIGHT),
|
|
172
220
|
);
|
|
173
221
|
const proofInput = new PrivateKernelInnerCircuitPrivateInputs(previousKernelData, privateCallData);
|
|
222
|
+
|
|
174
223
|
pushTestData('private-kernel-inputs-inner', proofInput);
|
|
224
|
+
|
|
175
225
|
output = await this.proofCreator.simulateProofInner(proofInput);
|
|
176
226
|
|
|
177
227
|
acirs.push(output.bytecode);
|
|
@@ -224,7 +274,14 @@ export class KernelProver {
|
|
|
224
274
|
const privateInputs = new PrivateKernelTailCircuitPrivateInputs(previousKernelData);
|
|
225
275
|
|
|
226
276
|
pushTestData('private-kernel-inputs-ordering', privateInputs);
|
|
277
|
+
|
|
227
278
|
const tailOutput = await this.proofCreator.simulateProofTail(privateInputs);
|
|
279
|
+
if (tailOutput.publicInputs.forPublic) {
|
|
280
|
+
const privateLogs = privateInputs.previousKernel.publicInputs.end.privateLogs;
|
|
281
|
+
const nonRevertiblePrivateLogs = tailOutput.publicInputs.forPublic.nonRevertibleAccumulatedData.privateLogs;
|
|
282
|
+
const revertiblePrivateLogs = tailOutput.publicInputs.forPublic.revertibleAccumulatedData.privateLogs;
|
|
283
|
+
checkPrivateLogs(privateLogs, nonRevertiblePrivateLogs, revertiblePrivateLogs, validationRequestsSplitCounter);
|
|
284
|
+
}
|
|
228
285
|
|
|
229
286
|
acirs.push(tailOutput.bytecode);
|
|
230
287
|
witnessStack.push(tailOutput.outputWitness);
|
|
@@ -233,6 +290,8 @@ export class KernelProver {
|
|
|
233
290
|
tailOutput.profileResult = { gateCounts };
|
|
234
291
|
}
|
|
235
292
|
|
|
293
|
+
this.log.info(`Witness generation took ${timer.ms()}ms`);
|
|
294
|
+
|
|
236
295
|
// TODO(#7368) how do we 'bincode' encode these inputs?
|
|
237
296
|
if (!dryRun) {
|
|
238
297
|
const ivcProof = await this.proofCreator.createClientIvcProof(acirs, witnessStack);
|
|
@@ -278,4 +337,14 @@ export class KernelProver {
|
|
|
278
337
|
acirHash,
|
|
279
338
|
});
|
|
280
339
|
}
|
|
340
|
+
|
|
341
|
+
private isPrivateOnly(executionResult: PrivateExecutionResult): boolean {
|
|
342
|
+
const makesPublicCalls =
|
|
343
|
+
executionResult.enqueuedPublicFunctionCalls.some(enqueuedCall => !enqueuedCall.isEmpty()) ||
|
|
344
|
+
!executionResult.publicTeardownFunctionCall.isEmpty();
|
|
345
|
+
return (
|
|
346
|
+
!makesPublicCalls &&
|
|
347
|
+
executionResult.nestedExecutions.every(nestedExecution => this.isPrivateOnly(nestedExecution))
|
|
348
|
+
);
|
|
349
|
+
}
|
|
281
350
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AppCircuitSimulateOutput,
|
|
3
|
-
type PrivateKernelProver,
|
|
4
|
-
type PrivateKernelSimulateOutput,
|
|
5
|
-
} from '@aztec/circuit-types';
|
|
1
|
+
import { type PrivateKernelProver, type PrivateKernelSimulateOutput } from '@aztec/circuit-types';
|
|
6
2
|
import type { CircuitSimulationStats } from '@aztec/circuit-types/stats';
|
|
7
3
|
import {
|
|
8
|
-
CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS,
|
|
9
4
|
ClientIvcProof,
|
|
10
5
|
type PrivateKernelCircuitPublicInputs,
|
|
11
6
|
type PrivateKernelInitCircuitPrivateInputs,
|
|
@@ -13,13 +8,12 @@ import {
|
|
|
13
8
|
type PrivateKernelResetCircuitPrivateInputs,
|
|
14
9
|
type PrivateKernelTailCircuitPrivateInputs,
|
|
15
10
|
type PrivateKernelTailCircuitPublicInputs,
|
|
16
|
-
VerificationKeyAsFields,
|
|
17
11
|
} from '@aztec/circuits.js';
|
|
18
|
-
import {
|
|
12
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
19
13
|
import { elapsed } from '@aztec/foundation/timer';
|
|
20
14
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
ClientCircuitVks,
|
|
16
|
+
type ClientProtocolArtifact,
|
|
23
17
|
executeInit,
|
|
24
18
|
executeInner,
|
|
25
19
|
executeReset,
|
|
@@ -27,7 +21,7 @@ import {
|
|
|
27
21
|
executeTailForPublic,
|
|
28
22
|
getPrivateKernelResetArtifactName,
|
|
29
23
|
maxPrivateKernelResetDimensions,
|
|
30
|
-
} from '@aztec/noir-protocol-circuits-types';
|
|
24
|
+
} from '@aztec/noir-protocol-circuits-types/client';
|
|
31
25
|
|
|
32
26
|
import { type WitnessMap } from '@noir-lang/types';
|
|
33
27
|
|
|
@@ -35,7 +29,7 @@ import { type WitnessMap } from '@noir-lang/types';
|
|
|
35
29
|
* Test Proof Creator executes circuit simulations and provides fake proofs.
|
|
36
30
|
*/
|
|
37
31
|
export class TestPrivateKernelProver implements PrivateKernelProver {
|
|
38
|
-
constructor(private log =
|
|
32
|
+
constructor(private log = createLogger('pxe:test_proof_creator')) {}
|
|
39
33
|
|
|
40
34
|
createClientIvcProof(_acirs: Buffer[], _witnessStack: WitnessMap[]): Promise<ClientIvcProof> {
|
|
41
35
|
return Promise.resolve(ClientIvcProof.empty());
|
|
@@ -73,7 +67,9 @@ export class TestPrivateKernelProver implements PrivateKernelProver {
|
|
|
73
67
|
privateInputs: PrivateKernelResetCircuitPrivateInputs,
|
|
74
68
|
): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
|
|
75
69
|
const variantPrivateInputs = privateInputs.trimToSizes();
|
|
76
|
-
const [duration, result] = await elapsed(() =>
|
|
70
|
+
const [duration, result] = await elapsed(() =>
|
|
71
|
+
executeReset(variantPrivateInputs, privateInputs.dimensions, privateInputs),
|
|
72
|
+
);
|
|
77
73
|
this.log.debug(`Simulated private kernel reset`, {
|
|
78
74
|
eventName: 'circuit-simulation',
|
|
79
75
|
circuitName: 'private-kernel-reset',
|
|
@@ -112,22 +108,12 @@ export class TestPrivateKernelProver implements PrivateKernelProver {
|
|
|
112
108
|
return Promise.resolve(0);
|
|
113
109
|
}
|
|
114
110
|
|
|
115
|
-
computeAppCircuitVerificationKey(
|
|
116
|
-
_bytecode: Buffer,
|
|
117
|
-
_appCircuitName?: string | undefined,
|
|
118
|
-
): Promise<AppCircuitSimulateOutput> {
|
|
119
|
-
const appCircuitProofOutput: AppCircuitSimulateOutput = {
|
|
120
|
-
verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS),
|
|
121
|
-
};
|
|
122
|
-
return Promise.resolve(appCircuitProofOutput);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
111
|
private makeEmptyKernelSimulateOutput<
|
|
126
112
|
PublicInputsType extends PrivateKernelTailCircuitPublicInputs | PrivateKernelCircuitPublicInputs,
|
|
127
|
-
>(publicInputs: PublicInputsType, circuitType:
|
|
113
|
+
>(publicInputs: PublicInputsType, circuitType: ClientProtocolArtifact) {
|
|
128
114
|
const kernelProofOutput: PrivateKernelSimulateOutput<PublicInputsType> = {
|
|
129
115
|
publicInputs,
|
|
130
|
-
verificationKey:
|
|
116
|
+
verificationKey: ClientCircuitVks[circuitType].keyAsFields,
|
|
131
117
|
outputWitness: new Map(),
|
|
132
118
|
bytecode: Buffer.from([]),
|
|
133
119
|
};
|
|
@@ -3,7 +3,7 @@ import { type AztecAddress } from '@aztec/circuits.js';
|
|
|
3
3
|
import { computeNoteHashNonce, siloNullifier } from '@aztec/circuits.js/hash';
|
|
4
4
|
import { type NoteSelector } from '@aztec/foundation/abi';
|
|
5
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
6
|
-
import { type AcirSimulator } from '@aztec/simulator';
|
|
6
|
+
import { type AcirSimulator } from '@aztec/simulator/client';
|
|
7
7
|
|
|
8
8
|
export interface NoteInfo {
|
|
9
9
|
noteHashIndex: number;
|
|
@@ -18,7 +18,7 @@ export interface NoteInfo {
|
|
|
18
18
|
* @dev Finds the index in the note hash tree by computing the note hash with different nonce and see which hash for
|
|
19
19
|
* the current tx matches this value.
|
|
20
20
|
* @remarks This method assists in identifying spent notes in the note hash tree.
|
|
21
|
-
* @param
|
|
21
|
+
* @param uniqueNoteHashes - Note hashes in the tx. One of them should correspond to the note we are looking for
|
|
22
22
|
* @param txHash - Hash of a tx the note was emitted in.
|
|
23
23
|
* @param contractAddress - Address of the contract the note was emitted in.
|
|
24
24
|
* @param storageSlot - Storage slot of the note.
|
|
@@ -32,7 +32,7 @@ export interface NoteInfo {
|
|
|
32
32
|
*/
|
|
33
33
|
export async function bruteForceNoteInfo(
|
|
34
34
|
simulator: AcirSimulator,
|
|
35
|
-
|
|
35
|
+
uniqueNoteHashes: Fr[],
|
|
36
36
|
txHash: TxHash,
|
|
37
37
|
contractAddress: AztecAddress,
|
|
38
38
|
storageSlot: Fr,
|
|
@@ -44,22 +44,22 @@ export async function bruteForceNoteInfo(
|
|
|
44
44
|
let noteHashIndex = 0;
|
|
45
45
|
let nonce: Fr | undefined;
|
|
46
46
|
let noteHash: Fr | undefined;
|
|
47
|
-
let
|
|
47
|
+
let uniqueNoteHash: Fr | undefined;
|
|
48
48
|
let innerNullifier: Fr | undefined;
|
|
49
49
|
const firstNullifier = Fr.fromBuffer(txHash.toBuffer());
|
|
50
50
|
|
|
51
|
-
for (; noteHashIndex <
|
|
51
|
+
for (; noteHashIndex < uniqueNoteHashes.length; ++noteHashIndex) {
|
|
52
52
|
if (excludedIndices.has(noteHashIndex)) {
|
|
53
53
|
continue;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
56
|
+
const uniqueNoteHashFromTxEffect = uniqueNoteHashes[noteHashIndex];
|
|
57
|
+
if (uniqueNoteHashFromTxEffect.equals(Fr.ZERO)) {
|
|
58
58
|
break;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
const expectedNonce = computeNoteHashNonce(firstNullifier, noteHashIndex);
|
|
62
|
-
({ noteHash,
|
|
62
|
+
({ noteHash, uniqueNoteHash, innerNullifier } = await simulator.computeNoteHashAndOptionallyANullifier(
|
|
63
63
|
contractAddress,
|
|
64
64
|
expectedNonce,
|
|
65
65
|
storageSlot,
|
|
@@ -68,7 +68,7 @@ export async function bruteForceNoteInfo(
|
|
|
68
68
|
note,
|
|
69
69
|
));
|
|
70
70
|
|
|
71
|
-
if (
|
|
71
|
+
if (uniqueNoteHashFromTxEffect.equals(uniqueNoteHash)) {
|
|
72
72
|
nonce = expectedNonce;
|
|
73
73
|
break;
|
|
74
74
|
}
|