@aztec/stdlib 0.0.1-commit.6c91f13 → 0.0.1-commit.6d3c34e

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 (240) hide show
  1. package/dest/abi/contract_artifact.d.ts +2 -2
  2. package/dest/abi/contract_artifact.d.ts.map +1 -1
  3. package/dest/abi/contract_artifact.js +1 -1
  4. package/dest/abi/selector.js +3 -1
  5. package/dest/avm/avm_accumulated_data.js +5 -2
  6. package/dest/avm/avm_circuit_public_inputs.js +3 -1
  7. package/dest/avm/public_data_update_request.js +3 -1
  8. package/dest/avm/public_inner_call_request.js +3 -1
  9. package/dest/avm/revert_code.js +3 -1
  10. package/dest/aztec-address/index.js +4 -2
  11. package/dest/block/attestation_info.d.ts +5 -5
  12. package/dest/block/attestation_info.d.ts.map +1 -1
  13. package/dest/block/attestation_info.js +4 -4
  14. package/dest/block/body.js +3 -1
  15. package/dest/block/l2_block.d.ts +6 -3
  16. package/dest/block/l2_block.d.ts.map +1 -1
  17. package/dest/block/l2_block.js +6 -4
  18. package/dest/block/l2_block_code_to_purge.d.ts +2 -3
  19. package/dest/block/l2_block_code_to_purge.d.ts.map +1 -1
  20. package/dest/block/l2_block_code_to_purge.js +2 -8
  21. package/dest/block/l2_block_header.d.ts +8 -12
  22. package/dest/block/l2_block_header.d.ts.map +1 -1
  23. package/dest/block/l2_block_header.js +25 -18
  24. package/dest/block/l2_block_new.d.ts +1 -2
  25. package/dest/block/l2_block_new.d.ts.map +1 -1
  26. package/dest/block/l2_block_new.js +4 -1
  27. package/dest/block/l2_block_source.d.ts +245 -41
  28. package/dest/block/l2_block_source.d.ts.map +1 -1
  29. package/dest/block/l2_block_source.js +23 -5
  30. package/dest/block/l2_block_stream/index.d.ts +2 -1
  31. package/dest/block/l2_block_stream/index.d.ts.map +1 -1
  32. package/dest/block/l2_block_stream/index.js +1 -0
  33. package/dest/block/l2_block_stream/interfaces.d.ts +12 -5
  34. package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
  35. package/dest/block/l2_block_stream/l2_block_stream.d.ts +4 -2
  36. package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
  37. package/dest/block/l2_block_stream/l2_block_stream.js +102 -30
  38. package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts +24 -16
  39. package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts.map +1 -1
  40. package/dest/block/l2_block_stream/l2_tips_memory_store.js +55 -61
  41. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +49 -0
  42. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -0
  43. package/dest/block/l2_block_stream/l2_tips_store_base.js +179 -0
  44. package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
  45. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  46. package/dest/block/test/l2_tips_store_test_suite.js +483 -38
  47. package/dest/block/validate_block_result.d.ts +24 -24
  48. package/dest/block/validate_block_result.d.ts.map +1 -1
  49. package/dest/block/validate_block_result.js +13 -13
  50. package/dest/checkpoint/checkpoint.d.ts +1 -1
  51. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  52. package/dest/checkpoint/checkpoint.js +1 -0
  53. package/dest/checkpoint/checkpoint_info.d.ts +32 -3
  54. package/dest/checkpoint/checkpoint_info.d.ts.map +1 -1
  55. package/dest/checkpoint/checkpoint_info.js +34 -1
  56. package/dest/checkpoint/index.d.ts +2 -1
  57. package/dest/checkpoint/index.d.ts.map +1 -1
  58. package/dest/checkpoint/index.js +1 -0
  59. package/dest/database-version/version_manager.js +3 -1
  60. package/dest/gas/gas.js +3 -1
  61. package/dest/gas/gas_fees.js +3 -1
  62. package/dest/interfaces/api_limit.d.ts +2 -1
  63. package/dest/interfaces/api_limit.d.ts.map +1 -1
  64. package/dest/interfaces/api_limit.js +1 -0
  65. package/dest/interfaces/archiver.d.ts +6 -6
  66. package/dest/interfaces/archiver.d.ts.map +1 -1
  67. package/dest/interfaces/archiver.js +6 -4
  68. package/dest/interfaces/aztec-node-admin.d.ts +12 -6
  69. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  70. package/dest/interfaces/aztec-node-admin.js +2 -2
  71. package/dest/interfaces/aztec-node.d.ts +11 -10
  72. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  73. package/dest/interfaces/aztec-node.js +10 -5
  74. package/dest/interfaces/configs.d.ts +6 -1
  75. package/dest/interfaces/configs.d.ts.map +1 -1
  76. package/dest/interfaces/configs.js +2 -1
  77. package/dest/interfaces/p2p.d.ts +7 -9
  78. package/dest/interfaces/p2p.d.ts.map +1 -1
  79. package/dest/interfaces/p2p.js +3 -4
  80. package/dest/interfaces/proving-job.d.ts +170 -170
  81. package/dest/interfaces/proving-job.d.ts.map +1 -1
  82. package/dest/interfaces/proving-job.js +1 -7
  83. package/dest/interfaces/server_circuit_prover.d.ts +4 -3
  84. package/dest/interfaces/server_circuit_prover.d.ts.map +1 -1
  85. package/dest/interfaces/validator.d.ts +41 -7
  86. package/dest/interfaces/validator.d.ts.map +1 -1
  87. package/dest/interfaces/validator.js +3 -1
  88. package/dest/kernel/claimed_length_array.js +3 -1
  89. package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts +6 -5
  90. package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts.map +1 -1
  91. package/dest/kernel/hints/build_note_hash_read_request_hints.js +5 -6
  92. package/dest/kernel/hints/transient_data_squashing_hint.js +3 -1
  93. package/dest/kernel/log_hash.js +3 -1
  94. package/dest/kernel/private_log_data.js +5 -2
  95. package/dest/kernel/private_to_avm_accumulated_data.js +5 -2
  96. package/dest/kernel/private_to_public_accumulated_data.js +3 -1
  97. package/dest/kernel/private_to_rollup_accumulated_data.js +3 -1
  98. package/dest/kernel/private_validation_requests.js +3 -1
  99. package/dest/kernel/public_call_request.js +5 -2
  100. package/dest/logs/contract_class_log.js +3 -1
  101. package/dest/logs/private_log.js +3 -1
  102. package/dest/logs/public_log.js +3 -1
  103. package/dest/messaging/in_hash.d.ts +4 -2
  104. package/dest/messaging/in_hash.d.ts.map +1 -1
  105. package/dest/messaging/in_hash.js +3 -1
  106. package/dest/messaging/l2_to_l1_membership.d.ts +88 -6
  107. package/dest/messaging/l2_to_l1_membership.d.ts.map +1 -1
  108. package/dest/messaging/l2_to_l1_membership.js +158 -42
  109. package/dest/messaging/out_hash.d.ts +2 -1
  110. package/dest/messaging/out_hash.d.ts.map +1 -1
  111. package/dest/messaging/out_hash.js +13 -4
  112. package/dest/p2p/attestation_utils.d.ts +3 -3
  113. package/dest/p2p/attestation_utils.d.ts.map +1 -1
  114. package/dest/p2p/attestation_utils.js +1 -1
  115. package/dest/p2p/block_proposal.d.ts +85 -21
  116. package/dest/p2p/block_proposal.d.ts.map +1 -1
  117. package/dest/p2p/block_proposal.js +120 -37
  118. package/dest/p2p/checkpoint_attestation.d.ts +77 -0
  119. package/dest/p2p/checkpoint_attestation.d.ts.map +1 -0
  120. package/dest/p2p/{block_attestation.js → checkpoint_attestation.js} +22 -19
  121. package/dest/p2p/checkpoint_proposal.d.ts +154 -0
  122. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -0
  123. package/dest/p2p/checkpoint_proposal.js +217 -0
  124. package/dest/p2p/consensus_payload.d.ts +6 -7
  125. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  126. package/dest/p2p/consensus_payload.js +3 -2
  127. package/dest/p2p/gossipable.d.ts +4 -3
  128. package/dest/p2p/gossipable.d.ts.map +1 -1
  129. package/dest/p2p/gossipable.js +16 -5
  130. package/dest/p2p/index.d.ts +4 -2
  131. package/dest/p2p/index.d.ts.map +1 -1
  132. package/dest/p2p/index.js +3 -1
  133. package/dest/p2p/signature_utils.d.ts +5 -3
  134. package/dest/p2p/signature_utils.d.ts.map +1 -1
  135. package/dest/p2p/signature_utils.js +3 -1
  136. package/dest/p2p/signed_txs.d.ts +40 -0
  137. package/dest/p2p/signed_txs.d.ts.map +1 -0
  138. package/dest/p2p/signed_txs.js +70 -0
  139. package/dest/p2p/topic_type.d.ts +3 -2
  140. package/dest/p2p/topic_type.d.ts.map +1 -1
  141. package/dest/p2p/topic_type.js +8 -2
  142. package/dest/rollup/block_rollup_public_inputs.d.ts +4 -9
  143. package/dest/rollup/block_rollup_public_inputs.d.ts.map +1 -1
  144. package/dest/rollup/block_rollup_public_inputs.js +6 -10
  145. package/dest/rollup/checkpoint_constant_data.js +3 -1
  146. package/dest/rollup/checkpoint_header.d.ts +15 -12
  147. package/dest/rollup/checkpoint_header.d.ts.map +1 -1
  148. package/dest/rollup/checkpoint_header.js +33 -19
  149. package/dest/rollup/checkpoint_rollup_public_inputs.d.ts +6 -1
  150. package/dest/rollup/checkpoint_rollup_public_inputs.d.ts.map +1 -1
  151. package/dest/rollup/checkpoint_rollup_public_inputs.js +6 -2
  152. package/dest/rollup/root_rollup_public_inputs.d.ts +8 -3
  153. package/dest/rollup/root_rollup_public_inputs.d.ts.map +1 -1
  154. package/dest/rollup/root_rollup_public_inputs.js +6 -3
  155. package/dest/tests/factories.d.ts +15 -7
  156. package/dest/tests/factories.d.ts.map +1 -1
  157. package/dest/tests/factories.js +57 -13
  158. package/dest/tests/mocks.d.ts +59 -10
  159. package/dest/tests/mocks.d.ts.map +1 -1
  160. package/dest/tests/mocks.js +89 -41
  161. package/dest/trees/append_only_tree_snapshot.js +3 -1
  162. package/dest/tx/block_header.js +3 -1
  163. package/dest/tx/call_context.js +3 -1
  164. package/dest/tx/global_variable_builder.d.ts +2 -2
  165. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  166. package/dest/tx/global_variables.js +3 -1
  167. package/dest/tx/index.d.ts +1 -2
  168. package/dest/tx/index.d.ts.map +1 -1
  169. package/dest/tx/index.js +0 -1
  170. package/dest/tx/private_execution_result.d.ts +1 -5
  171. package/dest/tx/private_execution_result.d.ts.map +1 -1
  172. package/dest/tx/private_execution_result.js +3 -20
  173. package/dest/tx/public_call_request_with_calldata.js +3 -1
  174. package/dest/tx/state_reference.js +3 -1
  175. package/dest/tx/tree_snapshots.js +3 -1
  176. package/dest/tx/tx.d.ts +1 -1
  177. package/dest/tx/tx.d.ts.map +1 -1
  178. package/dest/tx/tx.js +3 -1
  179. package/dest/tx/tx_effect.js +3 -1
  180. package/dest/tx/tx_execution_request.d.ts +1 -1
  181. package/dest/tx/tx_execution_request.d.ts.map +1 -1
  182. package/dest/tx/tx_execution_request.js +6 -2
  183. package/package.json +8 -8
  184. package/src/abi/contract_artifact.ts +10 -10
  185. package/src/block/attestation_info.ts +9 -6
  186. package/src/block/l2_block.ts +6 -5
  187. package/src/block/l2_block_code_to_purge.ts +3 -11
  188. package/src/block/l2_block_header.ts +26 -17
  189. package/src/block/l2_block_new.ts +5 -1
  190. package/src/block/l2_block_source.ts +66 -16
  191. package/src/block/l2_block_stream/index.ts +1 -0
  192. package/src/block/l2_block_stream/interfaces.ts +12 -4
  193. package/src/block/l2_block_stream/l2_block_stream.ts +121 -38
  194. package/src/block/l2_block_stream/l2_tips_memory_store.ts +62 -56
  195. package/src/block/l2_block_stream/l2_tips_store_base.ts +226 -0
  196. package/src/block/test/l2_tips_store_test_suite.ts +485 -36
  197. package/src/block/validate_block_result.ts +35 -31
  198. package/src/checkpoint/checkpoint.ts +1 -0
  199. package/src/checkpoint/checkpoint_info.ts +45 -2
  200. package/src/checkpoint/index.ts +1 -0
  201. package/src/interfaces/api_limit.ts +1 -0
  202. package/src/interfaces/archiver.ts +14 -6
  203. package/src/interfaces/aztec-node-admin.ts +5 -2
  204. package/src/interfaces/aztec-node.ts +43 -13
  205. package/src/interfaces/configs.ts +5 -0
  206. package/src/interfaces/p2p.ts +8 -12
  207. package/src/interfaces/proving-job.ts +2 -11
  208. package/src/interfaces/server_circuit_prover.ts +3 -2
  209. package/src/interfaces/validator.ts +57 -7
  210. package/src/kernel/hints/build_note_hash_read_request_hints.ts +5 -8
  211. package/src/messaging/in_hash.ts +3 -1
  212. package/src/messaging/l2_to_l1_membership.ts +176 -52
  213. package/src/messaging/out_hash.ts +17 -7
  214. package/src/p2p/attestation_utils.ts +3 -3
  215. package/src/p2p/block_proposal.ts +185 -41
  216. package/src/p2p/{block_attestation.ts → checkpoint_attestation.ts} +31 -25
  217. package/src/p2p/checkpoint_proposal.ts +337 -0
  218. package/src/p2p/consensus_payload.ts +5 -2
  219. package/src/p2p/gossipable.ts +14 -4
  220. package/src/p2p/index.ts +3 -1
  221. package/src/p2p/signature_utils.ts +3 -1
  222. package/src/p2p/signed_txs.ts +83 -0
  223. package/src/p2p/topic_type.ts +3 -2
  224. package/src/rollup/block_rollup_public_inputs.ts +3 -9
  225. package/src/rollup/checkpoint_header.ts +43 -20
  226. package/src/rollup/checkpoint_rollup_public_inputs.ts +6 -0
  227. package/src/rollup/root_rollup_public_inputs.ts +6 -0
  228. package/src/tests/factories.ts +53 -17
  229. package/src/tests/mocks.ts +166 -64
  230. package/src/tx/global_variable_builder.ts +1 -1
  231. package/src/tx/index.ts +0 -1
  232. package/src/tx/private_execution_result.ts +0 -15
  233. package/src/tx/tx.ts +2 -0
  234. package/src/tx/tx_execution_request.ts +2 -0
  235. package/dest/p2p/block_attestation.d.ts +0 -80
  236. package/dest/p2p/block_attestation.d.ts.map +0 -1
  237. package/dest/tx/content_commitment.d.ts +0 -49
  238. package/dest/tx/content_commitment.d.ts.map +0 -1
  239. package/dest/tx/content_commitment.js +0 -90
  240. package/src/tx/content_commitment.ts +0 -113
