diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index d284a204f06..f498e380362 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -80,23 +80,6 @@ var ( // 100 native token maxSystemBalance = new(uint256.Int).Mul(uint256.NewInt(100), uint256.NewInt(params.Ether)) - systemContracts = map[libcommon.Address]struct{}{ - systemcontracts.ValidatorContract: {}, - systemcontracts.SlashContract: {}, - systemcontracts.SystemRewardContract: {}, - systemcontracts.LightClientContract: {}, - systemcontracts.RelayerHubContract: {}, - systemcontracts.GovHubContract: {}, - systemcontracts.TokenHubContract: {}, - systemcontracts.RelayerIncentivizeContract: {}, - systemcontracts.CrossChainContract: {}, - systemcontracts.StakeHubContract: {}, - systemcontracts.GovernorContract: {}, - systemcontracts.GovTokenContract: {}, - systemcontracts.TimelockContract: {}, - systemcontracts.TokenRecoverPortalContract: {}, - } - validatorItemsCache []ValidatorItem maxElectedValidatorsCache = big.NewInt(0) ) @@ -1273,22 +1256,17 @@ func (p *Parlia) IsSystemTransaction(tx types.Transaction, header *types.Header) if err != nil { return false, errors.New("UnAuthorized transaction") } - if sender == header.Coinbase && isToSystemContract(*tx.GetTo()) && tx.GetPrice().IsZero() { + if sender == header.Coinbase && core.IsToSystemContract(*tx.GetTo()) && tx.GetPrice().IsZero() { return true, nil } return false, nil } -func isToSystemContract(to libcommon.Address) bool { - _, ok := systemContracts[to] - return ok -} - func (p *Parlia) IsSystemContract(to *libcommon.Address) bool { if to == nil { return false } - return isToSystemContract(*to) + return core.IsToSystemContract(*to) } func (p *Parlia) EnoughDistance(chain consensus.ChainReader, header *types.Header) bool { diff --git a/core/blockchain.go b/core/blockchain.go index bed26981e7a..2cdfa7d60ec 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -546,3 +546,25 @@ func BlockPostValidation(gasUsed, blobGasUsed uint64, checkReceipts bool, receip } return nil } + +var systemContracts = map[libcommon.Address]struct{}{ + systemcontracts.ValidatorContract: {}, + systemcontracts.SlashContract: {}, + systemcontracts.SystemRewardContract: {}, + systemcontracts.LightClientContract: {}, + systemcontracts.RelayerHubContract: {}, + systemcontracts.GovHubContract: {}, + systemcontracts.TokenHubContract: {}, + systemcontracts.RelayerIncentivizeContract: {}, + systemcontracts.CrossChainContract: {}, + systemcontracts.StakeHubContract: {}, + systemcontracts.GovernorContract: {}, + systemcontracts.GovTokenContract: {}, + systemcontracts.TimelockContract: {}, + systemcontracts.TokenRecoverPortalContract: {}, +} + +func IsToSystemContract(to libcommon.Address) bool { + _, ok := systemContracts[to] + return ok +} diff --git a/core/state_transition.go b/core/state_transition.go index 4fb41d4bbc8..4da8f8ff50b 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -337,9 +337,9 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (*evmtype // BSC always gave gas bailout due to system transactions that set 2^256/2 gas limit and // So when trace systemTx, skip PreCheck var skipCheck bool - if st.isParlia && st.msg.Gas() == math.MaxUint64/2 && st.gasPrice.IsZero() { + if st.isParlia && st.msg.Gas() == math.MaxUint64/2 && IsToSystemContract(*st.msg.To()) && st.msg.From() == coinbase { skipCheck = true - st.state.AddBalance(coinbase, st.state.GetBalance(consensus.SystemAddress), tracing.BalanceChangeUnspecified) + st.state.AddBalance(coinbase, st.msg.Value(), tracing.BalanceChangeUnspecified) } // Check clauses 1-3 and 6, buy gas if everything is correct