@aztec/stdlib 4.0.0-nightly.20260112 → 4.0.0-nightly.20260114

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 (219) hide show
  1. package/dest/abi/utils.d.ts +7 -1
  2. package/dest/abi/utils.d.ts.map +1 -1
  3. package/dest/abi/utils.js +7 -0
  4. package/dest/avm/avm.d.ts +300 -300
  5. package/dest/block/attestation_info.d.ts +5 -5
  6. package/dest/block/attestation_info.d.ts.map +1 -1
  7. package/dest/block/attestation_info.js +4 -4
  8. package/dest/block/body.d.ts +1 -1
  9. package/dest/block/body.d.ts.map +1 -1
  10. package/dest/block/body.js +2 -1
  11. package/dest/block/checkpointed_l2_block.d.ts +1 -1
  12. package/dest/block/checkpointed_l2_block.d.ts.map +1 -1
  13. package/dest/block/checkpointed_l2_block.js +5 -4
  14. package/dest/block/l2_block.d.ts +6 -3
  15. package/dest/block/l2_block.d.ts.map +1 -1
  16. package/dest/block/l2_block.js +3 -3
  17. package/dest/block/l2_block_code_to_purge.d.ts +1 -1
  18. package/dest/block/l2_block_code_to_purge.d.ts.map +1 -1
  19. package/dest/block/l2_block_code_to_purge.js +1 -1
  20. package/dest/block/l2_block_header.d.ts +6 -2
  21. package/dest/block/l2_block_header.d.ts.map +1 -1
  22. package/dest/block/l2_block_header.js +14 -7
  23. package/dest/block/l2_block_new.d.ts +1 -2
  24. package/dest/block/l2_block_new.d.ts.map +1 -1
  25. package/dest/block/l2_block_new.js +4 -1
  26. package/dest/block/l2_block_source.d.ts +247 -42
  27. package/dest/block/l2_block_source.d.ts.map +1 -1
  28. package/dest/block/l2_block_source.js +23 -5
  29. package/dest/block/l2_block_stream/index.d.ts +2 -1
  30. package/dest/block/l2_block_stream/index.d.ts.map +1 -1
  31. package/dest/block/l2_block_stream/index.js +1 -0
  32. package/dest/block/l2_block_stream/interfaces.d.ts +16 -5
  33. package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
  34. package/dest/block/l2_block_stream/l2_block_stream.d.ts +4 -2
  35. package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
  36. package/dest/block/l2_block_stream/l2_block_stream.js +102 -30
  37. package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts +24 -16
  38. package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts.map +1 -1
  39. package/dest/block/l2_block_stream/l2_tips_memory_store.js +55 -61
  40. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +49 -0
  41. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -0
  42. package/dest/block/l2_block_stream/l2_tips_store_base.js +179 -0
  43. package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
  44. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  45. package/dest/block/test/l2_tips_store_test_suite.js +483 -38
  46. package/dest/block/validate_block_result.d.ts +24 -24
  47. package/dest/block/validate_block_result.d.ts.map +1 -1
  48. package/dest/block/validate_block_result.js +18 -17
  49. package/dest/checkpoint/checkpoint.d.ts +2 -1
  50. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  51. package/dest/checkpoint/checkpoint.js +11 -1
  52. package/dest/checkpoint/checkpoint_info.d.ts +32 -3
  53. package/dest/checkpoint/checkpoint_info.d.ts.map +1 -1
  54. package/dest/checkpoint/checkpoint_info.js +34 -1
  55. package/dest/checkpoint/index.d.ts +2 -1
  56. package/dest/checkpoint/index.d.ts.map +1 -1
  57. package/dest/checkpoint/index.js +1 -0
  58. package/dest/checkpoint/published_checkpoint.d.ts +1 -1
  59. package/dest/checkpoint/published_checkpoint.d.ts.map +1 -1
  60. package/dest/checkpoint/published_checkpoint.js +4 -3
  61. package/dest/contract/index.d.ts +1 -3
  62. package/dest/contract/index.d.ts.map +1 -1
  63. package/dest/contract/index.js +0 -2
  64. package/dest/deserialization/index.d.ts +11 -0
  65. package/dest/deserialization/index.d.ts.map +1 -0
  66. package/dest/deserialization/index.js +10 -0
  67. package/dest/interfaces/api_limit.d.ts +2 -1
  68. package/dest/interfaces/api_limit.d.ts.map +1 -1
  69. package/dest/interfaces/api_limit.js +1 -0
  70. package/dest/interfaces/archiver.d.ts +6 -6
  71. package/dest/interfaces/archiver.d.ts.map +1 -1
  72. package/dest/interfaces/archiver.js +6 -4
  73. package/dest/interfaces/aztec-node-admin.d.ts +12 -9
  74. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  75. package/dest/interfaces/aztec-node-admin.js +2 -2
  76. package/dest/interfaces/aztec-node.d.ts +2 -2
  77. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  78. package/dest/interfaces/aztec-node.js +8 -3
  79. package/dest/interfaces/block-builder.d.ts +2 -2
  80. package/dest/interfaces/block-builder.d.ts.map +1 -1
  81. package/dest/interfaces/configs.d.ts +6 -1
  82. package/dest/interfaces/configs.d.ts.map +1 -1
  83. package/dest/interfaces/configs.js +2 -1
  84. package/dest/interfaces/p2p.d.ts +7 -9
  85. package/dest/interfaces/p2p.d.ts.map +1 -1
  86. package/dest/interfaces/p2p.js +3 -4
  87. package/dest/interfaces/validator.d.ts +41 -15
  88. package/dest/interfaces/validator.d.ts.map +1 -1
  89. package/dest/interfaces/validator.js +3 -2
  90. package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts +6 -5
  91. package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts.map +1 -1
  92. package/dest/kernel/hints/build_note_hash_read_request_hints.js +5 -6
  93. package/dest/messaging/l2_to_l1_membership.d.ts +1 -1
  94. package/dest/messaging/l2_to_l1_membership.d.ts.map +1 -1
  95. package/dest/messaging/l2_to_l1_membership.js +5 -3
  96. package/dest/messaging/out_hash.d.ts +41 -4
  97. package/dest/messaging/out_hash.d.ts.map +1 -1
  98. package/dest/messaging/out_hash.js +52 -26
  99. package/dest/note/note_dao.d.ts +8 -5
  100. package/dest/note/note_dao.d.ts.map +1 -1
  101. package/dest/note/note_dao.js +15 -12
  102. package/dest/p2p/attestation_utils.d.ts +3 -3
  103. package/dest/p2p/attestation_utils.d.ts.map +1 -1
  104. package/dest/p2p/attestation_utils.js +1 -1
  105. package/dest/p2p/block_proposal.d.ts +85 -21
  106. package/dest/p2p/block_proposal.d.ts.map +1 -1
  107. package/dest/p2p/block_proposal.js +126 -38
  108. package/dest/p2p/checkpoint_attestation.d.ts +78 -0
  109. package/dest/p2p/checkpoint_attestation.d.ts.map +1 -0
  110. package/dest/p2p/{block_attestation.js → checkpoint_attestation.js} +22 -19
  111. package/dest/p2p/checkpoint_proposal.d.ts +155 -0
  112. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -0
  113. package/dest/p2p/checkpoint_proposal.js +222 -0
  114. package/dest/p2p/consensus_payload.d.ts +5 -2
  115. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  116. package/dest/p2p/consensus_payload.js +3 -2
  117. package/dest/p2p/index.d.ts +4 -2
  118. package/dest/p2p/index.d.ts.map +1 -1
  119. package/dest/p2p/index.js +3 -1
  120. package/dest/p2p/signature_utils.d.ts +5 -3
  121. package/dest/p2p/signature_utils.d.ts.map +1 -1
  122. package/dest/p2p/signature_utils.js +3 -1
  123. package/dest/p2p/signed_txs.d.ts +40 -0
  124. package/dest/p2p/signed_txs.d.ts.map +1 -0
  125. package/dest/p2p/signed_txs.js +75 -0
  126. package/dest/p2p/topic_type.d.ts +3 -2
  127. package/dest/p2p/topic_type.d.ts.map +1 -1
  128. package/dest/p2p/topic_type.js +8 -2
  129. package/dest/rollup/block_headers_hash.js +1 -1
  130. package/dest/rollup/block_rollup_public_inputs.d.ts +2 -2
  131. package/dest/rollup/block_rollup_public_inputs.js +2 -2
  132. package/dest/rollup/checkpoint_header.d.ts +16 -2
  133. package/dest/rollup/checkpoint_header.d.ts.map +1 -1
  134. package/dest/rollup/checkpoint_header.js +25 -5
  135. package/dest/rollup/checkpoint_rollup_public_inputs.d.ts +11 -6
  136. package/dest/rollup/checkpoint_rollup_public_inputs.d.ts.map +1 -1
  137. package/dest/rollup/checkpoint_rollup_public_inputs.js +10 -6
  138. package/dest/rollup/checkpoint_root_rollup_private_inputs.d.ts +14 -3
  139. package/dest/rollup/checkpoint_root_rollup_private_inputs.d.ts.map +1 -1
  140. package/dest/rollup/checkpoint_root_rollup_private_inputs.js +13 -2
  141. package/dest/rollup/root_rollup_public_inputs.d.ts +5 -2
  142. package/dest/rollup/root_rollup_public_inputs.d.ts.map +1 -1
  143. package/dest/rollup/root_rollup_public_inputs.js +4 -1
  144. package/dest/tests/factories.d.ts +13 -1
  145. package/dest/tests/factories.d.ts.map +1 -1
  146. package/dest/tests/factories.js +53 -3
  147. package/dest/tests/mocks.d.ts +55 -9
  148. package/dest/tests/mocks.d.ts.map +1 -1
  149. package/dest/tests/mocks.js +84 -35
  150. package/dest/tx/private_execution_result.d.ts +1 -5
  151. package/dest/tx/private_execution_result.d.ts.map +1 -1
  152. package/dest/tx/private_execution_result.js +3 -20
  153. package/dest/tx/tx_effect.d.ts +1 -6
  154. package/dest/tx/tx_effect.d.ts.map +1 -1
  155. package/dest/tx/tx_effect.js +0 -7
  156. package/package.json +9 -8
  157. package/src/abi/utils.ts +17 -0
  158. package/src/block/attestation_info.ts +9 -6
  159. package/src/block/body.ts +2 -1
  160. package/src/block/checkpointed_l2_block.ts +5 -4
  161. package/src/block/l2_block.ts +4 -3
  162. package/src/block/l2_block_code_to_purge.ts +1 -0
  163. package/src/block/l2_block_header.ts +13 -0
  164. package/src/block/l2_block_new.ts +5 -1
  165. package/src/block/l2_block_source.ts +69 -17
  166. package/src/block/l2_block_stream/index.ts +1 -0
  167. package/src/block/l2_block_stream/interfaces.ts +16 -4
  168. package/src/block/l2_block_stream/l2_block_stream.ts +121 -38
  169. package/src/block/l2_block_stream/l2_tips_memory_store.ts +62 -56
  170. package/src/block/l2_block_stream/l2_tips_store_base.ts +226 -0
  171. package/src/block/test/l2_tips_store_test_suite.ts +485 -36
  172. package/src/block/validate_block_result.ts +40 -35
  173. package/src/checkpoint/checkpoint.ts +12 -1
  174. package/src/checkpoint/checkpoint_info.ts +45 -2
  175. package/src/checkpoint/index.ts +1 -0
  176. package/src/checkpoint/published_checkpoint.ts +4 -3
  177. package/src/contract/index.ts +0 -2
  178. package/src/deserialization/index.ts +21 -0
  179. package/src/interfaces/api_limit.ts +1 -0
  180. package/src/interfaces/archiver.ts +14 -6
  181. package/src/interfaces/aztec-node-admin.ts +5 -2
  182. package/src/interfaces/aztec-node.ts +30 -3
  183. package/src/interfaces/block-builder.ts +1 -0
  184. package/src/interfaces/configs.ts +5 -0
  185. package/src/interfaces/p2p.ts +8 -12
  186. package/src/interfaces/validator.ts +57 -11
  187. package/src/kernel/hints/build_note_hash_read_request_hints.ts +5 -8
  188. package/src/messaging/l2_to_l1_membership.ts +5 -3
  189. package/src/messaging/out_hash.ts +60 -29
  190. package/src/note/note_dao.ts +18 -13
  191. package/src/p2p/attestation_utils.ts +3 -3
  192. package/src/p2p/block_proposal.ts +191 -42
  193. package/src/p2p/{block_attestation.ts → checkpoint_attestation.ts} +31 -25
  194. package/src/p2p/checkpoint_proposal.ts +342 -0
  195. package/src/p2p/consensus_payload.ts +5 -2
  196. package/src/p2p/index.ts +3 -1
  197. package/src/p2p/signature_utils.ts +3 -1
  198. package/src/p2p/signed_txs.ts +88 -0
  199. package/src/p2p/topic_type.ts +3 -2
  200. package/src/rollup/block_headers_hash.ts +1 -1
  201. package/src/rollup/block_rollup_public_inputs.ts +2 -2
  202. package/src/rollup/checkpoint_header.ts +33 -0
  203. package/src/rollup/checkpoint_rollup_public_inputs.ts +12 -6
  204. package/src/rollup/checkpoint_root_rollup_private_inputs.ts +14 -1
  205. package/src/rollup/root_rollup_public_inputs.ts +4 -1
  206. package/src/tests/factories.ts +46 -2
  207. package/src/tests/mocks.ts +146 -50
  208. package/src/tx/private_execution_result.ts +0 -15
  209. package/src/tx/tx_effect.ts +0 -9
  210. package/dest/contract/contract_class_metadata.d.ts +0 -8
  211. package/dest/contract/contract_class_metadata.d.ts.map +0 -1
  212. package/dest/contract/contract_class_metadata.js +0 -1
  213. package/dest/contract/contract_metadata.d.ts +0 -7
  214. package/dest/contract/contract_metadata.d.ts.map +0 -1
  215. package/dest/contract/contract_metadata.js +0 -1
  216. package/dest/p2p/block_attestation.d.ts +0 -77
  217. package/dest/p2p/block_attestation.d.ts.map +0 -1
  218. package/src/contract/contract_class_metadata.ts +0 -8
  219. package/src/contract/contract_metadata.ts +0 -7
