@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
@@ -1,4 +1,4 @@
1
- import { SlotNumber } from '@aztec/foundation/branded-types';
1
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import { Buffer32 } from '@aztec/foundation/buffer';
3
3
  import { keccak256 } from '@aztec/foundation/crypto/keccak';
4
4
  import { tryRecoverAddress } from '@aztec/foundation/crypto/secp256k1-signer';
@@ -7,16 +7,19 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
7
7
  import { Signature } from '@aztec/foundation/eth-signature';
8
8
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
9
9
 
10
+ import type { L2Block } from '../block/l2_block.js';
10
11
  import type { L2BlockInfo } from '../block/l2_block_info.js';
12
+ import { MAX_TXS_PER_BLOCK } from '../deserialization/index.js';
13
+ import { BlockHeader } from '../tx/block_header.js';
11
14
  import { TxHash } from '../tx/index.js';
12
- import { Tx } from '../tx/tx.js';
13
- import { ConsensusPayload } from './consensus_payload.js';
15
+ import type { Tx } from '../tx/tx.js';
14
16
  import { Gossipable } from './gossipable.js';
15
17
  import {
16
18
  SignatureDomainSeparator,
17
19
  getHashedSignaturePayload,
18
20
  getHashedSignaturePayloadEthSignedMessage,
19
21
  } from './signature_utils.js';
22
+ import { SignedTxs } from './signed_txs.js';
20
23
  import { TopicType } from './topic_type.js';
21
24
 
