From b89f166893e91b68ced2afdd25922ae212395dca Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Tue, 16 Sep 2025 12:00:08 +0900 Subject: [PATCH 1/7] fix tx context --- go.mod | 4 ++-- go.sum | 4 ++-- gomod2nix.toml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index b0abb3cf1b..b2d0dc0f03 100644 --- a/go.mod +++ b/go.mod @@ -305,8 +305,8 @@ replace ( github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 // release/v1.15 github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20250815065500-a4fbafcae0dd - // develop - github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.22.1-0.20250909102334-034803df81c7 + // release/v0.22.x + github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.22.1-0.20250916025604-a85d8890cd52 // 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 e637ae49ff..b6d28a54cf 100644 --- a/go.sum +++ b/go.sum @@ -912,8 +912,8 @@ github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241217090828-cfbca9fe8254 github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241217090828-cfbca9fe8254/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM= github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20241217090828-cfbca9fe8254 h1:JzLOFRiKsDtLJt5h0M0jkEIPDKvFFyja7VEp7gG6O9U= github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20241217090828-cfbca9fe8254/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w= -github.com/crypto-org-chain/ethermint v0.22.1-0.20250909102334-034803df81c7 h1:3DnrW5+m1yKzAHWyQIM1o9MoOzghlDlr3s/GQdQmwu4= -github.com/crypto-org-chain/ethermint v0.22.1-0.20250909102334-034803df81c7/go.mod h1:StA36YNgLruMKlg6FG+fUie0+k3hQS8dapZJzl+CPI4= +github.com/crypto-org-chain/ethermint v0.22.1-0.20250916025604-a85d8890cd52 h1:jmP2dBG1FRNd+GW61zJiy8O4pYGjBCMbPtDZffZ7LBs= +github.com/crypto-org-chain/ethermint v0.22.1-0.20250916025604-a85d8890cd52/go.mod h1:StA36YNgLruMKlg6FG+fUie0+k3hQS8dapZJzl+CPI4= github.com/crypto-org-chain/go-block-stm v0.0.0-20241213061541-7afe924fb4a6 h1:6KPEi8dWkDSBddQb4NAvEXmNnTXymF3yVeTaT4Hz1iU= github.com/crypto-org-chain/go-block-stm v0.0.0-20241213061541-7afe924fb4a6/go.mod h1:iwQTX9xMX8NV9k3o2BiWXA0SswpsZrDk5q3gA7nWYiE= github.com/crypto-org-chain/go-ethereum v1.10.20-0.20250815065500-a4fbafcae0dd h1:ebSnzvM9yKVGFjvoGly7LFQQCS2HuOWMCvQyByJ52Gs= diff --git a/gomod2nix.toml b/gomod2nix.toml index 1a8cd16a34..cf5bb3daf9 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -315,8 +315,8 @@ schema = 3 version = "v0.2.2" hash = "sha256-0MLfSJKdeK3Z7tWAXTdzwB4091dmyxIX38S5SKH5QAw=" [mod."github.com/evmos/ethermint"] - version = "v0.22.1-0.20250909102334-034803df81c7" - hash = "sha256-7JEYNlsLkWO9LPR92ryqx8M+GkXTUrAz5e9sl0iY8Ow=" + version = "v0.22.1-0.20250916025604-a85d8890cd52" + hash = "sha256-UbnRRrKkc6nVOEErYg+JKQl9VqoQX2/CWejlGrwrJgI=" replaced = "github.com/crypto-org-chain/ethermint" [mod."github.com/fatih/color"] version = "v1.17.0" From 1d55fea21f63ae8fa5ee4459a548dfb2a33684a2 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Tue, 16 Sep 2025 12:02:18 +0900 Subject: [PATCH 2/7] add changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de6285976a..a41c787e16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## UNRELEASED +* [#1869](https://github.com/crypto-org-chain/cronos/pull/1869) Add missing tx context during vm initialisation + +*Sep 4, 2025* + +## v1.5.0 + ### State Machine Breaking * [#1731](https://github.com/crypto-org-chain/cronos/pull/1804) Upgrade to ibc-go v10.1.1 From e7637c508d73bae58af844bdbd0d92473c5366ea Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Tue, 16 Sep 2025 15:52:19 +0900 Subject: [PATCH 3/7] add test --- .../contracts/TestBlockTxProperties.sol | 17 ++++ integration_tests/test_basic.py | 92 +++++++++++++++++++ integration_tests/utils.py | 3 + 3 files changed, 112 insertions(+) create mode 100644 integration_tests/contracts/contracts/TestBlockTxProperties.sol diff --git a/integration_tests/contracts/contracts/TestBlockTxProperties.sol b/integration_tests/contracts/contracts/TestBlockTxProperties.sol new file mode 100644 index 0000000000..e699d9dd76 --- /dev/null +++ b/integration_tests/contracts/contracts/TestBlockTxProperties.sol @@ -0,0 +1,17 @@ +pragma solidity 0.8.21; + +contract TestBlockTxProperties { + event TxDetailsEvent( + address indexed origin, + address indexed sender, + uint value, + bytes data, + uint256 price, + uint gas, + bytes4 sig + ); + + function emitTxDetails() public payable { + emit TxDetailsEvent(tx.origin, msg.sender, msg.value, msg.data, tx.gasprice, gasleft(), msg.sig); + } +} diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index bf8ff20274..8a27160e49 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -10,6 +10,7 @@ from eth_utils import abi, big_endian_to_int from hexbytes import HexBytes from pystarport import cluster, ports +from web3._utils.events import get_event_data from .cosmoscli import CosmosCLI, module_address from .network import Geth @@ -1113,3 +1114,94 @@ def test_tx_replacement(cronos): {"to": ADDRS["community"], "value": 15, "gasPrice": gas_price}, ) assert "has already been mined" in str(exc) + + +def test_block_tx_properties(cronos): + """ + test block tx properties on cronos network + - deploy test contract + - call contract + - check all values are correct in log + """ + w3 = cronos.w3 + contract = deploy_contract( + w3, + CONTRACTS["TestBlockTxProperties"], + ) + + tx = contract.functions.emitTxDetails().build_transaction( + {"from": ADDRS["validator"]} + ) + receipt = send_transaction(w3, tx) + + assert receipt.status == 1 + assert len(receipt.logs) == 1 + + assert contract.address == receipt.logs[0]["address"] + event_signature = HexBytes( + abi.event_signature_to_log_topic( + "TxDetailsEvent(address,address,uint256,bytes,uint256,uint256,bytes4)" + ) + ) + assert event_signature == receipt.logs[0]["topics"][0] + validator_hex_address = HexBytes(b"\x00" * 12 + HexBytes(ADDRS["validator"])) + assert validator_hex_address == receipt.logs[0]["topics"][1] + assert validator_hex_address == receipt.logs[0]["topics"][2] + + event_abi = { + "anonymous": False, + "inputs": [ + { + "indexed": True, + "internalType": "address", + "name": "origin", + "type": "address", + }, + { + "indexed": True, + "internalType": "address", + "name": "sender", + "type": "address", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "value", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "bytes", + "name": "data", + "type": "bytes", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "price", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "uint256", + "name": "gas", + "type": "uint256", + }, + { + "indexed": False, + "internalType": "bytes4", + "name": "sig", + "type": "bytes4", + }, + ], + "name": "TxDetailsEvent", + "type": "event", + } + decoded = get_event_data(w3.codec, event_abi, receipt.logs[0]) + assert decoded["args"]["origin"] == ADDRS["validator"] + assert decoded["args"]["sender"] == ADDRS["validator"] + assert decoded["args"]["value"] == 0 + assert decoded["args"]["data"] != 0 + assert decoded["args"]["price"] > 0 + assert decoded["args"]["gas"] == 3633 + assert decoded["args"]["sig"] != 0 diff --git a/integration_tests/utils.py b/integration_tests/utils.py index 09498c306b..936299a05f 100644 --- a/integration_tests/utils.py +++ b/integration_tests/utils.py @@ -63,6 +63,7 @@ "TestICA": "TestICA.sol", "Random": "Random.sol", "TestRelayer": "TestRelayer.sol", + "TestBlockTxProperties": "TestBlockTxProperties.sol", } @@ -90,6 +91,8 @@ def contract_path(name, filename): CONTRACT_ABIS = { "IRelayerModule": Path(__file__).parent.parent / "build/IRelayerModule.abi", "IICAModule": Path(__file__).parent.parent / "build/IICAModule.abi", + "TestBlockTxProperties": Path(__file__).parent.parent + / "build/TestBlockTxProperties.abi", } From d28fabac574de1f15bb90daf5ac80f8e5b9a3b72 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Tue, 16 Sep 2025 15:53:06 +0900 Subject: [PATCH 4/7] remove unecessary abi --- integration_tests/utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration_tests/utils.py b/integration_tests/utils.py index 936299a05f..876317356d 100644 --- a/integration_tests/utils.py +++ b/integration_tests/utils.py @@ -91,8 +91,6 @@ def contract_path(name, filename): CONTRACT_ABIS = { "IRelayerModule": Path(__file__).parent.parent / "build/IRelayerModule.abi", "IICAModule": Path(__file__).parent.parent / "build/IICAModule.abi", - "TestBlockTxProperties": Path(__file__).parent.parent - / "build/TestBlockTxProperties.abi", } From 319f6cde2ae78278a1098427802d90f4c6ce44d9 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Tue, 16 Sep 2025 15:57:44 +0900 Subject: [PATCH 5/7] more robust test --- integration_tests/test_basic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index 8a27160e49..c518e49b09 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -1201,7 +1201,7 @@ def test_block_tx_properties(cronos): assert decoded["args"]["origin"] == ADDRS["validator"] assert decoded["args"]["sender"] == ADDRS["validator"] assert decoded["args"]["value"] == 0 - assert decoded["args"]["data"] != 0 + assert decoded["args"]["data"] == bytes.fromhex("8e091b5e") assert decoded["args"]["price"] > 0 assert decoded["args"]["gas"] == 3633 - assert decoded["args"]["sig"] != 0 + assert decoded["args"]["sig"] == bytes.fromhex("8e091b5e") From 9c22ec117c22d714df04158207f222acf3b99804 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Tue, 16 Sep 2025 16:00:32 +0900 Subject: [PATCH 6/7] cleanup --- integration_tests/test_basic.py | 67 +++++---------------------------- 1 file changed, 10 insertions(+), 57 deletions(-) diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index c518e49b09..c6e05b1153 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -1148,60 +1148,13 @@ def test_block_tx_properties(cronos): assert validator_hex_address == receipt.logs[0]["topics"][1] assert validator_hex_address == receipt.logs[0]["topics"][2] - event_abi = { - "anonymous": False, - "inputs": [ - { - "indexed": True, - "internalType": "address", - "name": "origin", - "type": "address", - }, - { - "indexed": True, - "internalType": "address", - "name": "sender", - "type": "address", - }, - { - "indexed": False, - "internalType": "uint256", - "name": "value", - "type": "uint256", - }, - { - "indexed": False, - "internalType": "bytes", - "name": "data", - "type": "bytes", - }, - { - "indexed": False, - "internalType": "uint256", - "name": "price", - "type": "uint256", - }, - { - "indexed": False, - "internalType": "uint256", - "name": "gas", - "type": "uint256", - }, - { - "indexed": False, - "internalType": "bytes4", - "name": "sig", - "type": "bytes4", - }, - ], - "name": "TxDetailsEvent", - "type": "event", - } - decoded = get_event_data(w3.codec, event_abi, receipt.logs[0]) - assert decoded["args"]["origin"] == ADDRS["validator"] - assert decoded["args"]["sender"] == ADDRS["validator"] - assert decoded["args"]["value"] == 0 - assert decoded["args"]["data"] == bytes.fromhex("8e091b5e") - assert decoded["args"]["price"] > 0 - assert decoded["args"]["gas"] == 3633 - assert decoded["args"]["sig"] == bytes.fromhex("8e091b5e") + # check event values + tx_details_event = contract.events.TxDetailsEvent().process_receipt(receipt) + data = tx_details_event[0]["args"] + assert data["origin"] == ADDRS["validator"] + assert data["sender"] == ADDRS["validator"] + assert data["value"] == 0 + assert data["data"] == bytes.fromhex("8e091b5e") + assert data["price"] > 0 + assert data["gas"] == 3633 + assert data["sig"] == bytes.fromhex("8e091b5e") From d19518067e04828c5fcf4bec6d65f478c97e47e5 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Tue, 16 Sep 2025 16:06:09 +0900 Subject: [PATCH 7/7] fix lint --- integration_tests/test_basic.py | 1 - 1 file changed, 1 deletion(-) diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index c6e05b1153..633855bff3 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -10,7 +10,6 @@ from eth_utils import abi, big_endian_to_int from hexbytes import HexBytes from pystarport import cluster, ports -from web3._utils.events import get_event_data from .cosmoscli import CosmosCLI, module_address from .network import Geth