From 1ceb1ba4963746cf27555adfb34ac361e823fedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Mon, 3 Mar 2025 09:53:19 +0100 Subject: [PATCH] fix(system-contract): Ensure header.coinbase is not set (#1127) --- consensus/system_contract/consensus.go | 15 ++++++++++++--- params/version.go | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/consensus/system_contract/consensus.go b/consensus/system_contract/consensus.go index ce33b84887..444b61d4a8 100644 --- a/consensus/system_contract/consensus.go +++ b/consensus/system_contract/consensus.go @@ -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 } diff --git a/params/version.go b/params/version.go index 932a969d21..b54686ad3e 100644 --- a/params/version.go +++ b/params/version.go @@ -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 )