@aztec/stdlib 0.0.1-commit.6c91f13 → 0.0.1-commit.96bb3f7

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
@@ -0,0 +1,337 @@
1
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { Buffer32 } from '@aztec/foundation/buffer';
3
+ import { keccak256 } from '@aztec/foundation/crypto/keccak';
4
+ import { tryRecoverAddress } from '@aztec/foundation/crypto/secp256k1-signer';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
6
+ import type { EthAddress } from '@aztec/foundation/eth-address';
7
+ import { Signature } from '@aztec/foundation/eth-signature';
8
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
9
+
10
+ import type { L2BlockInfo } from '../block/l2_block_info.js';
11
+ import { CheckpointHeader } from '../rollup/checkpoint_header.js';
12
+ import { BlockHeader } from '../tx/block_header.js';
13
+ import { TxHash } from '../tx/index.js';
14
+ import type { Tx } from '../tx/tx.js';
15
+ import { BlockProposal } from './block_proposal.js';
16
+ import { Gossipable } from './gossipable.js';
17
+ import {
18
+ SignatureDomainSeparator,
19
+ getHashedSignaturePayload,
20
+ getHashedSignaturePayloadEthSignedMessage,
21
+ } from './signature_utils.js';
22
+ import { SignedTxs } from './signed_txs.js';
23
+ import { TopicType } from './topic_type.js';
24
+
25
+ // REFACTOR(palla): Use a branded type instead of a subclass of Buffer32
26
+ export class CheckpointProposalHash extends Buffer32 {
27
+ constructor(hash: Buffer) {
28
+ super(hash);
29
+ }
30
+ }
31
+
32
+ export type CheckpointProposalOptions = {
33
+ publishFullTxs: boolean;
34
+ /** Whether to generate an invalid checkpoint proposal for broadcasting. Use only for testing. */
35
+ broadcastInvalidCheckpointProposal?: boolean;
36
+ };
37
+
38
+ /** Data for the last block included in a checkpoint proposal */
39
+ export type CheckpointLastBlockData = {
40
+ /** The per-block header for the last block in the checkpoint */
41
+ blockHeader: BlockHeader;
42
+ /** Index of this block within the checkpoint (should be the last index, e.g., numBlocks - 1) */
43
+ indexWithinCheckpoint: number; // REFACTOR(palla): Use branded type
44
+ /** The sequence of transactions in the last block */
45
+ txHashes: TxHash[];
46
+ /** The tx in the last block (optional, for DA guarantees) */
47
+ txs?: Tx[];
48
+ };
49
+
50
+ /** Last block included in a checkpoint proposal */
51
+ export type CheckpointLastBlock = Omit<CheckpointLastBlockData, 'txs'> & {
52
+ /** The proposer's signature over the block data (separate from checkpoint signature) */
53
+ signature: Signature;
54
+ /** The signed transactions in the last block (optional, for DA guarantees) */
55
+ signedTxs?: SignedTxs;
56
+ };
57
+
58
+ /**
59
+ * A checkpoint proposal is created by the leader of the chain for the last block in a checkpoint.
60
+ * It includes the aggregated checkpoint header that validators will attest to, plus optionally
61
+ * the last block's info for nodes to re-execute. This marks the completion of a slot's worth of blocks.
62
+ */
63
+ export class CheckpointProposal extends Gossipable {
64
+ static override p2pTopic = TopicType.checkpoint_proposal;
65
+
66
+ private sender: EthAddress | undefined;
67
+
68
+ constructor(
69
+ /** The aggregated checkpoint header for consensus */
70
+ public readonly checkpointHeader: CheckpointHeader,
71
+
72
+ /** Archive root after this checkpoint is applied */
73
+ public readonly archive: Fr,
74
+
75
+ /** The proposer's signature over the checkpoint payload (checkpointHeader + archive) */
76
+ public readonly signature: Signature,
77
+
78
+ /** Optional last block info, including its own signature for BlockProposal extraction */
79
+ public readonly lastBlock?: CheckpointLastBlock,
80
+ ) {
81
+ super();
82
+ }
83
+
84
+ override generateP2PMessageIdentifier(): Promise<Buffer32> {
85
+ return Promise.resolve(new CheckpointProposalHash(keccak256(this.signature.toBuffer())));
86
+ }
87
+
88
+ get slotNumber(): SlotNumber {
89
+ return this.checkpointHeader.slotNumber;
90
+ }
91
+
92
+ get blockNumber(): BlockNumber {
93
+ if (!this.lastBlock) {
94
+ throw new Error('Cannot get blockNumber without lastBlock');
95
+ }
96
+ return this.lastBlock.blockHeader.getBlockNumber();
97
+ }
98
+
99
+ /** Convenience getter for txHashes from lastBlock */
100
+ get txHashes(): TxHash[] {
101
+ return this.lastBlock?.txHashes ?? [];
102
+ }
103
+
104
+ /** Convenience getter for txs from lastBlock */
105
+ get txs(): Tx[] | undefined {
106
+ return this.lastBlock?.signedTxs?.txs;
107
+ }
108
+
109
+ /**
110
+ * Extract a BlockProposal from the last block info.
111
+ * Uses inHash from checkpointHeader.contentCommitment.inHash
112
+ */
113
+ getBlockProposal(): BlockProposal | undefined {
114
+ if (!this.lastBlock) {
115
+ return undefined;
116
+ }
117
+
118
+ return new BlockProposal(
119
+ this.lastBlock.blockHeader,
120
+ this.lastBlock.indexWithinCheckpoint,
121
+ this.checkpointHeader.inHash,
122
+ this.archive,
123
+ this.lastBlock.txHashes,
124
+ this.lastBlock.signature,
125
+ this.lastBlock.signedTxs,
126
+ );
127
+ }
128
+
129
+ toBlockInfo(): Omit<L2BlockInfo, 'blockNumber'> {
130
+ if (!this.lastBlock) {
131
+ throw new Error('Cannot get blockInfo without lastBlock');
132
+ }
133
+ return {
134
+ slotNumber: this.slotNumber,
135
+ lastArchive: this.lastBlock.blockHeader.lastArchive.root,
136
+ timestamp: this.lastBlock.blockHeader.globalVariables.timestamp,
137
+ archive: this.archive,
138
+ txCount: this.lastBlock.txHashes.length,
139
+ };
140
+ }
141
+
142
+ /**
143
+ * Get the payload to sign for this checkpoint proposal.
144
+ * The signature is over the checkpoint header + archive root (for consensus).
145
+ */
146
+ getPayloadToSign(domainSeparator: SignatureDomainSeparator): Buffer {
147
+ return serializeToBuffer([domainSeparator, this.checkpointHeader, this.archive]);
148
+ }
149
+
150
+ static async createProposalFromSigner(
151
+ checkpointHeader: CheckpointHeader,
152
+ archiveRoot: Fr,
153
+ lastBlockInfo: CheckpointLastBlockData | undefined,
154
+ payloadSigner: (payload: Buffer32) => Promise<Signature>,
155
+ ): Promise<CheckpointProposal> {
156
+ // Sign the checkpoint payload
157
+ const tempProposal = new CheckpointProposal(checkpointHeader, archiveRoot, Signature.empty(), undefined);
158
+
159
+ const checkpointHash = getHashedSignaturePayload(tempProposal, SignatureDomainSeparator.checkpointProposal);
160
+ const checkpointSignature = await payloadSigner(checkpointHash);
161
+
162
+ if (!lastBlockInfo) {
163
+ return new CheckpointProposal(checkpointHeader, archiveRoot, checkpointSignature);
164
+ }
165
+
166
+ const lastBlockProposal = await BlockProposal.createProposalFromSigner(
167
+ lastBlockInfo.blockHeader,
168
+ lastBlockInfo.indexWithinCheckpoint,
169
+ checkpointHeader.inHash,
170
+ archiveRoot,
171
+ lastBlockInfo.txHashes,
172
+ lastBlockInfo.txs,
173
+ payloadSigner,
174
+ );
175
+
176
+ return new CheckpointProposal(checkpointHeader, archiveRoot, checkpointSignature, {
177
+ blockHeader: lastBlockInfo.blockHeader,
178
+ indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
179
+ txHashes: lastBlockInfo.txHashes,
180
+ signature: lastBlockProposal.signature,
181
+ signedTxs: lastBlockProposal.signedTxs,
182
+ });
183
+ }
184
+
185
+ /**
186
+ * Lazily evaluate the sender of the proposal; result is cached.
187
+ * If there's a lastBlock, also verifies the block proposal sender matches the checkpoint sender.
188
+ * @returns The sender address, or undefined if signature recovery fails or senders don't match
189
+ */
190
+ getSender(): EthAddress | undefined {
191
+ if (!this.sender) {
192
+ const hashed = getHashedSignaturePayloadEthSignedMessage(this, SignatureDomainSeparator.checkpointProposal);
193
+ const checkpointSender = tryRecoverAddress(hashed, this.signature);
194
+
195
+ // If there's a lastBlock, verify the block proposal sender matches
196
+ if (checkpointSender && this.lastBlock) {
197
+ const blockProposal = this.getBlockProposal();
198
+ const blockSender = blockProposal?.getSender();
199
+ if (!blockSender || !blockSender.equals(checkpointSender)) {
200
+ return undefined; // Sender mismatch - fail
201
+ }
202
+ }
203
+
204
+ // Cache the sender for later use
205
+ this.sender = checkpointSender;
206
+ }
207
+
208
+ return this.sender;
209
+ }
210
+
211
+ getPayload() {
212
+ return this.getPayloadToSign(SignatureDomainSeparator.checkpointProposal);
213
+ }
214
+
215
+ toBuffer(): Buffer {
216
+ const buffer: any[] = [this.checkpointHeader, this.archive, this.signature];
217
+
218
+ if (this.lastBlock) {
219
+ buffer.push(1); // hasLastBlock = true
220
+ buffer.push(this.lastBlock.blockHeader);
221
+ buffer.push(this.lastBlock.indexWithinCheckpoint);
222
+ buffer.push(this.lastBlock.signature);
223
+ buffer.push(this.lastBlock.txHashes.length);
224
+ buffer.push(this.lastBlock.txHashes);
225
+ if (this.lastBlock.signedTxs) {
226
+ buffer.push(1); // hasSignedTxs = true
227
+ buffer.push(this.lastBlock.signedTxs.toBuffer());
228
+ } else {
229
+ buffer.push(0); // hasSignedTxs = false
230
+ }
231
+ } else {
232
+ buffer.push(0); // hasLastBlock = false
233
+ }
234
+
235
+ return serializeToBuffer(buffer);
236
+ }
237
+
238
+ static fromBuffer(buf: Buffer | BufferReader): CheckpointProposal {
239
+ const reader = BufferReader.asReader(buf);
240
+
241
+ const checkpointHeader = reader.readObject(CheckpointHeader);
242
+ const archive = reader.readObject(Fr);
243
+ const signature = reader.readObject(Signature);
244
+
245
+ const hasLastBlock = reader.readNumber();
246
+
247
+ if (hasLastBlock) {
248
+ const blockHeader = reader.readObject(BlockHeader);
249
+ const indexWithinCheckpoint = reader.readNumber();
250
+ const blockSignature = reader.readObject(Signature);
251
+ const txHashes = reader.readArray(reader.readNumber(), TxHash);
252
+
253
+ let signedTxs: SignedTxs | undefined;
254
+ if (!reader.isEmpty()) {
255
+ const hasSignedTxs = reader.readNumber();
256
+ if (hasSignedTxs) {
257
+ signedTxs = SignedTxs.fromBuffer(reader);
258
+ }
259
+ }
260
+
261
+ return new CheckpointProposal(checkpointHeader, archive, signature, {
262
+ blockHeader,
263
+ indexWithinCheckpoint,
264
+ txHashes,
265
+ signature: blockSignature,
266
+ signedTxs,
267
+ });
268
+ }
269
+
270
+ return new CheckpointProposal(checkpointHeader, archive, signature);
271
+ }
272
+
273
+ getSize(): number {
274
+ let size =
275
+ this.checkpointHeader.toBuffer().length +
276
+ this.archive.size +
277
+ this.signature.getSize() +
278
+ 4; /* hasLastBlock flag */
279
+
280
+ if (this.lastBlock) {
281
+ size +=
282
+ this.lastBlock.blockHeader.getSize() +
283
+ 4 /* indexWithinCheckpoint */ +
284
+ this.lastBlock.signature.getSize() +
285
+ 4 /* txHashes.length */ +
286
+ this.lastBlock.txHashes.length * TxHash.SIZE +
287
+ 4 /* hasSignedTxs flag */ +
288
+ (this.lastBlock.signedTxs ? this.lastBlock.signedTxs.getSize() : 0);
289
+ }
290
+
291
+ return size;
292
+ }
293
+
294
+ static empty(): CheckpointProposal {
295
+ return new CheckpointProposal(CheckpointHeader.empty(), Fr.ZERO, Signature.empty());
296
+ }
297
+
298
+ static random(): CheckpointProposal {
299
+ return new CheckpointProposal(CheckpointHeader.random(), Fr.random(), Signature.random(), {
300
+ blockHeader: BlockHeader.random(),
301
+ indexWithinCheckpoint: Math.floor(Math.random() * 5),
302
+ txHashes: [TxHash.random(), TxHash.random()],
303
+ signature: Signature.random(),
304
+ });
305
+ }
306
+
307
+ toInspect() {
308
+ return {
309
+ checkpointHeader: this.checkpointHeader.toInspect(),
310
+ archive: this.archive.toString(),
311
+ signature: this.signature.toString(),
312
+ lastBlock: this.lastBlock
313
+ ? {
314
+ blockHeader: this.lastBlock.blockHeader.toInspect(),
315
+ indexWithinCheckpoint: this.lastBlock.indexWithinCheckpoint,
316
+ txHashes: this.lastBlock.txHashes.map(h => h.toString()),
317
+ signature: this.lastBlock.signature.toString(),
318
+ }
319
+ : undefined,
320
+ };
321
+ }
322
+
323
+ /**
324
+ * Returns a copy of this proposal without lastBlock info, as a CheckpointProposalCore.
325
+ * Used when the lastBlock has been extracted and stored separately.
326
+ */
327
+ toCore(): CheckpointProposalCore {
328
+ return new CheckpointProposal(this.checkpointHeader, this.archive, this.signature);
329
+ }
330
+ }
331
+
332
+ /**
333
+ * A checkpoint proposal without the lastBlock info.
334
+ * Used when the lastBlock has been extracted and handled separately as a BlockProposal.
335
+ * This type makes it clear that lastBlock and getBlockProposal() are not available.
336
+ */
337
+ export type CheckpointProposalCore = Omit<CheckpointProposal, 'lastBlock' | 'getBlockProposal' | 'toCore'>;
@@ -10,8 +10,10 @@ import { z } from 'zod';
10
10
  import type { L2Block } from '../block/l2_block.js';