@@ -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
  /**
@@ -44,6 +51,14 @@ export interface ValidatorClientConfig {
44
51
 
45
52
  /** Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus */
46
53
  fishermanMode?: boolean;
54
+
55
+ // TODO(palla/mbps): Change default to false once checkpoint validation is stable
56
+ /** Skip checkpoint proposal validation and always attest (default: true) */
57
+ skipCheckpointProposalValidation?: boolean;
58
+
59
+ // TODO(palla/mbps): Change default to false once block sync is stable
60
+ /** Skip pushing re-executed blocks to archiver (default: true) */
61
+ skipPushProposedBlocksToArchiver?: boolean;
47
62
  }
48
63
 
49
64
  export type ValidatorClientFullConfig = ValidatorClientConfig &
@@ -66,6 +81,8 @@ export const ValidatorClientConfigSchema = zodFor<Omit<ValidatorClientConfig, 'v
66
81
  validatorReexecuteDeadlineMs: z.number().min(0),
67
82
  alwaysReexecuteBlockProposals: z.boolean().optional(),
68
83
  fishermanMode: z.boolean().optional(),
84
+ skipCheckpointProposalValidation: z.boolean().optional(),
85
+ skipPushProposedBlocksToArchiver: z.boolean().optional(),
69
86
  }),
