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

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