@aztec/pxe 0.40.1 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dest/database/kv_pxe_database.d.ts +1 -1
  2. package/dest/database/kv_pxe_database.js +2 -2
  3. package/dest/database/pxe_database.d.ts +5 -5
  4. package/dest/kernel_oracle/index.d.ts +7 -4
  5. package/dest/kernel_oracle/index.d.ts.map +1 -1
  6. package/dest/kernel_oracle/index.js +20 -4
  7. package/dest/kernel_prover/kernel_prover.d.ts.map +1 -1
  8. package/dest/kernel_prover/kernel_prover.js +17 -17
  9. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_init_hints.d.ts +3 -0
  10. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_init_hints.d.ts.map +1 -0
  11. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_init_hints.js +11 -0
  12. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.d.ts +4 -0
  13. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.d.ts.map +1 -0
  14. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.js +59 -0
  15. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_outputs.d.ts +4 -0
  16. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_outputs.d.ts.map +1 -0
  17. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_reset_outputs.js +12 -0
  18. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_tail_hints.d.ts +1 -2
  19. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_tail_hints.d.ts.map +1 -1
  20. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_tail_hints.js +7 -53
  21. package/dest/kernel_prover/private_inputs_builders/index.d.ts +3 -1
  22. package/dest/kernel_prover/private_inputs_builders/index.d.ts.map +1 -1
  23. package/dest/kernel_prover/private_inputs_builders/index.js +4 -2
  24. package/dest/kernel_prover/proving_data_oracle.d.ts +8 -6
  25. package/dest/kernel_prover/proving_data_oracle.d.ts.map +1 -1
  26. package/dest/kernel_prover/test/test_circuit_prover.d.ts +2 -1
  27. package/dest/kernel_prover/test/test_circuit_prover.d.ts.map +1 -1
  28. package/dest/kernel_prover/test/test_circuit_prover.js +14 -3
  29. package/dest/note_processor/note_processor.d.ts +2 -1
  30. package/dest/note_processor/note_processor.d.ts.map +1 -1
  31. package/dest/note_processor/note_processor.js +3 -2
  32. package/dest/note_processor/produce_note_dao.js +4 -20
  33. package/dest/pxe_service/create_pxe_service.d.ts +1 -1
  34. package/dest/pxe_service/create_pxe_service.d.ts.map +1 -1
  35. package/dest/pxe_service/create_pxe_service.js +6 -5
  36. package/dest/pxe_service/pxe_service.d.ts +5 -4
  37. package/dest/pxe_service/pxe_service.d.ts.map +1 -1
  38. package/dest/pxe_service/pxe_service.js +10 -12
  39. package/dest/pxe_service/test/pxe_test_suite.js +2 -2
  40. package/dest/simulator/index.d.ts +2 -1
  41. package/dest/simulator/index.d.ts.map +1 -1
  42. package/dest/simulator/index.js +1 -1
  43. package/dest/simulator_oracle/index.d.ts +6 -5
  44. package/dest/simulator_oracle/index.d.ts.map +1 -1
  45. package/dest/simulator_oracle/index.js +7 -8
  46. package/dest/synchronizer/synchronizer.d.ts +2 -1
  47. package/dest/synchronizer/synchronizer.d.ts.map +1 -1
  48. package/dest/synchronizer/synchronizer.js +8 -8
  49. package/package.json +14 -14
  50. package/src/database/kv_pxe_database.ts +2 -2
  51. package/src/database/pxe_database.ts +5 -5
  52. package/src/kernel_oracle/index.ts +29 -4
  53. package/src/kernel_prover/kernel_prover.ts +35 -26
  54. package/src/kernel_prover/private_inputs_builders/build_private_kernel_init_hints.ts +28 -0
  55. package/src/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.ts +179 -0
  56. package/src/kernel_prover/private_inputs_builders/{build_private_kernel_tail_outputs.ts → build_private_kernel_reset_outputs.ts} +14 -3
  57. package/src/kernel_prover/private_inputs_builders/build_private_kernel_tail_hints.ts +17 -126
  58. package/src/kernel_prover/private_inputs_builders/index.ts +3 -1
  59. package/src/kernel_prover/proving_data_oracle.ts +9 -5
  60. package/src/kernel_prover/test/test_circuit_prover.ts +24 -3
  61. package/src/note_processor/note_processor.ts +3 -2
  62. package/src/note_processor/produce_note_dao.ts +3 -19
  63. package/src/pxe_service/create_pxe_service.ts +9 -6
  64. package/src/pxe_service/pxe_service.ts +14 -12
  65. package/src/pxe_service/test/pxe_test_suite.ts +1 -1
  66. package/src/simulator/index.ts +2 -1
  67. package/src/simulator_oracle/index.ts +9 -9
  68. package/src/synchronizer/synchronizer.ts +8 -14
  69. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_tail_outputs.d.ts +0 -4
  70. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_tail_outputs.d.ts.map +0 -1
  71. package/dest/kernel_prover/private_inputs_builders/build_private_kernel_tail_outputs.js +0 -10