22
25
  export class BlockProposalHash extends Buffer32 {
@@ -32,10 +35,9 @@ export type BlockProposalOptions = {
32
35
  };
33
36
 
34
37
  /**
35
- * BlockProposal
36
- *
37
- * A block proposal is created by the leader of the chain proposing a sequence of transactions to
38
- * be included in the head of the chain
38
+ * A block proposal is created by the leader of the chain proposing a sequence of transactions
39
+ * to be included in a block within a checkpoint. This is used for non-last blocks in a slot.
40
+ * The last block is sent as part of a CheckpointProposal.
39
41
  */
40
42
  export class BlockProposal extends Gossipable {
41
43
  static override p2pTopic = TopicType.block_proposal;
@@ -43,18 +45,28 @@ export class BlockProposal extends Gossipable {
43
45
  private sender: EthAddress | undefined;
44
46
 
45
47
  constructor(
46
- /** The payload of the message, and what the signature is over */
47
- public readonly payload: ConsensusPayload,
48
+ /** The per-block header containing block state and global variables */
49
+ public readonly blockHeader: BlockHeader,
48
50
 
49
- /** The signer of the BlockProposal over the header of the new block*/
50
- public readonly signature: Signature,
51
+ // TODO(palla/mbps): Is this really needed? Can we just derive it from the indexWithinCheckpoint of the parent block and the slot number?
52
+ // See the block-proposal-handler, we have a lot of extra validations to check this is correct, so maybe we can avoid storing it here.
53
+ /** Index of this block within the checkpoint (0-indexed) */
54
+ public readonly indexWithinCheckpoint: number,
55
+
56
+ /** Hash of L1 to L2 messages for this checkpoint (constant across all blocks in checkpoint) */
57
+ public readonly inHash: Fr,
58
+
59
+ /** Archive root after this block is applied */
60
+ public readonly archiveRoot: Fr,
51
61
 
52
62
  /** The sequence of transactions in the block */
53
63
  public readonly txHashes: TxHash[],
54
64
 
55
- // Note(md): this is placed after the txs payload in order to be backwards compatible with previous versions
56
- /** The transactions in the block */
57
- public readonly txs?: Tx[],
65
+ /** The proposer's signature over the block data */
66
+ public readonly signature: Signature,
67
+
68
+ /** The signed transactions in the block (optional, for DA guarantees) */
69
+ public readonly signedTxs?: SignedTxs,
58
70
  ) {
59
71
  super();
60
72
  }
@@ -64,59 +76,123 @@ export class BlockProposal extends Gossipable {
64
76
  }
65
77
 
66
78
  get archive(): Fr {
67
- return this.payload.archive;
79
+ return this.archiveRoot;
68
80
  }
69
81
 
70
82
  get slotNumber(): SlotNumber {
71
- return this.payload.header.slotNumber;
83
+ return this.blockHeader.getSlot();
84
+ }
85
+
86
+ get blockNumber(): BlockNumber {
87
+ return this.blockHeader.getBlockNumber();
88
+ }
89
+
90
+ /** Convenience getter for txs from signedTxs */
91
+ get txs(): Tx[] | undefined {
92
+ return this.signedTxs?.txs;
72
93
  }
73
94
 
74
95
  toBlockInfo(): Omit<L2BlockInfo, 'blockNumber'> {
75
96
  return {
76
97
  slotNumber: this.slotNumber,
77
- lastArchive: this.payload.header.lastArchiveRoot,
78
- timestamp: this.payload.header.timestamp,
79
- archive: this.archive,
98
+ lastArchive: this.blockHeader.lastArchive.root,
99
+ timestamp: this.blockHeader.globalVariables.timestamp,
100
+ archive: this.archiveRoot,
80
101
  txCount: this.txHashes.length,
81
102
  };
82
103
  }
83
104
 
105
+ /**
106
+ * Get the payload to sign for this block proposal.
107
+ * The signature is over: blockHeader + indexWithinCheckpoint + inHash + archiveRoot + txHashes
108
+ */
109
+ getPayloadToSign(domainSeparator: SignatureDomainSeparator): Buffer {
110
+ return serializeToBuffer([
111
+ domainSeparator,
112
+ this.blockHeader,
113
+ this.indexWithinCheckpoint,
114
+ this.inHash,
115
+ this.archiveRoot,
116
+ this.txHashes.length,
117
+ this.txHashes,
118
+ ]);
119
+ }
120
+
84
121
  static async createProposalFromSigner(
85
- payload: ConsensusPayload,
122
+ blockHeader: BlockHeader,
123
+ indexWithinCheckpoint: number,
124
+ inHash: Fr,
125
+ archiveRoot: Fr,
86
126
  txHashes: TxHash[],
87
- // Note(md): Provided separately to tx hashes such that this function can be optional
88
127
  txs: Tx[] | undefined,
89
128
  payloadSigner: (payload: Buffer32) => Promise<Signature>,
90
- ) {
91
- const hashed = getHashedSignaturePayload(payload, SignatureDomainSeparator.blockProposal);
129
+ ): Promise<BlockProposal> {
130
+ // Create a temporary proposal to get the payload to sign
131
+ const tempProposal = new BlockProposal(
132
+ blockHeader,
133
+ indexWithinCheckpoint,
134
+ inHash,
135
+ archiveRoot,
136
+ txHashes,
137
+ Signature.empty(),
138
+ );
139
+
140
+ const hashed = getHashedSignaturePayload(tempProposal, SignatureDomainSeparator.blockProposal);
92
141
  const sig = await payloadSigner(hashed);
93
142
 
94
- return new BlockProposal(payload, sig, txHashes, txs);
143
+ // If txs are provided, sign them as well
144
+ let signedTxs: SignedTxs | undefined;
145
+ if (txs) {
146
+ signedTxs = await SignedTxs.createFromSigner(txs, payloadSigner);
147
+ }
148
+
149
+ return new BlockProposal(blockHeader, indexWithinCheckpoint, inHash, archiveRoot, txHashes, sig, signedTxs);
95
150
  }
96
151
 
97
- /**Get Sender
98
- * Lazily evaluate the sender of the proposal; result is cached
99
- * @returns The sender address, or undefined if signature recovery fails
152
+ /**
153
+ * Lazily evaluate the sender of the proposal; result is cached.
154
+ * If there's signedTxs, also verifies the signedTxs sender matches the block proposal sender.
155
+ * @returns The sender address, or undefined if signature recovery fails or senders don't match
100
156
  */
101
157
  getSender(): EthAddress | undefined {
102
158
  if (!this.sender) {
103
- const hashed = getHashedSignaturePayloadEthSignedMessage(this.payload, SignatureDomainSeparator.blockProposal);
159
+ const hashed = getHashedSignaturePayloadEthSignedMessage(this, SignatureDomainSeparator.blockProposal);
160
+ const blockSender = tryRecoverAddress(hashed, this.signature);
161
+
162
+ // If there's signedTxs, verify the sender matches
163
+ if (blockSender && this.signedTxs) {
164
+ const txsSender = this.signedTxs.getSender();
165
+ if (!txsSender || !txsSender.equals(blockSender)) {
166
+ return undefined; // Sender mismatch - fail
167
+ }
168
+ }
169
+
104
170
  // Cache the sender for later use
105
- this.sender = tryRecoverAddress(hashed, this.signature);
171
+ this.sender = blockSender;
106
172
  }
107
173
 
108
174
  return this.sender;
109
175
  }
110
176
 
111
177
  getPayload() {
112
- return this.payload.getPayloadToSign(SignatureDomainSeparator.blockProposal);
178
+ return this.getPayloadToSign(SignatureDomainSeparator.blockProposal);
113
179
  }
114
180
 
115
181
  toBuffer(): Buffer {
116
- const buffer: any[] = [this.payload, this.signature, this.txHashes.length, this.txHashes];
117
- if (this.txs) {
118
- buffer.push(this.txs.length);
119
- buffer.push(this.txs);
182
+ const buffer: any[] = [
183
+ this.blockHeader,
184
+ this.indexWithinCheckpoint,
185
+ this.inHash,
186
+ this.archiveRoot,
187
+ this.signature,
188
+ this.txHashes.length,
189
+ this.txHashes,
190
+ ];
191
+ if (this.signedTxs) {
192
+ buffer.push(1); // hasSignedTxs = true
193
+ buffer.push(this.signedTxs.toBuffer());
194
+ } else {
195
+ buffer.push(0); // hasSignedTxs = false
120
196
  }
121
197
  return serializeToBuffer(buffer);
122
198
  }
@@ -124,25 +200,98 @@ export class BlockProposal extends Gossipable {
124
200
  static fromBuffer(buf: Buffer | BufferReader): BlockProposal {
125
201
  const reader = BufferReader.asReader(buf);
126
202
 
127
- const payload = reader.readObject(ConsensusPayload);
128
- const sig = reader.readObject(Signature);
129
- const txHashes = reader.readArray(reader.readNumber(), TxHash);
203
+ const blockHeader = reader.readObject(BlockHeader);
204
+ const indexWithinCheckpoint = reader.readNumber();
205
+ const inHash = reader.readObject(Fr);
206
+ const archiveRoot = reader.readObject(Fr);
207
+ const signature = reader.readObject(Signature);
208
+ const txHashCount = reader.readNumber();
209
+ if (txHashCount > MAX_TXS_PER_BLOCK) {
210
+ throw new Error(`txHashes count ${txHashCount} exceeds maximum ${MAX_TXS_PER_BLOCK}`);
211
+ }
212
+ const txHashes = reader.readArray(txHashCount, TxHash);
130
213
 
131
214
  if (!reader.isEmpty()) {
132
- const txs = reader.readArray(reader.readNumber(), Tx);
133
- return new BlockProposal(payload, sig, txHashes, txs);
215
+ const hasSignedTxs = reader.readNumber();
216
+ if (hasSignedTxs) {
217
+ const signedTxs = SignedTxs.fromBuffer(reader);
218
+ return new BlockProposal(
219
+ blockHeader,
220
+ indexWithinCheckpoint,
221
+ inHash,
222
+ archiveRoot,
223
+ txHashes,
224
+ signature,
225
+ signedTxs,
226
+ );
227
+ }
134
228
  }
135
229
 
136
- return new BlockProposal(payload, sig, txHashes);
230
+ return new BlockProposal(blockHeader, indexWithinCheckpoint, inHash, archiveRoot, txHashes, signature);
137
231
  }
138
232
 
139
233
  getSize(): number {
140
234
  return (
141
- this.payload.getSize() +
235
+ this.blockHeader.getSize() +
236
+ 4 /* indexWithinCheckpoint */ +
237
+ this.inHash.size +
238
+ this.archiveRoot.size +
142
239
  this.signature.getSize() +
143
240
  4 /* txHashes.length */ +
144
241
  this.txHashes.length * TxHash.SIZE +
145
- (this.txs ? 4 /* txs.length */ + this.txs.reduce((acc, tx) => acc + tx.getSize(), 0) : 0)
242
+ 4 /* hasSignedTxs flag */ +
243
+ (this.signedTxs ? this.signedTxs.getSize() : 0)
244
+ );
245
+ }
246
+
247
+ static empty(): BlockProposal {
248
+ return new BlockProposal(BlockHeader.empty(), 0, Fr.ZERO, Fr.ZERO, [], Signature.empty());
249
+ }
250
+
251
+ static random(): BlockProposal {
252
+ return new BlockProposal(
253
+ BlockHeader.random(),
254
+ Math.floor(Math.random() * 5),
255
+ Fr.random(),
256
+ Fr.random(),
257
+ [TxHash.random(), TxHash.random()],
258
+ Signature.random(),
259
+ );
260
+ }
261
+
262
+ toInspect() {
263
+ return {
264
+ blockHeader: this.blockHeader.toInspect(),
265
+ indexWithinCheckpoint: this.indexWithinCheckpoint,
266
+ inHash: this.inHash.toString(),
267
+ archiveRoot: this.archiveRoot.toString(),
268
+ signature: this.signature.toString(),
269
+ txHashes: this.txHashes.map(h => h.toString()),
270
+ };
271
+ }
272
+
273
+ /**
274
+ * Check if this proposal matches the given block.
275
+ * Compares the archive root and block header.
276
+ * @param block - The L2Block to compare against
277
+ * @returns True if the proposal matches the block
278
+ */
279
+ matchesBlock(block: L2Block): boolean {
280
+ return this.archiveRoot.equals(block.archive.root) && this.blockHeader.equals(block.getBlockHeader());
281
+ }
282
+
283
+ /**
284
+ * Returns a copy of this proposal without signedTxs.
285
+ * Used when storing proposals in attestation pool to avoid storing full tx data.
286
+ */
287
+ withoutSignedTxs(): BlockProposal {
288
+ return new BlockProposal(
289
+ this.blockHeader,
290
+ this.indexWithinCheckpoint,
291
+ this.inHash,
292
+ this.archiveRoot,
293
+ this.txHashes,
294
+ this.signature,
146
295
  );
147
296
  }
148
297
  }
@@ -2,7 +2,7 @@ import { SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import { Buffer32 } from '@aztec/foundation/buffer';
3
3
  import { keccak256 } from '@aztec/foundation/crypto/keccak';
4
4
  import { tryRecoverAddress } from '@aztec/foundation/crypto/secp256k1-signer';
5
- import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import type { Fr } from '@aztec/foundation/curves/bn254';
6
6
  import type { EthAddress } from '@aztec/foundation/eth-address';
7
7
  import { Signature } from '@aztec/foundation/eth-signature';
8
8
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
@@ -10,25 +10,26 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
10
10
  import { z } from 'zod';
11
11
 
12
12
  import type { ZodFor } from '../schemas/index.js';
13
+ import { CheckpointProposal } from './checkpoint_proposal.js';
13
14
  import { ConsensusPayload } from './consensus_payload.js';
14
15
  import { Gossipable } from './gossipable.js';
15
16
  import { SignatureDomainSeparator, getHashedSignaturePayloadEthSignedMessage } from './signature_utils.js';
16
17
  import { TopicType } from './topic_type.js';
17
18
 
18
- export class BlockAttestationHash extends Buffer32 {
19
+ export class CheckpointAttestationHash extends Buffer32 {
19
20
  constructor(hash: Buffer) {
20
21
  super(hash);
21
22
  }
22
23
  }
23
24
 
24
25
  /**
25
- * BlockAttestation
26
+ * CheckpointAttestation
26
27
  *
27
- * A validator that has attested to seeing the contents of a block
28
- * will produce a block attestation over the header of the block
28
+ * A validator that has attested to seeing all blocks in a checkpoint
29
+ * will produce a checkpoint attestation over the checkpoint header.
29
30
  */
30
- export class BlockAttestation extends Gossipable {
31
- static override p2pTopic = TopicType.block_attestation;
31
+ export class CheckpointAttestation extends Gossipable {
32
+ static override p2pTopic = TopicType.checkpoint_attestation;
32
33
 
33
34
  private sender: EthAddress | undefined;
34
35
  private proposer: EthAddress | undefined;
@@ -37,27 +38,27 @@ export class BlockAttestation extends Gossipable {
37
38
  /** The payload of the message, and what the signature is over */
38
39
  public readonly payload: ConsensusPayload,
39
40
 
40
- /** The signature of the block attester */
41
+ /** The signature of the checkpoint attester */
41
42
  public readonly signature: Signature,
42
43
 
43
- /** The signature from the block proposer */
44
+ /** The signature from the checkpoint proposer */
44
45
  public readonly proposerSignature: Signature,
45
46
  ) {
46
47
  super();
47
48
  }
48
49
 
49
- static get schema(): ZodFor<BlockAttestation> {
50
+ static get schema(): ZodFor<CheckpointAttestation> {
50
51
  return z
51
52
  .object({
52
53
  payload: ConsensusPayload.schema,
53
54
  signature: Signature.schema,
54
55
  proposerSignature: Signature.schema,
55
56
  })
56
- .transform(obj => new BlockAttestation(obj.payload, obj.signature, obj.proposerSignature));
57
+ .transform(obj => new CheckpointAttestation(obj.payload, obj.signature, obj.proposerSignature));
57
58
  }
58
59
 
59
60
  override generateP2PMessageIdentifier(): Promise<Buffer32> {
60
- return Promise.resolve(new BlockAttestationHash(keccak256(this.signature.toBuffer())));
61
+ return Promise.resolve(new CheckpointAttestationHash(keccak256(this.signature.toBuffer())));
61
62
  }
62
63
 
63
64
  get archive(): Fr {
@@ -75,7 +76,10 @@ export class BlockAttestation extends Gossipable {
75
76
  getSender(): EthAddress | undefined {
76
77
  if (!this.sender) {
77
78
  // Recover the sender from the attestation
78
- const hashed = getHashedSignaturePayloadEthSignedMessage(this.payload, SignatureDomainSeparator.blockAttestation);
79
+ const hashed = getHashedSignaturePayloadEthSignedMessage(
80
+ this.payload,
81
+ SignatureDomainSeparator.checkpointAttestation,
82
+ );
79
83
  // Cache the sender for later use
80
84
  this.sender = tryRecoverAddress(hashed, this.signature);
81
85
  }
@@ -84,43 +88,45 @@ export class BlockAttestation extends Gossipable {
84
88
  }
85
89
 
86
90
  /**
87
- * Lazily evaluate and cache the proposer of the block
88
- * @returns The proposer of the block
91
+ * Lazily evaluate and cache the proposer of the checkpoint
92
+ * @returns The proposer of the checkpoint
89
93
  */
90
94
  getProposer(): EthAddress | undefined {
91
95
  if (!this.proposer) {
92
- // Recover the proposer from the proposal signature
93
- const hashed = getHashedSignaturePayloadEthSignedMessage(this.payload, SignatureDomainSeparator.blockProposal);
96
+ // Create a temporary CheckpointProposal to recover the proposer address.
97
+ // We need to use CheckpointProposal because it has a different getPayloadToSign()
98
+ // implementation than ConsensusPayload (uses serializeToBuffer vs ABI encoding).
99
+ const proposal = new CheckpointProposal(this.payload.header, this.payload.archive, this.proposerSignature);
94
100
  // Cache the proposer for later use
95
- this.proposer = tryRecoverAddress(hashed, this.proposerSignature);
101
+ this.proposer = proposal.getSender();
96
102
  }
97
103
 
98
104
  return this.proposer;
99
105
  }
100
106
 
101
107
  getPayload(): Buffer {
102
- return this.payload.getPayloadToSign(SignatureDomainSeparator.blockAttestation);
108
+ return this.payload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation);
103
109
  }
104
110
 
105
111
  toBuffer(): Buffer {
106
112
  return serializeToBuffer([this.payload, this.signature, this.proposerSignature]);
107
113
  }
108
114
 
109
- static fromBuffer(buf: Buffer | BufferReader): BlockAttestation {
115
+ static fromBuffer(buf: Buffer | BufferReader): CheckpointAttestation {
110
116
  const reader = BufferReader.asReader(buf);
111
- return new BlockAttestation(
117
+ return new CheckpointAttestation(
112
118
  reader.readObject(ConsensusPayload),
113
119
  reader.readObject(Signature),
114
120
  reader.readObject(Signature),
115
121
  );
116
122
  }
117
123
 
118
- static empty(): BlockAttestation {
119
- return new BlockAttestation(ConsensusPayload.empty(), Signature.empty(), Signature.empty());
124
+ static empty(): CheckpointAttestation {
125
+ return new CheckpointAttestation(ConsensusPayload.empty(), Signature.empty(), Signature.empty());
120
126
  }
121
127
 
122
- static random(): BlockAttestation {
123
- return new BlockAttestation(ConsensusPayload.random(), Signature.random(), Signature.random());
128
+ static random(): CheckpointAttestation {
129
+ return new CheckpointAttestation(ConsensusPayload.random(), Signature.random(), Signature.random());
124
130
  }
125
131
 
126
132
  getSize(): number {