70
87
  );
71
88
 
@@ -78,23 +95,56 @@ export const ValidatorClientFullConfigSchema = zodFor<Omit<ValidatorClientFullCo
78
95
  }),
79
96
  );
80
97
 
98
+ export type CreateCheckpointProposalLastBlockData = Omit<CheckpointLastBlockData, 'txHashes'> & { txs: Tx[] };
99
+
81
100
  export interface Validator {
82
101
  start(): Promise<void>;
83
102
  updateConfig(config: Partial<ValidatorClientFullConfig>): void;
84
103
 
85
104
  // Block validation responsibilities
86
105
  createBlockProposal(
87
- blockNumber: number,
88
- header: CheckpointHeader,
106
+ blockHeader: BlockHeader,
107
+ indexWithinCheckpoint: number,
108
+ inHash: Fr,
89
109
  archive: Fr,
90
110
  txs: Tx[],
91
111
  proposerAddress: EthAddress | undefined,
92
112
  options: BlockProposalOptions,
93
113
  ): Promise<BlockProposal | undefined>;
94
- attestToProposal(proposal: BlockProposal, sender: PeerId): Promise<BlockAttestation[] | undefined>;
114
+
115
+ /** Creates a checkpoint proposal for the last block in a checkpoint */
116
+ createCheckpointProposal(
117
+ checkpointHeader: CheckpointHeader,
118
+ archive: Fr,
119
+ lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
120
+ proposerAddress: EthAddress | undefined,
121
+ options: CheckpointProposalOptions,
122
+ ): Promise<CheckpointProposal>;
123
+
124
+ /**
125
+ * Validate a block proposal from a peer.
126
+ * Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
127
+ * @returns true if the proposal is valid, false otherwise
128
+ */
129
+ validateBlockProposal(proposal: BlockProposal, sender: PeerId): Promise<boolean>;
130
+
131
+ /**
132
+ * Validate and attest to a checkpoint proposal from a peer.
133
+ * @returns Checkpoint attestations if valid, undefined otherwise
134
+ */
135
+ attestToCheckpointProposal(
136
+ proposal: CheckpointProposal,
137
+ sender: PeerId,
138
+ ): Promise<CheckpointAttestation[] | undefined>;
95
139
 
96
140
  broadcastBlockProposal(proposal: BlockProposal): Promise<void>;
97
- collectAttestations(proposal: BlockProposal, required: number, deadline: Date): Promise<BlockAttestation[]>;
141
+
142
+ /** Collect own attestations for a checkpoint proposal (used when skipping p2p attestation collection) */
143
+ collectOwnAttestations(proposal: CheckpointProposal): Promise<CheckpointAttestation[]>;
144
+
145
+ /** Collect attestations from the p2p network for a checkpoint proposal */
146
+ collectAttestations(proposal: CheckpointProposal, required: number, deadline: Date): Promise<CheckpointAttestation[]>;
147
+
98
148
  signAttestationsAndSigners(
99
149
  attestationsAndSigners: CommitteeAttestationsAndSigners,
100
150
  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
  );
@@ -3,7 +3,9 @@ import { padArrayEnd } from '@aztec/foundation/collection';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { computeBalancedShaRoot } from '@aztec/foundation/trees';
5
5
 
6
- /** Computes the inHash for a block's ContentCommitment given its l1 to l2 messages. */
6
+ /**
7
+ * Computes the inHash for a checkpoint (or the first block in a checkpoint) given its l1 to l2 messages.
8
+ */
7
9
  export function computeInHashFromL1ToL2Messages(unpaddedL1ToL2Messages: Fr[]): Fr {
8
10
  const l1ToL2Messages = padArrayEnd<Fr, number>(unpaddedL1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
9
11
  return new Fr(computeBalancedShaRoot(l1ToL2Messages.map(msg => msg.toBuffer())));
@@ -1,9 +1,99 @@
1
- import type { BlockNumber } from '@aztec/foundation/branded-types';
1
+ import { AZTEC_MAX_EPOCH_DURATION } from '@aztec/constants';
2
+ import type { EpochNumber } from '@aztec/foundation/branded-types';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { SiblingPath, UnbalancedMerkleTreeCalculator, computeUnbalancedShaRoot } from '@aztec/foundation/trees';
4
5
 
6
+ /**
7
+ * # L2-to-L1 Message Tree Structure and Leaf IDs
8
+ *
9
+ * ## Overview
10
+ * L2-to-L1 messages are organized in a hierarchical 4-level tree structure within each epoch:
11
+ * Epoch → Checkpoints → Blocks → Transactions → Messages
12
+ *
13
+ * Each level uses an unbalanced Merkle tree, and some levels use compression (skipping zero hashes).
14
+ *
15
+ * ## Tree Levels
16
+ *
17
+ * 1. **Message Tree (TX Out Hash)**
18
+ * - Leaves: Individual L2-to-L1 messages within a transaction
19
+ * - Root: TX out hash
20
+ * - Type: Unbalanced, non-compressed (the circuits ensure that all messages are not empty.)
21
+ *
22
+ * 2. **Block Tree**
23
+ * - Leaves: TX out hashes from all transactions in a block
24
+ * - Root: Block out hash
25
+ * - Type: Unbalanced, compressed (zero hashes are skipped)
26
+ * - Compression: If a tx has no messages (out hash = 0), that branch is ignored
27
+ *
28
+ * 3. **Checkpoint Tree**
29
+ * - Leaves: Block out hashes from all blocks in a checkpoint
30
+ * - Root: Checkpoint out hash
31
+ * - Type: Unbalanced, compressed (zero hashes are skipped)
32
+ * - Compression: If a block has no messages (out hash = 0), that branch is ignored
33
+ *
34
+ * 4. **Epoch Tree**
35
+ * - Leaves: Checkpoint out hashes from all checkpoints in an epoch (padded to AZTEC_MAX_EPOCH_DURATION)
36
+ * - Root: Epoch out hash (set in the root rollup's public inputs and inserted into the Outbox on L1 when the epoch is proven)
37
+ * - Type: Unbalanced, non-compressed
38
+ * - **Important**: Padded with zeros up to AZTEC_MAX_EPOCH_DURATION to allow for proofs of partial epochs
39
+ *
40
+ * ## Combined Membership Proof
41
+ * To prove a message exists in an epoch, we combine the sibling paths from all 4 trees:
42
+ * [message siblings] + [tx siblings] + [block siblings] + [checkpoint siblings]
43
+ *
44
+ * ## Leaf ID: Stable Message Identification
45
+ *
46
+ * Each message gets a unique, stable **leaf ID** that identifies its position in the combined tree.
47
+ * The leaf ID is computed as:
48
+ * leafId = 2^pathSize + leafIndex
49
+ *
50
+ * Where:
51
+ * - `pathSize`: Total length of the combined sibling path (from all 4 tree levels)
52
+ * - `leafIndex`: The message's index in a balanced tree representation at that height
53
+ *
54
+ * ### Why Leaf IDs Are Stable
55
+ *
56
+ * The leaf ID is based on the message's position in the tree structure, which is determined by:
57
+ * - The checkpoint index within the epoch
58
+ * - The block index within the checkpoint
59
+ * - The transaction index within the block
60
+ * - The message index within the transaction
61
+ *
62
+ * These indices are structural and do NOT depend on the total number of blocks/checkpoints in the epoch.
63
+ *
64
+ * ### Critical Property: Preserving Consumed Status
65
+ *
66
+ * **Problem**: On L1, epoch proofs can be submitted incrementally. For example:
67
+ * - First, a proof for checkpoints 1-10 of epoch 0 is submitted (proves the first 10 checkpoints)
68
+ * - Later, a proof for checkpoints 1-20 of epoch 0 is submitted (proves all 20 checkpoints)
69
+ *
70
+ * When the longer proof is submitted, it updates the epoch's out hash root on L1 to reflect the complete epoch (all 20
71
+ * checkpoints). However, some messages from checkpoints 1-10 may have already been consumed.
72
+ *
73
+ * **Solution**: The Outbox on L1 tracks consumed messages using a bitmap indexed by leaf ID.
74
+ * Because leaf IDs are stable (they don't change when more checkpoints are added to the epoch), messages that were consumed
75
+ * under the shorter proof remain marked as consumed under the longer proof.
76
+ *
77
+ * This prevents double-spending of L2-to-L1 messages when longer epoch proofs are submitted.
78
+ */
79
+
80
+ /**
81
+ * Computes the unique leaf ID for an L2-to-L1 message.
82
+ *
83
+ * The leaf ID is stable across different epoch proof lengths and is used by the Outbox
84
+ * on L1 to track which messages have been consumed.
85
+ *
86
+ * @param membershipWitness - Contains the leafIndex and siblingPath for the message
87
+ * @returns The unique leaf ID used for tracking message consumption on L1
88
+ */
89
+ export function getL2ToL1MessageLeafId(
90
+ membershipWitness: Pick<L2ToL1MembershipWitness, 'leafIndex' | 'siblingPath'>,
91
+ ): bigint {
92
+ return 2n ** BigInt(membershipWitness.siblingPath.pathSize) + membershipWitness.leafIndex;
93
+ }
94
+
5
95
  export interface MessageRetrieval {
6
- getL2ToL1Messages(l2BlockNumber: BlockNumber): Promise<Fr[][] | undefined>;
96
+ getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]>;
7
97
  }
8
98
 
9
99
  export type L2ToL1MembershipWitness = {
@@ -14,76 +104,99 @@ export type L2ToL1MembershipWitness = {
14
104
 
15
105
  export async function computeL2ToL1MembershipWitness(
16
106
  messageRetriever: MessageRetrieval,
17
- l2BlockNumber: BlockNumber,
107
+ epoch: EpochNumber,
18
108
  message: Fr,
19
109
  ): Promise<L2ToL1MembershipWitness | undefined> {
20
- const messagesForAllTxs = await messageRetriever.getL2ToL1Messages(l2BlockNumber);
21
- if (!messagesForAllTxs) {
110
+ const messagesInEpoch = await messageRetriever.getL2ToL1Messages(epoch);
111
+ if (messagesInEpoch.length === 0) {
22
112
  return undefined;
23
113
  }
24
114
 
25
- return computeL2ToL1MembershipWitnessFromMessagesForAllTxs(messagesForAllTxs, message);
115
+ return computeL2ToL1MembershipWitnessFromMessagesInEpoch(messagesInEpoch, message);
26
116
  }
27
117
 
28
118
  // TODO: Allow to specify the message to consume by its index or by an offset, in case there are multiple messages with
29
119
  // the same value.
30
- export function computeL2ToL1MembershipWitnessFromMessagesForAllTxs(
31
- messagesForAllTxs: Fr[][],
120
+ export function computeL2ToL1MembershipWitnessFromMessagesInEpoch(
121
+ messagesInEpoch: Fr[][][][],
32
122
  message: Fr,
33
123
  ): L2ToL1MembershipWitness {
34
- // Find index of message in subtree and index of tx in a block.
124
+ // Find the index of the message in the tx, index of the tx in the block, and index of the block in the epoch.
35
125
  let messageIndexInTx = -1;
36
- const txIndex = messagesForAllTxs.findIndex(messages => {
37
- messageIndexInTx = messages.findIndex(msg => msg.equals(message));
38
- return messageIndexInTx !== -1;
126
+ let txIndex = -1;
127
+ let blockIndex = -1;
128
+ const checkpointIndex = messagesInEpoch.findIndex(messagesInCheckpoint => {
129
+ blockIndex = messagesInCheckpoint.findIndex(messagesInBlock => {
130
+ txIndex = messagesInBlock.findIndex(messagesInTx => {
131
+ messageIndexInTx = messagesInTx.findIndex(msg => msg.equals(message));
132
+ return messageIndexInTx !== -1;
133
+ });
134
+ return txIndex !== -1;
135
+ });
136
+ return blockIndex !== -1;
39
137
  });
40
138
 
41
- if (txIndex === -1) {
139
+ if (checkpointIndex === -1) {
42
140
  throw new Error('The L2ToL1Message you are trying to prove inclusion of does not exist');
43
141
  }
44
142
 
45
- // Get the txOutHash and the sibling path of the message in the tx subtree.
46
- const txMessages = messagesForAllTxs[txIndex];
47
- const txOutHashTree = UnbalancedMerkleTreeCalculator.create(txMessages.map(msg => msg.toBuffer()));
48
- const txOutHash = txOutHashTree.getRoot();
49
- const messagePathInSubtree = txOutHashTree.getSiblingPath(message.toBuffer());
50
-
51
- // Calculate txOutHash for all txs.
52
- const txSubtreeRoots = messagesForAllTxs.map((messages, i) => {
53
- // For a tx with no messages, we have to set an out hash of 0 to match what the circuit does.
54
- if (messages.length === 0) {
55
- return Fr.ZERO;
56
- }
143
+ // Build the tx tree.
144
+ const messagesInTx = messagesInEpoch[checkpointIndex][blockIndex][txIndex];
145
+ const txTree = UnbalancedMerkleTreeCalculator.create(messagesInTx.map(msg => msg.toBuffer()));
146
+ // Get the sibling path of the target message in the tx tree.
147
+ const pathToMessageInTxSubtree = txTree.getSiblingPathByLeafIndex(messageIndexInTx);
57
148
 
58
- if (i === txIndex) {
59
- return Fr.fromBuffer(txOutHash);
60
- }
149
+ // Build the tree of the block containing the target message.
150
+ const blockTree = buildBlockTree(messagesInEpoch[checkpointIndex][blockIndex]);
151
+ // Get the sibling path of the tx out hash in the block tree.
152
+ const pathToTxOutHashInBlockTree = blockTree.getSiblingPathByLeafIndex(txIndex);
61
153
 
62
- const root = computeUnbalancedShaRoot(messages.map(msg => msg.toBuffer()));
63
- return Fr.fromBuffer(root);
64
- });
154
+ // Build the tree of the checkpoint containing the target message.
155
+ const checkpointTree = buildCheckpointTree(messagesInEpoch[checkpointIndex]);
156
+ // Get the sibling path of the block out hash in the checkpoint tree.
157
+ const pathToBlockOutHashInCheckpointTree = checkpointTree.getSiblingPathByLeafIndex(blockIndex);
65
158
 
66
- // Construct the top tree.
67
- // The leaves of this tree are the `txOutHashes`.
68
- // The root of this tree should match the `out_hash` calculated in the circuits. Zero hashes are compressed to reduce
69
- // cost if the non-zero leaves result in a shorter path.
70
- const valueToCompress = Buffer.alloc(32);
71
- const topTree = UnbalancedMerkleTreeCalculator.create(
72
- txSubtreeRoots.map(root => root.toBuffer()),
73
- valueToCompress,
159
+ // Compute the out hashes of all checkpoints in the epoch.
160
+ let checkpointOutHashes = messagesInEpoch.map((messagesInCheckpoint, i) => {
161
+ if (i === checkpointIndex) {
162
+ return checkpointTree.getRoot();
163
+ }
164
+ return buildCheckpointTree(messagesInCheckpoint).getRoot();
165
+ });
166
+ // Pad to AZTEC_MAX_EPOCH_DURATION with zeros.
167
+ checkpointOutHashes = checkpointOutHashes.concat(
168
+ Array.from({ length: AZTEC_MAX_EPOCH_DURATION - messagesInEpoch.length }, () => Buffer.alloc(32)),
74
169
  );
75
- const root = Fr.fromBuffer(topTree.getRoot());
76
170
 
77
- // Compute the combined sibling path by appending the tx subtree path to the top tree path.
78
- const txPathInTopTree = topTree.getSiblingPath(txOutHash);
79
- const combinedPath = messagePathInSubtree.toBufferArray().concat(txPathInTopTree.toBufferArray());
171
+ // Build the epoch tree with all the checkpoint out hashes, including the padded zeros
172
+ const epochTree = UnbalancedMerkleTreeCalculator.create(checkpointOutHashes);
173
+ // Get the sibling path of the checkpoint out hash in the epoch tree.
174
+ const pathToCheckpointOutHashInEpochTree = epochTree.getSiblingPathByLeafIndex(checkpointIndex);
175
+
176
+ // The root of the epoch tree should match the `out_hash` in the root rollup's public inputs.
177
+ const root = Fr.fromBuffer(epochTree.getRoot());
178
+
179
+ // Compute the combined sibling path by appending the tx subtree path to the block tree path, then to the checkpoint
180
+ // tree path, then to the epoch tree path.
181
+ const combinedPath = pathToMessageInTxSubtree
182
+ .toBufferArray()
183
+ .concat(pathToTxOutHashInBlockTree.toBufferArray())
184
+ .concat(pathToBlockOutHashInCheckpointTree.toBufferArray())
185
+ .concat(pathToCheckpointOutHashInEpochTree.toBufferArray());
80
186
 
81
187
  // Compute the combined index.
82
- // It is the index of the message in the balanced tree at its current height.
83
- const txLeafIndexAtLevel = topTree.getLeafLocation(txIndex).index;
84
- const messageLeafPosition = txOutHashTree.getLeafLocation(messageIndexInTx);
85
- const numLeavesInLeftSubtrees = txLeafIndexAtLevel * (1 << messageLeafPosition.level);
86
- const combinedIndex = numLeavesInLeftSubtrees + messageLeafPosition.index;
188
+ // It is the index of the message in the balanced tree (by filling up the wonky tree with empty nodes) at its current
189
+ // height. It's used to validate the membership proof.
190
+ const messageLeafPosition = txTree.getLeafLocation(messageIndexInTx);
191
+ const txLeafPosition = blockTree.getLeafLocation(txIndex);
192
+ const blockLeafPosition = checkpointTree.getLeafLocation(blockIndex);
193
+ const checkpointLeafPosition = epochTree.getLeafLocation(checkpointIndex);
194
+ const numLeavesInLeftCheckpoints = checkpointLeafPosition.index * (1 << blockLeafPosition.level);
195
+ const indexAtCheckpointLevel = numLeavesInLeftCheckpoints + blockLeafPosition.index;
196
+ const numLeavesInLeftBlocks = indexAtCheckpointLevel * (1 << txLeafPosition.level);
197
+ const indexAtTxLevel = numLeavesInLeftBlocks + txLeafPosition.index;
198
+ const numLeavesInLeftTxs = indexAtTxLevel * (1 << messageLeafPosition.level);
199
+ const combinedIndex = numLeavesInLeftTxs + messageLeafPosition.index;
87
200
 
88
201
  return {
89
202
  root,
@@ -92,8 +205,19 @@ export function computeL2ToL1MembershipWitnessFromMessagesForAllTxs(
92
205
  };
93
206
  }
94
207
 
95
- export function getL2ToL1MessageLeafId(
96
- membershipWitness: Pick<L2ToL1MembershipWitness, 'leafIndex' | 'siblingPath'>,
97
- ): bigint {
98
- return 2n ** BigInt(membershipWitness.siblingPath.pathSize) + membershipWitness.leafIndex;
208
+ function buildCheckpointTree(messagesInCheckpoint: Fr[][][]) {
209
+ const blockOutHashes = messagesInCheckpoint.map(messagesInBlock => buildBlockTree(messagesInBlock).getRoot());
210
+ return buildCompressedTree(blockOutHashes);
211
+ }
212
+
213
+ function buildBlockTree(messagesInBlock: Fr[][]) {
214
+ const txOutHashes = messagesInBlock.map(messages => computeUnbalancedShaRoot(messages.map(msg => msg.toBuffer())));
215
+ return buildCompressedTree(txOutHashes);
216
+ }
217
+
218
+ function buildCompressedTree(leaves: Buffer[]) {
219
+ // Note: If a block or tx has no messages (i.e. leaf == Buffer.alloc(32)), we ignore that branch and only accumulate
220
+ // the non-zero hashes to match what the circuits do.
221
+ const valueToCompress = Buffer.alloc(32);
222
+ return UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress);
99
223
  }
@@ -1,5 +1,7 @@
1
+ import { AZTEC_MAX_EPOCH_DURATION } from '@aztec/constants';
2
+ import { padArrayEnd } from '@aztec/foundation/collection';
1
3
  import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { UnbalancedMerkleTreeCalculator, computeUnbalancedShaRoot } from '@aztec/foundation/trees';
4
+ import { computeCompressedUnbalancedShaRoot, computeUnbalancedShaRoot } from '@aztec/foundation/trees';
3
5
 
4
6
  export function computeTxOutHash(messages: Fr[]): Fr {
5
7
  if (!messages.length) {
@@ -20,6 +22,19 @@ export function computeCheckpointOutHash(messagesForAllTxs: Fr[][][]): Fr {
20
22
  return aggregateOutHashes(blockOutHashes);
21
23
  }
22
24
 
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));
36
+ }
37
+
23
38
  // The root of this tree should match the `out_hash` calculated in the circuits. Zero hashes are compressed to reduce
24
39
  // cost if the non-zero leaves result in a shorter path.
25
40
  function aggregateOutHashes(outHashes: Fr[]): Fr {
@@ -27,10 +42,5 @@ function aggregateOutHashes(outHashes: Fr[]): Fr {
27
42
  return Fr.ZERO;
28
43
  }
29
44
 
30
- const valueToCompress = Buffer.alloc(32);
31
- const tree = UnbalancedMerkleTreeCalculator.create(
32
- outHashes.map(hash => hash.toBuffer()),
33
- valueToCompress,
34
- );
35
- return Fr.fromBuffer(tree.getRoot());
45
+ return Fr.fromBuffer(computeCompressedUnbalancedShaRoot(outHashes.map(hash => hash.toBuffer())));
36
46
  }
@@ -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) {