Skip to content

Commit

Permalink
Merge branch 'main' into disable-gravity-bridge
Browse files Browse the repository at this point in the history
Signed-off-by: yihuang <[email protected]>
  • Loading branch information
yihuang authored Sep 27, 2023
2 parents 13e2722 + f11271b commit a5bbbe9
Show file tree
Hide file tree
Showing 53 changed files with 1,773 additions and 3,103 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
- (deps) [#1121](https://github.com/crypto-org-chain/cronos/pull/1121) Bump Cosmos-SDK to v0.47.5 and ibc-go to v7.2.0.
- [cronos#1014](https://github.com/crypto-org-chain/cronos/pull/1014) Support stateful precompiled contract for relayer.
- [cronos#1165](https://github.com/crypto-org-chain/cronos/pull/1165) Icaauth module is not adjusted correctly in ibc-go v7.2.0.
- [cronos#1163](https://github.com/crypto-org-chain/cronos/pull/1163) Support stateful precompiled contract for ica.
- [cronos#837](https://github.com/crypto-org-chain/cronos/pull/837) Support stateful precompiled contract for bank.
- [cronos#1184](https://github.com/crypto-org-chain/cronos/pull/1184) Update ibc-go to `v7.3.1`.
- [cronos#1187](https://github.com/crypto-org-chain/cronos/pull/1187) Disable gravity module in app.

### Bug Fixes
Expand Down Expand Up @@ -80,6 +82,8 @@
- [#1154](https://github.com/crypto-org-chain/cronos/pull/1154) Remove dependency on cosmos-sdk.
- [#1171](https://github.com/crypto-org-chain/cronos/pull/1171) Add memiavl background snapshot writing concurrency limit.
- [#1179](https://github.com/crypto-org-chain/cronos/pull/1179) Support blocking addresses in mempool.
- [#1182](https://github.com/crypto-org-chain/cronos/pull/1182) Bump librocksdb to 8.5.3.
- [#1183](https://github.com/crypto-org-chain/cronos/pull/1183) Avoid redundant logs added from relayer.

*April 13, 2023*

Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ func New(
[]vm.PrecompiledContract{
cronosprecompiles.NewBankContract(app.BankKeeper, appCodec),
cronosprecompiles.NewRelayerContract(app.IBCKeeper, appCodec),
cronosprecompiles.NewIcaContract(&app.ICAAuthKeeper, appCodec),
},
allKeys,
)
Expand Down
2 changes: 1 addition & 1 deletion app/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func benchmarkERC20Transfer(b *testing.B, db dbm.DB) {
ethSigner := ethtypes.LatestSignerForChainID(chainID)

signTx := func(msg *evmtypes.MsgEthereumTx) ([]byte, error) {
msg.From = address.String()
msg.From = address.Bytes()
if err := msg.Sign(ethSigner, signer); err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ require (
github.com/cometbft/cometbft v0.37.3-0.20230920093934-46df7b597e3c
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.3
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.2.0
github.com/cosmos/ibc-go/v7 v7.3.1-0.20230920070810-c3261472c815
github.com/crypto-org-chain/cronos/store v0.0.4
github.com/crypto-org-chain/cronos/versiondb v0.0.0-00010101000000-000000000000
github.com/ethereum/go-ethereum v1.10.26
github.com/evmos/ethermint v0.0.0-00010101000000-000000000000
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/linxGnu/grocksdb v1.8.0
github.com/linxGnu/grocksdb v1.8.4
github.com/peggyjv/gravity-bridge/module/v2 v2.0.0-20220420162017-838c0d25e974
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
Expand Down Expand Up @@ -233,7 +233,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.20230921025237-ae144329ecaf
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20230925072753-4062d0cc2a32
// 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
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoK
github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek=
github.com/cosmos/iavl v0.21.0-alpha.1.0.20230904092046-df3db2d96583 h1:3Matt7/LjZiZkIBPalYazOZcw2B05Ch14dU5TJyqJEc=
github.com/cosmos/iavl v0.21.0-alpha.1.0.20230904092046-df3db2d96583/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A=
github.com/cosmos/ibc-go/v7 v7.2.0 h1:dx0DLUl7rxdyZ8NiT6UsrbzKOJx/w7s+BOaewFRH6cg=
github.com/cosmos/ibc-go/v7 v7.2.0/go.mod h1:OOcjKIRku/j1Xs1RgKK0yvKRrJ5iFuZYMetR1n3yMlc=
github.com/cosmos/ibc-go/v7 v7.3.1-0.20230920070810-c3261472c815 h1:raSo7w7B3IXCb7DZozHWz8ajG7HLWZw9foiyCbEgInI=
github.com/cosmos/ibc-go/v7 v7.3.1-0.20230920070810-c3261472c815/go.mod h1:wvx4pPBofe5ZdMNV3OFRxSI4auEP5Qfqf8JXLLNV04g=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo=
Expand Down Expand Up @@ -482,8 +482,8 @@ github.com/crypto-org-chain/cometbft-db v0.0.0-20230921030527-0d47d7537e32 h1:Vq
github.com/crypto-org-chain/cometbft-db v0.0.0-20230921030527-0d47d7537e32/go.mod h1:V32HRAjDsAYLfAT90mk0O9UH+sE7P5apfiCmmmVLt3Q=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20230905040840-b3af5590283b h1:d2GOFR3i3BjDlPsmJkp8Gsrt9LK2nq2IVEnE/rMv1Fo=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20230905040840-b3af5590283b/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230921025237-ae144329ecaf h1:XvwFJ6kPHOYevfNjshq4n2nazvYzoSaQ8AjSYWSfUhI=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230921025237-ae144329ecaf/go.mod h1:KtjU2MHMCTcLnAoS9C3U3f+vx4f9HHNQRcOlxXiVDxY=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230925072753-4062d0cc2a32 h1:A++epzNCr3EY57dnU6UTSDwbCiPD6MjvUKHKSd/PoI8=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230925072753-4062d0cc2a32/go.mod h1:wnJQyK4n0vShhL+YIAUd7XCzUhgZ9fgG6yJ14n7qefo=
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 Expand Up @@ -1055,8 +1055,8 @@ github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6
github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
github.com/linxGnu/grocksdb v1.8.0 h1:H4L/LhP7GOMf1j17oQAElHgVlbEje2h14A8Tz9cM2BE=
github.com/linxGnu/grocksdb v1.8.0/go.mod h1:09CeBborffXhXdNpEcOeZrLKEnRtrZFEpFdPNI9Zjjg=
github.com/linxGnu/grocksdb v1.8.4 h1:ZMsBpPpJNtRLHiKKp0mI7gW+NT4s7UgfD5xHxx1jVRo=
github.com/linxGnu/grocksdb v1.8.4/go.mod h1:xZCIb5Muw+nhbDK4Y5UJuOrin5MceOuiXkVUR7vp4WY=
github.com/lufeee/execinquery v1.2.1/go.mod h1:EC7DrEKView09ocscGHC+apXMIaorh4xqSxS/dy8SbM=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
Expand Down
12 changes: 6 additions & 6 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ schema = 3
version = "v0.21.0-alpha.1.0.20230904092046-df3db2d96583"
hash = "sha256-3Va8Ljq63IXty0oHlRpqfsC6WsMut6TWZ2R+/nYtfTU="
[mod."github.com/cosmos/ibc-go/v7"]
version = "v7.2.0"
hash = "sha256-fg+0AykvEMzqRGI5CmqwjQtSIwTyT6RuSDpp12wzReM="
version = "v7.3.1-0.20230920070810-c3261472c815"
hash = "sha256-x/D64hmU+aOc5sm8RzXMB+8y+530+CCEik/Zpj3Rf9A="
[mod."github.com/cosmos/ics23/go"]
version = "v0.10.0"
hash = "sha256-KYEv727BO/ht63JO02xiKFGFAddg41Ve9l2vSSZZBq0="
Expand Down Expand Up @@ -213,8 +213,8 @@ schema = 3
hash = "sha256-GgcReGsIIuBE2TabDYqDO9sBGogdVr9RSh4arQzdPnE="
replaced = "github.com/evmos/go-ethereum"
[mod."github.com/evmos/ethermint"]
version = "v0.6.1-0.20230921025237-ae144329ecaf"
hash = "sha256-ZDzwB65qROKNIB4Yv1i+5FTJoejeuRCcUzUacyuFBFw="
version = "v0.6.1-0.20230925072753-4062d0cc2a32"
hash = "sha256-8zwdHROHnAVfly2PIaNAfiXfb2fWsTqePaZ58EJtjH4="
replaced = "github.com/crypto-org-chain/ethermint"
[mod."github.com/felixge/httpsnoop"]
version = "v1.0.2"
Expand Down Expand Up @@ -385,8 +385,8 @@ schema = 3
version = "v0.1.0"
hash = "sha256-wQqGTtRWsfR9n0O/SXHVgECebbnNmHddxJIbG63OJBQ="
[mod."github.com/linxGnu/grocksdb"]
version = "v1.8.0"
hash = "sha256-o6zj18at4oN6pqSioFqd1AXduR/cx0xDgtL1rPPw+1M="
version = "v1.8.4"
hash = "sha256-AGQ0YEuwUaev/mxOkiTNgAOLB9c7reHyTmNxXuaRah8="
[mod."github.com/magiconair/properties"]
version = "v1.8.7"
hash = "sha256-XQ2bnc2s7/IH3WxEO4GishZurMyKwEclZy1DXg+2xXc="
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/configs/ibc.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ config {
base_fee: '0',
},
},
icaauth: {
params: {
min_timeout_duration: '1ms',
},
},
},
},
},
Expand Down Expand Up @@ -100,6 +105,7 @@ config {
params: {
allow_messages: [
'/cosmos.bank.v1beta1.MsgSend',
'/cosmos.staking.v1beta1.MsgDelegate',
],
},
},
Expand Down
39 changes: 16 additions & 23 deletions integration_tests/contracts/contracts/TestBank.sol
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.6.6;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IBankModule} from "./src/Bank.sol";

contract TestBank is ERC20 {
address constant bankContract = 0x0000000000000000000000000000000000000064;
IBankModule bank = IBankModule(bankContract);

constructor() public ERC20("Bitcoin MAX", "MAX") {
_mint(msg.sender, 100000000000000000000000000);
}
function encodeMint(uint256 amount) internal view returns (bytes memory) {
return abi.encodeWithSignature("mint(address,uint256)", msg.sender, amount);
}
function moveToNative(uint256 amount) public {

function moveToNative(uint256 amount) public returns (bool) {
_burn(msg.sender, amount);
(bool result, ) = bankContract.call(encodeMint(amount));
require(result, "native call");
}
function encodeBurn(uint256 amount) internal view returns (bytes memory) {
return abi.encodeWithSignature("burn(address,uint256)", msg.sender, amount);
return bank.mint(msg.sender, amount);
}
function moveFromNative(uint256 amount) public {
(bool result, ) = bankContract.call(encodeBurn(amount));

function moveFromNative(uint256 amount) public returns (bool) {
bool result = bank.burn(msg.sender, amount);
require(result, "native call");
_mint(msg.sender, amount);
return result;
}
function encodeBalanceOf(address addr) internal view returns (bytes memory) {
return abi.encodeWithSignature("balanceOf(address,address)", address(this), addr);
}

function nativeBalanceOf(address addr) public returns (uint256) {
(bool result, bytes memory data) = bankContract.call(encodeBalanceOf(addr));
require(result, "native call");
return abi.decode(data, (uint256));
return bank.balanceOf(address(this), addr);
}

function moveToNativeRevert(uint256 amount) public {
moveToNative(amount);
revert("test");
}
function encodeTransfer(address recipient, uint256 amount) internal view returns (bytes memory) {
return abi.encodeWithSignature("transfer(address,address,uint256)", msg.sender, recipient, amount);
}
function nativeTransfer(address recipient, uint256 amount) public {

function nativeTransfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
(bool result, ) = bankContract.call(encodeTransfer(recipient, amount));
require(result, "native transfer");
return bank.transfer(msg.sender, recipient, amount);
}
}
95 changes: 95 additions & 0 deletions integration_tests/contracts/contracts/TestICA.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {IICAModule} from "./src/ICA.sol";

contract TestICA {
address constant icaContract = 0x0000000000000000000000000000000000000066;
IICAModule ica = IICAModule(icaContract);
address account;
uint64 lastAckSeq;

function encodeRegister(string memory connectionID, string memory version) internal view returns (bytes memory) {
return abi.encodeWithSignature(
"registerAccount(string,string)",
connectionID, msg.sender, version
);
}

function callRegister(string memory connectionID, string memory version) public returns (bool) {
require(account == address(0) || account == msg.sender, "register fail");
bool result = ica.registerAccount(connectionID, version);
require(result, "call failed");
account = msg.sender;
}

function getAccount() public view returns (address) {
return account;
}

function delegateRegister(string memory connectionID, string memory version) public returns (bool) {
(bool result,) = icaContract.delegatecall(encodeRegister(connectionID, version));
require(result, "call failed");
return true;
}

function staticRegister(string memory connectionID, string memory version) public returns (bool) {
(bool result,) = icaContract.staticcall(encodeRegister(connectionID, version));
require(result, "call failed");
return true;
}

function encodeQueryAccount(string memory connectionID, address addr) internal view returns (bytes memory) {
return abi.encodeWithSignature(
"queryAccount(string,address)",
connectionID, addr
);
}

function callQueryAccount(string memory connectionID, address addr) public returns (string memory) {
return ica.queryAccount(connectionID, addr);
}

function delegateQueryAccount(string memory connectionID, address addr) public returns (string memory) {
(bool result, bytes memory data) = icaContract.delegatecall(encodeQueryAccount(connectionID, addr));
require(result, "call failed");
return abi.decode(data, (string));
}

function staticQueryAccount(string memory connectionID, address addr) public returns (string memory) {
(bool result, bytes memory data) = icaContract.staticcall(encodeQueryAccount(connectionID, addr));
require(result, "call failed");
return abi.decode(data, (string));
}

function encodeSubmitMsgs(string memory connectionID, bytes memory data, uint256 timeout) internal view returns (bytes memory) {
return abi.encodeWithSignature(
"submitMsgs(string,bytes,uint256)",
connectionID, msg.sender, data, timeout
);
}

function callSubmitMsgs(string memory connectionID, bytes memory data, uint256 timeout) public returns (uint64) {
require(account == msg.sender, "not authorized");
lastAckSeq = ica.submitMsgs(connectionID, data, timeout);
return lastAckSeq;
}

function delegateSubmitMsgs(string memory connectionID, bytes memory data, uint256 timeout) public returns (uint64) {
(bool result, bytes memory data) = icaContract.delegatecall(encodeSubmitMsgs(connectionID, data, timeout));
require(result, "call failed");
lastAckSeq = abi.decode(data, (uint64));
return lastAckSeq;
}

function staticSubmitMsgs(string memory connectionID, bytes memory data, uint256 timeout) public returns (uint64) {
(bool result, bytes memory data) = icaContract.staticcall(encodeSubmitMsgs(connectionID, data, timeout));
require(result, "call failed");
lastAckSeq = abi.decode(data, (uint64));
return lastAckSeq;
}

function getLastAckSeq() public view returns (uint256) {
return lastAckSeq;
}
}
1 change: 1 addition & 0 deletions integration_tests/contracts/contracts/src
26 changes: 9 additions & 17 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,10 +1062,10 @@ def set_delegate_keys(self, val_addr, acc_addr, eth_addr, signature, **kwargs):
)

def query_gravity_params(self):
return json.loads(self.raw("query", "gravity", "params", home=self.data_dir))
return self.query_params("gravity")

def query_evm_params(self):
return json.loads(self.raw("query", "evm", "params", home=self.data_dir))
def query_params(self, module="cronos"):
return json.loads(self.raw("query", module, "params", home=self.data_dir))

def query_signer_set_txs(self):
return json.loads(
Expand Down Expand Up @@ -1275,7 +1275,7 @@ def icaauth_register_account(self, connid, **kwargs):
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def icaauth_submit_tx(self, connid, tx, **kwargs):
def icaauth_submit_tx(self, connid, tx, timeout_duration="1h", **kwargs):
default_kwargs = {
"home": self.data_dir,
"node": self.node_rpc,
Expand All @@ -1289,6 +1289,8 @@ def icaauth_submit_tx(self, connid, tx, **kwargs):
"submit-tx",
connid,
tx,
"--timeout-duration" if timeout_duration else None,
timeout_duration if timeout_duration else None,
"-y",
**(default_kwargs | kwargs),
)
Expand All @@ -1313,15 +1315,16 @@ def ica_query_account(self, connid, owner, **kwargs):
)
)

def ica_generate_packet_data(self, tx, memo=None, **kwargs):
def ica_generate_packet_data(self, tx, memo=None, encoding="proto3", **kwargs):
return json.loads(
self.raw(
"tx",
"interchain-accounts",
"host",
"generate-packet-data",
tx,
"--memo" if memo else None,
memo=memo,
encoding=encoding,
home=self.data_dir,
**kwargs,
)
Expand Down Expand Up @@ -1586,17 +1589,6 @@ def turn_bridge(self, enable, **kwargs):
)
)

def query_params(self):
"query cronos params"
return json.loads(
self.raw(
"query",
"cronos",
"params",
home=self.data_dir,
)
)

def evm_params(self, **kwargs):
default_kwargs = {
"node": self.node_rpc,
Expand Down
Loading

0 comments on commit a5bbbe9

Please sign in to comment.