@@ -4,14 +4,21 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
4
4
  import type { Signature } from '@aztec/foundation/eth-signature';
5
5
  import { schemas, zodFor } from '@aztec/foundation/schemas';
6
6
  import type { SequencerConfig, SlasherConfig } from '@aztec/stdlib/interfaces/server';
7
- import type { BlockAttestation, BlockProposal, BlockProposalOptions } from '@aztec/stdlib/p2p';
8
- import type { Tx } from '@aztec/stdlib/tx';
7
+ import type {
8
+ BlockProposal,
9
+ BlockProposalOptions,
10
+ CheckpointAttestation,
11
+ CheckpointLastBlockData,
12
+ CheckpointProposal,
13
+ CheckpointProposalOptions,
14
+ } from '@aztec/stdlib/p2p';
15
+ import type { CheckpointHeader } from '@aztec/stdlib/rollup';
16
+ import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
9
17
 
10
18
  import type { PeerId } from '@libp2p/interface';
11
19
  import { z } from 'zod';
12
20
 
13
21
  import type { CommitteeAttestationsAndSigners } from '../block/index.js';
14
- import type { CheckpointHeader } from '../rollup/checkpoint_header.js';
15
22
  import { AllowedElementSchema } from './allowed_element.js';
16
23
 
17
24
  /**
@@ -36,14 +43,19 @@ export interface ValidatorClientConfig {
36
43
  /** Whether to re-execute transactions in a block proposal before attesting */
