diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 4ff64e389e..e86ad34c95 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -377,11 +377,7 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit } if blockVer.LessThan(core.Ver0_13_2) { - // temporary hack - if block.SequencerAddress == nil { - block.SequencerAddress = &felt.Zero - } - if err := ComputeAndStoreP2PHash(txn, block, stateUpdate.StateDiff); err != nil { + if err := computeAndStoreP2PHash(txn, block, stateUpdate.StateDiff); err != nil { return err } } @@ -408,7 +404,7 @@ func (b *Blockchain) VerifyBlock(block *core.Block) error { }) } -func ComputeAndStoreP2PHash(txn db.Transaction, block *core.Block, stateDiff *core.StateDiff) error { +func computeAndStoreP2PHash(txn db.Transaction, block *core.Block, stateDiff *core.StateDiff) error { hash, _, err := core.Post0132Hash(block, stateDiff) if err != nil { return err diff --git a/core/block.go b/core/block.go index ab0cf01555..112c80f78d 100644 --- a/core/block.go +++ b/core/block.go @@ -216,21 +216,42 @@ func Post0132Hash(b *Block, stateDiff *StateDiff) (*felt.Felt, *BlockCommitments concatCounts := concatCounts(b.TransactionCount, b.EventCount, sdLength, b.L1DAMode) + // temporary hack + seqAddr := &felt.Zero + gasPriceStrk := &felt.Zero + l1DataGasPricrInWei := &felt.Zero + l1DataGasPriceInFri := &felt.Zero + + if b.SequencerAddress != nil { + seqAddr = b.SequencerAddress + } + if b.GasPriceSTRK != nil { + gasPriceStrk = b.GasPriceSTRK + } + if b.L1DataGasPrice != nil { + if b.L1DataGasPrice.PriceInWei != nil { + l1DataGasPricrInWei = b.L1DataGasPrice.PriceInWei + } + if b.L1DataGasPrice.PriceInFri != nil { + l1DataGasPriceInFri = b.L1DataGasPrice.PriceInFri + } + } + return crypto.PoseidonArray( new(felt.Felt).SetBytes([]byte("STARKNET_BLOCK_HASH0")), new(felt.Felt).SetUint64(b.Number), // block number b.GlobalStateRoot, // global state root - b.SequencerAddress, // sequencer address + seqAddr, // sequencer address new(felt.Felt).SetUint64(b.Timestamp), // block timestamp concatCounts, sdCommitment, - txCommitment, // transaction commitment - eCommitment, // event commitment - rCommitment, // receipt commitment - b.GasPrice, // gas price in wei - b.GasPriceSTRK, // gas price in fri - b.L1DataGasPrice.PriceInWei, - b.L1DataGasPrice.PriceInFri, + txCommitment, // transaction commitment + eCommitment, // event commitment + rCommitment, // receipt commitment + b.GasPrice, // gas price in wei + gasPriceStrk, // gas price in fri + l1DataGasPricrInWei, + l1DataGasPriceInFri, new(felt.Felt).SetBytes([]byte(b.ProtocolVersion)), &felt.Zero, // reserved: extra data b.ParentHash, // parent block hash