Skip to content

Commit

Permalink
Problem: restriction of same sender tx appear in the same tx after co…
Browse files Browse the repository at this point in the history
…ntract creation is not included (#1723)

* Problem: restriction of same sender tx appear in the same tx after contract creation is not included

* integration test

* cleanup

* cleanup

---------

Co-authored-by: HuangYi <[email protected]>
  • Loading branch information
mmsqe and yihuang authored Dec 18, 2024
1 parent 447007d commit 649fd58
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug Fixes

* [#1720](https://github.com/crypto-org-chain/cronos/pull/1720) Include the fix of performance regression after upgrade in iavl.
* [#1723](https://github.com/crypto-org-chain/cronos/pull/1723) Include the restriction of same sender tx appear in the same tx after contract creation in ethermint.

*Dec 9, 2024*

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/99designs/keyring v1.2.2
github.com/cometbft/cometbft v0.38.15
github.com/cosmos/cosmos-db v1.0.3-0.20240408151834-e75f6e4b28d8
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.50.9
github.com/cosmos/gogoproto v1.7.0
github.com/cosmos/ibc-go/modules/apps/callbacks v0.0.0-20240913130017-6b2554360c0e // v8.5.1
Expand Down Expand Up @@ -86,7 +87,6 @@ require (
github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect
github.com/cometbft/cometbft-db v0.15.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.2.3 // indirect
Expand Down Expand Up @@ -272,7 +272,7 @@ replace (
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.20240926023215-d2275b4afb9a
// release/v1.4.x
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20241118003049-cd93407bcf05
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20241217093037-21bd7ce300e8
// 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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241205052910-142c0afa4948
github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241205052910-142c0afa4948/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM=
github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20241205052910-142c0afa4948 h1:lb8Mztnt2bpCowKbZMHosyQtXN0QtX/MITH9y5DVNkU=
github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20241205052910-142c0afa4948/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w=
github.com/crypto-org-chain/ethermint v0.6.1-0.20241118003049-cd93407bcf05 h1:4mewSJnWOTwRbBntlAtOj5ZevujX4PGwn57QcO99+Bo=
github.com/crypto-org-chain/ethermint v0.6.1-0.20241118003049-cd93407bcf05/go.mod h1:9FNO9k70szJ7CEge4tnJraWu3baTbwNxjpZhZBqlMok=
github.com/crypto-org-chain/ethermint v0.6.1-0.20241217093037-21bd7ce300e8 h1:R07pGqWiqQNJonAA6htHUlniWRYP4ZnZEAVLLWX6E8Y=
github.com/crypto-org-chain/ethermint v0.6.1-0.20241217093037-21bd7ce300e8/go.mod h1:9FNO9k70szJ7CEge4tnJraWu3baTbwNxjpZhZBqlMok=
github.com/crypto-org-chain/go-block-stm v0.0.0-20240919080136-6c49aef68716 h1:OvD5Rm0B6LHUJk6z858UgwdP72jU2DuUdXeclRyKpDI=
github.com/crypto-org-chain/go-block-stm v0.0.0-20240919080136-6c49aef68716/go.mod h1:iwQTX9xMX8NV9k3o2BiWXA0SswpsZrDk5q3gA7nWYiE=
github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240926023215-d2275b4afb9a h1:IUPD+dg1YQl8cLocxQ/Mbx/ObTgAgcrZlcBhFjsLO40=
Expand Down
6 changes: 3 additions & 3 deletions gomod2nix.toml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions integration_tests/contracts/contracts/TestERC20Owner.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity 0.8.21;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// An utility erc20 contract that has a fancy method
contract TestERC20Owner is ERC20 {
constructor(address owner) public ERC20("Fancy", "FNY") {
_mint(owner, 100000000000000000000000000);
}
}

28 changes: 19 additions & 9 deletions integration_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
RevertTestContract,
assert_gov_params,
build_batch_tx,
build_batch_tx_signed,
contract_address,
contract_path,
deploy_contract,
Expand Down Expand Up @@ -677,24 +678,33 @@ def test_batch_tx(cronos):
"send multiple eth txs in single cosmos tx"
w3 = cronos.w3
cli = cronos.cosmos_cli()
sender = ADDRS["validator"]
deployer = ADDRS["validator"]
sender = ADDRS["signer1"]
recipient = ADDRS["community"]
deployer_nonce = w3.eth.get_transaction_count(deployer)
nonce = w3.eth.get_transaction_count(sender)
info = json.loads(CONTRACTS["TestERC20Utility"].read_text())
info = json.loads(CONTRACTS["TestERC20Owner"].read_text())
contract = w3.eth.contract(abi=info["abi"], bytecode=info["bytecode"])
deploy_tx = contract.constructor().build_transaction(
{"from": sender, "nonce": nonce}
deploy_tx = contract.constructor(sender).build_transaction(
{"from": deployer, "nonce": deployer_nonce}
)
contract = w3.eth.contract(
address=contract_address(deployer, deployer_nonce), abi=info["abi"]
)
contract = w3.eth.contract(address=contract_address(sender, nonce), abi=info["abi"])
transfer_tx1 = contract.functions.transfer(recipient, 1000).build_transaction(
{"from": sender, "nonce": nonce + 1, "gas": 200000}
{"from": sender, "nonce": nonce, "gas": 200000}
)
transfer_tx2 = contract.functions.transfer(recipient, 1000).build_transaction(
{"from": sender, "nonce": nonce + 2, "gas": 200000}
{"from": sender, "nonce": nonce + 1, "gas": 200000}
)

cosmos_tx, tx_hashes = build_batch_tx(
w3, cli, [deploy_tx, transfer_tx1, transfer_tx2]
cosmos_tx, tx_hashes = build_batch_tx_signed(
cli,
[
sign_transaction(w3, deploy_tx, KEYS["validator"]),
sign_transaction(w3, transfer_tx1, KEYS["signer1"]),
sign_transaction(w3, transfer_tx2, KEYS["signer1"]),
],
)
rsp = cli.broadcast_tx_json(cosmos_tx)
assert rsp["code"] == 0, rsp["raw_log"]
Expand Down
6 changes: 5 additions & 1 deletion integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"TestICA": "TestICA.sol",
"Random": "Random.sol",
"TestRelayer": "TestRelayer.sol",
"TestERC20Owner": "TestERC20Owner.sol",
}


Expand Down Expand Up @@ -548,7 +549,10 @@ def modify_command_in_supervisor_config(ini: Path, fn, **kwargs):

def build_batch_tx(w3, cli, txs, key=KEYS["validator"]):
"return cosmos batch tx and eth tx hashes"
signed_txs = [sign_transaction(w3, tx, key) for tx in txs]
return build_batch_tx_signed(cli, [sign_transaction(w3, tx, key) for tx in txs])


def build_batch_tx_signed(cli, signed_txs):
tmp_txs = [cli.build_evm_tx(signed.rawTransaction.hex()) for signed in signed_txs]

msgs = [tx["body"]["messages"][0] for tx in tmp_txs]
Expand Down

0 comments on commit 649fd58

Please sign in to comment.