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

Problem: selfdestruct could affect other contracts with same bytecode #618

Merged
merged 11 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Changelog

## UNRELEASED
*Aug 5, 2022*

## v0.8.0

### State Machine Breaking

- [#618](https://github.com/crypto-org-chain/cronos/pull/618) selfdestruct don't delete bytecode of smart contract.

*Aug 5, 2022*

## v0.7.1

### Bug Fixes

Expand Down
47 changes: 2 additions & 45 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"io"
"math/big"
"net/http"
"os"
"path/filepath"
Expand All @@ -24,7 +23,6 @@ import (
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -704,52 +702,11 @@ func New(
app.SetEndBlocker(app.EndBlocker)

// upgrade handlers
plan0_7_0 := "v0.7.0"
app.UpgradeKeeper.SetUpgradeHandler(plan0_7_0, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
updatedVM, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
if err != nil {
return nil, err
}
// Override feemarket parameters
initialBaseFee := int64(5000000000000)
app.FeeMarketKeeper.SetParams(ctx, feemarkettypes.Params{
NoBaseFee: false,
BaseFeeChangeDenominator: 100000000,
ElasticityMultiplier: 2,
InitialBaseFee: initialBaseFee,
EnableHeight: 0,
})
app.FeeMarketKeeper.SetBaseFee(ctx, big.NewInt(initialBaseFee))
evmParams := app.EvmKeeper.GetParams(ctx)
zeroInt := sdk.ZeroInt()
evmParams.ChainConfig.LondonBlock = &zeroInt
app.EvmKeeper.SetParams(ctx, evmParams)
return updatedVM, nil
})

// this upgrade is for breaking bug fixes on testnet
plan0_7_0Rc3HotfixTestnet := "v0.7.0-rc3-hotfix-testnet"
app.UpgradeKeeper.SetUpgradeHandler(plan0_7_0Rc3HotfixTestnet, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
cp := ctx.ConsensusParams()
cp.Block.MaxGas = 10000000
app.StoreConsensusParams(ctx, cp)
planName := "v0.7.0-hotfix"
app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == plan0_7_0 && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{"feemarket"},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
, rev ? "dirty"
}:
let
version = "v0.7.1";
version = "v0.8.0";
pname = "cronosd";
tags = [ "ledger" "netgo" network ]
++ lib.lists.optional (db_backend == "rocksdb") "rocksdb";
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ replace (

github.com/tendermint/tendermint => github.com/tendermint/tendermint v0.34.20

github.com/tharsis/ethermint => github.com/crypto-org-chain/ethermint v0.10.0-cronos.0.20220719024136-4658529abbf5
github.com/tharsis/ethermint => github.com/crypto-org-chain/ethermint v0.11.0-cronos

google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crypto-org-chain/ethermint v0.10.0-cronos.0.20220719024136-4658529abbf5 h1:2iLYA821730/uyyrY8Rn3AXxpYNPIsdelCuYcZyJSmE=
github.com/crypto-org-chain/ethermint v0.10.0-cronos.0.20220719024136-4658529abbf5/go.mod h1:T4f1p3L5kccbjBZMtJLKfOLiUXTO1OuS1I7FzQuJD+w=
github.com/crypto-org-chain/ethermint v0.11.0-cronos h1:CNqm0ZD5yuf1/ENki3hVMUAMCl74f4GSYPrGN/h38bA=
github.com/crypto-org-chain/ethermint v0.11.0-cronos/go.mod h1:T4f1p3L5kccbjBZMtJLKfOLiUXTO1OuS1I7FzQuJD+w=
github.com/crypto-org-chain/ibc-go/v2 v2.2.0-hooks2 h1:elj+Tb/3O9GA3pv62zkc1B0P8hl1WHmF6vF8PInEJm4=
github.com/crypto-org-chain/ibc-go/v2 v2.2.0-hooks2/go.mod h1:rAHRlBcRiHPP/JszN+08SJx3pegww9bcVncIb9QLx7I=
github.com/crypto-org-chain/keyring v1.1.6-fixes h1:AUFSu56NY6XobY6XfRoDx6v3loiOrHK5MNUm32GEjwA=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ schema = 3
version = "v0.6.7"
hash = "sha256-hl/3RrBrpkk2zA6dmrNlIYKs1/GfqegSscDSkA5Pjlo="
[mod."github.com/tharsis/ethermint"]
version = "v0.10.0-cronos.0.20220719024136-4658529abbf5"
hash = "sha256-86PPinRIfbATES4B4FLFE02GQSCBxO39Tsj/VYYhkr8="
version = "v0.11.0-cronos"
hash = "sha256-vSseS5bYyHAPPqwMujTLM/h/ckh3OWXZJR572Wh3KYU="
replaced = "github.com/crypto-org-chain/ethermint"
[mod."github.com/tklauser/go-sysconf"]
version = "v0.3.10"
Expand Down
2 changes: 0 additions & 2 deletions integration_tests/configs/cosmovisor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ cronos_777-1:
evm:
params:
evm_denom: basetcro
chain_config:
london_block: null
cronos:
params:
cronos_admin: ${CRONOS_ADMIN}
Expand Down
11 changes: 9 additions & 2 deletions integration_tests/configs/upgrade-test-package.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
let
pkgs = import ../../nix { };
released = import (builtins.fetchTarball "https://github.com/crypto-org-chain/cronos/archive/v0.6.5.tar.gz") { };
fetchFlake = repo: rev: (pkgs.flake-compat {
src = {
outPath = builtins.fetchTarball "https://github.com/${repo}/archive/${rev}.tar.gz";
inherit rev;
shortRev = builtins.substring 0 7 rev;
};
}).defaultNix;
released = (fetchFlake "crypto-org-chain/cronos" "8035ebdcc3ce1ed5ee3d4887eb4ea1032c4d283c").default;
current = pkgs.callPackage ../../. { };
in
pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis"; path = released; }
{ name = "v0.7.0"; path = current; }
{ name = "v0.7.0-hotfix"; path = current; }
]
17 changes: 2 additions & 15 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

import pytest
from dateutil.parser import isoparse
from pystarport import ports
from pystarport.cluster import SUPERVISOR_CONFIG_FILE

from .network import Cronos, setup_custom_cronos
from .utils import parse_events, wait_for_block, wait_for_block_time, wait_for_port
from .utils import parse_events, wait_for_block, wait_for_block_time


def init_cosmovisor(home):
Expand Down Expand Up @@ -83,7 +82,7 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos):
height = cli.block_height()
target_height = height + 15
print("upgrade height", target_height)
plan_name = "v0.7.0"
plan_name = "v0.7.0-hotfix"
rsp = cli.gov_propose(
"community",
"software-upgrade",
Expand Down Expand Up @@ -114,15 +113,3 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos):

# block should pass the target height
wait_for_block(cli, target_height + 2, timeout=480)

# check feemarket is enabled correctly
wait_for_port(ports.evmrpc_port(custom_cronos.base_port(0)))
w3 = custom_cronos.w3
# check base fee values
fee1 = 5000000000000 - 5000000000000 // 100000000
fee2 = fee1 - fee1 // 100000000
assert w3.eth.get_block(target_height).baseFeePerGas == fee1
assert w3.eth.get_block(target_height + 1).baseFeePerGas == fee2

# query legacy blocks before the upgrade
assert "baseFeePerGas" not in w3.eth.get_block(target_height - 1)
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import sources.nixpkgs {
inherit (pkgs.darwin.apple_sdk.frameworks) IOKit;
buildGoModule = pkgs.buildGo117Module;
};
flake-compat = import sources.flake-compat;
}) # update to a version that supports eip-1559
(import (sources.gomod2nix + "/overlay.nix"))
(_: pkgs: {
Expand Down
12 changes: 12 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
"url_template": "https://github.com/dapphub/dapptools/archive/refs/tags/hevm/0.49.0.tar.gz",
"version": "hevm/0.49.0"
},
"flake-compat": {
"branch": "master",
"description": null,
"homepage": null,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "b4a34015c698c7793d592d66adbab377907a2be8",
"sha256": "1qc703yg0babixi6wshn5wm2kgl5y1drcswgszh4xxzbrwkk9sv7",
"type": "tarball",
"url": "https://github.com/edolstra/flake-compat/archive/b4a34015c698c7793d592d66adbab377907a2be8.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"gomod2nix": {
"branch": "master",
"description": "Convert applications using Go modules to Nix expressions",
Expand Down