11
11
  import type { Checkpoint } from '../checkpoint/checkpoint.js';
12
12
  import { CheckpointHeader } from '../rollup/checkpoint_header.js';
13
+ import type { CheckpointProposal, CheckpointProposalCore } from './checkpoint_proposal.js';
13
14
  import type { Signable, SignatureDomainSeparator } from './signature_utils.js';
14
15
 
16
+ /** Checkpoint consensus payload as signed by validators and verified on L1. */
15
17
  export class ConsensusPayload implements Signable {
16
18
  private size: number | undefined;
17
19
 
@@ -59,8 +61,9 @@ export class ConsensusPayload implements Signable {
59
61
  return serializeToBuffer([this.header, this.archive]);
60
62
  }
61
63
 
62
- public equals(other: ConsensusPayload): boolean {
63
- return this.header.equals(other.header) && this.archive.equals(other.archive);
64
+ public equals(other: ConsensusPayload | CheckpointProposal | CheckpointProposalCore): boolean {
65
+ const otherHeader = 'checkpointHeader' in other ? other.checkpointHeader : other.header;
66
+ return this.header.equals(otherHeader) && this.archive.equals(other.archive);
64
67
  }
65
68
 
66
69
  static fromBuffer(buf: Buffer | BufferReader): ConsensusPayload {
@@ -7,23 +7,33 @@ export class P2PMessage {
7
7
  constructor(
8
8
  public readonly payload: Buffer,
9
9
  public readonly timestamp?: Date,
10
+ public readonly traceContext?: string,
10
11
  ) {}
11
12
 
12
- static fromGossipable(message: Gossipable, instrumentMessages = false): P2PMessage {
13
- return new P2PMessage(message.toBuffer(), instrumentMessages ? new Date() : undefined);
13
+ static fromGossipable(message: Gossipable, instrumentMessages = false, traceContext?: string): P2PMessage {
14
+ if (!instrumentMessages) {
15
+ return new P2PMessage(message.toBuffer());
16
+ }
17
+ return new P2PMessage(message.toBuffer(), new Date(), traceContext);
14
18
  }
15
19
 
16
20
  static fromMessageData(messageData: Buffer, instrumentMessages = false): P2PMessage {
17
21
  const reader = new BufferReader(messageData);
18
- const timestamp = instrumentMessages ? new Date(Number(reader.readUInt64())) : undefined;
22
+ let timestamp: Date | undefined;
23
+ let traceContext: string | undefined;
24
+ if (instrumentMessages) {
25
+ timestamp = new Date(Number(reader.readUInt64()));
26
+ traceContext = reader.readString();
27
+ }
19
28
  const payload = reader.readBuffer();
20
- return new P2PMessage(payload, timestamp);
29
+ return new P2PMessage(payload, timestamp, traceContext);
21
30
  }
22
31
 
23
32
  toMessageData(): Buffer {
24
33
  const arr: Buffer[] = [];
25
34
  if (this.timestamp) {
26
35
  arr.push(bigintToUInt64BE(BigInt(this.timestamp.getTime())));
36
+ arr.push(serializeToBuffer(this.traceContext ?? ''));
27
37
  }
28
38
  arr.push(serializeToBuffer(this.payload.length, this.payload));
29
39
  return serializeToBuffer(arr);
package/src/p2p/index.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  export * from './attestation_utils.js';
2
- export * from './block_attestation.js';
3
2
  export * from './block_proposal.js';
3
+ export * from './checkpoint_attestation.js';
4
+ export * from './checkpoint_proposal.js';
4
5
  export * from './consensus_payload.js';
5
6
  export * from './gossipable.js';
6
7
  export * from './interface.js';
7
8
  export * from './signature_utils.js';
9
+ export * from './signed_txs.js';
8
10
  export * from './topic_type.js';
9
11
  export * from './client_type.js';
10
12
  export * from './message_validator.js';
@@ -4,8 +4,10 @@ import { makeEthSignDigest } from '@aztec/foundation/crypto/secp256k1-signer';
4
4
 
5
5
  export enum SignatureDomainSeparator {
6
6
  blockProposal = 0,
7
- blockAttestation = 1,
7
+ checkpointAttestation = 1,
8
8
  attestationsAndSigners = 2,
9
+ checkpointProposal = 3,
10
+ signedTxs = 4,
9
11
  }
10
12
 
11
13
  export interface Signable {
@@ -0,0 +1,83 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { tryRecoverAddress } from '@aztec/foundation/crypto/secp256k1-signer';
3
+ import type { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { Signature } from '@aztec/foundation/eth-signature';
5
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
6
+
7
+ import { Tx } from '../tx/tx.js';
8
+ import {
9
+ SignatureDomainSeparator,
10
+ getHashedSignaturePayload,
11
+ getHashedSignaturePayloadEthSignedMessage,
12
+ } from './signature_utils.js';
13
+
14
+ /**
15
+ * A signed collection of transactions.
16
+ * The signature is over the transaction objects themselves, providing
17
+ * data availability guarantees beyond just the transaction hashes.
18
+ */
19
+ export class SignedTxs {
20
+ private sender: EthAddress | undefined;
21
+
22
+ constructor(
23
+ /** The transactions */
24
+ public readonly txs: Tx[],
25
+ /** The proposer's signature over the transactions */
26
+ public readonly signature: Signature,
27
+ ) {}
28
+
29
+ /**
30
+ * Get the payload to sign for this signed txs.
31
+ */
32
+ getPayloadToSign(domainSeparator: SignatureDomainSeparator): Buffer {
33
+ return serializeToBuffer([domainSeparator, this.txs.length, this.txs]);
34
+ }
35
+
36
+ /**
37
+ * Lazily evaluate the sender of the signed txs; result is cached
38
+ * @returns The sender address, or undefined if signature recovery fails
39
+ */
40
+ getSender(): EthAddress | undefined {
41
+ if (!this.sender) {
42
+ const hashed = getHashedSignaturePayloadEthSignedMessage(this, SignatureDomainSeparator.signedTxs);
43
+ this.sender = tryRecoverAddress(hashed, this.signature);
44
+ }
45
+ return this.sender;
46
+ }
47
+
48
+ /**
49
+ * Create SignedTxs from a signer function
50
+ */
51
+ static async createFromSigner(
52
+ txs: Tx[],
53
+ payloadSigner: (payload: Buffer32) => Promise<Signature>,
54
+ ): Promise<SignedTxs> {
55
+ const tempSignedTxs = new SignedTxs(txs, Signature.empty());
56
+ const hashed = getHashedSignaturePayload(tempSignedTxs, SignatureDomainSeparator.signedTxs);
57
+ const signature = await payloadSigner(hashed);
58
+ return new SignedTxs(txs, signature);
59
+ }
60
+
61
+ toBuffer(): Buffer {
62
+ return serializeToBuffer([this.txs.length, this.txs, this.signature]);
63
+ }
64
+
65
+ static fromBuffer(buf: Buffer | BufferReader): SignedTxs {
66
+ const reader = BufferReader.asReader(buf);
67
+ const txs = reader.readArray(reader.readNumber(), Tx);
68
+ const signature = reader.readObject(Signature);
69
+ return new SignedTxs(txs, signature);
70
+ }
71
+
72
+ getSize(): number {
73
+ return 4 /* txs.length */ + this.txs.reduce((acc, tx) => acc + tx.getSize(), 0) + this.signature.getSize();
74
+ }
75
+
76
+ static empty(): SignedTxs {
77
+ return new SignedTxs([], Signature.empty());
78
+ }
79
+
80
+ static random(): SignedTxs {
81
+ return new SignedTxs([Tx.random(), Tx.random()], Signature.random());
82
+ }
83
+ }
@@ -23,12 +23,13 @@ export function getTopicFromString(topicStr: string): TopicType | undefined {
23
23
  export enum TopicType {
24
24
  tx = 'tx',
25
25
  block_proposal = 'block_proposal',
26
- block_attestation = 'block_attestation',
26
+ checkpoint_proposal = 'checkpoint_proposal',
27
+ checkpoint_attestation = 'checkpoint_attestation',
27
28
  }
28
29
 
29
30
  export function getTopicTypeForClientType(clientType: P2PClientType) {
30
31
  if (clientType === P2PClientType.Full) {
31
- return Object.values(TopicType);
32
+ return [TopicType.tx, TopicType.block_proposal, TopicType.checkpoint_proposal, TopicType.checkpoint_attestation];
32
33
  } else if (clientType === P2PClientType.Prover) {
33
34
  return [TopicType.tx, TopicType.block_proposal];
34
35
  } else {
@@ -43,13 +43,9 @@ export class BlockRollupPublicInputs {
43
43
  */
44
44
  public endSpongeBlob: SpongeBlob,
45
45
  /**
46
- * Timestamp of the first block in this block range.
46
+ * Timestamp of the blocks in this block range.
47
47
  */
48
- public startTimestamp: UInt64,
49
- /**
50
- * Timestamp of the last block in this block range.
51
- */
52
- public endTimestamp: UInt64,
48
+ public timestamp: UInt64,
53
49
  /**
54
50
  * Hash of the headers of all blocks in this block range. It will be combined with the `blockHeadersHash` from
55
51
  * other blocks in the same checkpoint to form a wonky tree. The root of that tree becomes the final hash stored in
@@ -85,7 +81,6 @@ export class BlockRollupPublicInputs {
85
81
  reader.readObject(SpongeBlob),
86
82
  reader.readObject(SpongeBlob),
87
83
  reader.readUInt64(),
88
- reader.readUInt64(),
89
84
  Fr.fromBuffer(reader),
90
85
  Fr.fromBuffer(reader),
91
86
  Fr.fromBuffer(reader),
@@ -103,8 +98,7 @@ export class BlockRollupPublicInputs {
103
98
  this.endState,
104
99
  this.startSpongeBlob,
105
100
  this.endSpongeBlob,
106
- bigintToUInt64BE(this.startTimestamp),
107
- bigintToUInt64BE(this.endTimestamp),
101
+ bigintToUInt64BE(this.timestamp),
108
102
  this.blockHeadersHash,
109
103
  this.inHash,
110
104
  this.outHash,