37
44
  validatorReexecute: boolean;
38
45
 
39
- /** Will re-execute until this many milliseconds are left in the slot */
40
- validatorReexecuteDeadlineMs: number;
41
-
42
46
  /** Whether to always reexecute block proposals, even for non-validator nodes or when out of the currnet committee */
43
47
  alwaysReexecuteBlockProposals?: boolean;
44
48
 
45
49
  /** Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus */
46
50
  fishermanMode?: boolean;
51
+
52
+ // TODO(palla/mbps): Change default to false once checkpoint validation is stable
53
+ /** Skip checkpoint proposal validation and always attest (default: true) */
54
+ skipCheckpointProposalValidation?: boolean;
55
+
56
+ // TODO(palla/mbps): Change default to false once block sync is stable
57
+ /** Skip pushing re-executed blocks to archiver (default: true) */
58
+ skipPushProposedBlocksToArchiver?: boolean;
47
59
  }
48
60
 
49
61
  export type ValidatorClientFullConfig = ValidatorClientConfig &
@@ -63,9 +75,10 @@ export const ValidatorClientConfigSchema = zodFor<Omit<ValidatorClientConfig, 'v
63
75
  disabledValidators: z.array(schemas.EthAddress),
64
76
  attestationPollingIntervalMs: z.number().min(0),
