From c80c63523cfdf457ac9c247a8d550b95314f3016 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Wed, 16 Apr 2025 16:04:18 +0200 Subject: [PATCH 1/5] Use upstream params for params/extras/protocol_params.go constants --- core/block_validator.go | 10 +++++----- core/block_validator_test.go | 8 ++++++++ params/extras/protocol_params.go | 11 ----------- plugin/evm/header/extra.go | 8 ++++++-- plugin/evm/header/extra_test.go | 12 ++++++++++-- plugin/evm/header/gas_limit.go | 9 +++++---- plugin/evm/header/gas_limit_test.go | 13 +++++++------ 7 files changed, 41 insertions(+), 30 deletions(-) delete mode 100644 params/extras/protocol_params.go diff --git a/core/block_validator.go b/core/block_validator.go index 6a18502afe..488f18b7ce 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -31,11 +31,11 @@ import ( "fmt" "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/trie" "github.com/ava-labs/subnet-evm/consensus" "github.com/ava-labs/subnet-evm/core/state" "github.com/ava-labs/subnet-evm/params" - "github.com/ava-labs/subnet-evm/params/extras" ) // BlockValidator is responsible for validating block headers, uncles and @@ -148,10 +148,10 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD // the gas allowance. func CalcGasLimit(parentGasUsed, parentGasLimit, gasFloor, gasCeil uint64) uint64 { // contrib = (parentGasUsed * 3 / 2) / 1024 - contrib := (parentGasUsed + parentGasUsed/2) / extras.GasLimitBoundDivisor + contrib := (parentGasUsed + parentGasUsed/2) / ethparams.GasLimitBoundDivisor // decay = parentGasLimit / 1024 -1 - decay := parentGasLimit/extras.GasLimitBoundDivisor - 1 + decay := parentGasLimit/ethparams.GasLimitBoundDivisor - 1 /* strategy: gasLimit of block-to-mine is set based on parent's @@ -161,8 +161,8 @@ func CalcGasLimit(parentGasUsed, parentGasLimit, gasFloor, gasCeil uint64) uint6 from parentGasLimit * (2/3) parentGasUsed is. */ limit := parentGasLimit - decay + contrib - if limit < extras.MinGasLimit { - limit = extras.MinGasLimit + if limit < ethparams.MinGasLimit { + limit = ethparams.MinGasLimit } // If we're outside our allowed gas range, we try to hone towards them if limit < gasFloor { diff --git a/core/block_validator_test.go b/core/block_validator_test.go index b0bc93ff5f..a35339c4fe 100644 --- a/core/block_validator_test.go +++ b/core/block_validator_test.go @@ -28,6 +28,9 @@ package core import ( "testing" + + ethparams "github.com/ava-labs/libevm/params" + "github.com/stretchr/testify/assert" ) // TODO: Add TestHeaderVerification @@ -63,3 +66,8 @@ func TestCalcGasLimit(t *testing.T) { } } } + +func TestUpstreamParamsValues(t *testing.T) { + assert.Equal(t, uint64(1024), ethparams.GasLimitBoundDivisor, "gas limit bound divisor") + assert.Equal(t, uint64(5000), ethparams.MinGasLimit, "min gas limit") +} diff --git a/params/extras/protocol_params.go b/params/extras/protocol_params.go deleted file mode 100644 index 1a9281f0e3..0000000000 --- a/params/extras/protocol_params.go +++ /dev/null @@ -1,11 +0,0 @@ -// (c) 2025, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package extras - -const ( - GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations. - MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1). - MaximumExtraDataSize uint64 = 64 // Maximum size extra data may be after Genesis. - MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be. -) diff --git a/plugin/evm/header/extra.go b/plugin/evm/header/extra.go index e136c004df..91d4780172 100644 --- a/plugin/evm/header/extra.go +++ b/plugin/evm/header/extra.go @@ -13,6 +13,10 @@ import ( "github.com/ava-labs/subnet-evm/plugin/evm/upgrade/subnetevm" ) +const ( + maximumExtraDataSize = 64 // Maximum size extra data may be after Genesis. +) + var ( errInvalidExtraPrefix = errors.New("invalid header.Extra prefix") errInvalidExtraLength = errors.New("invalid header.Extra length") @@ -89,11 +93,11 @@ func VerifyExtra(rules extras.AvalancheRules, extra []byte) error { ) } default: - if uint64(extraLen) > extras.MaximumExtraDataSize { + if uint64(extraLen) > maximumExtraDataSize { return fmt.Errorf( "%w: expected <= %d but got %d", errInvalidExtraLength, - extras.MaximumExtraDataSize, + maximumExtraDataSize, extraLen, ) } diff --git a/plugin/evm/header/extra_test.go b/plugin/evm/header/extra_test.go index fd042c9f2d..2e85bdf1d8 100644 --- a/plugin/evm/header/extra_test.go +++ b/plugin/evm/header/extra_test.go @@ -8,10 +8,12 @@ import ( "testing" "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/params/extras" "github.com/ava-labs/subnet-evm/plugin/evm/customtypes" "github.com/ava-labs/subnet-evm/plugin/evm/upgrade/subnetevm" "github.com/ava-labs/subnet-evm/utils" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -187,13 +189,13 @@ func TestVerifyExtra(t *testing.T) { { name: "initial_valid", rules: extras.AvalancheRules{}, - extra: make([]byte, extras.MaximumExtraDataSize), + extra: make([]byte, maximumExtraDataSize), expected: nil, }, { name: "initial_invalid", rules: extras.AvalancheRules{}, - extra: make([]byte, extras.MaximumExtraDataSize+1), + extra: make([]byte, maximumExtraDataSize+1), expected: errInvalidExtraLength, }, { @@ -367,3 +369,9 @@ func TestPredicateBytesExtra(t *testing.T) { }) } } + +func TestUpstreamParamsValues(t *testing.T) { + assert.Equal(t, uint64(1024), ethparams.GasLimitBoundDivisor, "gas limit bound divisor") + assert.Equal(t, uint64(5000), ethparams.MinGasLimit, "min gas limit") + assert.Equal(t, uint64(0x7fffffffffffffff), ethparams.MaxGasLimit, "max gas limit") +} diff --git a/plugin/evm/header/gas_limit.go b/plugin/evm/header/gas_limit.go index 3b62e0ecc1..da57a27053 100644 --- a/plugin/evm/header/gas_limit.go +++ b/plugin/evm/header/gas_limit.go @@ -9,6 +9,7 @@ import ( "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/commontype" "github.com/ava-labs/subnet-evm/params/extras" ) @@ -81,18 +82,18 @@ func VerifyGasLimit( ) } default: - if header.GasLimit < extras.MinGasLimit || header.GasLimit > extras.MaxGasLimit { + if header.GasLimit < ethparams.MinGasLimit || header.GasLimit > ethparams.MaxGasLimit { return fmt.Errorf("%w: %d not in range [%d, %d]", errInvalidGasLimit, header.GasLimit, - extras.MinGasLimit, - extras.MaxGasLimit, + ethparams.MinGasLimit, + ethparams.MaxGasLimit, ) } // Verify that the gas limit remains within allowed bounds diff := math.AbsDiff(parent.GasLimit, header.GasLimit) - limit := parent.GasLimit / extras.GasLimitBoundDivisor + limit := parent.GasLimit / ethparams.GasLimitBoundDivisor if diff >= limit { return fmt.Errorf("%w: have %d, want %d += %d", errInvalidGasLimit, diff --git a/plugin/evm/header/gas_limit_test.go b/plugin/evm/header/gas_limit_test.go index 20aee06d8b..fa2ff83652 100644 --- a/plugin/evm/header/gas_limit_test.go +++ b/plugin/evm/header/gas_limit_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/commontype" "github.com/ava-labs/subnet-evm/params/extras" "github.com/stretchr/testify/require" @@ -104,10 +105,10 @@ func VerifyGasLimitTest(t *testing.T, feeConfig commontype.FeeConfig) { name: "pre_subnet_evm_too_low", upgrades: extras.TestPreSubnetEVMChainConfig.NetworkUpgrades, parent: &types.Header{ - GasLimit: extras.MinGasLimit, + GasLimit: ethparams.MinGasLimit, }, header: &types.Header{ - GasLimit: extras.MinGasLimit - 1, + GasLimit: ethparams.MinGasLimit - 1, }, want: errInvalidGasLimit, }, @@ -115,10 +116,10 @@ func VerifyGasLimitTest(t *testing.T, feeConfig commontype.FeeConfig) { name: "pre_subnet_evm_too_high", upgrades: extras.TestPreSubnetEVMChainConfig.NetworkUpgrades, parent: &types.Header{ - GasLimit: extras.MaxGasLimit, + GasLimit: ethparams.MaxGasLimit, }, header: &types.Header{ - GasLimit: extras.MaxGasLimit + 1, + GasLimit: ethparams.MaxGasLimit + 1, }, want: errInvalidGasLimit, }, @@ -126,10 +127,10 @@ func VerifyGasLimitTest(t *testing.T, feeConfig commontype.FeeConfig) { name: "pre_subnet_evm_too_large", upgrades: extras.TestPreSubnetEVMChainConfig.NetworkUpgrades, parent: &types.Header{ - GasLimit: extras.MinGasLimit, + GasLimit: ethparams.MinGasLimit, }, header: &types.Header{ - GasLimit: extras.MaxGasLimit, + GasLimit: ethparams.MaxGasLimit, }, want: errInvalidGasLimit, }, From bad76b65be496cf19d94921a5a178720642a2e50 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Wed, 16 Apr 2025 17:42:32 +0200 Subject: [PATCH 2/5] Use upstream params constants and delete params/protocol_params.go --- cmd/evm/internal/t8ntool/execution.go | 5 +- cmd/evm/internal/t8ntool/transaction.go | 3 +- cmd/simulator/load/funder.go | 4 +- cmd/simulator/load/loader.go | 7 +- consensus/misc/eip4844/eip4844.go | 18 +-- consensus/misc/eip4844/eip4844_test.go | 20 +-- core/bench_test.go | 11 +- core/block_validator.go | 4 +- core/block_validator_test.go | 8 - core/blockchain_repair_test.go | 5 +- core/blockchain_test.go | 9 +- core/chain_makers_test.go | 7 +- core/genesis.go | 5 +- core/state_processor.go | 9 +- core/state_processor_ext_test.go | 3 +- core/state_processor_test.go | 37 ++--- core/state_transition.go | 29 ++-- core/test_blockchain.go | 47 +++--- core/txindexer_test.go | 9 +- core/txpool/blobpool/blobpool.go | 9 +- core/txpool/blobpool/blobpool_test.go | 9 +- core/txpool/blobpool/evictheap_test.go | 6 +- core/txpool/validation.go | 11 +- core/vm/runtime/runtime.go | 3 +- eth/gasestimator/gasestimator.go | 9 +- eth/gasprice/feehistory_test.go | 3 +- eth/gasprice/gasprice_test.go | 9 +- eth/tracers/api_extra_test.go | 11 +- eth/tracers/api_test.go | 17 ++- ethclient/simulated/backend_test.go | 3 +- ethclient/simulated/options_test.go | 4 +- internal/ethapi/api_test.go | 11 +- internal/ethapi/transaction_args.go | 3 +- miner/worker.go | 13 +- params/config_test.go | 123 +++++++++++++++ params/protocol_params.go | 193 ------------------------ plugin/evm/header/extra_test.go | 8 - plugin/evm/syncervm_test.go | 4 +- sync/client/client.go | 9 +- sync/client/client_test.go | 3 +- sync/handlers/code_request_test.go | 9 +- tests/antithesis/main.go | 4 +- tests/state_test_util.go | 3 +- tests/utils/proposervm.go | 4 +- 44 files changed, 331 insertions(+), 390 deletions(-) delete mode 100644 params/protocol_params.go diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index 7b81bc1795..1ecf2c3e83 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -38,6 +38,7 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/ethdb" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/rlp" "github.com/ava-labs/libevm/trie" "github.com/ava-labs/libevm/triedb" @@ -222,8 +223,8 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, } txBlobGas := uint64(0) if tx.Type() == types.BlobTxType { - txBlobGas = uint64(params.BlobTxBlobGasPerBlob * len(tx.BlobHashes())) - if used, max := blobGasUsed+txBlobGas, uint64(params.MaxBlobGasPerBlock); used > max { + txBlobGas = uint64(ethparams.BlobTxBlobGasPerBlob * len(tx.BlobHashes())) + if used, max := blobGasUsed+txBlobGas, uint64(ethparams.MaxBlobGasPerBlock); used > max { err := fmt.Errorf("blob gas (%d) would exceed maximum allowance %d", used, max) log.Warn("rejected tx", "index", i, "err", err) rejectedTxs = append(rejectedTxs, &rejectedTx{i, err.Error()}) diff --git a/cmd/evm/internal/t8ntool/transaction.go b/cmd/evm/internal/t8ntool/transaction.go index 5336ee26d8..8c905c453d 100644 --- a/cmd/evm/internal/t8ntool/transaction.go +++ b/cmd/evm/internal/t8ntool/transaction.go @@ -37,6 +37,7 @@ import ( "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/common/hexutil" "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/rlp" "github.com/ava-labs/subnet-evm/core" "github.com/ava-labs/subnet-evm/params" @@ -176,7 +177,7 @@ func Transaction(ctx *cli.Context) error { r.Error = errors.New("gas * maxFeePerGas exceeds 256 bits") } // Check whether the init code size has been exceeded. - if params.GetExtra(chainConfig).IsDurango(0) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize { + if params.GetExtra(chainConfig).IsDurango(0) && tx.To() == nil && len(tx.Data()) > ethparams.MaxInitCodeSize { r.Error = errors.New("max initcode size exceeded") } results = append(results, r) diff --git a/cmd/simulator/load/funder.go b/cmd/simulator/load/funder.go index d576330ca3..4563d9af7c 100644 --- a/cmd/simulator/load/funder.go +++ b/cmd/simulator/load/funder.go @@ -12,11 +12,11 @@ import ( "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/cmd/simulator/key" "github.com/ava-labs/subnet-evm/cmd/simulator/metrics" "github.com/ava-labs/subnet-evm/cmd/simulator/txs" "github.com/ava-labs/subnet-evm/ethclient" - "github.com/ava-labs/subnet-evm/params" ) // DistributeFunds ensures that each address in keys has at least [minFundsPerAddr] by sending funds @@ -90,7 +90,7 @@ func DistributeFunds(ctx context.Context, client ethclient.Client, keys []*key.K Nonce: nonce, GasTipCap: gasTipCap, GasFeeCap: gasFeeCap, - Gas: params.TxGas, + Gas: ethparams.TxGas, To: &needFundsAddrs[i], Data: nil, Value: requiredFunds, diff --git a/cmd/simulator/load/loader.go b/cmd/simulator/load/loader.go index f0ada1f52f..6bfc74cc51 100644 --- a/cmd/simulator/load/loader.go +++ b/cmd/simulator/load/loader.go @@ -18,6 +18,7 @@ import ( "github.com/ava-labs/libevm/core/types" ethcrypto "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/cmd/simulator/config" "github.com/ava-labs/subnet-evm/cmd/simulator/key" "github.com/ava-labs/subnet-evm/cmd/simulator/metrics" @@ -180,10 +181,10 @@ func ExecuteLoader(ctx context.Context, config config.Config) error { } } - // Each address needs: params.GWei * MaxFeeCap * params.TxGas * TxsPerWorker total wei + // Each address needs: params.GWei * MaxFeeCap * ethparams.TxGas * TxsPerWorker total wei // to fund gas for all of their transactions. maxFeeCap := new(big.Int).Mul(big.NewInt(params.GWei), big.NewInt(config.MaxFeeCap)) - minFundsPerAddr := new(big.Int).Mul(maxFeeCap, big.NewInt(int64(config.TxsPerWorker*params.TxGas))) + minFundsPerAddr := new(big.Int).Mul(maxFeeCap, big.NewInt(int64(config.TxsPerWorker*ethparams.TxGas))) fundStart := time.Now() log.Info("Distributing funds", "numTxsPerWorker", config.TxsPerWorker, "minFunds", minFundsPerAddr) keys, err = DistributeFunds(ctx, clients[0], keys, config.Workers, minFundsPerAddr, m) @@ -217,7 +218,7 @@ func ExecuteLoader(ctx context.Context, config config.Config) error { Nonce: nonce, GasTipCap: gasTipCap, GasFeeCap: gasFeeCap, - Gas: params.TxGas, + Gas: ethparams.TxGas, To: &addr, Data: nil, Value: common.Big0, diff --git a/consensus/misc/eip4844/eip4844.go b/consensus/misc/eip4844/eip4844.go index bc6821847a..f1cff9b941 100644 --- a/consensus/misc/eip4844/eip4844.go +++ b/consensus/misc/eip4844/eip4844.go @@ -32,12 +32,12 @@ import ( "math/big" "github.com/ava-labs/libevm/core/types" - "github.com/ava-labs/subnet-evm/params" + ethparams "github.com/ava-labs/libevm/params" ) var ( - minBlobGasPrice = big.NewInt(params.BlobTxMinBlobGasprice) - blobGaspriceUpdateFraction = big.NewInt(params.BlobTxBlobGaspriceUpdateFraction) + minBlobGasPrice = big.NewInt(ethparams.BlobTxMinBlobGasprice) + blobGaspriceUpdateFraction = big.NewInt(ethparams.BlobTxBlobGaspriceUpdateFraction) ) // VerifyEIP4844Header verifies the presence of the excessBlobGas field and that @@ -52,11 +52,11 @@ func VerifyEIP4844Header(parent, header *types.Header) error { return errors.New("header is missing blobGasUsed") } // Verify that the blob gas used remains within reasonable limits. - if *header.BlobGasUsed > params.MaxBlobGasPerBlock { - return fmt.Errorf("blob gas used %d exceeds maximum allowance %d", *header.BlobGasUsed, params.MaxBlobGasPerBlock) + if *header.BlobGasUsed > ethparams.MaxBlobGasPerBlock { + return fmt.Errorf("blob gas used %d exceeds maximum allowance %d", *header.BlobGasUsed, ethparams.MaxBlobGasPerBlock) } - if *header.BlobGasUsed%params.BlobTxBlobGasPerBlob != 0 { - return fmt.Errorf("blob gas used %d not a multiple of blob gas per blob %d", header.BlobGasUsed, params.BlobTxBlobGasPerBlob) + if *header.BlobGasUsed%ethparams.BlobTxBlobGasPerBlob != 0 { + return fmt.Errorf("blob gas used %d not a multiple of blob gas per blob %d", header.BlobGasUsed, ethparams.BlobTxBlobGasPerBlob) } // Verify the excessBlobGas is correct based on the parent header var ( @@ -79,10 +79,10 @@ func VerifyEIP4844Header(parent, header *types.Header) error { // blobs on top of the excess blob gas. func CalcExcessBlobGas(parentExcessBlobGas uint64, parentBlobGasUsed uint64) uint64 { excessBlobGas := parentExcessBlobGas + parentBlobGasUsed - if excessBlobGas < params.BlobTxTargetBlobGasPerBlock { + if excessBlobGas < ethparams.BlobTxTargetBlobGasPerBlock { return 0 } - return excessBlobGas - params.BlobTxTargetBlobGasPerBlock + return excessBlobGas - ethparams.BlobTxTargetBlobGasPerBlock } // CalcBlobFee calculates the blobfee from the header's excess blob gas field. diff --git a/consensus/misc/eip4844/eip4844_test.go b/consensus/misc/eip4844/eip4844_test.go index 04c735f068..304f0611c5 100644 --- a/consensus/misc/eip4844/eip4844_test.go +++ b/consensus/misc/eip4844/eip4844_test.go @@ -21,7 +21,7 @@ import ( "math/big" "testing" - "github.com/ava-labs/subnet-evm/params" + ethparams "github.com/ava-labs/libevm/params" ) func TestCalcExcessBlobGas(t *testing.T) { @@ -34,23 +34,23 @@ func TestCalcExcessBlobGas(t *testing.T) { // slots are below - or equal - to the target. {0, 0, 0}, {0, 1, 0}, - {0, params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob, 0}, + {0, ethparams.BlobTxTargetBlobGasPerBlock / ethparams.BlobTxBlobGasPerBlob, 0}, // If the target blob gas is exceeded, the excessBlobGas should increase // by however much it was overshot - {0, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) + 1, params.BlobTxBlobGasPerBlob}, - {1, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) + 1, params.BlobTxBlobGasPerBlob + 1}, - {1, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) + 2, 2*params.BlobTxBlobGasPerBlob + 1}, + {0, (ethparams.BlobTxTargetBlobGasPerBlock / ethparams.BlobTxBlobGasPerBlob) + 1, ethparams.BlobTxBlobGasPerBlob}, + {1, (ethparams.BlobTxTargetBlobGasPerBlock / ethparams.BlobTxBlobGasPerBlob) + 1, ethparams.BlobTxBlobGasPerBlob + 1}, + {1, (ethparams.BlobTxTargetBlobGasPerBlock / ethparams.BlobTxBlobGasPerBlob) + 2, 2*ethparams.BlobTxBlobGasPerBlob + 1}, // The excess blob gas should decrease by however much the target was // under-shot, capped at zero. - {params.BlobTxTargetBlobGasPerBlock, params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob, params.BlobTxTargetBlobGasPerBlock}, - {params.BlobTxTargetBlobGasPerBlock, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) - 1, params.BlobTxTargetBlobGasPerBlock - params.BlobTxBlobGasPerBlob}, - {params.BlobTxTargetBlobGasPerBlock, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) - 2, params.BlobTxTargetBlobGasPerBlock - (2 * params.BlobTxBlobGasPerBlob)}, - {params.BlobTxBlobGasPerBlob - 1, (params.BlobTxTargetBlobGasPerBlock / params.BlobTxBlobGasPerBlob) - 1, 0}, + {ethparams.BlobTxTargetBlobGasPerBlock, ethparams.BlobTxTargetBlobGasPerBlock / ethparams.BlobTxBlobGasPerBlob, ethparams.BlobTxTargetBlobGasPerBlock}, + {ethparams.BlobTxTargetBlobGasPerBlock, (ethparams.BlobTxTargetBlobGasPerBlock / ethparams.BlobTxBlobGasPerBlob) - 1, ethparams.BlobTxTargetBlobGasPerBlock - ethparams.BlobTxBlobGasPerBlob}, + {ethparams.BlobTxTargetBlobGasPerBlock, (ethparams.BlobTxTargetBlobGasPerBlock / ethparams.BlobTxBlobGasPerBlob) - 2, ethparams.BlobTxTargetBlobGasPerBlock - (2 * ethparams.BlobTxBlobGasPerBlob)}, + {ethparams.BlobTxBlobGasPerBlob - 1, (ethparams.BlobTxTargetBlobGasPerBlock / ethparams.BlobTxBlobGasPerBlob) - 1, 0}, } for i, tt := range tests { - result := CalcExcessBlobGas(tt.excess, tt.blobs*params.BlobTxBlobGasPerBlob) + result := CalcExcessBlobGas(tt.excess, tt.blobs*ethparams.BlobTxBlobGasPerBlob) if result != tt.want { t.Errorf("test %d: excess blob gas mismatch: have %v, want %v", i, result, tt.want) } diff --git a/core/bench_test.go b/core/bench_test.go index c64a8b0679..24263187e0 100644 --- a/core/bench_test.go +++ b/core/bench_test.go @@ -38,6 +38,7 @@ import ( "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/ethdb" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/consensus/dummy" "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/plugin/evm/customrawdb" @@ -126,26 +127,26 @@ func init() { // and fills the blocks with many small transactions. func genTxRing(naccounts int) func(int, *BlockGen) { from := 0 - fee := big.NewInt(0).SetUint64(params.TxGas * 225000000000) + fee := big.NewInt(0).SetUint64(ethparams.TxGas * 225000000000) amount := big.NewInt(0).Set(benchRootFunds) return func(i int, gen *BlockGen) { block := gen.PrevBlock(i - 1) gas := block.GasLimit() signer := gen.Signer() for { - gas -= params.TxGas - if gas < params.TxGas { + gas -= ethparams.TxGas + if gas < ethparams.TxGas { break } to := (from + 1) % naccounts - burn := new(big.Int).SetUint64(params.TxGas) + burn := new(big.Int).SetUint64(ethparams.TxGas) burn.Mul(burn, gen.header.BaseFee) tx, err := types.SignNewTx(ringKeys[from], signer, &types.LegacyTx{ Nonce: gen.TxNonce(ringAddrs[from]), To: &ringAddrs[to], Value: amount.Sub(amount, fee), - Gas: params.TxGas, + Gas: ethparams.TxGas, GasPrice: big.NewInt(225000000000), }) if err != nil { diff --git a/core/block_validator.go b/core/block_validator.go index 488f18b7ce..eff7a21112 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -97,8 +97,8 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error { // Check blob gas usage. if header.BlobGasUsed != nil { - if want := *header.BlobGasUsed / params.BlobTxBlobGasPerBlob; uint64(blobs) != want { // div because the header is surely good vs the body might be bloated - return fmt.Errorf("blob gas used mismatch (header %v, calculated %v)", *header.BlobGasUsed, blobs*params.BlobTxBlobGasPerBlob) + if want := *header.BlobGasUsed / ethparams.BlobTxBlobGasPerBlob; uint64(blobs) != want { // div because the header is surely good vs the body might be bloated + return fmt.Errorf("blob gas used mismatch (header %v, calculated %v)", *header.BlobGasUsed, blobs*ethparams.BlobTxBlobGasPerBlob) } } else { if blobs > 0 { diff --git a/core/block_validator_test.go b/core/block_validator_test.go index a35339c4fe..b0bc93ff5f 100644 --- a/core/block_validator_test.go +++ b/core/block_validator_test.go @@ -28,9 +28,6 @@ package core import ( "testing" - - ethparams "github.com/ava-labs/libevm/params" - "github.com/stretchr/testify/assert" ) // TODO: Add TestHeaderVerification @@ -66,8 +63,3 @@ func TestCalcGasLimit(t *testing.T) { } } } - -func TestUpstreamParamsValues(t *testing.T) { - assert.Equal(t, uint64(1024), ethparams.GasLimitBoundDivisor, "gas limit bound divisor") - assert.Equal(t, uint64(5000), ethparams.MinGasLimit, "min gas limit") -} diff --git a/core/blockchain_repair_test.go b/core/blockchain_repair_test.go index 256abca3c5..a6732611b5 100644 --- a/core/blockchain_repair_test.go +++ b/core/blockchain_repair_test.go @@ -39,6 +39,7 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/crypto" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/triedb" "github.com/ava-labs/subnet-evm/consensus/dummy" "github.com/ava-labs/subnet-evm/params" @@ -568,7 +569,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s gspec.MustCommit(genDb, triedb.NewDatabase(genDb, nil)) sideblocks, _, err = GenerateChain(gspec.Config, gspec.ToBlock(), engine, genDb, tt.sidechainBlocks, 10, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{0x01}) - tx, err := types.SignTx(types.NewTransaction(b.TxNonce(addr1), common.Address{0x01}, big.NewInt(10000), params.TxGas, feeConfig.MinBaseFee, nil), signer, key1) + tx, err := types.SignTx(types.NewTransaction(b.TxNonce(addr1), common.Address{0x01}, big.NewInt(10000), ethparams.TxGas, feeConfig.MinBaseFee, nil), signer, key1) require.NoError(err) b.AddTx(tx) }) @@ -582,7 +583,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s canonblocks, _, err := GenerateChain(gspec.Config, gspec.ToBlock(), engine, genDb, tt.canonicalBlocks, 10, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{0x02}) b.SetDifficulty(big.NewInt(1000000)) - tx, err := types.SignTx(types.NewTransaction(b.TxNonce(addr1), common.Address{0x02}, big.NewInt(10000), params.TxGas, feeConfig.MinBaseFee, nil), signer, key1) + tx, err := types.SignTx(types.NewTransaction(b.TxNonce(addr1), common.Address{0x02}, big.NewInt(10000), ethparams.TxGas, feeConfig.MinBaseFee, nil), signer, key1) require.NoError(err) b.AddTx(tx) }) diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 3ea2abbab7..3de6e10e27 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -17,6 +17,7 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/eth/tracers/logger" "github.com/ava-labs/libevm/ethdb" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/consensus/dummy" "github.com/ava-labs/subnet-evm/core/state" "github.com/ava-labs/subnet-evm/core/state/pruner" @@ -331,7 +332,7 @@ func testRepopulateMissingTriesParallel(t *testing.T, parallelism int) { // This call generates a chain of 3 blocks. signer := types.HomesteadSigner{} _, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 10, 10, func(i int, gen *BlockGen) { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) }) if err != nil { @@ -447,7 +448,7 @@ func TestUngracefulAsyncShutdown(t *testing.T) { // This call generates a chain of 10 blocks. signer := types.HomesteadSigner{} _, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 10, 10, func(i int, gen *BlockGen) { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) }) if err != nil { @@ -1095,8 +1096,8 @@ func TestEIP3651(t *testing.T) { block := chain.GetBlockByNumber(1) // 1+2: Ensure EIP-1559 access lists are accounted for via gas usage. - innerGas := vm.GasQuickStep*2 + params.ColdSloadCostEIP2929*2 - expectedGas := params.TxGas + 5*vm.GasFastestStep + vm.GasQuickStep + 100 + innerGas // 100 because 0xaaaa is in access list + innerGas := vm.GasQuickStep*2 + ethparams.ColdSloadCostEIP2929*2 + expectedGas := ethparams.TxGas + 5*vm.GasFastestStep + vm.GasQuickStep + 100 + innerGas // 100 because 0xaaaa is in access list if block.GasUsed() != expectedGas { t.Fatalf("incorrect amount of gas spent: expected %d, got %d", expectedGas, block.GasUsed()) } diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index a200272c16..7ffd207ed6 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -35,6 +35,7 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/crypto" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/triedb" "github.com/ava-labs/subnet-evm/consensus/dummy" "github.com/ava-labs/subnet-evm/params" @@ -67,15 +68,15 @@ func ExampleGenerateChain() { switch i { case 0: // In block 1, addr1 sends addr2 some ether. - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) case 1: // In block 2, addr1 sends some more ether to addr2. // addr2 passes it on to addr3. - tx1, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(1000), params.TxGas, nil, nil), signer, key1) + tx1, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(1000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx1) case 2: - tx2, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr3, big.NewInt(1000), params.TxGas, nil, nil), signer, key2) + tx2, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr3, big.NewInt(1000), ethparams.TxGas, nil, nil), signer, key2) gen.AddTx(tx2) } }) diff --git a/core/genesis.go b/core/genesis.go index 9c0815d4fe..a517c66257 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -41,6 +41,7 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/ethdb" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/trie" "github.com/ava-labs/libevm/triedb" "github.com/ava-labs/subnet-evm/core/state" @@ -306,10 +307,10 @@ func (g *Genesis) toBlock(db ethdb.Database, triedb *triedb.Database) *types.Blo head.Root = root if g.GasLimit == 0 { - head.GasLimit = params.GenesisGasLimit + head.GasLimit = ethparams.GenesisGasLimit } if g.Difficulty == nil { - head.Difficulty = params.GenesisDifficulty + head.Difficulty = ethparams.GenesisDifficulty } if conf := g.Config; conf != nil { num := new(big.Int).SetUint64(g.Number) diff --git a/core/state_processor.go b/core/state_processor.go index 2b3b0a75be..2bd04a6880 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -35,6 +35,7 @@ import ( "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/consensus" "github.com/ava-labs/subnet-evm/core/state" "github.com/ava-labs/subnet-evm/params" @@ -147,7 +148,7 @@ func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, sta receipt.GasUsed = result.UsedGas if tx.Type() == types.BlobTxType { - receipt.BlobGasUsed = uint64(len(tx.BlobHashes()) * params.BlobTxBlobGasPerBlob) + receipt.BlobGasUsed = uint64(len(tx.BlobHashes()) * ethparams.BlobTxBlobGasPerBlob) receipt.BlobGasPrice = evm.Context.BlobBaseFee } @@ -186,16 +187,16 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat // If EIP-4788 is enabled, we need to invoke the beaconroot storage contract with // the new root msg := &Message{ - From: params.SystemAddress, + From: ethparams.SystemAddress, GasLimit: 30_000_000, GasPrice: common.Big0, GasFeeCap: common.Big0, GasTipCap: common.Big0, - To: ¶ms.BeaconRootsStorageAddress, + To: ðparams.BeaconRootsStorageAddress, Data: beaconRoot[:], } vmenv.Reset(NewEVMTxContext(msg), statedb) - statedb.AddAddressToAccessList(params.BeaconRootsStorageAddress) + statedb.AddAddressToAccessList(ethparams.BeaconRootsStorageAddress) _, _, _ = vmenv.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560) statedb.Finalise(true) } diff --git a/core/state_processor_ext_test.go b/core/state_processor_ext_test.go index 272960b850..341248ff8c 100644 --- a/core/state_processor_ext_test.go +++ b/core/state_processor_ext_test.go @@ -12,6 +12,7 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/crypto" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/consensus/dummy" "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/params/extras" @@ -88,7 +89,7 @@ func TestBadTxAllowListBlock(t *testing.T) { }{ { // Nonwhitelisted address txs: []*types.Transaction{ - mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(0), big.NewInt(225000000000)), + mkDynamicTx(0, common.Address{}, ethparams.TxGas, big.NewInt(0), big.NewInt(225000000000)), }, want: "could not apply tx 0 [0xc5725e8baac950b2925dd4fea446ccddead1cc0affdae18b31a7d910629d9225]: cannot issue transaction from non-allow listed address: 0x71562b71999873DB5b286dF957af199Ec94617F7", }, diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 89c6f7f634..46ee8bc108 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -37,6 +37,7 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/crypto" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/trie" "github.com/ava-labs/subnet-evm/consensus" "github.com/ava-labs/subnet-evm/consensus/dummy" @@ -126,7 +127,7 @@ func TestStateProcessorErrors(t *testing.T) { } // FullFaker used to skip header verification that enforces no blobs. blockchain, _ = NewBlockChain(db, DefaultCacheConfig, gspec, dummy.NewFullFaker(), vm.Config{}, common.Hash{}, false) - tooBigInitCode = [params.MaxInitCodeSize + 1]byte{} + tooBigInitCode = [ethparams.MaxInitCodeSize + 1]byte{} ) defer blockchain.Stop() @@ -139,14 +140,14 @@ func TestStateProcessorErrors(t *testing.T) { }{ { // ErrNonceTooLow txs: []*types.Transaction{ - makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(225000000000), nil), - makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(225000000000), nil), + makeTx(key1, 0, common.Address{}, big.NewInt(0), ethparams.TxGas, big.NewInt(225000000000), nil), + makeTx(key1, 0, common.Address{}, big.NewInt(0), ethparams.TxGas, big.NewInt(225000000000), nil), }, want: "could not apply tx 1 [0x734d821c990099c6ae42d78072aadd3931c35328cf03ef4cf5b2a4ac9c398522]: nonce too low: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tx: 0 state: 1", }, { // ErrNonceTooHigh txs: []*types.Transaction{ - makeTx(key1, 100, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(225000000000), nil), + makeTx(key1, 100, common.Address{}, big.NewInt(0), ethparams.TxGas, big.NewInt(225000000000), nil), }, want: "could not apply tx 0 [0x0df36254cfbef8ed6961b38fc68aecc777177166144c8a56bc8919e23a559bf4]: nonce too high: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tx: 100 state: 0", }, @@ -158,13 +159,13 @@ func TestStateProcessorErrors(t *testing.T) { }, { // ErrInsufficientFundsForTransfer txs: []*types.Transaction{ - makeTx(key1, 0, common.Address{}, big.NewInt(4000000000000000000), params.TxGas, big.NewInt(225000000000), nil), + makeTx(key1, 0, common.Address{}, big.NewInt(4000000000000000000), ethparams.TxGas, big.NewInt(225000000000), nil), }, want: "could not apply tx 0 [0x1632f2bffcce84a5c91dd8ab2016128fccdbcfbe0485d2c67457e1c793c72a4b]: insufficient funds for gas * price + value: address 0x71562b71999873DB5b286dF957af199Ec94617F7 have 4000000000000000000 want 4004725000000000000", }, { // ErrInsufficientFunds txs: []*types.Transaction{ - makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(900000000000000000), nil), + makeTx(key1, 0, common.Address{}, big.NewInt(0), ethparams.TxGas, big.NewInt(900000000000000000), nil), }, want: "could not apply tx 0 [0x4a69690c4b0cd85e64d0d9ea06302455b01e10a83db964d60281739752003440]: insufficient funds for gas * price + value: address 0x71562b71999873DB5b286dF957af199Ec94617F7 have 4000000000000000000 want 18900000000000000000000", }, @@ -174,37 +175,37 @@ func TestStateProcessorErrors(t *testing.T) { // multiplication len(data) +gas_per_byte overflows uint64. Not testable at the moment { // ErrIntrinsicGas txs: []*types.Transaction{ - makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas-1000, big.NewInt(225000000000), nil), + makeTx(key1, 0, common.Address{}, big.NewInt(0), ethparams.TxGas-1000, big.NewInt(225000000000), nil), }, want: "could not apply tx 0 [0x2fc3e3b5cc26917d413e26983fe189475f47d4f0757e32aaa5561fcb9c9dc432]: intrinsic gas too low: have 20000, want 21000", }, { // ErrGasLimitReached txs: []*types.Transaction{ - makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas*762, big.NewInt(225000000000), nil), + makeTx(key1, 0, common.Address{}, big.NewInt(0), ethparams.TxGas*762, big.NewInt(225000000000), nil), }, want: "could not apply tx 0 [0x76c07cc2b32007eb1a9c3fa066d579a3d77ec4ecb79bbc266624a601d7b08e46]: gas limit reached", }, { // ErrFeeCapTooLow txs: []*types.Transaction{ - mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(0), big.NewInt(0)), + mkDynamicTx(0, common.Address{}, ethparams.TxGas, big.NewInt(0), big.NewInt(0)), }, want: "could not apply tx 0 [0xc4ab868fef0c82ae0387b742aee87907f2d0fc528fc6ea0a021459fb0fc4a4a8]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 0, baseFee: 225000000000", }, { // ErrTipVeryHigh txs: []*types.Transaction{ - mkDynamicTx(0, common.Address{}, params.TxGas, tooBigNumber, big.NewInt(1)), + mkDynamicTx(0, common.Address{}, ethparams.TxGas, tooBigNumber, big.NewInt(1)), }, want: "could not apply tx 0 [0x15b8391b9981f266b32f3ab7da564bbeb3d6c21628364ea9b32a21139f89f712]: max priority fee per gas higher than 2^256-1: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxPriorityFeePerGas bit length: 257", }, { // ErrFeeCapVeryHigh txs: []*types.Transaction{ - mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(1), tooBigNumber), + mkDynamicTx(0, common.Address{}, ethparams.TxGas, big.NewInt(1), tooBigNumber), }, want: "could not apply tx 0 [0x48bc299b83fdb345c57478f239e89814bb3063eb4e4b49f3b6057a69255c16bd]: max fee per gas higher than 2^256-1: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas bit length: 257", }, { // ErrTipAboveFeeCap txs: []*types.Transaction{ - mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(2), big.NewInt(1)), + mkDynamicTx(0, common.Address{}, ethparams.TxGas, big.NewInt(2), big.NewInt(1)), }, want: "could not apply tx 0 [0xf987a31ff0c71895780a7612f965a0c8b056deb54e020bb44fa478092f14c9b4]: max priority fee per gas higher than max fee per gas: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxPriorityFeePerGas: 2, maxFeePerGas: 1", }, @@ -215,13 +216,13 @@ func TestStateProcessorErrors(t *testing.T) { // This test is designed to have the effective cost be covered by the balance, but // the extended requirement on FeeCap*gas < balance to fail txs: []*types.Transaction{ - mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(1), big.NewInt(200000000000000)), + mkDynamicTx(0, common.Address{}, ethparams.TxGas, big.NewInt(1), big.NewInt(200000000000000)), }, want: "could not apply tx 0 [0xa3840aa3cad37eec8607b9f4846813d4a80e70b462a793fa21f64138156f849b]: insufficient funds for gas * price + value: address 0x71562b71999873DB5b286dF957af199Ec94617F7 have 4000000000000000000 want 4200000000000000000", }, { // Another ErrInsufficientFunds, this one to ensure that feecap/tip of max u256 is allowed txs: []*types.Transaction{ - mkDynamicTx(0, common.Address{}, params.TxGas, bigNumber, bigNumber), + mkDynamicTx(0, common.Address{}, ethparams.TxGas, bigNumber, bigNumber), }, want: "could not apply tx 0 [0xd82a0c2519acfeac9a948258c47e784acd20651d9d80f9a1c67b4137651c3a24]: insufficient funds for gas * price + value: address 0x71562b71999873DB5b286dF957af199Ec94617F7 required balance exceeds 256 bits", }, @@ -239,7 +240,7 @@ func TestStateProcessorErrors(t *testing.T) { }, { // ErrBlobFeeCapTooLow txs: []*types.Transaction{ - mkBlobTx(0, common.Address{}, params.TxGas, big.NewInt(1), big.NewInt(1), big.NewInt(0), []common.Hash{(common.Hash{1})}), + mkBlobTx(0, common.Address{}, ethparams.TxGas, big.NewInt(1), big.NewInt(1), big.NewInt(0), []common.Hash{(common.Hash{1})}), }, want: "could not apply tx 0 [0x6c11015985ce82db691d7b2d017acda296db88b811c3c60dc71449c76256c716]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 1, baseFee: 225000000000", }, @@ -292,7 +293,7 @@ func TestStateProcessorErrors(t *testing.T) { }{ { // ErrTxTypeNotSupported txs: []*types.Transaction{ - mkDynamicTx(0, common.Address{}, params.TxGas-1000, big.NewInt(0), big.NewInt(0)), + mkDynamicTx(0, common.Address{}, ethparams.TxGas-1000, big.NewInt(0), big.NewInt(0)), }, want: "could not apply tx 0 [0x88626ac0d53cb65308f2416103c62bb1f18b805573d4f96a3640bbbfff13c14f]: transaction type not supported", }, @@ -332,7 +333,7 @@ func TestStateProcessorErrors(t *testing.T) { }{ { // ErrSenderNoEOA txs: []*types.Transaction{ - mkDynamicTx(0, common.Address{}, params.TxGas-1000, big.NewInt(0), big.NewInt(0)), + mkDynamicTx(0, common.Address{}, ethparams.TxGas-1000, big.NewInt(0), big.NewInt(0)), }, want: "could not apply tx 0 [0x88626ac0d53cb65308f2416103c62bb1f18b805573d4f96a3640bbbfff13c14f]: sender not an eoa: address 0x71562b71999873DB5b286dF957af199Ec94617F7, codehash: 0x9280914443471259d4570a8661015ae4a5b80186dbc619658fb494bebc3da3d1", }, @@ -409,7 +410,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr pUsed = *parent.BlobGasUsed() } excess := eip4844.CalcExcessBlobGas(pExcess, pUsed) - used := uint64(nBlobs * params.BlobTxBlobGasPerBlob) + used := uint64(nBlobs * ethparams.BlobTxBlobGasPerBlob) header.ExcessBlobGas = &excess header.BlobGasUsed = &used diff --git a/core/state_transition.go b/core/state_transition.go index e52a61fcb8..91f2a2ba93 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -36,6 +36,7 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/crypto/kzg4844" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/plugin/evm/vmerrors" "github.com/ava-labs/subnet-evm/precompile/contracts/txallowlist" @@ -84,9 +85,9 @@ func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation b // Set the starting gas for the raw transaction var gas uint64 if isContractCreation && rules.IsHomestead { - gas = params.TxGasContractCreation + gas = ethparams.TxGasContractCreation } else { - gas = params.TxGas + gas = ethparams.TxGas } dataLen := uint64(len(data)) // Bump the required gas by the amount of transactional data @@ -99,9 +100,9 @@ func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation b } } // Make sure we don't exceed uint64 for all data combinations - nonZeroGas := params.TxDataNonZeroGasFrontier + nonZeroGas := ethparams.TxDataNonZeroGasFrontier if rules.IsIstanbul { - nonZeroGas = params.TxDataNonZeroGasEIP2028 + nonZeroGas = ethparams.TxDataNonZeroGasEIP2028 } if (math.MaxUint64-gas)/nonZeroGas < nz { return 0, ErrGasUintOverflow @@ -109,17 +110,17 @@ func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation b gas += nz * nonZeroGas z := dataLen - nz - if (math.MaxUint64-gas)/params.TxDataZeroGas < z { + if (math.MaxUint64-gas)/ethparams.TxDataZeroGas < z { return 0, ErrGasUintOverflow } - gas += z * params.TxDataZeroGas + gas += z * ethparams.TxDataZeroGas if isContractCreation && params.GetRulesExtra(rules).IsDurango { lenWords := toWordSize(dataLen) - if (math.MaxUint64-gas)/params.InitCodeWordGas < lenWords { + if (math.MaxUint64-gas)/ethparams.InitCodeWordGas < lenWords { return 0, ErrGasUintOverflow } - gas += lenWords * params.InitCodeWordGas + gas += lenWords * ethparams.InitCodeWordGas } } if accessList != nil { @@ -141,8 +142,8 @@ func accessListGas(rules params.Rules, accessList types.AccessList) (uint64, err var gas uint64 rulesExtra := params.GetRulesExtra(rules) if !rulesExtra.PredicatersExist() { - gas += uint64(len(accessList)) * params.TxAccessListAddressGas - gas += uint64(accessList.StorageKeys()) * params.TxAccessListStorageKeyGas + gas += uint64(len(accessList)) * ethparams.TxAccessListAddressGas + gas += uint64(accessList.StorageKeys()) * ethparams.TxAccessListStorageKeyGas return gas, nil } @@ -154,7 +155,7 @@ func accessListGas(rules params.Rules, accessList types.AccessList) (uint64, err // the size of access lists that could be included in a block and standard access list gas costs. // Therefore, we only check for overflow when adding to [totalGas], which could include the sum of values // returned by a predicate. - accessTupleGas := params.TxAccessListAddressGas + uint64(len(accessTuple.StorageKeys))*params.TxAccessListStorageKeyGas + accessTupleGas := ethparams.TxAccessListAddressGas + uint64(len(accessTuple.StorageKeys))*ethparams.TxAccessListStorageKeyGas totalGas, overflow := cmath.SafeAdd(gas, accessTupleGas) if overflow { return 0, ErrGasUintOverflow @@ -484,8 +485,8 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { } // Check whether the init code size has been exceeded. - if rulesExtra.IsDurango && contractCreation && len(msg.Data) > params.MaxInitCodeSize { - return nil, fmt.Errorf("%w: code size %v limit %v", vm.ErrMaxInitCodeSizeExceeded, len(msg.Data), params.MaxInitCodeSize) + if rulesExtra.IsDurango && contractCreation && len(msg.Data) > ethparams.MaxInitCodeSize { + return nil, fmt.Errorf("%w: code size %v limit %v", vm.ErrMaxInitCodeSizeExceeded, len(msg.Data), ethparams.MaxInitCodeSize) } // Execute the preparatory steps for state transition which includes: @@ -552,5 +553,5 @@ func (st *StateTransition) gasUsed() uint64 { // blobGasUsed returns the amount of blob gas used by the message. func (st *StateTransition) blobGasUsed() uint64 { - return uint64(len(st.msg.BlobHashes) * params.BlobTxBlobGasPerBlob) + return uint64(len(st.msg.BlobHashes) * ethparams.BlobTxBlobGasPerBlob) } diff --git a/core/test_blockchain.go b/core/test_blockchain.go index 663ca4a378..85a6f329bf 100644 --- a/core/test_blockchain.go +++ b/core/test_blockchain.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/ethdb" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/commontype" "github.com/ava-labs/subnet-evm/consensus/dummy" "github.com/ava-labs/subnet-evm/core/state" @@ -217,7 +218,7 @@ func TestInsertChainAcceptSingleBlock(t *testing.T, create func(db ethdb.Databas // This call generates a chain of 3 blocks. signer := types.HomesteadSigner{} _, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, 10, func(i int, gen *BlockGen) { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) }) if err != nil { @@ -289,7 +290,7 @@ func TestInsertLongForkedChain(t *testing.T, create func(db ethdb.Database, gspe signer := types.HomesteadSigner{} _, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(i int, gen *BlockGen) { // Generate a transaction to create a unique block - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) }) if err != nil { @@ -299,7 +300,7 @@ func TestInsertLongForkedChain(t *testing.T, create func(db ethdb.Database, gspe // a longer chain can trigger a reorg. _, chain2, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks+1, 10, func(i int, gen *BlockGen) { // Generate a transaction with a different amount to ensure [chain2] is different than [chain1]. - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(5000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(5000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) }) if err != nil { @@ -453,7 +454,7 @@ func TestAcceptNonCanonicalBlock(t *testing.T, create func(db ethdb.Database, gs signer := types.HomesteadSigner{} _, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(i int, gen *BlockGen) { // Generate a transaction to create a unique block - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) }) if err != nil { @@ -461,7 +462,7 @@ func TestAcceptNonCanonicalBlock(t *testing.T, create func(db ethdb.Database, gs } _, chain2, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(i int, gen *BlockGen) { // Generate a transaction with a different amount to create a chain of blocks different from [chain1] - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(5000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(5000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) }) if err != nil { @@ -562,7 +563,7 @@ func TestSetPreferenceRewind(t *testing.T, create func(db ethdb.Database, gspec signer := types.HomesteadSigner{} _, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(i int, gen *BlockGen) { // Generate a transaction to create a unique block - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) }) if err != nil { @@ -700,10 +701,10 @@ func TestBuildOnVariousStages(t *testing.T, create func(db ethdb.Database, gspec genDB, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 20, 10, func(i int, gen *BlockGen) { // Send all funds back and forth between the two accounts if i%2 == 0 { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, genesisBalance, params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, genesisBalance, ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) } else { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr1, genesisBalance, params.TxGas, nil, nil), signer, key2) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr1, genesisBalance, ethparams.TxGas, nil, nil), signer, key2) gen.AddTx(tx) } }) @@ -714,10 +715,10 @@ func TestBuildOnVariousStages(t *testing.T, create func(db ethdb.Database, gspec chain2, _, err := GenerateChain(gspec.Config, chain1[9], blockchain.engine, genDB, 10, 10, func(i int, gen *BlockGen) { // Send all funds back and forth between the two accounts if i%2 == 0 { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr2, genesisBalance, params.TxGas, nil, nil), signer, key3) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr2, genesisBalance, ethparams.TxGas, nil, nil), signer, key3) gen.AddTx(tx) } else { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr3, genesisBalance, params.TxGas, nil, nil), signer, key2) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr3, genesisBalance, ethparams.TxGas, nil, nil), signer, key2) gen.AddTx(tx) } }) @@ -730,10 +731,10 @@ func TestBuildOnVariousStages(t *testing.T, create func(db ethdb.Database, gspec chain3, _, err := GenerateChain(gspec.Config, chain1[4], blockchain.engine, genDB, 10, 10, func(i int, gen *BlockGen) { // Send all funds back and forth between accounts 2 and 3. if i%2 == 0 { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr3, genesisBalance, params.TxGas, nil, nil), signer, key2) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr3, genesisBalance, ethparams.TxGas, nil, nil), signer, key2) gen.AddTx(tx) } else { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr2, genesisBalance, params.TxGas, nil, nil), signer, key3) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr2, genesisBalance, ethparams.TxGas, nil, nil), signer, key3) gen.AddTx(tx) } }) @@ -899,7 +900,7 @@ func TestReorgReInsert(t *testing.T, create func(db ethdb.Database, gspec *Genes numBlocks := 3 _, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(i int, gen *BlockGen) { // Generate a transaction to create a unique block - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) }) if err != nil { @@ -1005,7 +1006,7 @@ func TestAcceptBlockIdenticalStateRoot(t *testing.T, create func(db ethdb.Databa _, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, 10, func(i int, gen *BlockGen) { if i < 2 { // Send half the funds from addr1 to addr2 in one transaction per each of the two blocks in [chain1] - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(500000000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(500000000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) } // Allow the third block to be empty. @@ -1017,10 +1018,10 @@ func TestAcceptBlockIdenticalStateRoot(t *testing.T, create func(db ethdb.Databa // Send 1/4 of the funds from addr1 to addr2 in tx1 and 3/4 of the funds in tx2. This will produce the identical state // root in the second block of [chain2] as is present in the second block of [chain1]. if i == 0 { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(250000000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(250000000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) } else { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(750000000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(750000000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) } }) @@ -1148,7 +1149,7 @@ func TestReprocessAcceptBlockIdenticalStateRoot(t *testing.T, create func(db eth _, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, 10, func(i int, gen *BlockGen) { if i < 2 { // Send half the funds from addr1 to addr2 in one transaction per each of the two blocks in [chain1] - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(500000000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(500000000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) } // Allow the third block to be empty. @@ -1160,10 +1161,10 @@ func TestReprocessAcceptBlockIdenticalStateRoot(t *testing.T, create func(db eth // Send 1/4 of the funds from addr1 to addr2 in tx1 and 3/4 of the funds in tx2. This will produce the identical state // root in the second block of [chain2] as is present in the second block of [chain1]. if i == 0 { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(250000000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(250000000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) } else { - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(750000000), params.TxGas, nil, nil), signer, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(750000000), ethparams.TxGas, nil, nil), signer, key1) gen.AddTx(tx) } }) @@ -1305,7 +1306,7 @@ func TestGenerateChainInvalidBlockFee(t *testing.T, create func(db ethdb.Databas ChainID: params.TestChainConfig.ChainID, Nonce: gen.TxNonce(addr1), To: &addr2, - Gas: params.TxGas, + Gas: ethparams.TxGas, GasFeeCap: gen.BaseFee(), GasTipCap: big.NewInt(0), Data: []byte{}, @@ -1347,7 +1348,7 @@ func TestInsertChainInvalidBlockFee(t *testing.T, create func(db ethdb.Database, ChainID: params.TestChainConfig.ChainID, Nonce: gen.TxNonce(addr1), To: &addr2, - Gas: params.TxGas, + Gas: ethparams.TxGas, GasFeeCap: gen.BaseFee(), GasTipCap: big.NewInt(0), Data: []byte{}, @@ -1393,7 +1394,7 @@ func TestInsertChainValidBlockFee(t *testing.T, create func(db ethdb.Database, g ChainID: params.TestChainConfig.ChainID, Nonce: gen.TxNonce(addr1), To: &addr2, - Gas: params.TxGas, + Gas: ethparams.TxGas, Value: transfer, GasFeeCap: feeCap, GasTipCap: tip, @@ -1423,7 +1424,7 @@ func TestInsertChainValidBlockFee(t *testing.T, create func(db ethdb.Database, g genesisBalance := uint256.MustFromBig(genesisBalance) expectedBalance1 := new(uint256.Int).Sub(genesisBalance, transfer) baseFee := params.DefaultFeeConfig.MinBaseFee - feeSpend := new(big.Int).Mul(new(big.Int).Add(baseFee, tip), new(big.Int).SetUint64(params.TxGas)) + feeSpend := new(big.Int).Mul(new(big.Int).Add(baseFee, tip), new(big.Int).SetUint64(ethparams.TxGas)) expectedBalance1.Sub(expectedBalance1, uint256.MustFromBig(feeSpend)) if balance1.Cmp(expectedBalance1) != 0 { return fmt.Errorf("expected addr1 balance: %d, found balance: %d", expectedBalance1, balance1) diff --git a/core/txindexer_test.go b/core/txindexer_test.go index 8d34e59ca8..65a9684dbd 100644 --- a/core/txindexer_test.go +++ b/core/txindexer_test.go @@ -26,6 +26,7 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/ethdb" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/consensus/dummy" "github.com/ava-labs/subnet-evm/params" "github.com/stretchr/testify/require" @@ -49,14 +50,14 @@ func TestTransactionIndices(t *testing.T) { signer = types.LatestSigner(gspec.Config) ) genDb, blocks, _, err := GenerateChainWithGenesis(gspec, dummy.NewFaker(), 128, 10, func(i int, block *BlockGen) { - tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) require.NoError(err) block.AddTx(tx) }) require.NoError(err) blocks2, _, err := GenerateChain(gspec.Config, blocks[len(blocks)-1], dummy.NewFaker(), genDb, 10, 10, func(i int, block *BlockGen) { - tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) require.NoError(err) block.AddTx(tx) }) @@ -160,14 +161,14 @@ func TestTransactionSkipIndexing(t *testing.T) { signer = types.LatestSigner(gspec.Config) ) genDb, blocks, _, err := GenerateChainWithGenesis(gspec, dummy.NewCoinbaseFaker(), 5, 10, func(i int, block *BlockGen) { - tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) require.NoError(err) block.AddTx(tx) }) require.NoError(err) blocks2, _, err := GenerateChain(gspec.Config, blocks[len(blocks)-1], dummy.NewCoinbaseFaker(), genDb, 5, 10, func(i int, block *BlockGen) { - tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1) + tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1) require.NoError(err) block.AddTx(tx) }) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index d9ce1ec5f0..9d72a835db 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -44,6 +44,7 @@ import ( "github.com/ava-labs/libevm/event" "github.com/ava-labs/libevm/log" "github.com/ava-labs/libevm/metrics" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/rlp" "github.com/ava-labs/subnet-evm/consensus/misc/eip4844" "github.com/ava-labs/subnet-evm/core" @@ -58,12 +59,12 @@ import ( const ( // blobSize is the protocol constrained byte size of a single blob in a // transaction. There can be multiple of these embedded into a single tx. - blobSize = params.BlobTxFieldElementsPerBlob * params.BlobTxBytesPerFieldElement + blobSize = ethparams.BlobTxFieldElementsPerBlob * ethparams.BlobTxBytesPerFieldElement // maxBlobsPerTransaction is the maximum number of blobs a single transaction // is allowed to contain. Whilst the spec states it's unlimited, the block // data slots are protocol bound, which implicitly also limit this. - maxBlobsPerTransaction = params.MaxBlobGasPerBlock / params.BlobTxBlobGasPerBlob + maxBlobsPerTransaction = ethparams.MaxBlobGasPerBlock / ethparams.BlobTxBlobGasPerBlob // txAvgSize is an approximate byte size of a transaction metadata to avoid // tiny overflows causing all txs to move a shelf higher, wasting disk space. @@ -428,7 +429,7 @@ func (p *BlobPool) Init(gasTip uint64, head *types.Header, reserve txpool.Addres var ( // basefee = uint256.MustFromBig(eip1559.CalcBaseFee(p.chain.Config(), p.head)) basefee = uint256.MustFromBig(baseFee) - blobfee = uint256.NewInt(params.BlobTxMinBlobGasprice) + blobfee = uint256.NewInt(ethparams.BlobTxMinBlobGasprice) ) if p.head.ExcessBlobGas != nil { blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*p.head.ExcessBlobGas)) @@ -865,7 +866,7 @@ func (p *BlobPool) Reset(oldHead, newHead *types.Header) { var ( // basefee = uint256.MustFromBig(eip1559.CalcBaseFee(p.chain.Config(), newHead)) basefee = uint256.MustFromBig(baseFeeBig) - blobfee = uint256.MustFromBig(big.NewInt(params.BlobTxMinBlobGasprice)) + blobfee = uint256.MustFromBig(big.NewInt(ethparams.BlobTxMinBlobGasprice)) ) if newHead.ExcessBlobGas != nil { blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*newHead.ExcessBlobGas)) diff --git a/core/txpool/blobpool/blobpool_test.go b/core/txpool/blobpool/blobpool_test.go index a583a317c2..fa84261145 100644 --- a/core/txpool/blobpool/blobpool_test.go +++ b/core/txpool/blobpool/blobpool_test.go @@ -46,6 +46,7 @@ import ( "github.com/ava-labs/libevm/crypto/kzg4844" "github.com/ava-labs/libevm/ethdb/memorydb" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/rlp" "github.com/ava-labs/subnet-evm/commontype" "github.com/ava-labs/subnet-evm/consensus/misc/eip4844" @@ -591,7 +592,7 @@ func TestOpenDrops(t *testing.T) { chain := &testBlockChain{ config: testChainConfig, basefee: uint256.NewInt(uint64(legacy.BaseFee)), - blobfee: uint256.NewInt(params.BlobTxMinBlobGasprice), + blobfee: uint256.NewInt(ethparams.BlobTxMinBlobGasprice), statedb: statedb, } pool := New(Config{Datadir: storage}, chain) @@ -710,7 +711,7 @@ func TestOpenIndex(t *testing.T) { chain := &testBlockChain{ config: testChainConfig, basefee: uint256.NewInt(uint64(legacy.BaseFee)), - blobfee: uint256.NewInt(params.BlobTxMinBlobGasprice), + blobfee: uint256.NewInt(ethparams.BlobTxMinBlobGasprice), statedb: statedb, } pool := New(Config{Datadir: storage}, chain) @@ -1269,7 +1270,7 @@ func TestAdd(t *testing.T) { }, { // Same as above but blob fee cap equals minimum, should be accepted from: "alice", - tx: makeUnsignedTx(0, 1, 1, params.BlobTxMinBlobGasprice), + tx: makeUnsignedTx(0, 1, 1, ethparams.BlobTxMinBlobGasprice), err: nil, }, }, @@ -1344,7 +1345,7 @@ func BenchmarkPoolPending10GB(b *testing.B) { benchmarkPoolPending(b, 10_000_00 func benchmarkPoolPending(b *testing.B, datacap uint64) { // Calculate the maximum number of transaction that would fit into the pool // and generate a set of random accounts to seed them with. - capacity := datacap / params.BlobTxBlobGasPerBlob + capacity := datacap / ethparams.BlobTxBlobGasPerBlob var ( basefee = uint64(1050) diff --git a/core/txpool/blobpool/evictheap_test.go b/core/txpool/blobpool/evictheap_test.go index 9b7c0680bf..618b1ccc49 100644 --- a/core/txpool/blobpool/evictheap_test.go +++ b/core/txpool/blobpool/evictheap_test.go @@ -32,7 +32,7 @@ import ( "testing" "github.com/ava-labs/libevm/common" - "github.com/ava-labs/subnet-evm/params" + ethparams "github.com/ava-labs/libevm/params" "github.com/holiman/uint256" ) @@ -196,7 +196,7 @@ func BenchmarkPriceHeapReinit100GB(b *testing.B) { benchmarkPriceHeapReinit(b, 1 func benchmarkPriceHeapReinit(b *testing.B, datacap uint64) { // Calculate how many unique transactions we can fit into the provided disk // data cap - blobs := datacap / (params.BlobTxBytesPerFieldElement * params.BlobTxFieldElementsPerBlob) + blobs := datacap / (ethparams.BlobTxBytesPerFieldElement * ethparams.BlobTxFieldElementsPerBlob) // Create a random set of transactions with random fees. Use a separate account // for each transaction to make it worse case. @@ -256,7 +256,7 @@ func BenchmarkPriceHeapOverflow100GB(b *testing.B) { benchmarkPriceHeapOverflow( func benchmarkPriceHeapOverflow(b *testing.B, datacap uint64) { // Calculate how many unique transactions we can fit into the provided disk // data cap - blobs := datacap / (params.BlobTxBytesPerFieldElement * params.BlobTxFieldElementsPerBlob) + blobs := datacap / (ethparams.BlobTxBytesPerFieldElement * ethparams.BlobTxFieldElementsPerBlob) // Create a random set of transactions with random fees. Use a separate account // for each transaction to make it worse case. diff --git a/core/txpool/validation.go b/core/txpool/validation.go index 813eff1981..48e977238b 100644 --- a/core/txpool/validation.go +++ b/core/txpool/validation.go @@ -36,6 +36,7 @@ import ( "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/crypto/kzg4844" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/core" "github.com/ava-labs/subnet-evm/core/state" "github.com/ava-labs/subnet-evm/params" @@ -46,7 +47,7 @@ import ( var ( // blobTxMinBlobGasPrice is the big.Int version of the configured protocol // parameter to avoid constucting a new big integer for every transaction. - blobTxMinBlobGasPrice = big.NewInt(params.BlobTxMinBlobGasprice) + blobTxMinBlobGasPrice = big.NewInt(ethparams.BlobTxMinBlobGasprice) ) // ValidationOptions define certain differences between transaction validation @@ -86,8 +87,8 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types return fmt.Errorf("%w: type %d rejected, pool not yet in Cancun", core.ErrTxTypeNotSupported, tx.Type()) } // Check whether the init code size has been exceeded - if opts.Config.IsShanghai(head.Number, head.Time) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize { - return fmt.Errorf("%w: code size %v, limit %v", vm.ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize) + if opts.Config.IsShanghai(head.Number, head.Time) && tx.To() == nil && len(tx.Data()) > ethparams.MaxInitCodeSize { + return fmt.Errorf("%w: code size %v, limit %v", vm.ErrMaxInitCodeSizeExceeded, len(tx.Data()), ethparams.MaxInitCodeSize) } // Transactions can't be negative. This may never happen using RLP decoded // transactions but may occur for transactions created using the RPC. @@ -147,8 +148,8 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types if len(hashes) == 0 { return fmt.Errorf("blobless blob transaction") } - if len(hashes) > params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob { - return fmt.Errorf("too many blobs in transaction: have %d, permitted %d", len(hashes), params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob) + if len(hashes) > ethparams.MaxBlobGasPerBlock/ethparams.BlobTxBlobGasPerBlob { + return fmt.Errorf("too many blobs in transaction: have %d, permitted %d", len(hashes), ethparams.MaxBlobGasPerBlock/ethparams.BlobTxBlobGasPerBlob) } // Ensure commitments, proofs and hashes are valid if err := validateBlobSidecar(hashes, sidecar); err != nil { diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 7a5c5e14b2..c1c376a172 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -35,6 +35,7 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/crypto" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/core/state" "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/params/extras" @@ -116,7 +117,7 @@ func setDefaults(cfg *Config) { cfg.BaseFee = big.NewInt(legacy.BaseFee) } if cfg.BlobBaseFee == nil { - cfg.BlobBaseFee = big.NewInt(params.BlobTxMinBlobGasprice) + cfg.BlobBaseFee = big.NewInt(ethparams.BlobTxMinBlobGasprice) } } diff --git a/eth/gasestimator/gasestimator.go b/eth/gasestimator/gasestimator.go index ecb009a8da..63f4362c75 100644 --- a/eth/gasestimator/gasestimator.go +++ b/eth/gasestimator/gasestimator.go @@ -37,6 +37,7 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/core" "github.com/ava-labs/subnet-evm/core/state" "github.com/ava-labs/subnet-evm/params" @@ -67,7 +68,7 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin ) // Determine the highest gas limit can be used during the estimation. hi = opts.Header.GasLimit - if call.GasLimit >= params.TxGas { + if call.GasLimit >= ethparams.TxGas { hi = call.GasLimit } // Normalize the max fee per gas the call is willing to spend. @@ -114,9 +115,9 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin // unused access list items). Ever so slightly wasteful, but safer overall. if len(call.Data) == 0 { if call.To != nil && opts.State.GetCodeSize(*call.To) == 0 { - failed, _, err := execute(ctx, call, opts, params.TxGas) + failed, _, err := execute(ctx, call, opts, ethparams.TxGas) if !failed && err == nil { - return params.TxGas, nil, nil + return ethparams.TxGas, nil, nil } } } @@ -142,7 +143,7 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin // There's a fairly high chance for the transaction to execute successfully // with gasLimit set to the first execution's usedGas + gasRefund. Explicitly // check that gas amount and use as a limit for the binary search. - optimisticGasLimit := (result.UsedGas + result.RefundedGas + params.CallStipend) * 64 / 63 + optimisticGasLimit := (result.UsedGas + result.RefundedGas + ethparams.CallStipend) * 64 / 63 if optimisticGasLimit < hi { failed, _, err = execute(ctx, call, opts, optimisticGasLimit) if err != nil { diff --git a/eth/gasprice/feehistory_test.go b/eth/gasprice/feehistory_test.go index 9041b0bcaf..48887ad1c0 100644 --- a/eth/gasprice/feehistory_test.go +++ b/eth/gasprice/feehistory_test.go @@ -33,6 +33,7 @@ import ( "testing" "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/core" "github.com/stretchr/testify/require" @@ -94,7 +95,7 @@ func TestFeeHistory(t *testing.T) { ChainID: params.TestChainConfig.ChainID, Nonce: b.TxNonce(addr), To: &common.Address{}, - Gas: params.TxGas, + Gas: ethparams.TxGas, GasFeeCap: feeCap, GasTipCap: tip, Data: []byte{}, diff --git a/eth/gasprice/gasprice_test.go b/eth/gasprice/gasprice_test.go index dd12719853..5fb07fbb05 100644 --- a/eth/gasprice/gasprice_test.go +++ b/eth/gasprice/gasprice_test.go @@ -38,6 +38,7 @@ import ( "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/event" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/commontype" "github.com/ava-labs/subnet-evm/consensus/dummy" "github.com/ava-labs/subnet-evm/core" @@ -234,7 +235,7 @@ func testGenBlock(t *testing.T, tip int64, numTx int) func(int, *core.BlockGen) ChainID: params.TestChainConfig.ChainID, Nonce: b.TxNonce(addr), To: &common.Address{}, - Gas: params.TxGas, + Gas: ethparams.TxGas, GasFeeCap: feeCap, GasTipCap: txTip, Data: []byte{}, @@ -295,7 +296,7 @@ func TestSuggestTipCapSmallTips(t *testing.T) { ChainID: params.TestChainConfig.ChainID, Nonce: b.TxNonce(addr), To: &common.Address{}, - Gas: params.TxGas, + Gas: ethparams.TxGas, GasFeeCap: feeCap, GasTipCap: tip, Data: []byte{}, @@ -309,7 +310,7 @@ func TestSuggestTipCapSmallTips(t *testing.T) { ChainID: params.TestChainConfig.ChainID, Nonce: b.TxNonce(addr), To: &common.Address{}, - Gas: params.TxGas, + Gas: ethparams.TxGas, GasFeeCap: feeCap, GasTipCap: common.Big1, Data: []byte{}, @@ -350,7 +351,7 @@ func TestSuggestGasPriceSubnetEVM(t *testing.T) { tx := types.NewTx(&types.LegacyTx{ Nonce: b.TxNonce(addr), To: &common.Address{}, - Gas: params.TxGas, + Gas: ethparams.TxGas, GasPrice: gasPrice, Data: []byte{}, }) diff --git a/eth/tracers/api_extra_test.go b/eth/tracers/api_extra_test.go index ffd29c7e8f..7023896c32 100644 --- a/eth/tracers/api_extra_test.go +++ b/eth/tracers/api_extra_test.go @@ -17,6 +17,7 @@ import ( "github.com/ava-labs/libevm/common/math" "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/eth/tracers/logger" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/core" "github.com/ava-labs/subnet-evm/internal/ethapi" "github.com/ava-labs/subnet-evm/params" @@ -64,7 +65,7 @@ func TestTraceBlockPrecompileActivation(t *testing.T) { // Transfer from account[0] to account[1] // value: 1000 wei // fee: 0 wei - tx, _ := types.SignTx(types.NewTransaction(uint64(i), accounts[1].addr, big.NewInt(1000), params.TxGas, b.BaseFee(), nil), signer, accounts[0].key) + tx, _ := types.SignTx(types.NewTransaction(uint64(i), accounts[1].addr, big.NewInt(1000), ethparams.TxGas, b.BaseFee(), nil), signer, accounts[0].key) b.AddTx(tx) txHashes[i] = tx.Hash() }) @@ -170,7 +171,7 @@ func TestTraceTransactionPrecompileActivation(t *testing.T) { // Transfer from account[0] to account[1] // value: 1000 wei // fee: 0 wei - tx, _ := types.SignTx(types.NewTransaction(uint64(i), accounts[1].addr, big.NewInt(1000), params.TxGas, new(big.Int).Add(b.BaseFee(), big.NewInt(int64(500*params.GWei))), nil), signer, accounts[0].key) + tx, _ := types.SignTx(types.NewTransaction(uint64(i), accounts[1].addr, big.NewInt(1000), ethparams.TxGas, new(big.Int).Add(b.BaseFee(), big.NewInt(int64(500*params.GWei))), nil), signer, accounts[0].key) b.AddTx(tx) blockNoTxMap[uint64(i)] = tx.Hash() }) @@ -186,7 +187,7 @@ func TestTraceTransactionPrecompileActivation(t *testing.T) { err = json.Unmarshal(result.(json.RawMessage), &have) require.NoError(err) expected := &logger.ExecutionResult{ - Gas: params.TxGas, + Gas: ethparams.TxGas, Failed: false, ReturnValue: "", StructLogs: []logger.StructLogRes{}, @@ -240,7 +241,7 @@ func TestTraceChainPrecompileActivation(t *testing.T) { // value: 1000 wei // fee: 0 wei for j := 0; j < i+1; j++ { - tx, _ := types.SignTx(types.NewTransaction(nonce, accounts[1].addr, big.NewInt(1000), params.TxGas, b.BaseFee(), nil), signer, accounts[0].key) + tx, _ := types.SignTx(types.NewTransaction(nonce, accounts[1].addr, big.NewInt(1000), ethparams.TxGas, b.BaseFee(), nil), signer, accounts[0].key) b.AddTx(tx) nonce += 1 } @@ -331,7 +332,7 @@ func TestTraceCallWithOverridesStateUpgrade(t *testing.T) { // Transfer from account[0] to account[1] // value: 1000 wei // fee: 0 wei - tx, _ := types.SignTx(types.NewTransaction(uint64(i), accounts[1].addr, big.NewInt(1000), params.TxGas, b.BaseFee(), nil), signer, accounts[0].key) + tx, _ := types.SignTx(types.NewTransaction(uint64(i), accounts[1].addr, big.NewInt(1000), ethparams.TxGas, b.BaseFee(), nil), signer, accounts[0].key) b.AddTx(tx) }) defer backend.teardown() diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go index d5bb0b7d0d..0671d54583 100644 --- a/eth/tracers/api_test.go +++ b/eth/tracers/api_test.go @@ -45,6 +45,7 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/eth/tracers/logger" "github.com/ava-labs/libevm/ethdb" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/consensus" "github.com/ava-labs/subnet-evm/consensus/dummy" "github.com/ava-labs/subnet-evm/core" @@ -245,7 +246,7 @@ func TestTraceCall(t *testing.T) { Nonce: nonce, To: &accounts[1].addr, Value: big.NewInt(1000), - Gas: params.TxGas, + Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key) @@ -258,7 +259,7 @@ func TestTraceCall(t *testing.T) { Nonce: nonce, To: &accounts[2].addr, Value: big.NewInt(1000), - Gas: params.TxGas, + Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key) @@ -270,7 +271,7 @@ func TestTraceCall(t *testing.T) { Nonce: nonce, To: &accounts[1].addr, Value: big.NewInt(1000), - Gas: params.TxGas, + Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key) @@ -461,7 +462,7 @@ func TestTraceTransaction(t *testing.T) { Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), - Gas: params.TxGas, + Gas: ethparams.TxGas, GasPrice: new(big.Int).Add(b.BaseFee(), big.NewInt(int64(500*params.GWei))), Data: nil}), signer, accounts[0].key) @@ -479,7 +480,7 @@ func TestTraceTransaction(t *testing.T) { t.Errorf("failed to unmarshal result %v", err) } expected := &logger.ExecutionResult{ - Gas: params.TxGas, + Gas: ethparams.TxGas, Failed: false, ReturnValue: "", StructLogs: []logger.StructLogRes{}, @@ -519,7 +520,7 @@ func TestTraceBlock(t *testing.T) { Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), - Gas: params.TxGas, + Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key) @@ -616,7 +617,7 @@ func TestTracingWithOverrides(t *testing.T) { Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), - Gas: params.TxGas, + Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key) @@ -981,7 +982,7 @@ func TestTraceChain(t *testing.T) { // value: 1000 wei // fee: 0 wei for j := 0; j < i+1; j++ { - tx, _ := types.SignTx(types.NewTransaction(nonce, accounts[1].addr, big.NewInt(1000), params.TxGas, b.BaseFee(), nil), signer, accounts[0].key) + tx, _ := types.SignTx(types.NewTransaction(nonce, accounts[1].addr, big.NewInt(1000), ethparams.TxGas, b.BaseFee(), nil), signer, accounts[0].key) b.AddTx(tx) nonce += 1 } diff --git a/ethclient/simulated/backend_test.go b/ethclient/simulated/backend_test.go index df1e25a147..7c45b75a22 100644 --- a/ethclient/simulated/backend_test.go +++ b/ethclient/simulated/backend_test.go @@ -27,6 +27,7 @@ import ( "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/crypto" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/accounts/abi/bind" "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/rpc" @@ -266,7 +267,7 @@ func TestCommitReturnValue(t *testing.T) { // Create a block in the original chain (containing a transaction to force different block hashes) head, _ := client.HeaderByNumber(ctx, nil) // Should be child's, good enough gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1)) - _tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil) + _tx := types.NewTransaction(0, testAddr, big.NewInt(1000), ethparams.TxGas, gasPrice, nil) tx, _ := types.SignTx(_tx, types.LatestSignerForChainID(chainid), testKey) if err := client.SendTransaction(ctx, tx); err != nil { t.Fatalf("sending transaction: %v", err) diff --git a/ethclient/simulated/options_test.go b/ethclient/simulated/options_test.go index 9bc16c23bf..82c46d9234 100644 --- a/ethclient/simulated/options_test.go +++ b/ethclient/simulated/options_test.go @@ -24,8 +24,8 @@ import ( ethereum "github.com/ava-labs/libevm" "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/core" - "github.com/ava-labs/subnet-evm/params" ) // Tests that the simulator starts with the initial gas limit in the genesis block, @@ -59,7 +59,7 @@ func TestWithCallGasLimitOption(t *testing.T) { // Construct a simulator, targeting a different gas limit sim := NewBackend(types.GenesisAlloc{ testAddr: {Balance: big.NewInt(10000000000000000)}, - }, WithCallGasLimit(params.TxGas-1)) + }, WithCallGasLimit(ethparams.TxGas-1)) defer sim.Close() client := sim.Client() diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 0449b9301f..e09e88afc6 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -53,6 +53,7 @@ import ( "github.com/ava-labs/libevm/crypto/kzg4844" "github.com/ava-labs/libevm/ethdb" "github.com/ava-labs/libevm/event" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/commontype" "github.com/ava-labs/subnet-evm/consensus" "github.com/ava-labs/subnet-evm/consensus/dummy" @@ -658,7 +659,7 @@ func TestEstimateGas(t *testing.T) { // Transfer from account[0] to account[1] // value: 1000 wei // fee: 0 wei - tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), Gas: params.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key) + tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key) b.AddTx(tx) // b.SetPoS() })) @@ -819,7 +820,7 @@ func TestCall(t *testing.T) { // Transfer from account[0] to account[1] // value: 1000 wei // fee: 0 wei - tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), Gas: params.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key) + tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key) b.AddTx(tx) // b.SetPoS() })) @@ -1578,7 +1579,7 @@ func TestRPCGetBlockOrHeader(t *testing.T) { // Transfer from account[0] to account[1] // value: 1000 wei // fee: 0 wei - tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &acc2Addr, Value: big.NewInt(1000), Gas: params.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, acc1Key) + tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &acc2Addr, Value: big.NewInt(1000), Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, acc1Key) b.AddTx(tx) }) api := NewBlockChainAPI(backend) @@ -1837,7 +1838,7 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha switch i { case 0: // transfer 1000wei - tx, err = types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &acc2Addr, Value: big.NewInt(1000), Gas: params.TxGas, GasPrice: b.BaseFee(), Data: nil}), types.HomesteadSigner{}, acc1Key) + tx, err = types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &acc2Addr, Value: big.NewInt(1000), Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), types.HomesteadSigner{}, acc1Key) case 1: // create contract tx, err = types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: nil, Gas: 53100, GasPrice: b.BaseFee(), Data: common.FromHex("0x60806040")}), signer, acc1Key) @@ -1868,7 +1869,7 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha Nonce: uint64(i), GasTipCap: uint256.NewInt(1), GasFeeCap: uint256.MustFromBig(fee), - Gas: params.TxGas, + Gas: ethparams.TxGas, To: acc2Addr, BlobFeeCap: uint256.NewInt(1), BlobHashes: []common.Hash{{1}}, diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index f71a2662a5..6635efd20e 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -40,6 +40,7 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/crypto/kzg4844" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/consensus/misc/eip4844" "github.com/ava-labs/subnet-evm/core" "github.com/ava-labs/subnet-evm/params" @@ -48,7 +49,7 @@ import ( ) var ( - maxBlobsPerTransaction = params.MaxBlobGasPerBlock / params.BlobTxBlobGasPerBlob + maxBlobsPerTransaction = ethparams.MaxBlobGasPerBlock / ethparams.BlobTxBlobGasPerBlob ) // TransactionArgs represents the arguments to construct a new transaction diff --git a/miner/worker.go b/miner/worker.go index 2b389597a2..ece207bc41 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -43,6 +43,7 @@ import ( "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/event" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/commontype" "github.com/ava-labs/subnet-evm/consensus" "github.com/ava-labs/subnet-evm/consensus/misc/eip4844" @@ -324,7 +325,7 @@ func (w *worker) commitBlobTransaction(env *environment, tx *types.Transaction, // isn't really a better place right now. The blob gas limit is checked at block validation time // and not during execution. This means core.ApplyTransaction will not return an error if the // tx has too many blobs. So we have to explicitly check it here. - if (env.blobs+len(sc.Blobs))*params.BlobTxBlobGasPerBlob > params.MaxBlobGasPerBlock { + if (env.blobs+len(sc.Blobs))*ethparams.BlobTxBlobGasPerBlob > ethparams.MaxBlobGasPerBlock { return nil, errors.New("max data blobs reached") } receipt, err := w.applyTransaction(env, tx, coinbase) @@ -376,20 +377,20 @@ func (w *worker) applyTransaction(env *environment, tx *types.Transaction, coinb func (w *worker) commitTransactions(env *environment, plainTxs, blobTxs *transactionsByPriceAndNonce, coinbase common.Address) { for { // If we don't have enough gas for any further transactions then we're done. - if env.gasPool.Gas() < params.TxGas { - log.Trace("Not enough gas for further transactions", "have", env.gasPool, "want", params.TxGas) + if env.gasPool.Gas() < ethparams.TxGas { + log.Trace("Not enough gas for further transactions", "have", env.gasPool, "want", ethparams.TxGas) break } // If we don't have enough blob space for any further blob transactions, // skip that list altogether - if !blobTxs.Empty() && env.blobs*params.BlobTxBlobGasPerBlob >= params.MaxBlobGasPerBlock { + if !blobTxs.Empty() && env.blobs*ethparams.BlobTxBlobGasPerBlob >= ethparams.MaxBlobGasPerBlock { log.Trace("Not enough blob space for further blob transactions") blobTxs.Clear() // Fall though to pick up any plain txs } // If we don't have enough blob space for any further blob transactions, // skip that list altogether - if !blobTxs.Empty() && env.blobs*params.BlobTxBlobGasPerBlob >= params.MaxBlobGasPerBlock { + if !blobTxs.Empty() && env.blobs*ethparams.BlobTxBlobGasPerBlob >= ethparams.MaxBlobGasPerBlock { log.Trace("Not enough blob space for further blob transactions") blobTxs.Clear() // Fall though to pick up any plain txs @@ -423,7 +424,7 @@ func (w *worker) commitTransactions(env *environment, plainTxs, blobTxs *transac txs.Pop() continue } - if left := uint64(params.MaxBlobGasPerBlock - env.blobs*params.BlobTxBlobGasPerBlob); left < ltx.BlobGas { + if left := uint64(ethparams.MaxBlobGasPerBlock - env.blobs*ethparams.BlobTxBlobGasPerBlob); left < ltx.BlobGas { log.Trace("Not enough blob gas left for transaction", "hash", ltx.Hash, "left", left, "needed", ltx.BlobGas) txs.Pop() continue diff --git a/params/config_test.go b/params/config_test.go index 574a2524a4..7174fb300e 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -41,6 +41,7 @@ import ( "github.com/ava-labs/subnet-evm/precompile/contracts/rewardmanager" "github.com/ava-labs/subnet-evm/precompile/contracts/txallowlist" "github.com/ava-labs/subnet-evm/utils" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -340,3 +341,125 @@ func TestChainConfigMarshalWithUpgrades(t *testing.T) { require.NoError(t, err) require.Equal(t, config, unmarshalled) } + +// TestUpstreamParamsValues detects when a params value changes upstream to prevent a subtle change +// to one of the values to have an unpredicted impact in the libevm consumer. +// Values should be updated to newer upstream values once the consumer is updated to handle the +// updated value(s). +func TestUpstreamParamsValues(t *testing.T) { + assert.Equal(t, uint64(1024), ethparams.GasLimitBoundDivisor, "GasLimitBoundDivisor") + assert.Equal(t, uint64(5000), ethparams.MinGasLimit, "MinGasLimit") + assert.Equal(t, uint64(0x7fffffffffffffff), ethparams.MaxGasLimit, "MaxGasLimit") + assert.Equal(t, uint64(4712388), ethparams.GenesisGasLimit, "GenesisGasLimit") + assert.Equal(t, uint64(32), ethparams.MaximumExtraDataSize, "MaximumExtraDataSize") + assert.Equal(t, uint64(10), ethparams.ExpByteGas, "ExpByteGas") + assert.Equal(t, uint64(50), ethparams.SloadGas, "SloadGas") + assert.Equal(t, uint64(9000), ethparams.CallValueTransferGas, "CallValueTransferGas") + assert.Equal(t, uint64(25000), ethparams.CallNewAccountGas, "CallNewAccountGas") + assert.Equal(t, uint64(21000), ethparams.TxGas, "TxGas") + assert.Equal(t, uint64(53000), ethparams.TxGasContractCreation, "TxGasContractCreation") + assert.Equal(t, uint64(4), ethparams.TxDataZeroGas, "TxDataZeroGas") + assert.Equal(t, uint64(512), ethparams.QuadCoeffDiv, "QuadCoeffDiv") + assert.Equal(t, uint64(8), ethparams.LogDataGas, "LogDataGas") + assert.Equal(t, uint64(2300), ethparams.CallStipend, "CallStipend") + assert.Equal(t, uint64(30), ethparams.Keccak256Gas, "Keccak256Gas") + assert.Equal(t, uint64(6), ethparams.Keccak256WordGas, "Keccak256WordGas") + assert.Equal(t, uint64(2), ethparams.InitCodeWordGas, "InitCodeWordGas") + assert.Equal(t, uint64(20000), ethparams.SstoreSetGas, "SstoreSetGas") + assert.Equal(t, uint64(5000), ethparams.SstoreResetGas, "SstoreResetGas") + assert.Equal(t, uint64(5000), ethparams.SstoreClearGas, "SstoreClearGas") + assert.Equal(t, uint64(15000), ethparams.SstoreRefundGas, "SstoreRefundGas") + assert.Equal(t, uint64(200), ethparams.NetSstoreNoopGas, "NetSstoreNoopGas") + assert.Equal(t, uint64(20000), ethparams.NetSstoreInitGas, "NetSstoreInitGas") + assert.Equal(t, uint64(5000), ethparams.NetSstoreCleanGas, "NetSstoreCleanGas") + assert.Equal(t, uint64(200), ethparams.NetSstoreDirtyGas, "NetSstoreDirtyGas") + assert.Equal(t, uint64(15000), ethparams.NetSstoreClearRefund, "NetSstoreClearRefund") + assert.Equal(t, uint64(4800), ethparams.NetSstoreResetRefund, "NetSstoreResetRefund") + assert.Equal(t, uint64(19800), ethparams.NetSstoreResetClearRefund, "NetSstoreResetClearRefund") + assert.Equal(t, uint64(2300), ethparams.SstoreSentryGasEIP2200, "SstoreSentryGasEIP2200") + assert.Equal(t, uint64(20000), ethparams.SstoreSetGasEIP2200, "SstoreSetGasEIP2200") + assert.Equal(t, uint64(5000), ethparams.SstoreResetGasEIP2200, "SstoreResetGasEIP2200") + assert.Equal(t, uint64(15000), ethparams.SstoreClearsScheduleRefundEIP2200, "SstoreClearsScheduleRefundEIP2200") + assert.Equal(t, uint64(2600), ethparams.ColdAccountAccessCostEIP2929, "ColdAccountAccessCostEIP2929") + assert.Equal(t, uint64(2100), ethparams.ColdSloadCostEIP2929, "ColdSloadCostEIP2929") + assert.Equal(t, uint64(100), ethparams.WarmStorageReadCostEIP2929, "WarmStorageReadCostEIP2929") + assert.Equal(t, uint64(5000-2100+1900), ethparams.SstoreClearsScheduleRefundEIP3529, "SstoreClearsScheduleRefundEIP3529") + assert.Equal(t, uint64(1), ethparams.JumpdestGas, "JumpdestGas") + assert.Equal(t, uint64(30000), ethparams.EpochDuration, "EpochDuration") + assert.Equal(t, uint64(200), ethparams.CreateDataGas, "CreateDataGas") + assert.Equal(t, uint64(1024), ethparams.CallCreateDepth, "CallCreateDepth") + assert.Equal(t, uint64(10), ethparams.ExpGas, "ExpGas") + assert.Equal(t, uint64(375), ethparams.LogGas, "LogGas") + assert.Equal(t, uint64(3), ethparams.CopyGas, "CopyGas") + assert.Equal(t, uint64(1024), ethparams.StackLimit, "StackLimit") + assert.Equal(t, uint64(0), ethparams.TierStepGas, "TierStepGas") + assert.Equal(t, uint64(375), ethparams.LogTopicGas, "LogTopicGas") + assert.Equal(t, uint64(32000), ethparams.CreateGas, "CreateGas") + assert.Equal(t, uint64(32000), ethparams.Create2Gas, "Create2Gas") + assert.Equal(t, uint64(24000), ethparams.SelfdestructRefundGas, "SelfdestructRefundGas") + assert.Equal(t, uint64(3), ethparams.MemoryGas, "MemoryGas") + assert.Equal(t, uint64(68), ethparams.TxDataNonZeroGasFrontier, "TxDataNonZeroGasFrontier") + assert.Equal(t, uint64(16), ethparams.TxDataNonZeroGasEIP2028, "TxDataNonZeroGasEIP2028") + assert.Equal(t, uint64(2400), ethparams.TxAccessListAddressGas, "TxAccessListAddressGas") + assert.Equal(t, uint64(1900), ethparams.TxAccessListStorageKeyGas, "TxAccessListStorageKeyGas") + assert.Equal(t, uint64(40), ethparams.CallGasFrontier, "CallGasFrontier") + assert.Equal(t, uint64(700), ethparams.CallGasEIP150, "CallGasEIP150") + assert.Equal(t, uint64(20), ethparams.BalanceGasFrontier, "BalanceGasFrontier") + assert.Equal(t, uint64(400), ethparams.BalanceGasEIP150, "BalanceGasEIP150") + assert.Equal(t, uint64(700), ethparams.BalanceGasEIP1884, "BalanceGasEIP1884") + assert.Equal(t, uint64(20), ethparams.ExtcodeSizeGasFrontier, "ExtcodeSizeGasFrontier") + assert.Equal(t, uint64(700), ethparams.ExtcodeSizeGasEIP150, "ExtcodeSizeGasEIP150") + assert.Equal(t, uint64(50), ethparams.SloadGasFrontier, "SloadGasFrontier") + assert.Equal(t, uint64(200), ethparams.SloadGasEIP150, "SloadGasEIP150") + assert.Equal(t, uint64(800), ethparams.SloadGasEIP1884, "SloadGasEIP1884") + assert.Equal(t, uint64(800), ethparams.SloadGasEIP2200, "SloadGasEIP2200") + assert.Equal(t, uint64(400), ethparams.ExtcodeHashGasConstantinople, "ExtcodeHashGasConstantinople") + assert.Equal(t, uint64(700), ethparams.ExtcodeHashGasEIP1884, "ExtcodeHashGasEIP1884") + assert.Equal(t, uint64(5000), ethparams.SelfdestructGasEIP150, "SelfdestructGasEIP150") + assert.Equal(t, uint64(10), ethparams.ExpByteFrontier, "ExpByteFrontier") + assert.Equal(t, uint64(50), ethparams.ExpByteEIP158, "ExpByteEIP158") + assert.Equal(t, uint64(20), ethparams.ExtcodeCopyBaseFrontier, "ExtcodeCopyBaseFrontier") + assert.Equal(t, uint64(700), ethparams.ExtcodeCopyBaseEIP150, "ExtcodeCopyBaseEIP150") + assert.Equal(t, uint64(25000), ethparams.CreateBySelfdestructGas, "CreateBySelfdestructGas") + assert.Equal(t, 8, ethparams.DefaultBaseFeeChangeDenominator, "DefaultBaseFeeChangeDenominator") + assert.Equal(t, 2, ethparams.DefaultElasticityMultiplier, "DefaultElasticityMultiplier") + assert.Equal(t, 1000000000, ethparams.InitialBaseFee, "InitialBaseFee") + assert.Equal(t, 24576, ethparams.MaxCodeSize, "MaxCodeSize") + assert.Equal(t, 2*24576, ethparams.MaxInitCodeSize, "MaxInitCodeSize") + assert.Equal(t, uint64(3000), ethparams.EcrecoverGas, "EcrecoverGas") + assert.Equal(t, uint64(60), ethparams.Sha256BaseGas, "Sha256BaseGas") + assert.Equal(t, uint64(12), ethparams.Sha256PerWordGas, "Sha256PerWordGas") + assert.Equal(t, uint64(600), ethparams.Ripemd160BaseGas, "Ripemd160BaseGas") + assert.Equal(t, uint64(120), ethparams.Ripemd160PerWordGas, "Ripemd160PerWordGas") + assert.Equal(t, uint64(15), ethparams.IdentityBaseGas, "IdentityBaseGas") + assert.Equal(t, uint64(3), ethparams.IdentityPerWordGas, "IdentityPerWordGas") + assert.Equal(t, uint64(500), ethparams.Bn256AddGasByzantium, "Bn256AddGasByzantium") + assert.Equal(t, uint64(150), ethparams.Bn256AddGasIstanbul, "Bn256AddGasIstanbul") + assert.Equal(t, uint64(40000), ethparams.Bn256ScalarMulGasByzantium, "Bn256ScalarMulGasByzantium") + assert.Equal(t, uint64(6000), ethparams.Bn256ScalarMulGasIstanbul, "Bn256ScalarMulGasIstanbul") + assert.Equal(t, uint64(100000), ethparams.Bn256PairingBaseGasByzantium, "Bn256PairingBaseGasByzantium") + assert.Equal(t, uint64(45000), ethparams.Bn256PairingBaseGasIstanbul, "Bn256PairingBaseGasIstanbul") + assert.Equal(t, uint64(80000), ethparams.Bn256PairingPerPointGasByzantium, "Bn256PairingPerPointGasByzantium") + assert.Equal(t, uint64(34000), ethparams.Bn256PairingPerPointGasIstanbul, "Bn256PairingPerPointGasIstanbul") + assert.Equal(t, uint64(600), ethparams.Bls12381G1AddGas, "Bls12381G1AddGas") + assert.Equal(t, uint64(12000), ethparams.Bls12381G1MulGas, "Bls12381G1MulGas") + assert.Equal(t, uint64(4500), ethparams.Bls12381G2AddGas, "Bls12381G2AddGas") + assert.Equal(t, uint64(55000), ethparams.Bls12381G2MulGas, "Bls12381G2MulGas") + assert.Equal(t, uint64(115000), ethparams.Bls12381PairingBaseGas, "Bls12381PairingBaseGas") + assert.Equal(t, uint64(23000), ethparams.Bls12381PairingPerPairGas, "Bls12381PairingPerPairGas") + assert.Equal(t, uint64(5500), ethparams.Bls12381MapG1Gas, "Bls12381MapG1Gas") + assert.Equal(t, uint64(110000), ethparams.Bls12381MapG2Gas, "Bls12381MapG2Gas") + assert.Equal(t, uint64(2), ethparams.RefundQuotient, "RefundQuotient") + assert.Equal(t, uint64(5), ethparams.RefundQuotientEIP3529, "RefundQuotientEIP3529") + assert.Equal(t, 32, ethparams.BlobTxBytesPerFieldElement, "BlobTxBytesPerFieldElement") + assert.Equal(t, 4096, ethparams.BlobTxFieldElementsPerBlob, "BlobTxFieldElementsPerBlob") + assert.Equal(t, 1<<17, ethparams.BlobTxBlobGasPerBlob, "BlobTxBlobGasPerBlob") + assert.Equal(t, 1, ethparams.BlobTxMinBlobGasprice, "BlobTxMinBlobGasprice") + assert.Equal(t, 3338477, ethparams.BlobTxBlobGaspriceUpdateFraction, "BlobTxBlobGaspriceUpdateFraction") + assert.Equal(t, 50000, ethparams.BlobTxPointEvaluationPrecompileGas, "BlobTxPointEvaluationPrecompileGas") + assert.Equal(t, 3*131072, ethparams.BlobTxTargetBlobGasPerBlock, "BlobTxTargetBlobGasPerBlock") + assert.Equal(t, 6*131072, ethparams.MaxBlobGasPerBlock, "MaxBlobGasPerBlock") + assert.Equal(t, int64(131072), ethparams.GenesisDifficulty.Int64(), "GenesisDifficulty") + assert.Equal(t, common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"), ethparams.BeaconRootsStorageAddress, "BeaconRootsStorageAddress") + assert.Equal(t, common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe"), ethparams.SystemAddress, "SystemAddress") +} diff --git a/params/protocol_params.go b/params/protocol_params.go deleted file mode 100644 index 3d2275ef2a..0000000000 --- a/params/protocol_params.go +++ /dev/null @@ -1,193 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. -// -// This file is a derived work, based on the go-ethereum library whose original -// notices appear below. -// -// It is distributed under a license compatible with the licensing terms of the -// original code from which it is derived. -// -// Much love to the original authors for their work. -// ********** -// Copyright 2015 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package params - -import ( - "math/big" - - "github.com/ava-labs/libevm/common" -) - -const ( - GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block. - - ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction. - SloadGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added. - CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero. - CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior. - TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions. - TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions. - TxDataZeroGas uint64 = 4 // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions. - QuadCoeffDiv uint64 = 512 // Divisor for the quadratic particle of the memory cost equation. - LogDataGas uint64 = 8 // Per byte in a LOG* operation's data. - CallStipend uint64 = 2300 // Free gas given at beginning of call. - - Keccak256Gas uint64 = 30 // Once per KECCAK256 operation. - Keccak256WordGas uint64 = 6 // Once per word of the KECCAK256 operation's data. - InitCodeWordGas uint64 = 2 // Once per word of the init code when creating a contract. - - SstoreSetGas uint64 = 20000 // Once per SSTORE operation. - SstoreResetGas uint64 = 5000 // Once per SSTORE operation if the zeroness changes from zero. - SstoreClearGas uint64 = 5000 // Once per SSTORE operation if the zeroness doesn't change. - SstoreRefundGas uint64 = 15000 // Once per SSTORE operation if the zeroness changes to zero. - - NetSstoreNoopGas uint64 = 200 // Once per SSTORE operation if the value doesn't change. - NetSstoreInitGas uint64 = 20000 // Once per SSTORE operation from clean zero. - NetSstoreCleanGas uint64 = 5000 // Once per SSTORE operation from clean non-zero. - NetSstoreDirtyGas uint64 = 200 // Once per SSTORE operation from dirty. - - NetSstoreClearRefund uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot - NetSstoreResetRefund uint64 = 4800 // Once per SSTORE operation for resetting to the original non-zero value - NetSstoreResetClearRefund uint64 = 19800 // Once per SSTORE operation for resetting to the original zero value - - SstoreSentryGasEIP2200 uint64 = 2300 // Minimum gas required to be present for an SSTORE call, not consumed - SstoreSetGasEIP2200 uint64 = 20000 // Once per SSTORE operation from clean zero to non-zero - SstoreResetGasEIP2200 uint64 = 5000 // Once per SSTORE operation from clean non-zero to something else - SstoreClearsScheduleRefundEIP2200 uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot - - ColdAccountAccessCostEIP2929 = uint64(2600) // COLD_ACCOUNT_ACCESS_COST - ColdSloadCostEIP2929 = uint64(2100) // COLD_SLOAD_COST - WarmStorageReadCostEIP2929 = uint64(100) // WARM_STORAGE_READ_COST - - // In EIP-2200: SstoreResetGas was 5000. - // In EIP-2929: SstoreResetGas was changed to '5000 - COLD_SLOAD_COST'. - // In EIP-3529: SSTORE_CLEARS_SCHEDULE is defined as SSTORE_RESET_GAS + ACCESS_LIST_STORAGE_KEY_COST - // Which becomes: 5000 - 2100 + 1900 = 4800 - SstoreClearsScheduleRefundEIP3529 uint64 = SstoreResetGasEIP2200 - ColdSloadCostEIP2929 + TxAccessListStorageKeyGas - - JumpdestGas uint64 = 1 // Once per JUMPDEST operation. - EpochDuration uint64 = 30000 // Duration between proof-of-work epochs. - - CreateDataGas uint64 = 200 // - CallCreateDepth uint64 = 1024 // Maximum depth of call/create stack. - ExpGas uint64 = 10 // Once per EXP instruction - LogGas uint64 = 375 // Per LOG* operation. - CopyGas uint64 = 3 // - StackLimit uint64 = 1024 // Maximum size of VM stack allowed. - TierStepGas uint64 = 0 // Once per operation, for a selection of them. - LogTopicGas uint64 = 375 // Multiplied by the * of the LOG*, per LOG transaction. e.g. LOG0 incurs 0 * c_txLogTopicGas, LOG4 incurs 4 * c_txLogTopicGas. - CreateGas uint64 = 32000 // Once per CREATE operation & contract-creation transaction. - Create2Gas uint64 = 32000 // Once per CREATE2 operation - SelfdestructRefundGas uint64 = 24000 // Refunded following a selfdestruct operation. - MemoryGas uint64 = 3 // Times the address of the (highest referenced byte in memory + 1). NOTE: referencing happens on read, write and in instructions such as RETURN and CALL. - - TxDataNonZeroGasFrontier uint64 = 68 // Per byte of data attached to a transaction that is not equal to zero. NOTE: Not payable on data of calls between transactions. - TxDataNonZeroGasEIP2028 uint64 = 16 // Per byte of non zero data attached to a transaction after EIP 2028 (part in Istanbul) - TxAccessListAddressGas uint64 = 2400 // Per address specified in EIP 2930 access list - TxAccessListStorageKeyGas uint64 = 1900 // Per storage key specified in EIP 2930 access list - - // These have been changed during the course of the chain - CallGasFrontier uint64 = 40 // Once per CALL operation & message call transaction. - CallGasEIP150 uint64 = 700 // Static portion of gas for CALL-derivates after EIP 150 (Tangerine) - BalanceGasFrontier uint64 = 20 // The cost of a BALANCE operation - BalanceGasEIP150 uint64 = 400 // The cost of a BALANCE operation after Tangerine - BalanceGasEIP1884 uint64 = 700 // The cost of a BALANCE operation after EIP 1884 (part of Istanbul) - ExtcodeSizeGasFrontier uint64 = 20 // Cost of EXTCODESIZE before EIP 150 (Tangerine) - ExtcodeSizeGasEIP150 uint64 = 700 // Cost of EXTCODESIZE after EIP 150 (Tangerine) - SloadGasFrontier uint64 = 50 - SloadGasEIP150 uint64 = 200 - SloadGasEIP1884 uint64 = 800 // Cost of SLOAD after EIP 1884 (part of Istanbul) - SloadGasEIP2200 uint64 = 800 // Cost of SLOAD after EIP 2200 (part of Istanbul) - ExtcodeHashGasConstantinople uint64 = 400 // Cost of EXTCODEHASH (introduced in Constantinople) - ExtcodeHashGasEIP1884 uint64 = 700 // Cost of EXTCODEHASH after EIP 1884 (part in Istanbul) - SelfdestructGasEIP150 uint64 = 5000 // Cost of SELFDESTRUCT post EIP 150 (Tangerine) - - // EXP has a dynamic portion depending on the size of the exponent - ExpByteFrontier uint64 = 10 // was set to 10 in Frontier - ExpByteEIP158 uint64 = 50 // was raised to 50 during Eip158 (Spurious Dragon) - - // Extcodecopy has a dynamic AND a static cost. This represents only the - // static portion of the gas. It was changed during EIP 150 (Tangerine) - ExtcodeCopyBaseFrontier uint64 = 20 - ExtcodeCopyBaseEIP150 uint64 = 700 - - // CreateBySelfdestructGas is used when the refunded account is one that does - // not exist. This logic is similar to call. - // Introduced in Tangerine Whistle (Eip 150) - CreateBySelfdestructGas uint64 = 25000 - - MaxCodeSize = 24576 // Maximum bytecode to permit for a contract - MaxInitCodeSize = 2 * MaxCodeSize // Maximum initcode to permit in a creation transaction and create instructions - - // Precompiled contract gas prices - - EcrecoverGas uint64 = 3000 // Elliptic curve sender recovery gas price - Sha256BaseGas uint64 = 60 // Base price for a SHA256 operation - Sha256PerWordGas uint64 = 12 // Per-word price for a SHA256 operation - Ripemd160BaseGas uint64 = 600 // Base price for a RIPEMD160 operation - Ripemd160PerWordGas uint64 = 120 // Per-word price for a RIPEMD160 operation - IdentityBaseGas uint64 = 15 // Base price for a data copy operation - IdentityPerWordGas uint64 = 3 // Per-work price for a data copy operation - - Bn256AddGasByzantium uint64 = 500 // Byzantium gas needed for an elliptic curve addition - Bn256AddGasIstanbul uint64 = 150 // Gas needed for an elliptic curve addition - Bn256ScalarMulGasByzantium uint64 = 40000 // Byzantium gas needed for an elliptic curve scalar multiplication - Bn256ScalarMulGasIstanbul uint64 = 6000 // Gas needed for an elliptic curve scalar multiplication - Bn256PairingBaseGasByzantium uint64 = 100000 // Byzantium base price for an elliptic curve pairing check - Bn256PairingBaseGasIstanbul uint64 = 45000 // Base price for an elliptic curve pairing check - Bn256PairingPerPointGasByzantium uint64 = 80000 // Byzantium per-point price for an elliptic curve pairing check - Bn256PairingPerPointGasIstanbul uint64 = 34000 // Per-point price for an elliptic curve pairing check - - Bls12381G1AddGas uint64 = 600 // Price for BLS12-381 elliptic curve G1 point addition - Bls12381G1MulGas uint64 = 12000 // Price for BLS12-381 elliptic curve G1 point scalar multiplication - Bls12381G2AddGas uint64 = 4500 // Price for BLS12-381 elliptic curve G2 point addition - Bls12381G2MulGas uint64 = 55000 // Price for BLS12-381 elliptic curve G2 point scalar multiplication - Bls12381PairingBaseGas uint64 = 115000 // Base gas price for BLS12-381 elliptic curve pairing check - Bls12381PairingPerPairGas uint64 = 23000 // Per-point pair gas price for BLS12-381 elliptic curve pairing check - Bls12381MapG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation - Bls12381MapG2Gas uint64 = 110000 // Gas price for BLS12-381 mapping field element to G2 operation - - // The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529, - // up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529 - RefundQuotient uint64 = 2 - RefundQuotientEIP3529 uint64 = 5 - - BlobTxBytesPerFieldElement = 32 // Size in bytes of a field element - BlobTxFieldElementsPerBlob = 4096 // Number of field elements stored in a single data blob - BlobTxBlobGasPerBlob = 1 << 17 // Gas consumption of a single data blob (== blob byte size) - BlobTxMinBlobGasprice = 1 // Minimum gas price for data blobs - BlobTxBlobGaspriceUpdateFraction = 3338477 // Controls the maximum rate of change for blob gas price - BlobTxPointEvaluationPrecompileGas = 50000 // Gas price for the point evaluation precompile. - - BlobTxTargetBlobGasPerBlock = 3 * BlobTxBlobGasPerBlob // Target consumable blob gas for data blobs per block (for 1559-like pricing) - MaxBlobGasPerBlock = 6 * BlobTxBlobGasPerBlob // Maximum consumable blob gas for data blobs per block -) - -// Gas discount table for BLS12-381 G1 and G2 multi exponentiation operations -var Bls12381MultiExpDiscountTable = [128]uint64{1200, 888, 764, 641, 594, 547, 500, 453, 438, 423, 408, 394, 379, 364, 349, 334, 330, 326, 322, 318, 314, 310, 306, 302, 298, 294, 289, 285, 281, 277, 273, 269, 268, 266, 265, 263, 262, 260, 259, 257, 256, 254, 253, 251, 250, 248, 247, 245, 244, 242, 241, 239, 238, 236, 235, 233, 232, 231, 229, 228, 226, 225, 223, 222, 221, 220, 219, 219, 218, 217, 216, 216, 215, 214, 213, 213, 212, 211, 211, 210, 209, 208, 208, 207, 206, 205, 205, 204, 203, 202, 202, 201, 200, 199, 199, 198, 197, 196, 196, 195, 194, 193, 193, 192, 191, 191, 190, 189, 188, 188, 187, 186, 185, 185, 184, 183, 182, 182, 181, 180, 179, 179, 178, 177, 176, 176, 175, 174} - -var ( - DifficultyBoundDivisor = big.NewInt(2048) // The bound divisor of the difficulty, used in the update calculations. - GenesisDifficulty = big.NewInt(131072) // Difficulty of the Genesis block. - MinimumDifficulty = big.NewInt(131072) // The minimum that the difficulty may ever be. - DurationLimit = big.NewInt(13) // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not. - - // BeaconRootsStorageAddress is the address where historical beacon roots are stored as per EIP-4788 - BeaconRootsStorageAddress = common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02") - // SystemAddress is where the system-transaction is sent from as per EIP-4788 - SystemAddress common.Address = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe") -) diff --git a/plugin/evm/header/extra_test.go b/plugin/evm/header/extra_test.go index 2e85bdf1d8..b6b1da3aed 100644 --- a/plugin/evm/header/extra_test.go +++ b/plugin/evm/header/extra_test.go @@ -8,12 +8,10 @@ import ( "testing" "github.com/ava-labs/libevm/core/types" - ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/params/extras" "github.com/ava-labs/subnet-evm/plugin/evm/customtypes" "github.com/ava-labs/subnet-evm/plugin/evm/upgrade/subnetevm" "github.com/ava-labs/subnet-evm/utils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -369,9 +367,3 @@ func TestPredicateBytesExtra(t *testing.T) { }) } } - -func TestUpstreamParamsValues(t *testing.T) { - assert.Equal(t, uint64(1024), ethparams.GasLimitBoundDivisor, "gas limit bound divisor") - assert.Equal(t, uint64(5000), ethparams.MinGasLimit, "min gas limit") - assert.Equal(t, uint64(0x7fffffffffffffff), ethparams.MaxGasLimit, "max gas limit") -} diff --git a/plugin/evm/syncervm_test.go b/plugin/evm/syncervm_test.go index 7aac4fbdcf..3a687b7ab3 100644 --- a/plugin/evm/syncervm_test.go +++ b/plugin/evm/syncervm_test.go @@ -30,13 +30,13 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/ethdb" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/rlp" "github.com/ava-labs/libevm/trie" "github.com/ava-labs/libevm/triedb" "github.com/ava-labs/subnet-evm/consensus/dummy" "github.com/ava-labs/subnet-evm/constants" "github.com/ava-labs/subnet-evm/core" - "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/plugin/evm/customrawdb" "github.com/ava-labs/subnet-evm/plugin/evm/database" "github.com/ava-labs/subnet-evm/predicate" @@ -287,7 +287,7 @@ func createSyncServerAndClientVMs(t *testing.T, test syncTest, numBlocks int) *s } gen.AppendExtra(b) - tx := types.NewTransaction(gen.TxNonce(testEthAddrs[0]), testEthAddrs[1], common.Big1, params.TxGas, big.NewInt(testMinGasPrice), nil) + tx := types.NewTransaction(gen.TxNonce(testEthAddrs[0]), testEthAddrs[1], common.Big1, ethparams.TxGas, big.NewInt(testMinGasPrice), nil) signedTx, err := types.SignTx(tx, types.NewEIP155Signer(serverVM.chainConfig.ChainID), testKeys[0]) require.NoError(err) gen.AddTx(signedTx) diff --git a/sync/client/client.go b/sync/client/client.go index 85a6927445..9a63a8073f 100644 --- a/sync/client/client.go +++ b/sync/client/client.go @@ -13,19 +13,18 @@ import ( "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/sync/client/stats" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/libevm/common" - "github.com/ava-labs/libevm/crypto" - "github.com/ava-labs/libevm/log" - "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" + "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/ethdb" + "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/trie" "github.com/ava-labs/subnet-evm/peer" "github.com/ava-labs/subnet-evm/plugin/evm/message" @@ -267,7 +266,7 @@ func parseCode(codec codec.Manager, req message.Request, data []byte) (interface totalBytes := 0 for i, code := range response.Data { - if len(code) > params.MaxCodeSize { + if len(code) > ethparams.MaxCodeSize { return nil, 0, fmt.Errorf("%w: (hash %s) (size %d)", errMaxCodeSizeExceeded, codeRequest.Hashes[i], len(code)) } diff --git a/sync/client/client_test.go b/sync/client/client_test.go index 08e59a865c..03611ae1a9 100644 --- a/sync/client/client_test.go +++ b/sync/client/client_test.go @@ -19,6 +19,7 @@ import ( "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/crypto" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/triedb" "github.com/ava-labs/subnet-evm/consensus/dummy" "github.com/ava-labs/subnet-evm/core" @@ -74,7 +75,7 @@ func TestGetCode(t *testing.T) { }, "code size is too large": { setupRequest: func() (requestHashes []common.Hash, mockResponse message.CodeResponse, expectedCode [][]byte) { - oversizedCode := make([]byte, params.MaxCodeSize+1) + oversizedCode := make([]byte, ethparams.MaxCodeSize+1) codeHash := crypto.Keccak256Hash(oversizedCode) return []common.Hash{codeHash}, message.CodeResponse{ Data: [][]byte{oversizedCode}, diff --git a/sync/handlers/code_request_test.go b/sync/handlers/code_request_test.go index df6e336144..15b3bbb1a0 100644 --- a/sync/handlers/code_request_test.go +++ b/sync/handlers/code_request_test.go @@ -8,13 +8,12 @@ import ( "crypto/rand" "testing" - "github.com/ava-labs/subnet-evm/params" - "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/ethdb/memorydb" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/plugin/evm/message" "github.com/ava-labs/subnet-evm/sync/handlers/stats" "github.com/stretchr/testify/assert" @@ -27,10 +26,10 @@ func TestCodeRequestHandler(t *testing.T) { codeHash := crypto.Keccak256Hash(codeBytes) rawdb.WriteCode(database, codeHash, codeBytes) - maxSizeCodeBytes := make([]byte, params.MaxCodeSize) + maxSizeCodeBytes := make([]byte, ethparams.MaxCodeSize) n, err := rand.Read(maxSizeCodeBytes) assert.NoError(t, err) - assert.Equal(t, params.MaxCodeSize, n) + assert.Equal(t, ethparams.MaxCodeSize, n) maxSizeCodeHash := crypto.Keccak256Hash(maxSizeCodeBytes) rawdb.WriteCode(database, maxSizeCodeHash, maxSizeCodeBytes) @@ -80,7 +79,7 @@ func TestCodeRequestHandler(t *testing.T) { }, verifyStats: func(t *testing.T, stats *stats.MockHandlerStats) { assert.EqualValues(t, 1, mockHandlerStats.CodeRequestCount) - assert.EqualValues(t, params.MaxCodeSize, mockHandlerStats.CodeBytesReturnedSum) + assert.EqualValues(t, ethparams.MaxCodeSize, mockHandlerStats.CodeBytesReturnedSum) }, }, } diff --git a/tests/antithesis/main.go b/tests/antithesis/main.go index b6f68c21a6..68f319a003 100644 --- a/tests/antithesis/main.go +++ b/tests/antithesis/main.go @@ -25,9 +25,9 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/accounts/abi/bind" "github.com/ava-labs/subnet-evm/ethclient" - "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/tests" "github.com/ava-labs/subnet-evm/tests/utils" @@ -189,7 +189,7 @@ func transferFunds(ctx context.Context, client ethclient.Client, key *ecdsa.Priv Nonce: acceptedNonce, GasTipCap: gasTipCap, GasFeeCap: gasFeeCap, - Gas: params.TxGas, + Gas: ethparams.TxGas, To: &recipientAddress, Value: big.NewInt(int64(txAmount)), }) diff --git a/tests/state_test_util.go b/tests/state_test_util.go index f143bc7352..3070fd0ab9 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -43,6 +43,7 @@ import ( "github.com/ava-labs/libevm/core/vm" "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/ethdb" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/rlp" "github.com/ava-labs/libevm/triedb" "github.com/ava-labs/subnet-evm/consensus/misc/eip4844" @@ -281,7 +282,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh // - the block body is verified against the header in block_validator.go:ValidateBody // Here, we just do this shortcut smaller fix, since state tests do not // utilize those codepaths - if len(msg.BlobHashes)*params.BlobTxBlobGasPerBlob > params.MaxBlobGasPerBlock { + if len(msg.BlobHashes)*ethparams.BlobTxBlobGasPerBlob > ethparams.MaxBlobGasPerBlock { return state, common.Hash{}, errors.New("blob gas exceeds maximum") } } diff --git a/tests/utils/proposervm.go b/tests/utils/proposervm.go index d6888f018b..4816443532 100644 --- a/tests/utils/proposervm.go +++ b/tests/utils/proposervm.go @@ -12,8 +12,8 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/log" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/subnet-evm/ethclient" - "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/plugin/evm/upgrade/legacy" ) @@ -46,7 +46,7 @@ func IssueTxsToActivateProposerVMFork( txSigner := types.LatestSignerForChainID(chainID) for i := 0; i < numTriggerTxs; i++ { tx := types.NewTransaction( - nonce, addr, common.Big1, params.TxGas, gasPrice, nil) + nonce, addr, common.Big1, ethparams.TxGas, gasPrice, nil) triggerTx, err := types.SignTx(tx, txSigner, fundedKey) if err != nil { return err From e7224e84a79c0e9fabe8393987bb6293206a1374 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Fri, 18 Apr 2025 15:02:02 +0200 Subject: [PATCH 3/5] Table driven style for TestUpstreamParamsValues --- params/config_test.go | 239 ++++++++++++++++++++++-------------------- 1 file changed, 124 insertions(+), 115 deletions(-) diff --git a/params/config_test.go b/params/config_test.go index 7174fb300e..becf0c80e2 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -347,119 +347,128 @@ func TestChainConfigMarshalWithUpgrades(t *testing.T) { // Values should be updated to newer upstream values once the consumer is updated to handle the // updated value(s). func TestUpstreamParamsValues(t *testing.T) { - assert.Equal(t, uint64(1024), ethparams.GasLimitBoundDivisor, "GasLimitBoundDivisor") - assert.Equal(t, uint64(5000), ethparams.MinGasLimit, "MinGasLimit") - assert.Equal(t, uint64(0x7fffffffffffffff), ethparams.MaxGasLimit, "MaxGasLimit") - assert.Equal(t, uint64(4712388), ethparams.GenesisGasLimit, "GenesisGasLimit") - assert.Equal(t, uint64(32), ethparams.MaximumExtraDataSize, "MaximumExtraDataSize") - assert.Equal(t, uint64(10), ethparams.ExpByteGas, "ExpByteGas") - assert.Equal(t, uint64(50), ethparams.SloadGas, "SloadGas") - assert.Equal(t, uint64(9000), ethparams.CallValueTransferGas, "CallValueTransferGas") - assert.Equal(t, uint64(25000), ethparams.CallNewAccountGas, "CallNewAccountGas") - assert.Equal(t, uint64(21000), ethparams.TxGas, "TxGas") - assert.Equal(t, uint64(53000), ethparams.TxGasContractCreation, "TxGasContractCreation") - assert.Equal(t, uint64(4), ethparams.TxDataZeroGas, "TxDataZeroGas") - assert.Equal(t, uint64(512), ethparams.QuadCoeffDiv, "QuadCoeffDiv") - assert.Equal(t, uint64(8), ethparams.LogDataGas, "LogDataGas") - assert.Equal(t, uint64(2300), ethparams.CallStipend, "CallStipend") - assert.Equal(t, uint64(30), ethparams.Keccak256Gas, "Keccak256Gas") - assert.Equal(t, uint64(6), ethparams.Keccak256WordGas, "Keccak256WordGas") - assert.Equal(t, uint64(2), ethparams.InitCodeWordGas, "InitCodeWordGas") - assert.Equal(t, uint64(20000), ethparams.SstoreSetGas, "SstoreSetGas") - assert.Equal(t, uint64(5000), ethparams.SstoreResetGas, "SstoreResetGas") - assert.Equal(t, uint64(5000), ethparams.SstoreClearGas, "SstoreClearGas") - assert.Equal(t, uint64(15000), ethparams.SstoreRefundGas, "SstoreRefundGas") - assert.Equal(t, uint64(200), ethparams.NetSstoreNoopGas, "NetSstoreNoopGas") - assert.Equal(t, uint64(20000), ethparams.NetSstoreInitGas, "NetSstoreInitGas") - assert.Equal(t, uint64(5000), ethparams.NetSstoreCleanGas, "NetSstoreCleanGas") - assert.Equal(t, uint64(200), ethparams.NetSstoreDirtyGas, "NetSstoreDirtyGas") - assert.Equal(t, uint64(15000), ethparams.NetSstoreClearRefund, "NetSstoreClearRefund") - assert.Equal(t, uint64(4800), ethparams.NetSstoreResetRefund, "NetSstoreResetRefund") - assert.Equal(t, uint64(19800), ethparams.NetSstoreResetClearRefund, "NetSstoreResetClearRefund") - assert.Equal(t, uint64(2300), ethparams.SstoreSentryGasEIP2200, "SstoreSentryGasEIP2200") - assert.Equal(t, uint64(20000), ethparams.SstoreSetGasEIP2200, "SstoreSetGasEIP2200") - assert.Equal(t, uint64(5000), ethparams.SstoreResetGasEIP2200, "SstoreResetGasEIP2200") - assert.Equal(t, uint64(15000), ethparams.SstoreClearsScheduleRefundEIP2200, "SstoreClearsScheduleRefundEIP2200") - assert.Equal(t, uint64(2600), ethparams.ColdAccountAccessCostEIP2929, "ColdAccountAccessCostEIP2929") - assert.Equal(t, uint64(2100), ethparams.ColdSloadCostEIP2929, "ColdSloadCostEIP2929") - assert.Equal(t, uint64(100), ethparams.WarmStorageReadCostEIP2929, "WarmStorageReadCostEIP2929") - assert.Equal(t, uint64(5000-2100+1900), ethparams.SstoreClearsScheduleRefundEIP3529, "SstoreClearsScheduleRefundEIP3529") - assert.Equal(t, uint64(1), ethparams.JumpdestGas, "JumpdestGas") - assert.Equal(t, uint64(30000), ethparams.EpochDuration, "EpochDuration") - assert.Equal(t, uint64(200), ethparams.CreateDataGas, "CreateDataGas") - assert.Equal(t, uint64(1024), ethparams.CallCreateDepth, "CallCreateDepth") - assert.Equal(t, uint64(10), ethparams.ExpGas, "ExpGas") - assert.Equal(t, uint64(375), ethparams.LogGas, "LogGas") - assert.Equal(t, uint64(3), ethparams.CopyGas, "CopyGas") - assert.Equal(t, uint64(1024), ethparams.StackLimit, "StackLimit") - assert.Equal(t, uint64(0), ethparams.TierStepGas, "TierStepGas") - assert.Equal(t, uint64(375), ethparams.LogTopicGas, "LogTopicGas") - assert.Equal(t, uint64(32000), ethparams.CreateGas, "CreateGas") - assert.Equal(t, uint64(32000), ethparams.Create2Gas, "Create2Gas") - assert.Equal(t, uint64(24000), ethparams.SelfdestructRefundGas, "SelfdestructRefundGas") - assert.Equal(t, uint64(3), ethparams.MemoryGas, "MemoryGas") - assert.Equal(t, uint64(68), ethparams.TxDataNonZeroGasFrontier, "TxDataNonZeroGasFrontier") - assert.Equal(t, uint64(16), ethparams.TxDataNonZeroGasEIP2028, "TxDataNonZeroGasEIP2028") - assert.Equal(t, uint64(2400), ethparams.TxAccessListAddressGas, "TxAccessListAddressGas") - assert.Equal(t, uint64(1900), ethparams.TxAccessListStorageKeyGas, "TxAccessListStorageKeyGas") - assert.Equal(t, uint64(40), ethparams.CallGasFrontier, "CallGasFrontier") - assert.Equal(t, uint64(700), ethparams.CallGasEIP150, "CallGasEIP150") - assert.Equal(t, uint64(20), ethparams.BalanceGasFrontier, "BalanceGasFrontier") - assert.Equal(t, uint64(400), ethparams.BalanceGasEIP150, "BalanceGasEIP150") - assert.Equal(t, uint64(700), ethparams.BalanceGasEIP1884, "BalanceGasEIP1884") - assert.Equal(t, uint64(20), ethparams.ExtcodeSizeGasFrontier, "ExtcodeSizeGasFrontier") - assert.Equal(t, uint64(700), ethparams.ExtcodeSizeGasEIP150, "ExtcodeSizeGasEIP150") - assert.Equal(t, uint64(50), ethparams.SloadGasFrontier, "SloadGasFrontier") - assert.Equal(t, uint64(200), ethparams.SloadGasEIP150, "SloadGasEIP150") - assert.Equal(t, uint64(800), ethparams.SloadGasEIP1884, "SloadGasEIP1884") - assert.Equal(t, uint64(800), ethparams.SloadGasEIP2200, "SloadGasEIP2200") - assert.Equal(t, uint64(400), ethparams.ExtcodeHashGasConstantinople, "ExtcodeHashGasConstantinople") - assert.Equal(t, uint64(700), ethparams.ExtcodeHashGasEIP1884, "ExtcodeHashGasEIP1884") - assert.Equal(t, uint64(5000), ethparams.SelfdestructGasEIP150, "SelfdestructGasEIP150") - assert.Equal(t, uint64(10), ethparams.ExpByteFrontier, "ExpByteFrontier") - assert.Equal(t, uint64(50), ethparams.ExpByteEIP158, "ExpByteEIP158") - assert.Equal(t, uint64(20), ethparams.ExtcodeCopyBaseFrontier, "ExtcodeCopyBaseFrontier") - assert.Equal(t, uint64(700), ethparams.ExtcodeCopyBaseEIP150, "ExtcodeCopyBaseEIP150") - assert.Equal(t, uint64(25000), ethparams.CreateBySelfdestructGas, "CreateBySelfdestructGas") - assert.Equal(t, 8, ethparams.DefaultBaseFeeChangeDenominator, "DefaultBaseFeeChangeDenominator") - assert.Equal(t, 2, ethparams.DefaultElasticityMultiplier, "DefaultElasticityMultiplier") - assert.Equal(t, 1000000000, ethparams.InitialBaseFee, "InitialBaseFee") - assert.Equal(t, 24576, ethparams.MaxCodeSize, "MaxCodeSize") - assert.Equal(t, 2*24576, ethparams.MaxInitCodeSize, "MaxInitCodeSize") - assert.Equal(t, uint64(3000), ethparams.EcrecoverGas, "EcrecoverGas") - assert.Equal(t, uint64(60), ethparams.Sha256BaseGas, "Sha256BaseGas") - assert.Equal(t, uint64(12), ethparams.Sha256PerWordGas, "Sha256PerWordGas") - assert.Equal(t, uint64(600), ethparams.Ripemd160BaseGas, "Ripemd160BaseGas") - assert.Equal(t, uint64(120), ethparams.Ripemd160PerWordGas, "Ripemd160PerWordGas") - assert.Equal(t, uint64(15), ethparams.IdentityBaseGas, "IdentityBaseGas") - assert.Equal(t, uint64(3), ethparams.IdentityPerWordGas, "IdentityPerWordGas") - assert.Equal(t, uint64(500), ethparams.Bn256AddGasByzantium, "Bn256AddGasByzantium") - assert.Equal(t, uint64(150), ethparams.Bn256AddGasIstanbul, "Bn256AddGasIstanbul") - assert.Equal(t, uint64(40000), ethparams.Bn256ScalarMulGasByzantium, "Bn256ScalarMulGasByzantium") - assert.Equal(t, uint64(6000), ethparams.Bn256ScalarMulGasIstanbul, "Bn256ScalarMulGasIstanbul") - assert.Equal(t, uint64(100000), ethparams.Bn256PairingBaseGasByzantium, "Bn256PairingBaseGasByzantium") - assert.Equal(t, uint64(45000), ethparams.Bn256PairingBaseGasIstanbul, "Bn256PairingBaseGasIstanbul") - assert.Equal(t, uint64(80000), ethparams.Bn256PairingPerPointGasByzantium, "Bn256PairingPerPointGasByzantium") - assert.Equal(t, uint64(34000), ethparams.Bn256PairingPerPointGasIstanbul, "Bn256PairingPerPointGasIstanbul") - assert.Equal(t, uint64(600), ethparams.Bls12381G1AddGas, "Bls12381G1AddGas") - assert.Equal(t, uint64(12000), ethparams.Bls12381G1MulGas, "Bls12381G1MulGas") - assert.Equal(t, uint64(4500), ethparams.Bls12381G2AddGas, "Bls12381G2AddGas") - assert.Equal(t, uint64(55000), ethparams.Bls12381G2MulGas, "Bls12381G2MulGas") - assert.Equal(t, uint64(115000), ethparams.Bls12381PairingBaseGas, "Bls12381PairingBaseGas") - assert.Equal(t, uint64(23000), ethparams.Bls12381PairingPerPairGas, "Bls12381PairingPerPairGas") - assert.Equal(t, uint64(5500), ethparams.Bls12381MapG1Gas, "Bls12381MapG1Gas") - assert.Equal(t, uint64(110000), ethparams.Bls12381MapG2Gas, "Bls12381MapG2Gas") - assert.Equal(t, uint64(2), ethparams.RefundQuotient, "RefundQuotient") - assert.Equal(t, uint64(5), ethparams.RefundQuotientEIP3529, "RefundQuotientEIP3529") - assert.Equal(t, 32, ethparams.BlobTxBytesPerFieldElement, "BlobTxBytesPerFieldElement") - assert.Equal(t, 4096, ethparams.BlobTxFieldElementsPerBlob, "BlobTxFieldElementsPerBlob") - assert.Equal(t, 1<<17, ethparams.BlobTxBlobGasPerBlob, "BlobTxBlobGasPerBlob") - assert.Equal(t, 1, ethparams.BlobTxMinBlobGasprice, "BlobTxMinBlobGasprice") - assert.Equal(t, 3338477, ethparams.BlobTxBlobGaspriceUpdateFraction, "BlobTxBlobGaspriceUpdateFraction") - assert.Equal(t, 50000, ethparams.BlobTxPointEvaluationPrecompileGas, "BlobTxPointEvaluationPrecompileGas") - assert.Equal(t, 3*131072, ethparams.BlobTxTargetBlobGasPerBlock, "BlobTxTargetBlobGasPerBlock") - assert.Equal(t, 6*131072, ethparams.MaxBlobGasPerBlock, "MaxBlobGasPerBlock") - assert.Equal(t, int64(131072), ethparams.GenesisDifficulty.Int64(), "GenesisDifficulty") - assert.Equal(t, common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"), ethparams.BeaconRootsStorageAddress, "BeaconRootsStorageAddress") - assert.Equal(t, common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe"), ethparams.SystemAddress, "SystemAddress") + tests := map[string]struct { + param any + want any + }{ + "GasLimitBoundDivisor": {param: ethparams.GasLimitBoundDivisor, want: uint64(1024)}, + "MinGasLimit": {param: ethparams.MinGasLimit, want: uint64(5000)}, + "MaxGasLimit": {param: ethparams.MaxGasLimit, want: uint64(0x7fffffffffffffff)}, + "GenesisGasLimit": {param: ethparams.GenesisGasLimit, want: uint64(4712388)}, + "MaximumExtraDataSize": {param: ethparams.MaximumExtraDataSize, want: uint64(32)}, + "ExpByteGas": {param: ethparams.ExpByteGas, want: uint64(10)}, + "SloadGas": {param: ethparams.SloadGas, want: uint64(50)}, + "CallValueTransferGas": {param: ethparams.CallValueTransferGas, want: uint64(9000)}, + "CallNewAccountGas": {param: ethparams.CallNewAccountGas, want: uint64(25000)}, + "TxGas": {param: ethparams.TxGas, want: uint64(21000)}, + "TxGasContractCreation": {param: ethparams.TxGasContractCreation, want: uint64(53000)}, + "TxDataZeroGas": {param: ethparams.TxDataZeroGas, want: uint64(4)}, + "QuadCoeffDiv": {param: ethparams.QuadCoeffDiv, want: uint64(512)}, + "LogDataGas": {param: ethparams.LogDataGas, want: uint64(8)}, + "CallStipend": {param: ethparams.CallStipend, want: uint64(2300)}, + "Keccak256Gas": {param: ethparams.Keccak256Gas, want: uint64(30)}, + "Keccak256WordGas": {param: ethparams.Keccak256WordGas, want: uint64(6)}, + "InitCodeWordGas": {param: ethparams.InitCodeWordGas, want: uint64(2)}, + "SstoreSetGas": {param: ethparams.SstoreSetGas, want: uint64(20000)}, + "SstoreResetGas": {param: ethparams.SstoreResetGas, want: uint64(5000)}, + "SstoreClearGas": {param: ethparams.SstoreClearGas, want: uint64(5000)}, + "SstoreRefundGas": {param: ethparams.SstoreRefundGas, want: uint64(15000)}, + "NetSstoreNoopGas": {param: ethparams.NetSstoreNoopGas, want: uint64(200)}, + "NetSstoreInitGas": {param: ethparams.NetSstoreInitGas, want: uint64(20000)}, + "NetSstoreCleanGas": {param: ethparams.NetSstoreCleanGas, want: uint64(5000)}, + "NetSstoreDirtyGas": {param: ethparams.NetSstoreDirtyGas, want: uint64(200)}, + "NetSstoreClearRefund": {param: ethparams.NetSstoreClearRefund, want: uint64(15000)}, + "NetSstoreResetRefund": {param: ethparams.NetSstoreResetRefund, want: uint64(4800)}, + "NetSstoreResetClearRefund": {param: ethparams.NetSstoreResetClearRefund, want: uint64(19800)}, + "SstoreSentryGasEIP2200": {param: ethparams.SstoreSentryGasEIP2200, want: uint64(2300)}, + "SstoreSetGasEIP2200": {param: ethparams.SstoreSetGasEIP2200, want: uint64(20000)}, + "SstoreResetGasEIP2200": {param: ethparams.SstoreResetGasEIP2200, want: uint64(5000)}, + "SstoreClearsScheduleRefundEIP2200": {param: ethparams.SstoreClearsScheduleRefundEIP2200, want: uint64(15000)}, + "ColdAccountAccessCostEIP2929": {param: ethparams.ColdAccountAccessCostEIP2929, want: uint64(2600)}, + "ColdSloadCostEIP2929": {param: ethparams.ColdSloadCostEIP2929, want: uint64(2100)}, + "WarmStorageReadCostEIP2929": {param: ethparams.WarmStorageReadCostEIP2929, want: uint64(100)}, + "SstoreClearsScheduleRefundEIP3529": {param: ethparams.SstoreClearsScheduleRefundEIP3529, want: uint64(5000 - 2100 + 1900)}, + "JumpdestGas": {param: ethparams.JumpdestGas, want: uint64(1)}, + "EpochDuration": {param: ethparams.EpochDuration, want: uint64(30000)}, + "CreateDataGas": {param: ethparams.CreateDataGas, want: uint64(200)}, + "CallCreateDepth": {param: ethparams.CallCreateDepth, want: uint64(1024)}, + "ExpGas": {param: ethparams.ExpGas, want: uint64(10)}, + "LogGas": {param: ethparams.LogGas, want: uint64(375)}, + "CopyGas": {param: ethparams.CopyGas, want: uint64(3)}, + "StackLimit": {param: ethparams.StackLimit, want: uint64(1024)}, + "TierStepGas": {param: ethparams.TierStepGas, want: uint64(0)}, + "LogTopicGas": {param: ethparams.LogTopicGas, want: uint64(375)}, + "CreateGas": {param: ethparams.CreateGas, want: uint64(32000)}, + "Create2Gas": {param: ethparams.Create2Gas, want: uint64(32000)}, + "SelfdestructRefundGas": {param: ethparams.SelfdestructRefundGas, want: uint64(24000)}, + "MemoryGas": {param: ethparams.MemoryGas, want: uint64(3)}, + "TxDataNonZeroGasFrontier": {param: ethparams.TxDataNonZeroGasFrontier, want: uint64(68)}, + "TxDataNonZeroGasEIP2028": {param: ethparams.TxDataNonZeroGasEIP2028, want: uint64(16)}, + "TxAccessListAddressGas": {param: ethparams.TxAccessListAddressGas, want: uint64(2400)}, + "TxAccessListStorageKeyGas": {param: ethparams.TxAccessListStorageKeyGas, want: uint64(1900)}, + "CallGasFrontier": {param: ethparams.CallGasFrontier, want: uint64(40)}, + "CallGasEIP150": {param: ethparams.CallGasEIP150, want: uint64(700)}, + "BalanceGasFrontier": {param: ethparams.BalanceGasFrontier, want: uint64(20)}, + "BalanceGasEIP150": {param: ethparams.BalanceGasEIP150, want: uint64(400)}, + "BalanceGasEIP1884": {param: ethparams.BalanceGasEIP1884, want: uint64(700)}, + "ExtcodeSizeGasFrontier": {param: ethparams.ExtcodeSizeGasFrontier, want: uint64(20)}, + "ExtcodeSizeGasEIP150": {param: ethparams.ExtcodeSizeGasEIP150, want: uint64(700)}, + "SloadGasFrontier": {param: ethparams.SloadGasFrontier, want: uint64(50)}, + "SloadGasEIP150": {param: ethparams.SloadGasEIP150, want: uint64(200)}, + "SloadGasEIP1884": {param: ethparams.SloadGasEIP1884, want: uint64(800)}, + "SloadGasEIP2200": {param: ethparams.SloadGasEIP2200, want: uint64(800)}, + "ExtcodeHashGasConstantinople": {param: ethparams.ExtcodeHashGasConstantinople, want: uint64(400)}, + "ExtcodeHashGasEIP1884": {param: ethparams.ExtcodeHashGasEIP1884, want: uint64(700)}, + "SelfdestructGasEIP150": {param: ethparams.SelfdestructGasEIP150, want: uint64(5000)}, + "ExpByteFrontier": {param: ethparams.ExpByteFrontier, want: uint64(10)}, + "ExpByteEIP158": {param: ethparams.ExpByteEIP158, want: uint64(50)}, + "ExtcodeCopyBaseFrontier": {param: ethparams.ExtcodeCopyBaseFrontier, want: uint64(20)}, + "ExtcodeCopyBaseEIP150": {param: ethparams.ExtcodeCopyBaseEIP150, want: uint64(700)}, + "CreateBySelfdestructGas": {param: ethparams.CreateBySelfdestructGas, want: uint64(25000)}, + "DefaultBaseFeeChangeDenominator": {param: ethparams.DefaultBaseFeeChangeDenominator, want: 8}, + "DefaultElasticityMultiplier": {param: ethparams.DefaultElasticityMultiplier, want: 2}, + "InitialBaseFee": {param: ethparams.InitialBaseFee, want: 1000000000}, + "MaxCodeSize": {param: ethparams.MaxCodeSize, want: 24576}, + "MaxInitCodeSize": {param: ethparams.MaxInitCodeSize, want: 2 * 24576}, + "EcrecoverGas": {param: ethparams.EcrecoverGas, want: uint64(3000)}, + "Sha256BaseGas": {param: ethparams.Sha256BaseGas, want: uint64(60)}, + "Sha256PerWordGas": {param: ethparams.Sha256PerWordGas, want: uint64(12)}, + "Ripemd160BaseGas": {param: ethparams.Ripemd160BaseGas, want: uint64(600)}, + "Ripemd160PerWordGas": {param: ethparams.Ripemd160PerWordGas, want: uint64(120)}, + "IdentityBaseGas": {param: ethparams.IdentityBaseGas, want: uint64(15)}, + "IdentityPerWordGas": {param: ethparams.IdentityPerWordGas, want: uint64(3)}, + "Bn256AddGasByzantium": {param: ethparams.Bn256AddGasByzantium, want: uint64(500)}, + "Bn256AddGasIstanbul": {param: ethparams.Bn256AddGasIstanbul, want: uint64(150)}, + "Bn256ScalarMulGasByzantium": {param: ethparams.Bn256ScalarMulGasByzantium, want: uint64(40000)}, + "Bn256ScalarMulGasIstanbul": {param: ethparams.Bn256ScalarMulGasIstanbul, want: uint64(6000)}, + "Bn256PairingBaseGasByzantium": {param: ethparams.Bn256PairingBaseGasByzantium, want: uint64(100000)}, + "Bn256PairingBaseGasIstanbul": {param: ethparams.Bn256PairingBaseGasIstanbul, want: uint64(45000)}, + "Bn256PairingPerPointGasByzantium": {param: ethparams.Bn256PairingPerPointGasByzantium, want: uint64(80000)}, + "Bn256PairingPerPointGasIstanbul": {param: ethparams.Bn256PairingPerPointGasIstanbul, want: uint64(34000)}, + "Bls12381G1AddGas": {param: ethparams.Bls12381G1AddGas, want: uint64(600)}, + "Bls12381G1MulGas": {param: ethparams.Bls12381G1MulGas, want: uint64(12000)}, + "Bls12381G2AddGas": {param: ethparams.Bls12381G2AddGas, want: uint64(4500)}, + "Bls12381G2MulGas": {param: ethparams.Bls12381G2MulGas, want: uint64(55000)}, + "Bls12381PairingBaseGas": {param: ethparams.Bls12381PairingBaseGas, want: uint64(115000)}, + "Bls12381PairingPerPairGas": {param: ethparams.Bls12381PairingPerPairGas, want: uint64(23000)}, + "Bls12381MapG1Gas": {param: ethparams.Bls12381MapG1Gas, want: uint64(5500)}, + "Bls12381MapG2Gas": {param: ethparams.Bls12381MapG2Gas, want: uint64(110000)}, + "RefundQuotient": {param: ethparams.RefundQuotient, want: uint64(2)}, + "RefundQuotientEIP3529": {param: ethparams.RefundQuotientEIP3529, want: uint64(5)}, + "BlobTxBytesPerFieldElement": {param: ethparams.BlobTxBytesPerFieldElement, want: 32}, + "BlobTxFieldElementsPerBlob": {param: ethparams.BlobTxFieldElementsPerBlob, want: 4096}, + "BlobTxBlobGasPerBlob": {param: ethparams.BlobTxBlobGasPerBlob, want: 1 << 17}, + "BlobTxMinBlobGasprice": {param: ethparams.BlobTxMinBlobGasprice, want: 1}, + "BlobTxBlobGaspriceUpdateFraction": {param: ethparams.BlobTxBlobGaspriceUpdateFraction, want: 3338477}, + "BlobTxPointEvaluationPrecompileGas": {param: ethparams.BlobTxPointEvaluationPrecompileGas, want: 50000}, + "BlobTxTargetBlobGasPerBlock": {param: ethparams.BlobTxTargetBlobGasPerBlock, want: 3 * 131072}, + "MaxBlobGasPerBlock": {param: ethparams.MaxBlobGasPerBlock, want: 6 * 131072}, + "GenesisDifficulty": {param: ethparams.GenesisDifficulty.Int64(), want: int64(131072)}, + "BeaconRootsStorageAddress": {param: ethparams.BeaconRootsStorageAddress, want: common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02")}, + "SystemAddress": {param: ethparams.SystemAddress, want: common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe")}, + } + + for name, test := range tests { + assert.Equal(t, test.want, test.param, name) + } } From 135e9a8ac160bdf8ce23e842d8a235c61c455e38 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Fri, 18 Apr 2025 15:03:40 +0200 Subject: [PATCH 4/5] Move test to params/protocol_params_test.go --- params/config_test.go | 132 ------------------------------ params/protocol_params_test.go | 143 +++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 132 deletions(-) create mode 100644 params/protocol_params_test.go diff --git a/params/config_test.go b/params/config_test.go index becf0c80e2..574a2524a4 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -41,7 +41,6 @@ import ( "github.com/ava-labs/subnet-evm/precompile/contracts/rewardmanager" "github.com/ava-labs/subnet-evm/precompile/contracts/txallowlist" "github.com/ava-labs/subnet-evm/utils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -341,134 +340,3 @@ func TestChainConfigMarshalWithUpgrades(t *testing.T) { require.NoError(t, err) require.Equal(t, config, unmarshalled) } - -// TestUpstreamParamsValues detects when a params value changes upstream to prevent a subtle change -// to one of the values to have an unpredicted impact in the libevm consumer. -// Values should be updated to newer upstream values once the consumer is updated to handle the -// updated value(s). -func TestUpstreamParamsValues(t *testing.T) { - tests := map[string]struct { - param any - want any - }{ - "GasLimitBoundDivisor": {param: ethparams.GasLimitBoundDivisor, want: uint64(1024)}, - "MinGasLimit": {param: ethparams.MinGasLimit, want: uint64(5000)}, - "MaxGasLimit": {param: ethparams.MaxGasLimit, want: uint64(0x7fffffffffffffff)}, - "GenesisGasLimit": {param: ethparams.GenesisGasLimit, want: uint64(4712388)}, - "MaximumExtraDataSize": {param: ethparams.MaximumExtraDataSize, want: uint64(32)}, - "ExpByteGas": {param: ethparams.ExpByteGas, want: uint64(10)}, - "SloadGas": {param: ethparams.SloadGas, want: uint64(50)}, - "CallValueTransferGas": {param: ethparams.CallValueTransferGas, want: uint64(9000)}, - "CallNewAccountGas": {param: ethparams.CallNewAccountGas, want: uint64(25000)}, - "TxGas": {param: ethparams.TxGas, want: uint64(21000)}, - "TxGasContractCreation": {param: ethparams.TxGasContractCreation, want: uint64(53000)}, - "TxDataZeroGas": {param: ethparams.TxDataZeroGas, want: uint64(4)}, - "QuadCoeffDiv": {param: ethparams.QuadCoeffDiv, want: uint64(512)}, - "LogDataGas": {param: ethparams.LogDataGas, want: uint64(8)}, - "CallStipend": {param: ethparams.CallStipend, want: uint64(2300)}, - "Keccak256Gas": {param: ethparams.Keccak256Gas, want: uint64(30)}, - "Keccak256WordGas": {param: ethparams.Keccak256WordGas, want: uint64(6)}, - "InitCodeWordGas": {param: ethparams.InitCodeWordGas, want: uint64(2)}, - "SstoreSetGas": {param: ethparams.SstoreSetGas, want: uint64(20000)}, - "SstoreResetGas": {param: ethparams.SstoreResetGas, want: uint64(5000)}, - "SstoreClearGas": {param: ethparams.SstoreClearGas, want: uint64(5000)}, - "SstoreRefundGas": {param: ethparams.SstoreRefundGas, want: uint64(15000)}, - "NetSstoreNoopGas": {param: ethparams.NetSstoreNoopGas, want: uint64(200)}, - "NetSstoreInitGas": {param: ethparams.NetSstoreInitGas, want: uint64(20000)}, - "NetSstoreCleanGas": {param: ethparams.NetSstoreCleanGas, want: uint64(5000)}, - "NetSstoreDirtyGas": {param: ethparams.NetSstoreDirtyGas, want: uint64(200)}, - "NetSstoreClearRefund": {param: ethparams.NetSstoreClearRefund, want: uint64(15000)}, - "NetSstoreResetRefund": {param: ethparams.NetSstoreResetRefund, want: uint64(4800)}, - "NetSstoreResetClearRefund": {param: ethparams.NetSstoreResetClearRefund, want: uint64(19800)}, - "SstoreSentryGasEIP2200": {param: ethparams.SstoreSentryGasEIP2200, want: uint64(2300)}, - "SstoreSetGasEIP2200": {param: ethparams.SstoreSetGasEIP2200, want: uint64(20000)}, - "SstoreResetGasEIP2200": {param: ethparams.SstoreResetGasEIP2200, want: uint64(5000)}, - "SstoreClearsScheduleRefundEIP2200": {param: ethparams.SstoreClearsScheduleRefundEIP2200, want: uint64(15000)}, - "ColdAccountAccessCostEIP2929": {param: ethparams.ColdAccountAccessCostEIP2929, want: uint64(2600)}, - "ColdSloadCostEIP2929": {param: ethparams.ColdSloadCostEIP2929, want: uint64(2100)}, - "WarmStorageReadCostEIP2929": {param: ethparams.WarmStorageReadCostEIP2929, want: uint64(100)}, - "SstoreClearsScheduleRefundEIP3529": {param: ethparams.SstoreClearsScheduleRefundEIP3529, want: uint64(5000 - 2100 + 1900)}, - "JumpdestGas": {param: ethparams.JumpdestGas, want: uint64(1)}, - "EpochDuration": {param: ethparams.EpochDuration, want: uint64(30000)}, - "CreateDataGas": {param: ethparams.CreateDataGas, want: uint64(200)}, - "CallCreateDepth": {param: ethparams.CallCreateDepth, want: uint64(1024)}, - "ExpGas": {param: ethparams.ExpGas, want: uint64(10)}, - "LogGas": {param: ethparams.LogGas, want: uint64(375)}, - "CopyGas": {param: ethparams.CopyGas, want: uint64(3)}, - "StackLimit": {param: ethparams.StackLimit, want: uint64(1024)}, - "TierStepGas": {param: ethparams.TierStepGas, want: uint64(0)}, - "LogTopicGas": {param: ethparams.LogTopicGas, want: uint64(375)}, - "CreateGas": {param: ethparams.CreateGas, want: uint64(32000)}, - "Create2Gas": {param: ethparams.Create2Gas, want: uint64(32000)}, - "SelfdestructRefundGas": {param: ethparams.SelfdestructRefundGas, want: uint64(24000)}, - "MemoryGas": {param: ethparams.MemoryGas, want: uint64(3)}, - "TxDataNonZeroGasFrontier": {param: ethparams.TxDataNonZeroGasFrontier, want: uint64(68)}, - "TxDataNonZeroGasEIP2028": {param: ethparams.TxDataNonZeroGasEIP2028, want: uint64(16)}, - "TxAccessListAddressGas": {param: ethparams.TxAccessListAddressGas, want: uint64(2400)}, - "TxAccessListStorageKeyGas": {param: ethparams.TxAccessListStorageKeyGas, want: uint64(1900)}, - "CallGasFrontier": {param: ethparams.CallGasFrontier, want: uint64(40)}, - "CallGasEIP150": {param: ethparams.CallGasEIP150, want: uint64(700)}, - "BalanceGasFrontier": {param: ethparams.BalanceGasFrontier, want: uint64(20)}, - "BalanceGasEIP150": {param: ethparams.BalanceGasEIP150, want: uint64(400)}, - "BalanceGasEIP1884": {param: ethparams.BalanceGasEIP1884, want: uint64(700)}, - "ExtcodeSizeGasFrontier": {param: ethparams.ExtcodeSizeGasFrontier, want: uint64(20)}, - "ExtcodeSizeGasEIP150": {param: ethparams.ExtcodeSizeGasEIP150, want: uint64(700)}, - "SloadGasFrontier": {param: ethparams.SloadGasFrontier, want: uint64(50)}, - "SloadGasEIP150": {param: ethparams.SloadGasEIP150, want: uint64(200)}, - "SloadGasEIP1884": {param: ethparams.SloadGasEIP1884, want: uint64(800)}, - "SloadGasEIP2200": {param: ethparams.SloadGasEIP2200, want: uint64(800)}, - "ExtcodeHashGasConstantinople": {param: ethparams.ExtcodeHashGasConstantinople, want: uint64(400)}, - "ExtcodeHashGasEIP1884": {param: ethparams.ExtcodeHashGasEIP1884, want: uint64(700)}, - "SelfdestructGasEIP150": {param: ethparams.SelfdestructGasEIP150, want: uint64(5000)}, - "ExpByteFrontier": {param: ethparams.ExpByteFrontier, want: uint64(10)}, - "ExpByteEIP158": {param: ethparams.ExpByteEIP158, want: uint64(50)}, - "ExtcodeCopyBaseFrontier": {param: ethparams.ExtcodeCopyBaseFrontier, want: uint64(20)}, - "ExtcodeCopyBaseEIP150": {param: ethparams.ExtcodeCopyBaseEIP150, want: uint64(700)}, - "CreateBySelfdestructGas": {param: ethparams.CreateBySelfdestructGas, want: uint64(25000)}, - "DefaultBaseFeeChangeDenominator": {param: ethparams.DefaultBaseFeeChangeDenominator, want: 8}, - "DefaultElasticityMultiplier": {param: ethparams.DefaultElasticityMultiplier, want: 2}, - "InitialBaseFee": {param: ethparams.InitialBaseFee, want: 1000000000}, - "MaxCodeSize": {param: ethparams.MaxCodeSize, want: 24576}, - "MaxInitCodeSize": {param: ethparams.MaxInitCodeSize, want: 2 * 24576}, - "EcrecoverGas": {param: ethparams.EcrecoverGas, want: uint64(3000)}, - "Sha256BaseGas": {param: ethparams.Sha256BaseGas, want: uint64(60)}, - "Sha256PerWordGas": {param: ethparams.Sha256PerWordGas, want: uint64(12)}, - "Ripemd160BaseGas": {param: ethparams.Ripemd160BaseGas, want: uint64(600)}, - "Ripemd160PerWordGas": {param: ethparams.Ripemd160PerWordGas, want: uint64(120)}, - "IdentityBaseGas": {param: ethparams.IdentityBaseGas, want: uint64(15)}, - "IdentityPerWordGas": {param: ethparams.IdentityPerWordGas, want: uint64(3)}, - "Bn256AddGasByzantium": {param: ethparams.Bn256AddGasByzantium, want: uint64(500)}, - "Bn256AddGasIstanbul": {param: ethparams.Bn256AddGasIstanbul, want: uint64(150)}, - "Bn256ScalarMulGasByzantium": {param: ethparams.Bn256ScalarMulGasByzantium, want: uint64(40000)}, - "Bn256ScalarMulGasIstanbul": {param: ethparams.Bn256ScalarMulGasIstanbul, want: uint64(6000)}, - "Bn256PairingBaseGasByzantium": {param: ethparams.Bn256PairingBaseGasByzantium, want: uint64(100000)}, - "Bn256PairingBaseGasIstanbul": {param: ethparams.Bn256PairingBaseGasIstanbul, want: uint64(45000)}, - "Bn256PairingPerPointGasByzantium": {param: ethparams.Bn256PairingPerPointGasByzantium, want: uint64(80000)}, - "Bn256PairingPerPointGasIstanbul": {param: ethparams.Bn256PairingPerPointGasIstanbul, want: uint64(34000)}, - "Bls12381G1AddGas": {param: ethparams.Bls12381G1AddGas, want: uint64(600)}, - "Bls12381G1MulGas": {param: ethparams.Bls12381G1MulGas, want: uint64(12000)}, - "Bls12381G2AddGas": {param: ethparams.Bls12381G2AddGas, want: uint64(4500)}, - "Bls12381G2MulGas": {param: ethparams.Bls12381G2MulGas, want: uint64(55000)}, - "Bls12381PairingBaseGas": {param: ethparams.Bls12381PairingBaseGas, want: uint64(115000)}, - "Bls12381PairingPerPairGas": {param: ethparams.Bls12381PairingPerPairGas, want: uint64(23000)}, - "Bls12381MapG1Gas": {param: ethparams.Bls12381MapG1Gas, want: uint64(5500)}, - "Bls12381MapG2Gas": {param: ethparams.Bls12381MapG2Gas, want: uint64(110000)}, - "RefundQuotient": {param: ethparams.RefundQuotient, want: uint64(2)}, - "RefundQuotientEIP3529": {param: ethparams.RefundQuotientEIP3529, want: uint64(5)}, - "BlobTxBytesPerFieldElement": {param: ethparams.BlobTxBytesPerFieldElement, want: 32}, - "BlobTxFieldElementsPerBlob": {param: ethparams.BlobTxFieldElementsPerBlob, want: 4096}, - "BlobTxBlobGasPerBlob": {param: ethparams.BlobTxBlobGasPerBlob, want: 1 << 17}, - "BlobTxMinBlobGasprice": {param: ethparams.BlobTxMinBlobGasprice, want: 1}, - "BlobTxBlobGaspriceUpdateFraction": {param: ethparams.BlobTxBlobGaspriceUpdateFraction, want: 3338477}, - "BlobTxPointEvaluationPrecompileGas": {param: ethparams.BlobTxPointEvaluationPrecompileGas, want: 50000}, - "BlobTxTargetBlobGasPerBlock": {param: ethparams.BlobTxTargetBlobGasPerBlock, want: 3 * 131072}, - "MaxBlobGasPerBlock": {param: ethparams.MaxBlobGasPerBlock, want: 6 * 131072}, - "GenesisDifficulty": {param: ethparams.GenesisDifficulty.Int64(), want: int64(131072)}, - "BeaconRootsStorageAddress": {param: ethparams.BeaconRootsStorageAddress, want: common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02")}, - "SystemAddress": {param: ethparams.SystemAddress, want: common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe")}, - } - - for name, test := range tests { - assert.Equal(t, test.want, test.param, name) - } -} diff --git a/params/protocol_params_test.go b/params/protocol_params_test.go new file mode 100644 index 0000000000..79889454d8 --- /dev/null +++ b/params/protocol_params_test.go @@ -0,0 +1,143 @@ +// (c) 2025, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package params + +import ( + "testing" + + "github.com/ava-labs/libevm/common" + ethparams "github.com/ava-labs/libevm/params" + "github.com/stretchr/testify/assert" +) + +// TestUpstreamParamsValues detects when a params value changes upstream to prevent a subtle change +// to one of the values to have an unpredicted impact in the libevm consumer. +// Values should be updated to newer upstream values once the consumer is updated to handle the +// updated value(s). +func TestUpstreamParamsValues(t *testing.T) { + tests := map[string]struct { + param any + want any + }{ + "GasLimitBoundDivisor": {param: ethparams.GasLimitBoundDivisor, want: uint64(1024)}, + "MinGasLimit": {param: ethparams.MinGasLimit, want: uint64(5000)}, + "MaxGasLimit": {param: ethparams.MaxGasLimit, want: uint64(0x7fffffffffffffff)}, + "GenesisGasLimit": {param: ethparams.GenesisGasLimit, want: uint64(4712388)}, + "MaximumExtraDataSize": {param: ethparams.MaximumExtraDataSize, want: uint64(32)}, + "ExpByteGas": {param: ethparams.ExpByteGas, want: uint64(10)}, + "SloadGas": {param: ethparams.SloadGas, want: uint64(50)}, + "CallValueTransferGas": {param: ethparams.CallValueTransferGas, want: uint64(9000)}, + "CallNewAccountGas": {param: ethparams.CallNewAccountGas, want: uint64(25000)}, + "TxGas": {param: ethparams.TxGas, want: uint64(21000)}, + "TxGasContractCreation": {param: ethparams.TxGasContractCreation, want: uint64(53000)}, + "TxDataZeroGas": {param: ethparams.TxDataZeroGas, want: uint64(4)}, + "QuadCoeffDiv": {param: ethparams.QuadCoeffDiv, want: uint64(512)}, + "LogDataGas": {param: ethparams.LogDataGas, want: uint64(8)}, + "CallStipend": {param: ethparams.CallStipend, want: uint64(2300)}, + "Keccak256Gas": {param: ethparams.Keccak256Gas, want: uint64(30)}, + "Keccak256WordGas": {param: ethparams.Keccak256WordGas, want: uint64(6)}, + "InitCodeWordGas": {param: ethparams.InitCodeWordGas, want: uint64(2)}, + "SstoreSetGas": {param: ethparams.SstoreSetGas, want: uint64(20000)}, + "SstoreResetGas": {param: ethparams.SstoreResetGas, want: uint64(5000)}, + "SstoreClearGas": {param: ethparams.SstoreClearGas, want: uint64(5000)}, + "SstoreRefundGas": {param: ethparams.SstoreRefundGas, want: uint64(15000)}, + "NetSstoreNoopGas": {param: ethparams.NetSstoreNoopGas, want: uint64(200)}, + "NetSstoreInitGas": {param: ethparams.NetSstoreInitGas, want: uint64(20000)}, + "NetSstoreCleanGas": {param: ethparams.NetSstoreCleanGas, want: uint64(5000)}, + "NetSstoreDirtyGas": {param: ethparams.NetSstoreDirtyGas, want: uint64(200)}, + "NetSstoreClearRefund": {param: ethparams.NetSstoreClearRefund, want: uint64(15000)}, + "NetSstoreResetRefund": {param: ethparams.NetSstoreResetRefund, want: uint64(4800)}, + "NetSstoreResetClearRefund": {param: ethparams.NetSstoreResetClearRefund, want: uint64(19800)}, + "SstoreSentryGasEIP2200": {param: ethparams.SstoreSentryGasEIP2200, want: uint64(2300)}, + "SstoreSetGasEIP2200": {param: ethparams.SstoreSetGasEIP2200, want: uint64(20000)}, + "SstoreResetGasEIP2200": {param: ethparams.SstoreResetGasEIP2200, want: uint64(5000)}, + "SstoreClearsScheduleRefundEIP2200": {param: ethparams.SstoreClearsScheduleRefundEIP2200, want: uint64(15000)}, + "ColdAccountAccessCostEIP2929": {param: ethparams.ColdAccountAccessCostEIP2929, want: uint64(2600)}, + "ColdSloadCostEIP2929": {param: ethparams.ColdSloadCostEIP2929, want: uint64(2100)}, + "WarmStorageReadCostEIP2929": {param: ethparams.WarmStorageReadCostEIP2929, want: uint64(100)}, + "SstoreClearsScheduleRefundEIP3529": {param: ethparams.SstoreClearsScheduleRefundEIP3529, want: uint64(5000 - 2100 + 1900)}, + "JumpdestGas": {param: ethparams.JumpdestGas, want: uint64(1)}, + "EpochDuration": {param: ethparams.EpochDuration, want: uint64(30000)}, + "CreateDataGas": {param: ethparams.CreateDataGas, want: uint64(200)}, + "CallCreateDepth": {param: ethparams.CallCreateDepth, want: uint64(1024)}, + "ExpGas": {param: ethparams.ExpGas, want: uint64(10)}, + "LogGas": {param: ethparams.LogGas, want: uint64(375)}, + "CopyGas": {param: ethparams.CopyGas, want: uint64(3)}, + "StackLimit": {param: ethparams.StackLimit, want: uint64(1024)}, + "TierStepGas": {param: ethparams.TierStepGas, want: uint64(0)}, + "LogTopicGas": {param: ethparams.LogTopicGas, want: uint64(375)}, + "CreateGas": {param: ethparams.CreateGas, want: uint64(32000)}, + "Create2Gas": {param: ethparams.Create2Gas, want: uint64(32000)}, + "SelfdestructRefundGas": {param: ethparams.SelfdestructRefundGas, want: uint64(24000)}, + "MemoryGas": {param: ethparams.MemoryGas, want: uint64(3)}, + "TxDataNonZeroGasFrontier": {param: ethparams.TxDataNonZeroGasFrontier, want: uint64(68)}, + "TxDataNonZeroGasEIP2028": {param: ethparams.TxDataNonZeroGasEIP2028, want: uint64(16)}, + "TxAccessListAddressGas": {param: ethparams.TxAccessListAddressGas, want: uint64(2400)}, + "TxAccessListStorageKeyGas": {param: ethparams.TxAccessListStorageKeyGas, want: uint64(1900)}, + "CallGasFrontier": {param: ethparams.CallGasFrontier, want: uint64(40)}, + "CallGasEIP150": {param: ethparams.CallGasEIP150, want: uint64(700)}, + "BalanceGasFrontier": {param: ethparams.BalanceGasFrontier, want: uint64(20)}, + "BalanceGasEIP150": {param: ethparams.BalanceGasEIP150, want: uint64(400)}, + "BalanceGasEIP1884": {param: ethparams.BalanceGasEIP1884, want: uint64(700)}, + "ExtcodeSizeGasFrontier": {param: ethparams.ExtcodeSizeGasFrontier, want: uint64(20)}, + "ExtcodeSizeGasEIP150": {param: ethparams.ExtcodeSizeGasEIP150, want: uint64(700)}, + "SloadGasFrontier": {param: ethparams.SloadGasFrontier, want: uint64(50)}, + "SloadGasEIP150": {param: ethparams.SloadGasEIP150, want: uint64(200)}, + "SloadGasEIP1884": {param: ethparams.SloadGasEIP1884, want: uint64(800)}, + "SloadGasEIP2200": {param: ethparams.SloadGasEIP2200, want: uint64(800)}, + "ExtcodeHashGasConstantinople": {param: ethparams.ExtcodeHashGasConstantinople, want: uint64(400)}, + "ExtcodeHashGasEIP1884": {param: ethparams.ExtcodeHashGasEIP1884, want: uint64(700)}, + "SelfdestructGasEIP150": {param: ethparams.SelfdestructGasEIP150, want: uint64(5000)}, + "ExpByteFrontier": {param: ethparams.ExpByteFrontier, want: uint64(10)}, + "ExpByteEIP158": {param: ethparams.ExpByteEIP158, want: uint64(50)}, + "ExtcodeCopyBaseFrontier": {param: ethparams.ExtcodeCopyBaseFrontier, want: uint64(20)}, + "ExtcodeCopyBaseEIP150": {param: ethparams.ExtcodeCopyBaseEIP150, want: uint64(700)}, + "CreateBySelfdestructGas": {param: ethparams.CreateBySelfdestructGas, want: uint64(25000)}, + "DefaultBaseFeeChangeDenominator": {param: ethparams.DefaultBaseFeeChangeDenominator, want: 8}, + "DefaultElasticityMultiplier": {param: ethparams.DefaultElasticityMultiplier, want: 2}, + "InitialBaseFee": {param: ethparams.InitialBaseFee, want: 1000000000}, + "MaxCodeSize": {param: ethparams.MaxCodeSize, want: 24576}, + "MaxInitCodeSize": {param: ethparams.MaxInitCodeSize, want: 2 * 24576}, + "EcrecoverGas": {param: ethparams.EcrecoverGas, want: uint64(3000)}, + "Sha256BaseGas": {param: ethparams.Sha256BaseGas, want: uint64(60)}, + "Sha256PerWordGas": {param: ethparams.Sha256PerWordGas, want: uint64(12)}, + "Ripemd160BaseGas": {param: ethparams.Ripemd160BaseGas, want: uint64(600)}, + "Ripemd160PerWordGas": {param: ethparams.Ripemd160PerWordGas, want: uint64(120)}, + "IdentityBaseGas": {param: ethparams.IdentityBaseGas, want: uint64(15)}, + "IdentityPerWordGas": {param: ethparams.IdentityPerWordGas, want: uint64(3)}, + "Bn256AddGasByzantium": {param: ethparams.Bn256AddGasByzantium, want: uint64(500)}, + "Bn256AddGasIstanbul": {param: ethparams.Bn256AddGasIstanbul, want: uint64(150)}, + "Bn256ScalarMulGasByzantium": {param: ethparams.Bn256ScalarMulGasByzantium, want: uint64(40000)}, + "Bn256ScalarMulGasIstanbul": {param: ethparams.Bn256ScalarMulGasIstanbul, want: uint64(6000)}, + "Bn256PairingBaseGasByzantium": {param: ethparams.Bn256PairingBaseGasByzantium, want: uint64(100000)}, + "Bn256PairingBaseGasIstanbul": {param: ethparams.Bn256PairingBaseGasIstanbul, want: uint64(45000)}, + "Bn256PairingPerPointGasByzantium": {param: ethparams.Bn256PairingPerPointGasByzantium, want: uint64(80000)}, + "Bn256PairingPerPointGasIstanbul": {param: ethparams.Bn256PairingPerPointGasIstanbul, want: uint64(34000)}, + "Bls12381G1AddGas": {param: ethparams.Bls12381G1AddGas, want: uint64(600)}, + "Bls12381G1MulGas": {param: ethparams.Bls12381G1MulGas, want: uint64(12000)}, + "Bls12381G2AddGas": {param: ethparams.Bls12381G2AddGas, want: uint64(4500)}, + "Bls12381G2MulGas": {param: ethparams.Bls12381G2MulGas, want: uint64(55000)}, + "Bls12381PairingBaseGas": {param: ethparams.Bls12381PairingBaseGas, want: uint64(115000)}, + "Bls12381PairingPerPairGas": {param: ethparams.Bls12381PairingPerPairGas, want: uint64(23000)}, + "Bls12381MapG1Gas": {param: ethparams.Bls12381MapG1Gas, want: uint64(5500)}, + "Bls12381MapG2Gas": {param: ethparams.Bls12381MapG2Gas, want: uint64(110000)}, + "RefundQuotient": {param: ethparams.RefundQuotient, want: uint64(2)}, + "RefundQuotientEIP3529": {param: ethparams.RefundQuotientEIP3529, want: uint64(5)}, + "BlobTxBytesPerFieldElement": {param: ethparams.BlobTxBytesPerFieldElement, want: 32}, + "BlobTxFieldElementsPerBlob": {param: ethparams.BlobTxFieldElementsPerBlob, want: 4096}, + "BlobTxBlobGasPerBlob": {param: ethparams.BlobTxBlobGasPerBlob, want: 1 << 17}, + "BlobTxMinBlobGasprice": {param: ethparams.BlobTxMinBlobGasprice, want: 1}, + "BlobTxBlobGaspriceUpdateFraction": {param: ethparams.BlobTxBlobGaspriceUpdateFraction, want: 3338477}, + "BlobTxPointEvaluationPrecompileGas": {param: ethparams.BlobTxPointEvaluationPrecompileGas, want: 50000}, + "BlobTxTargetBlobGasPerBlock": {param: ethparams.BlobTxTargetBlobGasPerBlock, want: 3 * 131072}, + "MaxBlobGasPerBlock": {param: ethparams.MaxBlobGasPerBlock, want: 6 * 131072}, + "GenesisDifficulty": {param: ethparams.GenesisDifficulty.Int64(), want: int64(131072)}, + "BeaconRootsStorageAddress": {param: ethparams.BeaconRootsStorageAddress, want: common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02")}, + "SystemAddress": {param: ethparams.SystemAddress, want: common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe")}, + } + + for name, test := range tests { + assert.Equal(t, test.want, test.param, name) + } +} From 1ef15ea3dd575cd858920dceb95c5af1e0af72ec Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Fri, 18 Apr 2025 15:07:38 +0200 Subject: [PATCH 5/5] Remove MaximumExtraDataSize test case --- params/protocol_params_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/params/protocol_params_test.go b/params/protocol_params_test.go index 79889454d8..a732b5dd45 100644 --- a/params/protocol_params_test.go +++ b/params/protocol_params_test.go @@ -24,7 +24,6 @@ func TestUpstreamParamsValues(t *testing.T) { "MinGasLimit": {param: ethparams.MinGasLimit, want: uint64(5000)}, "MaxGasLimit": {param: ethparams.MaxGasLimit, want: uint64(0x7fffffffffffffff)}, "GenesisGasLimit": {param: ethparams.GenesisGasLimit, want: uint64(4712388)}, - "MaximumExtraDataSize": {param: ethparams.MaximumExtraDataSize, want: uint64(32)}, "ExpByteGas": {param: ethparams.ExpByteGas, want: uint64(10)}, "SloadGas": {param: ethparams.SloadGas, want: uint64(50)}, "CallValueTransferGas": {param: ethparams.CallValueTransferGas, want: uint64(9000)},