Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions consensus/system_contract/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -233,14 +240,19 @@ 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
}

// Finalize implements consensus.Engine. There is no post-transaction
// 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,
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
Loading