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