fix(system-contract): Ensure header.coinbase is not set (#1127)

This commit is contained in:
Péter Garamvölgyi 2025-03-03 09:53:19 +01:00 committed by GitHub
parent 1dedddbffb
commit 1ceb1ba496
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View file

@ -219,9 +219,16 @@ func (s *SystemContract) VerifyUncles(chain consensus.ChainReader, block *types.
// Prepare initializes the consensus fields of a block header according to the
// rules of a particular engine. Update only timestamp and prepare ExtraData for Signature
func (s *SystemContract) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error {
// Make sure unused fields are empty
header.Coinbase = common.Address{}
header.Nonce = types.BlockNonce{}
header.MixDigest = common.Hash{}
// Prepare EuclidV2-related fields
header.BlockSignature = make([]byte, extraSeal)
header.IsEuclidV2 = true
header.Extra = nil
// Ensure the timestamp has the correct delay
parent := chain.GetHeader(header.ParentHash, header.Number.Uint64()-1)
if parent == nil {
@ -233,7 +240,10 @@ func (s *SystemContract) Prepare(chain consensus.ChainHeaderReader, header *type
if s.config.RelaxedPeriod || header.Time < uint64(time.Now().Unix()) {
header.Time = uint64(time.Now().Unix())
}
// Difficulty must be 1
header.Difficulty = big.NewInt(1)
return nil
}
@ -241,6 +251,8 @@ func (s *SystemContract) Prepare(chain consensus.ChainHeaderReader, header *type
// No rules here
func (s *SystemContract) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) {
// No block rewards in PoA, so the state remains as is
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
header.UncleHash = types.CalcUncleHash(nil)
}
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
@ -249,9 +261,6 @@ func (s *SystemContract) FinalizeAndAssemble(chain consensus.ChainHeaderReader,
// Finalize block
s.Finalize(chain, header, state, txs, uncles)
// Assign the final state root to header.
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
// Assemble and return the final block for sealing.
return types.NewBlock(header, txs, nil, receipts, trie.NewStackTrie(nil)), nil
}

View file

@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major version component of the current release
VersionMinor = 8 // Minor version component of the current release
VersionPatch = 15 // Patch version component of the current release
VersionPatch = 16 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)