From f0d4032dfa9b73b0b5b6c0c098a087ca6a0a25fb Mon Sep 17 00:00:00 2001 From: "Leslie H. Cheung" <51898510+lezzokafka@users.noreply.github.com> Date: Thu, 2 May 2024 12:01:32 +0800 Subject: [PATCH 1/4] Update SECURITY.md (#1420) Signed-off-by: Leslie H. Cheung <51898510+lezzokafka@users.noreply.github.com> --- SECURITY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SECURITY.md b/SECURITY.md index bd8922f4a7..ac1f3d2b53 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -14,6 +14,6 @@ Once we receive a vulnerability report, Crypto.org will take these steps to addr 4. Crypto.org will publicly release the security patch for the vulnerability, and acknowledge the security fix in the release notes once the issue has been resolved. Public release notes can reference to the person or people who reported the vulnerability, unless they wish to stay anonymous. ## Contact Us -If you find a security issue, you can report it on the [Cronos Immunefi Bug Bounty Program](https://immunefi.com/bounty/cronos/) or you can contact our team directly at [chain-security@crypto.com](mailto:chain-security@crypto.com). +If you find a security issue, you can report it on the [Hackenproof Bug Bounty Program](https://hackenproof.com/cronos) or you can contact our team directly at [chain-security@crypto.com](mailto:chain-security@crypto.com). To communicate sensitive information, you can use the latest key in the [cryptocom's Keybase account](https://keybase.io/cryptocom/pgp_keys.asc) or use its [chat functionality](https://keybase.io/cryptocom/chat). From 6f49e3c7ca9a5017bde93318d194b17490b7de13 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 3 May 2024 11:15:45 +0800 Subject: [PATCH 2/4] Problem: new evm tx format not integrated (#1414) * Problem: new evm tx format not integrated * Update CHANGELOG.md Signed-off-by: yihuang * update deps * update go * use rly * less users * fix * update deps --------- Signed-off-by: yihuang Co-authored-by: mmsqe --- CHANGELOG.md | 1 + go.mod | 4 ++-- go.sum | 8 ++++---- gomod2nix.toml | 8 ++++---- integration_tests/ibc_utils.py | 3 ++- integration_tests/test_ibc_rly.py | 6 +++--- nix/default.nix | 4 ++-- nix/sources.json | 6 +++--- x/cronos/keeper/evm.go | 4 ++-- x/cronos/keeper/evm_hooks.go | 2 +- x/cronos/keeper/evm_hooks_test.go | 9 ++++----- x/cronos/keeper/grpc_query.go | 7 +------ x/cronos/rpc/api.go | 26 +++++++++----------------- x/cronos/types/interfaces.go | 2 +- 14 files changed, 39 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef215195c9..ae78f413a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * [#1377](https://github.com/crypto-org-chain/cronos/pull/1377) Upgrade sdk to 0.50, and integrate block-stm parallel tx execution. * [#1394](https://github.com/crypto-org-chain/cronos/pull/1394) Add icahost wirings but disable in parameters. * [#1407](https://github.com/crypto-org-chain/cronos/pull/1407) Add end-to-end encryption module. +* [#1414](https://github.com/crypto-org-chain/cronos/pull/1414) Integrate new evm tx format. ### Improvements diff --git a/go.mod b/go.mod index 95c85bcbc7..120d4ce53f 100644 --- a/go.mod +++ b/go.mod @@ -274,9 +274,9 @@ replace ( // dgrijalva/jwt-go is deprecated and doesn't receive security updates. // 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/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7 // block-stm branch - github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20240419013511-775ac80b75c7 + github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20240502052908-179e436703b3 // 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 1884d9987a..e637cba9b9 100644 --- a/go.sum +++ b/go.sum @@ -429,12 +429,12 @@ github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240415105151-0108877a3201 github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240415105151-0108877a3201/go.mod h1:lfuLI1f4o+0SGtlHQS4x5qsjRcZZfYqG8bp3k8hM0M8= github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240415105151-0108877a3201 h1:DbCOM19ywdL5K+bOy4h+0MppzcPgI2guHnYCfDNnAcM= github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240415105151-0108877a3201/go.mod h1:CBCU6fsRVz23QGFIQBb1DNX2DztJCf3jWyEkHY2nJQ0= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240419013511-775ac80b75c7 h1:tawNK/e1F1AexRdhxC9o6M70IIrbCuvM6C8F/ujHwTY= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240419013511-775ac80b75c7/go.mod h1:OSFT4cvzHl0g2DizYR9vIy5/xRYAvFJrnRydAmgCqyM= +github.com/crypto-org-chain/ethermint v0.6.1-0.20240502052908-179e436703b3 h1:YYmMJowZyiyioNHYnps5hw3XkV1zcXSC3jy/xzqK2Rg= +github.com/crypto-org-chain/ethermint v0.6.1-0.20240502052908-179e436703b3/go.mod h1:9MVSajfKloRP8h2chP78LhCKx5u9O2pCMBvxrmx6+0s= github.com/crypto-org-chain/go-block-stm v0.0.0-20240408011717-9f11af197bde h1:sQIHTJfVt5VTrF7po9eZiFkZiPjlHbFvnXtGCOoBjNM= github.com/crypto-org-chain/go-block-stm v0.0.0-20240408011717-9f11af197bde/go.mod h1:iwQTX9xMX8NV9k3o2BiWXA0SswpsZrDk5q3gA7nWYiE= -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/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7 h1:V43F3JFcqG4MUThf9W/DytnPblpR6CcaLBw2Wx6zTgE= +github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7/go.mod h1:+a8pUj1tOyJ2RinsNQD4326YS+leSoKGiG/uVVb0x6Y= github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/gomod2nix.toml b/gomod2nix.toml index e032605394..493dc9b728 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -258,12 +258,12 @@ schema = 3 version = "v1.6.1" hash = "sha256-zOpoaepCfPLmU9iQji/Ait+SVEHI9eF3rwtW0h/8lho=" [mod."github.com/ethereum/go-ethereum"] - version = "v1.10.20-0.20231207063621-43cf32d91c3e" - hash = "sha256-lDIqRLUrXYCb9mmFBY/+WW+ee69+IkxOgqjHVyo4ij0=" + version = "v1.10.20-0.20240425065928-ebb09502e7a7" + hash = "sha256-lE4G5FaRb3MVi9FFVn+WlwsSTOB4SbjmVboKyQ5yB0A=" replaced = "github.com/crypto-org-chain/go-ethereum" [mod."github.com/evmos/ethermint"] - version = "v0.6.1-0.20240419013511-775ac80b75c7" - hash = "sha256-94bgC0Z+VD8w9j8+mwW/7PJSZlpKdtdR87C1E8hg3T4=" + version = "v0.6.1-0.20240502052908-179e436703b3" + hash = "sha256-Qc5A89wi+KCKfFdyvZit5MI4yKDhDvvSjkiYL0EIzNA=" replaced = "github.com/crypto-org-chain/ethermint" [mod."github.com/fatih/color"] version = "v1.16.0" diff --git a/integration_tests/ibc_utils.py b/integration_tests/ibc_utils.py index e6a3fdfdb4..6895558dc7 100644 --- a/integration_tests/ibc_utils.py +++ b/integration_tests/ibc_utils.py @@ -333,7 +333,8 @@ def get_balances(chain, addr): def ibc_multi_transfer(ibc): chains = [ibc.cronos.cosmos_cli(), ibc.chainmain.cosmos_cli()] - users = [f"user{i}" for i in range(1, 21)] + # FIXME: more users after batch fix + users = [f"user{i}" for i in range(1, 2)] addrs0 = [chains[0].address(user) for user in users] addrs1 = [chains[1].address(user) for user in users] denom0 = "basetcro" diff --git a/integration_tests/test_ibc_rly.py b/integration_tests/test_ibc_rly.py index 1dbbe16a28..4b35d0f786 100644 --- a/integration_tests/test_ibc_rly.py +++ b/integration_tests/test_ibc_rly.py @@ -11,11 +11,11 @@ cronos_transfer_source_tokens, cronos_transfer_source_tokens_with_proxy, get_balance, - hermes_transfer, ibc_denom, ibc_incentivized_transfer, ibc_multi_transfer, prepare_network, + rly_transfer, ) from .utils import ( ADDRS, @@ -54,7 +54,7 @@ def ibc(request, tmp_path_factory): yield from prepare_network( path, name, - relayer=cluster.Relayer.HERMES.value, + relayer=cluster.Relayer.RLY.value, ) @@ -232,7 +232,7 @@ def test_ibc(ibc): w3 = ibc.cronos.w3 wait_for_new_blocks(ibc.cronos.cosmos_cli(), 1) start = w3.eth.get_block_number() - hermes_transfer(ibc) + rly_transfer(ibc) denom = ibc_denom(channel, src_denom) dst_addr = eth_to_bech32(cronos_signer2) old_dst_balance = get_balance(ibc.cronos, dst_addr, dst_denom) diff --git a/nix/default.nix b/nix/default.nix index e6c1364dc5..f061a10e59 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -47,11 +47,11 @@ import sources.nixpkgs { cosmovisor = pkgs.callPackage ./cosmovisor.nix { }; }) (_: pkgs: { - rly = pkgs.buildGo120Module rec { + rly = pkgs.buildGo121Module rec { name = "rly"; src = sources.relayer; subPackages = [ "." ]; - vendorHash = "sha256-5s5URiAZk59mOfZdUcqYAB/IvzFuBiQH5jDBuh6huTE="; + vendorHash = "sha256-dwKZZu9wKOo2u1/8AAWFx89iC9pWZbCxAERMMAOFsts="; doCheck = false; GOWORK = "off"; postInstall = '' diff --git a/nix/sources.json b/nix/sources.json index 336932e6c3..960af8a9a1 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -126,10 +126,10 @@ "homepage": "https://github.com/crypto-org-chain/relayer", "owner": "crypto-org-chain", "repo": "relayer", - "rev": "bd88a2cba9154450924837ecda915688ff8f9e04", - "sha256": "106mf4mc2ag4a5d21lcqpsq7ixvq70097jglw862jz4g9lbxyv8f", + "rev": "9479327b768a0a0e527c1b34eca353afebac5d15", + "sha256": "0ksxv4al8fjq7p8j3s28h23rr1qzn8fv7gmhcpchwz1536jx2kk4", "type": "tarball", - "url": "https://github.com/crypto-org-chain/relayer/archive/bd88a2cba9154450924837ecda915688ff8f9e04.tar.gz", + "url": "https://github.com/crypto-org-chain/relayer/archive/9479327b768a0a0e527c1b34eca353afebac5d15.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/x/cronos/keeper/evm.go b/x/cronos/keeper/evm.go index dd4a56dd2d..a0eb527622 100644 --- a/x/cronos/keeper/evm.go +++ b/x/cronos/keeper/evm.go @@ -22,7 +22,7 @@ const DefaultGasCap uint64 = 25000000 // CallEVM execute an evm message from native module func (k Keeper) CallEVM(ctx sdk.Context, to *common.Address, data []byte, value *big.Int, gasLimit uint64) (*core.Message, *evmtypes.MsgEthereumTxResponse, error) { nonce := k.evmKeeper.GetNonce(ctx, types.EVMModuleAddress) - msg := core.Message{ + msg := &core.Message{ From: types.EVMModuleAddress, To: to, Nonce: nonce, @@ -47,7 +47,7 @@ func (k Keeper) CallEVM(ctx sdk.Context, to *common.Address, data []byte, value } } - return &msg, ret, nil + return msg, ret, nil } // CallModuleCRC21 call a method of ModuleCRC21 contract diff --git a/x/cronos/keeper/evm_hooks.go b/x/cronos/keeper/evm_hooks.go index 44dee154aa..f630b719bc 100644 --- a/x/cronos/keeper/evm_hooks.go +++ b/x/cronos/keeper/evm_hooks.go @@ -26,7 +26,7 @@ func NewLogProcessEvmHook(handlers ...types.EvmLogHandler) *LogProcessEvmHook { } // PostTxProcessing implements EvmHook interface -func (h LogProcessEvmHook) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *ethtypes.Receipt) error { +func (h LogProcessEvmHook) PostTxProcessing(ctx sdk.Context, _ *core.Message, receipt *ethtypes.Receipt) error { addLogToReceiptFunc := newFuncAddLogToReceipt(receipt) for _, log := range receipt.Logs { if len(log.Topics) == 0 { diff --git a/x/cronos/keeper/evm_hooks_test.go b/x/cronos/keeper/evm_hooks_test.go index f46a6911d9..4c0428169f 100644 --- a/x/cronos/keeper/evm_hooks_test.go +++ b/x/cronos/keeper/evm_hooks_test.go @@ -6,7 +6,6 @@ import ( sdkmath "cosmossdk.io/math" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core" ethtypes "github.com/ethereum/go-ethereum/core/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -42,7 +41,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() { receipt := ðtypes.Receipt{ Logs: logs, } - err := suite.app.EvmKeeper.PostTxProcessing(suite.ctx, core.Message{}, receipt) + err := suite.app.EvmKeeper.PostTxProcessing(suite.ctx, nil, receipt) suite.Require().NoError(err) }, }, @@ -64,7 +63,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() { receipt := ðtypes.Receipt{ Logs: logs, } - err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, core.Message{}, receipt) + err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, nil, receipt) suite.Require().Error(err) }, }, @@ -94,7 +93,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() { receipt := ðtypes.Receipt{ Logs: logs, } - err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, core.Message{}, receipt) + err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, nil, receipt) suite.Require().NoError(err) balance = suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), denom) @@ -144,7 +143,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() { receipt := ðtypes.Receipt{ Logs: logs, } - err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, core.Message{}, receipt) + err = suite.app.EvmKeeper.PostTxProcessing(suite.ctx, nil, receipt) // should fail, because of not ibc denom name suite.Require().Error(err) }, diff --git a/x/cronos/keeper/grpc_query.go b/x/cronos/keeper/grpc_query.go index f8f37aeab1..7bc1568154 100644 --- a/x/cronos/keeper/grpc_query.go +++ b/x/cronos/keeper/grpc_query.go @@ -75,16 +75,11 @@ func (k Keeper) ReplayBlock(goCtx context.Context, req *types.ReplayBlockRequest // we assume the message executions are successful, they are filtered in json-rpc api for _, msg := range req.Msgs { // deduct fee - txData, err := evmtypes.UnpackTxData(msg.Data) - if err != nil { - return nil, err - } - // populate the `From` field if _, err := msg.GetSenderLegacy(ethtypes.LatestSignerForChainID(chainID)); err != nil { return nil, err } - fees, err := evmkeeper.VerifyFee(txData, evmDenom, baseFee, homestead, istanbul, shanghai, ctx.IsCheckTx()) + fees, err := evmkeeper.VerifyFee(msg, evmDenom, baseFee, homestead, istanbul, shanghai, ctx.IsCheckTx()) if err != nil { return nil, errorsmod.Wrapf(err, "failed to verify the fees") } diff --git a/x/cronos/rpc/api.go b/x/cronos/rpc/api.go index e2b6d68358..ebe7076e4d 100644 --- a/x/cronos/rpc/api.go +++ b/x/cronos/rpc/api.go @@ -159,12 +159,7 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block return nil, fmt.Errorf("invalid tx type: %T", msg) } - txData, err := evmtypes.UnpackTxData(ethMsg.Data) - if err != nil { - api.logger.Error("failed to unpack tx data", "error", err.Error()) - return nil, err - } - + txData := ethMsg.AsTransaction() parsedTx := parsedTxs.GetTxByMsgIndex(msgIndex) // Get the transaction result from the log @@ -179,7 +174,7 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block return nil, err } - logs, err := evmtypes.DecodeMsgLogsFromEvents(txResult.Data, parsedTx.MsgIndex, uint64(blockRes.Height)) + logs, err := evmtypes.DecodeMsgLogsFromEvents(txResult.Data, txResult.Events, parsedTx.MsgIndex, uint64(blockRes.Height)) if err != nil { api.logger.Debug("failed to parse logs", "block", resBlock.Block.Height, "txIndex", txIndex, "msgIndex", msgIndex, "error", err.Error()) } @@ -197,7 +192,7 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block // Implementation fields: These fields are added by geth when processing a transaction. // They are stored in the chain database. - "transactionHash": ethMsg.Hash, + "transactionHash": txData.Hash(), "contractAddress": nil, "gasUsed": hexutil.Uint64(parsedTx.GasUsed), @@ -209,21 +204,18 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block // sender and receiver (contract or EOA) addreses "from": from, - "to": txData.GetTo(), - "type": hexutil.Uint(ethMsg.AsTransaction().Type()), + "to": txData.To(), + "type": hexutil.Uint(txData.Type()), } // If the to is empty, assume it is a contract creation - if txData.GetTo() == nil { - receipt["contractAddress"] = crypto.CreateAddress(from, txData.GetNonce()) + if txData.To() == nil { + receipt["contractAddress"] = crypto.CreateAddress(from, txData.Nonce()) } - - if dynamicTx, ok := txData.(*evmtypes.DynamicFeeTx); ok { - receipt["effectiveGasPrice"] = hexutil.Big(*dynamicTx.EffectiveGasPrice(baseFee)) + if txData.Type() == ethtypes.DynamicFeeTxType { + receipt["effectiveGasPrice"] = hexutil.Big(*ethMsg.GetEffectiveGasPrice(baseFee)) } - receipts = append(receipts, receipt) - txIndex++ } cumulativeGasUsed += msgCumulativeGasUsed diff --git a/x/cronos/types/interfaces.go b/x/cronos/types/interfaces.go index 636266bf31..31334abde7 100644 --- a/x/cronos/types/interfaces.go +++ b/x/cronos/types/interfaces.go @@ -62,7 +62,7 @@ type EvmLogHandler interface { // EvmKeeper defines the interface for evm keeper type EvmKeeper interface { GetNonce(ctx sdk.Context, addr common.Address) uint64 - ApplyMessage(ctx sdk.Context, msg core.Message, tracer vm.EVMLogger, commit bool) (*evmtypes.MsgEthereumTxResponse, error) + ApplyMessage(ctx sdk.Context, msg *core.Message, tracer vm.EVMLogger, commit bool) (*evmtypes.MsgEthereumTxResponse, error) GetParams(ctx sdk.Context) evmtypes.Params // to replay the messages From cc44b30b4cdf5814c23b17abdc726697700663f7 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 3 May 2024 11:39:25 +0800 Subject: [PATCH 3/4] Problem: no validate for malformed e2ee key in register (#1421) * Problem: no validate for malformed e2ee key in register * update doc * Apply suggestions from code review * cleanup --------- Co-authored-by: yihuang --- CHANGELOG.md | 1 + integration_tests/configs/default.jsonnet | 2 +- integration_tests/cosmoscli.py | 4 ++-- integration_tests/test_e2ee.py | 7 +++++++ x/e2ee/keeper/keeper.go | 23 +++++++++++++++-------- x/e2ee/types/keys.go | 7 +------ x/e2ee/types/msg.go | 14 +++++++------- 7 files changed, 34 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae78f413a8..c64cadaea6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * (versiondb) [#1387](https://github.com/crypto-org-chain/cronos/pull/1387) Add dedicated config section for versiondb, prepare for sdk 0.50 integration. * (e2ee)[#1413](https://github.com/crypto-org-chain/cronos/pull/1413) Add custom keyring implementation for e2ee module. * (e2ee)[#1415](https://github.com/crypto-org-chain/cronos/pull/1415) Add batch keys query for e2ee module. +* (e2ee)[#1421](https://github.com/crypto-org-chain/cronos/pull/1421) Validate e2ee key when register. ### Bug Fixes diff --git a/integration_tests/configs/default.jsonnet b/integration_tests/configs/default.jsonnet index 04dc9271bc..33353020b5 100644 --- a/integration_tests/configs/default.jsonnet +++ b/integration_tests/configs/default.jsonnet @@ -90,7 +90,7 @@ e2ee: { keys: [{ address: 'crc16z0herz998946wr659lr84c8c556da55dc34hh', - key: std.base64('key'), + key: 'age1k3mpspxytgvx6e0jja0xgrtzz7vw2p00c2a3xmq5ygfzhwh4wg0s35z4c8', }], }, gov: { diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index eba113be43..e6b80e17f4 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -1852,7 +1852,7 @@ def query_e2ee_key(self, address): home=self.data_dir, output="json", ) - )["key"] + ).get("key") def query_e2ee_keys(self, *addresses): return json.loads( @@ -1864,7 +1864,7 @@ def query_e2ee_keys(self, *addresses): home=self.data_dir, output="json", ) - )["keys"] + ).get("keys") def register_e2ee_key(self, key, **kwargs): kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE) diff --git a/integration_tests/test_e2ee.py b/integration_tests/test_e2ee.py index 2c1738c7b4..c1d8a1ace8 100644 --- a/integration_tests/test_e2ee.py +++ b/integration_tests/test_e2ee.py @@ -1,3 +1,10 @@ +def test_register(cronos): + cli = cronos.cosmos_cli() + pubkey0 = cli.keygen(keyring_name="key0") + cli.register_e2ee_key(pubkey0 + "malformed", _from="validator") + assert not cli.query_e2ee_key(cli.address("validator")) + + def test_encrypt_decrypt(cronos): cli = cronos.cosmos_cli() diff --git a/x/e2ee/keeper/keeper.go b/x/e2ee/keeper/keeper.go index 6c04f96390..37c5655fb9 100644 --- a/x/e2ee/keeper/keeper.go +++ b/x/e2ee/keeper/keeper.go @@ -28,16 +28,26 @@ func NewKeeper(storeKey storetypes.StoreKey, addressCodec address.Codec) Keeper } } +func (k Keeper) registerEncryptionKey( + ctx context.Context, + address string, + key []byte, +) error { + bz, err := k.addressCodec.StringToBytes(address) + if err != nil { + return err + } + sdk.UnwrapSDKContext(ctx).KVStore(k.storeKey).Set(types.KeyPrefix(bz), key) + return nil +} + func (k Keeper) RegisterEncryptionKey( ctx context.Context, req *types.MsgRegisterEncryptionKey, ) (*types.MsgRegisterEncryptionKeyResponse, error) { - bz, err := k.addressCodec.StringToBytes(req.Address) - if err != nil { + if err := k.registerEncryptionKey(ctx, req.Address, []byte(req.Key)); err != nil { return nil, err } - sdkCtx := sdk.UnwrapSDKContext(ctx) - sdkCtx.KVStore(k.storeKey).Set(types.KeyPrefix(bz), []byte(req.Key)) return &types.MsgRegisterEncryptionKeyResponse{}, nil } @@ -46,10 +56,7 @@ func (k Keeper) InitGenesis( state *types.GenesisState, ) error { for _, key := range state.Keys { - if _, err := k.RegisterEncryptionKey(ctx, &types.MsgRegisterEncryptionKey{ - Address: key.Address, - Key: key.Key, - }); err != nil { + if err := k.registerEncryptionKey(ctx, key.Address, []byte(key.Key)); err != nil { return err } } diff --git a/x/e2ee/types/keys.go b/x/e2ee/types/keys.go index 5941cbf264..0dacda824f 100644 --- a/x/e2ee/types/keys.go +++ b/x/e2ee/types/keys.go @@ -1,8 +1,6 @@ package types import ( - "errors" - sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -39,8 +37,5 @@ func (e EncryptionKeyEntry) Validate() error { if _, err := sdk.AccAddressFromBech32(e.Address); err != nil { return err } - if len(e.Key) == 0 { - return errors.New("key can't be nil") - } - return nil + return ValidateRecipientKey(e.Key) } diff --git a/x/e2ee/types/msg.go b/x/e2ee/types/msg.go index a18c0b0b4b..316efbdec8 100644 --- a/x/e2ee/types/msg.go +++ b/x/e2ee/types/msg.go @@ -3,19 +3,19 @@ package types import ( fmt "fmt" + "filippo.io/age" sdk "github.com/cosmos/cosmos-sdk/types" ) func (m *MsgRegisterEncryptionKey) ValidateBasic() error { - if m.Address == "" { - return fmt.Errorf("address cannot be empty") - } - if len(m.Key) == 0 { - return fmt.Errorf("key cannot be nil") - } // validate bech32 format of Address if _, err := sdk.AccAddressFromBech32(m.Address); err != nil { return fmt.Errorf("invalid address: %s", err) } - return nil + return ValidateRecipientKey(m.Key) +} + +func ValidateRecipientKey(key string) error { + _, err := age.ParseX25519Recipient(key) + return err } From 9aa7258d5fd10a08731101e86cbf18cceeec2c99 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 3 May 2024 14:28:37 +0800 Subject: [PATCH 4/4] Problem: release workflow don't build x86 mac (#1423) Because macos-latest becomes M1 mac now. Solution: - update runner --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8c04205fee..017b829b74 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,7 +50,7 @@ jobs: needs: ["release"] strategy: matrix: - runner: [macos-latest, macos-14] + runner: [macos-13, macos-14] runs-on: ${{ matrix.runner }} environment: release steps: