3
3
pragma solidity >= 0.8.27 ;
4
4
5
5
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol " ;
6
+ import {Hash} from "@aztec/core/libraries/crypto/Hash.sol " ;
6
7
import {Errors} from "@aztec/core/libraries/Errors.sol " ;
7
8
8
9
import {Slot, Timestamp} from "@aztec/core/libraries/TimeLib.sol " ;
9
10
10
- struct AppendOnlyTreeSnapshot {
11
- bytes32 root;
12
- uint32 nextAvailableLeafIndex;
13
- }
14
-
15
- struct PartialStateReference {
16
- AppendOnlyTreeSnapshot noteHashTree;
17
- AppendOnlyTreeSnapshot nullifierTree;
18
- AppendOnlyTreeSnapshot contractTree;
19
- AppendOnlyTreeSnapshot publicDataTree;
20
- }
21
-
22
- struct StateReference {
23
- AppendOnlyTreeSnapshot l1ToL2MessageTree;
24
- // Note: Can't use "partial" name here as in protocol specs because it is a reserved solidity keyword
25
- PartialStateReference partialStateReference;
26
- }
27
-
28
11
struct GasFees {
29
12
uint256 feePerDaGas;
30
13
uint256 feePerL2Gas;
31
14
}
32
15
33
- struct GlobalVariables {
34
- uint256 chainId;
35
- uint256 version;
36
- uint256 blockNumber;
37
- Slot slotNumber;
38
- Timestamp timestamp;
39
- address coinbase;
40
- bytes32 feeRecipient;
41
- GasFees gasFees;
42
- }
43
-
44
16
struct ContentCommitment {
45
17
uint256 numTxs;
46
18
bytes32 blobsHash;
@@ -49,11 +21,13 @@ struct ContentCommitment {
49
21
}
50
22
51
23
struct Header {
52
- AppendOnlyTreeSnapshot lastArchive ;
24
+ bytes32 lastArchiveRoot ;
53
25
ContentCommitment contentCommitment;
54
- StateReference stateReference;
55
- GlobalVariables globalVariables;
56
- uint256 totalFees;
26
+ Slot slotNumber;
27
+ Timestamp timestamp;
28
+ address coinbase;
29
+ bytes32 feeRecipient;
30
+ GasFees gasFees;
57
31
uint256 totalManaUsed;
58
32
}
59
33
@@ -71,44 +45,24 @@ struct Header {
71
45
*
72
46
* | byte start | num bytes | name
73
47
* | --- | --- | ---
74
- * | | | Header {
75
- * | 0x0000 | 0x20 | lastArchive.root
76
- * | 0x0020 | 0x04 | lastArchive.nextAvailableLeafIndex
77
- * | | | ContentCommitment {
78
- * | 0x0024 | 0x20 | numTxs
79
- * | 0x0044 | 0x20 | blobsHash
80
- * | 0x0064 | 0x20 | inHash
81
- * | 0x0084 | 0x20 | outHash
82
- * | | | StateReference {
83
- * | 0x00a4 | 0x20 | l1ToL2MessageTree.root
84
- * | 0x00c4 | 0x04 | l1ToL2MessageTree.nextAvailableLeafIndex
85
- * | | | PartialStateReference {
86
- * | 0x00c8 | 0x20 | noteHashTree.root
87
- * | 0x00e8 | 0x04 | noteHashTree.nextAvailableLeafIndex
88
- * | 0x00ec | 0x20 | nullifierTree.root
89
- * | 0x010c | 0x04 | nullifierTree.nextAvailableLeafIndex
90
- * | 0x0110 | 0x20 | publicDataTree.root
91
- * | 0x0130 | 0x04 | publicDataTree.nextAvailableLeafIndex
92
- * | | | }
93
- * | | | }
94
- * | | | GlobalVariables {
95
- * | 0x0134 | 0x20 | chainId
96
- * | 0x0154 | 0x20 | version
97
- * | 0x0174 | 0x20 | blockNumber
98
- * | 0x0194 | 0x20 | slotNumber
99
- * | 0x01b4 | 0x20 | timestamp
100
- * | 0x01d4 | 0x14 | coinbase
101
- * | 0x01e8 | 0x20 | feeRecipient
102
- * | 0x0208 | 0x20 | gasFees.feePerDaGas
103
- * | 0x0228 | 0x20 | gasFees.feePerL2Gas
104
- * | | | }
48
+ * | 0x0000 | 0x20 | lastArchiveRoot
49
+ * | | | ContentCommitment {
50
+ * | 0x0020 | 0x20 | numTxs
51
+ * | 0x0040 | 0x20 | blobsHash
52
+ * | 0x0060 | 0x20 | inHash
53
+ * | 0x0080 | 0x20 | outHash
105
54
* | | | }
106
- * | 0x0248 | 0x20 | total_fees
107
- * | 0x0268 | 0x20 | total_mana_used
55
+ * | 0x00a0 | 0x20 | slotNumber
56
+ * | 0x00c0 | 0x08 | timestamp
57
+ * | 0x00c8 | 0x14 | coinbase
58
+ * | 0x00dc | 0x20 | feeRecipient
59
+ * | 0x00fc | 0x20 | gasFees.feePerDaGas
60
+ * | 0x011c | 0x20 | gasFees.feePerL2Gas
61
+ * | 0x013c | 0x20 | totalManaUsed
108
62
* | --- | --- | ---
109
63
*/
110
64
library HeaderLib {
111
- uint256 private constant HEADER_LENGTH = Constants.BLOCK_HEADER_LENGTH_BYTES ; // Header byte length
65
+ uint256 private constant HEADER_LENGTH = Constants.PROPOSED_BLOCK_HEADER_LENGTH_BYTES ; // Header byte length
112
66
113
67
/**
114
68
* @notice Decodes the header
@@ -124,47 +78,29 @@ library HeaderLib {
124
78
Header memory header;
125
79
126
80
// Reading lastArchive
127
- header.lastArchive = AppendOnlyTreeSnapshot (
128
- bytes32 (_header[0x0000 :0x0020 ]), uint32 (bytes4 (_header[0x0020 :0x0024 ]))
129
- );
81
+ header.lastArchiveRoot = bytes32 (_header[0x0000 :0x0020 ]);
130
82
131
83
// Reading ContentCommitment
132
- header.contentCommitment.numTxs = uint256 (bytes32 (_header[0x0024 :0x0044 ]));
133
- header.contentCommitment.blobsHash = bytes32 (_header[0x0044 :0x0064 ]);
134
- header.contentCommitment.inHash = bytes32 (_header[0x0064 :0x0084 ]);
135
- header.contentCommitment.outHash = bytes32 (_header[0x0084 :0x00a4 ]);
136
-
137
- // Reading StateReference
138
- header.stateReference.l1ToL2MessageTree = AppendOnlyTreeSnapshot (
139
- bytes32 (_header[0x00a4 :0x00c4 ]), uint32 (bytes4 (_header[0x00c4 :0x00c8 ]))
140
- );
141
- header.stateReference.partialStateReference.noteHashTree = AppendOnlyTreeSnapshot (
142
- bytes32 (_header[0x00c8 :0x00e8 ]), uint32 (bytes4 (_header[0x00e8 :0x00ec ]))
143
- );
144
- header.stateReference.partialStateReference.nullifierTree = AppendOnlyTreeSnapshot (
145
- bytes32 (_header[0x00ec :0x010c ]), uint32 (bytes4 (_header[0x010c :0x0110 ]))
146
- );
147
- header.stateReference.partialStateReference.publicDataTree = AppendOnlyTreeSnapshot (
148
- bytes32 (_header[0x0110 :0x0130 ]), uint32 (bytes4 (_header[0x0130 :0x0134 ]))
149
- );
150
-
151
- // Reading GlobalVariables
152
- header.globalVariables.chainId = uint256 (bytes32 (_header[0x0134 :0x0154 ]));
153
- header.globalVariables.version = uint256 (bytes32 (_header[0x0154 :0x0174 ]));
154
- header.globalVariables.blockNumber = uint256 (bytes32 (_header[0x0174 :0x0194 ]));
155
- header.globalVariables.slotNumber = Slot.wrap (uint256 (bytes32 (_header[0x0194 :0x01b4 ])));
156
- header.globalVariables.timestamp = Timestamp.wrap (uint256 (bytes32 (_header[0x01b4 :0x01d4 ])));
157
- header.globalVariables.coinbase = address (bytes20 (_header[0x01d4 :0x01e8 ]));
158
- header.globalVariables.feeRecipient = bytes32 (_header[0x01e8 :0x0208 ]);
159
- header.globalVariables.gasFees.feePerDaGas = uint256 (bytes32 (_header[0x0208 :0x0228 ]));
160
- header.globalVariables.gasFees.feePerL2Gas = uint256 (bytes32 (_header[0x0228 :0x0248 ]));
161
-
162
- // Reading totalFees
163
- header.totalFees = uint256 (bytes32 (_header[0x0248 :0x0268 ]));
84
+ header.contentCommitment.numTxs = uint256 (bytes32 (_header[0x0020 :0x0040 ]));
85
+ header.contentCommitment.blobsHash = bytes32 (_header[0x0040 :0x0060 ]);
86
+ header.contentCommitment.inHash = bytes32 (_header[0x0060 :0x0080 ]);
87
+ header.contentCommitment.outHash = bytes32 (_header[0x0080 :0x00a0 ]);
88
+
89
+ // Reading partial GlobalVariables
90
+ header.slotNumber = Slot.wrap (uint256 (bytes32 (_header[0x00a0 :0x00c0 ])));
91
+ header.timestamp = Timestamp.wrap (uint256 (uint64 (bytes8 (_header[0x00c0 :0x00c8 ]))));
92
+ header.coinbase = address (bytes20 (_header[0x00c8 :0x00dc ]));
93
+ header.feeRecipient = bytes32 (_header[0x00dc :0x00fc ]);
94
+ header.gasFees.feePerDaGas = uint256 (bytes32 (_header[0x00fc :0x011c ]));
95
+ header.gasFees.feePerL2Gas = uint256 (bytes32 (_header[0x011c :0x013c ]));
164
96
165
97
// Reading totalManaUsed
166
- header.totalManaUsed = uint256 (bytes32 (_header[0x0268 : 0x0288 ]));
98
+ header.totalManaUsed = uint256 (bytes32 (_header[0x013c : 0x015c ]));
167
99
168
100
return header;
169
101
}
102
+
103
+ function hash (bytes memory _header ) internal pure returns (bytes32 ) {
104
+ return Hash.sha256ToField (_header);
105
+ }
170
106
}
0 commit comments