@aztec/pxe 0.60.0 → 0.61.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/database/deferred_note_dao.d.ts +6 -19
- package/dest/database/deferred_note_dao.d.ts.map +1 -1
- package/dest/database/deferred_note_dao.js +8 -18
- 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 +3 -3
- package/dest/database/kv_pxe_database.d.ts +5 -3
- package/dest/database/kv_pxe_database.d.ts.map +1 -1
- package/dest/database/kv_pxe_database.js +22 -8
- package/dest/database/outgoing_note_dao.d.ts +1 -1
- package/dest/database/outgoing_note_dao.d.ts.map +1 -1
- package/dest/database/outgoing_note_dao.js +3 -3
- package/dest/database/pxe_database.d.ts +6 -4
- package/dest/database/pxe_database.d.ts.map +1 -1
- package/dest/note_processor/note_processor.d.ts +1 -5
- package/dest/note_processor/note_processor.d.ts.map +1 -1
- package/dest/note_processor/note_processor.js +56 -58
- package/dest/note_processor/utils/add_public_values_to_payload.d.ts +10 -0
- package/dest/note_processor/utils/add_public_values_to_payload.d.ts.map +1 -0
- package/dest/note_processor/utils/add_public_values_to_payload.js +48 -0
- package/dest/note_processor/utils/brute_force_note_info.d.ts +8 -3
- package/dest/note_processor/utils/brute_force_note_info.d.ts.map +1 -1
- package/dest/note_processor/utils/brute_force_note_info.js +6 -3
- package/dest/note_processor/utils/produce_note_daos.d.ts.map +1 -1
- package/dest/note_processor/utils/produce_note_daos.js +2 -4
- package/dest/note_processor/utils/produce_note_daos_for_key.d.ts +3 -3
- package/dest/note_processor/utils/produce_note_daos_for_key.d.ts.map +1 -1
- package/dest/note_processor/utils/produce_note_daos_for_key.js +7 -61
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +20 -6
- package/dest/simulator_oracle/index.d.ts +17 -1
- package/dest/simulator_oracle/index.d.ts.map +1 -1
- package/dest/simulator_oracle/index.js +40 -1
- package/dest/synchronizer/synchronizer.d.ts +1 -1
- package/dest/synchronizer/synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/synchronizer.js +3 -3
- package/package.json +14 -14
- package/src/database/deferred_note_dao.ts +6 -19
- package/src/database/incoming_note_dao.ts +2 -1
- package/src/database/kv_pxe_database.ts +26 -6
- package/src/database/outgoing_note_dao.ts +2 -1
- package/src/database/pxe_database.ts +8 -4
- package/src/note_processor/note_processor.ts +89 -88
- package/src/note_processor/utils/add_public_values_to_payload.ts +63 -0
- package/src/note_processor/utils/brute_force_note_info.ts +11 -3
- package/src/note_processor/utils/produce_note_daos.ts +5 -7
- package/src/note_processor/utils/produce_note_daos_for_key.ts +19 -114
- package/src/pxe_service/pxe_service.ts +22 -3
- package/src/simulator_oracle/index.ts +51 -0
- package/src/synchronizer/synchronizer.ts +2 -2
- package/dest/note_processor/utils/add_nullable_field_to_payload.d.ts +0 -12
- package/dest/note_processor/utils/add_nullable_field_to_payload.d.ts.map +0 -1
- package/dest/note_processor/utils/add_nullable_field_to_payload.js +0 -46
- package/src/note_processor/utils/add_nullable_field_to_payload.ts +0 -67
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type L1NotePayload, type TxHash, UnencryptedTxL2Logs } from '@aztec/circuit-types';
|
|
2
|
-
import { Fr, type PublicKey } from '@aztec/circuits.js';
|
|
1
|
+
import { type L1NotePayload, type Note, type TxHash, type UnencryptedTxL2Logs } from '@aztec/circuit-types';
|
|
2
|
+
import { type Fr, type PublicKey } from '@aztec/circuits.js';
|
|
3
3
|
import { type Logger } from '@aztec/foundation/log';
|
|
4
4
|
import { type AcirSimulator, ContractNotFoundError } from '@aztec/simulator';
|
|
5
5
|
|
|
6
6
|
import { DeferredNoteDao } from '../../database/deferred_note_dao.js';
|
|
7
7
|
import { type PxeDatabase } from '../../database/pxe_database.js';
|
|
8
|
-
import {
|
|
8
|
+
import { getOrderedNoteItems } from './add_public_values_to_payload.js';
|
|
9
9
|
import { type NoteInfo, bruteForceNoteInfo } from './brute_force_note_info.js';
|
|
10
10
|
|
|
11
11
|
export async function produceNoteDaosForKey<T>(
|
|
@@ -19,61 +19,40 @@ export async function produceNoteDaosForKey<T>(
|
|
|
19
19
|
excludedIndices: Set<number>,
|
|
20
20
|
logger: Logger,
|
|
21
21
|
unencryptedLogs: UnencryptedTxL2Logs,
|
|
22
|
-
daoConstructor: (
|
|
22
|
+
daoConstructor: (
|
|
23
|
+
note: Note,
|
|
24
|
+
payload: L1NotePayload,
|
|
25
|
+
noteInfo: NoteInfo,
|
|
26
|
+
dataStartIndexForTx: number,
|
|
27
|
+
pkM: PublicKey,
|
|
28
|
+
) => T,
|
|
23
29
|
): Promise<[T | undefined, DeferredNoteDao | undefined]> {
|
|
24
30
|
let noteDao: T | undefined;
|
|
25
31
|
let deferredNoteDao: DeferredNoteDao | undefined;
|
|
26
32
|
|
|
27
33
|
try {
|
|
34
|
+
// We get the note by merging publicly and privately delivered note values.
|
|
35
|
+
const note = await getOrderedNoteItems(db, payload);
|
|
36
|
+
|
|
28
37
|
const noteInfo = await bruteForceNoteInfo(
|
|
29
38
|
simulator,
|
|
30
39
|
noteHashes,
|
|
31
40
|
txHash,
|
|
32
|
-
payload,
|
|
41
|
+
payload.contractAddress,
|
|
42
|
+
payload.storageSlot,
|
|
43
|
+
payload.noteTypeId,
|
|
44
|
+
note,
|
|
33
45
|
excludedIndices,
|
|
34
46
|
true, // For incoming we compute a nullifier (recipient of incoming is the party that nullifies).
|
|
35
47
|
);
|
|
36
48
|
excludedIndices?.add(noteInfo.noteHashIndex);
|
|
37
49
|
|
|
38
|
-
noteDao = daoConstructor(payload, noteInfo, dataStartIndexForTx, pkM);
|
|
50
|
+
noteDao = daoConstructor(note, payload, noteInfo, dataStartIndexForTx, pkM);
|
|
39
51
|
} catch (e) {
|
|
40
52
|
if (e instanceof ContractNotFoundError) {
|
|
41
53
|
logger.warn(e.message);
|
|
42
54
|
|
|
43
|
-
deferredNoteDao = new DeferredNoteDao(
|
|
44
|
-
pkM,
|
|
45
|
-
payload.note,
|
|
46
|
-
payload.contractAddress,
|
|
47
|
-
payload.storageSlot,
|
|
48
|
-
payload.noteTypeId,
|
|
49
|
-
txHash,
|
|
50
|
-
noteHashes,
|
|
51
|
-
dataStartIndexForTx,
|
|
52
|
-
unencryptedLogs,
|
|
53
|
-
);
|
|
54
|
-
} else if (
|
|
55
|
-
(e as any).message.includes('failed to solve blackbox function: embedded_curve_add') ||
|
|
56
|
-
(e as any).message.includes('Could not find key prefix.')
|
|
57
|
-
) {
|
|
58
|
-
// TODO(#8769): This branch is a temporary partial notes delivery solution that should be eventually replaced.
|
|
59
|
-
// Both error messages above occur only when we are dealing with a partial note and are thrown when calling
|
|
60
|
-
// `note.compute_note_hash()` or `note.compute_nullifier_without_context()`
|
|
61
|
-
// in `compute_note_hash_and_optionally_a_nullifier` function. It occurs with partial notes because in the
|
|
62
|
-
// partial flow we receive a note log of a note that is missing some fields here and then we try to compute
|
|
63
|
-
// the note hash with MSM while some of the fields are zeroed out (or get a nsk for zero npk_m_hash).
|
|
64
|
-
noteDao = await handlePartialNote(
|
|
65
|
-
simulator,
|
|
66
|
-
db,
|
|
67
|
-
pkM,
|
|
68
|
-
payload,
|
|
69
|
-
txHash,
|
|
70
|
-
noteHashes,
|
|
71
|
-
dataStartIndexForTx,
|
|
72
|
-
excludedIndices,
|
|
73
|
-
logger,
|
|
74
|
-
unencryptedLogs,
|
|
75
|
-
daoConstructor,
|
|
76
|
-
);
|
|
55
|
+
deferredNoteDao = new DeferredNoteDao(pkM, payload, txHash, noteHashes, dataStartIndexForTx, unencryptedLogs);
|
|
77
56
|
} else {
|
|
78
57
|
logger.error(`Could not process note because of "${e}". Discarding note...`);
|
|
79
58
|
}
|
|
@@ -81,77 +60,3 @@ export async function produceNoteDaosForKey<T>(
|
|
|
81
60
|
|
|
82
61
|
return [noteDao, deferredNoteDao];
|
|
83
62
|
}
|
|
84
|
-
|
|
85
|
-
async function handlePartialNote<T>(
|
|
86
|
-
simulator: AcirSimulator,
|
|
87
|
-
db: PxeDatabase,
|
|
88
|
-
pkM: PublicKey,
|
|
89
|
-
payload: L1NotePayload,
|
|
90
|
-
txHash: TxHash,
|
|
91
|
-
noteHashes: Fr[],
|
|
92
|
-
dataStartIndexForTx: number,
|
|
93
|
-
excludedIndices: Set<number>,
|
|
94
|
-
logger: Logger,
|
|
95
|
-
unencryptedLogs: UnencryptedTxL2Logs,
|
|
96
|
-
daoConstructor: (payload: L1NotePayload, noteInfo: NoteInfo, dataStartIndexForTx: number, pkM: PublicKey) => T,
|
|
97
|
-
): Promise<T | undefined> {
|
|
98
|
-
let noteDao: T | undefined;
|
|
99
|
-
|
|
100
|
-
for (const functionLogs of unencryptedLogs.functionLogs) {
|
|
101
|
-
for (const log of functionLogs.logs) {
|
|
102
|
-
const { data } = log;
|
|
103
|
-
// It is the expectation that partial notes will have the corresponding unencrypted log be multiple
|
|
104
|
-
// of Fr.SIZE_IN_BYTES as the nullable fields should be simply concatenated.
|
|
105
|
-
if (data.length % Fr.SIZE_IN_BYTES === 0) {
|
|
106
|
-
const nullableFields = [];
|
|
107
|
-
for (let i = 0; i < data.length; i += Fr.SIZE_IN_BYTES) {
|
|
108
|
-
const chunk = data.subarray(i, i + Fr.SIZE_IN_BYTES);
|
|
109
|
-
nullableFields.push(Fr.fromBuffer(chunk));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// We insert the nullable fields into the note and then we try to produce the note dao again
|
|
113
|
-
const payloadWithNullableFields = await addNullableFieldsToPayload(db, payload, nullableFields);
|
|
114
|
-
|
|
115
|
-
let deferredNoteDao: DeferredNoteDao | undefined;
|
|
116
|
-
try {
|
|
117
|
-
[noteDao, deferredNoteDao] = await produceNoteDaosForKey(
|
|
118
|
-
simulator,
|
|
119
|
-
db,
|
|
120
|
-
pkM,
|
|
121
|
-
payloadWithNullableFields,
|
|
122
|
-
txHash,
|
|
123
|
-
noteHashes,
|
|
124
|
-
dataStartIndexForTx,
|
|
125
|
-
excludedIndices,
|
|
126
|
-
logger,
|
|
127
|
-
UnencryptedTxL2Logs.empty(), // We set unencrypted logs to empty to prevent infinite recursion.
|
|
128
|
-
daoConstructor,
|
|
129
|
-
);
|
|
130
|
-
} catch (e) {
|
|
131
|
-
// We ignore the key prefix error because that is expected to be triggered when an incorrect value
|
|
132
|
-
// is inserted at the position of `npk_m_hash`. This happens commonly because we are brute forcing
|
|
133
|
-
// the unencrypted logs.
|
|
134
|
-
if (!(e as any).message.includes('Could not find key prefix.')) {
|
|
135
|
-
throw e;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (deferredNoteDao) {
|
|
140
|
-
// This should not happen as we should first get contract not found error before the blackbox func error.
|
|
141
|
-
throw new Error('Partial notes should never be deferred.');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (noteDao) {
|
|
145
|
-
// We managed to complete the partial note so we terminate the search.
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (!noteDao) {
|
|
153
|
-
logger.error(`Partial note note found. Discarding note...`);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return noteDao;
|
|
157
|
-
}
|
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
type NodeInfo,
|
|
42
42
|
type PartialAddress,
|
|
43
43
|
type PrivateKernelTailCircuitPublicInputs,
|
|
44
|
+
computeAddressSecret,
|
|
44
45
|
computeContractAddressFromInstance,
|
|
45
46
|
computeContractClassId,
|
|
46
47
|
getContractClassFromArtifact,
|
|
@@ -135,7 +136,7 @@ export class PXEService implements PXE {
|
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
count++;
|
|
138
|
-
|
|
139
|
+
this.synchronizer.addAccount(address, this.keyStore, this.config.l2StartingBlock);
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
if (count > 0) {
|
|
@@ -194,7 +195,7 @@ export class PXEService implements PXE {
|
|
|
194
195
|
this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
|
|
195
196
|
return accountCompleteAddress;
|
|
196
197
|
} else {
|
|
197
|
-
|
|
198
|
+
this.synchronizer.addAccount(accountCompleteAddress, this.keyStore, this.config.l2StartingBlock);
|
|
198
199
|
this.log.info(`Registered account ${accountCompleteAddress.address.toString()}`);
|
|
199
200
|
this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
|
|
200
201
|
}
|
|
@@ -858,6 +859,7 @@ export class PXEService implements PXE {
|
|
|
858
859
|
from: number,
|
|
859
860
|
limit: number,
|
|
860
861
|
eventMetadata: EventMetadata<T>,
|
|
862
|
+
// TODO (#9272): Make this better, we should be able to only pass an address now
|
|
861
863
|
vpks: Point[],
|
|
862
864
|
): Promise<T[]> {
|
|
863
865
|
if (vpks.length === 0) {
|
|
@@ -871,7 +873,24 @@ export class PXEService implements PXE {
|
|
|
871
873
|
|
|
872
874
|
const encryptedLogs = encryptedTxLogs.flatMap(encryptedTxLog => encryptedTxLog.unrollLogs());
|
|
873
875
|
|
|
874
|
-
const vsks = await Promise.all(
|
|
876
|
+
const vsks = await Promise.all(
|
|
877
|
+
vpks.map(async vpk => {
|
|
878
|
+
const [keyPrefix, account] = this.keyStore.getKeyPrefixAndAccount(vpk);
|
|
879
|
+
let secretKey = await this.keyStore.getMasterSecretKey(vpk);
|
|
880
|
+
if (keyPrefix === 'iv') {
|
|
881
|
+
const registeredAccount = await this.getRegisteredAccount(account);
|
|
882
|
+
if (!registeredAccount) {
|
|
883
|
+
throw new Error('No registered account');
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
const preaddress = registeredAccount.getPreaddress();
|
|
887
|
+
|
|
888
|
+
secretKey = computeAddressSecret(preaddress, secretKey);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
return secretKey;
|
|
892
|
+
}),
|
|
893
|
+
);
|
|
875
894
|
|
|
876
895
|
const visibleEvents = encryptedLogs.flatMap(encryptedLog => {
|
|
877
896
|
for (const sk of vsks) {
|
|
@@ -14,10 +14,13 @@ import {
|
|
|
14
14
|
type Fr,
|
|
15
15
|
type FunctionSelector,
|
|
16
16
|
type Header,
|
|
17
|
+
IndexedTaggingSecret,
|
|
17
18
|
type KeyValidationRequest,
|
|
18
19
|
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
20
|
+
computeTaggingSecret,
|
|
19
21
|
} from '@aztec/circuits.js';
|
|
20
22
|
import { type FunctionArtifact, getFunctionArtifact } from '@aztec/foundation/abi';
|
|
23
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto';
|
|
21
24
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
22
25
|
import { type KeyStore } from '@aztec/key-store';
|
|
23
26
|
import { type DBOracle, MessageLoadOracleInputs } from '@aztec/simulator';
|
|
@@ -226,4 +229,52 @@ export class SimulatorOracle implements DBOracle {
|
|
|
226
229
|
public getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string> {
|
|
227
230
|
return this.contractDataOracle.getDebugFunctionName(contractAddress, selector);
|
|
228
231
|
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Returns the tagging secret for a given sender and recipient pair. For this to work, the ivpsk_m of the sender must be known.
|
|
235
|
+
* Includes the last known index used for tagging with this secret.
|
|
236
|
+
* @param contractAddress - The contract address to silo the secret for
|
|
237
|
+
* @param sender - The address sending the note
|
|
238
|
+
* @param recipient - The address receiving the note
|
|
239
|
+
* @returns A siloed tagging secret that can be used to tag notes.
|
|
240
|
+
*/
|
|
241
|
+
public async getAppTaggingSecret(
|
|
242
|
+
contractAddress: AztecAddress,
|
|
243
|
+
sender: AztecAddress,
|
|
244
|
+
recipient: AztecAddress,
|
|
245
|
+
): Promise<IndexedTaggingSecret> {
|
|
246
|
+
const senderCompleteAddress = await this.getCompleteAddress(sender);
|
|
247
|
+
const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);
|
|
248
|
+
const sharedSecret = computeTaggingSecret(senderCompleteAddress, senderIvsk, recipient);
|
|
249
|
+
// Silo the secret to the app so it can't be used to track other app's notes
|
|
250
|
+
const secret = poseidon2Hash([sharedSecret.x, sharedSecret.y, contractAddress]);
|
|
251
|
+
const [index] = await this.db.getTaggingSecretsIndexes([secret]);
|
|
252
|
+
return new IndexedTaggingSecret(secret, index);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Returns the siloed tagging secrets for a given recipient and all the senders in the address book
|
|
257
|
+
* @param contractAddress - The contract address to silo the secret for
|
|
258
|
+
* @param recipient - The address receiving the notes
|
|
259
|
+
* @returns A list of siloed tagging secrets
|
|
260
|
+
*/
|
|
261
|
+
public async getAppTaggingSecretsForSenders(
|
|
262
|
+
contractAddress: AztecAddress,
|
|
263
|
+
recipient: AztecAddress,
|
|
264
|
+
): Promise<IndexedTaggingSecret[]> {
|
|
265
|
+
const recipientCompleteAddress = await this.getCompleteAddress(recipient);
|
|
266
|
+
const completeAddresses = await this.db.getCompleteAddresses();
|
|
267
|
+
// Filter out the addresses corresponding to accounts
|
|
268
|
+
const accounts = await this.keyStore.getAccounts();
|
|
269
|
+
const senders = completeAddresses.filter(
|
|
270
|
+
completeAddress => !accounts.find(account => account.equals(completeAddress.address)),
|
|
271
|
+
);
|
|
272
|
+
const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
|
|
273
|
+
const secrets = senders.map(({ address: sender }) => {
|
|
274
|
+
const sharedSecret = computeTaggingSecret(recipientCompleteAddress, recipientIvsk, sender);
|
|
275
|
+
return poseidon2Hash([sharedSecret.x, sharedSecret.y, contractAddress]);
|
|
276
|
+
});
|
|
277
|
+
const indexes = await this.db.getTaggingSecretsIndexes(secrets);
|
|
278
|
+
return secrets.map((secret, i) => new IndexedTaggingSecret(secret, indexes[i]));
|
|
279
|
+
}
|
|
229
280
|
}
|
|
@@ -249,14 +249,14 @@ export class Synchronizer {
|
|
|
249
249
|
* @param startingBlock - The block where to start scanning for notes for this accounts.
|
|
250
250
|
* @returns A promise that resolves once the account is added to the Synchronizer.
|
|
251
251
|
*/
|
|
252
|
-
public
|
|
252
|
+
public addAccount(account: CompleteAddress, keyStore: KeyStore, startingBlock: number) {
|
|
253
253
|
const predicate = (x: NoteProcessor) => x.account.equals(account);
|
|
254
254
|
const processor = this.noteProcessors.find(predicate) ?? this.noteProcessorsToCatchUp.find(predicate);
|
|
255
255
|
if (processor) {
|
|
256
256
|
return;
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
this.noteProcessorsToCatchUp.push(
|
|
259
|
+
this.noteProcessorsToCatchUp.push(NoteProcessor.create(account, keyStore, this.db, this.node, startingBlock));
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
/**
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { L1NotePayload } from '@aztec/circuit-types';
|
|
2
|
-
import { type Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { type PxeDatabase } from '../../database/pxe_database.js';
|
|
4
|
-
/**
|
|
5
|
-
* Inserts publicly delivered nullable fields into the note payload.
|
|
6
|
-
* @param db - PXE database used to fetch contract instance and artifact.
|
|
7
|
-
* @param payload - Note payload to which nullable fields should be added.
|
|
8
|
-
* @param nullableFields - List of nullable fields to be added to the note payload.
|
|
9
|
-
* @returns Note payload with nullable fields added.
|
|
10
|
-
*/
|
|
11
|
-
export declare function addNullableFieldsToPayload(db: PxeDatabase, payload: L1NotePayload, nullableFields: Fr[]): Promise<L1NotePayload>;
|
|
12
|
-
//# sourceMappingURL=add_nullable_field_to_payload.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add_nullable_field_to_payload.d.ts","sourceRoot":"","sources":["../../../src/note_processor/utils/add_nullable_field_to_payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAQ,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAElE;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,EAAE,EAAE,WAAW,EACf,OAAO,EAAE,aAAa,EACtB,cAAc,EAAE,EAAE,EAAE,GACnB,OAAO,CAAC,aAAa,CAAC,CAiDxB"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { L1NotePayload, Note } from '@aztec/circuit-types';
|
|
2
|
-
import { ContractNotFoundError } from '@aztec/simulator';
|
|
3
|
-
/**
|
|
4
|
-
* Inserts publicly delivered nullable fields into the note payload.
|
|
5
|
-
* @param db - PXE database used to fetch contract instance and artifact.
|
|
6
|
-
* @param payload - Note payload to which nullable fields should be added.
|
|
7
|
-
* @param nullableFields - List of nullable fields to be added to the note payload.
|
|
8
|
-
* @returns Note payload with nullable fields added.
|
|
9
|
-
*/
|
|
10
|
-
export async function addNullableFieldsToPayload(db, payload, nullableFields) {
|
|
11
|
-
const instance = await db.getContractInstance(payload.contractAddress);
|
|
12
|
-
if (!instance) {
|
|
13
|
-
throw new ContractNotFoundError(`Could not find instance for ${payload.contractAddress.toString()}. This should never happen here as the partial notes flow should be triggered only for non-deferred notes.`);
|
|
14
|
-
}
|
|
15
|
-
const artifact = await db.getContractArtifact(instance.contractClassId);
|
|
16
|
-
if (!artifact) {
|
|
17
|
-
throw new Error(`Could not find artifact for contract class ${instance.contractClassId.toString()}. This should never happen here as the partial notes flow should be triggered only for non-deferred notes.`);
|
|
18
|
-
}
|
|
19
|
-
const noteFields = Object.values(artifact.notes).find(note => note.id.equals(payload.noteTypeId))?.fields;
|
|
20
|
-
if (!noteFields) {
|
|
21
|
-
throw new Error(`Could not find note fields for note type ${payload.noteTypeId.toString()}.`);
|
|
22
|
-
}
|
|
23
|
-
// We sort note fields by index so that we can iterate over them in order.
|
|
24
|
-
noteFields.sort((a, b) => a.index - b.index);
|
|
25
|
-
// Now we insert the nullable fields into the note based on its indices defined in the ABI.
|
|
26
|
-
const modifiedNoteItems = [...payload.note.items];
|
|
27
|
-
let indexInNullable = 0;
|
|
28
|
-
for (let i = 0; i < noteFields.length; i++) {
|
|
29
|
-
const noteField = noteFields[i];
|
|
30
|
-
if (noteField.nullable) {
|
|
31
|
-
if (i == noteFields.length - 1) {
|
|
32
|
-
// We are processing the last field so we simply insert the rest of the nullable fields at the end
|
|
33
|
-
modifiedNoteItems.push(...nullableFields.slice(indexInNullable));
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
const noteFieldLength = noteFields[i + 1].index - noteField.index;
|
|
37
|
-
const nullableFieldsToInsert = nullableFields.slice(indexInNullable, indexInNullable + noteFieldLength);
|
|
38
|
-
indexInNullable += noteFieldLength;
|
|
39
|
-
// Now we insert the nullable fields at the note field index
|
|
40
|
-
modifiedNoteItems.splice(noteField.index, 0, ...nullableFieldsToInsert);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return new L1NotePayload(new Note(modifiedNoteItems), payload.contractAddress, payload.storageSlot, payload.noteTypeId);
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkX251bGxhYmxlX2ZpZWxkX3RvX3BheWxvYWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbm90ZV9wcm9jZXNzb3IvdXRpbHMvYWRkX251bGxhYmxlX2ZpZWxkX3RvX3BheWxvYWQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGFBQWEsRUFBRSxJQUFJLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUUzRCxPQUFPLEVBQUUscUJBQXFCLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUl6RDs7Ozs7O0dBTUc7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLDBCQ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MsQ0FBQztZQUMxRSxDQUFDO1FBQ0gsQ0FBQztJQUNILENBQUM7SUFFRCxPQUFPLElBQUksYUFBYSxDQUN0QixJQUFJLElBQUksQ0FBQyxpQkFBaUIsQ0FBQyxFQUMzQixPQUFPLENBQUMsZUFBZSxFQUN2QixPQUFPLENBQUMsV0FBVyxFQUNuQixPQUFPLENBQUMsVUFBVSxDQUNuQixDQUFDO0FBQ0osQ0FBQyJ9
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { L1NotePayload, Note } from '@aztec/circuit-types';
|
|
2
|
-
import { type Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { ContractNotFoundError } from '@aztec/simulator';
|
|
4
|
-
|
|
5
|
-
import { type PxeDatabase } from '../../database/pxe_database.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Inserts publicly delivered nullable fields into the note payload.
|
|
9
|
-
* @param db - PXE database used to fetch contract instance and artifact.
|
|
10
|
-
* @param payload - Note payload to which nullable fields should be added.
|
|
11
|
-
* @param nullableFields - List of nullable fields to be added to the note payload.
|
|
12
|
-
* @returns Note payload with nullable fields added.
|
|
13
|
-
*/
|
|
14
|
-
export async function addNullableFieldsToPayload(
|
|
15
|
-
db: PxeDatabase,
|
|
16
|
-
payload: L1NotePayload,
|
|
17
|
-
nullableFields: Fr[],
|
|
18
|
-
): Promise<L1NotePayload> {
|
|
19
|
-
const instance = await db.getContractInstance(payload.contractAddress);
|
|
20
|
-
if (!instance) {
|
|
21
|
-
throw new ContractNotFoundError(
|
|
22
|
-
`Could not find instance for ${payload.contractAddress.toString()}. This should never happen here as the partial notes flow should be triggered only for non-deferred notes.`,
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const artifact = await db.getContractArtifact(instance.contractClassId);
|
|
27
|
-
if (!artifact) {
|
|
28
|
-
throw new Error(
|
|
29
|
-
`Could not find artifact for contract class ${instance.contractClassId.toString()}. This should never happen here as the partial notes flow should be triggered only for non-deferred notes.`,
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const noteFields = Object.values(artifact.notes).find(note => note.id.equals(payload.noteTypeId))?.fields;
|
|
34
|
-
|
|
35
|
-
if (!noteFields) {
|
|
36
|
-
throw new Error(`Could not find note fields for note type ${payload.noteTypeId.toString()}.`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// We sort note fields by index so that we can iterate over them in order.
|
|
40
|
-
noteFields.sort((a, b) => a.index - b.index);
|
|
41
|
-
|
|
42
|
-
// Now we insert the nullable fields into the note based on its indices defined in the ABI.
|
|
43
|
-
const modifiedNoteItems = [...payload.note.items];
|
|
44
|
-
let indexInNullable = 0;
|
|
45
|
-
for (let i = 0; i < noteFields.length; i++) {
|
|
46
|
-
const noteField = noteFields[i];
|
|
47
|
-
if (noteField.nullable) {
|
|
48
|
-
if (i == noteFields.length - 1) {
|
|
49
|
-
// We are processing the last field so we simply insert the rest of the nullable fields at the end
|
|
50
|
-
modifiedNoteItems.push(...nullableFields.slice(indexInNullable));
|
|
51
|
-
} else {
|
|
52
|
-
const noteFieldLength = noteFields[i + 1].index - noteField.index;
|
|
53
|
-
const nullableFieldsToInsert = nullableFields.slice(indexInNullable, indexInNullable + noteFieldLength);
|
|
54
|
-
indexInNullable += noteFieldLength;
|
|
55
|
-
// Now we insert the nullable fields at the note field index
|
|
56
|
-
modifiedNoteItems.splice(noteField.index, 0, ...nullableFieldsToInsert);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return new L1NotePayload(
|
|
62
|
-
new Note(modifiedNoteItems),
|
|
63
|
-
payload.contractAddress,
|
|
64
|
-
payload.storageSlot,
|
|
65
|
-
payload.noteTypeId,
|
|
66
|
-
);
|
|
67
|
-
}
|