diff --git a/consensus/misc/eip4844/eip4844.go b/consensus/misc/eip4844/eip4844.go index a3a8e675df..51fe31da1f 100644 --- a/consensus/misc/eip4844/eip4844.go +++ b/consensus/misc/eip4844/eip4844.go @@ -32,13 +32,13 @@ import ( "fmt" "math/big" - "github.com/ava-labs/coreth/params" "github.com/ava-labs/libevm/core/types" + 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 @@ -53,11 +53,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 ( @@ -80,10 +80,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 8e273e8649..2c4fd87063 100644 --- a/consensus/misc/eip4844/eip4844_test.go +++ b/consensus/misc/eip4844/eip4844_test.go @@ -32,7 +32,7 @@ import ( "math/big" "testing" - "github.com/ava-labs/coreth/params" + ethparams "github.com/ava-labs/libevm/params" ) func TestCalcExcessBlobGas(t *testing.T) { @@ -45,23 +45,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 edd3ae430d..0ef46235fc 100644 --- a/core/bench_test.go +++ b/core/bench_test.go @@ -41,6 +41,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" ) func BenchmarkInsertChain_empty_memdb(b *testing.B) { @@ -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 5d96b824a4..d019d830d0 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -36,6 +36,7 @@ import ( "github.com/ava-labs/coreth/plugin/evm/upgrade/ap0" "github.com/ava-labs/libevm/core/state" "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" "github.com/ava-labs/libevm/trie" ) @@ -98,8 +99,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 { @@ -149,10 +150,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) / ap0.GasLimitBoundDivisor + contrib := (parentGasUsed + parentGasUsed/2) / ethparams.GasLimitBoundDivisor // decay = parentGasLimit / 1024 -1 - decay := parentGasLimit/ap0.GasLimitBoundDivisor - 1 + decay := parentGasLimit/ethparams.GasLimitBoundDivisor - 1 /* strategy: gasLimit of block-to-mine is set based on parent's diff --git a/core/blockchain_ext_test.go b/core/blockchain_ext_test.go index 40cf0d14fc..ac269e7b6c 100644 --- a/core/blockchain_ext_test.go +++ b/core/blockchain_ext_test.go @@ -21,6 +21,8 @@ import ( "github.com/ava-labs/coreth/core/extstate" "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/plugin/evm/upgrade/ap4" + + ethparams "github.com/ava-labs/libevm/params" ) var ( @@ -270,7 +272,7 @@ func InsertChainAcceptSingleBlockTest(t *testing.T, create createFunc) { // This call generates a chain of 3 blocks. signer := types.HomesteadSigner{} _, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, 10, func(_ 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 { @@ -342,7 +344,7 @@ func InsertLongForkedChainTest(t *testing.T, create createFunc) { signer := types.HomesteadSigner{} _, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(_ 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 { @@ -352,7 +354,7 @@ func InsertLongForkedChainTest(t *testing.T, create createFunc) { // a longer chain can trigger a reorg. _, chain2, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks+1, 10, func(_ 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 { @@ -508,7 +510,7 @@ func AcceptNonCanonicalBlockTest(t *testing.T, create createFunc) { signer := types.HomesteadSigner{} _, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(_ 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 { @@ -516,7 +518,7 @@ func AcceptNonCanonicalBlockTest(t *testing.T, create createFunc) { } _, chain2, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(_ 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 { @@ -617,7 +619,7 @@ func SetPreferenceRewindTest(t *testing.T, create createFunc) { signer := types.HomesteadSigner{} _, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(_ 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 { @@ -755,10 +757,10 @@ func BuildOnVariousStagesTest(t *testing.T, create createFunc) { 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) } }) @@ -769,10 +771,10 @@ func BuildOnVariousStagesTest(t *testing.T, create createFunc) { 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) } }) @@ -785,10 +787,10 @@ func BuildOnVariousStagesTest(t *testing.T, create createFunc) { 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) } }) @@ -954,7 +956,7 @@ func EmptyAndNonEmptyBlocksTest(t *testing.T, create createFunc) { _, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 5, 10, func(i int, gen *BlockGen) { if i == 3 { // Generate a transaction to create a unique block - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), types.HomesteadSigner{}, key1) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), types.HomesteadSigner{}, key1) gen.AddTx(tx) } }) @@ -1025,7 +1027,7 @@ func ReorgReInsertTest(t *testing.T, create createFunc) { numBlocks := 3 _, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(_ 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 { @@ -1131,7 +1133,7 @@ func AcceptBlockIdenticalStateRootTest(t *testing.T, create createFunc) { _, 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. @@ -1143,10 +1145,10 @@ func AcceptBlockIdenticalStateRootTest(t *testing.T, create createFunc) { // 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) } }) @@ -1274,7 +1276,7 @@ func ReprocessAcceptBlockIdenticalStateRootTest(t *testing.T, create createFunc) _, 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. @@ -1286,10 +1288,10 @@ func ReprocessAcceptBlockIdenticalStateRootTest(t *testing.T, create createFunc) // 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) } }) @@ -1432,7 +1434,7 @@ func GenerateChainInvalidBlockFeeTest(t *testing.T, create createFunc) { 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{}, @@ -1474,7 +1476,7 @@ func InsertChainInvalidBlockFeeTest(t *testing.T, create createFunc) { 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{}, @@ -1522,7 +1524,7 @@ func InsertChainValidBlockFeeTest(t *testing.T, create createFunc) { ChainID: params.TestChainConfig.ChainID, Nonce: gen.TxNonce(addr1), To: &addr2, - Gas: params.TxGas, + Gas: ethparams.TxGas, Value: transfer, GasFeeCap: feeCap, GasTipCap: tip, @@ -1552,7 +1554,7 @@ func InsertChainValidBlockFeeTest(t *testing.T, create createFunc) { genesisBalance := uint256.MustFromBig(genesisBalance) expectedBalance1 := new(uint256.Int).Sub(genesisBalance, transfer) baseFee := chain[0].BaseFee() - 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) @@ -1599,7 +1601,7 @@ func ReexecBlocksTest(t *testing.T, create ReexecTestFunc) { // This call generates a chain of 10 blocks. signer := types.HomesteadSigner{} _, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 10, 10, func(_ 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 { @@ -1733,7 +1735,7 @@ func ReexecMaxBlocksTest(t *testing.T, create ReexecTestFunc) { signer := types.HomesteadSigner{} _, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, genNumBlocks, 10, func(_ 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 { diff --git a/core/blockchain_repair_test.go b/core/blockchain_repair_test.go index 6a30086951..c493e367d7 100644 --- a/core/blockchain_repair_test.go +++ b/core/blockchain_repair_test.go @@ -44,6 +44,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/stretchr/testify/require" ) @@ -576,7 +577,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, big.NewInt(ap3.InitialBaseFee), nil), signer, key1) + tx, err := types.SignTx(types.NewTransaction(b.TxNonce(addr1), common.Address{0x01}, big.NewInt(10000), ethparams.TxGas, big.NewInt(ap3.InitialBaseFee), nil), signer, key1) require.NoError(err) b.AddTx(tx) }) @@ -590,7 +591,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, big.NewInt(ap3.InitialBaseFee), nil), signer, key1) + tx, err := types.SignTx(types.NewTransaction(b.TxNonce(addr1), common.Address{0x02}, big.NewInt(10000), ethparams.TxGas, big.NewInt(ap3.InitialBaseFee), nil), signer, key1) require.NoError(err) b.AddTx(tx) }) diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 5c3b98d34d..d19c02b884 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -46,6 +46,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" ) var ( @@ -433,7 +434,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 { @@ -1108,8 +1109,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 2bae562610..5177131500 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -38,6 +38,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" ) @@ -68,15 +69,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 c6767ba1b7..5e282e9925 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -47,6 +47,7 @@ import ( "github.com/ava-labs/libevm/ethdb" "github.com/ava-labs/libevm/libevm/stateconf" "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/holiman/uint256" @@ -270,10 +271,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 b17a679561..2a19c117af 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -39,6 +39,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" ) // StateProcessor is a basic Processor, which takes care of transitioning @@ -149,7 +150,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 } @@ -188,16 +189,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_test.go b/core/state_processor_test.go index 4e18b4ce81..7f2c6ea57c 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -50,6 +50,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/holiman/uint256" "golang.org/x/crypto/sha3" @@ -130,7 +131,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() @@ -143,14 +144,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", }, @@ -163,13 +164,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", }, @@ -179,38 +180,38 @@ 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{ // This test was modified to account for ACP-176 gas limits - makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas*953, big.NewInt(acp176.MinGasPrice), nil), + makeTx(key1, 0, common.Address{}, big.NewInt(0), ethparams.TxGas*953, big.NewInt(acp176.MinGasPrice), nil), }, want: "could not apply tx 0 [0xcd46718c1af6fd074deb6b036d34c1cb499517bf90d93df74dcfaba25fdf34af]: 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: 1", }, { // 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", }, @@ -221,13 +222,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", }, @@ -245,7 +246,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 blob gas less than block blob gas fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7 blobGasFeeCap: 0, blobBaseFee: 1", }, @@ -304,7 +305,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", }, @@ -344,7 +345,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", }, @@ -417,7 +418,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 fb2c48e2c0..5eaa60ab74 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -40,6 +40,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/holiman/uint256" ) @@ -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 @@ -475,8 +476,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: @@ -555,5 +556,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/txindexer_test.go b/core/txindexer_test.go index 30a26e171c..1056c34b05 100644 --- a/core/txindexer_test.go +++ b/core/txindexer_test.go @@ -40,6 +40,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/stretchr/testify/require" ) @@ -61,14 +62,14 @@ func TestTransactionIndices(t *testing.T) { signer = types.LatestSigner(gspec.Config) ) genDb, blocks, _, err := GenerateChainWithGenesis(gspec, dummy.NewFakerWithCallbacks(TestCallbacks), 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.NewFakerWithCallbacks(TestCallbacks), 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) }) @@ -181,14 +182,14 @@ func TestTransactionSkipIndexing(t *testing.T) { signer = types.LatestSigner(gspec.Config) ) genDb, blocks, _, err := GenerateChainWithGenesis(gspec, dummy.NewFakerWithCallbacks(TestCallbacks), 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.NewFakerWithCallbacks(TestCallbacks), 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 a2384e5c61..d944c07c01 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -51,6 +51,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/holiman/billy" "github.com/holiman/uint256" @@ -59,12 +60,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. @@ -423,7 +424,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)) @@ -854,7 +855,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 a8ca72a261..dc70016fec 100644 --- a/core/txpool/blobpool/blobpool_test.go +++ b/core/txpool/blobpool/blobpool_test.go @@ -54,6 +54,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/holiman/billy" "github.com/holiman/uint256" @@ -585,7 +586,7 @@ func TestOpenDrops(t *testing.T) { chain := &testBlockChain{ config: testChainConfig, basefee: uint256.NewInt(ap3.MinBaseFee), - blobfee: uint256.NewInt(params.BlobTxMinBlobGasprice), + blobfee: uint256.NewInt(ethparams.BlobTxMinBlobGasprice), statedb: statedb, } pool := New(Config{Datadir: storage}, chain) @@ -704,7 +705,7 @@ func TestOpenIndex(t *testing.T) { chain := &testBlockChain{ config: testChainConfig, basefee: uint256.NewInt(ap3.MinBaseFee), - blobfee: uint256.NewInt(params.BlobTxMinBlobGasprice), + blobfee: uint256.NewInt(ethparams.BlobTxMinBlobGasprice), statedb: statedb, } pool := New(Config{Datadir: storage}, chain) @@ -1263,7 +1264,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, }, }, @@ -1338,7 +1339,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 ce7ce502e8..d52b0135df 100644 --- a/core/txpool/blobpool/evictheap_test.go +++ b/core/txpool/blobpool/evictheap_test.go @@ -32,8 +32,8 @@ import ( mrand "math/rand" "testing" - "github.com/ava-labs/coreth/params" "github.com/ava-labs/libevm/common" + ethparams "github.com/ava-labs/libevm/params" "github.com/holiman/uint256" ) @@ -197,7 +197,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. @@ -257,7 +257,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 09d21df35b..d6cae9dceb 100644 --- a/core/txpool/validation.go +++ b/core/txpool/validation.go @@ -40,12 +40,13 @@ 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" ) 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 @@ -85,8 +86,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. @@ -146,8 +147,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 a8a55ece20..1fa286279c 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -40,6 +40,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/holiman/uint256" ) @@ -122,7 +123,7 @@ func setDefaults(cfg *Config) { cfg.BaseFee = big.NewInt(ap3.InitialBaseFee) } 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 3fc7274f24..00990c61cf 100644 --- a/eth/gasestimator/gasestimator.go +++ b/eth/gasestimator/gasestimator.go @@ -41,6 +41,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" ) // Options are the contextual parameters to execute the requested call. @@ -68,7 +69,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. @@ -115,9 +116,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 } } } @@ -143,7 +144,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 51af6e79a7..aba2cd731e 100644 --- a/eth/gasprice/feehistory_test.go +++ b/eth/gasprice/feehistory_test.go @@ -34,12 +34,12 @@ import ( "testing" "github.com/ava-labs/coreth/core" - "github.com/ava-labs/libevm/core/types" - "github.com/stretchr/testify/require" - "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/rpc" "github.com/ava-labs/libevm/common" + "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" + "github.com/stretchr/testify/require" ) func TestFeeHistory(t *testing.T) { @@ -95,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 6ad8b9ef51..5652df812d 100644 --- a/eth/gasprice/gasprice_test.go +++ b/eth/gasprice/gasprice_test.go @@ -48,6 +48,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/stretchr/testify/require" ) @@ -236,7 +237,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{}, @@ -362,7 +363,7 @@ func TestSuggestGasPricePreAP3(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{}, }) @@ -404,7 +405,7 @@ func TestSuggestTipCapIncludesExtraDataGas(t *testing.T) { applyGasPriceTest(t, suggestTipCapTest{ chainConfig: params.TestChainConfig, numBlocks: 1000, - extDataGasUsage: big.NewInt(acp176.MinMaxPerSecond - int64(params.TxGas)), + extDataGasUsage: big.NewInt(acp176.MinMaxPerSecond - int64(ethparams.TxGas)), // The tip on the transaction is very large to pay the block gas cost. genBlock: testGenBlock(t, 100_000, 1), // The actual tip doesn't matter, we just want to ensure that the tip is diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go index c1aaca9a58..7f7f205c2d 100644 --- a/eth/tracers/api_test.go +++ b/eth/tracers/api_test.go @@ -54,6 +54,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" "golang.org/x/exp/slices" ) @@ -264,7 +265,7 @@ func testTraceCall(t *testing.T, scheme string) { 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) @@ -277,7 +278,7 @@ func testTraceCall(t *testing.T, scheme string) { 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) @@ -289,7 +290,7 @@ func testTraceCall(t *testing.T, scheme string) { 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) @@ -487,7 +488,7 @@ func testTraceTransaction(t *testing.T, scheme string) { 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) @@ -505,7 +506,7 @@ func testTraceTransaction(t *testing.T, scheme string) { t.Errorf("failed to unmarshal result %v", err) } expected := &logger.ExecutionResult{ - Gas: params.TxGas, + Gas: ethparams.TxGas, Failed: false, ReturnValue: "", StructLogs: []logger.StructLogRes{}, @@ -552,7 +553,7 @@ func testTraceBlock(t *testing.T, scheme string) { 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) @@ -657,7 +658,7 @@ func testTracingWithOverrides(t *testing.T, scheme string) { 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) @@ -1031,7 +1032,7 @@ func testTraceChain(t *testing.T, scheme string) { // 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 20b53817c9..5504315f29 100644 --- a/ethclient/simulated/backend_test.go +++ b/ethclient/simulated/backend_test.go @@ -36,11 +36,11 @@ import ( "time" "github.com/ava-labs/coreth/accounts/abi/bind" - "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/rpc" "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/stretchr/testify/require" ) @@ -64,7 +64,7 @@ func newTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) { // create a signed transaction to send head, _ := client.HeaderByNumber(context.Background(), nil) // Should be child's, good enough - gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(params.GWei)) + gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(ethparams.GWei)) addr := crypto.PubkeyToAddress(key.PublicKey) chainid, _ := client.ChainID(context.Background()) nonce, err := client.NonceAt(context.Background(), addr, nil) @@ -74,7 +74,7 @@ func newTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) { tx := types.NewTx(&types.DynamicFeeTx{ ChainID: chainid, Nonce: nonce, - GasTipCap: big.NewInt(params.GWei), + GasTipCap: big.NewInt(ethparams.GWei), GasFeeCap: gasPrice, Gas: 21000, To: &addr, @@ -277,7 +277,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 a41acf78b1..ac856e221d 100644 --- a/ethclient/simulated/options_test.go +++ b/ethclient/simulated/options_test.go @@ -34,10 +34,10 @@ import ( "testing" "github.com/ava-labs/coreth/core" - "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/plugin/evm/upgrade/acp176" ethereum "github.com/ava-labs/libevm" "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" ) // Tests that the simulator starts with the initial gas limit in the genesis block, @@ -71,7 +71,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 90d6a81c82..798109e95c 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -63,6 +63,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/holiman/uint256" "github.com/stretchr/testify/require" "golang.org/x/exp/slices" @@ -655,7 +656,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() })) @@ -816,7 +817,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() })) @@ -1585,7 +1586,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) @@ -1844,7 +1845,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) @@ -1875,7 +1876,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 2c0adc0619..92c1ed66da 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -45,11 +45,12 @@ 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/holiman/uint256" ) 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 0ba5b73778..a2b121bbd5 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -56,6 +56,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/holiman/uint256" ) @@ -334,7 +335,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) @@ -387,20 +388,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 @@ -434,7 +435,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 @@ -542,7 +543,7 @@ func (w *worker) handleResult(env *environment, block *types.Block, createdAt ti logs = append(logs, receipt.Logs...) } fees := totalFees(block, receipts) - feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(params.Ether)) + feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(ethparams.Ether)) log.Info("Commit new mining work", "number", block.Number(), "hash", hash, "uncles", 0, "txs", env.tcount, "gas", block.GasUsed(), "fees", feesInEther, diff --git a/nativeasset/contract_test.go b/nativeasset/contract_test.go index 81a9d89466..95cd169d1f 100644 --- a/nativeasset/contract_test.go +++ b/nativeasset/contract_test.go @@ -22,6 +22,7 @@ import ( "github.com/ava-labs/coreth/params" ethtypes "github.com/ava-labs/libevm/core/types" + ethparams "github.com/ava-labs/libevm/params" . "github.com/ava-labs/coreth/nativeasset" ) @@ -240,7 +241,7 @@ func TestStatefulPrecompile(t *testing.T) { precompileAddr: NativeAssetCallAddr, input: PackNativeAssetCallInput(userAddr2, assetID, big.NewInt(50), nil), value: big0, - gasInput: params.AssetCallApricot + params.CallNewAccountGas + 123, + gasInput: params.AssetCallApricot + ethparams.CallNewAccountGas + 123, expectedGasRemaining: 123, expectedErr: nil, expectedResult: nil, @@ -275,7 +276,7 @@ func TestStatefulPrecompile(t *testing.T) { precompileAddr: NativeAssetCallAddr, input: PackNativeAssetCallInput(userAddr2, assetID, big.NewInt(50), nil), value: uint256.NewInt(49), - gasInput: params.AssetCallApricot + params.CallNewAccountGas, + gasInput: params.AssetCallApricot + ethparams.CallNewAccountGas, expectedGasRemaining: 0, expectedErr: nil, expectedResult: nil, @@ -402,7 +403,7 @@ func TestStatefulPrecompile(t *testing.T) { precompileAddr: NativeAssetCallAddr, input: PackNativeAssetCallInput(userAddr2, assetID, big.NewInt(50), nil), value: uint256.NewInt(50), - gasInput: params.AssetCallApricot + params.CallNewAccountGas - 1, + gasInput: params.AssetCallApricot + ethparams.CallNewAccountGas - 1, expectedGasRemaining: 0, expectedErr: vm.ErrOutOfGas, expectedResult: nil, @@ -436,8 +437,8 @@ func TestStatefulPrecompile(t *testing.T) { precompileAddr: NativeAssetCallAddr, input: make([]byte, 24), value: uint256.NewInt(50), - gasInput: params.AssetCallApricot + params.CallNewAccountGas, - expectedGasRemaining: params.CallNewAccountGas, + gasInput: params.AssetCallApricot + ethparams.CallNewAccountGas, + expectedGasRemaining: ethparams.CallNewAccountGas, expectedErr: vm.ErrExecutionReverted, expectedResult: nil, name: "native asset call: invalid input", @@ -458,8 +459,8 @@ func TestStatefulPrecompile(t *testing.T) { precompileAddr: GenesisContractAddr, input: PackNativeAssetCallInput(userAddr2, assetID, big.NewInt(50), nil), value: big0, - gasInput: params.AssetCallApricot + params.CallNewAccountGas, - expectedGasRemaining: params.AssetCallApricot + params.CallNewAccountGas, + gasInput: params.AssetCallApricot + ethparams.CallNewAccountGas, + expectedGasRemaining: params.AssetCallApricot + ethparams.CallNewAccountGas, expectedErr: vm.ErrExecutionReverted, expectedResult: nil, name: "deprecated contract", diff --git a/params/hooks_libevm.go b/params/hooks_libevm.go index 8a22cece4a..1c2357c935 100644 --- a/params/hooks_libevm.go +++ b/params/hooks_libevm.go @@ -50,7 +50,7 @@ func (RulesExtra) MinimumGasConsumption(x uint64) uint64 { var PrecompiledContractsApricotPhase2 = map[common.Address]contract.StatefulPrecompiledContract{ nativeasset.GenesisContractAddr: &nativeasset.DeprecatedContract{}, nativeasset.NativeAssetBalanceAddr: &nativeasset.NativeAssetBalance{GasCost: AssetBalanceApricot}, - nativeasset.NativeAssetCallAddr: &nativeasset.NativeAssetCall{GasCost: AssetCallApricot, CallNewAccountGas: CallNewAccountGas}, + nativeasset.NativeAssetCallAddr: &nativeasset.NativeAssetCall{GasCost: AssetCallApricot, CallNewAccountGas: ethparams.CallNewAccountGas}, } var PrecompiledContractsApricotPhasePre6 = map[common.Address]contract.StatefulPrecompiledContract{ @@ -62,7 +62,7 @@ var PrecompiledContractsApricotPhasePre6 = map[common.Address]contract.StatefulP var PrecompiledContractsApricotPhase6 = map[common.Address]contract.StatefulPrecompiledContract{ nativeasset.GenesisContractAddr: &nativeasset.DeprecatedContract{}, nativeasset.NativeAssetBalanceAddr: &nativeasset.NativeAssetBalance{GasCost: AssetBalanceApricot}, - nativeasset.NativeAssetCallAddr: &nativeasset.NativeAssetCall{GasCost: AssetCallApricot, CallNewAccountGas: CallNewAccountGas}, + nativeasset.NativeAssetCallAddr: &nativeasset.NativeAssetCall{GasCost: AssetCallApricot, CallNewAccountGas: ethparams.CallNewAccountGas}, } var PrecompiledContractsBanff = map[common.Address]contract.StatefulPrecompiledContract{ diff --git a/params/protocol_params.go b/params/protocol_params.go deleted file mode 100644 index 71f0d3e0eb..0000000000 --- a/params/protocol_params.go +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. -// -// 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 -) - -const ( - // Avalanche Stateful Precompile Params - // Gas price for native asset balance lookup. Based on the cost of an SLOAD operation since native - // asset balances are kept in state storage. - AssetBalanceApricot uint64 = 2100 - // Gas price for native asset call. This gas price reflects the additional work done for the native - // asset transfer itself, which is a write to state storage. The cost of creating a new account and - // normal value transfer is assessed separately from this cost. - AssetCallApricot uint64 = 20000 -) - -// 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/params/protocol_params_ext.go b/params/protocol_params_ext.go new file mode 100644 index 0000000000..8612ae0b39 --- /dev/null +++ b/params/protocol_params_ext.go @@ -0,0 +1,15 @@ +// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package params + +const ( + // Avalanche Stateful Precompile Params + // Gas price for native asset balance lookup. Based on the cost of an SLOAD operation since native + // asset balances are kept in state storage. + AssetBalanceApricot uint64 = 2100 + // Gas price for native asset call. This gas price reflects the additional work done for the native + // asset transfer itself, which is a write to state storage. The cost of creating a new account and + // normal value transfer is assessed separately from this cost. + AssetCallApricot uint64 = 20000 +) diff --git a/params/protocol_params_test.go b/params/protocol_params_test.go new file mode 100644 index 0000000000..23b2fedd41 --- /dev/null +++ b/params/protocol_params_test.go @@ -0,0 +1,143 @@ +// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package params + +import ( + "testing" + + "github.com/ava-labs/libevm/common" + "github.com/stretchr/testify/assert" + + ethparams "github.com/ava-labs/libevm/params" +) + +// 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)}, + "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/plugin/evm/atomic/vm/syncervm_test.go b/plugin/evm/atomic/vm/syncervm_test.go index 5490f19abc..50e7185141 100644 --- a/plugin/evm/atomic/vm/syncervm_test.go +++ b/plugin/evm/atomic/vm/syncervm_test.go @@ -17,11 +17,12 @@ import ( "github.com/ava-labs/coreth/consensus/dummy" "github.com/ava-labs/coreth/core" "github.com/ava-labs/coreth/core/extstate" - "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/coreth/plugin/evm/atomic/atomictest" "github.com/ava-labs/coreth/plugin/evm/extension" "github.com/ava-labs/coreth/plugin/evm/vmtest" + + ethparams "github.com/ava-labs/libevm/params" ) func TestAtomicSyncerVM(t *testing.T) { @@ -65,7 +66,7 @@ func TestAtomicSyncerVM(t *testing.T) { includedAtomicTxs = append(includedAtomicTxs, exportTx) default: // Generate simple transfer transactions. pk := vmtest.TestKeys[0].ToECDSA() - tx := types.NewTransaction(gen.TxNonce(vmtest.TestEthAddrs[0]), vmtest.TestEthAddrs[1], common.Big1, params.TxGas, vmtest.InitialBaseFee, nil) + tx := types.NewTransaction(gen.TxNonce(vmtest.TestEthAddrs[0]), vmtest.TestEthAddrs[1], common.Big1, ethparams.TxGas, vmtest.InitialBaseFee, nil) signedTx, err := types.SignTx(tx, types.NewEIP155Signer(vm.Ethereum().BlockChain().Config().ChainID), pk) require.NoError(t, err) gen.AddTx(signedTx) diff --git a/plugin/evm/syncervm_test.go b/plugin/evm/syncervm_test.go index ace95098aa..e2cd900a3f 100644 --- a/plugin/evm/syncervm_test.go +++ b/plugin/evm/syncervm_test.go @@ -13,9 +13,10 @@ import ( "github.com/ava-labs/coreth/consensus/dummy" "github.com/ava-labs/coreth/core" - "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/plugin/evm/extension" "github.com/ava-labs/coreth/plugin/evm/vmtest" + + ethparams "github.com/ava-labs/libevm/params" ) func TestEVMSyncerVM(t *testing.T) { @@ -27,7 +28,7 @@ func TestEVMSyncerVM(t *testing.T) { require.NoError(t, err) gen.AppendExtra(b) - tx := types.NewTransaction(gen.TxNonce(vmtest.TestEthAddrs[0]), vmtest.TestEthAddrs[1], common.Big1, params.TxGas, vmtest.InitialBaseFee, nil) + tx := types.NewTransaction(gen.TxNonce(vmtest.TestEthAddrs[0]), vmtest.TestEthAddrs[1], common.Big1, ethparams.TxGas, vmtest.InitialBaseFee, nil) signedTx, err := types.SignTx(tx, types.NewEIP155Signer(vm.Ethereum().BlockChain().Config().ChainID), vmtest.TestKeys[0].ToECDSA()) require.NoError(t, err) gen.AddTx(signedTx) diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index d55302ec94..f12d6f41ab 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -47,6 +47,7 @@ import ( "github.com/ava-labs/coreth/utils" commonEng "github.com/ava-labs/avalanchego/snow/engine/common" + ethparams "github.com/ava-labs/libevm/params" ) var ( @@ -1691,7 +1692,7 @@ func TestNoBlobsAllowed(t *testing.T) { Nonce: 0, GasTipCap: uint256.NewInt(1), GasFeeCap: uint256.MustFromBig(fee), - Gas: params.TxGas, + Gas: ethparams.TxGas, To: vmtest.TestEthAddrs[0], BlobFeeCap: uint256.NewInt(1), BlobHashes: []common.Hash{{1}}, // This blob is expected to cause verification to fail @@ -1782,7 +1783,7 @@ func TestBuildBlockLargeTxStarvation(t *testing.T) { require := require.New(t) fork := upgradetest.Fortuna - amount := new(big.Int).Mul(big.NewInt(params.Ether), big.NewInt(4000)) + amount := new(big.Int).Mul(big.NewInt(ethparams.Ether), big.NewInt(4000)) genesis := vmtest.NewTestGenesis(vmtest.ForkToChainConfig[fork]) for _, addr := range vmtest.TestEthAddrs { genesis.Alloc[addr] = types.Account{Balance: amount} diff --git a/sync/blocksync/syncer_test.go b/sync/blocksync/syncer_test.go index 30ca510efe..c9d344129a 100644 --- a/sync/blocksync/syncer_test.go +++ b/sync/blocksync/syncer_test.go @@ -24,6 +24,7 @@ import ( syncclient "github.com/ava-labs/coreth/sync/client" handlerstats "github.com/ava-labs/coreth/sync/handlers/stats" + ethparams "github.com/ava-labs/libevm/params" ) func TestBlockSyncer_ParameterizedTests(t *testing.T) { @@ -157,7 +158,7 @@ func newTestEnvironment(t *testing.T, numBlocks int) *testEnvironment { _, blocks, _, err := core.GenerateChainWithGenesis(gspec, engine, numBlocks, 0, func(_ int, gen *core.BlockGen) { // Generate a transaction to create a unique block - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr), addr, big.NewInt(10), params.TxGas, nil, nil), signer, key) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr), addr, big.NewInt(10), ethparams.TxGas, nil, nil), signer, key) gen.AddTx(tx) }) require.NoError(t, err) diff --git a/sync/client/client.go b/sync/client/client.go index ab2eb632c1..14c4837dec 100644 --- a/sync/client/client.go +++ b/sync/client/client.go @@ -23,9 +23,10 @@ import ( "github.com/ava-labs/libevm/trie" "github.com/ava-labs/coreth/network" - "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/plugin/evm/message" "github.com/ava-labs/coreth/sync/client/stats" + + ethparams "github.com/ava-labs/libevm/params" ) const ( @@ -264,7 +265,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 ef3e8cd490..5f5c1bfc9c 100644 --- a/sync/client/client_test.go +++ b/sync/client/client_test.go @@ -28,6 +28,7 @@ import ( clientstats "github.com/ava-labs/coreth/sync/client/stats" handlerstats "github.com/ava-labs/coreth/sync/handlers/stats" + ethparams "github.com/ava-labs/libevm/params" ) func TestGetCode(t *testing.T) { @@ -74,7 +75,7 @@ func TestGetCode(t *testing.T) { }, "code size is too large": { setupRequest: func() (requestHashes []common.Hash, testResponse 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 9ca3f15582..4a3d64e31c 100644 --- a/sync/handlers/code_request_test.go +++ b/sync/handlers/code_request_test.go @@ -15,9 +15,10 @@ import ( "github.com/ava-labs/libevm/ethdb/memorydb" "github.com/stretchr/testify/assert" - "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/plugin/evm/message" "github.com/ava-labs/coreth/sync/handlers/stats/statstest" + + ethparams "github.com/ava-labs/libevm/params" ) func TestCodeRequestHandler(t *testing.T) { @@ -27,10 +28,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 +81,7 @@ func TestCodeRequestHandler(t *testing.T) { }, verifyStats: func(t *testing.T) { assert.EqualValues(t, 1, testHandlerStats.CodeRequestCount) - assert.EqualValues(t, params.MaxCodeSize, testHandlerStats.CodeBytesReturnedSum) + assert.EqualValues(t, ethparams.MaxCodeSize, testHandlerStats.CodeBytesReturnedSum) }, }, }