@@ -0,0 +1,179 @@
1
+ import {
2
+ Fr,
3
+ KeyValidationHint,
4
+ MAX_KEY_VALIDATION_REQUESTS_PER_TX,
5
+ MAX_NEW_NOTE_HASHES_PER_TX,
6
+ MAX_NEW_NULLIFIERS_PER_TX,
7
+ MAX_NOTE_ENCRYPTED_LOGS_PER_TX,
8
+ MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
9
+ MAX_NULLIFIER_READ_REQUESTS_PER_TX,
10
+ MembershipWitness,
11
+ NULLIFIER_TREE_HEIGHT,
12
+ PRIVATE_RESET_VARIANTS,
13
+ type PrivateKernelData,
14
+ PrivateKernelResetCircuitPrivateInputs,
15
+ type PrivateKernelResetCircuitPrivateInputsVariants,
16
+ PrivateKernelResetHints,
17
+ type ScopedKeyValidationRequest,
18
+ type ScopedNullifier,
19
+ type ScopedReadRequest,
20
+ buildNoteHashReadRequestHints,
21
+ buildNullifierReadRequestHints,
22
+ buildTransientDataHints,
23
+ } from '@aztec/circuits.js';
24
+ import { makeTuple } from '@aztec/foundation/array';
25
+ import { type Tuple } from '@aztec/foundation/serialize';
26
+
27
+ import { type ProvingDataOracle } from '../proving_data_oracle.js';
28
+ import { buildPrivateKernelResetOutputs } from './build_private_kernel_reset_outputs.js';
29
+
30
+ function getNullifierReadRequestHints<PENDING extends number, SETTLED extends number>(
31
+ nullifierReadRequests: Tuple<ScopedReadRequest, typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>,
32
+ nullifiers: Tuple<ScopedNullifier, typeof MAX_NEW_NULLIFIERS_PER_TX>,
33
+ oracle: ProvingDataOracle,
34
+ sizePending: PENDING,
35
+ sizeSettled: SETTLED,
36
+ ) {
37
+ const getNullifierMembershipWitness = async (nullifier: Fr) => {
38
+ const res = await oracle.getNullifierMembershipWitness(nullifier);
39
+ if (!res) {
40
+ throw new Error(`Cannot find the leaf for nullifier ${nullifier.toBigInt()}.`);
41
+ }
42
+
43
+ const { index, siblingPath, leafPreimage } = res;
44
+ return {
45
+ membershipWitness: new MembershipWitness(
46
+ NULLIFIER_TREE_HEIGHT,
47
+ index,
48
+ siblingPath.toTuple<typeof NULLIFIER_TREE_HEIGHT>(),
49
+ ),
50
+ leafPreimage,
51
+ };
52
+ };
53
+
54
+ return buildNullifierReadRequestHints(
55
+ { getNullifierMembershipWitness },
56
+ nullifierReadRequests,
57
+ nullifiers,
58
+ sizePending,
59
+ sizeSettled,
60
+ );
61
+ }
62
+
63
+ async function getMasterSecretKeysAndAppKeyGenerators(
64
+ keyValidationRequests: Tuple<ScopedKeyValidationRequest, typeof MAX_KEY_VALIDATION_REQUESTS_PER_TX>,
65
+ oracle: ProvingDataOracle,
66
+ ) {
67
+ const keysHints = makeTuple(MAX_KEY_VALIDATION_REQUESTS_PER_TX, KeyValidationHint.empty);
68
+
69
+ let keyIndex = 0;
70
+ for (let i = 0; i < keyValidationRequests.length; ++i) {
71
+ const request = keyValidationRequests[i].request;
72
+ if (request.isEmpty()) {
73
+ break;
74
+ }
75
+ const [secretKeys, appKeyGenerator] = await oracle.getMasterSecretKeyAndAppKeyGenerator(request.masterPublicKey);
76
+ keysHints[keyIndex] = new KeyValidationHint(secretKeys, new Fr(appKeyGenerator), i);
77
+ keyIndex++;
78
+ }
79
+ return {
80
+ keysCount: keyIndex,
81
+ keysHints,
82
+ };
83
+ }
84
+
85
+ export async function buildPrivateKernelResetInputs(
86
+ previousKernelData: PrivateKernelData,
87
+ noteHashLeafIndexMap: Map<bigint, bigint>,
88
+ oracle: ProvingDataOracle,
89
+ ) {
90
+ const publicInputs = previousKernelData.publicInputs;
91
+ // Use max sizes, they will be trimmed down later.
92
+ const {
93
+ numPendingReadHints: noteHashPendingReadHints,
94
+ numSettledReadHints: noteHashSettledReadHints,
95
+ hints: noteHashReadRequestHints,
96
+ } = await buildNoteHashReadRequestHints(
97
+ oracle,
98
+ publicInputs.validationRequests.noteHashReadRequests,
99
+ publicInputs.end.newNoteHashes,
100
+ noteHashLeafIndexMap,
101
+ MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
102
+ MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
103
+ );
104
+
105
+ const {
106
+ numPendingReadHints: nullifierPendingReadHints,
107
+ numSettledReadHints: nullifierSettledReadHints,
108
+ hints: nullifierReadRequestHints,
109
+ } = await getNullifierReadRequestHints(
110
+ publicInputs.validationRequests.nullifierReadRequests,
111
+ publicInputs.end.newNullifiers,
112
+ oracle,
113
+ MAX_NULLIFIER_READ_REQUESTS_PER_TX,
114
+ MAX_NULLIFIER_READ_REQUESTS_PER_TX,
115
+ );
116
+
117
+ const { keysCount, keysHints } = await getMasterSecretKeysAndAppKeyGenerators(
118
+ publicInputs.validationRequests.keyValidationRequests,
119
+ oracle,
120
+ );
121
+
122
+ const [
123
+ transientNullifierIndexesForNoteHashes,
124
+ transientNoteHashIndexesForNullifiers,
125
+ transientNoteHashIndexesForLogs,
126
+ ] = buildTransientDataHints(
127
+ publicInputs.end.newNoteHashes,
128
+ publicInputs.end.newNullifiers,
129
+ publicInputs.end.noteEncryptedLogsHashes,
130
+ MAX_NEW_NOTE_HASHES_PER_TX,
131
+ MAX_NEW_NULLIFIERS_PER_TX,
132
+ MAX_NOTE_ENCRYPTED_LOGS_PER_TX,
133
+ );
134
+
135
+ const expectedOutputs = buildPrivateKernelResetOutputs(
136
+ previousKernelData.publicInputs.end.newNoteHashes,
137
+ previousKernelData.publicInputs.end.newNullifiers,
138
+ previousKernelData.publicInputs.end.noteEncryptedLogsHashes,
139
+ );
140
+
141
+ let privateInputs;
142
+
143
+ for (const [sizeTag, hintSizes] of Object.entries(PRIVATE_RESET_VARIANTS)) {
144
+ if (
145
+ hintSizes.NOTE_HASH_PENDING_AMOUNT >= noteHashPendingReadHints &&
146
+ hintSizes.NOTE_HASH_SETTLED_AMOUNT >= noteHashSettledReadHints &&
147
+ hintSizes.NULLIFIER_PENDING_AMOUNT >= nullifierPendingReadHints &&
148
+ hintSizes.NULLIFIER_SETTLED_AMOUNT >= nullifierSettledReadHints &&
149
+ hintSizes.NULLIFIER_KEYS >= keysCount
150
+ ) {
151
+ privateInputs = new PrivateKernelResetCircuitPrivateInputs(
152
+ previousKernelData,
153
+ expectedOutputs,
154
+ new PrivateKernelResetHints(
155
+ transientNullifierIndexesForNoteHashes,
156
+ transientNoteHashIndexesForNullifiers,
157
+ transientNoteHashIndexesForLogs,
158
+ noteHashReadRequestHints,
159
+ nullifierReadRequestHints,
160
+ keysHints,
161
+ ).trimToSizes(
162
+ hintSizes.NOTE_HASH_PENDING_AMOUNT,
163
+ hintSizes.NOTE_HASH_SETTLED_AMOUNT,
164
+ hintSizes.NULLIFIER_PENDING_AMOUNT,
165
+ hintSizes.NULLIFIER_SETTLED_AMOUNT,
166
+ hintSizes.NULLIFIER_KEYS,
167
+ ),
168
+ sizeTag,
169
+ );
170
+ break;
171
+ }
172
+ }
173
+
174
+ if (!privateInputs) {
175
+ throw new Error('No private inputs found for the given hint sizes.');
176
+ }
177
+
178
+ return privateInputs as PrivateKernelResetCircuitPrivateInputsVariants;
179
+ }
@@ -1,16 +1,19 @@
1
1
  import {
2
2
  MAX_NEW_NOTE_HASHES_PER_TX,
3
3
  MAX_NEW_NULLIFIERS_PER_TX,
4
- PrivateKernelTailOutputs,
4
+ MAX_NOTE_ENCRYPTED_LOGS_PER_TX,
5
+ NoteLogHash,
6
+ PrivateKernelResetOutputs,
5
7
  ScopedNoteHash,
6
8
  ScopedNullifier,
7
9
  } from '@aztec/circuits.js';
