From 9d060fcc81890339f7c3d1d8a6b20a04999b9c4a Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 1 Apr 2024 09:33:48 +0800 Subject: [PATCH] fork upgrade --- CHANGELOG.md | 5 ++++ app/app.go | 1 + app/forks.go | 11 ++++++++ go.mod | 2 +- go.sum | 4 +-- gomod2nix.toml | 6 ++--- integration_tests/configs/fork.jsonnet | 9 +++++++ integration_tests/network.py | 3 ++- integration_tests/test_fork.py | 35 ++++++++++++++++++++++++++ 9 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 integration_tests/configs/fork.jsonnet create mode 100644 integration_tests/test_fork.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 4357af2954..034c119a04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ - [#1363](https://github.com/crypto-org-chain/cronos/pull/1363) Update ethermint to fix a panic on overflow and patch gasUsed in the RPC API. +### State Machine Breaking + +* [#1366](https://github.com/crypto-org-chain/ethermint/pull/1366) Keep behavior of random opcode as before. + + *March 26, 2024* ## v1.1.1 diff --git a/app/app.go b/app/app.go index 987c103492..1c405ffcdc 100644 --- a/app/app.go +++ b/app/app.go @@ -542,6 +542,7 @@ func New( }, }, allKeys, + RandomOpcodeForkEnabled, ) var gravityKeeper gravitykeeper.Keeper diff --git a/app/forks.go b/app/forks.go index 28e3b5c457..d4bc14cfb0 100644 --- a/app/forks.go +++ b/app/forks.go @@ -30,3 +30,14 @@ func BeginBlockForks(ctx sdk.Context, app *App) { } } } + +// TODO decide the fork heights +var RandomOpcodeForkHeights = map[string]int64{ + "cronosmainnet_25-1": 18, + "tempcronosmainnet_28-1": 18, + "cronostestnet_338-1": 18, +} + +func RandomOpcodeForkEnabled(ctx sdk.Context) bool { + return ctx.BlockHeight() >= RandomOpcodeForkHeights[ctx.ChainID()] +} diff --git a/go.mod b/go.mod index 6bda2206d4..90708c176c 100644 --- a/go.mod +++ b/go.mod @@ -239,7 +239,7 @@ replace ( // TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134 github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231207063621-43cf32d91c3e - github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20240326012741-6263a240556c + github.com/evmos/ethermint => github.com/mmsqe/ethermint v0.6.5-0.20240331073601-ade0cb7b783d // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0 diff --git a/go.sum b/go.sum index 8c4e4323b6..fb676b9512 100644 --- a/go.sum +++ b/go.sum @@ -488,8 +488,6 @@ github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63 h1:R1 github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63/go.mod h1:rocwIfnS+kA060x64gkSIRvWB9StSppIkJuo5MWzL24= github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20240228013111-9bd1e035ed1d h1:ihUBUAEwQYHZEqf7lXrJithNCUJTjB8q3oSQA6Nevco= github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20240228013111-9bd1e035ed1d/go.mod h1:cmAawe8FV/52oPKbgeHLt4UpNkrNu8R5KD+kw0kxJFc= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240326012741-6263a240556c h1:3VKwgmkb/CnjHT8v6bwMl70ferUVLcrefEpQc9Q8/F0= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240326012741-6263a240556c/go.mod h1:zJYmx1D+tDggzvXmdJ0/I62TeIykdCMfJBjBxOcniAU= github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231207063621-43cf32d91c3e h1:vnyepPQ/m25+19xcTuBUdRxmltZ/EjVWNqEjhg7Ummk= github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231207063621-43cf32d91c3e/go.mod h1:+a8pUj1tOyJ2RinsNQD4326YS+leSoKGiG/uVVb0x6Y= github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e h1:rSTc35OBjjCBx47rHPWBCIHNGPbMnEj8f7fNcK2TjVI= @@ -1165,6 +1163,8 @@ github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjU github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/mmsqe/ethermint v0.6.5-0.20240331073601-ade0cb7b783d h1:exXMTi3+Do+stu1pYYIx88rqcO053QGw/rfjk66DLKE= +github.com/mmsqe/ethermint v0.6.5-0.20240331073601-ade0cb7b783d/go.mod h1:zJYmx1D+tDggzvXmdJ0/I62TeIykdCMfJBjBxOcniAU= github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU= github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc= github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw= diff --git a/gomod2nix.toml b/gomod2nix.toml index c346bc00ae..a3af389da6 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -216,9 +216,9 @@ schema = 3 hash = "sha256-lDIqRLUrXYCb9mmFBY/+WW+ee69+IkxOgqjHVyo4ij0=" replaced = "github.com/crypto-org-chain/go-ethereum" [mod."github.com/evmos/ethermint"] - version = "v0.6.1-0.20240326012741-6263a240556c" - hash = "sha256-MgvJ9Z0zl+oZtMmbSAlqaibQvzKqEvM1016uF9GEHXI=" - replaced = "github.com/crypto-org-chain/ethermint" + version = "v0.6.5-0.20240331073601-ade0cb7b783d" + hash = "sha256-RnkjCBsqTgeyy/S/vtgJn/VtH4H8hVTtTLR1rCIOFJw=" + replaced = "github.com/mmsqe/ethermint" [mod."github.com/felixge/httpsnoop"] version = "v1.0.2" hash = "sha256-hj6FZQ1fDAV+1wGIViAt8XaAkWZ1I5vJzgjIJa7XRBA=" diff --git a/integration_tests/configs/fork.jsonnet b/integration_tests/configs/fork.jsonnet new file mode 100644 index 0000000000..c9c8a05227 --- /dev/null +++ b/integration_tests/configs/fork.jsonnet @@ -0,0 +1,9 @@ +local default = import 'default.jsonnet'; + +{ + 'cronosmainnet_25-1': default['cronos_777-1'] { + 'app-config'+: { + chain_id: 'cronosmainnet_25-1', + }, + }, +} diff --git a/integration_tests/network.py b/integration_tests/network.py index 8e18ad7d53..134496c47c 100644 --- a/integration_tests/network.py +++ b/integration_tests/network.py @@ -158,6 +158,7 @@ def setup_custom_cronos( chain_binary=None, wait_port=True, relayer=cluster.Relayer.HERMES.value, + chain_id="cronos_777-1", ): cmd = [ "pystarport", @@ -186,7 +187,7 @@ def setup_custom_cronos( if wait_port: wait_for_port(ports.evmrpc_port(base_port)) wait_for_port(ports.evmrpc_ws_port(base_port)) - yield Cronos(path / "cronos_777-1", chain_binary=chain_binary or "cronosd") + yield Cronos(path / chain_id, chain_binary=chain_binary or "cronosd") finally: os.killpg(os.getpgid(proc.pid), signal.SIGTERM) # proc.terminate() diff --git a/integration_tests/test_fork.py b/integration_tests/test_fork.py new file mode 100644 index 0000000000..a805703e32 --- /dev/null +++ b/integration_tests/test_fork.py @@ -0,0 +1,35 @@ +from pathlib import Path + +import pytest + +from .network import setup_custom_cronos +from .utils import CONTRACTS, deploy_contract, wait_for_new_blocks + +pytestmark = pytest.mark.upgrade + + +@pytest.fixture(scope="module") +def custom_cronos(tmp_path_factory): + yield from setup_custom_cronos( + tmp_path_factory.mktemp("fork"), + 27100, + Path(__file__).parent / "configs/fork.jsonnet", + chain_id="cronosmainnet_25-1", + ) + + +def test_slash_fork(custom_cronos): + w3 = custom_cronos.w3 + cli = custom_cronos.cosmos_cli() + random_contract = deploy_contract( + w3, + CONTRACTS["Random"], + ) + with pytest.raises(ValueError) as e_info: + res = random_contract.caller.randomTokenId() + assert "invalid memory address or nil pointer dereference" in str(e_info.value) + deploy_contract(w3, CONTRACTS["Greeter"]) + wait_for_new_blocks(cli, 3) + deploy_contract(w3, CONTRACTS["Greeter"]) + res = random_contract.caller.randomTokenId() + assert res > 0, res