@aztec/pxe 3.0.0-nightly.20251125 → 3.0.0-nightly.20251127
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/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -2
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +9 -3
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +3 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +3 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +4 -3
- package/dest/contract_function_simulator/oracle/oracle.d.ts +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +2 -2
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +2 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +10 -2
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +2 -1
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -1
- package/dest/contract_function_simulator/pxe_oracle_interface.js +7 -5
- package/dest/pxe.d.ts +3 -2
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +1 -13
- package/dest/storage/note_data_provider/index.d.ts +1 -1
- package/dest/storage/note_data_provider/index.d.ts.map +1 -1
- package/dest/storage/note_data_provider/index.js +1 -1
- package/dest/storage/note_data_provider/note_data_provider.d.ts +1 -1
- package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
- package/dest/storage/note_data_provider/note_data_provider.js +13 -10
- package/package.json +17 -17
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +10 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +10 -1
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +5 -3
- package/src/contract_function_simulator/oracle/oracle.ts +2 -0
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +5 -1
- package/src/contract_function_simulator/pxe_oracle_interface.ts +18 -12
- package/src/pxe.ts +4 -17
- package/src/storage/note_data_provider/index.ts +1 -1
- package/src/storage/note_data_provider/note_data_provider.ts +15 -9
- package/dest/storage/note_data_provider/note_dao.d.ts +0 -100
- package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
- package/dest/storage/note_data_provider/note_dao.js +0 -102
- package/src/storage/note_data_provider/note_dao.ts +0 -154
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/pxe",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.20251127",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": "./dest/entrypoints/server/index.js",
|
|
@@ -61,29 +61,29 @@
|
|
|
61
61
|
]
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@aztec/bb-prover": "3.0.0-nightly.
|
|
65
|
-
"@aztec/bb.js": "3.0.0-nightly.
|
|
66
|
-
"@aztec/builder": "3.0.0-nightly.
|
|
67
|
-
"@aztec/constants": "3.0.0-nightly.
|
|
68
|
-
"@aztec/ethereum": "3.0.0-nightly.
|
|
69
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
70
|
-
"@aztec/key-store": "3.0.0-nightly.
|
|
71
|
-
"@aztec/kv-store": "3.0.0-nightly.
|
|
72
|
-
"@aztec/noir-protocol-circuits-types": "3.0.0-nightly.
|
|
73
|
-
"@aztec/noir-types": "3.0.0-nightly.
|
|
74
|
-
"@aztec/protocol-contracts": "3.0.0-nightly.
|
|
75
|
-
"@aztec/simulator": "3.0.0-nightly.
|
|
76
|
-
"@aztec/stdlib": "3.0.0-nightly.
|
|
64
|
+
"@aztec/bb-prover": "3.0.0-nightly.20251127",
|
|
65
|
+
"@aztec/bb.js": "3.0.0-nightly.20251127",
|
|
66
|
+
"@aztec/builder": "3.0.0-nightly.20251127",
|
|
67
|
+
"@aztec/constants": "3.0.0-nightly.20251127",
|
|
68
|
+
"@aztec/ethereum": "3.0.0-nightly.20251127",
|
|
69
|
+
"@aztec/foundation": "3.0.0-nightly.20251127",
|
|
70
|
+
"@aztec/key-store": "3.0.0-nightly.20251127",
|
|
71
|
+
"@aztec/kv-store": "3.0.0-nightly.20251127",
|
|
72
|
+
"@aztec/noir-protocol-circuits-types": "3.0.0-nightly.20251127",
|
|
73
|
+
"@aztec/noir-types": "3.0.0-nightly.20251127",
|
|
74
|
+
"@aztec/protocol-contracts": "3.0.0-nightly.20251127",
|
|
75
|
+
"@aztec/simulator": "3.0.0-nightly.20251127",
|
|
76
|
+
"@aztec/stdlib": "3.0.0-nightly.20251127",
|
|
77
77
|
"koa": "^2.16.1",
|
|
78
78
|
"koa-router": "^13.1.1",
|
|
79
79
|
"lodash.omit": "^4.5.0",
|
|
80
80
|
"sha3": "^2.1.4",
|
|
81
81
|
"tslib": "^2.4.0",
|
|
82
|
-
"viem": "npm:@
|
|
82
|
+
"viem": "npm:@aztec/viem@2.38.2"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@aztec/merkle-tree": "3.0.0-nightly.
|
|
86
|
-
"@aztec/noir-test-contracts.js": "3.0.0-nightly.
|
|
85
|
+
"@aztec/merkle-tree": "3.0.0-nightly.20251127",
|
|
86
|
+
"@aztec/noir-test-contracts.js": "3.0.0-nightly.20251127",
|
|
87
87
|
"@jest/globals": "^30.0.0",
|
|
88
88
|
"@types/jest": "^30.0.0",
|
|
89
89
|
"@types/lodash.omit": "^4.5.7",
|
|
@@ -4,7 +4,7 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
4
4
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
6
6
|
// TODO(#14617): should we compute this from constants? This value is aztec-nr specific.
|
|
7
|
-
export const MAX_NOTE_PACKED_LEN =
|
|
7
|
+
export const MAX_NOTE_PACKED_LEN = 11;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Intermediate struct used to perform batch note validation by PXE. The `utilityValidateEnqueuedNotesAndEvents` oracle
|
|
@@ -14,6 +14,7 @@ export class NoteValidationRequest {
|
|
|
14
14
|
constructor(
|
|
15
15
|
public contractAddress: AztecAddress,
|
|
16
16
|
public storageSlot: Fr,
|
|
17
|
+
public randomness: Fr,
|
|
17
18
|
public noteNonce: Fr,
|
|
18
19
|
public content: Fr[],
|
|
19
20
|
public noteHash: Fr,
|
|
@@ -27,6 +28,7 @@ export class NoteValidationRequest {
|
|
|
27
28
|
|
|
28
29
|
const contractAddress = AztecAddress.fromField(reader.readField());
|
|
29
30
|
const storageSlot = reader.readField();
|
|
31
|
+
const randomness = reader.readField();
|
|
30
32
|
const noteNonce = reader.readField();
|
|
31
33
|
|
|
32
34
|
const contentStorage = reader.readFieldArray(MAX_NOTE_PACKED_LEN);
|
|
@@ -38,9 +40,16 @@ export class NoteValidationRequest {
|
|
|
38
40
|
const txHash = TxHash.fromField(reader.readField());
|
|
39
41
|
const recipient = AztecAddress.fromField(reader.readField());
|
|
40
42
|
|
|
43
|
+
if (reader.remainingFields() !== 0) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Error converting array of fields to NoteValidationRequest. Hint: check that MAX_NOTE_PACKED_LEN is consistent with private_notes::MAX_NOTE_PACKED_LEN in Aztec-nr.`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
41
49
|
return new NoteValidationRequest(
|
|
42
50
|
contractAddress,
|
|
43
51
|
storageSlot,
|
|
52
|
+
randomness,
|
|
44
53
|
noteNonce,
|
|
45
54
|
content,
|
|
46
55
|
noteHash,
|
|
@@ -23,6 +23,8 @@ export interface NoteData {
|
|
|
23
23
|
contractAddress: AztecAddress;
|
|
24
24
|
/** The storage slot of the note. */
|
|
25
25
|
storageSlot: Fr;
|
|
26
|
+
/** The randomness injected to the note */
|
|
27
|
+
randomness: Fr;
|
|
26
28
|
/** The nonce injected into the note hash preimage by kernels. */
|
|
27
29
|
noteNonce: Fr;
|
|
28
30
|
/** A hash of the note as it gets stored in the note hash tree. */
|
|
@@ -129,7 +131,14 @@ export interface IPrivateExecutionOracle {
|
|
|
129
131
|
|
|
130
132
|
privateStoreInExecutionCache(values: Fr[], hash: Fr): void;
|
|
131
133
|
privateLoadFromExecutionCache(hash: Fr): Promise<Fr[]>;
|
|
132
|
-
privateNotifyCreatedNote(
|
|
134
|
+
privateNotifyCreatedNote(
|
|
135
|
+
storageSlot: Fr,
|
|
136
|
+
randomness: Fr,
|
|
137
|
+
noteTypeId: NoteSelector,
|
|
138
|
+
note: Fr[],
|
|
139
|
+
noteHash: Fr,
|
|
140
|
+
counter: number,
|
|
141
|
+
): void;
|
|
133
142
|
privateNotifyNullifiedNote(innerNullifier: Fr, noteHash: Fr, counter: number): Promise<void>;
|
|
134
143
|
privateNotifyCreatedNullifier(innerNullifier: Fr): Promise<void>;
|
|
135
144
|
privateNotifyCreatedContractClassLog(log: ContractClassLog, counter: number): void;
|
|
@@ -24,6 +24,7 @@ function fromRawData(nonzeroNoteHashCounter: boolean, maybeNoteNonce: Fr): { sta
|
|
|
24
24
|
* and only after that it packs the retrieved note. Hence it doesn't map one to one with `RetrievedNote::pack()`.
|
|
25
25
|
*
|
|
26
26
|
* @param contractAddress - The address of the contract that owns the note
|
|
27
|
+
* @param randomness - The randomness injected into the note to get the hiding property of commitments
|
|
27
28
|
* @param noteNonce - The nonce injected into the note hash preimage by kernels.
|
|
28
29
|
* @param index - Optional index in the note hash tree. If undefined, indicates a transient note
|
|
29
30
|
* @param note - The note content containing the actual note data
|
|
@@ -31,22 +32,23 @@ function fromRawData(nonzeroNoteHashCounter: boolean, maybeNoteNonce: Fr): { sta
|
|
|
31
32
|
*/
|
|
32
33
|
export function packAsRetrievedNote({
|
|
33
34
|
contractAddress,
|
|
35
|
+
randomness,
|
|
34
36
|
noteNonce,
|
|
35
37
|
index,
|
|
36
38
|
note,
|
|
37
39
|
}: {
|
|
38
40
|
contractAddress: AztecAddress;
|
|
41
|
+
randomness: Fr;
|
|
39
42
|
noteNonce: Fr;
|
|
40
43
|
index?: bigint;
|
|
41
44
|
note: Note;
|
|
42
45
|
}) {
|
|
43
46
|
// If index is undefined, the note is transient which implies that the nonzero_note_hash_counter has to be true
|
|
44
|
-
const
|
|
45
|
-
const nonzeroNoteHashCounter = noteIsTransient ? true : false;
|
|
47
|
+
const nonzeroNoteHashCounter = index === undefined;
|
|
46
48
|
|
|
47
49
|
// To pack the note as retrieved note we first need to reconstruct the note metadata.
|
|
48
50
|
const noteMetadata = fromRawData(nonzeroNoteHashCounter, noteNonce);
|
|
49
51
|
|
|
50
52
|
// Pack metadata first (stage and maybe_note_nonce), followed by the rest
|
|
51
|
-
return [...note.items, contractAddress, new Fr(noteMetadata.stage), noteMetadata.maybeNoteNonce];
|
|
53
|
+
return [...note.items, contractAddress, randomness, new Fr(noteMetadata.stage), noteMetadata.maybeNoteNonce];
|
|
52
54
|
}
|
|
@@ -282,6 +282,7 @@ export class Oracle {
|
|
|
282
282
|
|
|
283
283
|
privateNotifyCreatedNote(
|
|
284
284
|
[storageSlot]: ACVMField[],
|
|
285
|
+
[randomness]: ACVMField[],
|
|
285
286
|
[noteTypeId]: ACVMField[],
|
|
286
287
|
note: ACVMField[],
|
|
287
288
|
[noteHash]: ACVMField[],
|
|
@@ -289,6 +290,7 @@ export class Oracle {
|
|
|
289
290
|
): Promise<ACVMField[]> {
|
|
290
291
|
this.handlerAsPrivate().privateNotifyCreatedNote(
|
|
291
292
|
Fr.fromString(storageSlot),
|
|
293
|
+
Fr.fromString(randomness),
|
|
292
294
|
NoteSelector.fromField(Fr.fromString(noteTypeId)),
|
|
293
295
|
note.map(Fr.fromString),
|
|
294
296
|
Fr.fromString(noteHash),
|
|
@@ -367,6 +367,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
367
367
|
* It can be used in subsequent calls (or transactions when chaining txs is possible).
|
|
368
368
|
* @param contractAddress - The contract address.
|
|
369
369
|
* @param storageSlot - The storage slot.
|
|
370
|
+
* @param randomness - The randomness injected into the note.
|
|
370
371
|
* @param noteTypeId - The type ID of the note.
|
|
371
372
|
* @param noteItems - The items to be included in a Note.
|
|
372
373
|
* @param noteHash - A hash of the new note.
|
|
@@ -374,6 +375,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
374
375
|
*/
|
|
375
376
|
public privateNotifyCreatedNote(
|
|
376
377
|
storageSlot: Fr,
|
|
378
|
+
randomness: Fr,
|
|
377
379
|
noteTypeId: NoteSelector,
|
|
378
380
|
noteItems: Fr[],
|
|
379
381
|
noteHash: Fr,
|
|
@@ -382,6 +384,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
382
384
|
this.log.debug(`Notified of new note with inner hash ${noteHash}`, {
|
|
383
385
|
contractAddress: this.callContext.contractAddress,
|
|
384
386
|
storageSlot,
|
|
387
|
+
randomness,
|
|
385
388
|
noteTypeId,
|
|
386
389
|
counter,
|
|
387
390
|
});
|
|
@@ -391,6 +394,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
391
394
|
{
|
|
392
395
|
contractAddress: this.callContext.contractAddress,
|
|
393
396
|
storageSlot,
|
|
397
|
+
randomness,
|
|
394
398
|
noteNonce: Fr.ZERO, // Nonce cannot be known during private execution.
|
|
395
399
|
note,
|
|
396
400
|
siloedNullifier: undefined, // Siloed nullifier cannot be known for newly created note.
|
|
@@ -398,7 +402,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
398
402
|
},
|
|
399
403
|
counter,
|
|
400
404
|
);
|
|
401
|
-
this.newNotes.push(
|
|
405
|
+
this.newNotes.push(NoteAndSlot.from({ note, storageSlot, randomness, noteTypeId }));
|
|
402
406
|
}
|
|
403
407
|
|
|
404
408
|
/**
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
} from '@aztec/stdlib/logs';
|
|
22
22
|
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
23
23
|
import { Note, type NoteStatus } from '@aztec/stdlib/note';
|
|
24
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
24
25
|
import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
25
26
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
26
27
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
@@ -31,7 +32,6 @@ import { ORACLE_VERSION } from '../oracle_version.js';
|
|
|
31
32
|
import type { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
|
|
32
33
|
import type { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
|
|
33
34
|
import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
|
|
34
|
-
import { NoteDao } from '../storage/note_data_provider/note_dao.js';
|
|
35
35
|
import type { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
|
|
36
36
|
import type { PrivateEventDataProvider } from '../storage/private_event_data_provider/private_event_data_provider.js';
|
|
37
37
|
import type { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
|
|
@@ -97,16 +97,19 @@ export class PXEOracleInterface implements ExecutionDataProvider {
|
|
|
97
97
|
status,
|
|
98
98
|
scopes,
|
|
99
99
|
});
|
|
100
|
-
return noteDaos.map(
|
|
101
|
-
contractAddress,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
return noteDaos.map(
|
|
101
|
+
({ contractAddress, storageSlot, randomness, noteNonce, note, noteHash, siloedNullifier, index }) => ({
|
|
102
|
+
contractAddress,
|
|
103
|
+
storageSlot,
|
|
104
|
+
randomness,
|
|
105
|
+
noteNonce,
|
|
106
|
+
note,
|
|
107
|
+
noteHash,
|
|
108
|
+
siloedNullifier,
|
|
109
|
+
// PXE can use this index to get full MembershipWitness
|
|
110
|
+
index,
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
async getFunctionArtifact(
|
|
@@ -597,6 +600,7 @@ export class PXEOracleInterface implements ExecutionDataProvider {
|
|
|
597
600
|
this.deliverNote(
|
|
598
601
|
request.contractAddress,
|
|
599
602
|
request.storageSlot,
|
|
603
|
+
request.randomness,
|
|
600
604
|
request.noteNonce,
|
|
601
605
|
request.content,
|
|
602
606
|
request.noteHash,
|
|
@@ -627,6 +631,7 @@ export class PXEOracleInterface implements ExecutionDataProvider {
|
|
|
627
631
|
async deliverNote(
|
|
628
632
|
contractAddress: AztecAddress,
|
|
629
633
|
storageSlot: Fr,
|
|
634
|
+
randomness: Fr,
|
|
630
635
|
noteNonce: Fr,
|
|
631
636
|
content: Fr[],
|
|
632
637
|
noteHash: Fr,
|
|
@@ -678,6 +683,7 @@ export class PXEOracleInterface implements ExecutionDataProvider {
|
|
|
678
683
|
new Note(content),
|
|
679
684
|
contractAddress,
|
|
680
685
|
storageSlot,
|
|
686
|
+
randomness,
|
|
681
687
|
noteNonce,
|
|
682
688
|
noteHash,
|
|
683
689
|
siloedNullifier,
|
|
@@ -685,9 +691,9 @@ export class PXEOracleInterface implements ExecutionDataProvider {
|
|
|
685
691
|
uniqueNoteHashTreeIndexInBlock?.l2BlockNumber,
|
|
686
692
|
uniqueNoteHashTreeIndexInBlock?.l2BlockHash.toString(),
|
|
687
693
|
uniqueNoteHashTreeIndexInBlock?.data,
|
|
688
|
-
recipient,
|
|
689
694
|
);
|
|
690
695
|
|
|
696
|
+
// The note was found by `recipient`, so we use that as the scope when storing the note.
|
|
691
697
|
await this.noteDataProvider.addNotes([noteDao], recipient);
|
|
692
698
|
this.log.verbose('Added note', {
|
|
693
699
|
index: noteDao.index,
|
package/src/pxe.ts
CHANGED
|
@@ -35,7 +35,8 @@ import type {
|
|
|
35
35
|
PrivateKernelExecutionProofOutput,
|
|
36
36
|
PrivateKernelTailCircuitPublicInputs,
|
|
37
37
|
} from '@aztec/stdlib/kernel';
|
|
38
|
-
import {
|
|
38
|
+
import type { NotesFilter } from '@aztec/stdlib/note';
|
|
39
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
39
40
|
import {
|
|
40
41
|
type ContractOverrides,
|
|
41
42
|
PrivateExecutionResult,
|
|
@@ -672,26 +673,12 @@ export class PXE {
|
|
|
672
673
|
* @param filter - The filter to apply to the notes.
|
|
673
674
|
* @returns The requested notes.
|
|
674
675
|
*/
|
|
675
|
-
public async getNotes(filter: NotesFilter): Promise<
|
|
676
|
+
public async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
676
677
|
// We need to manually trigger private state sync to have a guarantee that all the notes are available.
|
|
677
678
|
const call = await this.#getFunctionCall('sync_private_state', [], filter.contractAddress);
|
|
678
679
|
await this.simulateUtility(call);
|
|
679
680
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
const uniqueNotes = noteDaos.map(async dao => {
|
|
683
|
-
const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
|
|
684
|
-
const completeAddressIndex = completeAddresses.findIndex(completeAddress =>
|
|
685
|
-
completeAddress.address.equals(dao.recipient),
|
|
686
|
-
);
|
|
687
|
-
const completeAddress = completeAddresses[completeAddressIndex];
|
|
688
|
-
if (completeAddress === undefined) {
|
|
689
|
-
throw new Error(`Cannot find complete address for recipient ${dao.recipient.toString()}`);
|
|
690
|
-
}
|
|
691
|
-
const recipient = completeAddress.address;
|
|
692
|
-
return new UniqueNote(dao.note, recipient, dao.contractAddress, dao.storageSlot, dao.txHash, dao.noteNonce);
|
|
693
|
-
});
|
|
694
|
-
return Promise.all(uniqueNotes);
|
|
681
|
+
return this.noteDataProvider.getNotes(filter);
|
|
695
682
|
}
|
|
696
683
|
|
|
697
684
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { NoteDao } from '
|
|
1
|
+
export { NoteDao } from '@aztec/stdlib/note';
|
|
2
2
|
export { NoteDataProvider } from './note_data_provider.js';
|
|
@@ -5,8 +5,7 @@ import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@azte
|
|
|
5
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
6
|
import type { InBlock } from '@aztec/stdlib/block';
|
|
7
7
|
import { NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
|
|
8
|
-
|
|
9
|
-
import { NoteDao } from './note_dao.js';
|
|
8
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* NoteDataProvider manages the storage and retrieval of notes.
|
|
@@ -194,10 +193,12 @@ export class NoteDataProvider {
|
|
|
194
193
|
await this.#notes.set(noteIndex, dao.toBuffer());
|
|
195
194
|
await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
|
|
196
195
|
|
|
197
|
-
|
|
196
|
+
const scopes = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex));
|
|
198
197
|
|
|
199
198
|
if (scopes.length === 0) {
|
|
200
|
-
|
|
199
|
+
// We should never run into this error because notes always have a scope assigned to them - either on initial
|
|
200
|
+
// insertion via `addNotes` or when removing their nullifiers.
|
|
201
|
+
throw new Error(`No scopes found for nullified note with index ${noteIndex}`);
|
|
201
202
|
}
|
|
202
203
|
|
|
203
204
|
for (const scope of scopes) {
|
|
@@ -359,7 +360,14 @@ export class NoteDataProvider {
|
|
|
359
360
|
if (!noteBuffer) {
|
|
360
361
|
throw new Error('Note not found in applyNullifiers');
|
|
361
362
|
}
|
|
362
|
-
|
|
363
|
+
|
|
364
|
+
const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteIndex));
|
|
365
|
+
if (noteScopes.length === 0) {
|
|
366
|
+
// We should never run into this error because notes always have a scope assigned to them - either on initial
|
|
367
|
+
// insertion via `addNotes` or when removing their nullifiers.
|
|
368
|
+
throw new Error('Note scopes are missing in applyNullifiers');
|
|
369
|
+
}
|
|
370
|
+
|
|
363
371
|
const note = NoteDao.fromBuffer(noteBuffer);
|
|
364
372
|
|
|
365
373
|
nullifiedNotes.push(note);
|
|
@@ -374,10 +382,8 @@ export class NoteDataProvider {
|
|
|
374
382
|
await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(note.storageSlot.toString(), noteIndex);
|
|
375
383
|
}
|
|
376
384
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
await this.#nullifiedNotesToScope.set(noteIndex, scope);
|
|
380
|
-
}
|
|
385
|
+
for (const scope of noteScopes) {
|
|
386
|
+
await this.#nullifiedNotesToScope.set(noteIndex, scope);
|
|
381
387
|
}
|
|
382
388
|
await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
|
|
383
389
|
await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
-
import { Note } from '@aztec/stdlib/note';
|
|
5
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
6
|
-
import type { NoteData } from '../../contract_function_simulator/oracle/interfaces.js';
|
|
7
|
-
/**
|
|
8
|
-
* A Note Data Access Object, representing a note that was committed to the note hash tree, holding all of the
|
|
9
|
-
* information required to use it during execution and manage its state.
|
|
10
|
-
*/
|
|
11
|
-
export declare class NoteDao implements NoteData {
|
|
12
|
-
/** The packed content of the note, as will be returned in the getNotes oracle. */
|
|
13
|
-
note: Note;
|
|
14
|
-
/** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */
|
|
15
|
-
contractAddress: AztecAddress;
|
|
16
|
-
/**
|
|
17
|
-
* The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
|
|
18
|
-
* since contracts typically make queries based on it.
|
|
19
|
-
*/
|
|
20
|
-
storageSlot: Fr;
|
|
21
|
-
/** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
|
|
22
|
-
noteNonce: Fr;
|
|
23
|
-
/**
|
|
24
|
-
* The inner hash (non-unique, non-siloed) of the note. Each contract determines how the note is hashed. Can
|
|
25
|
-
* be used alongside contractAddress and nonce to compute the uniqueNoteHash and the siloedNoteHash.
|
|
26
|
-
*/
|
|
27
|
-
noteHash: Fr;
|
|
28
|
-
/**
|
|
29
|
-
* The nullifier of the note, siloed by contract address.
|
|
30
|
-
* Note: Might be set as 0 if the note was added to PXE as nullified.
|
|
31
|
-
*/
|
|
32
|
-
siloedNullifier: Fr;
|
|
33
|
-
/** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g.
|
|
34
|
-
* when searching for txEffects.
|
|
35
|
-
*/
|
|
36
|
-
txHash: TxHash;
|
|
37
|
-
/** The L2 block number in which the tx with this note was included. Used for note management while processing
|
|
38
|
-
* reorgs.*/
|
|
39
|
-
l2BlockNumber: number;
|
|
40
|
-
/** The L2 block hash in which the tx with this note was included. Used for note management while processing
|
|
41
|
-
* reorgs.*/
|
|
42
|
-
l2BlockHash: string;
|
|
43
|
-
/** The index of the leaf in the global note hash tree the note is stored at */
|
|
44
|
-
index: bigint;
|
|
45
|
-
/**
|
|
46
|
-
* The address whose public key was used to encrypt the note log during delivery.
|
|
47
|
-
* (This is the x-coordinate of the public key.)
|
|
48
|
-
*/
|
|
49
|
-
recipient: AztecAddress;
|
|
50
|
-
constructor(
|
|
51
|
-
/** The packed content of the note, as will be returned in the getNotes oracle. */
|
|
52
|
-
note: Note,
|
|
53
|
-
/** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */
|
|
54
|
-
contractAddress: AztecAddress,
|
|
55
|
-
/**
|
|
56
|
-
* The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
|
|
57
|
-
* since contracts typically make queries based on it.
|
|
58
|
-
*/
|
|
59
|
-
storageSlot: Fr,
|
|
60
|
-
/** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
|
|
61
|
-
noteNonce: Fr,
|
|
62
|
-
/**
|
|
63
|
-
* The inner hash (non-unique, non-siloed) of the note. Each contract determines how the note is hashed. Can
|
|
64
|
-
* be used alongside contractAddress and nonce to compute the uniqueNoteHash and the siloedNoteHash.
|
|
65
|
-
*/
|
|
66
|
-
noteHash: Fr,
|
|
67
|
-
/**
|
|
68
|
-
* The nullifier of the note, siloed by contract address.
|
|
69
|
-
* Note: Might be set as 0 if the note was added to PXE as nullified.
|
|
70
|
-
*/
|
|
71
|
-
siloedNullifier: Fr,
|
|
72
|
-
/** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g.
|
|
73
|
-
* when searching for txEffects.
|
|
74
|
-
*/
|
|
75
|
-
txHash: TxHash,
|
|
76
|
-
/** The L2 block number in which the tx with this note was included. Used for note management while processing
|
|
77
|
-
* reorgs.*/
|
|
78
|
-
l2BlockNumber: number,
|
|
79
|
-
/** The L2 block hash in which the tx with this note was included. Used for note management while processing
|
|
80
|
-
* reorgs.*/
|
|
81
|
-
l2BlockHash: string,
|
|
82
|
-
/** The index of the leaf in the global note hash tree the note is stored at */
|
|
83
|
-
index: bigint,
|
|
84
|
-
/**
|
|
85
|
-
* The address whose public key was used to encrypt the note log during delivery.
|
|
86
|
-
* (This is the x-coordinate of the public key.)
|
|
87
|
-
*/
|
|
88
|
-
recipient: AztecAddress);
|
|
89
|
-
toBuffer(): Buffer;
|
|
90
|
-
static fromBuffer(buffer: Buffer | BufferReader): NoteDao;
|
|
91
|
-
toString(): string;
|
|
92
|
-
static fromString(str: string): NoteDao;
|
|
93
|
-
/**
|
|
94
|
-
* Returns the size in bytes of the Note Dao.
|
|
95
|
-
* @returns - Its size in bytes.
|
|
96
|
-
*/
|
|
97
|
-
getSize(): number;
|
|
98
|
-
static random({ note, contractAddress, storageSlot, noteNonce, noteHash, siloedNullifier, txHash, l2BlockNumber, l2BlockHash, index, recipient, }?: Partial<NoteDao>): Promise<NoteDao>;
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=note_dao.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"note_dao.d.ts","sourceRoot":"","sources":["../../../src/storage/note_data_provider/note_dao.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAS,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wDAAwD,CAAC;AAEvF;;;GAGG;AACH,qBAAa,OAAQ,YAAW,QAAQ;IAIpC,kFAAkF;IAC3E,IAAI,EAAE,IAAI;IACjB,8GAA8G;IACvG,eAAe,EAAE,YAAY;IACpC;;;OAGG;IACI,WAAW,EAAE,EAAE;IACtB,gGAAgG;IACzF,SAAS,EAAE,EAAE;IAGpB;;;OAGG;IACI,QAAQ,EAAE,EAAE;IACnB;;;OAGG;IACI,eAAe,EAAE,EAAE;IAG1B;;OAEG;IACI,MAAM,EAAE,MAAM;IACrB;gBACY;IACL,aAAa,EAAE,MAAM;IAC5B;gBACY;IACL,WAAW,EAAE,MAAM;IAC1B,+EAA+E;IACxE,KAAK,EAAE,MAAM;IACpB;;;OAGG;IACI,SAAS,EAAE,YAAY;;IAzC9B,kFAAkF;IAC3E,IAAI,EAAE,IAAI;IACjB,8GAA8G;IACvG,eAAe,EAAE,YAAY;IACpC;;;OAGG;IACI,WAAW,EAAE,EAAE;IACtB,gGAAgG;IACzF,SAAS,EAAE,EAAE;IAGpB;;;OAGG;IACI,QAAQ,EAAE,EAAE;IACnB;;;OAGG;IACI,eAAe,EAAE,EAAE;IAG1B;;OAEG;IACI,MAAM,EAAE,MAAM;IACrB;gBACY;IACL,aAAa,EAAE,MAAM;IAC5B;gBACY;IACL,WAAW,EAAE,MAAM;IAC1B,+EAA+E;IACxE,KAAK,EAAE,MAAM;IACpB;;;OAGG;IACI,SAAS,EAAE,YAAY;IAGhC,QAAQ,IAAI,MAAM;IAgBlB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IA8B/C,QAAQ;IAIR,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM;IAK7B;;;OAGG;IACI,OAAO;WAMD,MAAM,CAAC,EAClB,IAAoB,EACpB,eAA2B,EAC3B,WAAyB,EACzB,SAAuB,EACvB,QAAsB,EACtB,eAA6B,EAC7B,MAAwB,EACxB,aAAgD,EAChD,WAAoC,EACpC,KAA8B,EAC9B,SAAqB,GACtB,GAAE,OAAO,CAAC,OAAO,CAAM;CAezB"}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { toBigIntBE } from '@aztec/foundation/bigint-buffer';
|
|
2
|
-
import { Fr, Point } from '@aztec/foundation/fields';
|
|
3
|
-
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import { Note } from '@aztec/stdlib/note';
|
|
6
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
7
|
-
/**
|
|
8
|
-
* A Note Data Access Object, representing a note that was committed to the note hash tree, holding all of the
|
|
9
|
-
* information required to use it during execution and manage its state.
|
|
10
|
-
*/ export class NoteDao {
|
|
11
|
-
note;
|
|
12
|
-
contractAddress;
|
|
13
|
-
storageSlot;
|
|
14
|
-
noteNonce;
|
|
15
|
-
noteHash;
|
|
16
|
-
siloedNullifier;
|
|
17
|
-
txHash;
|
|
18
|
-
l2BlockNumber;
|
|
19
|
-
l2BlockHash;
|
|
20
|
-
index;
|
|
21
|
-
recipient;
|
|
22
|
-
constructor(// Note information
|
|
23
|
-
/** The packed content of the note, as will be returned in the getNotes oracle. */ note, /** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */ contractAddress, /**
|
|
24
|
-
* The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
|
|
25
|
-
* since contracts typically make queries based on it.
|
|
26
|
-
*/ storageSlot, /** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */ noteNonce, // Computed values
|
|
27
|
-
/**
|
|
28
|
-
* The inner hash (non-unique, non-siloed) of the note. Each contract determines how the note is hashed. Can
|
|
29
|
-
* be used alongside contractAddress and nonce to compute the uniqueNoteHash and the siloedNoteHash.
|
|
30
|
-
*/ noteHash, /**
|
|
31
|
-
* The nullifier of the note, siloed by contract address.
|
|
32
|
-
* Note: Might be set as 0 if the note was added to PXE as nullified.
|
|
33
|
-
*/ siloedNullifier, // Metadata
|
|
34
|
-
/** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g.
|
|
35
|
-
* when searching for txEffects.
|
|
36
|
-
*/ txHash, /** The L2 block number in which the tx with this note was included. Used for note management while processing
|
|
37
|
-
* reorgs.*/ l2BlockNumber, /** The L2 block hash in which the tx with this note was included. Used for note management while processing
|
|
38
|
-
* reorgs.*/ l2BlockHash, /** The index of the leaf in the global note hash tree the note is stored at */ index, /**
|
|
39
|
-
* The address whose public key was used to encrypt the note log during delivery.
|
|
40
|
-
* (This is the x-coordinate of the public key.)
|
|
41
|
-
*/ recipient){
|
|
42
|
-
this.note = note;
|
|
43
|
-
this.contractAddress = contractAddress;
|
|
44
|
-
this.storageSlot = storageSlot;
|
|
45
|
-
this.noteNonce = noteNonce;
|
|
46
|
-
this.noteHash = noteHash;
|
|
47
|
-
this.siloedNullifier = siloedNullifier;
|
|
48
|
-
this.txHash = txHash;
|
|
49
|
-
this.l2BlockNumber = l2BlockNumber;
|
|
50
|
-
this.l2BlockHash = l2BlockHash;
|
|
51
|
-
this.index = index;
|
|
52
|
-
this.recipient = recipient;
|
|
53
|
-
}
|
|
54
|
-
toBuffer() {
|
|
55
|
-
return serializeToBuffer([
|
|
56
|
-
this.note,
|
|
57
|
-
this.contractAddress,
|
|
58
|
-
this.storageSlot,
|
|
59
|
-
this.noteNonce,
|
|
60
|
-
this.noteHash,
|
|
61
|
-
this.siloedNullifier,
|
|
62
|
-
this.txHash,
|
|
63
|
-
this.l2BlockNumber,
|
|
64
|
-
Fr.fromHexString(this.l2BlockHash),
|
|
65
|
-
this.index,
|
|
66
|
-
this.recipient
|
|
67
|
-
]);
|
|
68
|
-
}
|
|
69
|
-
static fromBuffer(buffer) {
|
|
70
|
-
const reader = BufferReader.asReader(buffer);
|
|
71
|
-
const note = Note.fromBuffer(reader);
|
|
72
|
-
const contractAddress = AztecAddress.fromBuffer(reader);
|
|
73
|
-
const storageSlot = Fr.fromBuffer(reader);
|
|
74
|
-
const noteNonce = Fr.fromBuffer(reader);
|
|
75
|
-
const noteHash = Fr.fromBuffer(reader);
|
|
76
|
-
const siloedNullifier = Fr.fromBuffer(reader);
|
|
77
|
-
const txHash = reader.readObject(TxHash);
|
|
78
|
-
const l2BlockNumber = reader.readNumber();
|
|
79
|
-
const l2BlockHash = Fr.fromBuffer(reader).toString();
|
|
80
|
-
const index = toBigIntBE(reader.readBytes(32));
|
|
81
|
-
const recipient = AztecAddress.fromBuffer(reader);
|
|
82
|
-
return new NoteDao(note, contractAddress, storageSlot, noteNonce, noteHash, siloedNullifier, txHash, l2BlockNumber, l2BlockHash, index, recipient);
|
|
83
|
-
}
|
|
84
|
-
toString() {
|
|
85
|
-
return '0x' + this.toBuffer().toString('hex');
|
|
86
|
-
}
|
|
87
|
-
static fromString(str) {
|
|
88
|
-
const hex = str.replace(/^0x/, '');
|
|
89
|
-
return NoteDao.fromBuffer(Buffer.from(hex, 'hex'));
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Returns the size in bytes of the Note Dao.
|
|
93
|
-
* @returns - Its size in bytes.
|
|
94
|
-
*/ getSize() {
|
|
95
|
-
const indexSize = Math.ceil(Math.log2(Number(this.index)));
|
|
96
|
-
const noteSize = 4 + this.note.items.length * Fr.SIZE_IN_BYTES;
|
|
97
|
-
return noteSize + AztecAddress.SIZE_IN_BYTES + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + indexSize;
|
|
98
|
-
}
|
|
99
|
-
static async random({ note = Note.random(), contractAddress = undefined, storageSlot = Fr.random(), noteNonce = Fr.random(), noteHash = Fr.random(), siloedNullifier = Fr.random(), txHash = TxHash.random(), l2BlockNumber = Math.floor(Math.random() * 1000), l2BlockHash = Fr.random().toString(), index = Fr.random().toBigInt(), recipient = undefined } = {}) {
|
|
100
|
-
return new NoteDao(note, contractAddress ?? await AztecAddress.random(), storageSlot, noteNonce, noteHash, siloedNullifier, txHash, l2BlockNumber, l2BlockHash, index, recipient ?? await AztecAddress.random());
|
|
101
|
-
}
|
|
102
|
-
}
|