65
77
  validatorReexecute: z.boolean(),
66
- validatorReexecuteDeadlineMs: z.number().min(0),
67
78
  alwaysReexecuteBlockProposals: z.boolean().optional(),
68
79
  fishermanMode: z.boolean().optional(),
80
+ skipCheckpointProposalValidation: z.boolean().optional(),
81
+ skipPushProposedBlocksToArchiver: z.boolean().optional(),
69
82
  }),
70
83
  );
71
84
 
@@ -78,23 +91,56 @@ export const ValidatorClientFullConfigSchema = zodFor<Omit<ValidatorClientFullCo
78
91
  }),
79
92
  );
80
93
 
94
+ export type CreateCheckpointProposalLastBlockData = Omit<CheckpointLastBlockData, 'txHashes'> & { txs: Tx[] };
95
+
81
96
  export interface Validator {
82
97
  start(): Promise<void>;
83
98
  updateConfig(config: Partial<ValidatorClientFullConfig>): void;
84
99
 
85
100
  // Block validation responsibilities
86
101
  createBlockProposal(
87
- blockNumber: number,
88
- header: CheckpointHeader,
102
+ blockHeader: BlockHeader,
103
+ indexWithinCheckpoint: number,
104
+ inHash: Fr,
89
105
  archive: Fr,
90
106
  txs: Tx[],
91
107
  proposerAddress: EthAddress | undefined,
92
108
  options: BlockProposalOptions,
93
109
  ): Promise<BlockProposal | undefined>;
94
- attestToProposal(proposal: BlockProposal, sender: PeerId): Promise<BlockAttestation[] | undefined>;
110
+
111
+ /** Creates a checkpoint proposal for the last block in a checkpoint */
112
+ createCheckpointProposal(
113
+ checkpointHeader: CheckpointHeader,
114
+ archive: Fr,
115
+ lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
116
+ proposerAddress: EthAddress | undefined,
117
+ options: CheckpointProposalOptions,
118
+ ): Promise<CheckpointProposal>;
119
+
120
+ /**
121
+ * Validate a block proposal from a peer.
122
+ * Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
123
+ * @returns true if the proposal is valid, false otherwise
124
+ */
125
+ validateBlockProposal(proposal: BlockProposal, sender: PeerId): Promise<boolean>;
126
+
127
+ /**
128
+ * Validate and attest to a checkpoint proposal from a peer.
129
+ * @returns Checkpoint attestations if valid, undefined otherwise
130
+ */
131
+ attestToCheckpointProposal(
132
+ proposal: CheckpointProposal,
133
+ sender: PeerId,
134
+ ): Promise<CheckpointAttestation[] | undefined>;
95
135
 
96
136
  broadcastBlockProposal(proposal: BlockProposal): Promise<void>;
97
- collectAttestations(proposal: BlockProposal, required: number, deadline: Date): Promise<BlockAttestation[]>;
137
+
138
+ /** Collect own attestations for a checkpoint proposal (used when skipping p2p attestation collection) */
139
+ collectOwnAttestations(proposal: CheckpointProposal): Promise<CheckpointAttestation[]>;
140
+
141
+ /** Collect attestations from the p2p network for a checkpoint proposal */
142
+ collectAttestations(proposal: CheckpointProposal, required: number, deadline: Date): Promise<CheckpointAttestation[]>;
143
+
98
144
  signAttestationsAndSigners(
99
145
  attestationsAndSigners: CommitteeAttestationsAndSigners,
100
146
  proposer: EthAddress,
@@ -3,6 +3,7 @@ import {
3
3
  MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
4
4
  type NOTE_HASH_TREE_HEIGHT,
5
5
  } from '@aztec/constants';
6
+ import type { Fr } from '@aztec/foundation/curves/bn254';
6
7
  import type { MembershipWitness } from '@aztec/foundation/trees';
7
8
 
8
9
  import type { ClaimedLengthArray } from '../claimed_length_array.js';
@@ -61,12 +62,11 @@ export function getNoteHashReadRequestResetActions(
61
62
 
62
63
  export async function buildNoteHashReadRequestHintsFromResetActions<PENDING extends number, SETTLED extends number>(
63
64
  oracle: {
64
- getNoteHashMembershipWitness(leafIndex: bigint): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT>>;
65
+ getNoteHashMembershipWitness(noteHash: Fr): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined>;
65
66
  },
66
67
  noteHashReadRequests: ClaimedLengthArray<ScopedReadRequest, typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX>,
67
68
  noteHashes: ClaimedLengthArray<ScopedNoteHash, typeof MAX_NOTE_HASHES_PER_TX>,
68
69
  resetActions: ReadRequestResetActions<typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX>,
69
- noteHashLeafIndexMap: Map<bigint, bigint>,
70
70
  maxPending: PENDING = MAX_NOTE_HASH_READ_REQUESTS_PER_TX as PENDING,
71
71
  maxSettled: SETTLED = MAX_NOTE_HASH_READ_REQUESTS_PER_TX as SETTLED,
72
72
  ) {
@@ -79,11 +79,10 @@ export async function buildNoteHashReadRequestHintsFromResetActions<PENDING exte
79
79
  for (let i = 0; i < resetActions.actions.length; i++) {
80
80
  if (resetActions.actions[i] === ReadRequestActionEnum.READ_AS_SETTLED) {
81
81
  const readRequest = noteHashReadRequests.array[i];
82
- const leafIndex = noteHashLeafIndexMap.get(readRequest.value.toBigInt());
83
- if (leafIndex === undefined) {
82
+ const membershipWitness = await oracle.getNoteHashMembershipWitness(readRequest.value);
83
+ if (!membershipWitness) {
84
84
  throw new Error('Read request is reading an unknown note hash.');
85
85
  }
86
- const membershipWitness = await oracle.getNoteHashMembershipWitness(leafIndex);
87
86
  builder.addSettledReadRequest(i, membershipWitness, readRequest.value);
88
87
  }
89
88
  }
@@ -101,11 +100,10 @@ export async function buildNoteHashReadRequestHintsFromResetActions<PENDING exte
101
100
 
102
101
  export async function buildNoteHashReadRequestHints<PENDING extends number, SETTLED extends number>(
103
102
  oracle: {
104
- getNoteHashMembershipWitness(leafIndex: bigint): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT>>;
103
+ getNoteHashMembershipWitness(noteHash: Fr): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT>>;
105
104
  },
106
105
  noteHashReadRequests: ClaimedLengthArray<ScopedReadRequest, typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX>,
107
106
  noteHashes: ClaimedLengthArray<ScopedNoteHash, typeof MAX_NOTE_HASHES_PER_TX>,
108
- noteHashLeafIndexMap: Map<bigint, bigint>,
109
107
  futureNoteHashes: ScopedNoteHash[],
110
108
  maxPending: PENDING = MAX_NOTE_HASH_READ_REQUESTS_PER_TX as PENDING,
111
109
  maxSettled: SETTLED = MAX_NOTE_HASH_READ_REQUESTS_PER_TX as SETTLED,
@@ -116,7 +114,6 @@ export async function buildNoteHashReadRequestHints<PENDING extends number, SETT
116
114
  noteHashReadRequests,
117
115
  noteHashes,
118
116
  resetActions,
119
- noteHashLeafIndexMap,
120
117
  maxPending,
121
118
  maxSettled,
122
119
  );
@@ -1,4 +1,4 @@
1
- import { AZTEC_MAX_EPOCH_DURATION } from '@aztec/constants';
1
+ import { OUT_HASH_TREE_LEAF_COUNT } from '@aztec/constants';
2
2
  import type { EpochNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { SiblingPath, UnbalancedMerkleTreeCalculator, computeUnbalancedShaRoot } from '@aztec/foundation/trees';
@@ -165,10 +165,12 @@ export function computeL2ToL1MembershipWitnessFromMessagesInEpoch(
165
165
  });
166
166
  // Pad to AZTEC_MAX_EPOCH_DURATION with zeros.
167
167
  checkpointOutHashes = checkpointOutHashes.concat(
168
- Array.from({ length: AZTEC_MAX_EPOCH_DURATION - messagesInEpoch.length }, () => Buffer.alloc(32)),
168
+ Array.from({ length: OUT_HASH_TREE_LEAF_COUNT - messagesInEpoch.length }, () => Buffer.alloc(32)),
169
169
  );
170
170
 
171
- // Build the epoch tree with all the checkpoint out hashes, including the padded zeros
171
+ // Build the epoch tree with all the checkpoint out hashes, including the padded zeros.
172
+ // Note: The epoch tree is actually a balanced tree, but we use an unbalanced tree calculator here to avoid turning
173
+ // this function into async.
172
174
  const epochTree = UnbalancedMerkleTreeCalculator.create(checkpointOutHashes);
173
175
  // Get the sibling path of the checkpoint out hash in the epoch tree.
174
176
  const pathToCheckpointOutHashInEpochTree = epochTree.getSiblingPathByLeafIndex(checkpointIndex);
@@ -1,46 +1,77 @@
1
- import { AZTEC_MAX_EPOCH_DURATION } from '@aztec/constants';
1
+ import { OUT_HASH_TREE_LEAF_COUNT } from '@aztec/constants';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { computeCompressedUnbalancedShaRoot, computeUnbalancedShaRoot } from '@aztec/foundation/trees';
4
+ import { computeBalancedShaRoot, computeUnbalancedShaRoot, computeWonkyShaRoot } from '@aztec/foundation/trees';
5
5
 
6
+ /**
7
+ * Computes the out hash of a tx. It's the root of the unbalanced tree of all the L2-to-L1 messages emitted by the tx.
8
+ * @param messages - The L2-to-L1 messages emitted by the tx.
9
+ * @returns The out hash of the tx.
10
+ */
6
11
  export function computeTxOutHash(messages: Fr[]): Fr {
12
+ // Must match the implementation in `tx_base_public_inputs_composer.nr > compute_kernel_out_hash()`
7
13
  if (!messages.length) {
8
14
  return Fr.ZERO;
9
15
  }
10
- // Tx out hash is the root of the unbalanced merkle tree of all the messages.
11
- // Zero hashes (which should not happen) are not compressed.
16
+ // It's an unbalanced tree because zero hashes (which should not happen) will be included.
12
17
  return Fr.fromBuffer(computeUnbalancedShaRoot(messages.map(msg => msg.toBuffer())));
13
18
  }
14
19
 
15
- export function computeBlockOutHash(messagesPerBlock: Fr[][]): Fr {
16
- const txOutHashes = messagesPerBlock.map(messages => computeTxOutHash(messages));
17
- return aggregateOutHashes(txOutHashes);
20
+ /**
21
+ * Computes the out hash of a block. It's the root of the wonky tree of all the tx out hashes.
22
+ * @param messagesPerTx - The L2-to-L1 messages emitted by the txs in the block. This is an array of message arrays.
23
+ * The array at index 0 contains the messages emitted by the first tx, the array at index 1 contains the messages
24
+ * emitted by the second tx, and so on.
25
+ * @returns The out hash of the block.
26
+ */
27
+ export function computeBlockOutHash(messagesPerTx: Fr[][]): Fr {
28
+ // See how the tx out hashes are aggregated into a block out hash in `merge_tx_rollups.nr > accumulate_out_hash()`.
29
+ const txOutHashes = messagesPerTx.map(messages => computeTxOutHash(messages));
30
+ return Fr.fromBuffer(computeWonkyShaRoot(txOutHashes.map(hash => hash.toBuffer())));
18
31
  }
19
32
 
20
- export function computeCheckpointOutHash(messagesForAllTxs: Fr[][][]): Fr {
21
- const blockOutHashes = messagesForAllTxs.map(block => computeBlockOutHash(block));
22
- return aggregateOutHashes(blockOutHashes);
33
+ /**
34
+ * Computes the out hash of a checkpoint. It's the root of the wonky tree of all the block out hashes.
35
+ * @param messagesPerBlock - The L2-to-L1 messages emitted by the txs in the blocks in the checkpoint. This is an array
36
+ * of arrays of messages. The array at index 0 contains the arrays of messages emitted by the first block, the array at
37
+ * index 1 contains the arrays of messages emitted by the second block, and so on.
38
+ * @returns The out hash of the checkpoint.
39
+ */
40
+ export function computeCheckpointOutHash(messagesPerBlock: Fr[][][]): Fr {
41
+ // See how the block out hashes are aggregated into a checkpoint out hash in `merge_block_rollups.nr > accumulate_out_hash()`.
42
+ const blockOutHashes = messagesPerBlock.map(block => computeBlockOutHash(block));
43
+ return Fr.fromBuffer(computeWonkyShaRoot(blockOutHashes.map(hash => hash.toBuffer())));
23
44
  }
24
45
 
25
- export function computeEpochOutHash(messagesInEpoch: Fr[][][][]): Fr {
26
- // Must match the implementation in `compute_epoch_out_hash.nr`.
27
- const checkpointOutHashes = messagesInEpoch
28
- .map(checkpoint => computeCheckpointOutHash(checkpoint))
29
- .map(hash => hash.toBuffer());
30
- if (checkpointOutHashes.every(hash => hash.equals(Buffer.alloc(32)))) {
31
- return Fr.ZERO;
32
- }
33
-
34
- const paddedOutHashes = padArrayEnd(checkpointOutHashes, Buffer.alloc(32), AZTEC_MAX_EPOCH_DURATION);
35
- return Fr.fromBuffer(computeUnbalancedShaRoot(paddedOutHashes));
46
+ /**
47
+ * Computes the accumulated (epoch) out hash of a checkpoint. It's the root of the balanced tree of all the out hashes
48
+ * from the first checkpoint in an epoch to the current checkpoint.
49
+ * It's this value that's set to the checkpoint header and validated on L1 instead of the checkpoint out hash.
50
+ * @param checkpointOutHashes - The out hashes of all checkpoints in the epoch.
51
+ * @returns The accumulated (epoch) out hash.
52
+ */
53
+ export function accumulateCheckpointOutHashes(checkpointOutHashes: Fr[]): Fr {
54
+ // See how the checkpoint out hashes are accumulated in `checkpoint_rollup_public_inputs_composer.nr > accumulate_checkpoint_out_hash()`.
55
+ const paddedOutHashes = padArrayEnd(
56
+ checkpointOutHashes.map(hash => hash.toBuffer()),
57
+ Buffer.alloc(32),
58
+ OUT_HASH_TREE_LEAF_COUNT,
59
+ );
60
+ return Fr.fromBuffer(computeBalancedShaRoot(paddedOutHashes));
36
61
  }
37
62
 
38
- // The root of this tree should match the `out_hash` calculated in the circuits. Zero hashes are compressed to reduce
39
- // cost if the non-zero leaves result in a shorter path.
40
- function aggregateOutHashes(outHashes: Fr[]): Fr {
41
- if (!outHashes.length) {
42
- return Fr.ZERO;
43
- }
44
-
45
- return Fr.fromBuffer(computeCompressedUnbalancedShaRoot(outHashes.map(hash => hash.toBuffer())));
63
+ /**
64
+ * Computes the epoch out hash. It's the root of the balanced tree of all the checkpoint out hashes.
65
+ * It should match the **accumulated** out hash of the last checkpoint in the epoch.
66
+ * This value will be inserted into the Outbox on L1.
67
+ * @param messagesPerCheckpoint - The L2-to-L1 messages emitted by the txs in the blocks in the checkpoints in the epoch.
68
+ * This is an array of arrays of arrays of messages. The array at index 0 contains the arrays of arrays of messages
69
+ * emitted by the first checkpoint, the array at index 1 contains the arrays of arrays of messages emitted by the second
70
+ * checkpoint, and so on.
71
+ * @returns The epoch out hash.
72
+ */
73
+ export function computeEpochOutHash(messagesPerCheckpoint: Fr[][][][]): Fr {
74
+ // See how the accumulated out hash is assigned to the root rollup's public inputs in `root_rollup.nr`.
75
+ const checkpointOutHashes = messagesPerCheckpoint.map(checkpoint => computeCheckpointOutHash(checkpoint));
76
+ return accumulateCheckpointOutHashes(checkpointOutHashes);
46
77
  }
@@ -1,4 +1,3 @@
1
- import { toBigIntBE } from '@aztec/foundation/bigint-buffer';
2
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
2
  import { Fr } from '@aztec/foundation/curves/bn254';
4
3
  import { Point } from '@aztec/foundation/curves/grumpkin';
@@ -56,8 +55,10 @@ export class NoteDao {
56
55
  /** The L2 block hash in which the tx with this note was included. Used for note management while processing
57
56
  * reorgs.*/
58
57
  public l2BlockHash: string,
59
- /** The index of the leaf in the global note hash tree the note is stored at */
60
- public index: bigint,
58
+ /** The index of the tx within the block, used for ordering notes. */
59
+ public txIndexInBlock: number,
60
+ /** The index of the note within the tx (based on note hash position), used for ordering notes. */
61
+ public noteIndexInTx: number,
61
62
  ) {}
62
63
 
63
64
  toBuffer(): Buffer {
@@ -73,7 +74,8 @@ export class NoteDao {
73
74
  this.txHash,
74
75
  this.l2BlockNumber,
75
76
  Fr.fromHexString(this.l2BlockHash),
76
- this.index,
77
+ this.txIndexInBlock,
78
+ this.noteIndexInTx,
77
79
  ]);
78
80
  }
79
81
 
@@ -91,7 +93,8 @@ export class NoteDao {
91
93
  const txHash = reader.readObject(TxHash);
92
94
  const l2BlockNumber = BlockNumber(reader.readNumber());
93
95
  const l2BlockHash = Fr.fromBuffer(reader).toString();
94
- const index = toBigIntBE(reader.readBytes(32));
96
+ const txIndexInBlock = reader.readNumber();
97
+ const noteIndexInTx = reader.readNumber();
95
98
 
96
99
  return new NoteDao(
97
100
  note,
@@ -105,7 +108,8 @@ export class NoteDao {
105
108
  txHash,
106
109
  l2BlockNumber,
107
110
  l2BlockHash,
108
- index,
111
+ txIndexInBlock,
112
+ noteIndexInTx,
109
113
  );
110
114
  }
111
115
 
@@ -134,7 +138,8 @@ export class NoteDao {
134
138
  this.txHash.equals(other.txHash) &&
135
139
  this.l2BlockNumber === other.l2BlockNumber &&
136
140
  this.l2BlockHash === other.l2BlockHash &&
137
- this.index === other.index
141
+ this.txIndexInBlock === other.txIndexInBlock &&
142
+ this.noteIndexInTx === other.noteIndexInTx
138
143
  );
139
144
  }
140
145
 
@@ -143,11 +148,9 @@ export class NoteDao {
143
148
  * @returns - Its size in bytes.
144
149
  */
145
150
  public getSize() {
146
- const indexSize = Math.ceil(Math.log2(Number(this.index)));
147
151
  const noteSize = 4 + this.note.items.length * Fr.SIZE_IN_BYTES;
148
- return (
149
- noteSize + AztecAddress.SIZE_IN_BYTES * 2 + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + indexSize
150
- );
152
+ // 2 numbers for txIndexInBlock and noteIndexInTx (4 bytes each)
153
+ return noteSize + AztecAddress.SIZE_IN_BYTES * 2 + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + 8;
151
154
  }
152
155
 
153
156
  static async random({
@@ -162,7 +165,8 @@ export class NoteDao {
162
165
  txHash = TxHash.random(),
163
166
  l2BlockNumber = BlockNumber(Math.floor(Math.random() * 1000)),
164
167
  l2BlockHash = Fr.random().toString(),
165
- index = Fr.random().toBigInt(),
168
+ txIndexInBlock = Math.floor(Math.random() * 100),
169
+ noteIndexInTx = Math.floor(Math.random() * 100),
166
170
  }: Partial<NoteDao> = {}) {
167
171
  return new NoteDao(
168
172
  note,
@@ -176,7 +180,8 @@ export class NoteDao {
176
180
  txHash,
177
181
  l2BlockNumber,
178
182
  l2BlockHash,
179
- index,
183
+ txIndexInBlock,
184
+ noteIndexInTx,
180
185
  );
181
186
  }
182
187
  }
@@ -1,7 +1,7 @@
1
1
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
2
 
3
3
  import { CommitteeAttestation } from '../block/index.js';
4
- import type { BlockAttestation } from './block_attestation.js';
4
+ import type { CheckpointAttestation } from './checkpoint_attestation.js';
5
5
 
6
6
  /**
7
7
  * Returns attestation signatures in the order of a series of provided ethereum addresses
@@ -9,10 +9,10 @@ import type { BlockAttestation } from './block_attestation.js';
9
9
  * @todo: perform this logic within the memory attestation store instead?
10
10
  */
11
11
  export function orderAttestations(
12
- attestations: BlockAttestation[],
12
+ attestations: CheckpointAttestation[],
13
13
  orderAddresses: EthAddress[],
14
14
  ): CommitteeAttestation[] {
15
- // Create a map of sender addresses to BlockAttestations
15
+ // Create a map of sender addresses to attestations
16
16
  const attestationMap = new Map<string, CommitteeAttestation>();
17
17
 
18
18
  for (const attestation of attestations) {