-
Notifications
You must be signed in to change notification settings - Fork 275
fix(all): critical fixes to the libevm branch #1551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0fca690
params/extras/config.go: re-add chain config fee config verification
qdm12 f5e0a91
core/genesis.go: re-add setEthUpgrades call
qdm12 ee4ca13
params/extras/config.go: add fee config to chain config description
qdm12 73326c0
params/extras/config.go: add allow fee reciptions to chain config des…
qdm12 ca366e6
TestChainConfigDescription
qdm12 bee8a62
TestChainConfigVerify
qdm12 2bf596a
Add TestGenesisEthUpgrades from coreth (slight changes)
qdm12 e5ccf99
Add comment on SetEthUpgrades
qdm12 5468bf2
Use regex for chain config description to avoid making a change detec…
qdm12 58b0c20
Shared `validFeeConfig` variable with all fields set to 1
qdm12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// (c) 2025 Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package core | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ava-labs/libevm/common" | ||
"github.com/ava-labs/libevm/core/rawdb" | ||
"github.com/ava-labs/libevm/core/types" | ||
"github.com/ava-labs/libevm/triedb" | ||
"github.com/ava-labs/subnet-evm/commontype" | ||
"github.com/ava-labs/subnet-evm/params" | ||
"github.com/ava-labs/subnet-evm/params/extras" | ||
"github.com/ava-labs/subnet-evm/utils" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGenesisEthUpgrades(t *testing.T) { | ||
db := rawdb.NewMemoryDatabase() | ||
preEthUpgrades := params.WithExtra( | ||
¶ms.ChainConfig{ | ||
ChainID: big.NewInt(43114), // Specifically refers to mainnet for this UT | ||
HomesteadBlock: big.NewInt(0), | ||
// For this test to be a proper regression test, DAOForkBlock and | ||
// DAOForkSupport should be set to match the values in | ||
// [params.SetEthUpgrades]. Otherwise, in case of a regression, the test | ||
// would pass as there would be a mismatch at genesis, which is | ||
// incorrectly considered a success. | ||
DAOForkBlock: big.NewInt(0), | ||
DAOForkSupport: true, | ||
EIP150Block: big.NewInt(0), | ||
EIP155Block: big.NewInt(0), | ||
EIP158Block: big.NewInt(0), | ||
ByzantiumBlock: big.NewInt(0), | ||
ConstantinopleBlock: big.NewInt(0), | ||
PetersburgBlock: big.NewInt(0), | ||
IstanbulBlock: big.NewInt(0), | ||
MuirGlacierBlock: big.NewInt(0), | ||
}, | ||
&extras.ChainConfig{ | ||
FeeConfig: commontype.FeeConfig{ | ||
MinBaseFee: big.NewInt(1), | ||
}, | ||
NetworkUpgrades: extras.NetworkUpgrades{ | ||
SubnetEVMTimestamp: utils.NewUint64(0), | ||
}, | ||
}, | ||
) | ||
tdb := triedb.NewDatabase(db, triedb.HashDefaults) | ||
config := *preEthUpgrades | ||
// Set this up once, just to get the genesis hash | ||
_, genHash, err := SetupGenesisBlock(db, tdb, &Genesis{Config: &config}, common.Hash{}, false) | ||
require.NoError(t, err) | ||
// Write the configuration back to the db as it would be in prior versions | ||
rawdb.WriteChainConfig(db, genHash, preEthUpgrades) | ||
// Make some other block | ||
block := types.NewBlock( | ||
&types.Header{ | ||
Number: big.NewInt(1640340), // Berlin activation on mainnet | ||
Difficulty: big.NewInt(1), | ||
ParentHash: genHash, | ||
Time: uint64(time.Now().Unix()), | ||
}, | ||
nil, nil, nil, nil, | ||
) | ||
rawdb.WriteBlock(db, block) | ||
// We should still be able to re-initialize | ||
config = *preEthUpgrades | ||
avalancheUpgrades := extras.NetworkUpgrades{} | ||
params.SetEthUpgrades(&config, avalancheUpgrades) // New versions will set additional fields eg, LondonBlock | ||
_, _, err = SetupGenesisBlock(db, tdb, &Genesis{Config: &config}, block.Hash(), false) | ||
require.NoError(t, err) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
// (c) 2025 Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package extras | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ava-labs/avalanchego/snow" | ||
"github.com/ava-labs/avalanchego/upgrade" | ||
"github.com/ava-labs/libevm/common" | ||
"github.com/ava-labs/subnet-evm/commontype" | ||
"github.com/ava-labs/subnet-evm/precompile/contracts/txallowlist" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func pointer[T any](v T) *T { return &v } | ||
|
||
func TestChainConfigDescription(t *testing.T) { | ||
qdm12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t.Parallel() | ||
|
||
tests := map[string]struct { | ||
config *ChainConfig | ||
wantRegex string | ||
}{ | ||
"nil": {}, | ||
"empty": { | ||
config: &ChainConfig{}, | ||
wantRegex: `Avalanche Upgrades \(timestamp based\)\: | ||
- SubnetEVM Timestamp: ( )+@nil( )+\(https:\/\/github\.com\/ava-labs\/avalanchego\/releases\/tag\/v1\.10\.0\) | ||
( - .+Timestamp: .+\n)+ | ||
Upgrade Config: {} | ||
Fee Config: {} | ||
Allow Fee Recipients: false | ||
$`, | ||
}, | ||
"set": { | ||
config: &ChainConfig{ | ||
NetworkUpgrades: NetworkUpgrades{ | ||
SubnetEVMTimestamp: pointer(uint64(1)), | ||
DurangoTimestamp: pointer(uint64(2)), | ||
EtnaTimestamp: pointer(uint64(3)), | ||
FortunaTimestamp: pointer(uint64(4)), | ||
}, | ||
FeeConfig: commontype.FeeConfig{ | ||
GasLimit: big.NewInt(5), | ||
TargetBlockRate: 6, | ||
MinBaseFee: big.NewInt(7), | ||
TargetGas: big.NewInt(8), | ||
BaseFeeChangeDenominator: big.NewInt(9), | ||
MinBlockGasCost: big.NewInt(10), | ||
MaxBlockGasCost: big.NewInt(11), | ||
BlockGasCostStep: big.NewInt(12), | ||
}, | ||
AllowFeeRecipients: true, | ||
UpgradeConfig: UpgradeConfig{ | ||
NetworkUpgradeOverrides: &NetworkUpgrades{ | ||
SubnetEVMTimestamp: pointer(uint64(13)), | ||
}, | ||
StateUpgrades: []StateUpgrade{ | ||
{ | ||
BlockTimestamp: pointer(uint64(14)), | ||
StateUpgradeAccounts: map[common.Address]StateUpgradeAccount{ | ||
common.Address{15}: { | ||
Code: []byte{16}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantRegex: `Avalanche Upgrades \(timestamp based\)\: | ||
- SubnetEVM Timestamp: ( )+@1( )+\(https:\/\/github\.com\/ava-labs\/avalanchego\/releases\/tag\/v1\.10\.0\) | ||
( - .+Timestamp: .+\n)+ | ||
Upgrade Config: {"networkUpgradeOverrides":{"subnetEVMTimestamp":13},"stateUpgrades":\[{"blockTimestamp":14,"accounts":{"0x0f00000000000000000000000000000000000000":{"code":"0x10"}}}\]} | ||
Fee Config: {"gasLimit":5,"targetBlockRate":6,"minBaseFee":7,"targetGas":8,"baseFeeChangeDenominator":9,"minBlockGasCost":10,"maxBlockGasCost":11,"blockGasCostStep":12} | ||
Allow Fee Recipients: true | ||
$`, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
got := test.config.Description() | ||
assert.Regexp(t, test.wantRegex, got, "config description mismatch") | ||
}) | ||
} | ||
} | ||
|
||
func TestChainConfigVerify(t *testing.T) { | ||
t.Parallel() | ||
|
||
validFeeConfig := commontype.FeeConfig{ | ||
GasLimit: big.NewInt(1), | ||
TargetBlockRate: 1, | ||
MinBaseFee: big.NewInt(1), | ||
TargetGas: big.NewInt(1), | ||
BaseFeeChangeDenominator: big.NewInt(1), | ||
MinBlockGasCost: big.NewInt(1), | ||
MaxBlockGasCost: big.NewInt(1), | ||
BlockGasCostStep: big.NewInt(1), | ||
} | ||
|
||
tests := map[string]struct { | ||
config ChainConfig | ||
errRegex string | ||
}{ | ||
"invalid_feeconfig": { | ||
config: ChainConfig{ | ||
FeeConfig: commontype.FeeConfig{ | ||
GasLimit: nil, | ||
}, | ||
}, | ||
errRegex: "^invalid fee config: ", | ||
}, | ||
"invalid_precompile_upgrades": { | ||
// Also see precompile_config_test.go TestVerifyWithChainConfig* tests | ||
config: ChainConfig{ | ||
FeeConfig: validFeeConfig, | ||
UpgradeConfig: UpgradeConfig{ | ||
PrecompileUpgrades: []PrecompileUpgrade{ | ||
// same precompile cannot be configured twice for the same timestamp | ||
{Config: txallowlist.NewDisableConfig(pointer(uint64(1)))}, | ||
{Config: txallowlist.NewDisableConfig(pointer(uint64(1)))}, | ||
}, | ||
}, | ||
}, | ||
errRegex: "^invalid precompile upgrades: ", | ||
}, | ||
"invalid_state_upgrades": { | ||
config: ChainConfig{ | ||
FeeConfig: validFeeConfig, | ||
UpgradeConfig: UpgradeConfig{ | ||
StateUpgrades: []StateUpgrade{ | ||
{BlockTimestamp: nil}, | ||
}, | ||
}, | ||
}, | ||
errRegex: "^invalid state upgrades: ", | ||
}, | ||
"invalid_network_upgrades": { | ||
config: ChainConfig{ | ||
FeeConfig: validFeeConfig, | ||
NetworkUpgrades: NetworkUpgrades{ | ||
SubnetEVMTimestamp: nil, | ||
}, | ||
AvalancheContext: AvalancheContext{SnowCtx: &snow.Context{}}, | ||
}, | ||
errRegex: "^invalid network upgrades: ", | ||
}, | ||
"valid": { | ||
config: ChainConfig{ | ||
FeeConfig: validFeeConfig, | ||
NetworkUpgrades: NetworkUpgrades{ | ||
SubnetEVMTimestamp: pointer(uint64(1)), | ||
DurangoTimestamp: pointer(uint64(2)), | ||
EtnaTimestamp: pointer(uint64(3)), | ||
FortunaTimestamp: pointer(uint64(4)), | ||
}, | ||
AvalancheContext: AvalancheContext{SnowCtx: &snow.Context{ | ||
NetworkUpgrades: upgrade.Config{ | ||
DurangoTime: time.Unix(2, 0), | ||
EtnaTime: time.Unix(3, 0), | ||
FortunaTime: time.Unix(4, 0), | ||
}, | ||
}}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
err := test.config.Verify() | ||
if test.errRegex == "" { | ||
assert.NoError(t, err) | ||
} else { | ||
require.Error(t, err) | ||
assert.Regexp(t, test.errRegex, err.Error()) | ||
} | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.