@aztec/pxe 0.12.0 → 0.13.1
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 +3 -3
- package/dest/contract_data_oracle/index.d.ts +9 -0
- package/dest/contract_data_oracle/index.d.ts.map +1 -1
- package/dest/contract_data_oracle/index.js +13 -1
- package/dest/contract_tree/index.js +2 -2
- package/dest/database/database.d.ts +17 -28
- package/dest/database/database.d.ts.map +1 -1
- package/dest/database/index.d.ts +0 -1
- package/dest/database/index.d.ts.map +1 -1
- package/dest/database/index.js +1 -2
- package/dest/database/memory_db.d.ts +8 -8
- package/dest/database/memory_db.d.ts.map +1 -1
- package/dest/database/memory_db.js +27 -19
- package/dest/database/note_dao.d.ts +61 -0
- package/dest/database/note_dao.d.ts.map +1 -0
- package/dest/database/note_dao.js +83 -0
- package/dest/kernel_oracle/index.js +2 -2
- package/dest/kernel_prover/kernel_prover.d.ts +4 -4
- package/dest/kernel_prover/kernel_prover.js +2 -2
- package/dest/note_processor/note_processor.d.ts +7 -6
- package/dest/note_processor/note_processor.d.ts.map +1 -1
- package/dest/note_processor/note_processor.js +31 -36
- package/dest/pxe_http/pxe_http_server.d.ts.map +1 -1
- package/dest/pxe_http/pxe_http_server.js +4 -3
- package/dest/pxe_service/pxe_service.d.ts +4 -4
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +32 -37
- package/dest/simulator_oracle/index.d.ts +2 -1
- package/dest/simulator_oracle/index.d.ts.map +1 -1
- package/dest/simulator_oracle/index.js +16 -5
- package/package.json +9 -9
- package/src/bin/index.ts +2 -2
- package/src/contract_data_oracle/index.ts +13 -0
- package/src/contract_tree/index.ts +1 -1
- package/src/database/database.ts +17 -28
- package/src/database/index.ts +0 -1
- package/src/database/memory_db.ts +33 -23
- package/src/database/note_dao.ts +90 -0
- package/src/kernel_oracle/index.ts +1 -1
- package/src/kernel_prover/kernel_prover.ts +4 -4
- package/src/note_processor/note_processor.ts +50 -48
- package/src/pxe_http/pxe_http_server.ts +4 -2
- package/src/pxe_service/pxe_service.ts +50 -50
- package/src/simulator_oracle/index.ts +28 -14
- package/dest/database/note_spending_info_dao.d.ts +0 -50
- package/dest/database/note_spending_info_dao.d.ts.map +0 -1
- package/dest/database/note_spending_info_dao.js +0 -24
- package/src/database/note_spending_info_dao.ts +0 -75
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { CircuitsWasm, MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX } from '@aztec/circuits.js';
|
|
1
|
+
import { CircuitsWasm, MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, PublicKey } from '@aztec/circuits.js';
|
|
2
2
|
import { computeCommitmentNonce, siloNullifier } from '@aztec/circuits.js/abis';
|
|
3
3
|
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
6
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
7
|
-
import { AztecNode, KeyStore, L2BlockContext, L2BlockL2Logs
|
|
7
|
+
import { AztecNode, KeyStore, L1NotePayload, L2BlockContext, L2BlockL2Logs } from '@aztec/types';
|
|
8
8
|
import { NoteProcessorStats } from '@aztec/types/stats';
|
|
9
9
|
|
|
10
|
-
import { Database
|
|
10
|
+
import { Database } from '../database/index.js';
|
|
11
|
+
import { NoteDao } from '../database/note_dao.js';
|
|
11
12
|
import { getAcirSimulator } from '../simulator/index.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -19,9 +20,9 @@ interface ProcessedData {
|
|
|
19
20
|
*/
|
|
20
21
|
blockContext: L2BlockContext;
|
|
21
22
|
/**
|
|
22
|
-
*
|
|
23
|
+
* DAOs of processed notes.
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
noteDaos: NoteDao[];
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -92,22 +93,23 @@ export class NoteProcessor {
|
|
|
92
93
|
return;
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
const
|
|
96
|
+
const blocksAndNotes: ProcessedData[] = [];
|
|
96
97
|
const curve = await Grumpkin.new();
|
|
97
98
|
|
|
98
99
|
// Iterate over both blocks and encrypted logs.
|
|
99
100
|
for (let blockIndex = 0; blockIndex < encryptedL2BlockLogs.length; ++blockIndex) {
|
|
100
101
|
this.stats.blocks++;
|
|
101
102
|
const { txLogs } = encryptedL2BlockLogs[blockIndex];
|
|
102
|
-
const
|
|
103
|
+
const blockContext = l2BlockContexts[blockIndex];
|
|
104
|
+
const block = blockContext.block;
|
|
103
105
|
const dataStartIndexForBlock = block.startNoteHashTreeSnapshot.nextAvailableLeafIndex;
|
|
104
106
|
|
|
105
107
|
// We are using set for `userPertainingTxIndices` to avoid duplicates. This would happen in case there were
|
|
106
108
|
// multiple encrypted logs in a tx pertaining to a user.
|
|
107
|
-
const
|
|
109
|
+
const noteDaos: NoteDao[] = [];
|
|
108
110
|
const privateKey = await this.keyStore.getAccountPrivateKey(this.publicKey);
|
|
109
111
|
|
|
110
|
-
// Iterate over all the encrypted logs and try decrypting them. If successful, store the note
|
|
112
|
+
// Iterate over all the encrypted logs and try decrypting them. If successful, store the note.
|
|
111
113
|
for (let indexOfTxInABlock = 0; indexOfTxInABlock < txLogs.length; ++indexOfTxInABlock) {
|
|
112
114
|
this.stats.txs++;
|
|
113
115
|
const dataStartIndexForTx = dataStartIndexForBlock + indexOfTxInABlock * MAX_NEW_COMMITMENTS_PER_TX;
|
|
@@ -126,26 +128,31 @@ export class NoteProcessor {
|
|
|
126
128
|
for (const functionLogs of txFunctionLogs) {
|
|
127
129
|
for (const logs of functionLogs.logs) {
|
|
128
130
|
this.stats.seen++;
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
131
|
+
const payload = L1NotePayload.fromEncryptedBuffer(logs, privateKey, curve);
|
|
132
|
+
if (payload) {
|
|
131
133
|
// We have successfully decrypted the data.
|
|
132
134
|
try {
|
|
133
135
|
const { commitmentIndex, nonce, innerNoteHash, siloedNullifier } = await this.findNoteIndexAndNullifier(
|
|
134
136
|
newCommitments,
|
|
135
137
|
newNullifiers[0],
|
|
136
|
-
|
|
138
|
+
payload,
|
|
137
139
|
excludedIndices,
|
|
138
140
|
);
|
|
139
141
|
const index = BigInt(dataStartIndexForTx + commitmentIndex);
|
|
140
142
|
excludedIndices.add(commitmentIndex);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
noteDaos.push(
|
|
144
|
+
new NoteDao(
|
|
145
|
+
payload.note,
|
|
146
|
+
payload.contractAddress,
|
|
147
|
+
payload.storageSlot,
|
|
148
|
+
blockContext.getTxHash(indexOfTxInABlock),
|
|
149
|
+
nonce,
|
|
150
|
+
innerNoteHash,
|
|
151
|
+
siloedNullifier,
|
|
152
|
+
index,
|
|
153
|
+
this.publicKey,
|
|
154
|
+
),
|
|
155
|
+
);
|
|
149
156
|
this.stats.decrypted++;
|
|
150
157
|
} catch (e) {
|
|
151
158
|
this.stats.failed++;
|
|
@@ -156,13 +163,13 @@ export class NoteProcessor {
|
|
|
156
163
|
}
|
|
157
164
|
}
|
|
158
165
|
|
|
159
|
-
|
|
166
|
+
blocksAndNotes.push({
|
|
160
167
|
blockContext: l2BlockContexts[blockIndex],
|
|
161
|
-
|
|
168
|
+
noteDaos,
|
|
162
169
|
});
|
|
163
170
|
}
|
|
164
171
|
|
|
165
|
-
await this.
|
|
172
|
+
await this.processBlocksAndNotes(blocksAndNotes);
|
|
166
173
|
|
|
167
174
|
this.syncedToBlock = l2BlockContexts[l2BlockContexts.length - 1].block.number;
|
|
168
175
|
this.log(`Synched block ${this.syncedToBlock}`);
|
|
@@ -173,20 +180,20 @@ export class NoteProcessor {
|
|
|
173
180
|
* commitment for the current tx matches this value.
|
|
174
181
|
* Compute the nullifier for a given transaction auxiliary data.
|
|
175
182
|
* The nullifier is calculated using the private key of the account,
|
|
176
|
-
* contract address, and note
|
|
183
|
+
* contract address, and the note associated with the l1NotePayload.
|
|
177
184
|
* This method assists in identifying spent commitments in the private state.
|
|
178
185
|
* @param commitments - Commitments in the tx. One of them should be the note's commitment.
|
|
179
186
|
* @param firstNullifier - First nullifier in the tx.
|
|
180
|
-
* @param
|
|
187
|
+
* @param l1NotePayload - An instance of l1NotePayload containing transaction details.
|
|
181
188
|
* @param excludedIndices - Indices that have been assigned a note in the same tx. Notes in a tx can have the same
|
|
182
|
-
*
|
|
189
|
+
* l1NotePayload. We need to find a different index for each replicate.
|
|
183
190
|
* @returns Information for a decrypted note, including the index of its commitment, nonce, inner note
|
|
184
191
|
* hash, and the siloed nullifier. Throw if cannot find the nonce for the note.
|
|
185
192
|
*/
|
|
186
193
|
private async findNoteIndexAndNullifier(
|
|
187
194
|
commitments: Fr[],
|
|
188
195
|
firstNullifier: Fr,
|
|
189
|
-
{ contractAddress, storageSlot,
|
|
196
|
+
{ contractAddress, storageSlot, note }: L1NotePayload,
|
|
190
197
|
excludedIndices: Set<number>,
|
|
191
198
|
) {
|
|
192
199
|
const wasm = await CircuitsWasm.get();
|
|
@@ -204,12 +211,7 @@ export class NoteProcessor {
|
|
|
204
211
|
|
|
205
212
|
const expectedNonce = computeCommitmentNonce(wasm, firstNullifier, commitmentIndex);
|
|
206
213
|
({ innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier } =
|
|
207
|
-
await this.simulator.computeNoteHashAndNullifier(
|
|
208
|
-
contractAddress,
|
|
209
|
-
expectedNonce,
|
|
210
|
-
storageSlot,
|
|
211
|
-
notePreimage.items,
|
|
212
|
-
));
|
|
214
|
+
await this.simulator.computeNoteHashAndNullifier(contractAddress, expectedNonce, storageSlot, note));
|
|
213
215
|
if (commitment.equals(uniqueSiloedNoteHash)) {
|
|
214
216
|
nonce = expectedNonce;
|
|
215
217
|
break;
|
|
@@ -253,28 +255,28 @@ https://github.com/AztecProtocol/aztec-packages/issues/1641`;
|
|
|
253
255
|
* transaction auxiliary data from the database. This function keeps track of new nullifiers
|
|
254
256
|
* and ensures all other transactions are updated with newly settled block information.
|
|
255
257
|
*
|
|
256
|
-
* @param
|
|
258
|
+
* @param blocksAndNotes - Array of objects containing L2BlockContexts, user-pertaining transaction indices, and NoteDaos.
|
|
257
259
|
*/
|
|
258
|
-
private async
|
|
259
|
-
const
|
|
260
|
-
if (
|
|
261
|
-
await this.db.
|
|
262
|
-
|
|
260
|
+
private async processBlocksAndNotes(blocksAndNotes: ProcessedData[]) {
|
|
261
|
+
const noteDaos = blocksAndNotes.flatMap(b => b.noteDaos);
|
|
262
|
+
if (noteDaos.length) {
|
|
263
|
+
await this.db.addNotes(noteDaos);
|
|
264
|
+
noteDaos.forEach(noteDao => {
|
|
263
265
|
this.log(
|
|
264
|
-
`Added note
|
|
265
|
-
|
|
266
|
-
} with nullifier ${
|
|
266
|
+
`Added note for contract ${noteDao.contractAddress} at slot ${
|
|
267
|
+
noteDao.storageSlot
|
|
268
|
+
} with nullifier ${noteDao.siloedNullifier.toString()}`,
|
|
267
269
|
);
|
|
268
270
|
});
|
|
269
271
|
}
|
|
270
272
|
|
|
271
|
-
const newNullifiers: Fr[] =
|
|
272
|
-
const
|
|
273
|
-
|
|
273
|
+
const newNullifiers: Fr[] = blocksAndNotes.flatMap(b => b.blockContext.block.newNullifiers);
|
|
274
|
+
const removedNotes = await this.db.removeNullifiedNotes(newNullifiers, this.publicKey);
|
|
275
|
+
removedNotes.forEach(noteDao => {
|
|
274
276
|
this.log(
|
|
275
|
-
`Removed note
|
|
276
|
-
|
|
277
|
-
} with nullifier ${
|
|
277
|
+
`Removed note for contract ${noteDao.contractAddress} at slot ${
|
|
278
|
+
noteDao.storageSlot
|
|
279
|
+
} with nullifier ${noteDao.siloedNullifier.toString()}`,
|
|
278
280
|
);
|
|
279
281
|
});
|
|
280
282
|
}
|
|
@@ -7,12 +7,13 @@ import {
|
|
|
7
7
|
CompleteAddress,
|
|
8
8
|
ContractData,
|
|
9
9
|
ExtendedContractData,
|
|
10
|
+
ExtendedNote,
|
|
10
11
|
ExtendedUnencryptedL2Log,
|
|
11
12
|
L2Block,
|
|
12
13
|
L2BlockL2Logs,
|
|
13
14
|
L2Tx,
|
|
14
15
|
LogId,
|
|
15
|
-
|
|
16
|
+
Note,
|
|
16
17
|
PXE,
|
|
17
18
|
Tx,
|
|
18
19
|
TxExecutionRequest,
|
|
@@ -47,7 +48,8 @@ export function createPXERpcServer(pxeService: PXE): JsonRpcServer {
|
|
|
47
48
|
Point,
|
|
48
49
|
Fr,
|
|
49
50
|
GrumpkinScalar,
|
|
50
|
-
|
|
51
|
+
Note,
|
|
52
|
+
ExtendedNote,
|
|
51
53
|
AuthWitness,
|
|
52
54
|
L2Block,
|
|
53
55
|
L2Tx,
|
|
@@ -22,7 +22,7 @@ import { encodeArguments } from '@aztec/foundation/abi';
|
|
|
22
22
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
23
23
|
import { Fr } from '@aztec/foundation/fields';
|
|
24
24
|
import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
25
|
-
import NoirVersion from '@aztec/noir-compiler/noir-version';
|
|
25
|
+
import { NoirVersion } from '@aztec/noir-compiler/noir-version';
|
|
26
26
|
import {
|
|
27
27
|
AuthWitness,
|
|
28
28
|
AztecNode,
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
ContractData,
|
|
31
31
|
DeployedContract,
|
|
32
32
|
ExtendedContractData,
|
|
33
|
+
ExtendedNote,
|
|
33
34
|
FunctionCall,
|
|
34
35
|
GetUnencryptedLogsResponse,
|
|
35
36
|
KeyStore,
|
|
@@ -38,7 +39,7 @@ import {
|
|
|
38
39
|
LogFilter,
|
|
39
40
|
MerkleTreeId,
|
|
40
41
|
NodeInfo,
|
|
41
|
-
|
|
42
|
+
NoteFilter,
|
|
42
43
|
PXE,
|
|
43
44
|
SimulationError,
|
|
44
45
|
Tx,
|
|
@@ -55,6 +56,7 @@ import {
|
|
|
55
56
|
import { PXEServiceConfig, getPackageInfo } from '../config/index.js';
|
|
56
57
|
import { ContractDataOracle } from '../contract_data_oracle/index.js';
|
|
57
58
|
import { Database } from '../database/index.js';
|
|
59
|
+
import { NoteDao } from '../database/note_dao.js';
|
|
58
60
|
import { KernelOracle } from '../kernel_oracle/index.js';
|
|
59
61
|
import { KernelProver } from '../kernel_prover/kernel_prover.js';
|
|
60
62
|
import { getAcirSimulator } from '../simulator/index.js';
|
|
@@ -192,40 +194,40 @@ export class PXEService implements PXE {
|
|
|
192
194
|
return await this.node.getPublicStorageAt(contract, storageSlot.value);
|
|
193
195
|
}
|
|
194
196
|
|
|
195
|
-
public async
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
197
|
+
public async getNotes(filter: NoteFilter): Promise<ExtendedNote[]> {
|
|
198
|
+
const noteDaos = await this.db.getNotes(filter);
|
|
199
|
+
|
|
200
|
+
// TODO(benesjan): Refactor --> This type conversion is ugly but I decided to keep it this way for now because
|
|
201
|
+
// key derivation will affect all this
|
|
202
|
+
const extendedNotes = noteDaos.map(async dao => {
|
|
203
|
+
let owner = filter.owner;
|
|
204
|
+
if (owner === undefined) {
|
|
205
|
+
const completeAddresses = (await this.db.getCompleteAddresses()).find(address =>
|
|
206
|
+
address.publicKey.equals(dao.publicKey),
|
|
207
|
+
);
|
|
208
|
+
if (completeAddresses === undefined) {
|
|
209
|
+
throw new Error(`Cannot find complete address for public key ${dao.publicKey.toString()}`);
|
|
210
|
+
}
|
|
211
|
+
owner = completeAddresses.address;
|
|
212
|
+
}
|
|
213
|
+
return new ExtendedNote(dao.note, owner, dao.contractAddress, dao.storageSlot, dao.txHash);
|
|
214
|
+
});
|
|
215
|
+
return Promise.all(extendedNotes);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
public async addNote(note: ExtendedNote) {
|
|
219
|
+
const { publicKey } = (await this.db.getCompleteAddress(note.owner)) ?? {};
|
|
216
220
|
if (!publicKey) {
|
|
217
221
|
throw new Error('Unknown account.');
|
|
218
222
|
}
|
|
219
223
|
|
|
224
|
+
const [nonce] = await this.getNoteNonces(note);
|
|
220
225
|
if (!nonce) {
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
if (!nonce) {
|
|
224
|
-
throw new Error(`Cannot find the note in tx: ${txHash}.`);
|
|
226
|
+
throw new Error(`Cannot find the note in tx: ${note.txHash}.`);
|
|
225
227
|
}
|
|
226
228
|
|
|
227
229
|
const { innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier } =
|
|
228
|
-
await this.simulator.computeNoteHashAndNullifier(contractAddress, nonce, storageSlot,
|
|
230
|
+
await this.simulator.computeNoteHashAndNullifier(note.contractAddress, nonce, note.storageSlot, note.note);
|
|
229
231
|
|
|
230
232
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386)
|
|
231
233
|
// This can always be `uniqueSiloedNoteHash` once notes added from public also include nonces.
|
|
@@ -236,33 +238,31 @@ export class PXEService implements PXE {
|
|
|
236
238
|
}
|
|
237
239
|
|
|
238
240
|
const wasm = await CircuitsWasm.get();
|
|
239
|
-
const siloedNullifier = siloNullifier(wasm, contractAddress, innerNullifier!);
|
|
241
|
+
const siloedNullifier = siloNullifier(wasm, note.contractAddress, innerNullifier!);
|
|
240
242
|
const nullifierIndex = await this.node.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, siloedNullifier.toBuffer());
|
|
241
243
|
if (nullifierIndex !== undefined) {
|
|
242
244
|
throw new Error('The note has been destroyed.');
|
|
243
245
|
}
|
|
244
246
|
|
|
245
|
-
await this.db.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
247
|
+
await this.db.addNote(
|
|
248
|
+
new NoteDao(
|
|
249
|
+
note.note,
|
|
250
|
+
note.contractAddress,
|
|
251
|
+
note.storageSlot,
|
|
252
|
+
note.txHash,
|
|
253
|
+
nonce,
|
|
254
|
+
innerNoteHash,
|
|
255
|
+
siloedNullifier,
|
|
256
|
+
index,
|
|
257
|
+
publicKey,
|
|
258
|
+
),
|
|
259
|
+
);
|
|
255
260
|
}
|
|
256
261
|
|
|
257
|
-
public async getNoteNonces(
|
|
258
|
-
|
|
259
|
-
storageSlot: Fr,
|
|
260
|
-
preimage: NotePreimage,
|
|
261
|
-
txHash: TxHash,
|
|
262
|
-
): Promise<Fr[]> {
|
|
263
|
-
const tx = await this.node.getTx(txHash);
|
|
262
|
+
public async getNoteNonces(note: ExtendedNote): Promise<Fr[]> {
|
|
263
|
+
const tx = await this.node.getTx(note.txHash);
|
|
264
264
|
if (!tx) {
|
|
265
|
-
throw new Error(`Unknown tx: ${txHash}`);
|
|
265
|
+
throw new Error(`Unknown tx: ${note.txHash}`);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
const wasm = await CircuitsWasm.get();
|
|
@@ -276,10 +276,10 @@ export class PXEService implements PXE {
|
|
|
276
276
|
|
|
277
277
|
const nonce = computeCommitmentNonce(wasm, firstNullifier, i);
|
|
278
278
|
const { siloedNoteHash, uniqueSiloedNoteHash } = await this.simulator.computeNoteHashAndNullifier(
|
|
279
|
-
contractAddress,
|
|
279
|
+
note.contractAddress,
|
|
280
280
|
nonce,
|
|
281
|
-
storageSlot,
|
|
282
|
-
|
|
281
|
+
note.storageSlot,
|
|
282
|
+
note.note,
|
|
283
283
|
);
|
|
284
284
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386)
|
|
285
285
|
// Remove this once notes added from public also include nonces.
|
|
@@ -45,19 +45,17 @@ export class SimulatorOracle implements DBOracle {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
async getNotes(contractAddress: AztecAddress, storageSlot: Fr) {
|
|
48
|
-
const noteDaos = await this.db.
|
|
49
|
-
return noteDaos.map(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}),
|
|
60
|
-
);
|
|
48
|
+
const noteDaos = await this.db.getNotes({ contractAddress, storageSlot });
|
|
49
|
+
return noteDaos.map(({ contractAddress, storageSlot, nonce, note, innerNoteHash, siloedNullifier, index }) => ({
|
|
50
|
+
contractAddress,
|
|
51
|
+
storageSlot,
|
|
52
|
+
nonce,
|
|
53
|
+
note,
|
|
54
|
+
innerNoteHash,
|
|
55
|
+
siloedNullifier,
|
|
56
|
+
// PXE can use this index to get full MembershipWitness
|
|
57
|
+
index,
|
|
58
|
+
}));
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
async getFunctionArtifact(
|
|
@@ -72,6 +70,22 @@ export class SimulatorOracle implements DBOracle {
|
|
|
72
70
|
};
|
|
73
71
|
}
|
|
74
72
|
|
|
73
|
+
async getFunctionArtifactByName(
|
|
74
|
+
contractAddress: AztecAddress,
|
|
75
|
+
functionName: string,
|
|
76
|
+
): Promise<FunctionArtifactWithDebugMetadata | undefined> {
|
|
77
|
+
const artifact = await this.contractDataOracle.getFunctionArtifactByName(contractAddress, functionName);
|
|
78
|
+
if (!artifact) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const debug = await this.contractDataOracle.getFunctionDebugMetadata(contractAddress, artifact.selector);
|
|
83
|
+
return {
|
|
84
|
+
...artifact,
|
|
85
|
+
debug,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
75
89
|
async getPortalContractAddress(contractAddress: AztecAddress): Promise<EthAddress> {
|
|
76
90
|
return await this.contractDataOracle.getPortalContractAddress(contractAddress);
|
|
77
91
|
}
|
|
@@ -88,7 +102,7 @@ export class SimulatorOracle implements DBOracle {
|
|
|
88
102
|
const messageAndIndex = await this.stateInfoProvider.getL1ToL2MessageAndIndex(msgKey);
|
|
89
103
|
const message = messageAndIndex.message.toFieldArray();
|
|
90
104
|
const index = messageAndIndex.index;
|
|
91
|
-
const siblingPath = await this.stateInfoProvider.
|
|
105
|
+
const siblingPath = await this.stateInfoProvider.getL1ToL2MessageSiblingPath(index);
|
|
92
106
|
return {
|
|
93
107
|
message,
|
|
94
108
|
siblingPath: siblingPath.toFieldArray(),
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, Fr, PublicKey } from '@aztec/circuits.js';
|
|
2
|
-
import { NotePreimage } from '@aztec/types';
|
|
3
|
-
/**
|
|
4
|
-
* Represents the data access object for auxiliary transaction data.
|
|
5
|
-
* Contains properties from the decrypted note, computed properties, and information about
|
|
6
|
-
* the public key used for encryption, as well as the location of the data in the tree.
|
|
7
|
-
*/
|
|
8
|
-
export interface NoteSpendingInfoDao {
|
|
9
|
-
/**
|
|
10
|
-
* The contract address this note is created in.
|
|
11
|
-
*/
|
|
12
|
-
contractAddress: AztecAddress;
|
|
13
|
-
/**
|
|
14
|
-
* The nonce of the note.
|
|
15
|
-
*/
|
|
16
|
-
nonce: Fr;
|
|
17
|
-
/**
|
|
18
|
-
* The specific storage location of the note on the contract.
|
|
19
|
-
*/
|
|
20
|
-
storageSlot: Fr;
|
|
21
|
-
/**
|
|
22
|
-
* The preimage of the note, containing essential information about the note.
|
|
23
|
-
*/
|
|
24
|
-
notePreimage: NotePreimage;
|
|
25
|
-
/**
|
|
26
|
-
* Inner note hash of the note. This is customizable by the app circuit.
|
|
27
|
-
* We can use this value to compute siloedNoteHash and uniqueSiloedNoteHash.
|
|
28
|
-
*/
|
|
29
|
-
innerNoteHash: Fr;
|
|
30
|
-
/**
|
|
31
|
-
* The nullifier of the note (siloed by contract address).
|
|
32
|
-
*/
|
|
33
|
-
siloedNullifier: Fr;
|
|
34
|
-
/**
|
|
35
|
-
* The location of the relevant note in the note hash tree.
|
|
36
|
-
*/
|
|
37
|
-
index: bigint;
|
|
38
|
-
/**
|
|
39
|
-
* The public key that was used to encrypt the data.
|
|
40
|
-
*/
|
|
41
|
-
publicKey: PublicKey;
|
|
42
|
-
}
|
|
43
|
-
export declare const createRandomNoteSpendingInfoDao: ({ contractAddress, nonce, storageSlot, notePreimage, innerNoteHash, siloedNullifier, index, publicKey, }?: Partial<NoteSpendingInfoDao>) => NoteSpendingInfoDao;
|
|
44
|
-
/**
|
|
45
|
-
* Returns the size in bytes of a note spending info dao.
|
|
46
|
-
* @param note - The note.
|
|
47
|
-
* @returns - Its size in bytes.
|
|
48
|
-
*/
|
|
49
|
-
export declare function getNoteSpendingInfoDaoSize(note: NoteSpendingInfoDao): number;
|
|
50
|
-
//# sourceMappingURL=note_spending_info_dao.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"note_spending_info_dao.d.ts","sourceRoot":"","sources":["../../src/database/note_spending_info_dao.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,eAAe,EAAE,YAAY,CAAC;IAC9B;;OAEG;IACH,KAAK,EAAE,EAAE,CAAC;IACV;;OAEG;IACH,WAAW,EAAE,EAAE,CAAC;IAChB;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B;;;OAGG;IACH,aAAa,EAAE,EAAE,CAAC;IAClB;;OAEG;IACH,eAAe,EAAE,EAAE,CAAC;IACpB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,eAAO,MAAM,+BAA+B,8GASzC,QAAQ,mBAAmB,CAAC,KAAQ,mBASrC,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,mBAAmB,UAInE"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, Fr } from '@aztec/circuits.js';
|
|
2
|
-
import { Point } from '@aztec/foundation/fields';
|
|
3
|
-
import { NotePreimage } from '@aztec/types';
|
|
4
|
-
export const createRandomNoteSpendingInfoDao = ({ contractAddress = AztecAddress.random(), nonce = Fr.random(), storageSlot = Fr.random(), notePreimage = NotePreimage.random(), innerNoteHash = Fr.random(), siloedNullifier = Fr.random(), index = Fr.random().value, publicKey = Point.random(), } = {}) => ({
|
|
5
|
-
contractAddress,
|
|
6
|
-
nonce,
|
|
7
|
-
storageSlot,
|
|
8
|
-
notePreimage,
|
|
9
|
-
innerNoteHash,
|
|
10
|
-
siloedNullifier,
|
|
11
|
-
index,
|
|
12
|
-
publicKey,
|
|
13
|
-
});
|
|
14
|
-
/**
|
|
15
|
-
* Returns the size in bytes of a note spending info dao.
|
|
16
|
-
* @param note - The note.
|
|
17
|
-
* @returns - Its size in bytes.
|
|
18
|
-
*/
|
|
19
|
-
export function getNoteSpendingInfoDaoSize(note) {
|
|
20
|
-
// 7 fields + 1 bigint + 1 buffer size (4 bytes) + 1 buffer
|
|
21
|
-
const indexSize = Math.ceil(Math.log2(Number(note.index)));
|
|
22
|
-
return 7 * Fr.SIZE_IN_BYTES + indexSize + 4 + note.notePreimage.items.length * Fr.SIZE_IN_BYTES;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm90ZV9zcGVuZGluZ19pbmZvX2Rhby5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kYXRhYmFzZS9ub3RlX3NwZW5kaW5nX2luZm9fZGFvLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxZQUFZLEVBQUUsRUFBRSxFQUFhLE1BQU0sb0JBQW9CLENBQUM7QUFDakUsT0FBTyxFQUFFLEtBQUssRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBQ2pELE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxjQUFjLENBQUM7QUEyQzVDLE1BQU0sQ0FBQyxNQUFNLCtCQUErQixHQUFHLENBQUMsRUFDOUMsZUFBZSxHQUFHLFlBQVksQ0FBQyxNQUFNLEVBQUUsRUFDdkMsS0FBSyxHQUFHLEVBQUUsQ0FBQyxNQUFNLEVBQUUsRUFDbkIsV0FBVyxHQUFHLEVBQUUsQ0FBQyxNQUFNLEVBQUUsRUFDekIsWUFBWSxHQUFHLFlBQVksQ0FBQyxNQUFNLEVBQUUsRUFDcEMsYUFBYSxHQUFHLEVBQUUsQ0FBQyxNQUFNLEVBQUUsRUFDM0IsZUFBZSxHQUFHLEVBQUUsQ0FBQyxNQUFNLEVBQUUsRUFDN0IsS0FBSyxHQUFHLEVBQUUsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxLQUFLLEVBQ3pCLFNBQVMsR0FBRyxLQUFLLENBQUMsTUFBTSxFQUFFLE1BQ00sRUFBRSxFQUF1QixFQUFFLENBQUMsQ0FBQztJQUM3RCxlQUFlO0lBQ2YsS0FBSztJQUNMLFdBQVc7SUFDWCxZQUFZO0lBQ1osYUFBYTtJQUNiLGVBQWU7SUFDZixLQUFLO0lBQ0wsU0FBUztDQUNWLENBQUMsQ0FBQztBQUVIOzs7O0dBSUc7QUFDSCxNQUFNLFVBQVUsMEJBQTBCLENBQUMsSUFBeUI7SUFDbEUsMkRBQTJEO0lBQzNELE1BQU0sU0FBUyxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUMzRCxPQUFPLENBQUMsR0FBRyxFQUFFLENBQUMsYUFBYSxHQUFHLFNBQVMsR0FBRyxDQUFDLEdBQUcsSUFBSSxDQUFDLFlBQVksQ0FBQyxLQUFLLENBQUMsTUFBTSxHQUFHLEVBQUUsQ0FBQyxhQUFhLENBQUM7QUFDbEcsQ0FBQyJ9
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, Fr, PublicKey } from '@aztec/circuits.js';
|
|
2
|
-
import { Point } from '@aztec/foundation/fields';
|
|
3
|
-
import { NotePreimage } from '@aztec/types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Represents the data access object for auxiliary transaction data.
|
|
7
|
-
* Contains properties from the decrypted note, computed properties, and information about
|
|
8
|
-
* the public key used for encryption, as well as the location of the data in the tree.
|
|
9
|
-
*/
|
|
10
|
-
export interface NoteSpendingInfoDao {
|
|
11
|
-
/**
|
|
12
|
-
* The contract address this note is created in.
|
|
13
|
-
*/
|
|
14
|
-
contractAddress: AztecAddress;
|
|
15
|
-
/**
|
|
16
|
-
* The nonce of the note.
|
|
17
|
-
*/
|
|
18
|
-
nonce: Fr;
|
|
19
|
-
/**
|
|
20
|
-
* The specific storage location of the note on the contract.
|
|
21
|
-
*/
|
|
22
|
-
storageSlot: Fr;
|
|
23
|
-
/**
|
|
24
|
-
* The preimage of the note, containing essential information about the note.
|
|
25
|
-
*/
|
|
26
|
-
notePreimage: NotePreimage;
|
|
27
|
-
/**
|
|
28
|
-
* Inner note hash of the note. This is customizable by the app circuit.
|
|
29
|
-
* We can use this value to compute siloedNoteHash and uniqueSiloedNoteHash.
|
|
30
|
-
*/
|
|
31
|
-
innerNoteHash: Fr;
|
|
32
|
-
/**
|
|
33
|
-
* The nullifier of the note (siloed by contract address).
|
|
34
|
-
*/
|
|
35
|
-
siloedNullifier: Fr;
|
|
36
|
-
/**
|
|
37
|
-
* The location of the relevant note in the note hash tree.
|
|
38
|
-
*/
|
|
39
|
-
index: bigint;
|
|
40
|
-
/**
|
|
41
|
-
* The public key that was used to encrypt the data.
|
|
42
|
-
*/
|
|
43
|
-
publicKey: PublicKey;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const createRandomNoteSpendingInfoDao = ({
|
|
47
|
-
contractAddress = AztecAddress.random(),
|
|
48
|
-
nonce = Fr.random(),
|
|
49
|
-
storageSlot = Fr.random(),
|
|
50
|
-
notePreimage = NotePreimage.random(),
|
|
51
|
-
innerNoteHash = Fr.random(),
|
|
52
|
-
siloedNullifier = Fr.random(),
|
|
53
|
-
index = Fr.random().value,
|
|
54
|
-
publicKey = Point.random(),
|
|
55
|
-
}: Partial<NoteSpendingInfoDao> = {}): NoteSpendingInfoDao => ({
|
|
56
|
-
contractAddress,
|
|
57
|
-
nonce,
|
|
58
|
-
storageSlot,
|
|
59
|
-
notePreimage,
|
|
60
|
-
innerNoteHash,
|
|
61
|
-
siloedNullifier,
|
|
62
|
-
index,
|
|
63
|
-
publicKey,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Returns the size in bytes of a note spending info dao.
|
|
68
|
-
* @param note - The note.
|
|
69
|
-
* @returns - Its size in bytes.
|
|
70
|
-
*/
|
|
71
|
-
export function getNoteSpendingInfoDaoSize(note: NoteSpendingInfoDao) {
|
|
72
|
-
// 7 fields + 1 bigint + 1 buffer size (4 bytes) + 1 buffer
|
|
73
|
-
const indexSize = Math.ceil(Math.log2(Number(note.index)));
|
|
74
|
-
return 7 * Fr.SIZE_IN_BYTES + indexSize + 4 + note.notePreimage.items.length * Fr.SIZE_IN_BYTES;
|
|
75
|
-
}
|