Skip to content

Commit

Permalink
Problem: logs in callback contract are lost (#1233)
Browse files Browse the repository at this point in the history
* Problem: logs in callback contract are lost

Closes: #1231

Solution:
- re-emit those logs

* Update CHANGELOG.md

Signed-off-by: yihuang <[email protected]>

* constant refactor

* fix getLogs

* use precompile relayer to test ica callback

* cover crc20 callbacks as well

* inject the statedb in ethermint

* simplify assert log

* test without rly precompile

* cleanup

* Revert "test without rly precompile"

This reverts commit 25c3fee.

---------

Signed-off-by: yihuang <[email protected]>
Co-authored-by: mmsqe <[email protected]>
  • Loading branch information
yihuang and mmsqe authored Nov 2, 2023
1 parent dbd86c4 commit 394bce5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [#1217](https://github.com/crypto-org-chain/cronos/pull/1217) Use the default chain-id behavour in sdk.
- [#1216](https://github.com/crypto-org-chain/cronos/pull/1216) Update ethermint to fix of avoid redundant parse chainID from gensis when start server.
- [#1230](https://github.com/crypto-org-chain/cronos/pull/1230) Fix mem store in versiondb multistore.
- [#1233](https://github.com/crypto-org-chain/cronos/pull/1233) Re-emit logs in callback contract.

*October 17, 2023*

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,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/evmos/go-ethereum v1.10.26-evmos-rc1
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20231027030935-291bfa0458c4
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20231101080732-b9078abfe0fd
// 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 @@ -484,8 +484,8 @@ 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.20231013072415-eec017435467 h1:m0/aHPIJAzi2MSP3TXzzbLTFf+koRFQiaYmerRZUtK4=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20231013072415-eec017435467/go.mod h1:G384omH7cXgm90xXR7xpHvsKG7vdBaDuz4To6GpTHUU=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231027030935-291bfa0458c4 h1:uLaq7qqIYJ2tJ5fQE5EBvqAgvM5Y4jWbz9V4AURwMGI=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231027030935-291bfa0458c4/go.mod h1:rbAKU2rftDobCIoCiol3SO+bTqw2cERu9TEki7PvfK0=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231101080732-b9078abfe0fd h1:8AWwJrxYtQxoZ1rrM9+w6MLScVe6LzskRo8UF9ep7Qs=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231101080732-b9078abfe0fd/go.mod h1:rbAKU2rftDobCIoCiol3SO+bTqw2cERu9TEki7PvfK0=
github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e h1:rSTc35OBjjCBx47rHPWBCIHNGPbMnEj8f7fNcK2TjVI=
github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e/go.mod h1:HBaDqlFjlaXJwVQtA7jHejyaA7xwjXI2o6pU/ccP3tE=
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ schema = 3
hash = "sha256-GgcReGsIIuBE2TabDYqDO9sBGogdVr9RSh4arQzdPnE="
replaced = "github.com/evmos/go-ethereum"
[mod."github.com/evmos/ethermint"]
version = "v0.6.1-0.20231027030935-291bfa0458c4"
hash = "sha256-T+iQ9tSyGTvJn7wSIFCFWqUeU9KUk3Ml4v1rgC9FENk="
version = "v0.6.1-0.20231101080732-b9078abfe0fd"
hash = "sha256-FlKoOdJbNqQfloOxV5AGd5TIm3VLjoZW8YOLnuJY7FY="
replaced = "github.com/crypto-org-chain/ethermint"
[mod."github.com/felixge/httpsnoop"]
version = "v1.0.2"
Expand Down
21 changes: 19 additions & 2 deletions integration_tests/test_ica_precompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from enum import IntEnum

import pytest
from pystarport import cluster
from web3.datastructures import AttributeDict

from .ibc_utils import (
Expand Down Expand Up @@ -45,9 +46,15 @@ class Status(IntEnum):
@pytest.fixture(scope="module")
def ibc(request, tmp_path_factory):
"prepare-network"
name = "ibc"
name = "ibc_rly"
path = tmp_path_factory.mktemp(name)
yield from prepare_network(path, name, incentivized=False, connection_only=True)
yield from prepare_network(
path,
name,
incentivized=False,
connection_only=True,
relayer=cluster.Relayer.RLY.value,
)


def register_acc(cli, w3, register, query, data, addr, channel_id):
Expand Down Expand Up @@ -177,6 +184,12 @@ def check_status():
wait_for_fn("current status", check_status)


def assert_packet_result(event, seq, status):
(logs) = event.getLogs()
assert len(logs) > 0
return logs[0].args == AttributeDict({"seq": seq, "status": status})


def test_sc_call(ibc):
cli_host = ibc.chainmain.cosmos_cli()
cli_controller = ibc.cronos.cosmos_cli()
Expand Down Expand Up @@ -243,6 +256,7 @@ def submit_msgs_ro(func, str):
status = tcontract.caller.statusMap(last_seq)
assert expected_seq == last_seq
assert status == Status.SUCCESS
assert_packet_result(tcontract.events.OnPacketResult, last_seq, status)
balance -= diff
assert cli_host.balance(ica_address, denom=denom) == balance

Expand All @@ -262,6 +276,7 @@ def submit_msgs_ro(func, str):
status = tcontract.caller.statusMap(last_seq)
assert expected_seq == last_seq
assert status == Status.SUCCESS
assert_packet_result(tcontract.events.OnPacketResult, last_seq, status)
balance -= diff
assert cli_host.balance(ica_address, denom=denom) == balance

Expand All @@ -282,6 +297,7 @@ def submit_msgs_ro(func, str):
status = tcontract.caller.statusMap(last_seq)
assert expected_seq == last_seq
assert status == Status.FAIL
assert_packet_result(tcontract.events.OnPacketResult, last_seq, status)
assert cli_host.balance(ica_address, denom=denom) == balance

# balance should not change on timeout
Expand All @@ -301,4 +317,5 @@ def submit_msgs_ro(func, str):
status = tcontract.caller.statusMap(last_seq)
assert expected_seq == last_seq
assert status == Status.FAIL
assert_packet_result(tcontract.events.OnPacketResult, last_seq, status)
assert cli_host.balance(ica_address, denom=denom) == balance
10 changes: 10 additions & 0 deletions x/cronos/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/evmos/ethermint/x/evm/statedb"
evmtypes "github.com/evmos/ethermint/x/evm/types"

"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
Expand All @@ -35,6 +37,14 @@ func (k Keeper) CallEVM(ctx sdk.Context, to *common.Address, data []byte, value
if err != nil {
return nil, nil, err
}

// if the call is from an precompiled contract call, then re-emit the logs into the original stateDB.
if stateDB, ok := ctx.Value(statedb.StateDBContextKey).(vm.StateDB); ok {
for _, l := range ret.Logs {
stateDB.AddLog(l.ToEthereum())
}
}

return &msg, ret, nil
}

Expand Down

0 comments on commit 394bce5

Please sign in to comment.