8
10
  import { padArrayEnd } from '@aztec/foundation/collection';
9
11
  import { type Tuple } from '@aztec/foundation/serialize';
10
12
 
11
- export function buildPrivateKernelTailOutputs(
13
+ export function buildPrivateKernelResetOutputs(
12
14
  prevNoteHashes: Tuple<ScopedNoteHash, typeof MAX_NEW_NOTE_HASHES_PER_TX>,
13
15
  prevNullifiers: Tuple<ScopedNullifier, typeof MAX_NEW_NULLIFIERS_PER_TX>,
16
+ prevLogs: Tuple<NoteLogHash, typeof MAX_NOTE_ENCRYPTED_LOGS_PER_TX>,
14
17
  ) {
15
18
  // Propagate note hashes that are not linked to a nullifier.
16
19
  // Note that note hashes can't link to the first nullifier (counter == 0).
@@ -26,5 +29,13 @@ export function buildPrivateKernelTailOutputs(
26
29
  MAX_NEW_NULLIFIERS_PER_TX,
27
30
  );
28
31
 
29
- return new PrivateKernelTailOutputs(noteHashes, nullifiers);
32
+ const nullifiedNotes = prevNoteHashes.filter(n => !n.isEmpty() && n.nullifierCounter).map(n => n.counter);
33
+
34
+ const logs = padArrayEnd(
35
+ prevLogs.filter(l => !l.isEmpty() && !nullifiedNotes.includes(l.noteHashCounter)),
36
+ NoteLogHash.empty(),
37
+ MAX_NOTE_ENCRYPTED_LOGS_PER_TX,
38
+ );
39
+
40
+ return new PrivateKernelResetOutputs(noteHashes, nullifiers, logs);
30
41
  }
@@ -1,119 +1,15 @@
1
1
  import {
2
- type Fr,
3
- GrumpkinScalar,
4
- type MAX_ENCRYPTED_LOGS_PER_TX,
2
+ MAX_ENCRYPTED_LOGS_PER_TX,
5
3
  MAX_NEW_NOTE_HASHES_PER_TX,
6
4
  MAX_NEW_NULLIFIERS_PER_TX,
7
- MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX,
8
- type MAX_NULLIFIER_READ_REQUESTS_PER_TX,
9
- type MAX_UNENCRYPTED_LOGS_PER_TX,
10
- MembershipWitness,
11
- NULLIFIER_TREE_HEIGHT,
5
+ MAX_NOTE_ENCRYPTED_LOGS_PER_TX,
6
+ MAX_UNENCRYPTED_LOGS_PER_TX,
12
7
  type PrivateKernelCircuitPublicInputs,
13
8
  PrivateKernelTailHints,
14
- type ScopedNullifier,
15
- type ScopedNullifierKeyValidationRequest,
16
- type ScopedReadRequest,
17
- type SideEffect,
18
- type SideEffectType,
19
- buildNoteHashReadRequestHints,
20
- buildNullifierReadRequestHints,
21
- buildTransientDataHints,
22
9
  sortByCounterGetSortedHints,
23
10
  } from '@aztec/circuits.js';
24
- import { makeTuple } from '@aztec/foundation/array';
25
- import { type Tuple } from '@aztec/foundation/serialize';
26
-
27
- import { type ProvingDataOracle } from '../proving_data_oracle.js';
28
-
29
- /** @deprecated Use sortByCounterGetSortedHints instead */
30
- function sortSideEffects<T extends SideEffectType, K extends number>(
31
- sideEffects: Tuple<T, K>,
32
- ): [Tuple<T, K>, Tuple<number, K>] {
33
- const sorted = sideEffects
34
- .map((sideEffect, index) => ({ sideEffect, index }))
35
- .sort((a, b) => {
36
- // Empty ones go to the right
37
- if (a.sideEffect.isEmpty()) {
38
- return 1;
39
- }
40
- return Number(a.sideEffect.counter.toBigInt() - b.sideEffect.counter.toBigInt());
41
- });
42
-
43
- const originalToSorted = sorted.map(() => 0);
44
- sorted.forEach(({ index }, i) => {
45
- originalToSorted[index] = i;
46
- });
47
-
48
- return [sorted.map(({ sideEffect }) => sideEffect) as Tuple<T, K>, originalToSorted as Tuple<number, K>];
49
- }
50
-
51
- function getNullifierReadRequestHints(
52
- nullifierReadRequests: Tuple<ScopedReadRequest, typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>,
53
- nullifiers: Tuple<ScopedNullifier, typeof MAX_NEW_NULLIFIERS_PER_TX>,
54
- oracle: ProvingDataOracle,
55
- ) {
56
- const getNullifierMembershipWitness = async (nullifier: Fr) => {
57
- const res = await oracle.getNullifierMembershipWitness(nullifier);
58
- if (!res) {
59
- throw new Error(`Cannot find the leaf for nullifier ${nullifier.toBigInt()}.`);
60
- }
61
-
62
- const { index, siblingPath, leafPreimage } = res;
63
- return {
64
- membershipWitness: new MembershipWitness(
65
- NULLIFIER_TREE_HEIGHT,
66
- index,
67
- siblingPath.toTuple<typeof NULLIFIER_TREE_HEIGHT>(),
68
- ),
69
- leafPreimage,
70
- };
71
- };
72
-
73
- return buildNullifierReadRequestHints({ getNullifierMembershipWitness }, nullifierReadRequests, nullifiers);
74
- }
75
-
76
- async function getMasterNullifierSecretKeys(
77
- nullifierKeyValidationRequests: Tuple<
78
- ScopedNullifierKeyValidationRequest,
79
- typeof MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX
80
- >,
81
- oracle: ProvingDataOracle,
82
- ) {
83
- const keys = makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, GrumpkinScalar.zero);
84
- for (let i = 0; i < nullifierKeyValidationRequests.length; ++i) {
85
- const request = nullifierKeyValidationRequests[i].request;
86
- if (request.isEmpty()) {
87
- break;
88
- }
89
- keys[i] = await oracle.getMasterNullifierSecretKey(request.masterNullifierPublicKey);
90
- }
91
- return keys;
92
- }
93
-
94
- export async function buildPrivateKernelTailHints(
95
- publicInputs: PrivateKernelCircuitPublicInputs,
96
- noteHashLeafIndexMap: Map<bigint, bigint>,
97
- oracle: ProvingDataOracle,
98
- ) {
99
- const noteHashReadRequestHints = await buildNoteHashReadRequestHints(
100
- oracle,
101
- publicInputs.validationRequests.noteHashReadRequests,
102
- publicInputs.end.newNoteHashes,
103
- noteHashLeafIndexMap,
104
- );
105
-
106
- const nullifierReadRequestHints = await getNullifierReadRequestHints(
107
- publicInputs.validationRequests.nullifierReadRequests,
108
- publicInputs.end.newNullifiers,
109
- oracle,
110
- );
111
-
112
- const masterNullifierSecretKeys = await getMasterNullifierSecretKeys(
113
- publicInputs.validationRequests.nullifierKeyValidationRequests,
114
- oracle,
115
- );
116
11
 
12
+ export function buildPrivateKernelTailHints(publicInputs: PrivateKernelCircuitPublicInputs) {
117
13
  const [sortedNoteHashes, sortedNoteHashesIndexes] = sortByCounterGetSortedHints(
118
14
  publicInputs.end.newNoteHashes,
119
15
  MAX_NEW_NOTE_HASHES_PER_TX,
@@ -124,33 +20,28 @@ export async function buildPrivateKernelTailHints(
124
20
  MAX_NEW_NULLIFIERS_PER_TX,
125
21
  );
126
22
 
127
- const [sortedEncryptedLogHashes, sortedEncryptedLogHashesIndexes] = sortSideEffects<
128
- SideEffect,
129
- typeof MAX_ENCRYPTED_LOGS_PER_TX
130
- >(publicInputs.end.encryptedLogsHashes);
23
+ const [sortedNoteEncryptedLogHashes, sortedNoteEncryptedLogHashesIndexes] = sortByCounterGetSortedHints(
24
+ publicInputs.end.noteEncryptedLogsHashes,
25
+ MAX_NOTE_ENCRYPTED_LOGS_PER_TX,
26
+ );
131
27
 
132
- const [sortedUnencryptedLogHashes, sortedUnencryptedLogHashesIndexes] = sortSideEffects<
133
- SideEffect,
134
- typeof MAX_UNENCRYPTED_LOGS_PER_TX
135
- >(publicInputs.end.unencryptedLogsHashes);
28
+ const [sortedEncryptedLogHashes, sortedEncryptedLogHashesIndexes] = sortByCounterGetSortedHints(
29
+ publicInputs.end.encryptedLogsHashes,
30
+ MAX_ENCRYPTED_LOGS_PER_TX,
31
+ );
136
32
 
137
- const [transientNullifierIndexesForNoteHashes, transientNoteHashIndexesForNullifiers] = buildTransientDataHints(
138
- sortedNoteHashes,
139
- sortedNullifiers,
140
- MAX_NEW_NOTE_HASHES_PER_TX,
141
- MAX_NEW_NULLIFIERS_PER_TX,
33
+ const [sortedUnencryptedLogHashes, sortedUnencryptedLogHashesIndexes] = sortByCounterGetSortedHints(
34
+ publicInputs.end.unencryptedLogsHashes,
35
+ MAX_UNENCRYPTED_LOGS_PER_TX,
142
36
  );
143
37
 
144
38
  return new PrivateKernelTailHints(
145
- transientNullifierIndexesForNoteHashes,
146
- transientNoteHashIndexesForNullifiers,
147
- noteHashReadRequestHints,
148
- nullifierReadRequestHints,
149
- masterNullifierSecretKeys,
150
39
  sortedNoteHashes,
151
40
  sortedNoteHashesIndexes,
152
41
  sortedNullifiers,
153
42
  sortedNullifiersIndexes,
43
+ sortedNoteEncryptedLogHashes,
44
+ sortedNoteEncryptedLogHashesIndexes,
154
45
  sortedEncryptedLogHashes,
155
46
  sortedEncryptedLogHashesIndexes,
156
47
  sortedUnencryptedLogHashes,
@@ -1,3 +1,5 @@
1
+ export { buildPrivateKernelInitHints } from './build_private_kernel_init_hints.js';
1
2
  export { buildPrivateKernelInnerHints } from './build_private_kernel_inner_hints.js';
2
3
  export { buildPrivateKernelTailHints } from './build_private_kernel_tail_hints.js';
3
- export { buildPrivateKernelTailOutputs } from './build_private_kernel_tail_outputs.js';
4
+ export { buildPrivateKernelResetInputs } from './build_private_kernel_reset_hints.js';
5
+ export { buildPrivateKernelResetOutputs } from './build_private_kernel_reset_outputs.js';
@@ -4,6 +4,7 @@ import {
4
4
  type Fr,
5
5
  type FunctionSelector,
6
6
  type GrumpkinPrivateKey,
7
+ type KeyGenerator,
7
8
  type MembershipWitness,
8
9
  type NOTE_HASH_TREE_HEIGHT,
9
10
  type Point,
@@ -70,10 +71,13 @@ export interface ProvingDataOracle {
70
71
  getNoteHashTreeRoot(): Promise<Fr>;
71
72
 
72
73
  /**
73
- * Get the master secret key of the nullifier public key.
74
- *
75
- * @param nullifierPublicKey - The nullifier public key.
76
- * @returns the master nullifier secret key.
74
+ * Retrieves the sk_m for the pk_m and a generator index of the key type.
75
+ * @throws If the provided public key is not associated with any of the registered accounts.
76
+ * @param masterPublicKey - The master public key to get secret key for.
77
+ * @returns A Promise that resolves to sk_m and the corresponding app key generator.
78
+ * @dev Used when feeding the sk_m to the kernel circuit for keys verification.
77
79
  */
78
- getMasterNullifierSecretKey(nullifierPublicKey: Point): Promise<GrumpkinPrivateKey>;
80
+ getMasterSecretKeyAndAppKeyGenerator(masterPublicKey: Point): Promise<[GrumpkinPrivateKey, KeyGenerator]>;
81
+
82
+ getFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
79
83
  }
@@ -1,11 +1,12 @@
1
1
  import { type AppCircuitProofOutput, type KernelProofOutput, type ProofCreator } from '@aztec/circuit-types';
2
- import { type CircuitSimulationStats } from '@aztec/circuit-types/stats';
2
+ import type { CircuitName, CircuitSimulationStats } from '@aztec/circuit-types/stats';
3
3
  import {
4
4
  NESTED_RECURSIVE_PROOF_LENGTH,
5
5
  type PrivateCircuitPublicInputs,
6
6
  type PrivateKernelCircuitPublicInputs,
7
7
  type PrivateKernelInitCircuitPrivateInputs,
8
8
  type PrivateKernelInnerCircuitPrivateInputs,
9
+ type PrivateKernelResetCircuitPrivateInputsVariants,
9
10
  type PrivateKernelTailCircuitPrivateInputs,
10
11
  type PrivateKernelTailCircuitPublicInputs,
11
12
  RECURSIVE_PROOF_LENGTH,
@@ -15,7 +16,13 @@ import {
15
16
  import { siloNoteHash } from '@aztec/circuits.js/hash';
16
17
  import { createDebugLogger } from '@aztec/foundation/log';
17
18
  import { elapsed } from '@aztec/foundation/timer';
18
- import { executeInit, executeInner, executeTail, executeTailForPublic } from '@aztec/noir-protocol-circuits-types';
19
+ import {
20
+ executeInit,
21
+ executeInner,
22
+ executeReset,
23
+ executeTail,
24
+ executeTailForPublic,
25
+ } from '@aztec/noir-protocol-circuits-types';
19
26
 
20
27
  /**
21
28
  * Test Proof Creator executes circuit simulations and provides fake proofs.
@@ -59,6 +66,20 @@ export class TestProofCreator implements ProofCreator {
59
66
  return this.makeEmptyKernelProofOutput<PrivateKernelCircuitPublicInputs>(result);
60
67
  }
61
68
 
69
+ public async createProofReset(
70
+ privateInputs: PrivateKernelResetCircuitPrivateInputsVariants,
71
+ ): Promise<KernelProofOutput<PrivateKernelCircuitPublicInputs>> {
72
+ const [duration, result] = await elapsed(() => executeReset(privateInputs));
73
+ this.log.debug(`Simulated private kernel reset`, {
74
+ eventName: 'circuit-simulation',
75
+ circuitName: ('private-kernel-reset-' + privateInputs.sizeTag) as CircuitName,
76
+ duration,
77
+ inputSize: privateInputs.toBuffer().length,
78
+ outputSize: result.toBuffer().length,
79
+ } satisfies CircuitSimulationStats);
80
+ return this.makeEmptyKernelProofOutput<PrivateKernelCircuitPublicInputs>(result);
81
+ }
82
+
62
83
  public async createProofTail(
63
84
  privateInputs: PrivateKernelTailCircuitPrivateInputs,
64
85
  ): Promise<KernelProofOutput<PrivateKernelTailCircuitPublicInputs>> {
@@ -68,7 +89,7 @@ export class TestProofCreator implements ProofCreator {
68
89
  );
69
90
  this.log.debug(`Simulated private kernel ordering`, {
70
91
  eventName: 'circuit-simulation',
71
- circuitName: 'private-kernel-ordering',
92
+ circuitName: 'private-kernel-tail',
72
93
  duration,
73
94
  inputSize: privateInputs.toBuffer().length,
74
95
  outputSize: result.toBuffer().length,
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  type AztecNode,
3
3
  type EncryptedL2BlockL2Logs,
4
- type KeyStore,
5
4
  L1NotePayload,
6
5
  type L2Block,
7
6
  TaggedNote,
@@ -11,6 +10,7 @@ import { INITIAL_L2_BLOCK_NUM, MAX_NEW_NOTE_HASHES_PER_TX, type PublicKey } from
11
10
  import { type Fr } from '@aztec/foundation/fields';
12
11
  import { createDebugLogger } from '@aztec/foundation/log';
13
12
  import { Timer } from '@aztec/foundation/timer';
13
+ import { type KeyStore } from '@aztec/key-store';
14
14
  import { ContractNotFoundError } from '@aztec/simulator';
15
15
 
16
16
  import { DeferredNoteDao } from '../database/deferred_note_dao.js';
@@ -130,7 +130,8 @@ export class NoteProcessor {
130
130
  for (const functionLogs of txFunctionLogs) {
131
131
  for (const log of functionLogs.logs) {
132
132
  this.stats.seen++;
133
- const taggedNote = TaggedNote.fromEncryptedBuffer(log.data, secretKey);
133
+ // @todo Issue(#6410) We should also try decrypting as outgoing if this fails.
134
+ const taggedNote = TaggedNote.decryptAsIncoming(log.data, secretKey);
134
135
  if (taggedNote?.notePayload) {
135
136
  const { notePayload: payload } = taggedNote;
136
137
  // We have successfully decrypted the data.
@@ -107,25 +107,9 @@ async function findNoteIndexAndNullifier(
107
107
  }
108
108
 
109
109
  if (!nonce) {
110
- let errorString;
111
- if (siloedNoteHash == undefined) {
112
- errorString = 'Cannot find a matching commitment for the note.';
113
- } else {
114
- errorString = `We decrypted a log, but couldn't find a corresponding note in the tree.
115
- This might be because the note was nullified in the same tx which created it.
116
- In that case, everything is fine. To check whether this is the case, look back through
117
- the logs for a notification
118
- 'important: chopped commitment for siloed inner hash note
119
- ${siloedNoteHash.toString()}'.
120
- If you can see that notification. Everything's fine.
121
- If that's not the case, and you can't find such a notification, something has gone wrong.
122
- There could be a problem with the way you've defined a custom note, or with the way you're
123
- serializing / deserializing / hashing / encrypting / decrypting that note.
124
- Please see the following github issue to track an improvement that we're working on:
125
- https://github.com/AztecProtocol/aztec-packages/issues/1641`;
126
- }
127
-
128
- throw new Error(errorString);
110
+ // NB: this used to warn the user that a decrypted log didn't match any notes.
111
+ // This was previously fine as we didn't chop transient note logs, but now we do (#1641 complete).
112
+ throw new Error('Cannot find a matching commitment for the note.');
129
113
  }
130
114
 
131
115
  return {
@@ -1,7 +1,8 @@
1
1
  import { BBNativeProofCreator } from '@aztec/bb-prover';
2
2
  import { type AztecNode, type ProofCreator } from '@aztec/circuit-types';
3
3
  import { randomBytes } from '@aztec/foundation/crypto';
4
- import { TestKeyStore } from '@aztec/key-store';
4
+ import { createDebugLogger } from '@aztec/foundation/log';
5
+ import { KeyStore } from '@aztec/key-store';
5
6
  import { AztecLmdbStore } from '@aztec/kv-store/lmdb';
6
7
  import { initStoreForRollup } from '@aztec/kv-store/utils';
7
8
  import { getCanonicalClassRegisterer } from '@aztec/protocol-contracts/class-registerer';
@@ -19,7 +20,7 @@ import { PXEService } from './pxe_service.js';
19
20
 
20
21
  /**
21
22
  * Create and start an PXEService instance with the given AztecNode.
22
- * If no keyStore or database is provided, it will use TestKeyStore and MemoryDB as default values.
23
+ * If no keyStore or database is provided, it will use KeyStore and MemoryDB as default values.
23
24
  * Returns a Promise that resolves to the started PXEService instance.
24
25
  *
25
26
  * @param aztecNode - The AztecNode instance to be used by the server.
@@ -41,9 +42,7 @@ export async function createPXEService(
41
42
  const keyStorePath = config.dataDirectory ? join(config.dataDirectory, 'pxe_key_store') : undefined;
42
43
  const l1Contracts = await aztecNode.getL1ContractAddresses();
43
44
 
44
- const keyStore = new TestKeyStore(
45
- await initStoreForRollup(AztecLmdbStore.open(keyStorePath), l1Contracts.rollupAddress),
46
- );
45
+ const keyStore = new KeyStore(await initStoreForRollup(AztecLmdbStore.open(keyStorePath), l1Contracts.rollupAddress));
47
46
  const db = new KVPxeDatabase(await initStoreForRollup(AztecLmdbStore.open(pxeDbPath), l1Contracts.rollupAddress));
48
47
 
49
48
  // (@PhilWindle) Temporary validation until WASM is implemented
@@ -54,7 +53,11 @@ export async function createPXEService(
54
53
  }
55
54
  prover = !config.proverEnabled
56
55
  ? new TestProofCreator()
57
- : new BBNativeProofCreator(config.bbBinaryPath!, config.bbWorkingDirectory!);
56
+ : new BBNativeProofCreator(
57
+ config.bbBinaryPath!,
58
+ config.bbWorkingDirectory!,
59
+ createDebugLogger('aztec:pxe:bb-native-prover' + (logSuffix ? `:${logSuffix}` : '')),
60
+ );
58
61
  }
59
62
 
60
63
  const server = new PXEService(keyStore, aztecNode, db, prover, config, logSuffix);
@@ -5,7 +5,6 @@ import {
5
5
  ExtendedNote,
6
6
  type FunctionCall,
7
7
  type GetUnencryptedLogsResponse,
8
- type KeyStore,
9
8
  type L2Block,
10
9
  type LogFilter,
11
10
  MerkleTreeId,
@@ -38,16 +37,19 @@ import {
38
37
  import { computeNoteHashNonce, siloNullifier } from '@aztec/circuits.js/hash';
39
38
  import { type ContractArtifact, type DecodedReturn, FunctionSelector, encodeArguments } from '@aztec/foundation/abi';
40
39
  import { arrayNonEmptyLength, padArrayEnd } from '@aztec/foundation/collection';
41
- import { Fr } from '@aztec/foundation/fields';
40
+ import { type Fq, Fr } from '@aztec/foundation/fields';
42
41
  import { SerialQueue } from '@aztec/foundation/fifo';
43
42
  import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
44
43
  import { Timer } from '@aztec/foundation/timer';
44
+ import { type KeyStore } from '@aztec/key-store';
45
45
  import {
46
46
  type AcirSimulator,
47
47
  type ExecutionResult,
48
+ accumulateReturnValues,
48
49
  collectEnqueuedPublicFunctionCalls,
49
50
  collectPublicTeardownFunctionCall,
50
51
  collectSortedEncryptedLogs,
52
+ collectSortedNoteEncryptedLogs,
51
53
  collectSortedUnencryptedLogs,
52
54
  resolveOpcodeLocations,
53
55
  } from '@aztec/simulator';
@@ -159,6 +161,10 @@ export class PXEService implements PXE {
159
161
  return this.db.getAuthWitness(messageHash);
160
162
  }
161
163
 
164
+ async rotateNskM(account: AztecAddress, secretKey: Fq): Promise<void> {
165
+ await this.keyStore.rotateMasterNullifierKey(account, secretKey);
166
+ }
167
+
162
168
  public addCapsule(capsule: Fr[]) {
163
169
  return this.db.addCapsule(capsule);
164
170
  }
@@ -207,14 +213,6 @@ export class PXEService implements PXE {
207
213
  return Promise.resolve(account);
208
214
  }
209
215
 
210
- public async getRegisteredAccountPublicKeysHash(address: AztecAddress): Promise<Fr | undefined> {
211
- const accounts = await this.keyStore.getAccounts();
212
- if (!accounts.some(account => account.equals(address))) {
213
- return undefined;
214
- }
215
- return this.keyStore.getPublicKeysHash(address);
216
- }
217
-
218
216
  public async registerRecipient(recipient: CompleteAddress): Promise<void> {
219
217
  const wasAdded = await this.db.addCompleteAddress(recipient);
220
218
 
@@ -468,7 +466,7 @@ export class PXEService implements PXE {
468
466
  return txHash;
469
467
  }
470
468
 
471
- public async viewTx(
469
+ public async simulateUnconstrained(
472
470
  functionName: string,
473
471
  args: any[],
474
472
  to: AztecAddress,
@@ -523,6 +521,7 @@ export class PXEService implements PXE {
523
521
  args: encodeArguments(functionDao, args),
524
522
  functionData: FunctionData.fromAbi(functionDao),
525
523
  to,
524
+ isStatic: functionDao.isStatic,
526
525
  };
527
526
  }
528
527
 
@@ -665,6 +664,7 @@ export class PXEService implements PXE {
665
664
  this.log.debug(`Executing kernel prover...`);
666
665
  const { proof, publicInputs } = await kernelProver.prove(txExecutionRequest.toTxRequest(), executionResult);
667
666
 
667
+ const noteEncryptedLogs = new EncryptedTxL2Logs([collectSortedNoteEncryptedLogs(executionResult)]);
668
668
  const unencryptedLogs = new UnencryptedTxL2Logs([collectSortedUnencryptedLogs(executionResult)]);
669
669
  const encryptedLogs = new EncryptedTxL2Logs([collectSortedEncryptedLogs(executionResult)]);
670
670
  const enqueuedPublicFunctions = collectEnqueuedPublicFunctionCalls(executionResult);
@@ -677,12 +677,14 @@ export class PXEService implements PXE {
677
677
  const tx = new Tx(
678
678
  publicInputs,
679
679
  proof.binaryProof,
680
+ noteEncryptedLogs,
680
681
  encryptedLogs,
681
682
  unencryptedLogs,
682
683
  enqueuedPublicFunctions,
683
684
  teardownPublicFunction,
684
685
  );
685
- return new SimulatedTx(tx, executionResult.returnValues);
686
+
687
+ return new SimulatedTx(tx, accumulateReturnValues(executionResult));
686
688
  }
687
689
 
688
690
  /**