@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,9 +1,12 @@
|
|
|
1
1
|
import { type L1NotePayload, type TxHash } from '@aztec/circuit-types';
|
|
2
2
|
import { Fr, type PublicKey } from '@aztec/circuits.js';
|
|
3
3
|
import { computeNoteHashNonce, siloNullifier } from '@aztec/circuits.js/hash';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
5
|
+
import { type AcirSimulator, ContractNotFoundError } from '@aztec/simulator';
|
|
5
6
|
|
|
6
|
-
import {
|
|
7
|
+
import { DeferredNoteDao } from '../database/deferred_note_dao.js';
|
|
8
|
+
import { IncomingNoteDao } from '../database/incoming_note_dao.js';
|
|
9
|
+
import { OutgoingNoteDao } from '../database/outgoing_note_dao.js';
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* Decodes a note from a transaction that we know was intended for us.
|
|
@@ -11,96 +14,207 @@ import { NoteDao } from '../database/note_dao.js';
|
|
|
11
14
|
* Accepts a set of excluded indices, which are indices that have been assigned a note in the same tx.
|
|
12
15
|
* Inserts the index of the note into the excludedIndices set if the note is successfully decoded.
|
|
13
16
|
*
|
|
14
|
-
* @param
|
|
17
|
+
* @param ivpkM - The public counterpart to the secret key to be used in the decryption of incoming note logs.
|
|
18
|
+
* @param ovpkM - The public counterpart to the secret key to be used in the decryption of outgoing note logs.
|
|
15
19
|
* @param payload - An instance of l1NotePayload.
|
|
16
20
|
* @param txHash - The hash of the transaction that created the note. Equivalent to the first nullifier of the transaction.
|
|
17
21
|
* @param newNoteHashes - New note hashes in this transaction, one of which belongs to this note.
|
|
18
22
|
* @param dataStartIndexForTx - The next available leaf index for the note hash tree for this transaction.
|
|
19
23
|
* @param excludedIndices - Indices that have been assigned a note in the same tx. Notes in a tx can have the same l1NotePayload, we need to find a different index for each replicate.
|
|
20
24
|
* @param simulator - An instance of AcirSimulator.
|
|
21
|
-
* @returns
|
|
25
|
+
* @returns An object containing the incoming, outgoing, and deferred notes.
|
|
22
26
|
*/
|
|
23
|
-
export async function
|
|
27
|
+
export async function produceNoteDaos(
|
|
24
28
|
simulator: AcirSimulator,
|
|
25
|
-
|
|
29
|
+
ivpkM: PublicKey | undefined,
|
|
30
|
+
ovpkM: PublicKey | undefined,
|
|
26
31
|
payload: L1NotePayload,
|
|
27
32
|
txHash: TxHash,
|
|
28
33
|
newNoteHashes: Fr[],
|
|
29
34
|
dataStartIndexForTx: number,
|
|
30
35
|
excludedIndices: Set<number>,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
log: Logger,
|
|
37
|
+
): Promise<{
|
|
38
|
+
incomingNote: IncomingNoteDao | undefined;
|
|
39
|
+
outgoingNote: OutgoingNoteDao | undefined;
|
|
40
|
+
incomingDeferredNote: DeferredNoteDao | undefined;
|
|
41
|
+
outgoingDeferredNote: DeferredNoteDao | undefined;
|
|
42
|
+
}> {
|
|
43
|
+
if (!ivpkM && !ovpkM) {
|
|
44
|
+
throw new Error('Both ivpkM and ovpkM are undefined. Cannot create note.');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let incomingNote: IncomingNoteDao | undefined;
|
|
48
|
+
let outgoingNote: OutgoingNoteDao | undefined;
|
|
49
|
+
let incomingDeferredNote: DeferredNoteDao | undefined;
|
|
50
|
+
let outgoingDeferredNote: DeferredNoteDao | undefined;
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
if (ivpkM) {
|
|
54
|
+
const { noteHashIndex, nonce, innerNoteHash, siloedNullifier } = await findNoteIndexAndNullifier(
|
|
55
|
+
simulator,
|
|
56
|
+
newNoteHashes,
|
|
57
|
+
txHash,
|
|
58
|
+
payload,
|
|
59
|
+
excludedIndices,
|
|
60
|
+
true, // For incoming we compute a nullifier (recipient of incoming is the party that nullifies).
|
|
61
|
+
);
|
|
62
|
+
const index = BigInt(dataStartIndexForTx + noteHashIndex);
|
|
63
|
+
excludedIndices?.add(noteHashIndex);
|
|
64
|
+
|
|
65
|
+
incomingNote = new IncomingNoteDao(
|
|
66
|
+
payload.note,
|
|
67
|
+
payload.contractAddress,
|
|
68
|
+
payload.storageSlot,
|
|
69
|
+
payload.noteTypeId,
|
|
70
|
+
txHash,
|
|
71
|
+
nonce,
|
|
72
|
+
innerNoteHash,
|
|
73
|
+
siloedNullifier,
|
|
74
|
+
index,
|
|
75
|
+
ivpkM,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
if (e instanceof ContractNotFoundError) {
|
|
80
|
+
log.warn(e.message);
|
|
81
|
+
|
|
82
|
+
if (ivpkM) {
|
|
83
|
+
incomingDeferredNote = new DeferredNoteDao(
|
|
84
|
+
ivpkM,
|
|
85
|
+
payload.note,
|
|
86
|
+
payload.contractAddress,
|
|
87
|
+
payload.storageSlot,
|
|
88
|
+
payload.noteTypeId,
|
|
89
|
+
txHash,
|
|
90
|
+
newNoteHashes,
|
|
91
|
+
dataStartIndexForTx,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
log.error(`Could not process note because of "${e}". Discarding note...`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
if (ovpkM) {
|
|
101
|
+
if (incomingNote) {
|
|
102
|
+
// Incoming note is defined meaning that this PXE has both the incoming and outgoing keys. We can skip computing
|
|
103
|
+
// note hash and note index since we already have them in the incoming note.
|
|
104
|
+
outgoingNote = new OutgoingNoteDao(
|
|
105
|
+
payload.note,
|
|
106
|
+
payload.contractAddress,
|
|
107
|
+
payload.storageSlot,
|
|
108
|
+
payload.noteTypeId,
|
|
109
|
+
txHash,
|
|
110
|
+
incomingNote.nonce,
|
|
111
|
+
incomingNote.innerNoteHash,
|
|
112
|
+
incomingNote.index,
|
|
113
|
+
ovpkM,
|
|
114
|
+
);
|
|
115
|
+
} else {
|
|
116
|
+
const { noteHashIndex, nonce, innerNoteHash } = await findNoteIndexAndNullifier(
|
|
117
|
+
simulator,
|
|
118
|
+
newNoteHashes,
|
|
119
|
+
txHash,
|
|
120
|
+
payload,
|
|
121
|
+
excludedIndices,
|
|
122
|
+
false, // For outgoing we do not compute a nullifier.
|
|
123
|
+
);
|
|
124
|
+
const index = BigInt(dataStartIndexForTx + noteHashIndex);
|
|
125
|
+
excludedIndices?.add(noteHashIndex);
|
|
126
|
+
outgoingNote = new OutgoingNoteDao(
|
|
127
|
+
payload.note,
|
|
128
|
+
payload.contractAddress,
|
|
129
|
+
payload.storageSlot,
|
|
130
|
+
payload.noteTypeId,
|
|
131
|
+
txHash,
|
|
132
|
+
nonce,
|
|
133
|
+
innerNoteHash,
|
|
134
|
+
index,
|
|
135
|
+
ovpkM,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} catch (e) {
|
|
140
|
+
if (e instanceof ContractNotFoundError) {
|
|
141
|
+
log.warn(e.message);
|
|
142
|
+
|
|
143
|
+
if (ovpkM) {
|
|
144
|
+
outgoingDeferredNote = new DeferredNoteDao(
|
|
145
|
+
ovpkM,
|
|
146
|
+
payload.note,
|
|
147
|
+
payload.contractAddress,
|
|
148
|
+
payload.storageSlot,
|
|
149
|
+
payload.noteTypeId,
|
|
150
|
+
txHash,
|
|
151
|
+
newNoteHashes,
|
|
152
|
+
dataStartIndexForTx,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
log.error(`Could not process note because of "${e}". Discarding note...`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
incomingNote,
|
|
162
|
+
outgoingNote,
|
|
163
|
+
incomingDeferredNote,
|
|
164
|
+
outgoingDeferredNote,
|
|
165
|
+
};
|
|
53
166
|
}
|
|
54
167
|
|
|
55
168
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* @param
|
|
63
|
-
* @param txHash - First nullifier in the tx.
|
|
64
|
-
* @param l1NotePayload - An instance of l1NotePayload.
|
|
169
|
+
* Finds nonce, index, inner hash and siloed nullifier for a given note.
|
|
170
|
+
* @dev Finds the index in the note hash tree by computing the note hash with different nonce and see which hash for
|
|
171
|
+
* the current tx matches this value.
|
|
172
|
+
* @remarks This method assists in identifying spent notes in the note hash tree.
|
|
173
|
+
* @param noteHashes - Note hashes in the tx. One of them should correspond to the note we are looking for
|
|
174
|
+
* @param txHash - Hash of a tx the note was emitted in.
|
|
175
|
+
* @param l1NotePayload - The note payload.
|
|
65
176
|
* @param excludedIndices - Indices that have been assigned a note in the same tx. Notes in a tx can have the same
|
|
66
177
|
* l1NotePayload. We need to find a different index for each replicate.
|
|
67
|
-
* @
|
|
68
|
-
*
|
|
178
|
+
* @param computeNullifier - A flag indicating whether to compute the nullifier or just return 0.
|
|
179
|
+
* @returns Nonce, index, inner hash and siloed nullifier for a given note.
|
|
180
|
+
* @throws If cannot find the nonce for the note.
|
|
69
181
|
*/
|
|
70
182
|
async function findNoteIndexAndNullifier(
|
|
71
183
|
simulator: AcirSimulator,
|
|
72
|
-
|
|
184
|
+
noteHashes: Fr[],
|
|
73
185
|
txHash: TxHash,
|
|
74
186
|
{ contractAddress, storageSlot, noteTypeId, note }: L1NotePayload,
|
|
75
187
|
excludedIndices: Set<number>,
|
|
188
|
+
computeNullifier: boolean,
|
|
76
189
|
) {
|
|
77
|
-
let
|
|
190
|
+
let noteHashIndex = 0;
|
|
78
191
|
let nonce: Fr | undefined;
|
|
79
192
|
let innerNoteHash: Fr | undefined;
|
|
80
193
|
let siloedNoteHash: Fr | undefined;
|
|
81
194
|
let innerNullifier: Fr | undefined;
|
|
82
195
|
const firstNullifier = Fr.fromBuffer(txHash.toBuffer());
|
|
83
196
|
|
|
84
|
-
for (;
|
|
85
|
-
if (excludedIndices.has(
|
|
197
|
+
for (; noteHashIndex < noteHashes.length; ++noteHashIndex) {
|
|
198
|
+
if (excludedIndices.has(noteHashIndex)) {
|
|
86
199
|
continue;
|
|
87
200
|
}
|
|
88
201
|
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
202
|
+
const noteHash = noteHashes[noteHashIndex];
|
|
203
|
+
if (noteHash.equals(Fr.ZERO)) {
|
|
91
204
|
break;
|
|
92
205
|
}
|
|
93
206
|
|
|
94
|
-
const expectedNonce = computeNoteHashNonce(firstNullifier,
|
|
95
|
-
({ innerNoteHash, siloedNoteHash, innerNullifier } = await simulator.
|
|
207
|
+
const expectedNonce = computeNoteHashNonce(firstNullifier, noteHashIndex);
|
|
208
|
+
({ innerNoteHash, siloedNoteHash, innerNullifier } = await simulator.computeNoteHashAndOptionallyANullifier(
|
|
96
209
|
contractAddress,
|
|
97
210
|
expectedNonce,
|
|
98
211
|
storageSlot,
|
|
99
212
|
noteTypeId,
|
|
213
|
+
computeNullifier,
|
|
100
214
|
note,
|
|
101
215
|
));
|
|
102
216
|
|
|
103
|
-
if (
|
|
217
|
+
if (noteHash.equals(siloedNoteHash)) {
|
|
104
218
|
nonce = expectedNonce;
|
|
105
219
|
break;
|
|
106
220
|
}
|
|
@@ -109,11 +223,11 @@ async function findNoteIndexAndNullifier(
|
|
|
109
223
|
if (!nonce) {
|
|
110
224
|
// NB: this used to warn the user that a decrypted log didn't match any notes.
|
|
111
225
|
// This was previously fine as we didn't chop transient note logs, but now we do (#1641 complete).
|
|
112
|
-
throw new Error('Cannot find a matching
|
|
226
|
+
throw new Error('Cannot find a matching note hash for the note.');
|
|
113
227
|
}
|
|
114
228
|
|
|
115
229
|
return {
|
|
116
|
-
|
|
230
|
+
noteHashIndex,
|
|
117
231
|
nonce,
|
|
118
232
|
innerNoteHash: innerNoteHash!,
|
|
119
233
|
siloedNullifier: siloNullifier(contractAddress, innerNullifier!),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthWitness,
|
|
3
3
|
CompleteAddress,
|
|
4
|
-
|
|
4
|
+
EncryptedNoteL2BlockL2Logs,
|
|
5
5
|
ExtendedNote,
|
|
6
6
|
ExtendedUnencryptedL2Log,
|
|
7
7
|
L2Block,
|
|
@@ -50,7 +50,7 @@ export function createPXERpcServer(pxeService: PXE): JsonRpcServer {
|
|
|
50
50
|
TxEffect,
|
|
51
51
|
LogId,
|
|
52
52
|
},
|
|
53
|
-
{ SimulatedTx, Tx, TxReceipt,
|
|
53
|
+
{ SimulatedTx, Tx, TxReceipt, EncryptedNoteL2BlockL2Logs, UnencryptedL2BlockL2Logs, NullifierMembershipWitness },
|
|
54
54
|
['start', 'stop'],
|
|
55
55
|
);
|
|
56
56
|
}
|
|
@@ -5,6 +5,7 @@ import { createDebugLogger } from '@aztec/foundation/log';
|
|
|
5
5
|
import { KeyStore } from '@aztec/key-store';
|
|
6
6
|
import { AztecLmdbStore } from '@aztec/kv-store/lmdb';
|
|
7
7
|
import { initStoreForRollup } from '@aztec/kv-store/utils';
|
|
8
|
+
import { getCanonicalAuthRegistry } from '@aztec/protocol-contracts/auth-registry';
|
|
8
9
|
import { getCanonicalClassRegisterer } from '@aztec/protocol-contracts/class-registerer';
|
|
9
10
|
import { getCanonicalGasToken } from '@aztec/protocol-contracts/gas-token';
|
|
10
11
|
import { getCanonicalInstanceDeployer } from '@aztec/protocol-contracts/instance-deployer';
|
|
@@ -65,8 +66,9 @@ export async function createPXEService(
|
|
|
65
66
|
getCanonicalClassRegisterer(),
|
|
66
67
|
getCanonicalInstanceDeployer(),
|
|
67
68
|
getCanonicalMultiCallEntrypointContract(),
|
|
68
|
-
getCanonicalGasToken(
|
|
69
|
+
getCanonicalGasToken(),
|
|
69
70
|
getCanonicalKeyRegistry(),
|
|
71
|
+
getCanonicalAuthRegistry(),
|
|
70
72
|
]) {
|
|
71
73
|
await server.registerContract(contract);
|
|
72
74
|
}
|