Skip to content
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

Add requirement that Subnet-evm upgrade is enabled at genesis #419

Merged
merged 32 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
44fb324
Add requirement that Subnet-evm upgrade is enabled at genesis
anusha-ctrl Dec 20, 2022
756a872
Add test for nil
anusha-ctrl Dec 20, 2022
b7afb02
remove err
anusha-ctrl Dec 20, 2022
5b59ecb
modify comment
anusha-ctrl Dec 20, 2022
c9addb4
add one more comment
anusha-ctrl Dec 20, 2022
226cdd9
test improvements
anusha-ctrl Dec 20, 2022
551f896
fix comment
anusha-ctrl Dec 20, 2022
23356a3
fix comment
anusha-ctrl Dec 20, 2022
3fd850e
timestamp
anusha-ctrl Dec 20, 2022
4289b66
fix existing test:
anusha-ctrl Dec 21, 2022
6c547ce
fix one more existing test
anusha-ctrl Dec 21, 2022
d28645e
fix spacing
anusha-ctrl Dec 21, 2022
9c399ce
clean up
anusha-ctrl Dec 21, 2022
5b3591f
address comments
anusha-ctrl Dec 22, 2022
35164b8
use commmon big 0
anusha-ctrl Dec 22, 2022
d2ec18c
address comments
anusha-ctrl Dec 22, 2022
b5d071d
Check before upgrade bytes
anusha-ctrl Dec 22, 2022
ffbcf2c
comment tests until new NetworkUpgrade is added
anusha-ctrl Dec 22, 2022
dd23588
Merge branch 'master' into add-upgrade-requirement
anusha-ctrl Dec 22, 2022
0ed192a
Merge branch 'master' into add-upgrade-requirement
aaronbuchwald Dec 27, 2022
8fd026d
skip instead of comment out
anusha-ctrl Jan 10, 2023
506e935
Merge branch 'add-upgrade-requirement' of https://github.com/ava-labs…
anusha-ctrl Jan 10, 2023
efcfd0c
Merge branch 'master' into add-upgrade-requirement
anusha-ctrl Jan 11, 2023
06406b2
add config flag
anusha-ctrl Jan 11, 2023
067db7a
Merge branch 'add-upgrade-requirement' of https://github.com/ava-labs…
anusha-ctrl Jan 11, 2023
ab79415
add unit test to test override
anusha-ctrl Jan 11, 2023
9ef4d85
lint
anusha-ctrl Jan 11, 2023
473c66d
remove skips
anusha-ctrl Jan 11, 2023
b9c3af5
lint
anusha-ctrl Jan 11, 2023
7a31c12
Merge branch 'master' into add-upgrade-requirement
anusha-ctrl Jan 11, 2023
e650678
unify to one test
anusha-ctrl Jan 12, 2023
09361b1
fix typo
anusha-ctrl Jan 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugin/evm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ type Config struct {
// identical state with the pre-upgrade ruleset.
SkipUpgradeCheck bool `json:"skip-upgrade-check"`

// SkipSubnetEVMUpgradeCheck disables checking that SubnetEVM Upgrade is enabled at genesis
SkipSubnetEVMUpgradeCheck bool `json:"skip-subnet-evm-upgrade-check"`

// AcceptedCacheSize is the depth to keep in the accepted headers cache and the
// accepted logs cache at the accepted tip.
//
Expand Down
22 changes: 15 additions & 7 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ var (
)

var (
errEmptyBlock = errors.New("empty block")
errUnsupportedFXs = errors.New("unsupported feature extensions")
errInvalidBlock = errors.New("invalid block")
errInvalidNonce = errors.New("invalid nonce")
errUnclesUnsupported = errors.New("uncles unsupported")
errNilBaseFeeSubnetEVM = errors.New("nil base fee is invalid after subnetEVM")
errNilBlockGasCostSubnetEVM = errors.New("nil blockGasCost is invalid after subnetEVM")
errEmptyBlock = errors.New("empty block")
errUnsupportedFXs = errors.New("unsupported feature extensions")
errInvalidBlock = errors.New("invalid block")
errInvalidNonce = errors.New("invalid nonce")
errUnclesUnsupported = errors.New("uncles unsupported")
errNilBaseFeeSubnetEVM = errors.New("nil base fee is invalid after subnetEVM")
errNilBlockGasCostSubnetEVM = errors.New("nil blockGasCost is invalid after subnetEVM")
errSubnetEVMUpgradeNotEnabled = errors.New("SubnetEVM upgrade is not enabled in genesis")
)

var originalStderr *os.File
Expand Down Expand Up @@ -369,6 +370,13 @@ func (vm *VM) Initialize(
vm.chainConfig = g.Config
vm.networkID = vm.ethConfig.NetworkId

if !vm.config.SkipSubnetEVMUpgradeCheck {
// check that subnetEVM upgrade is enabled from genesis before upgradeBytes
if !vm.chainConfig.IsSubnetEVM(common.Big0) {
return errSubnetEVMUpgradeNotEnabled
}
}

// Apply upgradeBytes (if any) by unmarshalling them into [chainConfig.UpgradeConfig].
// Initializing the chain will verify upgradeBytes are compatible with existing values.
if len(upgradeBytes) > 0 {
Expand Down
58 changes: 55 additions & 3 deletions plugin/evm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ var (
password = "CjasdjhiPeirbSenfeI13" // #nosec G101
// Use chainId: 43111, so that it does not overlap with any Avalanche ChainIDs, which may have their
// config overridden in vm.Initialize.
genesisJSONSubnetEVM = "{\"config\":{\"chainId\":43111,\"homesteadBlock\":0,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0,\"subnetEVMTimestamp\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x7A1200\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"0x71562b71999873DB5b286dF957af199Ec94617F7\": {\"balance\":\"0x4192927743b88000\"}, \"0x703c4b2bD70c169f5717101CaeE543299Fc946C7\": {\"balance\":\"0x4192927743b88000\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}"
genesisJSONPreSubnetEVM = "{\"config\":{\"chainId\":43111,\"homesteadBlock\":0,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x7A1200\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"0x71562b71999873DB5b286dF957af199Ec94617F7\": {\"balance\":\"0x4192927743b88000\"}, \"0x703c4b2bD70c169f5717101CaeE543299Fc946C7\": {\"balance\":\"0x4192927743b88000\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}"
genesisJSONLatest = genesisJSONSubnetEVM
genesisJSONSubnetEVMLateEnablement = "{\"config\":{\"chainId\":43111,\"homesteadBlock\":0,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0,\"subnetEVMTimestamp\":50},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x7A1200\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"0x71562b71999873DB5b286dF957af199Ec94617F7\": {\"balance\":\"0x4192927743b88000\"}, \"0x703c4b2bD70c169f5717101CaeE543299Fc946C7\": {\"balance\":\"0x4192927743b88000\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}"
genesisJSONSubnetEVM = "{\"config\":{\"chainId\":43111,\"homesteadBlock\":0,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0,\"subnetEVMTimestamp\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x7A1200\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"0x71562b71999873DB5b286dF957af199Ec94617F7\": {\"balance\":\"0x4192927743b88000\"}, \"0x703c4b2bD70c169f5717101CaeE543299Fc946C7\": {\"balance\":\"0x4192927743b88000\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}"
genesisJSONPreSubnetEVM = "{\"config\":{\"chainId\":43111,\"homesteadBlock\":0,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x7A1200\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"0x71562b71999873DB5b286dF957af199Ec94617F7\": {\"balance\":\"0x4192927743b88000\"}, \"0x703c4b2bD70c169f5717101CaeE543299Fc946C7\": {\"balance\":\"0x4192927743b88000\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}"
genesisJSONLatest = genesisJSONSubnetEVM

firstTxAmount *big.Int
genesisBalance *big.Int
Expand Down Expand Up @@ -376,6 +377,57 @@ func issueAndAccept(t *testing.T, issuer <-chan engCommon.Message, vm *VM) snowm
return blk
}

func TestSubnetEVMUpgradeRequiredAtGenesis(t *testing.T) {
genesisTests := []struct {
genesisJSON string
configJSON string
expectedErr error
}{
{
// we expect an error when subnet evm upgrade is nil in chain config
genesisJSON: genesisJSONPreSubnetEVM,
configJSON: "",
expectedErr: errSubnetEVMUpgradeNotEnabled,
},
{
// we expect an error when subnet evm upgrade is not enabled at genesis and at a later block instead
genesisJSON: genesisJSONSubnetEVMLateEnablement,
configJSON: "",
expectedErr: errSubnetEVMUpgradeNotEnabled,
},
{
// we do not expect an err when skip-subnet-evm-upgrade-check is set to true
genesisJSON: genesisJSONPreSubnetEVM,
configJSON: "{\"skip-subnet-evm-upgrade-check\": true}",
expectedErr: nil,
},
{
// we do not expect an err when skip-subnet-evm-upgrade-check is set to true
genesisJSON: genesisJSONSubnetEVMLateEnablement,
configJSON: "{\"skip-subnet-evm-upgrade-check\": true}",
expectedErr: nil,
},
}

for _, test := range genesisTests {
ctx, dbManager, genesisBytes, issuer := setupGenesis(t, test.genesisJSON)
vm := &VM{}
err := vm.Initialize(
context.Background(),
ctx,
dbManager,
genesisBytes,
[]byte(""),
[]byte(test.configJSON),
issuer,
[]*engCommon.Fx{},
nil,
)

require.ErrorIs(t, err, test.expectedErr)
}
}

func TestBuildEthTxBlock(t *testing.T) {
// reduce block gas cost
issuer, vm, dbManager, _ := GenesisVM(t, true, genesisJSONSubnetEVM, "{\"pruning-enabled\":true}", "")
Expand Down
8 changes: 5 additions & 3 deletions plugin/evm/vm_upgrade_bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ func TestVMUpgradeBytesNetworkUpgrades(t *testing.T) {
if err != nil {
t.Fatalf("could not marshal upgradeConfig to json: %s", err)
}
configJSON := "{\"skip-subnet-evm-upgrade-check\": true}"

// initialize the VM with these upgrade bytes
issuer, vm, dbManager, appSender := GenesisVM(t, true, genesisJSONPreSubnetEVM, "", string(upgradeBytesJSON))
issuer, vm, dbManager, appSender := GenesisVM(t, true, genesisJSONPreSubnetEVM, configJSON, string(upgradeBytesJSON))
vm.clock.Set(subnetEVMTimestamp)

// verify upgrade is applied
Expand Down Expand Up @@ -237,9 +238,10 @@ func TestVMUpgradeBytesNetworkUpgradesWithGenesis(t *testing.T) {
if err != nil {
t.Fatalf("could not marshal upgradeConfig to json: %s", err)
}
configJSON := "{\"skip-subnet-evm-upgrade-check\": true}"

// initialize the VM with these upgrade bytes
_, vm, _, _ := GenesisVM(t, true, string(genesisBytes), "", string(upgradeBytesJSON))
_, vm, _, _ := GenesisVM(t, true, string(genesisBytes), configJSON, string(upgradeBytesJSON))

// verify upgrade is rescheduled
assert.False(t, vm.chainConfig.IsSubnetEVM(genesisSubnetEVMTimestamp))
Expand All @@ -257,7 +259,7 @@ func TestVMUpgradeBytesNetworkUpgradesWithGenesis(t *testing.T) {
}

// initialize the VM with these upgrade bytes
_, vm, _, _ = GenesisVM(t, true, string(genesisBytes), "", string(upgradeBytesJSON))
_, vm, _, _ = GenesisVM(t, true, string(genesisBytes), configJSON, string(upgradeBytesJSON))

// verify upgrade is aborted
assert.False(t, vm.chainConfig.IsSubnetEVM(genesisSubnetEVMTimestamp))
Expand Down