4
4
"encoding/binary"
5
5
"errors"
6
6
"fmt"
7
- "github.com/davecgh/go-spew/spew"
8
7
"slices"
9
8
10
9
"github.com/Masterminds/semver/v3"
@@ -193,11 +192,11 @@ func pre07Hash(b *Block, chain *felt.Felt) (*felt.Felt, *BlockCommitments, error
193
192
}
194
193
195
194
func Post0132Hash (b * Block , stateDiff * StateDiff ) (* felt.Felt , * BlockCommitments , error ) {
196
- wg := conc .NewWaitGroup ()
197
195
var txCommitment , eCommitment , rCommitment , sdCommitment * felt.Felt
198
196
var sdLength uint64
199
197
var tErr , eErr , rErr error
200
198
199
+ wg := conc .NewWaitGroup ()
201
200
wg .Go (func () {
202
201
txCommitment , tErr = transactionCommitmentPoseidon (b .Transactions )
203
202
})
@@ -207,12 +206,10 @@ func Post0132Hash(b *Block, stateDiff *StateDiff) (*felt.Felt, *BlockCommitments
207
206
wg .Go (func () {
208
207
rCommitment , rErr = receiptCommitment (b .Receipts )
209
208
})
210
-
211
209
wg .Go (func () {
212
210
sdLength = stateDiff .Length ()
213
211
sdCommitment = stateDiff .Hash ()
214
212
})
215
-
216
213
wg .Wait ()
217
214
218
215
if tErr != nil {
@@ -227,32 +224,12 @@ func Post0132Hash(b *Block, stateDiff *StateDiff) (*felt.Felt, *BlockCommitments
227
224
228
225
concatCounts := concatCounts (b .TransactionCount , b .EventCount , sdLength , b .L1DAMode )
229
226
230
- hash := crypto .PoseidonArray (
231
- new (felt.Felt ).SetBytes ([]byte ("STARKNET_BLOCK_HASH0" )),
232
- new (felt.Felt ).SetUint64 (b .Number ), // block number
233
- b .GlobalStateRoot , // global state root
234
- b .SequencerAddress , // sequencer address
235
- new (felt.Felt ).SetUint64 (b .Timestamp ), // block timestamp
236
- concatCounts ,
237
- sdCommitment ,
238
- txCommitment , // transaction commitment
239
- eCommitment , // event commitment
240
- rCommitment , // receipt commitment
241
- b .GasPrice , // gas price in wei
242
- b .GasPriceSTRK , // gas price in fri
243
- b .L1DataGasPrice .PriceInWei ,
244
- b .L1DataGasPrice .PriceInFri ,
245
- new (felt.Felt ).SetBytes ([]byte (b .ProtocolVersion )),
246
- & felt .Zero , // reserved: extra data
247
- b .ParentHash , // parent block hash
248
- )
249
-
250
- if b .Number == 24521 {
251
- spew .Dump (
252
- b .Number , // block number
253
- b .GlobalStateRoot , // global state root
254
- b .SequencerAddress , // sequencer address
255
- b .Timestamp , // block timestamp
227
+ return crypto .PoseidonArray (
228
+ new (felt.Felt ).SetBytes ([]byte ("STARKNET_BLOCK_HASH0" )),
229
+ new (felt.Felt ).SetUint64 (b .Number ), // block number
230
+ b .GlobalStateRoot , // global state root
231
+ b .SequencerAddress , // sequencer address
232
+ new (felt.Felt ).SetUint64 (b .Timestamp ), // block timestamp
256
233
concatCounts ,
257
234
sdCommitment ,
258
235
txCommitment , // transaction commitment
@@ -262,19 +239,15 @@ func Post0132Hash(b *Block, stateDiff *StateDiff) (*felt.Felt, *BlockCommitments
262
239
b .GasPriceSTRK , // gas price in fri
263
240
b .L1DataGasPrice .PriceInWei ,
264
241
b .L1DataGasPrice .PriceInFri ,
265
- b .ProtocolVersion ,
242
+ new (felt. Felt ). SetBytes ([] byte ( b .ProtocolVersion )) ,
266
243
& felt .Zero , // reserved: extra data
267
244
b .ParentHash , // parent block hash
268
- fmt .Sprintf ("new hash is %v" , hash ),
269
- )
270
- }
271
-
272
- return hash , & BlockCommitments {
273
- TransactionCommitment : txCommitment ,
274
- EventCommitment : eCommitment ,
275
- ReceiptCommitment : rCommitment ,
276
- StateDiffCommitment : sdCommitment ,
277
- }, nil
245
+ ), & BlockCommitments {
246
+ TransactionCommitment : txCommitment ,
247
+ EventCommitment : eCommitment ,
248
+ ReceiptCommitment : rCommitment ,
249
+ StateDiffCommitment : sdCommitment ,
250
+ }, nil
278
251
}
279
252
280
253
// post07Hash computes the block hash for blocks generated after Cairo 0.7.0
0 commit comments