@aztec/stdlib 4.0.0-nightly.20260111 → 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.
- package/dest/block/attestation_info.d.ts +5 -5
- package/dest/block/attestation_info.d.ts.map +1 -1
- package/dest/block/attestation_info.js +4 -4
- package/dest/block/l2_block.d.ts +6 -3
- package/dest/block/l2_block.d.ts.map +1 -1
- package/dest/block/l2_block.js +2 -2
- package/dest/block/l2_block_new.d.ts +1 -2
- package/dest/block/l2_block_new.d.ts.map +1 -1
- package/dest/block/l2_block_new.js +4 -1
- package/dest/block/l2_block_source.d.ts +245 -41
- package/dest/block/l2_block_source.d.ts.map +1 -1
- package/dest/block/l2_block_source.js +23 -5
- package/dest/block/l2_block_stream/index.d.ts +2 -1
- package/dest/block/l2_block_stream/index.d.ts.map +1 -1
- package/dest/block/l2_block_stream/index.js +1 -0
- package/dest/block/l2_block_stream/interfaces.d.ts +16 -5
- package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.d.ts +4 -2
- package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.js +102 -30
- package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts +24 -16
- package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_tips_memory_store.js +55 -61
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +49 -0
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -0
- package/dest/block/l2_block_stream/l2_tips_store_base.js +179 -0
- package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
- package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
- package/dest/block/test/l2_tips_store_test_suite.js +483 -38
- package/dest/block/validate_block_result.d.ts +24 -24
- package/dest/block/validate_block_result.d.ts.map +1 -1
- package/dest/block/validate_block_result.js +13 -13
- package/dest/checkpoint/checkpoint.d.ts +1 -1
- package/dest/checkpoint/checkpoint.d.ts.map +1 -1
- package/dest/checkpoint/checkpoint.js +1 -0
- package/dest/checkpoint/checkpoint_info.d.ts +32 -3
- package/dest/checkpoint/checkpoint_info.d.ts.map +1 -1
- package/dest/checkpoint/checkpoint_info.js +34 -1
- package/dest/checkpoint/index.d.ts +2 -1
- package/dest/checkpoint/index.d.ts.map +1 -1
- package/dest/checkpoint/index.js +1 -0
- package/dest/interfaces/api_limit.d.ts +2 -1
- package/dest/interfaces/api_limit.d.ts.map +1 -1
- package/dest/interfaces/api_limit.js +1 -0
- package/dest/interfaces/archiver.d.ts +6 -6
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +6 -4
- package/dest/interfaces/aztec-node-admin.d.ts +12 -6
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-admin.js +2 -2
- package/dest/interfaces/aztec-node.d.ts +2 -2
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +8 -3
- package/dest/interfaces/configs.d.ts +6 -1
- package/dest/interfaces/configs.d.ts.map +1 -1
- package/dest/interfaces/configs.js +2 -1
- package/dest/interfaces/p2p.d.ts +7 -9
- package/dest/interfaces/p2p.d.ts.map +1 -1
- package/dest/interfaces/p2p.js +3 -4
- package/dest/interfaces/proving-job.d.ts +166 -166
- package/dest/interfaces/validator.d.ts +41 -7
- package/dest/interfaces/validator.d.ts.map +1 -1
- package/dest/interfaces/validator.js +3 -1
- package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts +6 -5
- package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts.map +1 -1
- package/dest/kernel/hints/build_note_hash_read_request_hints.js +5 -6
- package/dest/p2p/attestation_utils.d.ts +3 -3
- package/dest/p2p/attestation_utils.d.ts.map +1 -1
- package/dest/p2p/attestation_utils.js +1 -1
- package/dest/p2p/block_proposal.d.ts +85 -21
- package/dest/p2p/block_proposal.d.ts.map +1 -1
- package/dest/p2p/block_proposal.js +120 -37
- package/dest/p2p/checkpoint_attestation.d.ts +77 -0
- package/dest/p2p/checkpoint_attestation.d.ts.map +1 -0
- package/dest/p2p/{block_attestation.js → checkpoint_attestation.js} +22 -19
- package/dest/p2p/checkpoint_proposal.d.ts +154 -0
- package/dest/p2p/checkpoint_proposal.d.ts.map +1 -0
- package/dest/p2p/checkpoint_proposal.js +217 -0
- package/dest/p2p/consensus_payload.d.ts +4 -2
- package/dest/p2p/consensus_payload.d.ts.map +1 -1
- package/dest/p2p/consensus_payload.js +3 -2
- package/dest/p2p/index.d.ts +4 -2
- package/dest/p2p/index.d.ts.map +1 -1
- package/dest/p2p/index.js +3 -1
- package/dest/p2p/signature_utils.d.ts +5 -3
- package/dest/p2p/signature_utils.d.ts.map +1 -1
- package/dest/p2p/signature_utils.js +3 -1
- package/dest/p2p/signed_txs.d.ts +40 -0
- package/dest/p2p/signed_txs.d.ts.map +1 -0
- package/dest/p2p/signed_txs.js +70 -0
- package/dest/p2p/topic_type.d.ts +3 -2
- package/dest/p2p/topic_type.d.ts.map +1 -1
- package/dest/p2p/topic_type.js +8 -2
- package/dest/rollup/checkpoint_header.d.ts +5 -1
- package/dest/rollup/checkpoint_header.d.ts.map +1 -1
- package/dest/rollup/checkpoint_header.js +4 -0
- package/dest/tests/factories.d.ts +13 -1
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +50 -1
- package/dest/tests/mocks.d.ts +55 -9
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +84 -35
- package/dest/tx/private_execution_result.d.ts +1 -5
- package/dest/tx/private_execution_result.d.ts.map +1 -1
- package/dest/tx/private_execution_result.js +3 -20
- package/package.json +8 -8
- package/src/block/attestation_info.ts +9 -6
- package/src/block/l2_block.ts +3 -3
- package/src/block/l2_block_new.ts +5 -1
- package/src/block/l2_block_source.ts +66 -16
- package/src/block/l2_block_stream/index.ts +1 -0
- package/src/block/l2_block_stream/interfaces.ts +16 -4
- package/src/block/l2_block_stream/l2_block_stream.ts +121 -38
- package/src/block/l2_block_stream/l2_tips_memory_store.ts +62 -56
- package/src/block/l2_block_stream/l2_tips_store_base.ts +226 -0
- package/src/block/test/l2_tips_store_test_suite.ts +485 -36
- package/src/block/validate_block_result.ts +35 -31
- package/src/checkpoint/checkpoint.ts +1 -0
- package/src/checkpoint/checkpoint_info.ts +45 -2
- package/src/checkpoint/index.ts +1 -0
- package/src/interfaces/api_limit.ts +1 -0
- package/src/interfaces/archiver.ts +14 -6
- package/src/interfaces/aztec-node-admin.ts +5 -2
- package/src/interfaces/aztec-node.ts +30 -3
- package/src/interfaces/configs.ts +5 -0
- package/src/interfaces/p2p.ts +8 -12
- package/src/interfaces/validator.ts +57 -7
- package/src/kernel/hints/build_note_hash_read_request_hints.ts +5 -8
- package/src/p2p/attestation_utils.ts +3 -3
- package/src/p2p/block_proposal.ts +185 -41
- package/src/p2p/{block_attestation.ts → checkpoint_attestation.ts} +31 -25
- package/src/p2p/checkpoint_proposal.ts +337 -0
- package/src/p2p/consensus_payload.ts +5 -2
- package/src/p2p/index.ts +3 -1
- package/src/p2p/signature_utils.ts +3 -1
- package/src/p2p/signed_txs.ts +83 -0
- package/src/p2p/topic_type.ts +3 -2
- package/src/rollup/checkpoint_header.ts +13 -0
- package/src/tests/factories.ts +42 -1
- package/src/tests/mocks.ts +146 -50
- package/src/tx/private_execution_result.ts +0 -15
- package/dest/p2p/block_attestation.d.ts +0 -77
- package/dest/p2p/block_attestation.d.ts.map +0 -1
|
@@ -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
|
-
|
|
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 {
|
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
|
-
|
|
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
|
+
}
|
package/src/p2p/topic_type.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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 {
|
|
@@ -14,11 +14,13 @@ import { z } from 'zod';
|
|
|
14
14
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
15
15
|
import { GasFees } from '../gas/index.js';
|
|
16
16
|
import { schemas } from '../schemas/index.js';
|
|
17
|
+
import type { GlobalVariables } from '../tx/global_variables.js';
|
|
17
18
|
import type { UInt64 } from '../types/shared.js';
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Header of a checkpoint. A checkpoint is a collection of blocks submitted to L1 all within the same slot.
|
|
21
22
|
* TODO(palla/mbps): Should this include chainId and version as well? Is this used just in circuits?
|
|
23
|
+
* TODO(palla/mbps): What about CheckpointNumber?
|
|
22
24
|
*/
|
|
23
25
|
export class CheckpointHeader {
|
|
24
26
|
constructor(
|
|
@@ -112,6 +114,17 @@ export class CheckpointHeader {
|
|
|
112
114
|
);
|
|
113
115
|
}
|
|
114
116
|
|
|
117
|
+
/** Returns true if the global variables match those in the checkpoint header. */
|
|
118
|
+
matchesGlobalVariables(other: GlobalVariables) {
|
|
119
|
+
return (
|
|
120
|
+
this.coinbase.equals(other.coinbase) &&
|
|
121
|
+
this.feeRecipient.equals(other.feeRecipient) &&
|
|
122
|
+
this.gasFees.equals(other.gasFees) &&
|
|
123
|
+
this.slotNumber === other.slotNumber &&
|
|
124
|
+
this.timestamp === other.timestamp
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
115
128
|
toBuffer() {
|
|
116
129
|
// Note: The order here must match the order in the ProposedHeaderLib solidity library.
|
|
117
130
|
return serializeToBuffer([
|
package/src/tests/factories.ts
CHANGED
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
VK_TREE_HEIGHT,
|
|
44
44
|
} from '@aztec/constants';
|
|
45
45
|
import { type FieldsOf, makeTuple } from '@aztec/foundation/array';
|
|
46
|
-
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
46
|
+
import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
47
47
|
import { compact } from '@aztec/foundation/collection';
|
|
48
48
|
import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
|
|
49
49
|
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
@@ -88,6 +88,7 @@ import { PublicDataRead } from '../avm/public_data_read.js';
|
|
|
88
88
|
import { PublicDataWrite } from '../avm/public_data_write.js';
|
|
89
89
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
90
90
|
import { L2BlockHeader } from '../block/l2_block_header.js';
|
|
91
|
+
import type { L2Tips } from '../block/l2_block_source.js';
|
|
91
92
|
import {
|
|
92
93
|
type ContractClassPublic,
|
|
93
94
|
ContractDeploymentData,
|
|
@@ -1736,3 +1737,43 @@ export async function randomTxScopedPublicL2Log(opts?: {
|
|
|
1736
1737
|
opts?.firstNullifier ?? Fr.random(),
|
|
1737
1738
|
);
|
|
1738
1739
|
}
|
|
1740
|
+
|
|
1741
|
+
/**
|
|
1742
|
+
* Creates L2Tips with all tips pointing to the same block number.
|
|
1743
|
+
* Useful for mocking aztecNode.getL2Tips() in tests.
|
|
1744
|
+
* @param blockNumber - The block number to use for all tips.
|
|
1745
|
+
* @param hash - Optional hash for the block (defaults to empty string).
|
|
1746
|
+
* @param checkpointNumber - Optional checkpoint number (defaults to blockNumber).
|
|
1747
|
+
* @param checkpointHash - Optional checkpoint hash (defaults to block hash).
|
|
1748
|
+
* @returns L2Tips object with all tips at the same block.
|
|
1749
|
+
*/
|
|
1750
|
+
export function makeL2Tips(
|
|
1751
|
+
blockNumber: number | BlockNumber,
|
|
1752
|
+
hash = '',
|
|
1753
|
+
checkpointNumber?: number | CheckpointNumber,
|
|
1754
|
+
checkpointHash?: string,
|
|
1755
|
+
): L2Tips {
|
|
1756
|
+
const bn = typeof blockNumber === 'number' ? BlockNumber(blockNumber) : blockNumber;
|
|
1757
|
+
const cpn =
|
|
1758
|
+
checkpointNumber !== undefined
|
|
1759
|
+
? typeof checkpointNumber === 'number'
|
|
1760
|
+
? CheckpointNumber(checkpointNumber)
|
|
1761
|
+
: checkpointNumber
|
|
1762
|
+
: CheckpointNumber(bn);
|
|
1763
|
+
const cph = checkpointHash ?? hash;
|
|
1764
|
+
return {
|
|
1765
|
+
proposed: { number: bn, hash },
|
|
1766
|
+
checkpointed: {
|
|
1767
|
+
block: { number: bn, hash },
|
|
1768
|
+
checkpoint: { number: cpn, hash: cph },
|
|
1769
|
+
},
|
|
1770
|
+
proven: {
|
|
1771
|
+
block: { number: bn, hash },
|
|
1772
|
+
checkpoint: { number: cpn, hash: cph },
|
|
1773
|
+
},
|
|
1774
|
+
finalized: {
|
|
1775
|
+
block: { number: bn, hash },
|
|
1776
|
+
checkpoint: { number: cpn, hash: cph },
|
|
1777
|
+
},
|
|
1778
|
+
};
|
|
1779
|
+
}
|