@aztec/pxe 0.0.1-commit.c7c42ec → 0.0.1-commit.c80b6263
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/check_oracle_version.js +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts +11 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +68 -20
- package/dest/config/index.d.ts +3 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -0
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
- package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/benchmarked_node.js +77 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +8 -9
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +33 -19
- package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +45 -28
- package/dest/contract_function_simulator/index.d.ts +2 -2
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -3
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +6 -3
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -11
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
- package/dest/contract_function_simulator/oracle/oracle.d.ts +10 -8
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +43 -32
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +1 -37
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +16 -18
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +24 -38
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +27 -17
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +72 -72
- package/dest/contract_sync/index.d.ts +23 -0
- package/dest/contract_sync/index.d.ts.map +1 -0
- package/dest/contract_sync/index.js +54 -0
- package/dest/debug/pxe_debug_utils.d.ts +16 -6
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +20 -10
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +20 -6
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +21 -7
- package/dest/entrypoints/pxe_creation_options.d.ts +5 -3
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +3 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -0
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +30 -15
- package/dest/events/event_service.d.ts +4 -3
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +17 -19
- package/dest/events/private_event_filter_validator.d.ts +5 -5
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +5 -6
- package/dest/job_coordinator/job_coordinator.d.ts +75 -0
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
- package/dest/job_coordinator/job_coordinator.js +94 -0
- package/dest/logs/log_service.d.ts +4 -2
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +22 -14
- package/dest/notes/note_service.d.ts +5 -4
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +30 -34
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +4 -3
- package/dest/private_kernel/hints/index.d.ts +2 -2
- package/dest/private_kernel/hints/index.d.ts.map +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
- package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +13 -7
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +6 -7
- package/dest/private_kernel/private_kernel_oracle.d.ts +24 -28
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +90 -2
- package/dest/pxe.d.ts +8 -36
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +75 -93
- package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +132 -23
- package/dest/storage/note_store/note_store.d.ts +45 -56
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +244 -263
- package/dest/storage/note_store/stored_note.d.ts +16 -0
- package/dest/storage/note_store/stored_note.d.ts.map +1 -0
- package/dest/storage/note_store/stored_note.js +43 -0
- package/dest/storage/private_event_store/private_event_store.d.ts +47 -7
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +203 -68
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +69 -12
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +110 -28
- package/dest/tagging/constants.d.ts +2 -0
- package/dest/tagging/constants.d.ts.map +1 -0
- package/dest/tagging/constants.js +10 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +46 -0
- package/dest/tagging/index.d.ts +3 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +2 -10
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +8 -8
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +8 -8
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -2
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +10 -5
- package/package.json +18 -18
- package/src/bin/check_oracle_version.ts +1 -0
- package/src/block_synchronizer/block_synchronizer.ts +87 -32
- package/src/config/index.ts +14 -0
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/benchmarked_node.ts +103 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +39 -21
- package/src/contract_function_simulator/execution_note_cache.ts +44 -25
- package/src/contract_function_simulator/index.ts +1 -1
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +5 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
- package/src/contract_function_simulator/oracle/interfaces.ts +20 -10
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
- package/src/contract_function_simulator/oracle/oracle.ts +56 -41
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -69
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +43 -42
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +92 -76
- package/src/contract_sync/index.ts +98 -0
- package/src/debug/pxe_debug_utils.ts +26 -11
- package/src/entrypoints/client/bundle/utils.ts +12 -15
- package/src/entrypoints/client/lazy/utils.ts +13 -16
- package/src/entrypoints/pxe_creation_options.ts +4 -2
- package/src/entrypoints/server/index.ts +2 -0
- package/src/entrypoints/server/utils.ts +26 -34
- package/src/events/event_service.ts +17 -21
- package/src/events/private_event_filter_validator.ts +3 -5
- package/src/job_coordinator/job_coordinator.ts +150 -0
- package/src/logs/log_service.ts +33 -12
- package/src/notes/note_service.ts +37 -40
- package/src/oracle_version.ts +4 -3
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +33 -22
- package/src/private_kernel/private_kernel_execution_prover.ts +9 -8
- package/src/private_kernel/private_kernel_oracle.ts +116 -36
- package/src/pxe.ts +136 -122
- package/src/storage/capsule_store/capsule_store.ts +159 -23
- package/src/storage/note_store/note_store.ts +286 -317
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +277 -76
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +89 -13
- package/src/storage/tagging_store/sender_tagging_store.ts +129 -28
- package/src/tagging/constants.ts +10 -0
- package/src/tagging/get_all_logs_by_tags.ts +68 -0
- package/src/tagging/index.ts +2 -11
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +21 -7
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +10 -7
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -13
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
- package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
- package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
- package/dest/contract_function_simulator/proxied_node.js +0 -27
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
- package/dest/public_storage/public_storage_service.d.ts +0 -24
- package/dest/public_storage/public_storage_service.d.ts.map +0 -1
- package/dest/public_storage/public_storage_service.js +0 -26
- package/dest/tree_membership/tree_membership_service.d.ts +0 -52
- package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.js +0 -84
- package/src/contract_function_simulator/proxied_node.ts +0 -33
- package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
- package/src/public_storage/public_storage_service.ts +0 -33
- package/src/tree_membership/tree_membership_service.ts +0 -112
|
@@ -15,6 +15,7 @@ export class NoteService {
|
|
|
15
15
|
private readonly noteStore: NoteStore,
|
|
16
16
|
private readonly aztecNode: AztecNode,
|
|
17
17
|
private readonly anchorBlockStore: AnchorBlockStore,
|
|
18
|
+
private readonly jobId: string,
|
|
18
19
|
) {}
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -33,15 +34,18 @@ export class NoteService {
|
|
|
33
34
|
status: NoteStatus,
|
|
34
35
|
scopes?: AztecAddress[],
|
|
35
36
|
) {
|
|
36
|
-
const noteDaos = await this.noteStore.getNotes(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
const noteDaos = await this.noteStore.getNotes(
|
|
38
|
+
{
|
|
39
|
+
contractAddress,
|
|
40
|
+
owner,
|
|
41
|
+
storageSlot,
|
|
42
|
+
status,
|
|
43
|
+
scopes,
|
|
44
|
+
},
|
|
45
|
+
this.jobId,
|
|
46
|
+
);
|
|
43
47
|
return noteDaos.map(
|
|
44
|
-
({ contractAddress, owner, storageSlot, randomness, noteNonce, note, noteHash, siloedNullifier
|
|
48
|
+
({ contractAddress, owner, storageSlot, randomness, noteNonce, note, noteHash, siloedNullifier }) => ({
|
|
45
49
|
contractAddress,
|
|
46
50
|
owner,
|
|
47
51
|
storageSlot,
|
|
@@ -49,9 +53,8 @@ export class NoteService {
|
|
|
49
53
|
noteNonce,
|
|
50
54
|
note,
|
|
51
55
|
noteHash,
|
|
56
|
+
isPending: false, // Note service deals only with settled notes
|
|
52
57
|
siloedNullifier,
|
|
53
|
-
// PXE can use this index to get full MembershipWitness
|
|
54
|
-
index,
|
|
55
58
|
}),
|
|
56
59
|
);
|
|
57
60
|
}
|
|
@@ -69,9 +72,9 @@ export class NoteService {
|
|
|
69
72
|
* @param contractAddress - The contract whose notes should be checked and nullified.
|
|
70
73
|
*/
|
|
71
74
|
public async syncNoteNullifiers(contractAddress: AztecAddress): Promise<void> {
|
|
72
|
-
const
|
|
75
|
+
const anchorBlockHash = await (await this.anchorBlockStore.getBlockHeader()).hash();
|
|
73
76
|
|
|
74
|
-
const contractNotes = await this.noteStore.getNotes({ contractAddress });
|
|
77
|
+
const contractNotes = await this.noteStore.getNotes({ contractAddress }, this.jobId);
|
|
75
78
|
|
|
76
79
|
if (contractNotes.length === 0) {
|
|
77
80
|
return;
|
|
@@ -92,7 +95,7 @@ export class NoteService {
|
|
|
92
95
|
const nullifierIndexes = (
|
|
93
96
|
await Promise.all(
|
|
94
97
|
nullifierBatches.map(batch =>
|
|
95
|
-
this.aztecNode.findLeavesIndexes(
|
|
98
|
+
this.aztecNode.findLeavesIndexes(anchorBlockHash, MerkleTreeId.NULLIFIER_TREE, batch),
|
|
96
99
|
),
|
|
97
100
|
)
|
|
98
101
|
).flat();
|
|
@@ -105,10 +108,10 @@ export class NoteService {
|
|
|
105
108
|
})
|
|
106
109
|
.filter(nullifier => nullifier !== undefined) as DataInBlock<Fr>[];
|
|
107
110
|
|
|
108
|
-
await this.noteStore.applyNullifiers(foundNullifiers);
|
|
111
|
+
await this.noteStore.applyNullifiers(foundNullifiers, this.jobId);
|
|
109
112
|
}
|
|
110
113
|
|
|
111
|
-
public async
|
|
114
|
+
public async validateAndStoreNote(
|
|
112
115
|
contractAddress: AztecAddress,
|
|
113
116
|
owner: AztecAddress,
|
|
114
117
|
storageSlot: Fr,
|
|
@@ -139,41 +142,33 @@ export class NoteService {
|
|
|
139
142
|
// number which *should* be recent enough to be available, even for non-archive nodes.
|
|
140
143
|
// Also note that the note should never be ahead of the synced block here since `fetchTaggedLogs` only processes
|
|
141
144
|
// logs up to the synced block making this only an additional safety check.
|
|
142
|
-
const
|
|
145
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
146
|
+
const anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
147
|
+
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
143
148
|
|
|
144
149
|
// By computing siloed and unique note hashes ourselves we prevent contracts from interfering with the note storage
|
|
145
150
|
// of other contracts, which would constitute a security breach.
|
|
146
151
|
const uniqueNoteHash = await computeUniqueNoteHash(noteNonce, await siloNoteHash(contractAddress, noteHash));
|
|
147
152
|
const siloedNullifier = await siloNullifier(contractAddress, nullifier);
|
|
148
153
|
|
|
149
|
-
const txEffect = await
|
|
154
|
+
const [txEffect, [nullifierIndex]] = await Promise.all([
|
|
155
|
+
this.aztecNode.getTxEffect(txHash),
|
|
156
|
+
this.aztecNode.findLeavesIndexes(anchorBlockHash, MerkleTreeId.NULLIFIER_TREE, [siloedNullifier]),
|
|
157
|
+
]);
|
|
150
158
|
if (!txEffect) {
|
|
151
159
|
throw new Error(`Could not find tx effect for tx hash ${txHash}`);
|
|
152
160
|
}
|
|
153
161
|
|
|
154
|
-
if (txEffect.l2BlockNumber >
|
|
155
|
-
throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${
|
|
162
|
+
if (txEffect.l2BlockNumber > anchorBlockNumber) {
|
|
163
|
+
throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${anchorBlockNumber}`);
|
|
156
164
|
}
|
|
157
165
|
|
|
158
|
-
|
|
159
|
-
|
|
166
|
+
// Find the index of the note hash in the noteHashes array to determine note ordering within the tx
|
|
167
|
+
const noteIndexInTx = txEffect.data.noteHashes.findIndex(nh => nh.equals(uniqueNoteHash));
|
|
168
|
+
if (noteIndexInTx === -1) {
|
|
160
169
|
throw new Error(`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present in tx ${txHash}`);
|
|
161
170
|
}
|
|
162
171
|
|
|
163
|
-
// We store notes by their index in the global note hash tree, which has the convenient side effect of validating
|
|
164
|
-
// note existence in said tree. We concurrently also check if the note's nullifier exists, performing all node
|
|
165
|
-
// queries in a single round-trip.
|
|
166
|
-
const [[uniqueNoteHashTreeIndexInBlock], [nullifierIndex]] = await Promise.all([
|
|
167
|
-
this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NOTE_HASH_TREE, [uniqueNoteHash]),
|
|
168
|
-
this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [siloedNullifier]),
|
|
169
|
-
]);
|
|
170
|
-
|
|
171
|
-
if (uniqueNoteHashTreeIndexInBlock === undefined) {
|
|
172
|
-
throw new Error(
|
|
173
|
-
`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present on the tree at block ${syncedBlockNumber} (from tx ${txHash})`,
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
172
|
const noteDao = new NoteDao(
|
|
178
173
|
new Note(content),
|
|
179
174
|
contractAddress,
|
|
@@ -184,17 +179,19 @@ export class NoteService {
|
|
|
184
179
|
noteHash,
|
|
185
180
|
siloedNullifier,
|
|
186
181
|
txHash,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
182
|
+
txEffect.l2BlockNumber,
|
|
183
|
+
txEffect.l2BlockHash.toString(),
|
|
184
|
+
txEffect.txIndexInBlock,
|
|
185
|
+
noteIndexInTx,
|
|
190
186
|
);
|
|
191
187
|
|
|
192
188
|
// The note was found by `recipient`, so we use that as the scope when storing the note.
|
|
193
|
-
await this.noteStore.addNotes([noteDao], recipient);
|
|
189
|
+
await this.noteStore.addNotes([noteDao], recipient, this.jobId);
|
|
194
190
|
|
|
195
191
|
if (nullifierIndex !== undefined) {
|
|
192
|
+
// We found nullifier index which implies that the note has already been nullified.
|
|
196
193
|
const { data: _, ...blockHashAndNum } = nullifierIndex;
|
|
197
|
-
await this.noteStore.applyNullifiers([{ data: siloedNullifier, ...blockHashAndNum }]);
|
|
194
|
+
await this.noteStore.applyNullifiers([{ data: siloedNullifier, ...blockHashAndNum }], this.jobId);
|
|
198
195
|
}
|
|
199
196
|
}
|
|
200
197
|
}
|
package/src/oracle_version.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
///
|
|
5
5
|
/// @dev Whenever a contract function or Noir test is run, the `utilityAssertCompatibleOracleVersion` oracle is called
|
|
6
6
|
/// and if the oracle version is incompatible an error is thrown.
|
|
7
|
-
export const ORACLE_VERSION =
|
|
7
|
+
export const ORACLE_VERSION = 9;
|
|
8
8
|
|
|
9
9
|
/// This hash is computed as by hashing the Oracle interface and it is used to detect when the Oracle interface changes,
|
|
10
|
-
/// which in turn implies that you need to update the ORACLE_VERSION constant
|
|
11
|
-
|
|
10
|
+
/// which in turn implies that you need to update the ORACLE_VERSION constant in this file and in
|
|
11
|
+
/// `noir-projects/aztec-nr/aztec/src/oracle/version.nr`.
|
|
12
|
+
export const ORACLE_INTERFACE_HASH = '9866cc52510acaef75a3d47a0ed501fd9ff92b9d53b2c8a88c8a3ffd04ced81f';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './private_kernel_reset_private_inputs_builder.js';
|
|
2
2
|
export * from './compute_tx_include_by_timestamp.js';
|
|
@@ -138,7 +138,7 @@ export class PrivateKernelResetPrivateInputsBuilder {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
async build(oracle: PrivateKernelOracle
|
|
141
|
+
async build(oracle: PrivateKernelOracle) {
|
|
142
142
|
if (privateKernelResetDimensionNames.every(name => !this.requestedDimensions[name])) {
|
|
143
143
|
throw new Error('Reset is not required.');
|
|
144
144
|
}
|
|
@@ -157,16 +157,6 @@ export class PrivateKernelResetPrivateInputsBuilder {
|
|
|
157
157
|
allowRemainder,
|
|
158
158
|
);
|
|
159
159
|
|
|
160
|
-
const previousVkMembershipWitness = await oracle.getVkMembershipWitness(
|
|
161
|
-
this.previousKernelOutput.verificationKey.keyAsFields,
|
|
162
|
-
);
|
|
163
|
-
const vkData = new VkData(
|
|
164
|
-
this.previousKernelOutput.verificationKey,
|
|
165
|
-
Number(previousVkMembershipWitness.leafIndex),
|
|
166
|
-
previousVkMembershipWitness.siblingPath,
|
|
167
|
-
);
|
|
168
|
-
const previousKernelData = new PrivateKernelData(this.previousKernelOutput.publicInputs, vkData);
|
|
169
|
-
|
|
170
160
|
this.reduceReadRequestActions(
|
|
171
161
|
this.noteHashResetActions,
|
|
172
162
|
dimensions.NOTE_HASH_PENDING_READ,
|
|
@@ -178,30 +168,51 @@ export class PrivateKernelResetPrivateInputsBuilder {
|
|
|
178
168
|
dimensions.NULLIFIER_SETTLED_READ,
|
|
179
169
|
);
|
|
180
170
|
|
|
181
|
-
//
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
171
|
+
// Execute all the expensive node querying operations in parallel.
|
|
172
|
+
const [previousVkMembershipWitness, noteHashReadRequestHints, nullifierReadRequestHints, keyValidationHints] =
|
|
173
|
+
await Promise.all([
|
|
174
|
+
oracle.getVkMembershipWitness(this.previousKernelOutput.verificationKey.keyAsFields),
|
|
175
|
+
buildNoteHashReadRequestHintsFromResetActions<
|
|
176
|
+
typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
|
|
177
|
+
typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX
|
|
178
|
+
>(
|
|
189
179
|
oracle,
|
|
190
180
|
this.previousKernel.validationRequests.noteHashReadRequests,
|
|
191
181
|
this.previousKernel.end.noteHashes,
|
|
192
182
|
this.noteHashResetActions,
|
|
193
|
-
noteHashLeafIndexMap,
|
|
194
183
|
),
|
|
195
|
-
|
|
184
|
+
buildNullifierReadRequestHintsFromResetActions<
|
|
185
|
+
typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
186
|
+
typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX
|
|
187
|
+
>(
|
|
196
188
|
{ getNullifierMembershipWitness: getNullifierMembershipWitnessResolver(oracle) },
|
|
197
189
|
this.previousKernel.validationRequests.nullifierReadRequests,
|
|
198
190
|
this.nullifierResetActions,
|
|
199
191
|
),
|
|
200
|
-
|
|
192
|
+
getMasterSecretKeysAndAppKeyGenerators(
|
|
201
193
|
this.previousKernel.validationRequests.scopedKeyValidationRequestsAndGenerators,
|
|
202
194
|
dimensions.KEY_VALIDATION,
|
|
203
195
|
oracle,
|
|
204
196
|
),
|
|
197
|
+
]);
|
|
198
|
+
|
|
199
|
+
const vkData = new VkData(
|
|
200
|
+
this.previousKernelOutput.verificationKey,
|
|
201
|
+
Number(previousVkMembershipWitness.leafIndex),
|
|
202
|
+
previousVkMembershipWitness.siblingPath,
|
|
203
|
+
);
|
|
204
|
+
const previousKernelData = new PrivateKernelData(this.previousKernelOutput.publicInputs, vkData);
|
|
205
|
+
|
|
206
|
+
// TODO: Enable padding when we have a better idea what are the final amounts we should pad to.
|
|
207
|
+
const paddedSideEffects = PaddedSideEffects.empty();
|
|
208
|
+
|
|
209
|
+
return new PrivateKernelResetCircuitPrivateInputs(
|
|
210
|
+
previousKernelData,
|
|
211
|
+
paddedSideEffects,
|
|
212
|
+
new PrivateKernelResetHints(
|
|
213
|
+
noteHashReadRequestHints,
|
|
214
|
+
nullifierReadRequestHints,
|
|
215
|
+
keyValidationHints,
|
|
205
216
|
this.transientDataSquashingHints,
|
|
206
217
|
),
|
|
207
218
|
dimensions,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto/keys';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
5
5
|
import { Timer } from '@aztec/foundation/timer';
|
|
6
6
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
@@ -28,13 +28,12 @@ import {
|
|
|
28
28
|
type PrivateCallExecutionResult,
|
|
29
29
|
type PrivateExecutionResult,
|
|
30
30
|
TxRequest,
|
|
31
|
-
collectNoteHashLeafIndexMap,
|
|
32
31
|
collectNoteHashNullifierCounterMap,
|
|
33
32
|
getFinalMinRevertibleSideEffectCounter,
|
|
34
33
|
} from '@aztec/stdlib/tx';
|
|
35
34
|
import { VerificationKeyAsFields, VerificationKeyData, VkData } from '@aztec/stdlib/vks';
|
|
36
35
|
|
|
37
|
-
import { PrivateKernelResetPrivateInputsBuilder } from './hints/
|
|
36
|
+
import { PrivateKernelResetPrivateInputsBuilder } from './hints/private_kernel_reset_private_inputs_builder.js';
|
|
38
37
|
import type { PrivateKernelOracle } from './private_kernel_oracle.js';
|
|
39
38
|
|
|
40
39
|
const NULL_SIMULATE_OUTPUT: PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs> = {
|
|
@@ -57,13 +56,16 @@ export interface PrivateKernelExecutionProverConfig {
|
|
|
57
56
|
* inform state tree updates.
|
|
58
57
|
*/
|
|
59
58
|
export class PrivateKernelExecutionProver {
|
|
60
|
-
private log
|
|
59
|
+
private log: Logger;
|
|
61
60
|
|
|
62
61
|
constructor(
|
|
63
62
|
private oracle: PrivateKernelOracle,
|
|
64
63
|
private proofCreator: PrivateKernelProver,
|
|
65
64
|
private fakeProofs = false,
|
|
66
|
-
|
|
65
|
+
bindings?: LoggerBindings,
|
|
66
|
+
) {
|
|
67
|
+
this.log = createLogger('pxe:private-kernel-execution-prover', bindings);
|
|
68
|
+
}
|
|
67
69
|
|
|
68
70
|
/**
|
|
69
71
|
* Generate a proof for a given transaction request and execution result.
|
|
@@ -101,7 +103,6 @@ export class PrivateKernelExecutionProver {
|
|
|
101
103
|
|
|
102
104
|
const executionSteps: PrivateExecutionStep[] = [];
|
|
103
105
|
|
|
104
|
-
const noteHashLeafIndexMap = collectNoteHashLeafIndexMap(executionResult);
|
|
105
106
|
const noteHashNullifierCounterMap = collectNoteHashNullifierCounterMap(executionResult);
|
|
106
107
|
const minRevertibleSideEffectCounter = getFinalMinRevertibleSideEffectCounter(executionResult);
|
|
107
108
|
const splitCounter = isPrivateOnlyTx ? 0 : minRevertibleSideEffectCounter;
|
|
@@ -116,7 +117,7 @@ export class PrivateKernelExecutionProver {
|
|
|
116
117
|
);
|
|
117
118
|
while (resetBuilder.needsReset()) {
|
|
118
119
|
const witgenTimer = new Timer();
|
|
119
|
-
const privateInputs = await resetBuilder.build(this.oracle
|
|
120
|
+
const privateInputs = await resetBuilder.build(this.oracle);
|
|
120
121
|
output = generateWitnesses
|
|
121
122
|
? await this.proofCreator.generateResetOutput(privateInputs)
|
|
122
123
|
: await this.proofCreator.simulateReset(privateInputs);
|
|
@@ -224,7 +225,7 @@ export class PrivateKernelExecutionProver {
|
|
|
224
225
|
);
|
|
225
226
|
while (resetBuilder.needsReset()) {
|
|
226
227
|
const witgenTimer = new Timer();
|
|
227
|
-
const privateInputs = await resetBuilder.build(this.oracle
|
|
228
|
+
const privateInputs = await resetBuilder.build(this.oracle);
|
|
228
229
|
output = generateWitnesses
|
|
229
230
|
? await this.proofCreator.generateResetOutput(privateInputs)
|
|
230
231
|
: await this.proofCreator.simulateReset(privateInputs);
|
|
@@ -1,72 +1,152 @@
|
|
|
1
|
-
import { FUNCTION_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT, VK_TREE_HEIGHT } from '@aztec/constants';
|
|
1
|
+
import { FUNCTION_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT, VK_TREE_HEIGHT } from '@aztec/constants';
|
|
2
2
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import type { GrumpkinScalar, Point } from '@aztec/foundation/curves/grumpkin';
|
|
4
4
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
5
|
+
import type { KeyStore } from '@aztec/key-store';
|
|
6
|
+
import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
7
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
5
8
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
6
9
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
11
|
+
import {
|
|
12
|
+
type ContractInstanceWithAddress,
|
|
13
|
+
computeContractClassIdPreimage,
|
|
14
|
+
computeSaltedInitializationHash,
|
|
15
|
+
} from '@aztec/stdlib/contract';
|
|
16
|
+
import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
|
|
17
|
+
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
18
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
7
19
|
import { UpdatedClassIdHints } from '@aztec/stdlib/kernel';
|
|
8
|
-
import type { PublicKeys } from '@aztec/stdlib/keys';
|
|
9
20
|
import type { NullifierMembershipWitness } from '@aztec/stdlib/trees';
|
|
10
21
|
import type { VerificationKeyAsFields } from '@aztec/stdlib/vks';
|
|
11
22
|
|
|
23
|
+
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
24
|
+
|
|
12
25
|
/**
|
|
13
26
|
* Provides functionality needed by the private kernel for interacting with our state trees.
|
|
14
|
-
* This is either PrivateKernelOracleImpl, or a mocked test implementation.
|
|
15
27
|
*/
|
|
16
|
-
export
|
|
28
|
+
export class PrivateKernelOracle {
|
|
29
|
+
constructor(
|
|
30
|
+
private contractStore: ContractStore,
|
|
31
|
+
private keyStore: KeyStore,
|
|
32
|
+
private node: AztecNode,
|
|
33
|
+
private blockHash: BlockHash,
|
|
34
|
+
) {}
|
|
35
|
+
|
|
17
36
|
/** Retrieves the preimage of a contract address from the registered contract instances db. */
|
|
18
|
-
getContractAddressPreimage(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
37
|
+
public async getContractAddressPreimage(
|
|
38
|
+
address: AztecAddress,
|
|
39
|
+
): Promise<ContractInstanceWithAddress & { saltedInitializationHash: Fr }> {
|
|
40
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
41
|
+
if (!instance) {
|
|
42
|
+
throw new Error(`Contract instance not found when getting address preimage. Contract address: ${address}.`);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
saltedInitializationHash: await computeSaltedInitializationHash(instance),
|
|
46
|
+
...instance,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
24
49
|
|
|
25
50
|
/** Retrieves the preimage of a contract class id from the contract classes db. */
|
|
26
|
-
getContractClassIdPreimage(
|
|
27
|
-
contractClassId
|
|
28
|
-
|
|
51
|
+
public async getContractClassIdPreimage(contractClassId: Fr) {
|
|
52
|
+
const contractClass = await this.contractStore.getContractClass(contractClassId);
|
|
53
|
+
if (!contractClass) {
|
|
54
|
+
throw new Error(`Contract class not found when getting class id preimage. Class id: ${contractClassId}.`);
|
|
55
|
+
}
|
|
56
|
+
return computeContractClassIdPreimage(contractClass);
|
|
57
|
+
}
|
|
29
58
|
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
*/
|
|
33
|
-
getFunctionMembershipWitness(
|
|
59
|
+
/** Returns a membership witness with the sibling path and leaf index in our private functions tree. */
|
|
60
|
+
public async getFunctionMembershipWitness(
|
|
34
61
|
contractClassId: Fr,
|
|
35
62
|
selector: FunctionSelector,
|
|
36
|
-
): Promise<MembershipWitness<typeof FUNCTION_TREE_HEIGHT
|
|
63
|
+
): Promise<MembershipWitness<typeof FUNCTION_TREE_HEIGHT>> {
|
|
64
|
+
const membershipWitness = await this.contractStore.getFunctionMembershipWitness(contractClassId, selector);
|
|
65
|
+
if (!membershipWitness) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Membership witness not found for contract class id ${contractClassId} and selector ${selector}.`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return membershipWitness;
|
|
71
|
+
}
|
|
37
72
|
|
|
38
73
|
/**
|
|
39
74
|
* Returns a membership witness with the sibling path and leaf index in our protocol VK indexed merkle tree.
|
|
40
75
|
* Used to validate the previous kernel's verification key.
|
|
41
76
|
*/
|
|
42
|
-
getVkMembershipWitness(vk: VerificationKeyAsFields): Promise<MembershipWitness<typeof VK_TREE_HEIGHT
|
|
77
|
+
public getVkMembershipWitness(vk: VerificationKeyAsFields): Promise<MembershipWitness<typeof VK_TREE_HEIGHT>> {
|
|
78
|
+
const leafIndex = getVKIndex(vk);
|
|
79
|
+
return Promise.resolve(new MembershipWitness(VK_TREE_HEIGHT, BigInt(leafIndex), getVKSiblingPath(leafIndex)));
|
|
80
|
+
}
|
|
43
81
|
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
82
|
+
/** Returns a membership witness with the sibling path and leaf index in our note hash tree. */
|
|
83
|
+
getNoteHashMembershipWitness(noteHash: Fr): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
84
|
+
return this.node.getNoteHashMembershipWitness(this.blockHash, noteHash);
|
|
85
|
+
}
|
|
47
86
|
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
87
|
+
/** Returns a membership witness with the sibling path and leaf index in our nullifier indexed merkle tree. */
|
|
88
|
+
getNullifierMembershipWitness(nullifier: Fr): Promise<NullifierMembershipWitness | undefined> {
|
|
89
|
+
return this.node.getNullifierMembershipWitness(this.blockHash, nullifier);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Returns the root of our note hash merkle tree. */
|
|
93
|
+
async getNoteHashTreeRoot(): Promise<Fr> {
|
|
94
|
+
const header = await this.node.getBlockHeader(this.blockHash);
|
|
95
|
+
if (!header) {
|
|
96
|
+
throw new Error(`No block header found for block hash ${this.blockHash}`);
|
|
97
|
+
}
|
|
98
|
+
return header.state.partial.noteHashTree.root;
|
|
99
|
+
}
|
|
56
100
|
|
|
57
101
|
/**
|
|
58
102
|
* Retrieves the sk_m corresponding to the pk_m.
|
|
59
103
|
* @throws If the provided public key is not associated with any of the registered accounts.
|
|
60
|
-
* @param
|
|
104
|
+
* @param masterPublicKey - The master public key to get secret key for.
|
|
61
105
|
* @returns A Promise that resolves to sk_m.
|
|
62
106
|
* @dev Used when feeding the sk_m to the kernel circuit for keys verification.
|
|
63
107
|
*/
|
|
64
|
-
getMasterSecretKey(masterPublicKey: Point): Promise<GrumpkinScalar
|
|
108
|
+
public getMasterSecretKey(masterPublicKey: Point): Promise<GrumpkinScalar> {
|
|
109
|
+
return this.keyStore.getMasterSecretKey(masterPublicKey);
|
|
110
|
+
}
|
|
65
111
|
|
|
66
112
|
/** Use debug data to get the function name corresponding to a selector. */
|
|
67
|
-
getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined
|
|
113
|
+
public getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
114
|
+
return this.contractStore.getDebugFunctionName(contractAddress, selector);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Returns a membership witness and leaf index to our public data indexed merkle tree,
|
|
119
|
+
* along with an associated DelayedPublicMutable containing the class ID to update.
|
|
120
|
+
*/
|
|
121
|
+
public async getUpdatedClassIdHints(contractAddress: AztecAddress): Promise<UpdatedClassIdHints> {
|
|
122
|
+
const { delayedPublicMutableSlot, delayedPublicMutableHashSlot } =
|
|
123
|
+
await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(contractAddress);
|
|
124
|
+
|
|
125
|
+
const hashLeafSlot = await computePublicDataTreeLeafSlot(
|
|
126
|
+
ProtocolContractAddress.ContractInstanceRegistry,
|
|
127
|
+
delayedPublicMutableHashSlot,
|
|
128
|
+
);
|
|
129
|
+
const updatedClassIdWitness = await this.node.getPublicDataWitness(this.blockHash, hashLeafSlot);
|
|
130
|
+
|
|
131
|
+
if (!updatedClassIdWitness) {
|
|
132
|
+
throw new Error(`No public data tree witness found for ${hashLeafSlot}`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const readStorage = (storageSlot: Fr) =>
|
|
136
|
+
this.node.getPublicStorageAt(this.blockHash, ProtocolContractAddress.ContractInstanceRegistry, storageSlot);
|
|
137
|
+
const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(
|
|
138
|
+
delayedPublicMutableSlot,
|
|
139
|
+
readStorage,
|
|
140
|
+
);
|
|
68
141
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
142
|
+
return new UpdatedClassIdHints(
|
|
143
|
+
new MembershipWitness(
|
|
144
|
+
PUBLIC_DATA_TREE_HEIGHT,
|
|
145
|
+
updatedClassIdWitness.index,
|
|
146
|
+
updatedClassIdWitness.siblingPath.toTuple(),
|
|
147
|
+
),
|
|
148
|
+
updatedClassIdWitness.leafPreimage,
|
|
149
|
+
delayedPublicMutableValues,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
72
152
|
}
|