@aztec/pxe 3.0.0-devnet.6 → 3.0.0-devnet.6-patch.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/check_oracle_version.d.ts +1 -1
- package/dest/bin/check_oracle_version.js +105 -15
- package/dest/config/index.d.ts +2 -10
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +7 -13
- package/dest/config/package_info.d.ts +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +6 -6
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +15 -16
- package/dest/contract_function_simulator/execution_data_provider.d.ts +13 -19
- package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.d.ts +9 -7
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +21 -13
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
- package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +3 -3
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +6 -4
- 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 +12 -3
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/utility_context.js +1 -1
- package/dest/contract_function_simulator/oracle/index.d.ts +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +17 -10
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +2 -4
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +10 -4
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +10 -5
- package/dest/contract_function_simulator/oracle/oracle.d.ts +5 -4
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +31 -14
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +4 -3
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +8 -12
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +20 -7
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +13 -11
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +5 -4
- package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_node.d.ts +1 -1
- package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -1
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +15 -13
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -1
- package/dest/contract_function_simulator/pxe_oracle_interface.js +50 -25
- package/dest/entrypoints/client/bundle/index.d.ts +1 -1
- 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 +13 -4
- package/dest/entrypoints/client/lazy/index.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +13 -4
- package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +1 -1
- 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 +13 -20
- package/dest/error_enriching.d.ts +1 -1
- package/dest/events/index.d.ts +2 -0
- package/dest/events/index.d.ts.map +1 -0
- package/dest/events/index.js +1 -0
- package/dest/events/private_event_filter_validator.d.ts +8 -0
- package/dest/events/private_event_filter_validator.d.ts.map +1 -0
- package/dest/events/private_event_filter_validator.js +39 -0
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.js +2 -2
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +3 -3
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +7 -7
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +1 -1
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/index.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +4 -4
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +26 -25
- package/dest/private_kernel/private_kernel_oracle.d.ts +3 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +6 -5
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
- package/dest/pxe.d.ts +26 -19
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +35 -50
- package/dest/storage/address_data_provider/address_data_provider.d.ts +1 -1
- package/dest/storage/address_data_provider/address_data_provider.d.ts.map +1 -1
- package/dest/storage/address_data_provider/index.d.ts +1 -1
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +2 -2
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
- package/dest/storage/capsule_data_provider/capsule_data_provider.js +1 -1
- package/dest/storage/capsule_data_provider/index.d.ts +1 -1
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts +3 -13
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
- package/dest/storage/contract_data_provider/contract_data_provider.js +0 -12
- package/dest/storage/contract_data_provider/index.d.ts +1 -1
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts +1 -1
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +1 -1
- package/dest/storage/contract_data_provider/private_functions_tree.js +1 -1
- package/dest/storage/index.d.ts +1 -1
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/note_data_provider/index.d.ts +2 -2
- 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 +8 -7
- package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
- package/dest/storage/note_data_provider/note_data_provider.js +27 -13
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +30 -14
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +1 -1
- package/dest/storage/private_event_data_provider/private_event_data_provider.js +47 -25
- package/dest/storage/sync_data_provider/index.d.ts +1 -1
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts +3 -2
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +1 -1
- package/dest/storage/tagging_data_provider/index.d.ts +1 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +1 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +1 -1
- package/dest/synchronizer/index.d.ts +1 -1
- package/dest/synchronizer/synchronizer.d.ts +3 -2
- package/dest/synchronizer/synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/synchronizer.js +2 -1
- package/dest/tagging/constants.d.ts +1 -1
- package/dest/tagging/index.d.ts +1 -1
- package/dest/tagging/siloed_tag.d.ts +2 -2
- package/dest/tagging/siloed_tag.d.ts.map +1 -1
- package/dest/tagging/siloed_tag.js +1 -1
- package/dest/tagging/tag.d.ts +2 -2
- package/dest/tagging/tag.d.ts.map +1 -1
- package/dest/tagging/tag.js +1 -1
- package/dest/tagging/utils.d.ts +1 -1
- package/package.json +20 -19
- package/src/bin/check_oracle_version.ts +130 -20
- package/src/config/index.ts +8 -23
- package/src/contract_function_simulator/contract_function_simulator.ts +23 -18
- package/src/contract_function_simulator/execution_data_provider.ts +18 -18
- package/src/contract_function_simulator/execution_note_cache.ts +22 -11
- package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -2
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +14 -2
- package/src/contract_function_simulator/noir-structs/utility_context.ts +1 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +24 -8
- package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +21 -5
- package/src/contract_function_simulator/oracle/oracle.ts +40 -10
- package/src/contract_function_simulator/oracle/private_execution.ts +3 -2
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +17 -4
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +22 -9
- package/src/contract_function_simulator/pick_notes.ts +1 -1
- package/src/contract_function_simulator/pxe_oracle_interface.ts +98 -59
- package/src/entrypoints/client/bundle/utils.ts +10 -4
- package/src/entrypoints/client/lazy/utils.ts +10 -5
- package/src/entrypoints/pxe_creation_options.ts +4 -1
- package/src/entrypoints/server/utils.ts +13 -31
- package/src/events/index.ts +1 -0
- package/src/events/private_event_filter_validator.ts +47 -0
- package/src/oracle_version.ts +2 -2
- package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +5 -9
- package/src/private_kernel/private_kernel_execution_prover.ts +27 -31
- package/src/private_kernel/private_kernel_oracle.ts +2 -1
- package/src/private_kernel/private_kernel_oracle_impl.ts +4 -3
- package/src/pxe.ts +50 -75
- package/src/storage/capsule_data_provider/capsule_data_provider.ts +1 -1
- package/src/storage/contract_data_provider/contract_data_provider.ts +1 -18
- package/src/storage/contract_data_provider/private_functions_tree.ts +1 -1
- package/src/storage/note_data_provider/index.ts +1 -1
- package/src/storage/note_data_provider/note_data_provider.ts +34 -15
- package/src/storage/private_event_data_provider/private_event_data_provider.ts +69 -35
- package/src/storage/sync_data_provider/sync_data_provider.ts +2 -1
- package/src/synchronizer/synchronizer.ts +2 -1
- package/src/tagging/siloed_tag.ts +2 -2
- package/src/tagging/tag.ts +2 -2
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto/keys';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
5
5
|
import { Timer } from '@aztec/foundation/timer';
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
type PrivateKernelTailCircuitPublicInputs,
|
|
24
24
|
PrivateVerificationKeyHints,
|
|
25
25
|
} from '@aztec/stdlib/kernel';
|
|
26
|
-
import {
|
|
26
|
+
import { ChonkProof, ChonkProofWithPublicInputs } from '@aztec/stdlib/proofs';
|
|
27
27
|
import {
|
|
28
28
|
type PrivateCallExecutionResult,
|
|
29
29
|
type PrivateExecutionResult,
|
|
@@ -53,7 +53,7 @@ export interface PrivateKernelExecutionProverConfig {
|
|
|
53
53
|
/**
|
|
54
54
|
* The PrivateKernelExecutionProver class is responsible for taking a transaction request and sequencing the
|
|
55
55
|
* the execution of the private functions within, sequenced with private kernel "glue" to check protocol rules.
|
|
56
|
-
* The result can be a
|
|
56
|
+
* The result can be a chonk proof of the private transaction portion, or just a simulation that can e.g.
|
|
57
57
|
* inform state tree updates.
|
|
58
58
|
*/
|
|
59
59
|
export class PrivateKernelExecutionProver {
|
|
@@ -103,9 +103,8 @@ export class PrivateKernelExecutionProver {
|
|
|
103
103
|
|
|
104
104
|
const noteHashLeafIndexMap = collectNoteHashLeafIndexMap(executionResult);
|
|
105
105
|
const noteHashNullifierCounterMap = collectNoteHashNullifierCounterMap(executionResult);
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
: getFinalMinRevertibleSideEffectCounter(executionResult);
|
|
106
|
+
const minRevertibleSideEffectCounter = getFinalMinRevertibleSideEffectCounter(executionResult);
|
|
107
|
+
const splitCounter = isPrivateOnlyTx ? 0 : minRevertibleSideEffectCounter;
|
|
109
108
|
|
|
110
109
|
while (executionStack.length) {
|
|
111
110
|
if (!firstIteration) {
|
|
@@ -113,7 +112,7 @@ export class PrivateKernelExecutionProver {
|
|
|
113
112
|
output,
|
|
114
113
|
executionStack,
|
|
115
114
|
noteHashNullifierCounterMap,
|
|
116
|
-
|
|
115
|
+
splitCounter,
|
|
117
116
|
);
|
|
118
117
|
while (resetBuilder.needsReset()) {
|
|
119
118
|
const witgenTimer = new Timer();
|
|
@@ -134,7 +133,7 @@ export class PrivateKernelExecutionProver {
|
|
|
134
133
|
output,
|
|
135
134
|
executionStack,
|
|
136
135
|
noteHashNullifierCounterMap,
|
|
137
|
-
|
|
136
|
+
splitCounter,
|
|
138
137
|
);
|
|
139
138
|
}
|
|
140
139
|
}
|
|
@@ -171,6 +170,7 @@ export class PrivateKernelExecutionProver {
|
|
|
171
170
|
privateCallData,
|
|
172
171
|
isPrivateOnlyTx,
|
|
173
172
|
executionResult.firstNullifier,
|
|
173
|
+
minRevertibleSideEffectCounter,
|
|
174
174
|
);
|
|
175
175
|
this.log.debug(
|
|
176
176
|
`Calling private kernel init with isPrivateOnly ${isPrivateOnlyTx} and firstNullifierHint ${proofInput.firstNullifierHint}`,
|
|
@@ -220,7 +220,7 @@ export class PrivateKernelExecutionProver {
|
|
|
220
220
|
output,
|
|
221
221
|
[],
|
|
222
222
|
noteHashNullifierCounterMap,
|
|
223
|
-
|
|
223
|
+
splitCounter,
|
|
224
224
|
);
|
|
225
225
|
while (resetBuilder.needsReset()) {
|
|
226
226
|
const witgenTimer = new Timer();
|
|
@@ -239,12 +239,7 @@ export class PrivateKernelExecutionProver {
|
|
|
239
239
|
},
|
|
240
240
|
});
|
|
241
241
|
|
|
242
|
-
resetBuilder = new PrivateKernelResetPrivateInputsBuilder(
|
|
243
|
-
output,
|
|
244
|
-
[],
|
|
245
|
-
noteHashNullifierCounterMap,
|
|
246
|
-
validationRequestsSplitCounter,
|
|
247
|
-
);
|
|
242
|
+
resetBuilder = new PrivateKernelResetPrivateInputsBuilder(output, [], noteHashNullifierCounterMap, splitCounter);
|
|
248
243
|
}
|
|
249
244
|
|
|
250
245
|
if (output.publicInputs.feePayer.isZero() && skipFeeEnforcement) {
|
|
@@ -295,8 +290,8 @@ export class PrivateKernelExecutionProver {
|
|
|
295
290
|
},
|
|
296
291
|
});
|
|
297
292
|
|
|
298
|
-
// Hiding
|
|
299
|
-
// For simulation, we can end with the tail, since the
|
|
293
|
+
// Hiding kernel is only executed if we are generating witnesses.
|
|
294
|
+
// For simulation, we can end with the tail, since the Hiding kernel will simply return the same tail output.
|
|
300
295
|
if (generateWitnesses) {
|
|
301
296
|
const previousKernelVkData = await this.getVkData(tailOutput.verificationKey);
|
|
302
297
|
|
|
@@ -347,50 +342,50 @@ export class PrivateKernelExecutionProver {
|
|
|
347
342
|
this.log.info(`Private kernel witness generation took ${timer.ms()}ms`);
|
|
348
343
|
}
|
|
349
344
|
|
|
350
|
-
let
|
|
345
|
+
let chonkProof: ChonkProof;
|
|
351
346
|
// TODO(#7368) how do we 'bincode' encode these inputs?
|
|
352
347
|
let provingTime;
|
|
353
348
|
if (!skipProofGeneration) {
|
|
354
349
|
const provingTimer = new Timer();
|
|
355
|
-
const proofWithPublicInputs = await this.proofCreator.
|
|
350
|
+
const proofWithPublicInputs = await this.proofCreator.createChonkProof(executionSteps);
|
|
356
351
|
provingTime = provingTimer.ms();
|
|
357
352
|
this.ensurePublicInputsMatch(proofWithPublicInputs, tailOutput.publicInputs);
|
|
358
|
-
|
|
353
|
+
chonkProof = proofWithPublicInputs.removePublicInputs();
|
|
359
354
|
} else {
|
|
360
|
-
|
|
355
|
+
chonkProof = ChonkProof.random();
|
|
361
356
|
}
|
|
362
357
|
|
|
363
358
|
return {
|
|
364
359
|
publicInputs: tailOutput.publicInputs,
|
|
365
360
|
executionSteps,
|
|
366
|
-
|
|
361
|
+
chonkProof,
|
|
367
362
|
timings: provingTime ? { proving: provingTime } : undefined,
|
|
368
363
|
};
|
|
369
364
|
}
|
|
370
365
|
|
|
371
366
|
/**
|
|
372
|
-
* Checks that the public inputs of the
|
|
367
|
+
* Checks that the public inputs of the chonk proof match the public inputs of the tail circuit.
|
|
373
368
|
* This can only mismatch if there is a circuit / noir / bb bug.
|
|
374
|
-
* @param
|
|
369
|
+
* @param chonkProof - The chonk proof with public inputs.
|
|
375
370
|
* @param tailPublicInputs - The public inputs resulting from witness generation of the tail circuit.
|
|
376
371
|
*/
|
|
377
372
|
private ensurePublicInputsMatch(
|
|
378
|
-
|
|
373
|
+
chonkProof: ChonkProofWithPublicInputs,
|
|
379
374
|
tailPublicInputs: PrivateKernelTailCircuitPublicInputs,
|
|
380
375
|
) {
|
|
381
|
-
const
|
|
376
|
+
const serializedChonkProofPublicInputs = chonkProof.getPublicInputs();
|
|
382
377
|
const serializedTailPublicInputs = tailPublicInputs.publicInputs().toFields();
|
|
383
|
-
if (
|
|
378
|
+
if (serializedChonkProofPublicInputs.length !== serializedTailPublicInputs.length) {
|
|
384
379
|
throw new Error(
|
|
385
|
-
`Public inputs length mismatch: ${
|
|
380
|
+
`Public inputs length mismatch: ${serializedChonkProofPublicInputs.length} !== ${serializedTailPublicInputs.length}`,
|
|
386
381
|
);
|
|
387
382
|
}
|
|
388
383
|
if (
|
|
389
|
-
!
|
|
384
|
+
!serializedChonkProofPublicInputs.every((input: Fr, index: number) =>
|
|
390
385
|
input.equals(serializedTailPublicInputs[index]),
|
|
391
386
|
)
|
|
392
387
|
) {
|
|
393
|
-
throw new Error(`Public inputs mismatch between kernel and
|
|
388
|
+
throw new Error(`Public inputs mismatch between kernel and chonk proof`);
|
|
394
389
|
}
|
|
395
390
|
}
|
|
396
391
|
|
|
@@ -420,6 +415,7 @@ export class PrivateKernelExecutionProver {
|
|
|
420
415
|
await this.oracle.getContractClassIdPreimage(currentContractClassId);
|
|
421
416
|
|
|
422
417
|
const updatedClassIdHints = await this.oracle.getUpdatedClassIdHints(contractAddress);
|
|
418
|
+
|
|
423
419
|
return PrivateCallData.from({
|
|
424
420
|
publicInputs,
|
|
425
421
|
vk,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FUNCTION_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT, VK_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import type { Fr
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import type { GrumpkinScalar, Point } from '@aztec/foundation/curves/grumpkin';
|
|
3
4
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
4
5
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
6
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NOTE_HASH_TREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT, VK_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import type { Fr
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import type { GrumpkinScalar, Point } from '@aztec/foundation/curves/grumpkin';
|
|
3
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
5
6
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
@@ -8,7 +9,7 @@ import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-type
|
|
|
8
9
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
9
10
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
10
11
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
|
-
import type {
|
|
12
|
+
import type { BlockParameter } from '@aztec/stdlib/block';
|
|
12
13
|
import { computeContractClassIdPreimage, computeSaltedInitializationHash } from '@aztec/stdlib/contract';
|
|
13
14
|
import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
|
|
14
15
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
@@ -31,7 +32,7 @@ export class PrivateKernelOracleImpl implements PrivateKernelOracle {
|
|
|
31
32
|
private contractDataProvider: ContractDataProvider,
|
|
32
33
|
private keyStore: KeyStore,
|
|
33
34
|
private node: AztecNode,
|
|
34
|
-
private blockNumber:
|
|
35
|
+
private blockNumber: BlockParameter = 'latest',
|
|
35
36
|
private log = createLogger('pxe:kernel_oracle'),
|
|
36
37
|
) {}
|
|
37
38
|
|
package/src/pxe.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
4
5
|
import { Timer } from '@aztec/foundation/timer';
|
|
@@ -9,11 +10,10 @@ import { type ProtocolContractsProvider, protocolContractNames } from '@aztec/pr
|
|
|
9
10
|
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
10
11
|
import {
|
|
11
12
|
type ContractArtifact,
|
|
12
|
-
|
|
13
|
+
EventSelector,
|
|
13
14
|
FunctionCall,
|
|
14
15
|
FunctionSelector,
|
|
15
16
|
FunctionType,
|
|
16
|
-
decodeFromAbi,
|
|
17
17
|
decodeFunctionSignature,
|
|
18
18
|
encodeArguments,
|
|
19
19
|
} from '@aztec/stdlib/abi';
|
|
@@ -28,16 +28,18 @@ import {
|
|
|
28
28
|
getContractClassFromArtifact,
|
|
29
29
|
} from '@aztec/stdlib/contract';
|
|
30
30
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
31
|
-
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
31
|
+
import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
|
|
32
32
|
import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
|
|
33
33
|
import type {
|
|
34
34
|
PrivateExecutionStep,
|
|
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,
|
|
42
|
+
type InTx,
|
|
41
43
|
PrivateExecutionResult,
|
|
42
44
|
PrivateSimulationResult,
|
|
43
45
|
type ProvingTimings,
|
|
@@ -64,6 +66,7 @@ import { ProxiedContractDataProviderFactory } from './contract_function_simulato
|
|
|
64
66
|
import { ProxiedNodeFactory } from './contract_function_simulator/proxied_node.js';
|
|
65
67
|
import { PXEOracleInterface } from './contract_function_simulator/pxe_oracle_interface.js';
|
|
66
68
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
69
|
+
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
67
70
|
import {
|
|
68
71
|
PrivateKernelExecutionProver,
|
|
69
72
|
type PrivateKernelExecutionProverConfig,
|
|
@@ -78,6 +81,11 @@ import { SyncDataProvider } from './storage/sync_data_provider/sync_data_provide
|
|
|
78
81
|
import { TaggingDataProvider } from './storage/tagging_data_provider/tagging_data_provider.js';
|
|
79
82
|
import { Synchronizer } from './synchronizer/index.js';
|
|
80
83
|
|
|
84
|
+
export type PackedPrivateEvent = InTx & {
|
|
85
|
+
packedEvent: Fr[];
|
|
86
|
+
eventSelector: EventSelector;
|
|
87
|
+
};
|
|
88
|
+
|
|
81
89
|
/**
|
|
82
90
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
83
91
|
* manage private state of users.
|
|
@@ -250,7 +258,7 @@ export class PXE {
|
|
|
250
258
|
const contract = await this.contractDataProvider.getContract(to);
|
|
251
259
|
if (!contract) {
|
|
252
260
|
throw new Error(
|
|
253
|
-
`Unknown contract ${to}: add it to PXE by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/
|
|
261
|
+
`Unknown contract ${to}: add it to PXE by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`,
|
|
254
262
|
);
|
|
255
263
|
}
|
|
256
264
|
|
|
@@ -362,7 +370,7 @@ export class PXE {
|
|
|
362
370
|
* @param proofCreator - The proof creator to use for proving the execution.
|
|
363
371
|
* @param privateExecutionResult - The result of the private execution
|
|
364
372
|
* @param config - The configuration for the kernel execution prover.
|
|
365
|
-
* @returns An object that contains the output of the kernel execution, including the
|
|
373
|
+
* @returns An object that contains the output of the kernel execution, including the ChonkProof if proving is enabled.
|
|
366
374
|
*/
|
|
367
375
|
async #prove(
|
|
368
376
|
txExecutionRequest: TxExecutionRequest,
|
|
@@ -662,25 +670,12 @@ export class PXE {
|
|
|
662
670
|
* @param filter - The filter to apply to the notes.
|
|
663
671
|
* @returns The requested notes.
|
|
664
672
|
*/
|
|
665
|
-
public async getNotes(filter: NotesFilter): Promise<
|
|
673
|
+
public async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
666
674
|
// We need to manually trigger private state sync to have a guarantee that all the notes are available.
|
|
667
|
-
await this
|
|
668
|
-
|
|
669
|
-
const noteDaos = await this.noteDataProvider.getNotes(filter);
|
|
675
|
+
const call = await this.#getFunctionCall('sync_private_state', [], filter.contractAddress);
|
|
676
|
+
await this.simulateUtility(call);
|
|
670
677
|
|
|
671
|
-
|
|
672
|
-
const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
|
|
673
|
-
const completeAddressIndex = completeAddresses.findIndex(completeAddress =>
|
|
674
|
-
completeAddress.address.equals(dao.recipient),
|
|
675
|
-
);
|
|
676
|
-
const completeAddress = completeAddresses[completeAddressIndex];
|
|
677
|
-
if (completeAddress === undefined) {
|
|
678
|
-
throw new Error(`Cannot find complete address for recipient ${dao.recipient.toString()}`);
|
|
679
|
-
}
|
|
680
|
-
const recipient = completeAddress.address;
|
|
681
|
-
return new UniqueNote(dao.note, recipient, dao.contractAddress, dao.storageSlot, dao.txHash, dao.noteNonce);
|
|
682
|
-
});
|
|
683
|
-
return Promise.all(uniqueNotes);
|
|
678
|
+
return this.noteDataProvider.getNotes(filter);
|
|
684
679
|
}
|
|
685
680
|
|
|
686
681
|
/**
|
|
@@ -707,7 +702,7 @@ export class PXE {
|
|
|
707
702
|
|
|
708
703
|
const {
|
|
709
704
|
publicInputs,
|
|
710
|
-
|
|
705
|
+
chonkProof,
|
|
711
706
|
executionSteps,
|
|
712
707
|
timings: { proving } = {},
|
|
713
708
|
} = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
@@ -735,7 +730,7 @@ export class PXE {
|
|
|
735
730
|
|
|
736
731
|
this.log.debug(`Proving completed in ${totalTime}ms`, { timings });
|
|
737
732
|
|
|
738
|
-
const txProvingResult = new TxProvingResult(privateExecutionResult, publicInputs,
|
|
733
|
+
const txProvingResult = new TxProvingResult(privateExecutionResult, publicInputs, chonkProof!, {
|
|
739
734
|
timings,
|
|
740
735
|
nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
|
|
741
736
|
});
|
|
@@ -905,10 +900,9 @@ export class PXE {
|
|
|
905
900
|
|
|
906
901
|
if (skipKernels) {
|
|
907
902
|
// According to the protocol rules, the nonce generator for the note hashes
|
|
908
|
-
// can either be the first nullifier in the tx or the
|
|
909
|
-
// if there are none.
|
|
903
|
+
// can either be the first nullifier in the tx or the protocol nullifier if there are none.
|
|
910
904
|
const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
|
|
911
|
-
? await txRequest.toTxRequest().hash()
|
|
905
|
+
? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
|
|
912
906
|
: privateExecutionResult.firstNullifier;
|
|
913
907
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
914
908
|
privateExecutionResult,
|
|
@@ -1000,21 +994,15 @@ export class PXE {
|
|
|
1000
994
|
/**
|
|
1001
995
|
* Simulate the execution of a contract utility function.
|
|
1002
996
|
*
|
|
1003
|
-
* @param
|
|
1004
|
-
* @param args - The arguments to be provided to the function.
|
|
1005
|
-
* @param to - The address of the contract to be called.
|
|
997
|
+
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
1006
998
|
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
1007
|
-
* @param from - (Optional) The msg sender to set for the call.
|
|
1008
999
|
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
1009
1000
|
* default to all.
|
|
1010
1001
|
* @returns The result of the utility function call, structured based on the function ABI.
|
|
1011
1002
|
*/
|
|
1012
1003
|
public simulateUtility(
|
|
1013
|
-
|
|
1014
|
-
args: any[],
|
|
1015
|
-
to: AztecAddress,
|
|
1004
|
+
call: FunctionCall,
|
|
1016
1005
|
authwits?: AuthWitness[],
|
|
1017
|
-
_from?: AztecAddress,
|
|
1018
1006
|
scopes?: AztecAddress[],
|
|
1019
1007
|
): Promise<UtilitySimulationResult> {
|
|
1020
1008
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
@@ -1026,20 +1014,14 @@ export class PXE {
|
|
|
1026
1014
|
const syncTimer = new Timer();
|
|
1027
1015
|
await this.synchronizer.sync();
|
|
1028
1016
|
const syncTime = syncTimer.ms();
|
|
1029
|
-
const functionCall = await this.#getFunctionCall(functionName, args, to);
|
|
1030
1017
|
const functionTimer = new Timer();
|
|
1031
1018
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1032
|
-
const executionResult = await this.#simulateUtility(
|
|
1033
|
-
contractFunctionSimulator,
|
|
1034
|
-
functionCall,
|
|
1035
|
-
authwits ?? [],
|
|
1036
|
-
scopes,
|
|
1037
|
-
);
|
|
1019
|
+
const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes);
|
|
1038
1020
|
const functionTime = functionTimer.ms();
|
|
1039
1021
|
|
|
1040
1022
|
const totalTime = totalTimer.ms();
|
|
1041
1023
|
|
|
1042
|
-
const perFunction = [{ functionName, time: functionTime }];
|
|
1024
|
+
const perFunction = [{ functionName: call.name, time: functionTime }];
|
|
1043
1025
|
|
|
1044
1026
|
const timings: SimulationTimings = {
|
|
1045
1027
|
total: totalTime,
|
|
@@ -1051,10 +1033,11 @@ export class PXE {
|
|
|
1051
1033
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
1052
1034
|
return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
|
|
1053
1035
|
} catch (err: any) {
|
|
1036
|
+
const { to, name, args } = call;
|
|
1054
1037
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1055
1038
|
throw this.#contextualizeError(
|
|
1056
1039
|
err,
|
|
1057
|
-
`simulateUtility ${to}:${
|
|
1040
|
+
`simulateUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1058
1041
|
`scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
|
|
1059
1042
|
);
|
|
1060
1043
|
}
|
|
@@ -1063,40 +1046,32 @@ export class PXE {
|
|
|
1063
1046
|
|
|
1064
1047
|
/**
|
|
1065
1048
|
* Returns the private events given search parameters.
|
|
1066
|
-
* @param
|
|
1067
|
-
* @param
|
|
1068
|
-
*
|
|
1069
|
-
*
|
|
1070
|
-
*
|
|
1071
|
-
*
|
|
1049
|
+
* @param eventSelector - Event selector to search for.
|
|
1050
|
+
* @param filter
|
|
1051
|
+
* contractAddress - The address of the contract to get events from. Required.
|
|
1052
|
+
* scopes - One or more event scope addresses to filter by. Required.
|
|
1053
|
+
* fromBlock - The block number to search from (inclusive). Optional. If provided, it must be >= 0.
|
|
1054
|
+
* Defaults to 0.
|
|
1055
|
+
* If toBlock is defined but fromBlock is not, fromBlock defaults to toBlock - 1.
|
|
1056
|
+
* toBlock - The block number to search up to (exclusive). Optional. If provided, it must be > 0.
|
|
1057
|
+
* Defaults to the latest known block to PXE + 1.
|
|
1058
|
+
* @returns - The packed events with block and tx metadata.
|
|
1072
1059
|
*/
|
|
1073
|
-
public async getPrivateEvents
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
if (recipients.length === 0) {
|
|
1081
|
-
throw new Error('Recipients are required to get private events');
|
|
1082
|
-
}
|
|
1060
|
+
public async getPrivateEvents(
|
|
1061
|
+
eventSelector: EventSelector,
|
|
1062
|
+
filter: PrivateEventFilter,
|
|
1063
|
+
): Promise<PackedPrivateEvent[]> {
|
|
1064
|
+
// We need to manually trigger private state sync to have a guarantee that all the events are available.
|
|
1065
|
+
const call = await this.#getFunctionCall('sync_private_state', [], filter.contractAddress);
|
|
1066
|
+
await this.simulateUtility(call);
|
|
1083
1067
|
|
|
1084
|
-
|
|
1068
|
+
const sanitizedFilter = await new PrivateEventFilterValidator(this.syncDataProvider).validate(filter);
|
|
1085
1069
|
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
const events = await this.privateEventDataProvider.getPrivateEvents(
|
|
1090
|
-
contractAddress,
|
|
1091
|
-
from,
|
|
1092
|
-
numBlocks,
|
|
1093
|
-
recipients,
|
|
1094
|
-
eventMetadataDef.eventSelector,
|
|
1070
|
+
this.log.error(
|
|
1071
|
+
`Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
|
|
1095
1072
|
);
|
|
1096
1073
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
return decodedEvents;
|
|
1074
|
+
return this.privateEventDataProvider.getPrivateEvents(eventSelector, sanitizedFilter);
|
|
1100
1075
|
}
|
|
1101
1076
|
|
|
1102
1077
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FUNCTION_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import type { Fr } from '@aztec/foundation/
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
4
4
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
5
5
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
@@ -184,23 +184,6 @@ export class ContractDataProvider {
|
|
|
184
184
|
return fnArtifact && { ...fnArtifact, contractName: artifact.name };
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
/**
|
|
188
|
-
* Retrieves the artifact of a specified function within a given contract.
|
|
189
|
-
* The function is identified by its name, which is unique within a contract.
|
|
190
|
-
* Throws if the contract has not been added to the database.
|
|
191
|
-
*
|
|
192
|
-
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
193
|
-
* @param functionName - The name of the function.
|
|
194
|
-
* @returns The corresponding function's artifact as an object
|
|
195
|
-
*/
|
|
196
|
-
public async getFunctionArtifactByName(
|
|
197
|
-
contractAddress: AztecAddress,
|
|
198
|
-
functionName: string,
|
|
199
|
-
): Promise<FunctionArtifact | undefined> {
|
|
200
|
-
const artifact = await this.#getContractArtifactByAddress(contractAddress);
|
|
201
|
-
return artifact?.functions.find(fn => fn.name === functionName);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
187
|
public async getFunctionAbi(
|
|
205
188
|
contractAddress: AztecAddress,
|
|
206
189
|
selector: FunctionSelector,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FUNCTION_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
4
4
|
import { MembershipWitness, type MerkleTree } from '@aztec/foundation/trees';
|
|
5
5
|
import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { NoteDao } from '
|
|
1
|
+
export { NoteDao } from '@aztec/stdlib/note';
|
|
2
2
|
export { NoteDataProvider } from './note_data_provider.js';
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
2
|
-
import type { Fr } from '@aztec/foundation/
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
4
4
|
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
|
|
5
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
-
import type {
|
|
6
|
+
import type { DataInBlock } 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) {
|
|
@@ -223,8 +224,9 @@ export class NoteDataProvider {
|
|
|
223
224
|
* parameters.
|
|
224
225
|
*
|
|
225
226
|
* @param filter - Filter criteria including contractAddress (required), and optional
|
|
226
|
-
* storageSlot, status, scopes and siloedNullifier.
|
|
227
|
-
* @returns
|
|
227
|
+
* owner, storageSlot, status, scopes, and siloedNullifier.
|
|
228
|
+
* @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
|
|
229
|
+
* returned once if this is the case)
|
|
228
230
|
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
229
231
|
*/
|
|
230
232
|
async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
@@ -306,6 +308,10 @@ export class NoteDataProvider {
|
|
|
306
308
|
continue;
|
|
307
309
|
}
|
|
308
310
|
|
|
311
|
+
if (filter.owner && !note.owner.equals(filter.owner)) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
|
|
309
315
|
if (filter.storageSlot && !note.storageSlot.equals(filter.storageSlot!)) {
|
|
310
316
|
continue;
|
|
311
317
|
}
|
|
@@ -318,7 +324,15 @@ export class NoteDataProvider {
|
|
|
318
324
|
}
|
|
319
325
|
}
|
|
320
326
|
|
|
321
|
-
|
|
327
|
+
// A note might be present in multiple scopes - we ensure it is only returned once
|
|
328
|
+
const deduplicated: NoteDao[] = [];
|
|
329
|
+
for (const note of result) {
|
|
330
|
+
if (!deduplicated.some(existing => existing.equals(note))) {
|
|
331
|
+
deduplicated.push(note);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return deduplicated;
|
|
322
336
|
}
|
|
323
337
|
|
|
324
338
|
/**
|
|
@@ -332,7 +346,7 @@ export class NoteDataProvider {
|
|
|
332
346
|
* @returns Promise resolving to array of nullified NoteDao objects
|
|
333
347
|
* @throws Error if any nullifier is not found in the active notes
|
|
334
348
|
*/
|
|
335
|
-
applyNullifiers(nullifiers:
|
|
349
|
+
applyNullifiers(nullifiers: DataInBlock<Fr>[]): Promise<NoteDao[]> {
|
|
336
350
|
if (nullifiers.length === 0) {
|
|
337
351
|
return Promise.resolve([]);
|
|
338
352
|
}
|
|
@@ -359,7 +373,14 @@ export class NoteDataProvider {
|
|
|
359
373
|
if (!noteBuffer) {
|
|
360
374
|
throw new Error('Note not found in applyNullifiers');
|
|
361
375
|
}
|
|
362
|
-
|
|
376
|
+
|
|
377
|
+
const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteIndex));
|
|
378
|
+
if (noteScopes.length === 0) {
|
|
379
|
+
// We should never run into this error because notes always have a scope assigned to them - either on initial
|
|
380
|
+
// insertion via `addNotes` or when removing their nullifiers.
|
|
381
|
+
throw new Error('Note scopes are missing in applyNullifiers');
|
|
382
|
+
}
|
|
383
|
+
|
|
363
384
|
const note = NoteDao.fromBuffer(noteBuffer);
|
|
364
385
|
|
|
365
386
|
nullifiedNotes.push(note);
|
|
@@ -374,10 +395,8 @@ export class NoteDataProvider {
|
|
|
374
395
|
await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(note.storageSlot.toString(), noteIndex);
|
|
375
396
|
}
|
|
376
397
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
await this.#nullifiedNotesToScope.set(noteIndex, scope);
|
|
380
|
-
}
|
|
398
|
+
for (const scope of noteScopes) {
|
|
399
|
+
await this.#nullifiedNotesToScope.set(noteIndex, scope);
|
|
381
400
|
}
|
|
382
401
|
await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
|
|
383
402
|
await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
|