├── .clang-format ├── .codecov.yml ├── .envrc.example ├── .flake8 ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── build.yml │ ├── codeql-analysis.yml │ ├── container.yml │ ├── gosec.yml │ ├── linkchecker.yml │ ├── lint.yml │ ├── proto.yml │ ├── release.yml │ ├── semgrep.yml │ ├── sims.yml │ └── test.yml ├── .gitignore ├── .gitmodules ├── .golangci.yml ├── .mergify.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── README.md ├── SECURITY.md ├── app ├── app.go ├── bench_test.go ├── block_address.go ├── export.go ├── forks.go ├── legacy.go ├── legacy │ └── icaauth │ │ └── types │ │ ├── codec.go │ │ └── tx.pb.go ├── legacy_test.go ├── prefix.go ├── proposal.go ├── proposal_test.go ├── sim_test.go ├── state.go ├── storeloader.go ├── test_helpers.go ├── upgrades.go ├── upgrades_test.go ├── versiondb.go └── versiondb_placeholder.go ├── assets └── cronos.svg ├── buf.work.yaml ├── client └── docs │ ├── config.json │ ├── embed.go │ └── swagger-ui │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── index.html │ ├── oauth2-redirect.html │ ├── swagger-ui-bundle.js │ ├── swagger-ui-bundle.js.map │ ├── swagger-ui-es-bundle-core.js │ ├── swagger-ui-es-bundle-core.js.map │ ├── swagger-ui-es-bundle.js │ ├── swagger-ui-es-bundle.js.map │ ├── swagger-ui-standalone-preset.js │ ├── swagger-ui-standalone-preset.js.map │ ├── swagger-ui.css │ ├── swagger-ui.css.map │ ├── swagger-ui.js │ ├── swagger-ui.js.map │ └── swagger.yaml ├── cmd └── cronosd │ ├── cmd │ ├── config.go │ ├── root.go │ ├── versiondb.go │ └── versiondb_placeholder.go │ ├── config │ ├── config.go │ ├── prefix_mainnet.go │ └── prefix_testnet.go │ ├── main.go │ └── opendb │ ├── opendb.go │ └── opendb_rocksdb.go ├── contracts ├── .gitattributes ├── .gitignore ├── LICENSE ├── Makefile ├── shell.nix └── src │ ├── ModuleCRC20.sol │ ├── ModuleCRC20.t.sol │ ├── ModuleCRC20Proxy.sol │ ├── ModuleCRC20ProxyAuthority.sol │ └── ModuleCRC21.sol ├── default.nix ├── docs ├── api │ └── json-rpc │ │ ├── endpoints.md │ │ ├── events.md │ │ ├── namespaces.md │ │ └── server.md ├── architecture │ ├── README.md │ ├── adr-001.md │ ├── adr-002.md │ ├── adr-003.md │ ├── adr-004.md │ ├── adr-005.md │ ├── adr-006.md │ ├── adr-007.md │ ├── adr-008.md │ ├── adr-009.md │ └── adr-template.md ├── audit │ └── report_ethermint_1.2_final_public.pdf ├── docs.go ├── gravity-bridge │ ├── dev-setup-guide.md │ ├── gorc-build.md │ ├── gorc-keystores.md │ ├── gravity-bridge-relayer-modes.md │ ├── pioneer11-orchestrator-relayer-deployment-guide.md │ ├── pioneer11-relayer-only-deployment-guide.md │ └── systemd │ │ ├── gorc.service.template │ │ └── setup-gorc-service.sh ├── integration-test.md ├── protodoc-markdown.tmpl └── static │ └── openapi.yml ├── flake.lock ├── flake.nix ├── go.mod ├── go.sum ├── gomod2nix.toml ├── integration_tests ├── .flake8 ├── .isort.cfg ├── README.md ├── __init__.py ├── configs │ ├── broadcast.jsonnet │ ├── broken-cronosd.nix │ ├── broken-cronosd.patch │ ├── cosmovisor.jsonnet │ ├── cosmovisor_gravity.jsonnet │ ├── default.jsonnet │ ├── disable_auto_deployment.jsonnet │ ├── enable-indexer.jsonnet │ ├── genesis_token_mapping.jsonnet │ ├── ibc.jsonnet │ ├── ibc_rly.jsonnet │ ├── ibc_rly_evm.jsonnet │ ├── ibc_timeout.jsonnet │ ├── long_timeout_commit.jsonnet │ ├── low_block_gas_limit.jsonnet │ ├── min_gas_price.jsonnet │ ├── min_gas_price_eq.jsonnet │ ├── min_gas_price_lte.jsonnet │ ├── pruned-node.jsonnet │ ├── replay-tx-0x06d2fa464546e99d2147e1fc997ddb624cec9c8c5e25a050cc381ee8a384eed3.tx │ ├── rollback.jsonnet │ └── upgrade-test-package.nix ├── conftest.py ├── contracts │ ├── .gitignore │ ├── contracts │ │ ├── CosmosToken.sol │ │ ├── CroBridge.sol │ │ ├── CronosGravityCancellation.sol │ │ ├── Gravity.sol │ │ ├── Greeter.sol │ │ ├── ICosmosToken.sol │ │ ├── Random.sol │ │ ├── TestBank.sol │ │ ├── TestBlackListERC20.sol │ │ ├── TestCRC20.sol │ │ ├── TestCRC20Proxy.sol │ │ ├── TestERC20A.sol │ │ ├── TestERC20Utility.sol │ │ ├── TestERC21Source.sol │ │ ├── TestICA.sol │ │ ├── TestMaliciousSupply.sol │ │ ├── TestMessageCall.sol │ │ ├── TestRelayer.sol │ │ ├── TestRevert.sol │ │ ├── TestSuicide.sol │ │ └── src │ ├── hardhat.config.ts │ ├── package-lock.json │ └── package.json ├── cosmoscli.py ├── eip712_utils.py ├── gorc.py ├── gravity_utils.py ├── ibc_utils.py ├── msg_send_types.json ├── network.py ├── poetry.lock ├── protobuf │ ├── cosmos │ │ ├── bank │ │ │ └── v1beta1 │ │ │ │ ├── bank_pb2.py │ │ │ │ └── tx_pb2.py │ │ ├── base │ │ │ └── v1beta1 │ │ │ │ └── coin_pb2.py │ │ ├── crypto │ │ │ ├── multisig │ │ │ │ └── v1beta1 │ │ │ │ │ └── multisig_pb2.py │ │ │ └── secp256k1 │ │ │ │ └── keys_pb2.py │ │ └── tx │ │ │ ├── signing │ │ │ └── v1beta1 │ │ │ │ └── signing_pb2.py │ │ │ └── v1beta1 │ │ │ └── tx_pb2.py │ ├── cosmos_proto │ │ └── cosmos_pb2.py │ ├── ethermint │ │ ├── crypto │ │ │ └── v1 │ │ │ │ └── ethsecp256k1 │ │ │ │ └── keys_pb2.py │ │ ├── evm │ │ │ └── v1 │ │ │ │ └── query_pb2.py │ │ └── types │ │ │ └── v1 │ │ │ └── web3_pb2.py │ └── gogoproto │ │ └── gogo_pb2.py ├── pyproject.toml ├── pytest.ini ├── shell.nix ├── test_bank_precompiles.py ├── test_basic.py ├── test_broadcast.py ├── test_e2ee.py ├── test_eip1559.py ├── test_eip712.py ├── test_exported_genesis.py ├── test_filters.py ├── test_gov_update_params.py ├── test_gravity.py ├── test_gravity_2.py ├── test_ibc.py ├── test_ibc_rly.py ├── test_ibc_rly_gas.py ├── test_ibc_timeout.py ├── test_ibc_update_client.py ├── test_ica.py ├── test_ica_incentivized.py ├── test_ica_precompile.py ├── test_mempool.py ├── test_min_gas_price.py ├── test_permissions.py ├── test_pruned_node.py ├── test_replay_block.py ├── test_rollback.py ├── test_streamer.py ├── test_subscribe.py ├── test_upgrade.py ├── test_versiondb.py ├── test_vesting.py └── utils.py ├── memiavl ├── README.md ├── benchmark_test.go ├── changeset.pb.go ├── commit_info.pb.go ├── db.go ├── db_test.go ├── export.go ├── filelock.go ├── go.mod ├── go.sum ├── import.go ├── iterator.go ├── iterator_test.go ├── kv.pb.go ├── layout_little_endian.go ├── layout_native.go ├── mem_node.go ├── mmap.go ├── multitree.go ├── node.go ├── persisted_node.go ├── proof.go ├── proof_test.go ├── snapshot.go ├── snapshot_test.go ├── tree.go ├── tree_test.go ├── types.go ├── wal.go ├── wal.pb.go └── wal_test.go ├── nix ├── build_overlay.nix ├── bundle-win-exe.nix ├── cosmovisor.nix ├── cronos-matrix.nix ├── dapptools-overlay.nix ├── dapptools.patch ├── default.nix ├── gen-binding-shell.nix ├── go-ethereum.nix ├── golangci-lint.nix ├── hermes.nix ├── rename-exe.nix ├── rocksdb.nix ├── scripts.nix ├── sources.json ├── sources.nix ├── testenv.nix ├── testground-cronosd.patch └── testground-image.nix ├── proto ├── buf.gen.gogo.yaml ├── buf.gen.swagger.yaml ├── buf.lock ├── buf.yaml ├── cronos │ ├── cronos.proto │ ├── genesis.proto │ ├── query.proto │ └── tx.proto ├── e2ee │ ├── genesis.proto │ ├── query.proto │ └── tx.proto └── memiavl │ ├── changeset.proto │ ├── commit_info.proto │ ├── kv.proto │ └── wal.proto ├── scripts ├── .env ├── codesign_macos.sh ├── cronos-devnet.yaml ├── gen-bindings-contracts ├── gen-cronos-contracts ├── geth-genesis.json ├── protoc-swagger-gen.sh ├── protocgen.sh ├── release.sh ├── run-integration-tests ├── start-cronos ├── start-geth └── test-cronos-contracts ├── store ├── cachemulti │ └── store.go ├── config │ ├── config.go │ └── toml.go ├── go.mod ├── go.sum ├── memiavlstore │ └── store.go ├── rootmulti │ ├── import.go │ ├── objstore.go │ ├── objstore_placeholder.go │ ├── snapshot.go │ ├── store.go │ └── store_test.go └── setup.go ├── testground ├── README.md └── benchmark │ ├── .flake8 │ ├── benchmark │ ├── __init__.py │ ├── cli.py │ ├── cosmostx.py │ ├── echo.py │ ├── erc20.py │ ├── peer.py │ ├── stateless.py │ ├── stats.py │ ├── test_utils.py │ ├── testnet.py │ ├── topology.py │ ├── transaction.py │ ├── types.py │ └── utils.py │ ├── compositions │ └── docker-compose.jsonnet │ ├── flake.lock │ ├── flake.nix │ ├── overlay.nix │ ├── poetry.lock │ └── pyproject.toml ├── testutil └── simapp │ └── simapp.go ├── third_party └── proto │ ├── buf.lock │ ├── buf.yaml │ ├── ethermint │ ├── crypto │ │ └── v1 │ │ │ └── ethsecp256k1 │ │ │ └── keys.proto │ ├── evm │ │ └── v1 │ │ │ ├── access_tuple.proto │ │ │ ├── chain_config.proto │ │ │ ├── chain_config_v0.proto │ │ │ ├── events.proto │ │ │ ├── genesis.proto │ │ │ ├── log.proto │ │ │ ├── params.proto │ │ │ ├── params_v0.proto │ │ │ ├── params_v4.proto │ │ │ ├── query.proto │ │ │ ├── state.proto │ │ │ ├── trace_config.proto │ │ │ ├── trace_config_v0.proto │ │ │ ├── transaction_logs.proto │ │ │ ├── tx.proto │ │ │ └── tx_result.proto │ ├── feemarket │ │ └── v1 │ │ │ ├── events.proto │ │ │ ├── feemarket.proto │ │ │ ├── genesis.proto │ │ │ ├── query.proto │ │ │ └── tx.proto │ └── types │ │ └── v1 │ │ ├── account.proto │ │ ├── dynamic_fee.proto │ │ ├── indexer.proto │ │ └── web3.proto │ └── ibc │ ├── applications │ ├── fee │ │ └── v1 │ │ │ ├── ack.proto │ │ │ ├── fee.proto │ │ │ ├── genesis.proto │ │ │ ├── metadata.proto │ │ │ ├── query.proto │ │ │ └── tx.proto │ ├── interchain_accounts │ │ ├── controller │ │ │ └── v1 │ │ │ │ ├── controller.proto │ │ │ │ ├── query.proto │ │ │ │ └── tx.proto │ │ ├── genesis │ │ │ └── v1 │ │ │ │ └── genesis.proto │ │ ├── host │ │ │ └── v1 │ │ │ │ ├── host.proto │ │ │ │ ├── query.proto │ │ │ │ └── tx.proto │ │ └── v1 │ │ │ ├── account.proto │ │ │ ├── metadata.proto │ │ │ └── packet.proto │ └── transfer │ │ ├── v1 │ │ ├── authz.proto │ │ ├── genesis.proto │ │ ├── query.proto │ │ ├── transfer.proto │ │ └── tx.proto │ │ └── v2 │ │ └── packet.proto │ ├── core │ ├── channel │ │ └── v1 │ │ │ ├── channel.proto │ │ │ ├── genesis.proto │ │ │ ├── query.proto │ │ │ ├── tx.proto │ │ │ └── upgrade.proto │ ├── client │ │ └── v1 │ │ │ ├── client.proto │ │ │ ├── genesis.proto │ │ │ ├── query.proto │ │ │ └── tx.proto │ ├── commitment │ │ └── v1 │ │ │ └── commitment.proto │ ├── connection │ │ └── v1 │ │ │ ├── connection.proto │ │ │ ├── genesis.proto │ │ │ ├── query.proto │ │ │ └── tx.proto │ └── types │ │ └── v1 │ │ └── genesis.proto │ └── lightclients │ ├── localhost │ └── v2 │ │ └── localhost.proto │ ├── solomachine │ ├── v2 │ │ └── solomachine.proto │ └── v3 │ │ └── solomachine.proto │ ├── tendermint │ └── v1 │ │ └── tendermint.proto │ └── wasm │ └── v1 │ ├── genesis.proto │ ├── query.proto │ ├── tx.proto │ └── wasm.proto ├── versiondb ├── README.md ├── backend_test_utils.go ├── client │ ├── changeset.go │ ├── changeset_test.go │ ├── cmd.go │ ├── convert_to_sst.go │ ├── convert_to_sst_test.go │ ├── dump.go │ ├── fixdata.go │ ├── flags.go │ ├── ingest_sst.go │ ├── print.go │ ├── restore.go │ ├── restore_app_db.go │ ├── stores.go │ ├── to_versiondb.go │ ├── verify.go │ └── wrapreader.go ├── extsort │ ├── delta_encoding.go │ ├── delta_encoding_test.go │ ├── merge.go │ ├── sort.go │ ├── sort_test.go │ └── types.go ├── go.mod ├── go.sum ├── multistore.go ├── objstore.go ├── store.go ├── streaming_service.go ├── tsrocksdb │ ├── comparator.go │ ├── iterator.go │ ├── opts.go │ ├── store.go │ └── store_test.go └── types.go └── x ├── cronos ├── client │ ├── cli │ │ ├── query.go │ │ └── tx.go │ └── proposal_handler.go ├── events │ ├── README.md │ ├── bindings │ │ ├── cosmos │ │ │ ├── lib │ │ │ │ └── cosmos_types.abigen.go │ │ │ └── precompile │ │ │ │ ├── bank │ │ │ │ └── i_bank_module.abigen.go │ │ │ │ ├── ica │ │ │ │ └── i_ica_module.abigen.go │ │ │ │ ├── icacallback │ │ │ │ └── i_ica_callback.abigen.go │ │ │ │ └── relayer │ │ │ │ ├── i_relayer_functions.abigen.go │ │ │ │ └── i_relayer_module.abigen.go │ │ └── src │ │ │ ├── Bank.sol │ │ │ ├── CosmosTypes.sol │ │ │ ├── ICA.sol │ │ │ ├── ICACallback.sol │ │ │ ├── Relayer.sol │ │ │ └── RelayerFunctions.sol │ ├── decoders.go │ ├── event.go │ ├── events.go │ └── types │ │ └── types.go ├── exported │ └── exported.go ├── genesis.go ├── genesis_test.go ├── handler_test.go ├── keeper │ ├── evm.go │ ├── evm_hooks.go │ ├── evm_hooks_test.go │ ├── evm_test.go │ ├── evmhandlers │ │ ├── send_cro_to_ibc.go │ │ ├── send_to_account.go │ │ ├── send_to_ibc.go │ │ └── send_to_ibc_v2.go │ ├── evmhandlers_test.go │ ├── grpc_query.go │ ├── ibc.go │ ├── ibc_test.go │ ├── keeper.go │ ├── keeper_test.go │ ├── migrations.go │ ├── mock │ │ └── ibckeeper_mock.go │ ├── msg_server.go │ ├── msg_server_test.go │ ├── params.go │ ├── params_test.go │ ├── permissions.go │ ├── permissions_test.go │ └── precompiles │ │ ├── bank.go │ │ ├── base_contract.go │ │ ├── ica.go │ │ ├── interface.go │ │ ├── relayer.go │ │ └── utils.go ├── middleware │ └── conversion_middleware.go ├── migrations │ └── v2 │ │ ├── migrate.go │ │ └── migrate_test.go ├── module.go ├── proposal_handler.go ├── rpc │ └── api.go ├── simulation │ ├── decoder.go │ ├── decoder_test.go │ ├── genesis.go │ ├── genesis_test.go │ └── operations.go ├── spec │ ├── 01_concepts.md │ ├── 02_state.md │ ├── 03_state_transitions.md │ ├── 04_messages.md │ ├── 05_abci.md │ ├── 06_events.md │ ├── 07_params.md │ └── README.md └── types │ ├── codec.go │ ├── contracts.go │ ├── contracts │ ├── ModuleCRC20.json │ ├── ModuleCRC20Proxy.json │ ├── ModuleCRC20ProxyAuthority.json │ └── ModuleCRC21.json │ ├── cronos.pb.go │ ├── errors.go │ ├── events.go │ ├── genesis.go │ ├── genesis.pb.go │ ├── genesis_test.go │ ├── interfaces.go │ ├── keys.go │ ├── messages.go │ ├── messages_test.go │ ├── params.go │ ├── params_test.go │ ├── proposal.go │ ├── query.go │ ├── query.pb.go │ ├── query.pb.gw.go │ ├── tracer.go │ ├── tx.pb.go │ ├── types.go │ └── types_test.go └── e2ee ├── README.md ├── autocli.go ├── client └── cli │ ├── cmd.go │ ├── decrypt.go │ ├── encrypt.go │ ├── encrypt_to_validators.go │ ├── generate.go │ ├── pubkey.go │ ├── query.go │ └── tx.go ├── keeper └── keeper.go ├── keyring ├── keyring.go └── keyring_test.go ├── module.go └── types ├── codec.go ├── genesis.go ├── genesis.pb.go ├── keys.go ├── msg.go ├── query.pb.go ├── query.pb.gw.go └── tx.pb.go /.codecov.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This codecov.yml is the default configuration for 3 | # all repositories on Codecov. You may adjust the settings 4 | # below in your own codecov.yml in your repository. 5 | # 6 | coverage: 7 | precision: 2 8 | round: down 9 | range: 70...100 10 | 11 | status: 12 | # Learn more at https://docs.codecov.io/docs/commit-status 13 | project: 14 | default: 15 | threshold: 1% # allow this much decrease on project 16 | app: 17 | target: 70% 18 | flags: 19 | - app 20 | modules: 21 | target: 70% 22 | flags: 23 | - modules 24 | clients: 25 | flags: 26 | - clients 27 | changes: false 28 | 29 | comment: 30 | layout: "reach, diff, files" 31 | behavior: default # update if exists else create new 32 | require_changes: true 33 | 34 | flags: 35 | app: 36 | paths: 37 | - "app/" 38 | modules: 39 | paths: 40 | - "x/" 41 | - "!x/**/client/" # ignore client package 42 | clients: 43 | paths: 44 | - "client/" 45 | - "x/**/client/" 46 | 47 | ignore: 48 | - "docs" 49 | - "*.md" 50 | - "cmd" 51 | - "**/*.pb.go" 52 | - "**/*.pb.gw.go" 53 | - "x/**/*.pb.gw.go" 54 | - "scripts/" 55 | - "app/app.go" 56 | - "app/prefix.go" 57 | - "app/test_helpers.go" 58 | -------------------------------------------------------------------------------- /.envrc.example: -------------------------------------------------------------------------------- 1 | # default: go, gomod2nix 2 | # rocksdb: go, gomod2nix, librocksdb 3 | # full: go, gomod2nix, librocksdb, python env 4 | use flake .#full 5 | TMPDIR=/tmp 6 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 88 3 | extend-ignore = E203 4 | exclude = .git,__pycache__,./integration_tests/contracts,./integration_tests/**/*_pb2.py 5 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @crypto-org-chain/cronos-dev 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/gosec.yml: -------------------------------------------------------------------------------- 1 | name: Run Gosec 2 | on: 3 | pull_request: 4 | push: 5 | branches: 6 | - main 7 | - release/** 8 | 9 | jobs: 10 | Gosec: 11 | runs-on: ubuntu-latest 12 | permissions: 13 | actions: read 14 | contents: read 15 | security-events: write 16 | env: 17 | GO111MODULE: on 18 | steps: 19 | - uses: actions/checkout@v3 20 | - uses: technote-space/get-diff-action@f27caffdd0fb9b13f4fc191c016bb4e0632844af # v3 21 | with: 22 | SUFFIX_FILTER: | 23 | .go 24 | .mod 25 | .sum 26 | - name: Run Gosec Security Scanner 27 | uses: informalsystems/gosec@f3d05e8e90198e1d4823cf4e8cb36ad490df8677 # v0.10.4 28 | with: 29 | # we let the report trigger content trigger a failure using the GitHub Security features. 30 | args: '-no-fail -fmt sarif -out results.sarif ./...' 31 | if: "env.GIT_DIFF_FILTERED != ''" 32 | - name: Upload SARIF file 33 | uses: github/codeql-action/upload-sarif@v2 34 | with: 35 | # Path to SARIF file relative to the root of the repository 36 | sarif_file: results.sarif 37 | if: "env.GIT_DIFF_FILTERED != ''" 38 | -------------------------------------------------------------------------------- /.github/workflows/linkchecker.yml: -------------------------------------------------------------------------------- 1 | name: Check Markdown links 2 | on: 3 | schedule: 4 | - cron: "* */24 * * *" 5 | pull_request: 6 | push: 7 | branches: 8 | - main 9 | - release/** 10 | jobs: 11 | markdown-link-check: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | with: 16 | fetch-depth: 0 17 | - id: changed-files 18 | uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5 19 | with: 20 | files: | 21 | docs/**/*.md 22 | - uses: gaurav-nelson/github-action-markdown-link-check@4d5a901466436052915a68d4a856171a50b2c762 # 1.0.13 23 | if: steps.changed-files.outputs.any_changed == 'true' 24 | with: 25 | folder-path: "docs" 26 | -------------------------------------------------------------------------------- /.github/workflows/semgrep.yml: -------------------------------------------------------------------------------- 1 | name: Semgrep 2 | on: 3 | # Scan changed files in PRs, block on new issues only (existing issues ignored) 4 | pull_request: {} 5 | push: 6 | branches: 7 | - main 8 | - release/** 9 | paths: 10 | - .github/workflows/semgrep.yml 11 | schedule: 12 | - cron: '0 0 * * 0' 13 | jobs: 14 | # Update from: https://semgrep.dev/docs/semgrep-ci/sample-ci-configs/#github-actions 15 | semgrep: 16 | name: Scan 17 | runs-on: ubuntu-latest 18 | container: 19 | image: returntocorp/semgrep 20 | if: (github.actor != 'dependabot[bot]') 21 | steps: 22 | # Fetch project source with GitHub Actions Checkout. 23 | - uses: actions/checkout@v3 24 | with: 25 | submodules: true 26 | # Run the "semgrep ci" command on the command line of the docker image. 27 | - run: semgrep ci 28 | env: 29 | # Add the rules that Semgrep uses by setting the SEMGREP_RULES environment variable. 30 | SEMGREP_RULES: p/golang # more at semgrep.dev/explore 31 | SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} 32 | # Uncomment SEMGREP_TIMEOUT to set this job's timeout (in seconds): 33 | # Default timeout is 1800 seconds (30 minutes). 34 | # Set to 0 to disable the timeout. 35 | # SEMGREP_TIMEOUT: 300 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | release/ 2 | /build 3 | coverage.txt 4 | __pycache__ 5 | /dist 6 | /vendor 7 | go.work 8 | go.work.sum 9 | 10 | # nix 11 | result 12 | 13 | # pystarport 14 | /data 15 | 16 | # Jetbrains 17 | .idea 18 | 19 | # vscode 20 | .vscode 21 | 22 | # yaml for test 23 | integration_tests/configs/*.yaml 24 | 25 | # direnv 26 | .envrc 27 | .direnv 28 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "contracts/lib/ds-test"] 2 | path = contracts/lib/ds-test 3 | url = https://github.com/dapphub/ds-test 4 | [submodule "contracts/lib/ds-token"] 5 | path = contracts/lib/ds-token 6 | url = https://github.com/dapphub/ds-token 7 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | run: 2 | tests: true 3 | timeout: 10m 4 | sort-results: true 5 | allow-parallel-runners: true 6 | exclude-dir: testutil/testdata_pulsar 7 | concurrency: 4 8 | 9 | linters: 10 | disable-all: true 11 | enable: 12 | - dogsled 13 | - exportloopref 14 | - goconst 15 | - gocritic 16 | - gofumpt 17 | - gosec 18 | - gosimple 19 | - govet 20 | - ineffassign 21 | - misspell 22 | - nakedret 23 | - nolintlint 24 | - staticcheck 25 | - stylecheck 26 | - typecheck 27 | - unconvert 28 | - unused 29 | 30 | issues: 31 | exclude-rules: 32 | - text: "Use of weak random number generator" 33 | linters: 34 | - gosec 35 | - text: "ST1003:" 36 | linters: 37 | - stylecheck 38 | # FIXME: Disabled until golangci-lint updates stylecheck with this fix: 39 | # https://github.com/dominikh/go-tools/issues/389 40 | - text: "ST1016:" 41 | linters: 42 | - stylecheck 43 | - path: "migrations" 44 | text: "SA1019:" 45 | linters: 46 | - staticcheck 47 | - text: "leading space" 48 | linters: 49 | - nolintlint 50 | 51 | max-issues-per-linter: 10000 52 | max-same-issues: 10000 53 | 54 | linters-settings: 55 | dogsled: 56 | max-blank-identifiers: 3 57 | maligned: 58 | # print struct with more effective memory layout or not, false by default 59 | suggest-new: true 60 | nolintlint: 61 | allow-unused: false 62 | allow-leading-space: true 63 | require-explanation: false 64 | require-specific: false 65 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | queue_rules: 2 | - name: default 3 | conditions: 4 | - "#approved-reviews-by>1" 5 | 6 | pull_request_rules: 7 | - name: automerge to the base branch with label automerge and branch protection passing 8 | conditions: 9 | - "#approved-reviews-by>1" 10 | - base=main 11 | - label=automerge 12 | actions: 13 | queue: 14 | name: default 15 | merge: 16 | method: squash 17 | - name: backport patches to v0.6.x branch 18 | conditions: 19 | - base=main 20 | - label=backport/0.6.x 21 | actions: 22 | backport: 23 | branches: 24 | - release/v0.6.x -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright 2021-present Cronos Labs 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. -------------------------------------------------------------------------------- /app/forks.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import sdk "github.com/cosmos/cosmos-sdk/types" 4 | 5 | // Fork defines a struct containing the requisite fields for a non-software upgrade proposal 6 | // Hard Fork at a given height to implement. 7 | // There is one time code that can be added for the start of the Fork, in `BeginForkLogic`. 8 | // Any other change in the code should be height-gated, if the goal is to have old and new binaries 9 | // to be compatible prior to the upgrade height. 10 | // 11 | // Adapted from osmosis: https://github.com/osmosis-labs/osmosis/blob/057192c2c0949fde5673a5f314bf41816f808fd9/app/upgrades/types.go#L40 12 | type Fork struct { 13 | // Upgrade version name, for the upgrade handler, e.g. `v7` 14 | UpgradeName string 15 | // height the upgrade occurs at 16 | UpgradeHeight int64 17 | // chain-id the upgrade occurs at 18 | UpgradeChainId string 19 | 20 | // Function that runs some custom state transition code at the beginning of a fork. 21 | BeginForkLogic func(ctx sdk.Context, app *App) 22 | } 23 | 24 | // BeginBlockForks is intended to be ran in a chain upgrade. 25 | func BeginBlockForks(ctx sdk.Context, app *App) { 26 | for _, fork := range Forks { 27 | if ctx.BlockHeight() == fork.UpgradeHeight && ctx.ChainID() == fork.UpgradeChainId { 28 | fork.BeginForkLogic(ctx, app) 29 | return 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/legacy.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "github.com/cosmos/cosmos-sdk/codec" 5 | cdctypes "github.com/cosmos/cosmos-sdk/codec/types" 6 | "github.com/cosmos/cosmos-sdk/x/authz" 7 | icaauthtypes "github.com/crypto-org-chain/cronos/v2/app/legacy/icaauth/types" 8 | ) 9 | 10 | func RegisterLegacyCodec(cdc *codec.LegacyAmino) { 11 | icaauthtypes.RegisterCodec(cdc) 12 | authz.RegisterLegacyAminoCodec(cdc) 13 | } 14 | 15 | func RegisterLegacyInterfaces(registry cdctypes.InterfaceRegistry) { 16 | icaauthtypes.RegisterInterfaces(registry) 17 | authz.RegisterInterfaces(registry) 18 | } 19 | -------------------------------------------------------------------------------- /app/legacy/icaauth/types/codec.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/cosmos/cosmos-sdk/codec" 5 | cdctypes "github.com/cosmos/cosmos-sdk/codec/types" 6 | sdk "github.com/cosmos/cosmos-sdk/types" 7 | "github.com/cosmos/cosmos-sdk/types/msgservice" 8 | ) 9 | 10 | func RegisterCodec(cdc *codec.LegacyAmino) { 11 | cdc.RegisterConcrete(&MsgRegisterAccount{}, "icaauth/RegisterAccount", nil) 12 | cdc.RegisterConcrete(&MsgSubmitTx{}, "icaauth/SubmitTx", nil) 13 | } 14 | 15 | func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { 16 | registry.RegisterImplementations((*sdk.Msg)(nil), 17 | &MsgRegisterAccount{}, 18 | ) 19 | registry.RegisterImplementations((*sdk.Msg)(nil), 20 | &MsgSubmitTx{}, 21 | ) 22 | msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) 23 | } 24 | -------------------------------------------------------------------------------- /app/prefix.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | cmdcfg "github.com/crypto-org-chain/cronos/v2/cmd/cronosd/config" 6 | ethcfg "github.com/evmos/ethermint/cmd/config" 7 | ) 8 | 9 | func SetConfig() { 10 | config := sdk.GetConfig() 11 | cmdcfg.SetBech32Prefixes(config) 12 | ethcfg.SetBip44CoinType(config) 13 | // Make sure address is compatible with ethereum 14 | config.SetAddressVerifier(VerifyAddressFormat) 15 | config.Seal() 16 | } 17 | -------------------------------------------------------------------------------- /app/state.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" 7 | simtypes "github.com/cosmos/cosmos-sdk/types/simulation" 8 | stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" 9 | 10 | evmtypes "github.com/evmos/ethermint/x/evm/types" 11 | ) 12 | 13 | func StateFn(app *App) simtypes.AppStateFn { 14 | var bondDenom string 15 | return simtestutil.AppStateFnWithExtendedCbs( 16 | app.AppCodec(), 17 | app.SimulationManager(), 18 | app.DefaultGenesis(), 19 | func(moduleName string, genesisState interface{}) { 20 | if moduleName == stakingtypes.ModuleName { 21 | stakingState := genesisState.(*stakingtypes.GenesisState) 22 | bondDenom = stakingState.Params.BondDenom 23 | } 24 | }, 25 | func(rawState map[string]json.RawMessage) { 26 | evmStateBz, ok := rawState[evmtypes.ModuleName] 27 | if !ok { 28 | panic("evm genesis state is missing") 29 | } 30 | 31 | evmState := new(evmtypes.GenesisState) 32 | app.AppCodec().MustUnmarshalJSON(evmStateBz, evmState) 33 | 34 | // we should replace the EvmDenom with BondDenom 35 | evmState.Params.EvmDenom = bondDenom 36 | 37 | // change appState back 38 | rawState[evmtypes.ModuleName] = app.AppCodec().MustMarshalJSON(evmState) 39 | }, 40 | ) 41 | } 42 | -------------------------------------------------------------------------------- /app/storeloader.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | storetypes "cosmossdk.io/store/types" 5 | upgradetypes "cosmossdk.io/x/upgrade/types" 6 | "github.com/cosmos/cosmos-sdk/baseapp" 7 | ) 8 | 9 | // MaxVersionStoreLoader will be used when there's versiondb to cap the loaded iavl version 10 | func MaxVersionStoreLoader(version int64) baseapp.StoreLoader { 11 | if version == 0 { 12 | return baseapp.DefaultStoreLoader 13 | } 14 | 15 | return func(ms storetypes.CommitMultiStore) error { 16 | return ms.LoadVersion(version) 17 | } 18 | } 19 | 20 | // MaxVersionUpgradeStoreLoader is used to prepare baseapp with a fixed StoreLoader 21 | func MaxVersionUpgradeStoreLoader(version int64, upgradeHeight int64, storeUpgrades *storetypes.StoreUpgrades) baseapp.StoreLoader { 22 | if version == 0 { 23 | return upgradetypes.UpgradeStoreLoader(upgradeHeight, storeUpgrades) 24 | } 25 | 26 | return func(ms storetypes.CommitMultiStore) error { 27 | if upgradeHeight == ms.LastCommitID().Version+1 { 28 | // Check if the current commit version and upgrade height matches 29 | if len(storeUpgrades.Renamed) > 0 || len(storeUpgrades.Deleted) > 0 || len(storeUpgrades.Added) > 0 { 30 | return ms.LoadLatestVersionAndUpgrade(storeUpgrades) 31 | } 32 | } 33 | 34 | // Otherwise load default store loader 35 | return MaxVersionStoreLoader(version)(ms) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/versiondb_placeholder.go: -------------------------------------------------------------------------------- 1 | //go:build !rocksdb 2 | // +build !rocksdb 3 | 4 | package app 5 | 6 | import ( 7 | "errors" 8 | 9 | storetypes "cosmossdk.io/store/types" 10 | ) 11 | 12 | func (app *App) setupVersionDB( 13 | homePath string, 14 | keys map[string]*storetypes.KVStoreKey, 15 | tkeys map[string]*storetypes.TransientStoreKey, 16 | memKeys map[string]*storetypes.MemoryStoreKey, 17 | okeys map[string]*storetypes.ObjectStoreKey, 18 | ) (storetypes.RootMultiStore, error) { 19 | return nil, errors.New("versiondb is not supported in this binary") 20 | } 21 | -------------------------------------------------------------------------------- /buf.work.yaml: -------------------------------------------------------------------------------- 1 | version: v1 2 | directories: 3 | - proto 4 | - third_party/proto 5 | -------------------------------------------------------------------------------- /client/docs/embed.go: -------------------------------------------------------------------------------- 1 | package docs 2 | 3 | import "embed" 4 | 5 | //go:embed swagger-ui 6 | var SwaggerUI embed.FS 7 | -------------------------------------------------------------------------------- /client/docs/swagger-ui/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crypto-org-chain/cronos/4815e61174f2917df82316ab53e0d142127d820c/client/docs/swagger-ui/favicon-16x16.png -------------------------------------------------------------------------------- /client/docs/swagger-ui/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crypto-org-chain/cronos/4815e61174f2917df82316ab53e0d142127d820c/client/docs/swagger-ui/favicon-32x32.png -------------------------------------------------------------------------------- /cmd/cronosd/cmd/config.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | type VersionDBConfig struct { 4 | // Enable defines if the versiondb should be enabled. 5 | Enable bool `mapstructure:"enable"` 6 | } 7 | 8 | func DefaultVersionDBConfig() VersionDBConfig { 9 | return VersionDBConfig{ 10 | Enable: false, 11 | } 12 | } 13 | 14 | var DefaultVersionDBTemplate = ` 15 | [versiondb] 16 | # Enable defines if the versiondb should be enabled. 17 | enable = {{ .VersionDB.Enable }} 18 | ` 19 | -------------------------------------------------------------------------------- /cmd/cronosd/cmd/versiondb.go: -------------------------------------------------------------------------------- 1 | //go:build rocksdb 2 | // +build rocksdb 3 | 4 | package cmd 5 | 6 | import ( 7 | "sort" 8 | 9 | "github.com/crypto-org-chain/cronos/v2/app" 10 | "github.com/crypto-org-chain/cronos/v2/cmd/cronosd/opendb" 11 | versiondbclient "github.com/crypto-org-chain/cronos/versiondb/client" 12 | "github.com/linxGnu/grocksdb" 13 | "github.com/spf13/cobra" 14 | ) 15 | 16 | func ChangeSetCmd() *cobra.Command { 17 | keys, _, _, _ := app.StoreKeys() 18 | storeNames := make([]string, 0, len(keys)) 19 | for name := range keys { 20 | storeNames = append(storeNames, name) 21 | } 22 | sort.Strings(storeNames) 23 | 24 | return versiondbclient.ChangeSetGroupCmd(versiondbclient.Options{ 25 | DefaultStores: storeNames, 26 | OpenReadOnlyDB: opendb.OpenReadOnlyDB, 27 | AppRocksDBOptions: func(sstFileWriter bool) *grocksdb.Options { 28 | return opendb.NewRocksdbOptions(nil, sstFileWriter) 29 | }, 30 | }) 31 | } 32 | -------------------------------------------------------------------------------- /cmd/cronosd/cmd/versiondb_placeholder.go: -------------------------------------------------------------------------------- 1 | //go:build !rocksdb 2 | // +build !rocksdb 3 | 4 | package cmd 5 | 6 | import ( 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func ChangeSetCmd() *cobra.Command { 11 | return nil 12 | } 13 | -------------------------------------------------------------------------------- /cmd/cronosd/config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import sdk "github.com/cosmos/cosmos-sdk/types" 4 | 5 | // SetBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings. 6 | func SetBech32Prefixes(config *sdk.Config) { 7 | config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) 8 | config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) 9 | config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) 10 | } 11 | -------------------------------------------------------------------------------- /cmd/cronosd/config/prefix_mainnet.go: -------------------------------------------------------------------------------- 1 | //go:build !testnet 2 | // +build !testnet 3 | 4 | package config 5 | 6 | import sdk "github.com/cosmos/cosmos-sdk/types" 7 | 8 | const ( 9 | // Bech32Prefix defines the Bech32 prefix used for Cronos Accounts 10 | Bech32Prefix = "crc" 11 | 12 | // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address 13 | Bech32PrefixAccAddr = Bech32Prefix 14 | // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key 15 | Bech32PrefixAccPub = Bech32Prefix + sdk.PrefixPublic 16 | // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address 17 | Bech32PrefixValAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator 18 | // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key 19 | Bech32PrefixValPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic 20 | // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address 21 | Bech32PrefixConsAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus 22 | // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key 23 | Bech32PrefixConsPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic 24 | ) 25 | -------------------------------------------------------------------------------- /cmd/cronosd/config/prefix_testnet.go: -------------------------------------------------------------------------------- 1 | //go:build testnet 2 | // +build testnet 3 | 4 | package config 5 | 6 | import sdk "github.com/cosmos/cosmos-sdk/types" 7 | 8 | const ( 9 | // Bech32Prefix defines the Bech32 prefix used for Cronos Accounts 10 | Bech32Prefix = "tcrc" 11 | 12 | // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address 13 | Bech32PrefixAccAddr = Bech32Prefix 14 | // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key 15 | Bech32PrefixAccPub = Bech32Prefix + sdk.PrefixPublic 16 | // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address 17 | Bech32PrefixValAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator 18 | // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key 19 | Bech32PrefixValPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic 20 | // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address 21 | Bech32PrefixConsAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus 22 | // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key 23 | Bech32PrefixConsPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic 24 | ) 25 | -------------------------------------------------------------------------------- /cmd/cronosd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | 6 | svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" 7 | "github.com/crypto-org-chain/cronos/v2/app" 8 | "github.com/crypto-org-chain/cronos/v2/cmd/cronosd/cmd" 9 | ) 10 | 11 | func main() { 12 | rootCmd := cmd.NewRootCmd() 13 | if err := svrcmd.Execute(rootCmd, cmd.EnvPrefix, app.DefaultNodeHome); err != nil { 14 | os.Exit(1) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /cmd/cronosd/opendb/opendb.go: -------------------------------------------------------------------------------- 1 | //go:build !rocksdb 2 | // +build !rocksdb 3 | 4 | package opendb 5 | 6 | import ( 7 | "path/filepath" 8 | 9 | dbm "github.com/cosmos/cosmos-db" 10 | "github.com/cosmos/cosmos-sdk/server/types" 11 | ) 12 | 13 | func OpenDB(_ types.AppOptions, home string, backendType dbm.BackendType) (dbm.DB, error) { 14 | dataDir := filepath.Join(home, "data") 15 | return dbm.NewDB("application", backendType, dataDir) 16 | } 17 | 18 | // OpenReadOnlyDB opens rocksdb backend in read-only mode. 19 | func OpenReadOnlyDB(home string, backendType dbm.BackendType) (dbm.DB, error) { 20 | return OpenDB(nil, home, backendType) 21 | } 22 | -------------------------------------------------------------------------------- /contracts/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /contracts/.gitignore: -------------------------------------------------------------------------------- 1 | /out 2 | -------------------------------------------------------------------------------- /contracts/Makefile: -------------------------------------------------------------------------------- 1 | SOLC_VERSION := $(shell which solc) 2 | all :; dapp --use ${SOLC_VERSION} build 3 | clean :; dapp clean 4 | test :; dapp --use ${SOLC_VERSION} test 5 | deploy :; dapp create CronosERC20 6 | -------------------------------------------------------------------------------- /contracts/shell.nix: -------------------------------------------------------------------------------- 1 | { system ? builtins.currentSystem, pkgs ? import ../nix { inherit system; } }: 2 | pkgs.mkShell { 3 | buildInputs = [ 4 | pkgs.which 5 | pkgs.jq 6 | pkgs.dapp 7 | pkgs.solc-versions.solc_0_6_8 8 | ]; 9 | } 10 | -------------------------------------------------------------------------------- /contracts/src/ModuleCRC20.t.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.8; 2 | 3 | import "ds-test/test.sol"; 4 | 5 | import "./ModuleCRC20.sol"; 6 | 7 | contract ModuleCRC20Test is DSTest { 8 | ModuleCRC20 token; 9 | 10 | function setUp() public { 11 | token = new ModuleCRC20("gravity0x0", 0); 12 | } 13 | 14 | function test_basic_sanity() public { 15 | assertEq(uint(token.decimals()), uint(0)); 16 | assertEq(token.native_denom(), "gravity0x0"); 17 | } 18 | 19 | function testFail_mint_by_cronos_module() public { 20 | token.mint_by_cronos_module(0x208AE63c976d145AB328afdcE251c7051D8E452D, 100); 21 | } 22 | 23 | function testFail_burn_by_cronos_module() public { 24 | token.burn_by_cronos_module(0x208AE63c976d145AB328afdcE251c7051D8E452D, 100); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /contracts/src/ModuleCRC20ProxyAuthority.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.8; 2 | 3 | contract ModuleCRC20ProxyAuthority { 4 | address proxyAddress; 5 | 6 | constructor(address _proxyAddress) public { 7 | proxyAddress = _proxyAddress; 8 | } 9 | 10 | function canCall( 11 | address src, address dst, bytes4 sig 12 | ) public view returns (bool) { 13 | if (src == proxyAddress) { 14 | return true; 15 | } 16 | 17 | return false; 18 | } 19 | } -------------------------------------------------------------------------------- /docs/architecture/adr-template.md: -------------------------------------------------------------------------------- 1 | # ADR {ADR-NUMBER}: {TITLE} 2 | 3 | ## Changelog 4 | * {date}: {changelog} 5 | 6 | ## Context 7 | 8 | > This section contains all the context one needs to understand the current state, and why there is a problem. It should be as succinct as possible and introduce the high level idea behind the solution. 9 | ## Decision 10 | 11 | > This section explains all of the details of the proposed solution, including implementation details. 12 | It should also describe affects / corollary items that may need to be changed as a part of this. 13 | If the proposed change will be large, please also indicate a way to do the change to maximize ease of review. 14 | (e.g. the optimal split of things to do between separate PR's) 15 | 16 | ## Status 17 | 18 | > A decision may be "proposed" if it hasn't been agreed upon yet, or "accepted" once it is agreed upon. If a later ADR changes or reverses a decision, it may be marked as "deprecated" or "superseded" with a reference to its replacement. 19 | 20 | {Deprecated|Proposed|Accepted} 21 | 22 | ## Consequences 23 | 24 | > This section describes the consequences, after applying the decision. All consequences should be summarized here, not just the "positive" ones. 25 | 26 | ### Positive 27 | 28 | ### Negative 29 | 30 | ### Neutral 31 | 32 | ## References 33 | 34 | > Are there any relevant PR comments, issues that led up to this, or articles referenced for why we made the given design choice? If so link them here! 35 | 36 | * {reference link} -------------------------------------------------------------------------------- /docs/audit/report_ethermint_1.2_final_public.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crypto-org-chain/cronos/4815e61174f2917df82316ab53e0d142127d820c/docs/audit/report_ethermint_1.2_final_public.pdf -------------------------------------------------------------------------------- /docs/docs.go: -------------------------------------------------------------------------------- 1 | package docs 2 | 3 | import "embed" 4 | 5 | // Docs embed docs static files 6 | // 7 | //go:embed static 8 | var Docs embed.FS 9 | -------------------------------------------------------------------------------- /docs/gravity-bridge/gorc-build.md: -------------------------------------------------------------------------------- 1 | ## Gravity Orchestrator (gorc) 2 | 3 | gorc, short for gravity orchestrator, is the main process to run gravity bridge orchestrators (for validators) and relayers. 4 | 5 | This guide shows the build process for gorc. 6 | 7 | ### Prerequisites 8 | 9 | - rust & cargo [>=1.61] (can be installed [here](https://www.rust-lang.org/tools/install)). They must be included in $PATH variable 10 | 11 | ### Build 12 | 13 | In order to build the binary, we will need to first clone the repository: 14 | 15 | ```bash 16 | git clone https://github.com/crypto-org-chain/gravity-bridge.git 17 | cd gravity-bridge 18 | git checkout v2.0.0-cronos-alpha0 19 | ``` 20 | 21 | Then, we can build with cargo: 22 | 23 | ```bash 24 | cd orchestrator 25 | cargo build --release --features ethermint 26 | ``` 27 | 28 | After the build is complete, you will find the binary at `./target/release/gorc` 29 | -------------------------------------------------------------------------------- /docs/gravity-bridge/gravity-bridge-relayer-modes.md: -------------------------------------------------------------------------------- 1 | ## Gravity Bridge Relayer Modes 2 | 3 | Gravity Bridge relayer supports the following modes: 4 | 1. AlwaysRelay 5 | 2. Api 6 | 3. File 7 | 8 | 9 | ### Always relay mode 10 | 11 | Using this mode, the relayer will always relay the batches ignoring the cost, profitable or not. 12 | 13 | ### Api mode 14 | 15 | The env variable `RELAYER_API_URL` needs to be set to use this mode. The relayer will call an API that will estimate the cost of sending the batch, check if the daily limit is reached and none of the addresses are blacklisted. It will send the batch only if all the conditions are met. 16 | ### File mode 17 | 18 | A file `token_prices_json` needs to be present in running directory to use this mode. The relayer will fetch the price of each tokens supported using the file as a data source and relay the batch only if it is profitable. -------------------------------------------------------------------------------- /docs/gravity-bridge/systemd/gorc.service.template: -------------------------------------------------------------------------------- 1 | # /etc/systemd/system/gorc.service 2 | [Unit] 3 | Description=gorc 4 | ConditionPathExists= 5 | After=network.target 6 | 7 | [Service] 8 | Type=simple 9 | User= 10 | WorkingDirectory= 11 | ExecStart= -c /gorc.toml 12 | Restart=on-failure 13 | RestartSec=10 14 | 15 | Environment="RELAYER_API_URL=https://cronos.org/pioneer11/relayer/relayer" 16 | 17 | [Install] 18 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /integration_tests/.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 88 3 | extend-ignore = E203 4 | exclude = .git,__pycache__ 5 | -------------------------------------------------------------------------------- /integration_tests/.isort.cfg: -------------------------------------------------------------------------------- 1 | [settings] 2 | # compatible with black 3 | # https://black.readthedocs.io/en/stable/the_black_code_style.html 4 | multi_line_output = 3 5 | include_trailing_comma = True 6 | force_grid_wrap = 0 7 | use_parentheses = True 8 | ensure_newline_before_comments = True 9 | line_length = 88 10 | -------------------------------------------------------------------------------- /integration_tests/README.md: -------------------------------------------------------------------------------- 1 | [Integration test doc](../docs/integration-test.md) -------------------------------------------------------------------------------- /integration_tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crypto-org-chain/cronos/4815e61174f2917df82316ab53e0d142127d820c/integration_tests/__init__.py -------------------------------------------------------------------------------- /integration_tests/configs/broadcast.jsonnet: -------------------------------------------------------------------------------- 1 | local config = import 'default.jsonnet'; 2 | 3 | config { 4 | 'cronos_777-1'+: { 5 | validators: [validator { 6 | client_config: { 7 | 'broadcast-mode': 'sync', 8 | }, 9 | } for validator in super.validators], 10 | }, 11 | } 12 | -------------------------------------------------------------------------------- /integration_tests/configs/broken-cronosd.nix: -------------------------------------------------------------------------------- 1 | { 2 | pkgs ? import ../../nix { }, 3 | }: 4 | let 5 | cronosd = (pkgs.callPackage ../../. { }); 6 | in 7 | cronosd.overrideAttrs (oldAttrs: { 8 | patches = oldAttrs.patches or [ ] ++ [ ./broken-cronosd.patch ]; 9 | }) 10 | -------------------------------------------------------------------------------- /integration_tests/configs/broken-cronosd.patch: -------------------------------------------------------------------------------- 1 | diff --git a/app/app.go b/app/app.go 2 | index 6e9d3a80..83b83274 100644 3 | --- a/app/app.go 4 | +++ b/app/app.go 5 | @@ -1144,6 +1144,10 @@ func (app *App) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) { 6 | 7 | // EndBlocker application updates every end block 8 | func (app *App) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) { 9 | + if ctx.BlockHeight()%10 == 0 { 10 | + store := ctx.KVStore(app.keys["cronos"]) 11 | + store.Set([]byte("hello"), []byte("world")) 12 | + } 13 | rsp, err := app.ModuleManager.EndBlock(ctx) 14 | if err := app.RefreshBlockList(ctx); err != nil { 15 | app.Logger().Error("failed to update blocklist", "error", err) 16 | -------------------------------------------------------------------------------- /integration_tests/configs/cosmovisor.jsonnet: -------------------------------------------------------------------------------- 1 | local config = import 'default.jsonnet'; 2 | 3 | config { 4 | 'cronos_777-1'+: { 5 | 'app-config'+: { 6 | 'app-db-backend': 'rocksdb', 7 | 'minimum-gas-prices': '100000000000basetcro', 8 | 'iavl-lazy-loading':: super['iavl-lazy-loading'], 9 | }, 10 | validators: [super.validators[0] { 11 | 'app-config'+: { 12 | store: { 13 | streamers: ['versiondb'], 14 | }, 15 | }, 16 | }] + super.validators[1:], 17 | genesis+: { 18 | app_state+: { 19 | bank+: { 20 | params: { 21 | send_enabled: [ 22 | { 23 | denom: 'stake', 24 | enabled: true, 25 | }, 26 | { 27 | denom: 'basetcro', 28 | enabled: false, 29 | }, 30 | ], 31 | }, 32 | }, 33 | feemarket+: { 34 | params+: { 35 | no_base_fee: false, 36 | base_fee:: super.base_fee, 37 | }, 38 | }, 39 | gov: { 40 | voting_params: { 41 | voting_period: '10s', 42 | }, 43 | deposit_params: { 44 | max_deposit_period: '10s', 45 | min_deposit: [ 46 | { 47 | denom: 'basetcro', 48 | amount: '1', 49 | }, 50 | ], 51 | }, 52 | }, 53 | }, 54 | }, 55 | }, 56 | } 57 | -------------------------------------------------------------------------------- /integration_tests/configs/cosmovisor_gravity.jsonnet: -------------------------------------------------------------------------------- 1 | local config = import 'default.jsonnet'; 2 | 3 | config { 4 | 'cronos_777-1'+: { 5 | 'app-config'+: { 6 | 'app-db-backend': 'rocksdb', 7 | 'minimum-gas-prices': '100000000000basetcro', 8 | memiavl:: super.memiavl, 9 | store:: super.store, 10 | streamers:: super.streamers, 11 | 'iavl-lazy-loading':: super['iavl-lazy-loading'], 12 | }, 13 | validators: [super.validators[0] { 14 | 'app-config':: super['app-config'], 15 | }] + super.validators[1:], 16 | genesis+: { 17 | app_state+: { 18 | feemarket+: { 19 | params+: { 20 | no_base_fee: true, 21 | }, 22 | }, 23 | }, 24 | }, 25 | }, 26 | } 27 | -------------------------------------------------------------------------------- /integration_tests/configs/disable_auto_deployment.jsonnet: -------------------------------------------------------------------------------- 1 | local config = import 'default.jsonnet'; 2 | 3 | config { 4 | 'cronos_777-1'+: { 5 | 'start-flags': '--trace --inv-check-period 5', 6 | 'app-config'+: { 7 | 'minimum-gas-prices':: super['minimum-gas-prices'], 8 | 'json-rpc'+: { 9 | api:: super['api'], 10 | }, 11 | }, 12 | accounts: [{ 13 | name: 'community', 14 | coins: '10000000000000000000000basetcro', 15 | mnemonic: '${COMMUNITY_MNEMONIC}', 16 | }], 17 | genesis+: { 18 | app_state+: { 19 | cronos: { 20 | params: { 21 | cronos_admin: 'crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp', 22 | enable_auto_deployment: false, 23 | }, 24 | }, 25 | transfer:: super['transfer'], 26 | }, 27 | consensus+: { 28 | params+: { 29 | block+: { 30 | time_iota_ms: '2000', 31 | }, 32 | }, 33 | }, 34 | }, 35 | }, 36 | } 37 | -------------------------------------------------------------------------------- /integration_tests/configs/enable-indexer.jsonnet: -------------------------------------------------------------------------------- 1 | local config = import 'default.jsonnet'; 2 | 3 | config { 4 | 'cronos_777-1'+: { 5 | config+: { 6 | tx_index+: { 7 | indexer: 'null', 8 | }, 9 | }, 10 | 'app-config'+: { 11 | 'json-rpc'+: { 12 | 'enable-indexer': true, 13 | }, 14 | }, 15 | genesis+: { 16 | app_state+: { 17 | feemarket+: { 18 | params+: { 19 | min_gas_multiplier: '0', 20 | }, 21 | }, 22 | }, 23 | }, 24 | }, 25 | } 26 | -------------------------------------------------------------------------------- /integration_tests/configs/ibc_rly.jsonnet: -------------------------------------------------------------------------------- 1 | local ibc = import 'ibc.jsonnet'; 2 | 3 | ibc { 4 | 'chainmain-1'+: { 5 | validators: [ 6 | { 7 | coins: '987870000000000000cro', 8 | staked: '20000000000000cro', 9 | mnemonic: '${VALIDATOR' + i + '_MNEMONIC}', 10 | base_port: 26800 + i * 10, 11 | } 12 | for i in std.range(1, 2) 13 | ], 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /integration_tests/configs/ibc_rly_evm.jsonnet: -------------------------------------------------------------------------------- 1 | local ibc = import 'ibc_rly.jsonnet'; 2 | 3 | ibc { 4 | relayer+: { 5 | chains: [super.chains[0] { 6 | precompiled_contract_address: '0x6F1805D56bF05b7be10857F376A5b1c160C8f72C', 7 | json_rpc_address: 'http://127.0.0.1:26701', 8 | }] + super.chains[1:], 9 | }, 10 | } 11 | -------------------------------------------------------------------------------- /integration_tests/configs/ibc_timeout.jsonnet: -------------------------------------------------------------------------------- 1 | local ibc = import 'ibc.jsonnet'; 2 | 3 | ibc { 4 | 'cronos_777-1'+: { 5 | key_name: 'signer3', 6 | accounts: super.accounts + [{ 7 | name: 'signer3', 8 | coins: '0basetcro', 9 | mnemonic: '${SIGNER3_MNEMONIC}', 10 | }], 11 | genesis+: { 12 | app_state+: { 13 | cronos+: { 14 | params+: { 15 | ibc_timeout: 0, 16 | }, 17 | }, 18 | }, 19 | }, 20 | }, 21 | relayer+: { 22 | chains: [super.chains[0] { 23 | fee_granter: 'crc16z0herz998946wr659lr84c8c556da55dc34hh', //signer1 24 | }] + super.chains[1:], 25 | }, 26 | } 27 | -------------------------------------------------------------------------------- /integration_tests/configs/long_timeout_commit.jsonnet: -------------------------------------------------------------------------------- 1 | local default = import 'default.jsonnet'; 2 | 3 | default { 4 | 'cronos_777-1'+: { 5 | config+: { 6 | consensus+: { 7 | timeout_commit: '15s', 8 | }, 9 | }, 10 | 'app-config'+: { 11 | 'blocked-addresses': ['crc16z0herz998946wr659lr84c8c556da55dc34hh'], 12 | }, 13 | }, 14 | } 15 | -------------------------------------------------------------------------------- /integration_tests/configs/low_block_gas_limit.jsonnet: -------------------------------------------------------------------------------- 1 | local config = import 'default.jsonnet'; 2 | 3 | config { 4 | 'cronos_777-1'+: { 5 | 'app-config'+: { 6 | evm+: { 7 | 'max-tx-gas-wanted': 1, 8 | }, 9 | }, 10 | config+: { 11 | consensus+: { 12 | timeout_commit: '5s', 13 | }, 14 | }, 15 | genesis+: { 16 | consensus+: { 17 | params+: { 18 | block+: { 19 | max_gas: '815000', 20 | }, 21 | }, 22 | }, 23 | }, 24 | }, 25 | } 26 | -------------------------------------------------------------------------------- /integration_tests/configs/min_gas_price.jsonnet: -------------------------------------------------------------------------------- 1 | local config = import 'default.jsonnet'; 2 | 3 | config { 4 | 'cronos_777-1'+: { 5 | validators: [validator { 6 | gas_prices: '10000000000000basetcro', 7 | } for validator in super.validators], 8 | genesis+: { 9 | app_state+: { 10 | feemarket+: { 11 | params+: { 12 | base_fee_change_denominator: '3', 13 | elasticity_multiplier: '4', 14 | base_fee: '10000000000000', 15 | min_gas_price: '10000000000000', 16 | }, 17 | }, 18 | }, 19 | }, 20 | }, 21 | } 22 | -------------------------------------------------------------------------------- /integration_tests/configs/min_gas_price_eq.jsonnet: -------------------------------------------------------------------------------- 1 | local config = import 'min_gas_price_lte.jsonnet'; 2 | 3 | config { 4 | 'cronos_777-1'+: { 5 | genesis+: { 6 | consensus+: { 7 | params+: { 8 | block+: { 9 | max_gas: '84000000', 10 | }, 11 | }, 12 | }, 13 | }, 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /integration_tests/configs/min_gas_price_lte.jsonnet: -------------------------------------------------------------------------------- 1 | local config = import 'min_gas_price.jsonnet'; 2 | 3 | config { 4 | 'cronos_777-1'+: { 5 | genesis+: { 6 | app_state+: { 7 | feemarket+: { 8 | params+: { 9 | base_fee_change_denominator: '300', 10 | elasticity_multiplier: '4000', 11 | }, 12 | }, 13 | }, 14 | }, 15 | }, 16 | } 17 | -------------------------------------------------------------------------------- /integration_tests/configs/pruned-node.jsonnet: -------------------------------------------------------------------------------- 1 | local config = import 'default.jsonnet'; 2 | 3 | config { 4 | 'cronos_777-1'+: { 5 | 'app-config'+: { 6 | pruning: 'everything', 7 | 'state-sync'+: { 8 | 'snapshot-interval': 0, 9 | }, 10 | }, 11 | validators: [super.validators[0] { 12 | // don't enable versiondb, since it don't do pruning right now 13 | 'app-config':: super['app-config'], 14 | }] + super.validators[1:], 15 | genesis+: { 16 | app_state+: { 17 | feemarket+: { 18 | params+: { 19 | min_gas_multiplier: '0', 20 | }, 21 | }, 22 | }, 23 | }, 24 | }, 25 | } 26 | -------------------------------------------------------------------------------- /integration_tests/configs/rollback.jsonnet: -------------------------------------------------------------------------------- 1 | local config = import 'default.jsonnet'; 2 | 3 | config { 4 | 'cronos_777-1'+: { 5 | validators: super.validators + [{ 6 | name: 'rollback-test-memiavl', 7 | 'app-config': { 8 | memiavl: { 9 | enable: true, 10 | }, 11 | }, 12 | }, { 13 | name: 'rollback-test-iavl', 14 | 'app-config': { 15 | memiavl: { 16 | enable: false, 17 | }, 18 | }, 19 | }], 20 | }, 21 | } 22 | -------------------------------------------------------------------------------- /integration_tests/configs/upgrade-test-package.nix: -------------------------------------------------------------------------------- 1 | let 2 | pkgs = import ../../nix { }; 3 | fetchFlake = 4 | repo: rev: 5 | (pkgs.flake-compat { 6 | src = { 7 | outPath = builtins.fetchTarball "https://github.com/${repo}/archive/${rev}.tar.gz"; 8 | inherit rev; 9 | shortRev = builtins.substring 0 7 rev; 10 | }; 11 | }).defaultNix; 12 | # v1.0.15 13 | releasedGenesis = 14 | (fetchFlake "crypto-org-chain/cronos" "1f5e2618362303d91f621b47cbc1115cf4fa0195").default; 15 | # release/v1.1.x 16 | released1_1 = 17 | (fetchFlake "crypto-org-chain/cronos" "69a80154b6b24fca15f3562e2c4b312ee1092220").default; 18 | # release/v1.2.x 19 | released1_2 = 20 | (fetchFlake "crypto-org-chain/cronos" "1aea999eef67a0a01b22422bad94b36e45b9759a").default; 21 | # release/v1.3.x 22 | released1_3 = 23 | (fetchFlake "crypto-org-chain/cronos" "dd3cea2df41732ef030a1f830244e340f3cf6bf0").default; 24 | # release/v1.4.x 25 | released1_4 = 26 | (fetchFlake "crypto-org-chain/cronos" "ce797fa995000530ee53cd1fbeb3c67180648002").default; 27 | current = pkgs.callPackage ../../. { }; 28 | in 29 | pkgs.linkFarm "upgrade-test-package" [ 30 | { 31 | name = "genesis"; 32 | path = releasedGenesis; 33 | } 34 | { 35 | name = "v1.1.0"; 36 | path = released1_1; 37 | } 38 | { 39 | name = "v1.2"; 40 | path = released1_2; 41 | } 42 | { 43 | name = "v1.3"; 44 | path = released1_3; 45 | } 46 | { 47 | name = "v1.4"; 48 | path = released1_4; 49 | } 50 | { 51 | name = "v1.4.0-rc5-testnet"; 52 | path = current; 53 | } 54 | ] 55 | -------------------------------------------------------------------------------- /integration_tests/contracts/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /typechain 3 | /artifacts 4 | /cache 5 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/CroBridge.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.6; 2 | 3 | contract CroBridge { 4 | 5 | event __CronosSendCroToIbc(address sender, string recipient, uint256 amount); 6 | 7 | // Pay the contract a certain CRO amount and trigger a CRO transfer 8 | // from the contract to recipient through IBC 9 | function send_cro_to_crypto_org(string memory recipient) public payable { 10 | emit __CronosSendCroToIbc(msg.sender, recipient, msg.value); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/CronosGravityCancellation.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.6; 2 | 3 | contract CronosGravityCancellation { 4 | 5 | event __CronosCancelSendToEvmChain(address indexed sender, uint256 id); 6 | 7 | // Cancel a send to chain transaction considering if it hasn't been batched yet. 8 | function cancelTransaction(uint256 id) public { 9 | emit __CronosCancelSendToEvmChain(msg.sender, id); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/Greeter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.8.21; 2 | 3 | contract Greeter { 4 | string public greeting; 5 | 6 | event ChangeGreeting(address from, string value); 7 | 8 | constructor() public { 9 | greeting = "Hello"; 10 | } 11 | 12 | function setGreeting(string memory _greeting) public { 13 | greeting = _greeting; 14 | emit ChangeGreeting(msg.sender, _greeting); 15 | } 16 | 17 | function greet() public view returns (string memory) { 18 | return greeting; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/ICosmosToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity 0.8.21; 4 | 5 | /** 6 | * @dev Interface of the CosmosToken deployed by the gravity contract 7 | */ 8 | interface ICosmosToken { 9 | /** 10 | * @dev Sets the gravity contract and transfer the balance to the new address. 11 | * 12 | * Requirements: 13 | * 14 | * - `msg.sender` must be the current gravity contract 15 | */ 16 | function setGravityContract(address _gravityAddress) external; 17 | 18 | } -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/Random.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.15; 3 | 4 | contract Random { 5 | function randomTokenId() public returns (uint256) { 6 | return uint256(keccak256(abi.encodePacked(block.prevrandao))); 7 | } 8 | } -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/TestBank.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.6; 3 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 4 | import {IBankModule} from "./src/Bank.sol"; 5 | 6 | contract TestBank is ERC20 { 7 | address constant bankContract = 0x0000000000000000000000000000000000000064; 8 | IBankModule bank = IBankModule(bankContract); 9 | 10 | constructor() public ERC20("Bitcoin MAX", "MAX") { 11 | _mint(msg.sender, 100000000000000000000000000); 12 | } 13 | 14 | function moveToNative(uint256 amount) public returns (bool) { 15 | _burn(msg.sender, amount); 16 | return bank.mint(msg.sender, amount); 17 | } 18 | 19 | function moveFromNative(uint256 amount) public returns (bool) { 20 | bool result = bank.burn(msg.sender, amount); 21 | require(result, "native call"); 22 | _mint(msg.sender, amount); 23 | return result; 24 | } 25 | 26 | function nativeBalanceOf(address addr) public returns (uint256) { 27 | return bank.balanceOf(address(this), addr); 28 | } 29 | 30 | function moveToNativeRevert(uint256 amount) public { 31 | moveToNative(amount); 32 | revert("test"); 33 | } 34 | 35 | function nativeTransfer(address recipient, uint256 amount) public returns (bool) { 36 | _transfer(msg.sender, recipient, amount); 37 | return bank.transfer(msg.sender, recipient, amount); 38 | } 39 | } -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/TestBlackListERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.8.21; 2 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 3 | 4 | contract TestBlackListERC20 is ERC20 { 5 | address public blacklisted; 6 | 7 | constructor(address blacklistAddresses) public ERC20("USDC", "USDC") { 8 | _mint(msg.sender, 100000000000000000000000000); 9 | blacklisted = blacklistAddresses; 10 | } 11 | 12 | function transfer(address to, uint256 amount) public override returns (bool) { 13 | require(false == isBlacklisted(to), "address is blacklisted"); 14 | return super.transfer(to, amount); 15 | } 16 | 17 | function isBlacklisted(address _target) private returns (bool) { 18 | if (blacklisted == _target) { 19 | return true; 20 | } 21 | return false; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/TestCRC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.8.21; 2 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 3 | 4 | // An utility erc20 contract that has a fancy method 5 | contract TestCRC20 is ERC20 { 6 | event __CronosSendToAccount(address recipient, uint256 amount); 7 | event __CronosSendToEthereum(address recipient, uint256 amount, uint256 bridge_fee); 8 | address constant module_address = 0x89A7EF2F08B1c018D5Cc88836249b84Dd5392905; 9 | address public owner; 10 | 11 | constructor() public ERC20("Test", "TEST") { 12 | _mint(msg.sender, 100000000000000000000000000); 13 | owner = msg.sender; 14 | } 15 | 16 | function mint_by_cronos_module(address addr, uint amount) public { 17 | require(msg.sender == module_address); 18 | _mint(addr, amount); 19 | } 20 | 21 | // send to ethereum through gravity bridge 22 | function send_to_ethereum(address recipient, uint256 amount, uint256 bridge_fee) external { 23 | uint256 total = amount + bridge_fee; 24 | require(total >= amount, "safe-math-add-overflow"); 25 | _burn(msg.sender, total); 26 | emit __CronosSendToEthereum(recipient, amount, bridge_fee); 27 | } 28 | 29 | function mint(address account, uint256 amount) external { 30 | // Should be protected by only owner 31 | _mint(account, amount); 32 | } 33 | 34 | function burn(uint256 amount) external { 35 | _burn(msg.sender, amount); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/TestERC20A.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.8.10; 2 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 3 | 4 | contract TestERC20A is ERC20 { 5 | event __CronosSendToAccount(address recipient, uint256 amount); 6 | 7 | constructor() public ERC20("Bitcoin MAX", "MAX") { 8 | _mint(msg.sender, 100000000000000000000000000); 9 | } 10 | 11 | function test_native_transfer(uint amount) public { 12 | emit __CronosSendToAccount(msg.sender, amount); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/TestERC20Utility.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.8.21; 2 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 3 | 4 | // An utility erc20 contract that has a fancy method 5 | contract TestERC20Utility is ERC20 { 6 | event __CronosSendToAccount(address recipient, uint256 amount); 7 | event __CronosSendToEthereum(address recipient, uint256 amount, uint256 bridge_fee); 8 | address constant module_address = 0x89A7EF2F08B1c018D5Cc88836249b84Dd5392905; 9 | 10 | constructor() public ERC20("Fancy", "FNY") { 11 | _mint(msg.sender, 100000000000000000000000000); 12 | } 13 | 14 | function fancy() public view returns (uint256) { 15 | return 42; 16 | } 17 | 18 | function mint_by_cronos_module(address addr, uint amount) public { 19 | require(msg.sender == module_address); 20 | _mint(addr, amount); 21 | } 22 | 23 | // send to ethereum through gravity bridge 24 | function send_to_ethereum(address recipient, uint256 amount, uint256 bridge_fee) external { 25 | uint256 total = amount + bridge_fee; 26 | require(total >= amount, "safe-math-add-overflow"); 27 | _burn(msg.sender, total); 28 | emit __CronosSendToEthereum(recipient, amount, bridge_fee); 29 | } 30 | 31 | function test_log0() public { 32 | bytes32 data = "hello world"; 33 | assembly { 34 | let p := mload(0x20) 35 | mstore(p, data) 36 | log0(p, 0x20) 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/TestMaliciousSupply.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.8.21; 2 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 3 | 4 | // This contract is for testing a case on the gravity bridge when attacker try to send an amount 5 | // that exceed the limit allowed ( max(uint256) ) 6 | contract TestMaliciousSupply is ERC20 { 7 | uint256 public count; 8 | 9 | constructor() public ERC20("MAX", "MAX") { 10 | _mint(msg.sender, 115792089237316195423570985008687907853269984665640564039457584007913129639935); 11 | } 12 | 13 | // transferFrom just increment the counter so that in case the count is even 14 | // SendToCosmos will record an event that simulate a transfer of token amount equal to max(uint256) 15 | // since it records the difference of balance of the gravity contract after the transferFrom 16 | function transferFrom( 17 | address from, 18 | address to, 19 | uint256 amount 20 | ) public virtual override returns (bool) { 21 | count = count + 1; 22 | return true; 23 | } 24 | 25 | // if the count is even, then balanceOf will return zero 26 | // if the count is odd, then it return max uint256 27 | function balanceOf(address account) public view virtual override returns (uint256) { 28 | if (count % 2 == 0) { 29 | return 0; 30 | } else { 31 | return 115792089237316195423570985008687907853269984665640564039457584007913129639935; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/TestMessageCall.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.6; 2 | 3 | contract Inner { 4 | event TestEvent(uint256); 5 | function test() public returns (uint256) { 6 | emit TestEvent(42); 7 | return 42; 8 | } 9 | } 10 | 11 | // An contract that do lots of message calls 12 | contract TestMessageCall { 13 | Inner _inner; 14 | constructor() public { 15 | _inner = new Inner(); 16 | } 17 | 18 | function test(uint iterations) public returns (uint256) { 19 | uint256 n = 0; 20 | for (uint i = 0; i < iterations; i++) { 21 | n += _inner.test(); 22 | } 23 | return n; 24 | } 25 | 26 | function inner() public view returns (address) { 27 | return address(_inner); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/TestRelayer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | import {IRelayerFunctions} from "./src/RelayerFunctions.sol"; 5 | 6 | contract TestRelayer { 7 | address constant relayerContract = 0x0000000000000000000000000000000000000065; 8 | IRelayerFunctions relayer = IRelayerFunctions(relayerContract); 9 | address payee; 10 | address counterpartyPayee; 11 | 12 | function batchCall(bytes[] memory payloads) public { 13 | for (uint256 i = 0; i < payloads.length; i++) { 14 | (bool success,) = relayerContract.call(payloads[i]); 15 | require(success); 16 | } 17 | } 18 | 19 | function callRegisterPayee(string calldata portID, string calldata channelID, address payeeAddr) public returns (bool) { 20 | require(payee == address(0) || payee == msg.sender, "register fail"); 21 | bool result = relayer.registerPayee(portID, channelID, payeeAddr); 22 | require(result, "call failed"); 23 | payee = msg.sender; 24 | } 25 | 26 | function callRegisterCounterpartyPayee(string calldata portID, string calldata channelID, string calldata counterpartyPayeeAddr) public returns (bool) { 27 | require(counterpartyPayee == address(0) || counterpartyPayee == msg.sender, "register fail"); 28 | bool result = relayer.registerCounterpartyPayee(portID, channelID, counterpartyPayeeAddr); 29 | require(result, "call failed"); 30 | counterpartyPayee = msg.sender; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/TestRevert.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.6.6; 3 | 4 | contract TestRevert { 5 | uint256 state; 6 | constructor() public { 7 | state = 0; 8 | } 9 | function transfer(uint256 value) public payable { 10 | uint256 minimal = 5 * 10 ** 18; 11 | state = value; 12 | if(state < minimal) { 13 | revert("Not enough tokens to transfer"); 14 | } 15 | } 16 | function query() view public returns (uint256) { 17 | return state; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/TestSuicide.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.6.6; 3 | 4 | contract Destroyee { 5 | function destroy() public { 6 | selfdestruct(payable(msg.sender)); 7 | } 8 | } 9 | 10 | contract Destroyer { 11 | function check_codesize_after_suicide(Destroyee destroyee) public { 12 | address addr = address(destroyee); 13 | destroyee.destroy(); 14 | uint _size = 0; 15 | assembly { 16 | _size := extcodesize(addr) 17 | } 18 | require(_size > 0); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /integration_tests/contracts/contracts/src: -------------------------------------------------------------------------------- 1 | ../../../x/cronos/events/bindings/src -------------------------------------------------------------------------------- /integration_tests/contracts/hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import "hardhat-typechain"; 2 | 3 | module.exports = { 4 | solidity: { 5 | compilers: [ 6 | { 7 | version: "0.8.21", 8 | settings: { 9 | optimizer: { 10 | enabled: true 11 | }, 12 | evmVersion: "shanghai" 13 | } 14 | }, 15 | { 16 | version: "0.8.10", 17 | settings: { 18 | optimizer: { 19 | enabled: true 20 | } 21 | } 22 | }, 23 | { 24 | version: "0.6.6", 25 | settings: { 26 | optimizer: { 27 | enabled: true 28 | } 29 | } 30 | }, 31 | ], 32 | }, 33 | typechain: { 34 | outDir: "typechain", 35 | target: "ethers-v5", 36 | runOnCompile: true 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /integration_tests/contracts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contracts", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "typechain": "npx hardhat typechain" 7 | }, 8 | "dependencies": { 9 | "hardhat-typechain": "^0.3.5", 10 | "ts-generator": "^0.1.1", 11 | "typechain": "^4.0.3", 12 | "@typechain/ethers-v5": "^5.0.0", 13 | "@openzeppelin/contracts": "^4.7.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration_tests/gorc.py: -------------------------------------------------------------------------------- 1 | from pystarport.utils import interact 2 | 3 | 4 | class GoRc: 5 | def __init__(self, config_path): 6 | self.config_path = config_path 7 | 8 | def sign_validator(self, eth_key_name, val_addr, nonce): 9 | return ( 10 | interact( 11 | f"gorc -c {self.config_path} sign-delegate-keys " 12 | f"{eth_key_name} {val_addr} {nonce}" 13 | ) 14 | .strip() 15 | .decode() 16 | ) 17 | 18 | def add_eth_key(self, name): 19 | interact(f"gorc -c {self.config_path} keys eth add {name}") 20 | 21 | def add_cosmos_key(self, name): 22 | interact(f"gorc -c {self.config_path} keys cosmos add {name}") 23 | 24 | def show_eth_addr(self, name): 25 | return ( 26 | interact(f"gorc -c {self.config_path} keys eth show {name}") 27 | .strip() 28 | .decode() 29 | ) 30 | 31 | def show_cosmos_addr(self, name): 32 | return ( 33 | interact(f"gorc -c {self.config_path} keys cosmos show {name}") 34 | .split()[1] 35 | .decode() 36 | ) 37 | -------------------------------------------------------------------------------- /integration_tests/msg_send_types.json: -------------------------------------------------------------------------------- 1 | {"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"string"},{"name":"salt","type":"string"}],"Tx":[{"name":"account_number","type":"string"},{"name":"chain_id","type":"string"},{"name":"fee","type":"Fee"},{"name":"memo","type":"string"},{"name":"msgs","type":"Msg[]"},{"name":"sequence","type":"string"}],"Fee":[{"name":"feePayer","type":"string"},{"name":"amount","type":"Coin[]"},{"name":"gas","type":"string"}],"Coin":[{"name":"denom","type":"string"},{"name":"amount","type":"string"}],"Msg":[{"name":"type","type":"string"},{"name":"value","type":"MsgValue"}],"MsgValue":[{"name":"from_address","type":"string"},{"name":"to_address","type":"string"},{"name":"amount","type":"TypeAmount[]"}],"TypeAmount":[{"name":"denom","type":"string"},{"name":"amount","type":"string"}]} -------------------------------------------------------------------------------- /integration_tests/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "integration_tests" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["chain-dev "] 6 | 7 | [tool.poetry.dependencies] 8 | python = "^3.9" 9 | pytest = "^8.0" 10 | pytest-github-actions-annotate-failures = "^0.2" 11 | flake8 = "^7.0" 12 | black = "^24.3" 13 | flake8-black = "^0.3" 14 | flake8-isort = "^6.1" 15 | pep8-naming = "^0.13" 16 | protobuf = "^4.25" 17 | python-dateutil = "^2.8" 18 | web3 = "^6.15" 19 | python-dotenv = "^1.0" 20 | pystarport = { git = "https://github.com/crypto-com/pystarport.git", branch = "main" } 21 | websockets = "^12.0" 22 | toml = "^0" 23 | jsonnet = "^0" 24 | eth-account = "^0.11" 25 | cprotobuf = "^0.1.11" 26 | flaky = "^3.7" 27 | eth-bloom = "^3.0" 28 | eth-hash = "^0" 29 | pyyaml = "^6.0.2rc1" 30 | pytest-timeout = "^2.3.1" 31 | 32 | [tool.poetry.dev-dependencies] 33 | 34 | [build-system] 35 | requires = ["poetry-core>=1.0.0"] 36 | build-backend = "poetry.core.masonry.api" 37 | -------------------------------------------------------------------------------- /integration_tests/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | addopts = --ignore=contracts 3 | python_files = integration_tests/*.py 4 | -------------------------------------------------------------------------------- /integration_tests/shell.nix: -------------------------------------------------------------------------------- 1 | { 2 | system ? builtins.currentSystem, 3 | pkgs ? import ../nix { inherit system; }, 4 | }: 5 | pkgs.mkShell { 6 | buildInputs = [ 7 | (pkgs.callPackage ../. { coverage = true; }) # cronosd 8 | pkgs.start-scripts 9 | pkgs.go-ethereum 10 | pkgs.cosmovisor 11 | pkgs.nodejs 12 | pkgs.test-env 13 | pkgs.chain-maind 14 | pkgs.hermes 15 | pkgs.rly 16 | ]; 17 | shellHook = '' 18 | mkdir ./coverage 19 | export GOCOVERDIR=./coverage 20 | export TMPDIR=/tmp 21 | ''; 22 | } 23 | -------------------------------------------------------------------------------- /integration_tests/test_broadcast.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import pytest 4 | 5 | from .network import setup_custom_cronos 6 | from .utils import submit_any_proposal 7 | 8 | pytestmark = pytest.mark.gov 9 | 10 | 11 | @pytest.fixture(scope="module") 12 | def custom_cronos(tmp_path_factory): 13 | path = tmp_path_factory.mktemp("cronos") 14 | yield from setup_custom_cronos( 15 | path, 26400, Path(__file__).parent / "configs/broadcast.jsonnet" 16 | ) 17 | 18 | 19 | def test_submit_any_proposal(custom_cronos, tmp_path): 20 | submit_any_proposal(custom_cronos, tmp_path) 21 | -------------------------------------------------------------------------------- /integration_tests/test_ibc_rly_gas.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from .ibc_utils import ( 4 | ibc_incentivized_transfer, 5 | ibc_multi_transfer, 6 | ibc_transfer, 7 | log_gas_records, 8 | prepare_network, 9 | ) 10 | from .utils import wait_for_new_blocks 11 | 12 | pytestmark = pytest.mark.ibc_rly_gas 13 | 14 | 15 | @pytest.fixture(scope="module", params=["ibc_rly_evm", "ibc_rly"]) 16 | def ibc(request, tmp_path_factory): 17 | "prepare-network" 18 | name = request.param 19 | path = tmp_path_factory.mktemp(name) 20 | yield from prepare_network(path, name, need_relayer_caller=name == "ibc_rly_evm") 21 | 22 | 23 | records = [] 24 | 25 | 26 | def test_ibc(ibc): 27 | # chainmain-1 relayer -> cronos_777-1 signer2 28 | cli = ibc.cronos.cosmos_cli() 29 | wait_for_new_blocks(cli, 1) 30 | ibc_transfer(ibc) 31 | ibc_incentivized_transfer(ibc) 32 | ibc_multi_transfer(ibc) 33 | diff = 0.15 34 | record = log_gas_records(cli) 35 | if record: 36 | records.append(record) 37 | if len(records) == 2: 38 | res = float(sum(records[0]) / sum(records[1])) 39 | assert 1 - diff <= res <= 1 + diff, res 40 | -------------------------------------------------------------------------------- /integration_tests/test_permissions.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from .utils import ADDRS, eth_to_bech32, wait_for_new_blocks 4 | 5 | 6 | def test_permissions_updates(cronos): 7 | """ 8 | - test permissions updates 9 | - reproduce an iavl prune issue: https://github.com/cosmos/iavl/pull/1007 10 | """ 11 | acc = eth_to_bech32(ADDRS["signer1"]) 12 | cli = cronos.cosmos_cli(2) # node2 is iavl 13 | cli.create_account("community", os.environ["COMMUNITY_MNEMONIC"]) 14 | cli.create_account("admin", os.environ["VALIDATOR1_MNEMONIC"]) 15 | rsp = cli.query_permissions(acc) 16 | print("permissions", rsp) 17 | assert rsp["can_change_token_mapping"] is False 18 | assert rsp["can_turn_bridge"] is False 19 | 20 | # update permissions 21 | rsp = cli.update_permissions(acc, 3, from_="community") 22 | assert rsp["code"] != 0, "should not have the permission" 23 | 24 | rsp = cli.update_permissions(acc, 3, from_="admin") 25 | assert rsp["code"] == 0, rsp["raw_log"] 26 | 27 | wait_for_new_blocks(cli, 5) 28 | 29 | rsp = cli.query_permissions(acc) 30 | print("permissions", rsp) 31 | assert rsp["can_change_token_mapping"] is True 32 | assert rsp["can_turn_bridge"] is True 33 | 34 | cronos.supervisorctl("stop", "cronos_777-1-node2") 35 | print(cli.prune()) 36 | cronos.supervisorctl("start", "cronos_777-1-node2") 37 | 38 | rsp = cli.update_permissions(acc, 4, from_="admin") 39 | assert rsp["code"] == 0, rsp["raw_log"] 40 | 41 | wait_for_new_blocks(cli, 5) 42 | -------------------------------------------------------------------------------- /integration_tests/test_vesting.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | 4 | def test_create_account(cronos): 5 | """ 6 | test create vesting account is disabled: 7 | """ 8 | cli = cronos.cosmos_cli() 9 | src = "vesting" 10 | addr = cli.create_account(src)["address"] 11 | denom = "basetcro" 12 | balance = cli.balance(addr, denom) 13 | assert balance == 0 14 | amount = 10000 15 | fee = 4000000000000000 16 | amt = f"{amount}{denom}" 17 | end_time = int(time.time()) + 3000 18 | fees = f"{fee}{denom}" 19 | res = cli.create_vesting_account(addr, amt, end_time, from_="validator", fees=fees) 20 | assert res["code"] != 0 21 | assert "vesting messages are not supported" in res["raw_log"] 22 | -------------------------------------------------------------------------------- /memiavl/filelock.go: -------------------------------------------------------------------------------- 1 | package memiavl 2 | 3 | import ( 4 | "path/filepath" 5 | 6 | "github.com/zbiljic/go-filelock" 7 | ) 8 | 9 | type FileLock interface { 10 | Unlock() error 11 | Destroy() error 12 | } 13 | 14 | func LockFile(fname string) (FileLock, error) { 15 | path, err := filepath.Abs(fname) 16 | if err != nil { 17 | return nil, err 18 | } 19 | fl, err := filelock.New(path) 20 | if err != nil { 21 | return nil, err 22 | } 23 | if _, err := fl.TryLock(); err != nil { 24 | return nil, err 25 | } 26 | 27 | return fl, nil 28 | } 29 | -------------------------------------------------------------------------------- /memiavl/mmap.go: -------------------------------------------------------------------------------- 1 | package memiavl 2 | 3 | import ( 4 | "errors" 5 | "os" 6 | 7 | "github.com/ledgerwatch/erigon-lib/mmap" 8 | ) 9 | 10 | // MmapFile manage the resources of a mmap-ed file 11 | type MmapFile struct { 12 | file *os.File 13 | data []byte 14 | // mmap handle for windows (this is used to close mmap) 15 | handle *[mmap.MaxMapSize]byte 16 | } 17 | 18 | // Open openes the file and create the mmap. 19 | // the mmap is created with flags: PROT_READ, MAP_SHARED, MADV_RANDOM. 20 | func NewMmap(path string) (*MmapFile, error) { 21 | file, err := os.Open(path) 22 | if err != nil { 23 | return nil, err 24 | } 25 | 26 | data, handle, err := Mmap(file) 27 | if err != nil { 28 | _ = file.Close() 29 | return nil, err 30 | } 31 | 32 | return &MmapFile{ 33 | file: file, 34 | data: data, 35 | handle: handle, 36 | }, nil 37 | } 38 | 39 | // Close closes the file and mmap handles 40 | func (m *MmapFile) Close() error { 41 | var err error 42 | if m.handle != nil { 43 | err = mmap.Munmap(m.data, m.handle) 44 | } 45 | return errors.Join(err, m.file.Close()) 46 | } 47 | 48 | // Data returns the mmap-ed buffer 49 | func (m *MmapFile) Data() []byte { 50 | return m.data 51 | } 52 | 53 | func Mmap(f *os.File) ([]byte, *[mmap.MaxMapSize]byte, error) { 54 | fi, err := f.Stat() 55 | if err != nil || fi.Size() == 0 { 56 | return nil, nil, err 57 | } 58 | 59 | return mmap.Mmap(f, int(fi.Size())) 60 | } 61 | -------------------------------------------------------------------------------- /memiavl/types.go: -------------------------------------------------------------------------------- 1 | package memiavl 2 | 3 | import fmt "fmt" 4 | 5 | // Logger is what any CometBFT library should take. 6 | type Logger interface { 7 | Debug(msg string, keyvals ...interface{}) 8 | Info(msg string, keyvals ...interface{}) 9 | Error(msg string, keyvals ...interface{}) 10 | } 11 | 12 | type nopLogger struct{} 13 | 14 | // Interface assertions 15 | var _ Logger = (*nopLogger)(nil) 16 | 17 | // NewNopLogger returns a logger that doesn't do anything. 18 | func NewNopLogger() Logger { return &nopLogger{} } 19 | 20 | func (nopLogger) Info(string, ...interface{}) {} 21 | func (nopLogger) Debug(string, ...interface{}) {} 22 | func (nopLogger) Error(string, ...interface{}) {} 23 | 24 | // ExportNode contains exported node data. 25 | type ExportNode struct { 26 | Key []byte 27 | Value []byte 28 | Version int64 29 | Height int8 30 | } 31 | 32 | func (cid CommitID) String() string { 33 | return fmt.Sprintf("CommitID{%v:%X}", cid.Hash, cid.Version) 34 | } 35 | -------------------------------------------------------------------------------- /memiavl/wal_test.go: -------------------------------------------------------------------------------- 1 | package memiavl 2 | 3 | import ( 4 | "os" 5 | "path/filepath" 6 | "testing" 7 | 8 | "github.com/stretchr/testify/require" 9 | "github.com/tidwall/wal" 10 | ) 11 | 12 | func TestCorruptedTail(t *testing.T) { 13 | opts := &wal.Options{ 14 | LogFormat: wal.JSON, 15 | } 16 | dir := t.TempDir() 17 | 18 | testCases := []struct { 19 | name string 20 | logs []byte 21 | lastIndex uint64 22 | }{ 23 | {"failure-1", []byte("\n"), 0}, 24 | {"failure-2", []byte(`{}` + "\n"), 0}, 25 | {"failure-3", []byte(`{"index":"1"}` + "\n"), 0}, 26 | {"failure-4", []byte(`{"index":"1","data":"?"}`), 0}, 27 | {"failure-5", []byte(`{"index":1,"data":"?"}` + "\n" + `{"index":"1","data":"?"}`), 1}, 28 | } 29 | 30 | for _, tc := range testCases { 31 | t.Run(tc.name, func(t *testing.T) { 32 | os.WriteFile(filepath.Join(dir, "00000000000000000001"), tc.logs, 0o600) 33 | 34 | _, err := wal.Open(dir, opts) 35 | require.Equal(t, wal.ErrCorrupt, err) 36 | 37 | log, err := OpenWAL(dir, opts) 38 | require.NoError(t, err) 39 | 40 | lastIndex, err := log.LastIndex() 41 | require.NoError(t, err) 42 | require.Equal(t, tc.lastIndex, lastIndex) 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /nix/build_overlay.nix: -------------------------------------------------------------------------------- 1 | # some basic overlays necessary for the build 2 | final: super: { 3 | rocksdb = final.callPackage ./rocksdb.nix { }; 4 | golangci-lint = final.callPackage ./golangci-lint.nix { }; 5 | } 6 | -------------------------------------------------------------------------------- /nix/bundle-win-exe.nix: -------------------------------------------------------------------------------- 1 | { 2 | runCommand, 3 | windows, 4 | stdenv, 5 | rocksdb, 6 | bzip2, 7 | lz4, 8 | snappy, 9 | zstd, 10 | zlib, 11 | cronosd, 12 | }: 13 | runCommand "tarball-${cronosd.name}" 14 | { 15 | # manually enumerate the runtime dependencies of cronosd on mingwW64 16 | deps = [ 17 | "${rocksdb}/bin/librocksdb-shared.dll" 18 | "${snappy}/bin/libsnappy.dll" 19 | "${lz4.out}/bin/liblz4.dll" 20 | "${bzip2.bin}/bin/libbz2-1.dll" 21 | "${zlib}/bin/zlib1.dll" 22 | "${zstd.bin}/bin/libzstd.dll" 23 | "${windows.mingw_w64_pthreads}/bin/libwinpthread-1.dll" 24 | "${windows.mcfgthreads}/bin/libmcfgthread-1.dll" 25 | "${stdenv.cc.cc.lib}/x86_64-w64-mingw32/lib/libgcc_s_seh-1.dll" 26 | "${stdenv.cc.cc.lib}/x86_64-w64-mingw32/lib/libstdc++-6.dll" 27 | ]; 28 | } 29 | '' 30 | mkdir -p $out 31 | for so in $deps 32 | do 33 | cp $so $out/ 34 | done 35 | 36 | cp ${cronosd}/bin/${cronosd.meta.mainProgram} $out/ 37 | '' 38 | -------------------------------------------------------------------------------- /nix/cosmovisor.nix: -------------------------------------------------------------------------------- 1 | { buildGoModule, fetchFromGitHub }: 2 | 3 | let 4 | version = "1.5.0"; 5 | cosmos-sdk = fetchFromGitHub { 6 | owner = "cosmos"; 7 | repo = "cosmos-sdk"; 8 | rev = "tools/cosmovisor/v${version}"; 9 | hash = "sha256-Ov8FGpDOcsqmFLT2s/ubjmTXj17sQjBWRAdxlJ6DNEY="; 10 | }; 11 | in 12 | buildGoModule rec { 13 | name = "cosmovisor"; 14 | version = "1.5.0"; 15 | src = cosmos-sdk + "/tools/cosmovisor"; 16 | subPackages = [ "./cmd/cosmovisor" ]; 17 | vendorHash = "sha256-IkPnnfkofn5w8Oa/uzGxgI1eb5RrJ9haNgj4mBXF+n8="; 18 | doCheck = false; 19 | } 20 | -------------------------------------------------------------------------------- /nix/dapptools-overlay.nix: -------------------------------------------------------------------------------- 1 | { dapptools-release, dapptools-master }: 2 | self: super: 3 | let 4 | dapptools = 5 | { 6 | x86_64-linux = (import (dapptools-release + "/release.nix") { }).dapphub.linux.stable; 7 | x86_64-darwin = (import (dapptools-release + "/release.nix") { }).dapphub.darwin.stable; 8 | } 9 | .${self.system} or (throw "Unsupported system: ${self.system}"); 10 | dapptools-patched = self.srcOnly { 11 | name = "dapptools-patched"; 12 | src = dapptools-master; 13 | patches = [ ./dapptools.patch ]; 14 | }; 15 | in 16 | { 17 | # use released version to hit the binary cache 18 | inherit (dapptools) dapp solc-versions; 19 | # use the patched version to access solc-static-versions 20 | inherit (import (dapptools-patched + "/overlay.nix") self super) solc-static-versions; 21 | } 22 | -------------------------------------------------------------------------------- /nix/dapptools.patch: -------------------------------------------------------------------------------- 1 | From 455cfd7356c0a10d276e614304ed2b93b880257d Mon Sep 17 00:00:00 2001 2 | From: HuangYi 3 | Date: Mon, 11 Sep 2023 14:50:08 +0800 4 | Subject: [PATCH] fix solc-static on macos 5 | 6 | --- 7 | nix/solc-static.nix | 2 +- 8 | 1 file changed, 1 insertion(+), 1 deletion(-) 9 | 10 | diff --git a/nix/solc-static.nix b/nix/solc-static.nix 11 | index 8ea194ea..e6945828 100644 12 | --- a/nix/solc-static.nix 13 | +++ b/nix/solc-static.nix 14 | @@ -40,7 +40,7 @@ stdenv.mkDerivation rec { 15 | sha256 = "${sha256}"; 16 | }; 17 | 18 | - nativeBuildInputs = [ autoPatchelfHook makeWrapper ]; 19 | + nativeBuildInputs = [ makeWrapper ] ++ lib.optional stdenv.isLinux autoPatchelfHook; 20 | 21 | postFixup = if (platform == "linux-amd64") then '' 22 | wrapProgram $out/bin/solc-${version} \ 23 | -- 24 | 2.39.2 25 | 26 | -------------------------------------------------------------------------------- /nix/gen-binding-shell.nix: -------------------------------------------------------------------------------- 1 | { 2 | system ? builtins.currentSystem, 3 | pkgs ? import ./. { inherit system; }, 4 | }: 5 | let 6 | renameExe = pkgs.callPackage ./rename-exe.nix { }; 7 | in 8 | pkgs.mkShell { 9 | buildInputs = [ 10 | pkgs.go-ethereum 11 | (renameExe pkgs.solc-static-versions.solc_0_6_8 "solc-0.6.8" "solc06") 12 | (renameExe pkgs.solc-static-versions.solc_0_8_21 "solc-0.8.21" "solc08") 13 | ]; 14 | } 15 | -------------------------------------------------------------------------------- /nix/golangci-lint.nix: -------------------------------------------------------------------------------- 1 | { 2 | buildGo123Module, 3 | fetchFromGitHub, 4 | lib, 5 | installShellFiles, 6 | }: 7 | 8 | buildGo123Module rec { 9 | pname = "golangci-lint"; 10 | version = "1.60.1"; 11 | 12 | src = fetchFromGitHub { 13 | owner = "golangci"; 14 | repo = "golangci-lint"; 15 | rev = "v${version}"; 16 | hash = "sha256-+F/t5UJjyqOsabi2J4M9g5JvAqfKjOvlzdhNozRCv70="; 17 | }; 18 | 19 | vendorHash = "sha256-elDDSAeEpKXn6fhBFB218mWsSq0mo+GcfQsTDOAPSCI="; 20 | 21 | subPackages = [ "cmd/golangci-lint" ]; 22 | 23 | nativeBuildInputs = [ installShellFiles ]; 24 | 25 | ldflags = [ 26 | "-s" 27 | "-w" 28 | "-X main.version=${version}" 29 | "-X main.commit=v${version}" 30 | "-X main.date=19700101-00:00:00" 31 | ]; 32 | 33 | postInstall = '' 34 | for shell in bash zsh fish; do 35 | HOME=$TMPDIR $out/bin/golangci-lint completion $shell > golangci-lint.$shell 36 | installShellCompletion golangci-lint.$shell 37 | done 38 | ''; 39 | 40 | meta = with lib; { 41 | description = "Fast linters Runner for Go"; 42 | homepage = "https://golangci-lint.run/"; 43 | changelog = "https://github.com/golangci/golangci-lint/blob/v${version}/CHANGELOG.md"; 44 | mainProgram = "golangci-lint"; 45 | license = licenses.gpl3Plus; 46 | maintainers = with maintainers; [ 47 | SuperSandro2000 48 | mic92 49 | ]; 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /nix/hermes.nix: -------------------------------------------------------------------------------- 1 | { 2 | src, 3 | lib, 4 | stdenv, 5 | darwin, 6 | rustPlatform, 7 | symlinkJoin, 8 | openssl, 9 | pkg-config, 10 | }: 11 | 12 | rustPlatform.buildRustPackage rec { 13 | name = "hermes"; 14 | inherit src; 15 | cargoBuildFlags = "-p ibc-relayer-cli"; 16 | buildInputs = lib.optionals stdenv.isDarwin [ 17 | darwin.apple_sdk.frameworks.Security 18 | pkg-config 19 | openssl 20 | darwin.libiconv 21 | darwin.apple_sdk.frameworks.SystemConfiguration 22 | ]; 23 | cargoLock = { 24 | lockFile = "${src}/Cargo.lock"; 25 | outputHashes = { 26 | "ibc-proto-0.46.0" = "sha256-3rNlmu5jN5eRICynnT+Vib0PrlJOuaJnwbaTYJdX8/8="; 27 | }; 28 | }; 29 | doCheck = false; 30 | RUSTFLAGS = "--cfg ossl111 --cfg ossl110 --cfg ossl101"; 31 | OPENSSL_NO_VENDOR = "1"; 32 | OPENSSL_DIR = symlinkJoin { 33 | name = "openssl"; 34 | paths = with openssl; [ 35 | out 36 | dev 37 | ]; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /nix/rename-exe.nix: -------------------------------------------------------------------------------- 1 | { runCommandLocal }: 2 | drv: oldName: newName: 3 | runCommandLocal drv.name { } '' 4 | mkdir -p $out/bin 5 | ln -s ${drv}/bin/${oldName} $out/bin/${newName} 6 | '' 7 | -------------------------------------------------------------------------------- /nix/scripts.nix: -------------------------------------------------------------------------------- 1 | { 2 | pkgs, 3 | config, 4 | cronos ? (import ../. { inherit pkgs; }), 5 | }: 6 | rec { 7 | start-cronos = pkgs.writeShellScriptBin "start-cronos" '' 8 | # rely on environment to provide cronosd 9 | export PATH=${pkgs.test-env}/bin:$PATH 10 | ${../scripts/start-cronos} ${config.cronos-config} ${config.dotenv} $@ 11 | ''; 12 | start-geth = pkgs.writeShellScriptBin "start-geth" '' 13 | export PATH=${pkgs.test-env}/bin:${pkgs.go-ethereum}/bin:$PATH 14 | source ${config.dotenv} 15 | ${../scripts/start-geth} ${config.geth-genesis} $@ 16 | ''; 17 | start-scripts = pkgs.symlinkJoin { 18 | name = "start-scripts"; 19 | paths = [ 20 | start-cronos 21 | start-geth 22 | ]; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /nix/testenv.nix: -------------------------------------------------------------------------------- 1 | { 2 | poetry2nix, 3 | lib, 4 | python311, 5 | }: 6 | poetry2nix.mkPoetryEnv { 7 | projectDir = ../integration_tests; 8 | python = python311; 9 | overrides = poetry2nix.overrides.withDefaults ( 10 | self: super: 11 | let 12 | buildSystems = { 13 | pystarport = [ "poetry-core" ]; 14 | cprotobuf = [ "setuptools" ]; 15 | durations = [ "setuptools" ]; 16 | multitail2 = [ "setuptools" ]; 17 | pytest-github-actions-annotate-failures = [ "setuptools" ]; 18 | flake8-black = [ "setuptools" ]; 19 | flake8-isort = [ "hatchling" ]; 20 | pyunormalize = [ "setuptools" ]; 21 | eth-bloom = [ "setuptools" ]; 22 | isort = [ "poetry-core" ]; 23 | }; 24 | in 25 | lib.mapAttrs ( 26 | attr: systems: 27 | super.${attr}.overridePythonAttrs (old: { 28 | nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ map (a: self.${a}) systems; 29 | }) 30 | ) buildSystems 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /nix/testground-cronosd.patch: -------------------------------------------------------------------------------- 1 | diff --git a/app/app.go b/app/app.go 2 | index 678ccc0a..ba64a7fe 100644 3 | --- a/app/app.go 4 | +++ b/app/app.go 5 | @@ -1060,6 +1060,7 @@ func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64, bl 6 | }, 7 | ExtraDecorators: []sdk.AnteDecorator{blockAddressDecorator}, 8 | PendingTxListener: app.onPendingTx, 9 | + UnsafeUnorderedTx: true, 10 | } 11 | 12 | anteHandler, err := evmante.NewAnteHandler(options) 13 | -------------------------------------------------------------------------------- /nix/testground-image.nix: -------------------------------------------------------------------------------- 1 | { 2 | dockerTools, 3 | runCommandLocal, 4 | cronos-matrix, 5 | benchmark-testcase, 6 | }: 7 | let 8 | patched-cronosd = cronos-matrix.cronosd.overrideAttrs (oldAttrs: { 9 | patches = oldAttrs.patches or [ ] ++ [ ./testground-cronosd.patch ]; 10 | }); 11 | in 12 | let 13 | tmpDir = runCommandLocal "tmp" { } '' 14 | mkdir -p $out/tmp/ 15 | ''; 16 | in 17 | dockerTools.buildLayeredImage { 18 | name = "cronos-testground"; 19 | created = "now"; 20 | contents = [ 21 | benchmark-testcase 22 | patched-cronosd 23 | tmpDir 24 | ]; 25 | config = { 26 | Expose = [ 27 | 9090 28 | 26657 29 | 26656 30 | 1317 31 | 26658 32 | 26660 33 | 26659 34 | 30000 35 | ]; 36 | Cmd = [ "/bin/stateless-testcase" ]; 37 | Env = [ "PYTHONUNBUFFERED=1" ]; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /proto/buf.gen.gogo.yaml: -------------------------------------------------------------------------------- 1 | version: v1 2 | plugins: 3 | - name: gocosmos 4 | out: .. 5 | opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types 6 | - name: grpc-gateway 7 | out: .. 8 | opt: logtostderr=true,allow_colon_final_segments=true 9 | -------------------------------------------------------------------------------- /proto/buf.gen.swagger.yaml: -------------------------------------------------------------------------------- 1 | version: v1 2 | plugins: 3 | - name: swagger 4 | out: ../tmp-swagger-gen 5 | opt: logtostderr=true,fqn_for_swagger_name=true,simple_operation_ids=true 6 | -------------------------------------------------------------------------------- /proto/buf.lock: -------------------------------------------------------------------------------- 1 | # Generated by buf. DO NOT EDIT. 2 | version: v1 3 | deps: 4 | - remote: buf.build 5 | owner: cosmos 6 | repository: cosmos-proto 7 | commit: 1935555c206d4afb9e94615dfd0fad31 8 | digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377 9 | - remote: buf.build 10 | owner: cosmos 11 | repository: cosmos-sdk 12 | commit: 954f7b05f38440fc8250134b15adec47 13 | digest: shake256:2ab4404fd04a7d1d52df0e2d0f2d477a3d83ffd88d876957bf3fedfd702c8e52833d65b3ce1d89a3c5adf2aab512616b0e4f51d8463f07eda9a8a3317ee3ac54 14 | - remote: buf.build 15 | owner: cosmos 16 | repository: gogo-proto 17 | commit: 5e5b9fdd01804356895f8f79a6f1ddc1 18 | digest: shake256:0b85da49e2e5f9ebc4806eae058e2f56096ff3b1c59d1fb7c190413dd15f45dd456f0b69ced9059341c80795d2b6c943de15b120a9e0308b499e43e4b5fc2952 19 | - remote: buf.build 20 | owner: cosmos 21 | repository: ics23 22 | commit: 55085f7c710a45f58fa09947208eb70b 23 | digest: shake256:9bf0bc495b5a11c88d163d39ef521bc4b00bc1374a05758c91d82821bdc61f09e8c2c51dda8452529bf80137f34d852561eacbe9550a59015d51cecb0dacb628 24 | - remote: buf.build 25 | owner: googleapis 26 | repository: googleapis 27 | commit: cc916c31859748a68fd229a3c8d7a2e8 28 | digest: shake256:469b049d0eb04203d5272062636c078decefc96fec69739159c25d85349c50c34c7706918a8b216c5c27f76939df48452148cff8c5c3ae77fa6ba5c25c1b8bf8 29 | -------------------------------------------------------------------------------- /proto/buf.yaml: -------------------------------------------------------------------------------- 1 | # Generated by "buf config migrate-v1beta1". Edit as necessary, and 2 | # remove this comment when you're finished. 3 | # 4 | # This module represents the "proto" root found in 5 | # the previous configuration. 6 | version: v1 7 | name: buf.build/crypto-org-chain/cronos 8 | deps: 9 | - buf.build/cosmos/cosmos-sdk:954f7b05f38440fc8250134b15adec47 10 | - buf.build/cosmos/cosmos-proto:1935555c206d4afb9e94615dfd0fad31 11 | - buf.build/cosmos/gogo-proto:5e5b9fdd01804356895f8f79a6f1ddc1 12 | - buf.build/googleapis/googleapis:cc916c31859748a68fd229a3c8d7a2e8 13 | - buf.build/cosmos/ics23:b1abd8678aab07165efd453c96796a179eb3131f 14 | - buf.build/crypto-org-chain/cronos-thirdparty 15 | breaking: 16 | use: 17 | - FILE 18 | lint: 19 | use: 20 | - DEFAULT 21 | - COMMENTS 22 | - FILE_LOWER_SNAKE_CASE 23 | except: 24 | - UNARY_RPC 25 | - COMMENT_FIELD 26 | - SERVICE_SUFFIX 27 | - PACKAGE_VERSION_SUFFIX 28 | - RPC_REQUEST_STANDARD_NAME 29 | -------------------------------------------------------------------------------- /proto/cronos/cronos.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cronos; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/crypto-org-chain/cronos/v2/x/cronos/types"; 7 | 8 | // Params defines the parameters for the cronos module. 9 | message Params { 10 | option (gogoproto.goproto_stringer) = false; 11 | string ibc_cro_denom = 1 [(gogoproto.moretags) = "yaml:\"ibc_cro_denom,omitempty\""]; 12 | uint64 ibc_timeout = 2; 13 | // the admin address who can update token mapping 14 | string cronos_admin = 3; 15 | bool enable_auto_deployment = 4; 16 | uint64 max_callback_gas = 5; 17 | } 18 | 19 | // TokenMappingChangeProposal defines a proposal to change one token mapping. 20 | message TokenMappingChangeProposal { 21 | option (gogoproto.goproto_getters) = false; 22 | option (gogoproto.goproto_stringer) = false; 23 | 24 | string title = 1; 25 | string description = 2; 26 | string denom = 3; 27 | string contract = 4; 28 | // only when updating cronos (source) tokens 29 | string symbol = 5; 30 | uint32 decimal = 6; 31 | } 32 | 33 | // TokenMapping defines a mapping between native denom and contract 34 | message TokenMapping { 35 | string denom = 1; 36 | string contract = 2; 37 | } 38 | -------------------------------------------------------------------------------- /proto/cronos/genesis.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cronos; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "cronos/cronos.proto"; 6 | 7 | // this line is used by starport scaffolding # genesis/proto/import 8 | 9 | option go_package = "github.com/crypto-org-chain/cronos/v2/x/cronos/types"; 10 | 11 | // GenesisState defines the cronos module's genesis state. 12 | message GenesisState { 13 | // params defines all the paramaters of the module. 14 | Params params = 1 [(gogoproto.nullable) = false]; 15 | repeated TokenMapping external_contracts = 2 [(gogoproto.nullable) = false]; 16 | repeated TokenMapping auto_contracts = 3 [(gogoproto.nullable) = false]; 17 | // this line is used by starport scaffolding # genesis/proto/state 18 | // this line is used by starport scaffolding # ibc/genesis/proto 19 | } 20 | -------------------------------------------------------------------------------- /proto/e2ee/genesis.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package e2ee; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/crypto-org-chain/cronos/v2/x/e2ee/types"; 7 | 8 | // EncryptionKeyEntry is a type that contains the owner and the public key. 9 | message EncryptionKeyEntry { 10 | string address = 1; 11 | string key = 2; 12 | } 13 | 14 | // GenesisState defines the e2ee module's genesis state. 15 | message GenesisState { 16 | // params defines all the paramaters of the module. 17 | repeated EncryptionKeyEntry keys = 1 [(gogoproto.nullable) = false]; 18 | } 19 | -------------------------------------------------------------------------------- /proto/e2ee/query.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package e2ee; 3 | 4 | import "google/api/annotations.proto"; 5 | 6 | option go_package = "github.com/crypto-org-chain/cronos/v2/x/e2ee/types"; 7 | 8 | // Query defines the gRPC querier service. 9 | service Query { 10 | // Key queries the encryption key of a given address 11 | rpc Key(KeyRequest) returns (KeyResponse) { 12 | option (google.api.http).get = "/e2ee/v1/key/{address}"; 13 | } 14 | // Keys queries the encryption keys for a batch of addresses 15 | rpc Keys(KeysRequest) returns (KeysResponse) { 16 | option (google.api.http) = { 17 | post: "/e2ee/v1/keys" 18 | body: "*" 19 | }; 20 | } 21 | } 22 | 23 | // KeyRequest is the request type for the Query/Key RPC method. 24 | message KeyRequest { 25 | string address = 1; 26 | } 27 | 28 | // KeyResponse is the response type for the Query/Key RPC method. 29 | message KeyResponse { 30 | string key = 1; 31 | } 32 | 33 | 34 | // KeysRequest is the request type for the Query/Key RPC method. 35 | message KeysRequest { 36 | repeated string addresses = 1; 37 | } 38 | 39 | // KeysResponse is the response type for the Query/Key RPC method. 40 | message KeysResponse { 41 | repeated string keys = 1; 42 | } 43 | -------------------------------------------------------------------------------- /proto/e2ee/tx.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package e2ee; 3 | 4 | import "cosmos/msg/v1/msg.proto"; 5 | 6 | option go_package = "github.com/crypto-org-chain/cronos/v2/x/e2ee/types"; 7 | 8 | // Msg defines the e2ee Msg service 9 | service Msg { 10 | option (cosmos.msg.v1.service) = true; 11 | 12 | // RegisterEncryptionKey registers a new encryption key to a specific account 13 | rpc RegisterEncryptionKey(MsgRegisterEncryptionKey) returns (MsgRegisterEncryptionKeyResponse); 14 | } 15 | 16 | // MsgRegisterEncryptionKey defines the Msg/RegisterEncryptionKey request type 17 | message MsgRegisterEncryptionKey { 18 | option (cosmos.msg.v1.signer) = "address"; 19 | 20 | string address = 1; 21 | string key = 2; 22 | } 23 | 24 | // MsgRegisterEncryptionKeyResponse defines the Msg/RegisterEncryptionKey response type 25 | message MsgRegisterEncryptionKeyResponse { 26 | } 27 | -------------------------------------------------------------------------------- /proto/memiavl/changeset.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package memiavl; 3 | 4 | option go_package = "github.com/crypto-org-chain/cronos/memiavl"; 5 | 6 | // KVPair represents a key-value pair 7 | message KVPair { 8 | bool delete = 1; 9 | bytes key = 2; 10 | bytes value = 3; 11 | } 12 | 13 | // ChangeSet represents a list of key-value pairs 14 | message ChangeSet { 15 | repeated KVPair pairs = 1; 16 | } 17 | -------------------------------------------------------------------------------- /proto/memiavl/commit_info.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package memiavl; 3 | 4 | option go_package = "github.com/crypto-org-chain/cronos/memiavl"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | 8 | // CommitInfo defines commit information used by the multi-store when committing 9 | // a version/height. 10 | message CommitInfo { 11 | int64 version = 1; 12 | repeated StoreInfo store_infos = 2 [(gogoproto.nullable) = false]; 13 | } 14 | 15 | // StoreInfo defines store-specific commit information. It contains a reference 16 | // between a store name and the commit ID. 17 | message StoreInfo { 18 | string name = 1; 19 | CommitID commit_id = 2 [(gogoproto.nullable) = false]; 20 | } 21 | 22 | // CommitID defines the committment information when a specific store is 23 | // committed. 24 | message CommitID { 25 | option (gogoproto.goproto_stringer) = false; 26 | 27 | int64 version = 1; 28 | bytes hash = 2; 29 | } 30 | -------------------------------------------------------------------------------- /proto/memiavl/kv.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | // vendored from cosmos.store.internal.kv.v1beta1; 3 | package memiavl; 4 | 5 | import "gogoproto/gogo.proto"; 6 | 7 | option go_package = "github.com/crypto-org-chain/cronos/memiavl"; 8 | 9 | // Pairs defines a repeated slice of Pair objects. 10 | message Pairs { 11 | repeated Pair pairs = 1 [(gogoproto.nullable) = false]; 12 | } 13 | 14 | // Pair defines a key/value bytes tuple. 15 | message Pair { 16 | bytes key = 1; 17 | bytes value = 2; 18 | } 19 | -------------------------------------------------------------------------------- /proto/memiavl/wal.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package memiavl; 3 | 4 | option go_package = "github.com/crypto-org-chain/cronos/memiavl"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "memiavl/changeset.proto"; 8 | import "memiavl/commit_info.proto"; 9 | 10 | // NamedChangeSet combine a tree name with the changeset 11 | message NamedChangeSet { 12 | ChangeSet changeset = 1 [(gogoproto.nullable) = false]; 13 | string name = 2; 14 | } 15 | 16 | // TreeNameUpgrade defines upgrade of tree names: 17 | // - New tree: { name: "tree" } 18 | // - Delete tree: { name: "tree", delete: true } 19 | // - Rename tree: { name: "new-tree", rename_from: "old-tree" } 20 | message TreeNameUpgrade { 21 | string name = 1; 22 | string rename_from = 2; 23 | bool delete = 3; 24 | } 25 | 26 | // WALEntry is a single Write-Ahead-Log entry 27 | message WALEntry { 28 | repeated NamedChangeSet changesets = 1; 29 | repeated TreeNameUpgrade upgrades = 2; 30 | } 31 | 32 | // MultiTreeMetadata stores the metadata for MultiTree 33 | message MultiTreeMetadata { 34 | CommitInfo commit_info = 1; 35 | int64 initial_version = 2; 36 | } 37 | -------------------------------------------------------------------------------- /scripts/.env: -------------------------------------------------------------------------------- 1 | export PASSWORD='123456' 2 | export VALIDATOR1_MNEMONIC="visit craft resemble online window solution west chuckle music diesel vital settle comic tribe project blame bulb armed flower region sausage mercy arrive release" 3 | export VALIDATOR2_MNEMONIC="direct travel shrug hand twice agent sail sell jump phone velvet pilot mango charge usual multiply orient garment bleak virtual action mention panda vast" 4 | export VALIDATOR3_MNEMONIC="panda much deny whale fun iron liquid rookie rice ridge artist slush legend salad adapt public all thunder galaxy give ostrich endless prosper good" 5 | export COMMUNITY_MNEMONIC="notable error gospel wave pair ugly measure elite toddler cost various fly make eye ketchup despair slab throw tribe swarm word fruit into inmate" 6 | export SIGNER1_MNEMONIC="shed crumble dismiss loyal latin million oblige gesture shrug still oxygen custom remove ribbon disorder palace addict again blanket sad flock consider obey popular" 7 | export SIGNER2_MNEMONIC="night renew tonight dinner shaft scheme domain oppose echo summer broccoli agent face guitar surface belt veteran siren poem alcohol menu custom crunch index" 8 | export SIGNER3_MNEMONIC="step endless survey brand topic warrior merry boat metal throw tag recycle pitch animal drill jar hero library arm swift kitten proof acoustic chef" 9 | # same account as VALIDATOR1_MNEMONIC 10 | export CRONOS_ADMIN="crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp" 11 | export IBC_CRO_DENOM="ibc/6411AE2ADA1E73DB59DB151A8988F9B7D5E7E233D8414DB6817F8F1A01611F86" 12 | -------------------------------------------------------------------------------- /scripts/codesign_macos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | echo 'List signing identities' 5 | security find-identity -v -p codesigning 6 | 7 | TMPD=$(mktemp -d) 8 | tar xfz $1 -C $TMPD 9 | 10 | echo "Codesign" 11 | find $TMPD -type f \( -name "*.dylib" -or -name cronosd \) | xargs -I{} codesign --force --options runtime -v -s "$MAC_CODE_API_DEVELOPER_ID" {} 12 | 13 | echo "Archive" 14 | WORKDIR=$PWD 15 | cd $TMPD 16 | # notarytool only accepts zip format 17 | zip -r "$WORKDIR/signed.zip" . 18 | cd $WORKDIR 19 | tar cfz signed.tar.gz -C $TMPD . 20 | 21 | echo "Notarize" 22 | echo "$MAC_CODE_API_KEY" > /tmp/api_key.p8 23 | UUID=$(xcrun notarytool submit signed.zip -f json --key /tmp/api_key.p8 --key-id "$MAC_CODE_API_KEY_ID" --issuer "$MAC_CODE_API_ISSUER_ID" --wait | jq -r ".id") 24 | echo "UUID: $UUID" 25 | xcrun notarytool log "$UUID" --key /tmp/api_key.p8 --key-id "$MAC_CODE_API_KEY_ID" --issuer "$MAC_CODE_API_ISSUER_ID" 26 | 27 | echo "Cleanup" 28 | rm -r $TMPD 29 | rm /tmp/api_key.p8 30 | -------------------------------------------------------------------------------- /scripts/gen-bindings-contracts: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | solc08 --abi --bin x/cronos/events/bindings/src/CosmosTypes.sol -o build --overwrite 4 | solc08 --abi --bin x/cronos/events/bindings/src/Relayer.sol -o build --overwrite 5 | solc08 --abi --bin x/cronos/events/bindings/src/RelayerFunctions.sol -o build --overwrite 6 | solc08 --abi --bin x/cronos/events/bindings/src/Bank.sol -o build --overwrite 7 | solc08 --abi --bin x/cronos/events/bindings/src/ICA.sol -o build --overwrite 8 | solc08 --abi --bin x/cronos/events/bindings/src/ICACallback.sol -o build --overwrite 9 | 10 | 11 | abigen --pkg lib --abi build/CosmosTypes.abi --bin build/CosmosTypes.bin --out x/cronos/events/bindings/cosmos/lib/cosmos_types.abigen.go --type CosmosTypes 12 | abigen --pkg relayer --abi build/IRelayerModule.abi --bin build/IRelayerModule.bin --out x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_module.abigen.go --type RelayerModule 13 | abigen --pkg relayer --abi build/IRelayerFunctions.abi --bin build/IRelayerFunctions.bin --out x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_functions.abigen.go --type RelayerFunctions 14 | abigen --pkg bank --abi build/IBankModule.abi --bin build/IBankModule.bin --out x/cronos/events/bindings/cosmos/precompile/bank/i_bank_module.abigen.go --type BankModule 15 | abigen --pkg ica --abi build/IICAModule.abi --bin build/IICAModule.bin --out x/cronos/events/bindings/cosmos/precompile/ica/i_ica_module.abigen.go --type ICAModule 16 | abigen --pkg icacallback --abi build/IICACallback.abi --bin build/IICACallback.bin --out x/cronos/events/bindings/cosmos/precompile/icacallback/i_ica_callback.abigen.go --type ICACallback 17 | -------------------------------------------------------------------------------- /scripts/gen-cronos-contracts: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | make -C contracts 3 | cat contracts/out/dapp.sol.json | \ 4 | jq '.contracts."src/ModuleCRC20.sol".ModuleCRC20' | \ 5 | jq '{abi, bin: .evm.bytecode.object}' \ 6 | > x/cronos/types/contracts/ModuleCRC20.json 7 | cat contracts/out/dapp.sol.json | \ 8 | jq '.contracts."src/ModuleCRC21.sol".ModuleCRC21' | \ 9 | jq '{abi, bin: .evm.bytecode.object}' \ 10 | > x/cronos/types/contracts/ModuleCRC21.json 11 | cat contracts/out/dapp.sol.json | \ 12 | jq '.contracts."src/ModuleCRC20Proxy.sol".ModuleCRC20Proxy' | \ 13 | jq '{abi, bin: .evm.bytecode.object}' \ 14 | > x/cronos/types/contracts/ModuleCRC20Proxy.json 15 | cat contracts/out/dapp.sol.json | \ 16 | jq '.contracts."src/ModuleCRC20ProxyAuthority.sol".ModuleCRC20ProxyAuthority' | \ 17 | jq '{abi, bin: .evm.bytecode.object}' \ 18 | > x/cronos/types/contracts/ModuleCRC20ProxyAuthority.json 19 | -------------------------------------------------------------------------------- /scripts/geth-genesis.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "chainId": 777, 4 | "homesteadBlock": 0, 5 | "eip150Block": 0, 6 | "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", 7 | "eip155Block": 0, 8 | "eip158Block": 0, 9 | "byzantiumBlock": 0, 10 | "constantinopleBlock": 0, 11 | "petersburgBlock": 0, 12 | "istanbulBlock": 0, 13 | "muirGlacierBlock": 0, 14 | "berlinBlock": 0, 15 | "yoloV3Block": 0, 16 | "londonBlock": 0, 17 | "shanghaiTime": 0, 18 | "clique": { 19 | "period": 2, 20 | "epoch": 30000 21 | } 22 | }, 23 | "nonce": "0x0", 24 | "timestamp": "0x60ed6d23", 25 | "extraData": "0x000000000000000000000000000000000000000000000000000000000000000057f96e6b86cdefdb3d412547816a82e3e0ebf9d20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 26 | "gasLimit": "0x4db9760", 27 | "difficulty": "0x1", 28 | "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 29 | "coinbase": "0x0000000000000000000000000000000000000000", 30 | "alloc": { 31 | "57f96e6b86cdefdb3d412547816a82e3e0ebf9d2": { 32 | "balance": "0x21e19e0c9bab2400000" 33 | }, 34 | "378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec": { 35 | "balance": "0x21e19e0c9bab2400000" 36 | } 37 | }, 38 | "number": "0x0", 39 | "gasUsed": "0x0", 40 | "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 41 | "baseFeePerGas": "100000000000" 42 | } 43 | -------------------------------------------------------------------------------- /scripts/protoc-swagger-gen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | 5 | mkdir -p ./tmp-swagger-gen 6 | 7 | cd proto 8 | echo "Generate cronos swagger files" 9 | proto_dirs=$(find ./ -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) 10 | for dir in $proto_dirs; do 11 | # generate swagger files (filter query files) 12 | query_file=$(find "${dir}" -maxdepth 1 \( -name 'query.proto' -o -name 'service.proto' \)) 13 | if [[ ! -z "$query_file" ]]; then 14 | echo "$query_file" 15 | buf generate --template buf.gen.swagger.yaml "$query_file" 16 | fi 17 | done 18 | 19 | echo "Generate cosmos swagger files" 20 | 21 | proto_dir="../third_party/proto" 22 | proto_dirs=$(find "${proto_dir}/ethermint" "${proto_dir}/ibc" -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) 23 | for dir in $proto_dirs; do 24 | # generate swagger files (filter query files) 25 | query_file=$(find "${dir}" -maxdepth 1 \( -name 'query.proto' -o -name 'service.proto' \)) 26 | if [[ ! -z "$query_file" ]]; then 27 | echo "$query_file" 28 | buf generate --template buf.gen.swagger.yaml "$query_file" 29 | fi 30 | done 31 | 32 | buf generate --template buf.gen.swagger.yaml "buf.build/cosmos/cosmos-sdk:954f7b05f38440fc8250134b15adec47" 33 | 34 | cd .. 35 | 36 | echo "Combine swagger files" 37 | # combine swagger files 38 | # uses nodejs package `swagger-combine`. 39 | # all the individual swagger files need to be configured in `config.json` for merging 40 | swagger-combine ./client/docs/config.json -o ./client/docs/swagger-ui/swagger.yaml -f yaml --continueOnConflictingPaths true --includeDefinitions true 41 | 42 | # clean swagger files 43 | rm -rf ./tmp-swagger-gen 44 | -------------------------------------------------------------------------------- /scripts/protocgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | 5 | echo "Generating gogo proto code" 6 | cd proto 7 | proto_dirs=$(find . -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) 8 | for dir in $proto_dirs; do 9 | for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do 10 | if grep "option go_package" $file &> /dev/null ; then 11 | buf generate --template buf.gen.gogo.yaml $file 12 | fi 13 | done 14 | done 15 | 16 | cd .. 17 | 18 | # move proto files to the right places 19 | cp -r github.com/crypto-org-chain/cronos/v2/* ./ 20 | cp -r github.com/crypto-org-chain/cronos/memiavl/* ./memiavl/ 21 | rm -rf github.com 22 | 23 | # TODO uncomment go mod tidy after upgrading to ghcr.io/cosmos/proto-builder v0.12.0 24 | # go mod tidy 25 | 26 | 27 | -------------------------------------------------------------------------------- /scripts/run-integration-tests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | cd "$(dirname "$0")" 4 | 5 | # explicitly set a short TMPDIR to prevent path too long issue on macosx 6 | export TMPDIR=/tmp 7 | 8 | echo "build test contracts" 9 | cd ../integration_tests/contracts 10 | HUSKY_SKIP_INSTALL=1 npm install 11 | npm run typechain 12 | cd ../.. 13 | TESTS_TO_RUN="${TESTS_TO_RUN:-all}" 14 | if [[ "$TESTS_TO_RUN" == "all" ]]; then 15 | echo "run all tests" 16 | cmd="pytest -vv -s --session-timeout=6000 --timeout=6000" 17 | else 18 | echo "run tests matching $TESTS_TO_RUN" 19 | cmd="pytest -vv -s --session-timeout=1800 --timeout=1800 -m '$TESTS_TO_RUN'" 20 | fi 21 | nix-shell ./integration_tests/shell.nix --run "$cmd" 22 | -------------------------------------------------------------------------------- /scripts/start-cronos: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | CONFIG=$1 5 | if [ -z "$CONFIG" ]; then 6 | echo "No config file supplied" 7 | exit 1 8 | fi 9 | shift 10 | 11 | DOTENV=$1 12 | if [ -z "$DOTENV" ]; then 13 | echo "No dotenv file supplied" 14 | exit 1 15 | fi 16 | shift 17 | 18 | DATA=$1 19 | if [ -z "$DATA" ]; then 20 | echo "No data directory supplied" 21 | exit 1 22 | fi 23 | shift 24 | 25 | echo 'pystarport:' 26 | echo ' config: '$CONFIG 27 | echo ' dotenv: '$DOTENV 28 | echo ' data: '$DATA 29 | 30 | pystarport init --config $CONFIG --dotenv $DOTENV --data $DATA $@ 31 | supervisord -c $DATA/tasks.ini 32 | -------------------------------------------------------------------------------- /scripts/start-geth: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | CONFIG=$1 5 | if [ -z $CONFIG ]; then 6 | echo "No config file supplied" 7 | exit 1 8 | fi 9 | shift 10 | 11 | DATA=$1 12 | if [ -z $DATA ]; then 13 | echo "No data directory supplied" 14 | exit 1 15 | fi 16 | shift 17 | 18 | geth --datadir $DATA init $CONFIG 19 | pwdfile=$(mktemp /tmp/password.XXXXXX) 20 | tmpfile=$(mktemp /tmp/validator-key.XXXXXX) 21 | 22 | cat > $pwdfile << EOF 23 | $PASSWORD 24 | EOF 25 | 26 | # import validator key 27 | validator_key=$(python -c """ 28 | from eth_account import Account 29 | Account.enable_unaudited_hdwallet_features() 30 | print(Account.from_mnemonic('$VALIDATOR1_MNEMONIC').key.hex().replace('0x','')) 31 | """) 32 | 33 | cat > $tmpfile << EOF 34 | $validator_key 35 | EOF 36 | geth --datadir $DATA --password $pwdfile account import $tmpfile 37 | 38 | # import community key 39 | community_key=$(python -c """ 40 | from eth_account import Account 41 | Account.enable_unaudited_hdwallet_features() 42 | print(Account.from_mnemonic('$COMMUNITY_MNEMONIC').key.hex().replace('0x','')) 43 | """) 44 | 45 | cat > $tmpfile << EOF 46 | $community_key 47 | EOF 48 | geth --datadir $DATA --password $pwdfile account import $tmpfile 49 | 50 | rm $tmpfile 51 | 52 | # start up 53 | geth --networkid 777 --datadir $DATA --http --http.addr localhost --http.api 'personal,eth,net,web3,txpool,miner' \ 54 | -unlock '0x57f96e6b86cdefdb3d412547816a82e3e0ebf9d2' --password $pwdfile \ 55 | --mine --allow-insecure-unlock \ 56 | $@ 57 | 58 | rm $pwdfile 59 | -------------------------------------------------------------------------------- /scripts/test-cronos-contracts: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | make -C contracts test 3 | -------------------------------------------------------------------------------- /store/cachemulti/store.go: -------------------------------------------------------------------------------- 1 | package cachemulti 2 | 3 | import ( 4 | "io" 5 | 6 | "cosmossdk.io/store/cachemulti" 7 | "cosmossdk.io/store/types" 8 | ) 9 | 10 | var NoopCloser io.Closer = CloserFunc(func() error { return nil }) 11 | 12 | type CloserFunc func() error 13 | 14 | func (fn CloserFunc) Close() error { 15 | return fn() 16 | } 17 | 18 | // Store wraps sdk's cachemulti.Store to add io.Closer interface 19 | type Store struct { 20 | cachemulti.Store 21 | io.Closer 22 | } 23 | 24 | func NewStore( 25 | stores map[types.StoreKey]types.CacheWrapper, 26 | traceWriter io.Writer, traceContext types.TraceContext, 27 | closer io.Closer, 28 | ) Store { 29 | if closer == nil { 30 | closer = NoopCloser 31 | } 32 | store := cachemulti.NewStore(nil, stores, nil, traceWriter, traceContext) 33 | return Store{ 34 | Store: store, 35 | Closer: closer, 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /store/config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import "github.com/crypto-org-chain/cronos/memiavl" 4 | 5 | const DefaultCacheSize = 1000 6 | 7 | type MemIAVLConfig struct { 8 | // Enable defines if the memiavl should be enabled. 9 | Enable bool `mapstructure:"enable"` 10 | // ZeroCopy defines if the memiavl should return slices pointing to mmap-ed buffers directly (zero-copy), 11 | // the zero-copied slices must not be retained beyond current block's execution. 12 | // the sdk address cache will be disabled if zero-copy is enabled. 13 | ZeroCopy bool `mapstructure:"zero-copy"` 14 | // AsyncCommitBuffer defines the size of asynchronous commit queue, this greatly improve block catching-up 15 | // performance, -1 means synchronous commit. 16 | AsyncCommitBuffer int `mapstructure:"async-commit-buffer"` 17 | // SnapshotKeepRecent defines what many old snapshots (excluding the latest one) to keep after new snapshots are 18 | // taken, defaults to 1 to make sure ibc relayers work. 19 | SnapshotKeepRecent uint32 `mapstructure:"snapshot-keep-recent"` 20 | // SnapshotInterval defines the block interval the memiavl snapshot is taken, default to 1000. 21 | SnapshotInterval uint32 `mapstructure:"snapshot-interval"` 22 | // CacheSize defines the size of the cache for each memiavl store. 23 | CacheSize int `mapstructure:"cache-size"` 24 | } 25 | 26 | func DefaultMemIAVLConfig() MemIAVLConfig { 27 | return MemIAVLConfig{ 28 | CacheSize: DefaultCacheSize, 29 | SnapshotInterval: memiavl.DefaultSnapshotInterval, 30 | SnapshotKeepRecent: 1, 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /store/config/toml.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | // DefaultConfigTemplate defines the configuration template for the memiavl configuration 4 | const DefaultConfigTemplate = ` 5 | ############################################################################### 6 | ### MemIAVL Configuration ### 7 | ############################################################################### 8 | 9 | [memiavl] 10 | 11 | # Enable defines if the memiavl should be enabled. 12 | enable = {{ .MemIAVL.Enable }} 13 | 14 | # ZeroCopy defines if the memiavl should return slices pointing to mmap-ed buffers directly (zero-copy), 15 | # the zero-copied slices must not be retained beyond current block's execution. 16 | # the sdk address cache will be disabled if zero-copy is enabled. 17 | zero-copy = {{ .MemIAVL.ZeroCopy }} 18 | 19 | # AsyncCommitBuffer defines the size of asynchronous commit queue, this greatly improve block catching-up 20 | # performance, -1 means synchronous commit. 21 | async-commit-buffer = {{ .MemIAVL.AsyncCommitBuffer }} 22 | 23 | # SnapshotKeepRecent defines what many old snapshots (excluding the latest one) to keep after new snapshots are 24 | # taken, defaults to 1 to make sure ibc relayers work. 25 | snapshot-keep-recent = {{ .MemIAVL.SnapshotKeepRecent }} 26 | 27 | # SnapshotInterval defines the block interval the memiavl snapshot is taken, default to 1000. 28 | snapshot-interval = {{ .MemIAVL.SnapshotInterval }} 29 | 30 | # CacheSize defines the size of the cache for each memiavl store, default to 1000. 31 | cache-size = {{ .MemIAVL.CacheSize }} 32 | ` 33 | -------------------------------------------------------------------------------- /store/rootmulti/objstore.go: -------------------------------------------------------------------------------- 1 | //go:build objstore 2 | // +build objstore 3 | 4 | package rootmulti 5 | 6 | import ( 7 | "fmt" 8 | 9 | "cosmossdk.io/store/transient" 10 | "cosmossdk.io/store/types" 11 | "github.com/crypto-org-chain/cronos/memiavl" 12 | ) 13 | 14 | // Implements interface MultiStore 15 | func (rs *Store) GetObjKVStore(key types.StoreKey) types.ObjKVStore { 16 | s, ok := rs.stores[key].(types.ObjKVStore) 17 | if !ok { 18 | panic(fmt.Sprintf("store with key %v is not ObjKVStore", key)) 19 | } 20 | return s 21 | } 22 | 23 | func (rs *Store) loadExtraStore(db *memiavl.DB, key types.StoreKey, params storeParams) (types.CommitStore, error) { 24 | if params.typ == types.StoreTypeObject { 25 | if _, ok := key.(*types.ObjectStoreKey); !ok { 26 | return nil, fmt.Errorf("unexpected key type for a ObjectStoreKey; got: %s, %T", key.String(), key) 27 | } 28 | 29 | return transient.NewObjStore(), nil 30 | } 31 | 32 | panic(fmt.Sprintf("unrecognized store type %v", params.typ)) 33 | } 34 | -------------------------------------------------------------------------------- /store/rootmulti/objstore_placeholder.go: -------------------------------------------------------------------------------- 1 | //go:build !objstore 2 | // +build !objstore 3 | 4 | package rootmulti 5 | 6 | import ( 7 | "fmt" 8 | 9 | "cosmossdk.io/store/types" 10 | "github.com/crypto-org-chain/cronos/memiavl" 11 | ) 12 | 13 | func (rs *Store) loadExtraStore(db *memiavl.DB, key types.StoreKey, params storeParams) (types.CommitStore, error) { 14 | panic(fmt.Sprintf("unrecognized store type %v", params.typ)) 15 | } 16 | -------------------------------------------------------------------------------- /store/rootmulti/store_test.go: -------------------------------------------------------------------------------- 1 | package rootmulti 2 | 3 | import ( 4 | "testing" 5 | 6 | "cosmossdk.io/log" 7 | "cosmossdk.io/store/types" 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func TestLastCommitID(t *testing.T) { 12 | store := NewStore(t.TempDir(), log.NewNopLogger(), false, false) 13 | require.Equal(t, types.CommitID{}, store.LastCommitID()) 14 | } 15 | -------------------------------------------------------------------------------- /testground/benchmark/.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 88 3 | extend-ignore = E203 4 | exclude = __pycache__ 5 | -------------------------------------------------------------------------------- /testground/benchmark/benchmark/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crypto-org-chain/cronos/4815e61174f2917df82316ab53e0d142127d820c/testground/benchmark/benchmark/__init__.py -------------------------------------------------------------------------------- /testground/benchmark/benchmark/echo.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import threading 3 | 4 | 5 | async def handle_echo(reader: asyncio.StreamReader, writer: asyncio.StreamWriter): 6 | data = await reader.read(1024) 7 | if data: 8 | writer.write(data) 9 | await writer.drain() 10 | writer.close() 11 | await writer.wait_closed() 12 | 13 | 14 | async def echo_server(port: int): 15 | server = await asyncio.start_server(handle_echo, "0.0.0.0", port) 16 | async with server: 17 | await server.serve_forever() 18 | 19 | 20 | def run_echo_server(port: int): 21 | """ 22 | run async echo server in a thread. 23 | """ 24 | threading.Thread(target=asyncio.run, args=(echo_server(port),), daemon=True).start() 25 | -------------------------------------------------------------------------------- /testground/benchmark/benchmark/test_utils.py: -------------------------------------------------------------------------------- 1 | from .utils import merge_genesis 2 | 3 | 4 | def test_merge_genesis(): 5 | g = merge_genesis( 6 | {"app_state": {"auth": {"accounts": [1]}}}, 7 | {"app_state": {"auth": {"accounts": [2]}}}, 8 | ) 9 | assert g["app_state"]["auth"]["accounts"] == [1, 2] 10 | -------------------------------------------------------------------------------- /testground/benchmark/benchmark/topology.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | from .types import PeerPacket 4 | 5 | 6 | def connect_all(peer, peers: List[PeerPacket]) -> str: 7 | """ 8 | connect the peer to all the other peers 9 | 10 | returns the value for persistent-peers config 11 | """ 12 | return ",".join(other.peer_id for other in peers if other.peer_id != peer.peer_id) 13 | -------------------------------------------------------------------------------- /testground/benchmark/benchmark/types.py: -------------------------------------------------------------------------------- 1 | from typing import List, Optional 2 | 3 | from pydantic import BaseModel 4 | 5 | from .utils import bech32_to_eth 6 | 7 | 8 | class Balance(BaseModel): 9 | amount: str 10 | denom: str 11 | 12 | def __str__(self): 13 | return f"{self.amount}{self.denom}" 14 | 15 | 16 | class GenesisAccount(BaseModel): 17 | address: str 18 | coins: List[Balance] 19 | 20 | @property 21 | def eth_address(self) -> str: 22 | return bech32_to_eth(self.address) 23 | 24 | 25 | class PeerPacket(BaseModel): 26 | ip: str 27 | node_id: str 28 | peer_id: str 29 | accounts: List[GenesisAccount] 30 | gentx: Optional[dict] = None 31 | -------------------------------------------------------------------------------- /testground/benchmark/compositions/docker-compose.jsonnet: -------------------------------------------------------------------------------- 1 | std.manifestYamlDoc({ 2 | services: { 3 | ['testplan-' + i]: { 4 | image: 'cronos-testground:latest', 5 | command: 'stateless-testcase run', 6 | container_name: 'testplan-' + i, 7 | volumes: [ 8 | std.extVar('outputs') + ':/outputs', 9 | ], 10 | environment: { 11 | JOB_COMPLETION_INDEX: i, 12 | }, 13 | } 14 | for i in std.range(0, std.extVar('nodes') - 1) 15 | }, 16 | }) 17 | -------------------------------------------------------------------------------- /testground/benchmark/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 4 | flake-utils.url = "github:numtide/flake-utils"; 5 | poetry2nix = { 6 | url = "github:nix-community/poetry2nix"; 7 | inputs.nixpkgs.follows = "nixpkgs"; 8 | inputs.flake-utils.follows = "flake-utils"; 9 | }; 10 | }; 11 | 12 | outputs = 13 | { 14 | self, 15 | nixpkgs, 16 | flake-utils, 17 | poetry2nix, 18 | }: 19 | flake-utils.lib.eachDefaultSystem ( 20 | system: 21 | let 22 | pkgs = import nixpkgs { 23 | inherit system; 24 | overlays = [ 25 | poetry2nix.overlays.default 26 | (import ./overlay.nix) 27 | ]; 28 | config = { }; 29 | }; 30 | in 31 | rec { 32 | packages.default = pkgs.benchmark-testcase; 33 | apps = { 34 | default = { 35 | type = "app"; 36 | program = "${pkgs.benchmark-testcase}/bin/stateless-testcase"; 37 | }; 38 | stateless-testcase = { 39 | type = "app"; 40 | program = "${pkgs.benchmark-testcase}/bin/stateless-testcase"; 41 | }; 42 | testnet = { 43 | type = "app"; 44 | program = "${pkgs.benchmark-testcase}/bin/testnet"; 45 | }; 46 | }; 47 | devShells.default = pkgs.mkShell { buildInputs = [ pkgs.benchmark-testcase-env ]; }; 48 | legacyPackages = pkgs; 49 | } 50 | ); 51 | } 52 | -------------------------------------------------------------------------------- /testground/benchmark/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "benchmark" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["huangyi "] 6 | 7 | [tool.poetry.dependencies] 8 | python = "^3.11" 9 | influxdb-client = "^1" 10 | websocket-client = "^1" 11 | netifaces = "^0" 12 | pydantic = "^2" 13 | tomlkit = "^0" 14 | web3 = "^6" 15 | hexbytes = "^0" 16 | bech32 = "^1" 17 | requests = "^2.32" 18 | click = "^8.1.7" 19 | ujson = "^5.10.0" 20 | jsonmerge = "^1.9.2" 21 | 22 | backoff = "^2.2.1" 23 | cprotobuf = "^0.1.11" 24 | [tool.poetry.group.dev.dependencies] 25 | pytest = "^8.2" 26 | pytest-github-actions-annotate-failures = "^0.2.0" 27 | black = "^24.10.0" 28 | flake8 = "^7.1.1" 29 | flake8-black = "^0.3.6" 30 | flake8-isort = "^6.1.1" 31 | 32 | [build-system] 33 | requires = ["poetry-core"] 34 | build-backend = "poetry.core.masonry.api" 35 | 36 | [tool.poetry.scripts] 37 | stateless-testcase = "benchmark.stateless:cli" 38 | testnet = "benchmark.testnet:cli" 39 | 40 | [tool.black] 41 | line-length = 88 42 | 43 | [tool.isort] 44 | profile = "black" 45 | -------------------------------------------------------------------------------- /testutil/simapp/simapp.go: -------------------------------------------------------------------------------- 1 | package simapp 2 | 3 | import ( 4 | "time" 5 | 6 | "cosmossdk.io/log" 7 | abci "github.com/cometbft/cometbft/abci/types" 8 | tmproto "github.com/cometbft/cometbft/proto/tendermint/types" 9 | tmtypes "github.com/cometbft/cometbft/types" 10 | tmdb "github.com/cosmos/cosmos-db" 11 | simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" 12 | 13 | "github.com/crypto-org-chain/cronos/v2/app" 14 | ) 15 | 16 | // New creates application instance with in-memory database and disabled logging. 17 | func New(dir string) *app.App { 18 | db := tmdb.NewMemDB() 19 | logger := log.NewNopLogger() 20 | 21 | a := app.New(logger, db, nil, true, simtestutil.EmptyAppOptions{}) 22 | // InitChain updates deliverState which is required when app.NewContext is called 23 | a.InitChain(&abci.RequestInitChain{ 24 | ConsensusParams: defaultConsensusParams, 25 | AppStateBytes: []byte("{}"), 26 | }) 27 | return a 28 | } 29 | 30 | var defaultConsensusParams = &tmproto.ConsensusParams{ 31 | Block: &tmproto.BlockParams{ 32 | MaxBytes: 200000, 33 | MaxGas: 2000000, 34 | }, 35 | Evidence: &tmproto.EvidenceParams{ 36 | MaxAgeNumBlocks: 302400, 37 | MaxAgeDuration: 504 * time.Hour, // 3 weeks is the max duration 38 | MaxBytes: 10000, 39 | }, 40 | Validator: &tmproto.ValidatorParams{ 41 | PubKeyTypes: []string{ 42 | tmtypes.ABCIPubKeyTypeEd25519, 43 | }, 44 | }, 45 | } 46 | -------------------------------------------------------------------------------- /third_party/proto/buf.lock: -------------------------------------------------------------------------------- 1 | # Generated by buf. DO NOT EDIT. 2 | version: v1 3 | deps: 4 | - remote: buf.build 5 | owner: cosmos 6 | repository: cosmos-proto 7 | commit: 1935555c206d4afb9e94615dfd0fad31 8 | digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377 9 | - remote: buf.build 10 | owner: cosmos 11 | repository: cosmos-sdk 12 | commit: 954f7b05f38440fc8250134b15adec47 13 | digest: shake256:2ab4404fd04a7d1d52df0e2d0f2d477a3d83ffd88d876957bf3fedfd702c8e52833d65b3ce1d89a3c5adf2aab512616b0e4f51d8463f07eda9a8a3317ee3ac54 14 | - remote: buf.build 15 | owner: cosmos 16 | repository: gogo-proto 17 | commit: 5e5b9fdd01804356895f8f79a6f1ddc1 18 | digest: shake256:0b85da49e2e5f9ebc4806eae058e2f56096ff3b1c59d1fb7c190413dd15f45dd456f0b69ced9059341c80795d2b6c943de15b120a9e0308b499e43e4b5fc2952 19 | - remote: buf.build 20 | owner: cosmos 21 | repository: ics23 22 | commit: 55085f7c710a45f58fa09947208eb70b 23 | digest: shake256:9bf0bc495b5a11c88d163d39ef521bc4b00bc1374a05758c91d82821bdc61f09e8c2c51dda8452529bf80137f34d852561eacbe9550a59015d51cecb0dacb628 24 | - remote: buf.build 25 | owner: googleapis 26 | repository: googleapis 27 | commit: cc916c31859748a68fd229a3c8d7a2e8 28 | digest: shake256:469b049d0eb04203d5272062636c078decefc96fec69739159c25d85349c50c34c7706918a8b216c5c27f76939df48452148cff8c5c3ae77fa6ba5c25c1b8bf8 29 | -------------------------------------------------------------------------------- /third_party/proto/buf.yaml: -------------------------------------------------------------------------------- 1 | # Generated by "buf config migrate-v1beta1". Edit as necessary, and 2 | # remove this comment when you're finished. 3 | # 4 | # This module represents the "proto" root found in 5 | # the previous configuration. 6 | version: v1 7 | name: buf.build/crypto-org-chain/cronos-thirdparty 8 | deps: 9 | - buf.build/cosmos/cosmos-sdk:954f7b05f38440fc8250134b15adec47 10 | - buf.build/cosmos/cosmos-proto:1935555c206d4afb9e94615dfd0fad31 11 | - buf.build/cosmos/gogo-proto:5e5b9fdd01804356895f8f79a6f1ddc1 12 | - buf.build/googleapis/googleapis:cc916c31859748a68fd229a3c8d7a2e8 13 | - buf.build/cosmos/ics23:b1abd8678aab07165efd453c96796a179eb3131f 14 | breaking: 15 | use: 16 | - FILE 17 | lint: 18 | use: 19 | - DEFAULT 20 | - COMMENTS 21 | - FILE_LOWER_SNAKE_CASE 22 | except: 23 | - UNARY_RPC 24 | - COMMENT_FIELD 25 | - SERVICE_SUFFIX 26 | - PACKAGE_VERSION_SUFFIX 27 | - RPC_REQUEST_STANDARD_NAME 28 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/crypto/v1/ethsecp256k1/keys.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.crypto.v1.ethsecp256k1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/evmos/ethermint/crypto/ethsecp256k1"; 7 | 8 | // PubKey defines a type alias for an ecdsa.PublicKey that implements 9 | // Tendermint's PubKey interface. It represents the 33-byte compressed public 10 | // key format. 11 | message PubKey { 12 | option (gogoproto.goproto_stringer) = false; 13 | 14 | // key is the public key in byte form 15 | bytes key = 1; 16 | } 17 | 18 | // PrivKey defines a type alias for an ecdsa.PrivateKey that implements 19 | // Tendermint's PrivateKey interface. 20 | message PrivKey { 21 | // key is the private key in byte form 22 | bytes key = 1; 23 | } 24 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/evm/v1/access_tuple.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.evm.v1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/evmos/ethermint/x/evm/types"; 7 | 8 | // AccessTuple is the element type of an access list. 9 | message AccessTuple { 10 | option (gogoproto.goproto_getters) = false; 11 | 12 | // address is a hex formatted ethereum address 13 | string address = 1; 14 | // storage_keys are hex formatted hashes of the storage keys 15 | repeated string storage_keys = 2 [(gogoproto.jsontag) = "storageKeys"]; 16 | } 17 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/evm/v1/events.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.evm.v1; 3 | 4 | option go_package = "github.com/evmos/ethermint/x/evm/types"; 5 | 6 | // EventEthereumTx defines the event for an Ethereum transaction 7 | message EventEthereumTx { 8 | // amount 9 | string amount = 1; 10 | // eth_hash is the Ethereum hash of the transaction 11 | string eth_hash = 2; 12 | // index of the transaction in the block 13 | string index = 3; 14 | // gas_used is the amount of gas used by the transaction 15 | string gas_used = 4; 16 | // hash is the Tendermint hash of the transaction 17 | string hash = 5; 18 | // recipient of the transaction 19 | string recipient = 6; 20 | // eth_tx_failed contains a VM error should it occur 21 | string eth_tx_failed = 7; 22 | } 23 | 24 | // EventTxLog defines the event for an Ethereum transaction log 25 | message EventTxLog { 26 | // tx_logs is an array of transaction logs 27 | repeated string tx_logs = 1; 28 | } 29 | 30 | // EventMessage 31 | message EventMessage { 32 | // module which emits the event 33 | string module = 1; 34 | // sender of the message 35 | string sender = 2; 36 | // tx_type is the type of the message 37 | string tx_type = 3; 38 | } 39 | 40 | // EventBlockBloom defines an Ethereum block bloom filter event 41 | message EventBlockBloom { 42 | // bloom is the bloom filter of the block 43 | string bloom = 1; 44 | } 45 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/evm/v1/genesis.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.evm.v1; 3 | 4 | import "ethermint/evm/v1/params.proto"; 5 | import "ethermint/evm/v1/state.proto"; 6 | import "gogoproto/gogo.proto"; 7 | 8 | option go_package = "github.com/evmos/ethermint/x/evm/types"; 9 | 10 | // GenesisState defines the evm module's genesis state. 11 | message GenesisState { 12 | // accounts is an array containing the ethereum genesis accounts. 13 | repeated GenesisAccount accounts = 1 [(gogoproto.nullable) = false]; 14 | // params defines all the parameters of the module. 15 | Params params = 2 [(gogoproto.nullable) = false]; 16 | } 17 | 18 | // GenesisAccount defines an account to be initialized in the genesis state. 19 | // Its main difference between with Geth's GenesisAccount is that it uses a 20 | // custom storage type and that it doesn't contain the private key field. 21 | message GenesisAccount { 22 | // address defines an ethereum hex formated address of an account 23 | string address = 1; 24 | // code defines the hex bytes of the account code. 25 | string code = 2; 26 | // storage defines the set of state key values for the account. 27 | repeated State storage = 3 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "Storage"]; 28 | } 29 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/evm/v1/log.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.evm.v1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/evmos/ethermint/x/evm/types"; 7 | 8 | // Log represents an protobuf compatible Ethereum Log that defines a contract 9 | // log event. These events are generated by the LOG opcode and stored/indexed by 10 | // the node. 11 | // 12 | // NOTE: address, topics and data are consensus fields. The rest of the fields 13 | // are derived, i.e. filled in by the nodes, but not secured by consensus. 14 | message Log { 15 | // address of the contract that generated the event 16 | string address = 1; 17 | // topics is a list of topics provided by the contract. 18 | repeated string topics = 2; 19 | // data which is supplied by the contract, usually ABI-encoded 20 | bytes data = 3; 21 | 22 | // block_number of the block in which the transaction was included 23 | uint64 block_number = 4 [(gogoproto.jsontag) = "blockNumber"]; 24 | // tx_hash is the transaction hash 25 | string tx_hash = 5 [(gogoproto.jsontag) = "transactionHash"]; 26 | // tx_index of the transaction in the block 27 | uint64 tx_index = 6 [(gogoproto.jsontag) = "transactionIndex"]; 28 | // block_hash of the block in which the transaction was included 29 | string block_hash = 7 [(gogoproto.jsontag) = "blockHash"]; 30 | // index of the log in the block 31 | uint64 index = 8 [(gogoproto.jsontag) = "logIndex"]; 32 | 33 | // removed is true if this log was reverted due to a chain 34 | // reorganisation. You must pay attention to this field if you receive logs 35 | // through a filter query. 36 | bool removed = 9; 37 | } -------------------------------------------------------------------------------- /third_party/proto/ethermint/evm/v1/params.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.evm.v1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "ethermint/evm/v1/chain_config.proto"; 6 | 7 | option go_package = "github.com/evmos/ethermint/x/evm/types"; 8 | 9 | // Params defines the EVM module parameters 10 | message Params { 11 | // evm_denom represents the token denomination used to run the EVM state 12 | // transitions. 13 | string evm_denom = 1 [(gogoproto.moretags) = "yaml:\"evm_denom\""]; 14 | // enable_create toggles state transitions that use the vm.Create function 15 | bool enable_create = 2 [(gogoproto.moretags) = "yaml:\"enable_create\""]; 16 | // enable_call toggles state transitions that use the vm.Call function 17 | bool enable_call = 3 [(gogoproto.moretags) = "yaml:\"enable_call\""]; 18 | // extra_eips defines the additional EIPs for the vm.Config 19 | repeated int64 extra_eips = 4 [(gogoproto.customname) = "ExtraEIPs", (gogoproto.moretags) = "yaml:\"extra_eips\""]; 20 | // chain_config defines the EVM chain configuration parameters 21 | ChainConfig chain_config = 5 [(gogoproto.nullable) = false]; 22 | // allow_unprotected_txs defines if replay-protected (i.e non EIP155 23 | // signed) transactions can be executed on the state machine. 24 | bool allow_unprotected_txs = 6; 25 | // header_hash_num is the number of header hash to persist. 26 | uint64 header_hash_num = 7; 27 | } -------------------------------------------------------------------------------- /third_party/proto/ethermint/evm/v1/params_v0.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.evm.v1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "ethermint/evm/v1/chain_config_v0.proto"; 6 | 7 | option go_package = "github.com/evmos/ethermint/x/evm/types"; 8 | 9 | // V0Params defines the EVM module parameters 10 | message V0Params { 11 | // evm_denom represents the token denomination used to run the EVM state 12 | // transitions. 13 | string evm_denom = 1 [(gogoproto.moretags) = "yaml:\"evm_denom\""]; 14 | // enable_create toggles state transitions that use the vm.Create function 15 | bool enable_create = 2 [(gogoproto.moretags) = "yaml:\"enable_create\""]; 16 | // enable_call toggles state transitions that use the vm.Call function 17 | bool enable_call = 3 [(gogoproto.moretags) = "yaml:\"enable_call\""]; 18 | // extra_eips defines the additional EIPs for the vm.Config 19 | repeated int64 extra_eips = 4 [(gogoproto.customname) = "ExtraEIPs", (gogoproto.moretags) = "yaml:\"extra_eips\""]; 20 | // chain_config defines the EVM chain configuration parameters 21 | V0ChainConfig chain_config = 5 [(gogoproto.nullable) = false]; 22 | // allow_unprotected_txs defines if replay-protected (i.e non EIP155 23 | // signed) transactions can be executed on the state machine. 24 | bool allow_unprotected_txs = 6; 25 | } 26 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/evm/v1/params_v4.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.evm.v1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "ethermint/evm/v1/chain_config_v0.proto"; 6 | 7 | option go_package = "github.com/evmos/ethermint/x/evm/types"; 8 | 9 | // V4Params defines the EVM module parameters 10 | message V4Params { 11 | // evm_denom represents the token denomination used to run the EVM state 12 | // transitions. 13 | string evm_denom = 1 [(gogoproto.moretags) = "yaml:\"evm_denom\""]; 14 | // enable_create toggles state transitions that use the vm.Create function 15 | bool enable_create = 2 [(gogoproto.moretags) = "yaml:\"enable_create\""]; 16 | // enable_call toggles state transitions that use the vm.Call function 17 | bool enable_call = 3 [(gogoproto.moretags) = "yaml:\"enable_call\""]; 18 | // extra_eips defines the additional EIPs for the vm.Config 19 | ExtraEIPs extra_eips = 4 [(gogoproto.customname) = "ExtraEIPs", (gogoproto.nullable) = false]; 20 | // chain_config defines the EVM chain configuration parameters 21 | V0ChainConfig chain_config = 5 [(gogoproto.nullable) = false]; 22 | // allow_unprotected_txs defines if replay-protected (i.e non EIP155 23 | // signed) transactions can be executed on the state machine. 24 | bool allow_unprotected_txs = 6; 25 | } 26 | 27 | // ExtraEIPs represents extra EIPs for the vm.Config 28 | message ExtraEIPs { 29 | // eips defines the additional EIPs for the vm.Config 30 | repeated int64 eips = 1 [(gogoproto.customname) = "EIPs", (gogoproto.moretags) = "yaml:\"eips\""]; 31 | } -------------------------------------------------------------------------------- /third_party/proto/ethermint/evm/v1/state.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.evm.v1; 3 | 4 | option go_package = "github.com/evmos/ethermint/x/evm/types"; 5 | 6 | // State represents a single Storage key value pair item. 7 | message State { 8 | // key is the stored key 9 | string key = 1; 10 | // value is the stored value for the given key 11 | string value = 2; 12 | } -------------------------------------------------------------------------------- /third_party/proto/ethermint/evm/v1/transaction_logs.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.evm.v1; 3 | 4 | import "ethermint/evm/v1/log.proto"; 5 | 6 | option go_package = "github.com/evmos/ethermint/x/evm/types"; 7 | 8 | // TransactionLogs define the logs generated from a transaction execution 9 | // with a given hash. It it used for import/export data as transactions are not 10 | // persisted on blockchain state after an upgrade. 11 | message TransactionLogs { 12 | // hash of the transaction 13 | string hash = 1; 14 | // logs is an array of Logs for the given transaction hash 15 | repeated Log logs = 2; 16 | } 17 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/evm/v1/tx_result.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.evm.v1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "ethermint/evm/v1/transaction_logs.proto"; 6 | 7 | option go_package = "github.com/evmos/ethermint/x/evm/types"; 8 | 9 | // TxResult stores results of Tx execution. 10 | message TxResult { 11 | option (gogoproto.goproto_getters) = false; 12 | 13 | // contract_address contains the ethereum address of the created contract (if 14 | // any). If the state transition is an evm.Call, the contract address will be 15 | // empty. 16 | string contract_address = 1 [(gogoproto.moretags) = "yaml:\"contract_address\""]; 17 | // bloom represents the bloom filter bytes 18 | bytes bloom = 2; 19 | // tx_logs contains the transaction hash and the proto-compatible ethereum 20 | // logs. 21 | TransactionLogs tx_logs = 3 [(gogoproto.moretags) = "yaml:\"tx_logs\"", (gogoproto.nullable) = false]; 22 | // ret defines the bytes from the execution. 23 | bytes ret = 4; 24 | // reverted flag is set to true when the call has been reverted 25 | bool reverted = 5; 26 | // gas_used notes the amount of gas consumed while execution 27 | uint64 gas_used = 6; 28 | } 29 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/feemarket/v1/events.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.feemarket.v1; 3 | 4 | option go_package = "github.com/evmos/ethermint/x/feemarket/types"; 5 | 6 | // EventFeeMarket is the event type for the fee market module 7 | message EventFeeMarket { 8 | // base_fee for EIP-1559 blocks 9 | string base_fee = 1; 10 | } 11 | 12 | // EventBlockGas defines an Ethereum block gas event 13 | message EventBlockGas { 14 | // height of the block 15 | string height = 1; 16 | // amount of gas wanted by the block 17 | string amount = 2; 18 | } 19 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/feemarket/v1/feemarket.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.feemarket.v1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/evmos/ethermint/x/feemarket/types"; 7 | 8 | // Params defines the EVM module parameters 9 | message Params { 10 | // no_base_fee forces the EIP-1559 base fee to 0 (needed for 0 price calls) 11 | bool no_base_fee = 1; 12 | // base_fee_change_denominator bounds the amount the base fee can change 13 | // between blocks. 14 | uint32 base_fee_change_denominator = 2; 15 | // elasticity_multiplier bounds the maximum gas limit an EIP-1559 block may 16 | // have. 17 | uint32 elasticity_multiplier = 3; 18 | // DEPRECATED: initial base fee for EIP-1559 blocks. 19 | reserved 4; 20 | reserved "initial_base_fee"; 21 | // enable_height defines at which block height the base fee calculation is enabled. 22 | int64 enable_height = 5; 23 | // base_fee for EIP-1559 blocks. 24 | string base_fee = 6 [(gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false]; 25 | // min_gas_price defines the minimum gas price value for cosmos and eth transactions 26 | string min_gas_price = 7 27 | [(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; 28 | // min_gas_multiplier bounds the minimum gas used to be charged 29 | // to senders based on gas limit 30 | string min_gas_multiplier = 8 31 | [(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false]; 32 | } 33 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/feemarket/v1/genesis.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.feemarket.v1; 3 | 4 | import "ethermint/feemarket/v1/feemarket.proto"; 5 | import "gogoproto/gogo.proto"; 6 | 7 | option go_package = "github.com/evmos/ethermint/x/feemarket/types"; 8 | 9 | // GenesisState defines the feemarket module's genesis state. 10 | message GenesisState { 11 | // params defines all the parameters of the feemarket module. 12 | Params params = 1 [(gogoproto.nullable) = false]; 13 | // DEPRECATED: base fee is the exported value from previous software version. 14 | // Zero by default. 15 | reserved 2; 16 | reserved "base_fee"; 17 | // block_gas is the amount of gas wanted on the last block before the upgrade. 18 | // Zero by default. 19 | uint64 block_gas = 3; 20 | } -------------------------------------------------------------------------------- /third_party/proto/ethermint/feemarket/v1/tx.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.feemarket.v1; 3 | 4 | import "cosmos/msg/v1/msg.proto"; 5 | import "cosmos_proto/cosmos.proto"; 6 | import "ethermint/feemarket/v1/feemarket.proto"; 7 | import "gogoproto/gogo.proto"; 8 | 9 | option go_package = "github.com/evmos/ethermint/x/feemarket/types"; 10 | 11 | // Msg defines the erc20 Msg service. 12 | service Msg { 13 | option (cosmos.msg.v1.service) = true; 14 | // UpdateParams defined a governance operation for updating the x/feemarket module parameters. 15 | // The authority is hard-coded to the Cosmos SDK x/gov module account 16 | rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); 17 | } 18 | 19 | // MsgUpdateParams defines a Msg for updating the x/feemarket module parameters. 20 | message MsgUpdateParams { 21 | option (cosmos.msg.v1.signer) = "authority"; 22 | // authority is the address of the governance account. 23 | string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; 24 | // params defines the x/feemarket parameters to update. 25 | // NOTE: All parameters must be supplied. 26 | Params params = 2 [(gogoproto.nullable) = false]; 27 | } 28 | 29 | // MsgUpdateParamsResponse defines the response structure for executing a 30 | // MsgUpdateParams message. 31 | message MsgUpdateParamsResponse {} 32 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/types/v1/account.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.types.v1; 3 | 4 | import "cosmos/auth/v1beta1/auth.proto"; 5 | import "cosmos_proto/cosmos.proto"; 6 | import "gogoproto/gogo.proto"; 7 | 8 | option go_package = "github.com/evmos/ethermint/types"; 9 | 10 | // EthAccount implements the sdk.AccountI interface and embeds an 11 | // authtypes.BaseAccount type. It is compatible with the auth AccountKeeper. 12 | message EthAccount { 13 | option (gogoproto.goproto_getters) = false; 14 | option (gogoproto.goproto_stringer) = false; 15 | option (gogoproto.equal) = false; 16 | 17 | option (cosmos_proto.implements_interface) = "cosmos.auth.v1beta1.AccountI"; 18 | 19 | // base_account is an authtypes.BaseAccount 20 | cosmos.auth.v1beta1.BaseAccount base_account = 1 21 | [(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""]; 22 | 23 | // code_hash is the hash calculated from the code contents 24 | string code_hash = 2 [(gogoproto.moretags) = "yaml:\"code_hash\""]; 25 | } 26 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/types/v1/dynamic_fee.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.types.v1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/evmos/ethermint/types"; 7 | 8 | // ExtensionOptionDynamicFeeTx is an extension option that specifies the maxPrioPrice for cosmos tx 9 | message ExtensionOptionDynamicFeeTx { 10 | // max_priority_price is the same as `max_priority_fee_per_gas` in eip-1559 spec 11 | string max_priority_price = 1 12 | [(gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false]; 13 | } 14 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/types/v1/indexer.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.types.v1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/evmos/ethermint/types"; 7 | 8 | // TxResult is the value stored in eth tx indexer 9 | message TxResult { 10 | option (gogoproto.goproto_getters) = false; 11 | 12 | // height of the blockchain 13 | int64 height = 1; 14 | // tx_index of the cosmos transaction 15 | uint32 tx_index = 2; 16 | // msg_index in a batch transaction 17 | uint32 msg_index = 3; 18 | 19 | // eth_tx_index is the index in the list of valid eth tx in the block, 20 | // aka. the transaction list returned by eth_getBlock api. 21 | int32 eth_tx_index = 4; 22 | // failed is true if the eth transaction did not go succeed 23 | bool failed = 5; 24 | // gas_used by the transaction. If it exceeds the block gas limit, 25 | // it's set to gas limit, which is what's actually deducted by ante handler. 26 | uint64 gas_used = 6; 27 | // cumulative_gas_used specifies the cumulated amount of gas used for all 28 | // processed messages within the current batch transaction. 29 | uint64 cumulative_gas_used = 7; 30 | } 31 | -------------------------------------------------------------------------------- /third_party/proto/ethermint/types/v1/web3.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package ethermint.types.v1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/evmos/ethermint/types"; 7 | 8 | // ExtensionOptionsWeb3Tx is an extension option that specifies the typed chain id, 9 | // the fee payer as well as its signature data. 10 | message ExtensionOptionsWeb3Tx { 11 | option (gogoproto.goproto_getters) = false; 12 | 13 | // typed_data_chain_id is used only in EIP712 Domain and should match 14 | // Ethereum network ID in a Web3 provider (e.g. Metamask). 15 | uint64 typed_data_chain_id = 1 16 | [(gogoproto.jsontag) = "typedDataChainID,omitempty", (gogoproto.customname) = "TypedDataChainID"]; 17 | 18 | // fee_payer is an account address for the fee payer. It will be validated 19 | // during EIP712 signature checking. 20 | string fee_payer = 2 [(gogoproto.jsontag) = "feePayer,omitempty"]; 21 | 22 | // fee_payer_sig is a signature data from the fee paying account, 23 | // allows to perform fee delegation when using EIP712 Domain. 24 | bytes fee_payer_sig = 3 [(gogoproto.jsontag) = "feePayerSig,omitempty"]; 25 | } 26 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/fee/v1/ack.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.fee.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"; 6 | 7 | // IncentivizedAcknowledgement is the acknowledgement format to be used by applications wrapped in the fee middleware 8 | message IncentivizedAcknowledgement { 9 | // the underlying app acknowledgement bytes 10 | bytes app_acknowledgement = 1; 11 | // the relayer address which submits the recv packet message 12 | string forward_relayer_address = 2; 13 | // success flag of the base application callback 14 | bool underlying_app_success = 3; 15 | } 16 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/fee/v1/metadata.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.fee.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"; 6 | 7 | // Metadata defines the ICS29 channel specific metadata encoded into the channel version bytestring 8 | // See ICS004: https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#Versioning 9 | message Metadata { 10 | // fee_version defines the ICS29 fee version 11 | string fee_version = 1; 12 | // app_version defines the underlying application version, which may or may not be a JSON encoded bytestring 13 | string app_version = 2; 14 | } 15 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/interchain_accounts/controller/v1/controller.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.interchain_accounts.controller.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"; 6 | 7 | // Params defines the set of on-chain interchain accounts parameters. 8 | // The following parameters may be used to disable the controller submodule. 9 | message Params { 10 | // controller_enabled enables or disables the controller submodule. 11 | bool controller_enabled = 1; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/interchain_accounts/host/v1/host.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.interchain_accounts.host.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"; 6 | 7 | // Params defines the set of on-chain interchain accounts parameters. 8 | // The following parameters may be used to disable the host submodule. 9 | message Params { 10 | // host_enabled enables or disables the host submodule. 11 | bool host_enabled = 1; 12 | // allow_messages defines a list of sdk message typeURLs allowed to be executed on a host chain. 13 | repeated string allow_messages = 2; 14 | } 15 | 16 | // QueryRequest defines the parameters for a particular query request 17 | // by an interchain account. 18 | message QueryRequest { 19 | // path defines the path of the query request as defined by ADR-021. 20 | // https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-021-protobuf-query-encoding.md#custom-query-registration-and-routing 21 | string path = 1; 22 | // data defines the payload of the query request as defined by ADR-021. 23 | // https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-021-protobuf-query-encoding.md#custom-query-registration-and-routing 24 | bytes data = 2; 25 | } 26 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/interchain_accounts/host/v1/query.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.interchain_accounts.host.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"; 6 | 7 | import "google/api/annotations.proto"; 8 | import "ibc/applications/interchain_accounts/host/v1/host.proto"; 9 | 10 | // Query provides defines the gRPC querier service. 11 | service Query { 12 | // Params queries all parameters of the ICA host submodule. 13 | rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { 14 | option (google.api.http).get = "/ibc/apps/interchain_accounts/host/v1/params"; 15 | } 16 | } 17 | 18 | // QueryParamsRequest is the request type for the Query/Params RPC method. 19 | message QueryParamsRequest {} 20 | 21 | // QueryParamsResponse is the response type for the Query/Params RPC method. 22 | message QueryParamsResponse { 23 | // params defines the parameters of the module. 24 | Params params = 1; 25 | } 26 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/interchain_accounts/v1/account.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.interchain_accounts.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"; 6 | 7 | import "cosmos_proto/cosmos.proto"; 8 | import "gogoproto/gogo.proto"; 9 | import "cosmos/auth/v1beta1/auth.proto"; 10 | 11 | // An InterchainAccount is defined as a BaseAccount & the address of the account owner on the controller chain 12 | message InterchainAccount { 13 | option (gogoproto.goproto_getters) = false; 14 | option (gogoproto.goproto_stringer) = false; 15 | option (cosmos_proto.implements_interface) = "ibc.applications.interchain_accounts.v1.InterchainAccountI"; 16 | 17 | cosmos.auth.v1beta1.BaseAccount base_account = 1 [(gogoproto.embed) = true]; 18 | string account_owner = 2; 19 | } 20 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/interchain_accounts/v1/metadata.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.interchain_accounts.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"; 6 | 7 | // Metadata defines a set of protocol specific data encoded into the ICS27 channel version bytestring 8 | // See ICS004: https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#Versioning 9 | message Metadata { 10 | // version defines the ICS27 protocol version 11 | string version = 1; 12 | // controller_connection_id is the connection identifier associated with the controller chain 13 | string controller_connection_id = 2; 14 | // host_connection_id is the connection identifier associated with the host chain 15 | string host_connection_id = 3; 16 | // address defines the interchain account address to be fulfilled upon the OnChanOpenTry handshake step 17 | // NOTE: the address field is empty on the OnChanOpenInit handshake step 18 | string address = 4; 19 | // encoding defines the supported codec format 20 | string encoding = 5; 21 | // tx_type defines the type of transactions the interchain account can execute 22 | string tx_type = 6; 23 | } 24 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/interchain_accounts/v1/packet.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.interchain_accounts.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"; 6 | 7 | import "google/protobuf/any.proto"; 8 | import "gogoproto/gogo.proto"; 9 | 10 | // Type defines a classification of message issued from a controller chain to its associated interchain accounts 11 | // host 12 | enum Type { 13 | option (gogoproto.goproto_enum_prefix) = false; 14 | 15 | // Default zero value enumeration 16 | TYPE_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNSPECIFIED"]; 17 | // Execute a transaction on an interchain accounts host chain 18 | TYPE_EXECUTE_TX = 1 [(gogoproto.enumvalue_customname) = "EXECUTE_TX"]; 19 | } 20 | 21 | // InterchainAccountPacketData is comprised of a raw transaction, type of transaction and optional memo field. 22 | message InterchainAccountPacketData { 23 | Type type = 1; 24 | bytes data = 2; 25 | string memo = 3; 26 | } 27 | 28 | // CosmosTx contains a list of sdk.Msg's. It should be used when sending transactions to an SDK host chain. 29 | message CosmosTx { 30 | repeated google.protobuf.Any messages = 1; 31 | } 32 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/transfer/v1/authz.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.transfer.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"; 6 | 7 | import "cosmos_proto/cosmos.proto"; 8 | import "gogoproto/gogo.proto"; 9 | import "cosmos/base/v1beta1/coin.proto"; 10 | 11 | // Allocation defines the spend limit for a particular port and channel 12 | message Allocation { 13 | // the port on which the packet will be sent 14 | string source_port = 1; 15 | // the channel by which the packet will be sent 16 | string source_channel = 2; 17 | // spend limitation on the channel 18 | repeated cosmos.base.v1beta1.Coin spend_limit = 3 19 | [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; 20 | // allow list of receivers, an empty allow list permits any receiver address 21 | repeated string allow_list = 4; 22 | // allow list of memo strings, an empty list prohibits all memo strings; 23 | // a list only with "*" permits any memo string 24 | repeated string allowed_packet_data = 5; 25 | } 26 | 27 | // TransferAuthorization allows the grantee to spend up to spend_limit coins from 28 | // the granter's account for ibc transfer on a specific channel 29 | message TransferAuthorization { 30 | option (cosmos_proto.implements_interface) = "cosmos.authz.v1beta1.Authorization"; 31 | 32 | // port and channel amounts 33 | repeated Allocation allocations = 1 [(gogoproto.nullable) = false]; 34 | } 35 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/transfer/v1/genesis.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.transfer.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"; 6 | 7 | import "ibc/applications/transfer/v1/transfer.proto"; 8 | import "cosmos/base/v1beta1/coin.proto"; 9 | import "gogoproto/gogo.proto"; 10 | 11 | // GenesisState defines the ibc-transfer genesis state 12 | message GenesisState { 13 | string port_id = 1; 14 | repeated DenomTrace denom_traces = 2 [(gogoproto.castrepeated) = "Traces", (gogoproto.nullable) = false]; 15 | Params params = 3 [(gogoproto.nullable) = false]; 16 | // total_escrowed contains the total amount of tokens escrowed 17 | // by the transfer module 18 | repeated cosmos.base.v1beta1.Coin total_escrowed = 4 19 | [(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false]; 20 | } 21 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/transfer/v1/transfer.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.transfer.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"; 6 | 7 | // DenomTrace contains the base denomination for ICS20 fungible tokens and the 8 | // source tracing information path. 9 | message DenomTrace { 10 | // path defines the chain of port/channel identifiers used for tracing the 11 | // source of the fungible token. 12 | string path = 1; 13 | // base denomination of the relayed fungible token. 14 | string base_denom = 2; 15 | } 16 | 17 | // Params defines the set of IBC transfer parameters. 18 | // NOTE: To prevent a single token from being transferred, set the 19 | // TransfersEnabled parameter to true and then set the bank module's SendEnabled 20 | // parameter for the denomination to false. 21 | message Params { 22 | // send_enabled enables or disables all cross-chain token transfers from this 23 | // chain. 24 | bool send_enabled = 1; 25 | // receive_enabled enables or disables all cross-chain token transfers to this 26 | // chain. 27 | bool receive_enabled = 2; 28 | } 29 | -------------------------------------------------------------------------------- /third_party/proto/ibc/applications/transfer/v2/packet.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.applications.transfer.v2; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"; 6 | 7 | // FungibleTokenPacketData defines a struct for the packet payload 8 | // See FungibleTokenPacketData spec: 9 | // https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#data-structures 10 | message FungibleTokenPacketData { 11 | // the token denomination to be transferred 12 | string denom = 1; 13 | // the token amount to be transferred 14 | string amount = 2; 15 | // the sender address 16 | string sender = 3; 17 | // the recipient address on the destination chain 18 | string receiver = 4; 19 | // optional memo 20 | string memo = 5; 21 | } 22 | -------------------------------------------------------------------------------- /third_party/proto/ibc/core/channel/v1/genesis.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.core.channel.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"; 6 | 7 | import "gogoproto/gogo.proto"; 8 | import "ibc/core/channel/v1/channel.proto"; 9 | 10 | // GenesisState defines the ibc channel submodule's genesis state. 11 | message GenesisState { 12 | repeated IdentifiedChannel channels = 1 [(gogoproto.casttype) = "IdentifiedChannel", (gogoproto.nullable) = false]; 13 | repeated PacketState acknowledgements = 2 [(gogoproto.nullable) = false]; 14 | repeated PacketState commitments = 3 [(gogoproto.nullable) = false]; 15 | repeated PacketState receipts = 4 [(gogoproto.nullable) = false]; 16 | repeated PacketSequence send_sequences = 5 [(gogoproto.nullable) = false]; 17 | repeated PacketSequence recv_sequences = 6 [(gogoproto.nullable) = false]; 18 | repeated PacketSequence ack_sequences = 7 [(gogoproto.nullable) = false]; 19 | // the sequence for the next generated channel identifier 20 | uint64 next_channel_sequence = 8; 21 | Params params = 9 [(gogoproto.nullable) = false]; 22 | } 23 | 24 | // PacketSequence defines the genesis type necessary to retrieve and store 25 | // next send and receive sequences. 26 | message PacketSequence { 27 | string port_id = 1; 28 | string channel_id = 2; 29 | uint64 sequence = 3; 30 | } 31 | -------------------------------------------------------------------------------- /third_party/proto/ibc/core/commitment/v1/commitment.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.core.commitment.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"; 6 | 7 | import "gogoproto/gogo.proto"; 8 | import "cosmos/ics23/v1/proofs.proto"; 9 | 10 | // MerkleRoot defines a merkle root hash. 11 | // In the Cosmos SDK, the AppHash of a block header becomes the root. 12 | message MerkleRoot { 13 | option (gogoproto.goproto_getters) = false; 14 | 15 | bytes hash = 1; 16 | } 17 | 18 | // MerklePrefix is merkle path prefixed to the key. 19 | // The constructed key from the Path and the key will be append(Path.KeyPath, 20 | // append(Path.KeyPrefix, key...)) 21 | message MerklePrefix { 22 | bytes key_prefix = 1; 23 | } 24 | 25 | // MerklePath is the path used to verify commitment proofs, which can be an 26 | // arbitrary structured object (defined by a commitment type). 27 | // MerklePath is represented from root-to-leaf 28 | message MerklePath { 29 | repeated string key_path = 1; 30 | } 31 | 32 | // MerkleProof is a wrapper type over a chain of CommitmentProofs. 33 | // It demonstrates membership or non-membership for an element or set of 34 | // elements, verifiable in conjunction with a known commitment root. Proofs 35 | // should be succinct. 36 | // MerkleProofs are ordered from leaf-to-root 37 | message MerkleProof { 38 | repeated cosmos.ics23.v1.CommitmentProof proofs = 1; 39 | } 40 | -------------------------------------------------------------------------------- /third_party/proto/ibc/core/connection/v1/genesis.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.core.connection.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"; 6 | 7 | import "gogoproto/gogo.proto"; 8 | import "ibc/core/connection/v1/connection.proto"; 9 | 10 | // GenesisState defines the ibc connection submodule's genesis state. 11 | message GenesisState { 12 | repeated IdentifiedConnection connections = 1 [(gogoproto.nullable) = false]; 13 | repeated ConnectionPaths client_connection_paths = 2 [(gogoproto.nullable) = false]; 14 | // the sequence for the next generated connection identifier 15 | uint64 next_connection_sequence = 3; 16 | Params params = 4 [(gogoproto.nullable) = false]; 17 | } 18 | -------------------------------------------------------------------------------- /third_party/proto/ibc/core/types/v1/genesis.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.core.types.v1; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/core/types"; 6 | 7 | import "gogoproto/gogo.proto"; 8 | import "ibc/core/client/v1/genesis.proto"; 9 | import "ibc/core/connection/v1/genesis.proto"; 10 | import "ibc/core/channel/v1/genesis.proto"; 11 | 12 | // GenesisState defines the ibc module's genesis state. 13 | message GenesisState { 14 | // ICS002 - Clients genesis state 15 | ibc.core.client.v1.GenesisState client_genesis = 1 [(gogoproto.nullable) = false]; 16 | // ICS003 - Connections genesis state 17 | ibc.core.connection.v1.GenesisState connection_genesis = 2 [(gogoproto.nullable) = false]; 18 | // ICS004 - Channel genesis state 19 | ibc.core.channel.v1.GenesisState channel_genesis = 3 [(gogoproto.nullable) = false]; 20 | } 21 | -------------------------------------------------------------------------------- /third_party/proto/ibc/lightclients/localhost/v2/localhost.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ibc.lightclients.localhost.v2; 4 | 5 | option go_package = "github.com/cosmos/ibc-go/v8/modules/light-clients/09-localhost;localhost"; 6 | 7 | import "ibc/core/client/v1/client.proto"; 8 | import "gogoproto/gogo.proto"; 9 | 10 | // ClientState defines the 09-localhost client state 11 | message ClientState { 12 | option (gogoproto.goproto_getters) = false; 13 | 14 | // the latest block height 15 | ibc.core.client.v1.Height latest_height = 1 [(gogoproto.nullable) = false]; 16 | } 17 | -------------------------------------------------------------------------------- /third_party/proto/ibc/lightclients/wasm/v1/genesis.proto: -------------------------------------------------------------------------------- 1 | 2 | syntax = "proto3"; 3 | package ibc.lightclients.wasm.v1; 4 | 5 | import "gogoproto/gogo.proto"; 6 | 7 | option go_package = "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"; 8 | 9 | // GenesisState defines 08-wasm's keeper genesis state 10 | message GenesisState { 11 | // uploaded light client wasm contracts 12 | repeated Contract contracts = 1 [(gogoproto.nullable) = false]; 13 | } 14 | 15 | // Contract stores contract code 16 | message Contract { 17 | option (gogoproto.goproto_getters) = false; 18 | // contract byte code 19 | bytes code_bytes = 1; 20 | } -------------------------------------------------------------------------------- /third_party/proto/ibc/lightclients/wasm/v1/wasm.proto: -------------------------------------------------------------------------------- 1 | 2 | syntax = "proto3"; 3 | package ibc.lightclients.wasm.v1; 4 | 5 | import "gogoproto/gogo.proto"; 6 | import "ibc/core/client/v1/client.proto"; 7 | 8 | option go_package = "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"; 9 | 10 | // Wasm light client's Client state 11 | message ClientState { 12 | option (gogoproto.goproto_getters) = false; 13 | // bytes encoding the client state of the underlying light client 14 | // implemented as a Wasm contract. 15 | bytes data = 1; 16 | bytes checksum = 2; 17 | ibc.core.client.v1.Height latest_height = 3 [(gogoproto.nullable) = false]; 18 | } 19 | 20 | // Wasm light client's ConsensusState 21 | message ConsensusState { 22 | option (gogoproto.goproto_getters) = false; 23 | // bytes encoding the consensus state of the underlying light client 24 | // implemented as a Wasm contract. 25 | bytes data = 1; 26 | } 27 | 28 | // Wasm light client message (either header(s) or misbehaviour) 29 | message ClientMessage { 30 | option (gogoproto.goproto_getters) = false; 31 | 32 | bytes data = 1; 33 | } 34 | 35 | // Checksums defines a list of all checksums that are stored 36 | // 37 | // Deprecated: This message is deprecated in favor of storing the checksums 38 | // using a Collections.KeySet. 39 | message Checksums { 40 | option deprecated = true; 41 | 42 | repeated bytes checksums = 1; 43 | } -------------------------------------------------------------------------------- /versiondb/client/cmd.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | dbm "github.com/cosmos/cosmos-db" 5 | "github.com/linxGnu/grocksdb" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | // Options defines the customizable settings of ChangeSetGroupCmd 10 | type Options struct { 11 | DefaultStores []string 12 | OpenReadOnlyDB func(home string, backend dbm.BackendType) (dbm.DB, error) 13 | AppRocksDBOptions func(sstFileWriter bool) *grocksdb.Options 14 | } 15 | 16 | func ChangeSetGroupCmd(opts Options) *cobra.Command { 17 | cmd := &cobra.Command{ 18 | Use: "changeset", 19 | Short: "dump and manage change sets files and ingest into versiondb", 20 | } 21 | cmd.AddCommand( 22 | ListDefaultStoresCmd(opts.DefaultStores), 23 | DumpChangeSetCmd(opts), 24 | PrintChangeSetCmd(), 25 | VerifyChangeSetCmd(opts.DefaultStores), 26 | BuildVersionDBSSTCmd(opts.DefaultStores), 27 | IngestVersionDBSSTCmd(), 28 | ChangeSetToVersionDBCmd(), 29 | RestoreAppDBCmd(opts), 30 | RestoreVersionDBCmd(), 31 | FixDataCmd(opts.DefaultStores), 32 | ) 33 | return cmd 34 | } 35 | -------------------------------------------------------------------------------- /versiondb/client/fixdata.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "github.com/crypto-org-chain/cronos/versiondb/tsrocksdb" 5 | "github.com/linxGnu/grocksdb" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | const ( 10 | FlagDryRun = "dry-run" 11 | FlagStore = "store-name" 12 | ) 13 | 14 | func FixDataCmd(defaultStores []string) *cobra.Command { 15 | cmd := &cobra.Command{ 16 | Use: "fixdata ", 17 | Args: cobra.ExactArgs(1), 18 | Short: "Fix wrong data in versiondb, see: https://github.com/crypto-org-chain/cronos/issues/1683", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | dir := args[0] 21 | dryRun, err := cmd.Flags().GetBool(FlagDryRun) 22 | if err != nil { 23 | return err 24 | } 25 | stores, err := cmd.Flags().GetStringArray(FlagStore) 26 | if err != nil { 27 | return err 28 | } 29 | if len(stores) == 0 { 30 | stores = defaultStores 31 | } 32 | 33 | var ( 34 | db *grocksdb.DB 35 | cfHandle *grocksdb.ColumnFamilyHandle 36 | ) 37 | 38 | if dryRun { 39 | db, cfHandle, err = tsrocksdb.OpenVersionDBForReadOnly(dir, false) 40 | } else { 41 | db, cfHandle, err = tsrocksdb.OpenVersionDB(dir) 42 | } 43 | if err != nil { 44 | return err 45 | } 46 | 47 | versionDB := tsrocksdb.NewStoreWithDB(db, cfHandle) 48 | if err := versionDB.FixData(stores, dryRun); err != nil { 49 | return err 50 | } 51 | 52 | return nil 53 | }, 54 | } 55 | 56 | cmd.Flags().Bool(FlagDryRun, false, "Dry run, do not write to the database, open the database in read-only mode.") 57 | cmd.Flags().StringArray(FlagStore, []string{}, "Store names to fix, if not specified, all stores will be fixed.") 58 | return cmd 59 | } 60 | -------------------------------------------------------------------------------- /versiondb/client/flags.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | const ( 4 | IAVLV0 = iota 5 | IAVLV1 6 | ) 7 | 8 | const ( 9 | flagStartVersion = "start-version" 10 | flagEndVersion = "end-version" 11 | flagOutput = "output" 12 | flagConcurrency = "concurrency" 13 | flagCheck = "check" 14 | flagSave = "save" 15 | flagNoParseChangeset = "no-parse-changeset" 16 | flagChunkSize = "chunk-size" 17 | flagZlibLevel = "zlib-level" 18 | flagSSTFileSize = "sst-file-size" 19 | flagMoveFiles = "move-files" 20 | flagStore = "store" 21 | flagStores = "stores" 22 | flagMaximumVersion = "maximum-version" 23 | flagTargetVersion = "target-version" 24 | flagSaveSnapshot = "save-snapshot" 25 | flagLoadSnapshot = "load-snapshot" 26 | flagSorterChunkSize = "sorter-chunk-size" 27 | flagInitialVersion = "initial-version" 28 | flagSDK64Compact = "sdk64-compact" 29 | flagIAVLVersion = "iavl-version" 30 | ) 31 | -------------------------------------------------------------------------------- /versiondb/client/stores.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func ListDefaultStoresCmd(stores []string) *cobra.Command { 11 | cmd := &cobra.Command{ 12 | Use: "default-stores", 13 | Short: "List the store names in current binary version", 14 | Args: cobra.NoArgs, 15 | RunE: func(cmd *cobra.Command, args []string) error { 16 | for _, name := range stores { 17 | fmt.Println(name) 18 | } 19 | 20 | return nil 21 | }, 22 | } 23 | return cmd 24 | } 25 | 26 | func GetStoresOrDefault(cmd *cobra.Command, defaultStores []string) ([]string, error) { 27 | stores, err := cmd.Flags().GetString(flagStores) 28 | if err != nil { 29 | return nil, err 30 | } 31 | if len(stores) == 0 { 32 | return defaultStores, nil 33 | } 34 | return strings.Split(stores, " "), nil 35 | } 36 | -------------------------------------------------------------------------------- /versiondb/client/to_versiondb.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "github.com/cosmos/iavl" 5 | "github.com/crypto-org-chain/cronos/versiondb/tsrocksdb" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func ChangeSetToVersionDBCmd() *cobra.Command { 10 | cmd := &cobra.Command{ 11 | Use: "to-versiondb versiondb-path plain-1 [plain-2] ...", 12 | Short: "Feed change set files into versiondb", 13 | Args: cobra.MinimumNArgs(2), 14 | RunE: func(cmd *cobra.Command, args []string) error { 15 | store, err := cmd.Flags().GetString(flagStore) 16 | if err != nil { 17 | return err 18 | } 19 | 20 | versionDB, err := tsrocksdb.NewStore(args[0]) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | for _, plainFile := range args[1:] { 26 | if err := withChangeSetFile(plainFile, func(reader Reader) error { 27 | _, err := IterateChangeSets(reader, func(version int64, changeSet *iavl.ChangeSet) (bool, error) { 28 | if err := versionDB.FeedChangeSet(version, store, changeSet); err != nil { 29 | return false, err 30 | } 31 | return true, nil 32 | }) 33 | 34 | return err 35 | }); err != nil { 36 | return err 37 | } 38 | } 39 | 40 | return nil 41 | }, 42 | } 43 | 44 | cmd.Flags().String(flagStore, "", "store name, the keys are prefixed with \"s/k:{store}/\"") 45 | return cmd 46 | } 47 | -------------------------------------------------------------------------------- /versiondb/client/wrapreader.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "errors" 5 | "io" 6 | ) 7 | 8 | type wrapReader struct { 9 | reader Reader 10 | closer io.Closer 11 | } 12 | 13 | // WrapReader wraps reader and closer together to create a new io.ReadCloser. 14 | // 15 | // The Read function will simply call the wrapped reader's Read function, 16 | // while the Close function will call the wrapped closer's Close function. 17 | // 18 | // If the wrapped reader is also an io.Closer, 19 | // its Close function will be called in Close as well. 20 | // 21 | // closer can be `nil`, to support stdin. 22 | func WrapReader(reader Reader, closer io.Closer) ReadCloser { 23 | return &wrapReader{ 24 | reader: reader, 25 | closer: closer, 26 | } 27 | } 28 | 29 | func (r *wrapReader) Read(p []byte) (int, error) { 30 | return r.reader.Read(p) 31 | } 32 | 33 | func (r *wrapReader) ReadByte() (byte, error) { 34 | return r.reader.ReadByte() 35 | } 36 | 37 | func (r *wrapReader) Close() error { 38 | var errs []error 39 | if closer, ok := r.reader.(io.Closer); ok { 40 | errs = append(errs, closer.Close()) 41 | } 42 | if r.closer != nil { 43 | errs = append(errs, r.closer.Close()) 44 | } 45 | return errors.Join(errs...) 46 | } 47 | -------------------------------------------------------------------------------- /versiondb/extsort/delta_encoding_test.go: -------------------------------------------------------------------------------- 1 | package extsort 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "testing" 7 | 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func TestDeltaEncoding(t *testing.T) { 12 | testCases := []struct { 13 | name string 14 | keys []string 15 | expSize int 16 | }{ 17 | { 18 | "no share", 19 | []string{"hello", "world"}, 20 | 14, 21 | }, 22 | { 23 | "share", 24 | []string{"hello", "hello2"}, 25 | 10, 26 | }, 27 | } 28 | 29 | for _, tc := range testCases { 30 | t.Run(tc.name, func(t *testing.T) { 31 | encoder := NewDeltaEncoder() 32 | var buf bytes.Buffer 33 | for _, key := range tc.keys { 34 | require.NoError(t, encoder.Write(&buf, []byte(key))) 35 | } 36 | require.Equal(t, tc.expSize, buf.Len()) 37 | 38 | decoder := NewDeltaDecoder() 39 | var keys []string 40 | for { 41 | key, err := decoder.Read(&buf) 42 | if err == io.EOF { 43 | break 44 | } 45 | require.NoError(t, err) 46 | keys = append(keys, string(key)) 47 | } 48 | require.Equal(t, tc.keys, keys) 49 | }) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /versiondb/extsort/types.go: -------------------------------------------------------------------------------- 1 | package extsort 2 | 3 | type ( 4 | // LesserFunc compares two items in external sorter 5 | LesserFunc func(a, b []byte) bool 6 | // NextFunc is a stream that yields bytes, it should return `nil` when stream is exhausted 7 | NextFunc func() ([]byte, error) 8 | ) 9 | -------------------------------------------------------------------------------- /versiondb/objstore.go: -------------------------------------------------------------------------------- 1 | //go:build objstore 2 | // +build objstore 3 | 4 | package versiondb 5 | 6 | import "cosmossdk.io/store/types" 7 | 8 | // GetObjKVStore implements `MultiStore` interface 9 | func (s *MultiStore) GetObjKVStore(storeKey types.StoreKey) types.ObjKVStore { 10 | return s.GetStore(storeKey).(types.ObjKVStore) 11 | } 12 | -------------------------------------------------------------------------------- /versiondb/streaming_service.go: -------------------------------------------------------------------------------- 1 | package versiondb 2 | 3 | import ( 4 | "context" 5 | 6 | abci "github.com/cometbft/cometbft/abci/types" 7 | 8 | "cosmossdk.io/store/types" 9 | ) 10 | 11 | var _ types.ABCIListener = &StreamingService{} 12 | 13 | // StreamingService is a concrete implementation of StreamingService that accumulate the state changes in current block, 14 | // writes the ordered changeset out to version storage. 15 | type StreamingService struct { 16 | versionStore VersionStore 17 | currentBlockNumber int64 // the current block number 18 | } 19 | 20 | // NewStreamingService creates a new StreamingService for the provided writeDir, (optional) filePrefix, and storeKeys 21 | func NewStreamingService(versionStore VersionStore) *StreamingService { 22 | return &StreamingService{versionStore: versionStore} 23 | } 24 | 25 | // ListenFinalizeBlock satisfies the types.ABCIListener interface 26 | func (fss *StreamingService) ListenFinalizeBlock(ctx context.Context, req abci.RequestFinalizeBlock, res abci.ResponseFinalizeBlock) error { 27 | fss.currentBlockNumber = req.Height 28 | return nil 29 | } 30 | 31 | func (fss *StreamingService) ListenCommit(ctx context.Context, res abci.ResponseCommit, changeSet []*types.StoreKVPair) error { 32 | return fss.versionStore.PutAtVersion(fss.currentBlockNumber, changeSet) 33 | } 34 | -------------------------------------------------------------------------------- /versiondb/types.go: -------------------------------------------------------------------------------- 1 | package versiondb 2 | 3 | import ( 4 | "cosmossdk.io/store/types" 5 | ) 6 | 7 | type Iterator interface { 8 | types.Iterator 9 | 10 | Timestamp() []byte 11 | } 12 | 13 | // VersionStore is a versioned storage of a flat key-value pairs. 14 | // it don't need to support merkle proof, so could be implemented in a much more efficient way. 15 | // `nil` version means the latest version. 16 | type VersionStore interface { 17 | GetAtVersion(storeKey string, key []byte, version *int64) ([]byte, error) 18 | HasAtVersion(storeKey string, key []byte, version *int64) (bool, error) 19 | IteratorAtVersion(storeKey string, start, end []byte, version *int64) (Iterator, error) 20 | ReverseIteratorAtVersion(storeKey string, start, end []byte, version *int64) (Iterator, error) 21 | GetLatestVersion() (int64, error) 22 | 23 | // Persist the change set of a block, 24 | // the `changeSet` should be ordered by (storeKey, key), 25 | // the version should be latest version plus one. 26 | PutAtVersion(version int64, changeSet []*types.StoreKVPair) error 27 | 28 | // Import the initial state of the store 29 | Import(version int64, ch <-chan ImportEntry) error 30 | 31 | // Flush wal logs, and make the changes persistent, 32 | // mainly for rocksdb version upgrade, sometimes the wal format is not compatible. 33 | Flush() error 34 | } 35 | 36 | type ImportEntry struct { 37 | StoreKey string 38 | Key []byte 39 | Value []byte 40 | } 41 | -------------------------------------------------------------------------------- /x/cronos/client/proposal_handler.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | govclient "github.com/cosmos/cosmos-sdk/x/gov/client" 5 | 6 | "github.com/crypto-org-chain/cronos/v2/x/cronos/client/cli" 7 | ) 8 | 9 | // ProposalHandler is the token mapping change proposal handler. 10 | var ProposalHandler = govclient.NewProposalHandler(cli.NewSubmitTokenMappingChangeProposalTxCmd) 11 | -------------------------------------------------------------------------------- /x/cronos/events/README.md: -------------------------------------------------------------------------------- 1 | Convert native events emitted by precompiles to ethereum logs. 2 | -------------------------------------------------------------------------------- /x/cronos/events/bindings/src/Bank.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | interface IBankModule { 5 | function mint(address,uint256) external payable returns (bool); 6 | function balanceOf(address,address) external view returns (uint256); 7 | function burn(address,uint256) external payable returns (bool); 8 | function transfer(address,address,uint256) external payable returns (bool); 9 | } 10 | -------------------------------------------------------------------------------- /x/cronos/events/bindings/src/CosmosTypes.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | library Cosmos { 5 | struct Coin { 6 | uint256 amount; 7 | string denom; 8 | } 9 | } 10 | 11 | contract CosmosTypes { 12 | function coin(Cosmos.Coin calldata) public pure {} 13 | } 14 | -------------------------------------------------------------------------------- /x/cronos/events/bindings/src/ICA.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | interface IICAModule { 5 | event SubmitMsgsResult(string indexed packetSrcChannel, uint64 seq); 6 | function registerAccount(string calldata connectionID, string calldata version, int32 ordering) external payable returns (bool); 7 | function queryAccount(string calldata connectionID, address addr) external view returns (string memory); 8 | function submitMsgs(string calldata connectionID, bytes calldata data, uint256 timeout) external payable returns (uint64); 9 | } 10 | -------------------------------------------------------------------------------- /x/cronos/events/bindings/src/ICACallback.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | interface IICACallback { 5 | function onPacketResultCallback(string calldata packetSrcChannel, uint64 seq, bool ack) external payable returns (bool); 6 | } 7 | -------------------------------------------------------------------------------- /x/cronos/events/types/types.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | const ( 4 | EventTypeSubmitMsgsResult = "submit_msgs_result" 5 | AttributeKeySeq = "seq" 6 | AttributeKeySrcPortInfo = "packet_src_port_info" 7 | AttributeKeySrcChannelInfo = "packet_src_channel_info" 8 | ) 9 | -------------------------------------------------------------------------------- /x/cronos/exported/exported.go: -------------------------------------------------------------------------------- 1 | package exported 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" 6 | ) 7 | 8 | type ( 9 | ParamSet = paramtypes.ParamSet 10 | 11 | // Subspace defines an interface that implements the legacy x/params Subspace 12 | // type. 13 | // 14 | // NOTE: This is used solely for migration of x/params managed parameters. 15 | Subspace interface { 16 | GetParamSetIfExists(ctx sdk.Context, ps ParamSet) 17 | } 18 | ) 19 | -------------------------------------------------------------------------------- /x/cronos/keeper/migrations.go: -------------------------------------------------------------------------------- 1 | package keeper 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" 6 | v2 "github.com/crypto-org-chain/cronos/v2/x/cronos/migrations/v2" 7 | ) 8 | 9 | // Migrator is a struct for handling in-place store migrations. 10 | type Migrator struct { 11 | keeper Keeper 12 | legacySubspace paramstypes.Subspace 13 | } 14 | 15 | // NewMigrator returns a new Migrator. 16 | func NewMigrator(keeper Keeper, ss paramstypes.Subspace) Migrator { 17 | return Migrator{keeper: keeper, legacySubspace: ss} 18 | } 19 | 20 | // Migrate1to2 migrates from version 1 to 2. 21 | func (m Migrator) Migrate1to2(ctx sdk.Context) error { 22 | err := v2.Migrate(ctx, ctx.KVStore(m.keeper.storeKey), m.legacySubspace, m.keeper.cdc) 23 | return err 24 | } 25 | -------------------------------------------------------------------------------- /x/cronos/keeper/mock/ibckeeper_mock.go: -------------------------------------------------------------------------------- 1 | package keeper_test 2 | 3 | import ( 4 | "context" 5 | 6 | tmbytes "github.com/cometbft/cometbft/libs/bytes" 7 | sdk "github.com/cosmos/cosmos-sdk/types" 8 | "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" 9 | ) 10 | 11 | type IbcKeeperMock struct{} 12 | 13 | func (i IbcKeeperMock) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.MsgTransferResponse, error) { 14 | return nil, nil 15 | } 16 | 17 | func (i IbcKeeperMock) GetDenomTrace(ctx sdk.Context, denomTraceHash tmbytes.HexBytes) (types.DenomTrace, bool) { 18 | if denomTraceHash.String() == "6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865" { 19 | return types.DenomTrace{ 20 | Path: "transfer/channel-0", 21 | BaseDenom: "basetcro", 22 | }, true 23 | } 24 | if denomTraceHash.String() == "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" { 25 | return types.DenomTrace{ 26 | Path: "transfer/channel-0", 27 | BaseDenom: "correctIBCToken", 28 | }, true 29 | } 30 | return types.DenomTrace{}, false 31 | } 32 | -------------------------------------------------------------------------------- /x/cronos/keeper/precompiles/base_contract.go: -------------------------------------------------------------------------------- 1 | package precompiles 2 | 3 | import ( 4 | "github.com/ethereum/go-ethereum/common" 5 | ) 6 | 7 | type Registrable interface { 8 | RegistryKey() common.Address 9 | } 10 | 11 | type BaseContract interface { 12 | Registrable 13 | } 14 | 15 | type baseContract struct { 16 | address common.Address 17 | } 18 | 19 | func NewBaseContract(address common.Address) BaseContract { 20 | return &baseContract{ 21 | address: address, 22 | } 23 | } 24 | 25 | func (c *baseContract) RegistryKey() common.Address { 26 | return c.address 27 | } 28 | -------------------------------------------------------------------------------- /x/cronos/keeper/precompiles/interface.go: -------------------------------------------------------------------------------- 1 | package precompiles 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | "github.com/ethereum/go-ethereum/common" 6 | "github.com/ethereum/go-ethereum/core/vm" 7 | "github.com/evmos/ethermint/x/evm/statedb" 8 | ) 9 | 10 | // ExtStateDB defines extra methods of statedb to support stateful precompiled contracts 11 | type ExtStateDB interface { 12 | vm.StateDB 13 | ExecuteNativeAction(contract common.Address, converter statedb.EventConverter, action func(ctx sdk.Context) error) error 14 | Context() sdk.Context 15 | } 16 | -------------------------------------------------------------------------------- /x/cronos/migrations/v2/migrate.go: -------------------------------------------------------------------------------- 1 | package v2 2 | 3 | import ( 4 | storetypes "cosmossdk.io/store/types" 5 | "github.com/cosmos/cosmos-sdk/codec" 6 | sdk "github.com/cosmos/cosmos-sdk/types" 7 | "github.com/crypto-org-chain/cronos/v2/x/cronos/exported" 8 | "github.com/crypto-org-chain/cronos/v2/x/cronos/types" 9 | ) 10 | 11 | // Migrate migrates the x/cronos module state from the consensus version 1 to 12 | // version 2. Specifically, it takes the parameters that are currently stored 13 | // and managed by the x/params modules and stores them directly into the x/cronos 14 | // module state. 15 | func Migrate(ctx sdk.Context, store storetypes.KVStore, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error { 16 | var currParams types.Params 17 | legacySubspace.GetParamSetIfExists(ctx, &currParams) 18 | 19 | if err := currParams.Validate(); err != nil { 20 | return err 21 | } 22 | if currParams.GetMaxCallbackGas() == 0 { 23 | currParams.MaxCallbackGas = types.MaxCallbackGasDefaultValue 24 | } 25 | bz := cdc.MustMarshal(&currParams) 26 | store.Set(types.ParamsKey, bz) 27 | 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /x/cronos/migrations/v2/migrate_test.go: -------------------------------------------------------------------------------- 1 | package v2_test 2 | 3 | import ( 4 | "testing" 5 | 6 | simappparams "cosmossdk.io/simapp/params" 7 | storetypes "cosmossdk.io/store/types" 8 | "github.com/cosmos/cosmos-sdk/testutil" 9 | sdk "github.com/cosmos/cosmos-sdk/types" 10 | "github.com/crypto-org-chain/cronos/v2/x/cronos/exported" 11 | v2 "github.com/crypto-org-chain/cronos/v2/x/cronos/migrations/v2" 12 | "github.com/crypto-org-chain/cronos/v2/x/cronos/types" 13 | "github.com/stretchr/testify/require" 14 | ) 15 | 16 | type mockSubspace struct { 17 | ps types.Params 18 | } 19 | 20 | func newMockSubspace(ps types.Params) mockSubspace { 21 | return mockSubspace{ps: ps} 22 | } 23 | 24 | func (ms mockSubspace) GetParamSetIfExists(ctx sdk.Context, ps exported.ParamSet) { 25 | *ps.(*types.Params) = ms.ps 26 | } 27 | 28 | func TestMigrate(t *testing.T) { 29 | storeKey := storetypes.NewKVStoreKey(types.ModuleName) 30 | ctx := testutil.DefaultContext(storeKey, storetypes.NewTransientStoreKey("test")) 31 | store := ctx.KVStore(storeKey) 32 | cdc := simappparams.MakeTestEncodingConfig().Codec 33 | legacySubspace := newMockSubspace(types.DefaultParams()) 34 | v2.Migrate(ctx, store, legacySubspace, cdc) 35 | var p types.Params 36 | require.NoError(t, cdc.Unmarshal(store.Get(types.ParamsKey), &p)) 37 | require.Equal(t, legacySubspace.ps, p) 38 | } 39 | -------------------------------------------------------------------------------- /x/cronos/proposal_handler.go: -------------------------------------------------------------------------------- 1 | package cronos 2 | 3 | import ( 4 | "cosmossdk.io/errors" 5 | sdk "github.com/cosmos/cosmos-sdk/types" 6 | sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" 7 | govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" 8 | 9 | "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper" 10 | "github.com/crypto-org-chain/cronos/v2/x/cronos/types" 11 | ) 12 | 13 | // NewTokenMappingChangeProposalHandler creates a new governance Handler for a TokenMappingChangeProposal 14 | func NewTokenMappingChangeProposalHandler(k keeper.Keeper) govtypes.Handler { 15 | return func(ctx sdk.Context, content govtypes.Content) error { 16 | switch c := content.(type) { 17 | case *types.TokenMappingChangeProposal: 18 | // check first that the denom is one of the denom supported by cronos 19 | if !types.IsValidCoinDenom(c.Denom) { 20 | return errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid coin denom %s", c.Denom) 21 | } 22 | 23 | msg := types.MsgUpdateTokenMapping{ 24 | Denom: c.Denom, 25 | Contract: c.Contract, 26 | Symbol: c.Symbol, 27 | Decimal: c.Decimal, 28 | } 29 | return k.RegisterOrUpdateTokenMapping(ctx, &msg) 30 | default: 31 | return errors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized cronos proposal content type: %T", c) 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /x/cronos/simulation/decoder.go: -------------------------------------------------------------------------------- 1 | package simulation 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | 7 | "github.com/cosmos/cosmos-sdk/types/kv" 8 | "github.com/crypto-org-chain/cronos/v2/x/cronos/types" 9 | "github.com/ethereum/go-ethereum/common" 10 | ) 11 | 12 | // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's 13 | // value to the corresponding cronos type. 14 | func NewDecodeStore() func(kvA, kvB kv.Pair) string { 15 | return func(kvA, kvB kv.Pair) string { 16 | switch { 17 | case bytes.Equal(kvA.Key[:1], types.KeyPrefixDenomToExternalContract): 18 | contractA := common.BytesToAddress(kvA.Value).String() 19 | contractB := common.BytesToAddress(kvB.Value).String() 20 | 21 | return fmt.Sprintf("%v\n%v", contractA, contractB) 22 | case bytes.Equal(kvA.Key[:1], types.KeyPrefixDenomToAutoContract): 23 | contractA := common.BytesToAddress(kvA.Value).String() 24 | contractB := common.BytesToAddress(kvB.Value).String() 25 | 26 | return fmt.Sprintf("%v\n%v", contractA, contractB) 27 | case bytes.Equal(kvA.Key[:1], types.KeyPrefixContractToDenom): 28 | denomA := string(kvA.Value) 29 | denomB := string(kvB.Value) 30 | 31 | return fmt.Sprintf("%v\n%v", denomA, denomB) 32 | default: 33 | panic(fmt.Sprintf("invalid evm key prefix %X", kvA.Key[:1])) 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /x/cronos/simulation/decoder_test.go: -------------------------------------------------------------------------------- 1 | package simulation 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/cosmos/cosmos-sdk/types/kv" 10 | "github.com/crypto-org-chain/cronos/v2/x/cronos/types" 11 | "github.com/ethereum/go-ethereum/common" 12 | ) 13 | 14 | // TestDecodeStore tests that evm simulation decoder decodes the key value pairs as expected. 15 | func TestDecodeStore(t *testing.T) { 16 | dec := NewDecodeStore() 17 | 18 | contract := common.HexToAddress("0xabc") 19 | denom := types.IbcCroDenomDefaultValue 20 | 21 | kvPairs := kv.Pairs{ 22 | Pairs: []kv.Pair{ 23 | {Key: types.KeyPrefixDenomToAutoContract, Value: contract.Bytes()}, 24 | {Key: types.KeyPrefixDenomToExternalContract, Value: contract.Bytes()}, 25 | {Key: types.KeyPrefixContractToDenom, Value: []byte(denom)}, 26 | }, 27 | } 28 | 29 | tests := []struct { 30 | name string 31 | expectedLog string 32 | }{ 33 | {"ExternalContract", fmt.Sprintf("%v\n%v", contract, contract)}, 34 | {"AutoContract", fmt.Sprintf("%v\n%v", contract, contract)}, 35 | {"Denom", fmt.Sprintf("%v\n%v", denom, denom)}, 36 | {"other", ""}, 37 | } 38 | for i, tt := range tests { 39 | i, tt := i, tt 40 | t.Run(tt.name, func(t *testing.T) { 41 | switch i { 42 | case len(tests) - 1: 43 | require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name) 44 | default: 45 | require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name) 46 | } 47 | }) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /x/cronos/spec/02_state.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | # State 6 | 7 | The `x/cronos` module keeps the following objects in state: 8 | 9 | | | Key | Value | 10 | | ----------------------- | -------------------------------------- | -------------------------- | 11 | | DenomToExternalContract | `[]byte{1} + []byte(denom)` | `[]byte(contract_address)` | 12 | | DenomToAutoContract | `[]byte{2} + []byte(denom)` | `[]byte(contract_address)` | 13 | | ContractToDenom | `[]byte{3} + []byte(contract_address)` | `[]byte(denom)` | 14 | 15 | - `DenomToExternalContract` stores a map from denom to external CRC20 contract. 16 | - `DenomToAutoContract` stores a map from denom to auto-deployed CRC20 contract. 17 | - `ContractToDenom` stores the reversed map for both external and auto-deployed contracts. 18 | -------------------------------------------------------------------------------- /x/cronos/spec/03_state_transitions.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | # State Transitions 6 | 7 | 8 | 9 | This document describes the state transition operations of Cronos module, currently the only state is token mapping. 10 | 11 | ## Token Mapping 12 | 13 | ### Create/Update 14 | 15 | There are several scenarios when the token mapping is updated: 16 | 17 | - When auto-deployment is enabled and a new IBC or gravity token arrived. 18 | - When auto-deployment is enabled and `MsgConvertVouchers` message executed with a new token. 19 | - When a `TokenMappingChangeProposal` gov proposal is executed. 20 | - When the admin account execute a `MsgUpdateTokenMapping` message. 21 | 22 | When the mapping updated, the token migration between old and new contracts can be managed by contract developer, for example, the new contract could allow user to swap old token to new one. 23 | 24 | #### Contract Migration 25 | 26 | When token mapping get updated, the old contract still exists. 27 | 28 | ### Delete 29 | 30 | There's no way to delete a token mapping currently. 31 | -------------------------------------------------------------------------------- /x/cronos/spec/05_abci.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | # ABCI 6 | 7 | ## InitGenesis 8 | 9 | `InitGenesis` initializes the Cronos module genesis state by setting the `GenesisState` fields to the 10 | store. In particular it sets the parameters and token mapping state. 11 | 12 | ## ExportGenesis 13 | 14 | The `ExportGenesis` ABCI function exports the genesis state of the Cronos module. In particular, it 15 | iterates all token mappings to genesis. 16 | -------------------------------------------------------------------------------- /x/cronos/spec/06_events.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | # Events 6 | 7 | The Cronos module emits the Cosmos SDK [events](./../../../docs/quickstart/events.md#sdk-and-tendermint-events) after a state execution. It can be expected that the type `message`, with an 8 | attribute key of `action` will represent the first event for each message being processed as emitted 9 | by the Cosmos SDK's `Baseapp` (i.e the basic application that implements Tendermint Core's ABCI 10 | interface). 11 | 12 | ## MsgConvertVouchers 13 | 14 | | Type | Attribute Key | Attribute Value | 15 | | ---------------- | ------------- | ------------------ | 16 | | convert_vouchers | `"sender"` | `{bech32_address}` | 17 | | convert_vouchers | `"amount"` | `{amount}` | 18 | | message | module | cronos | 19 | | message | action | ConvertVouchers | 20 | 21 | ## MsgTransferTokens 22 | 23 | | Type | Attribute Key | Attribute Value | 24 | | --------------- | ------------- | ------------------ | 25 | | transfer_tokens | `"sender"` | `{bech32_address}` | 26 | | transfer_tokens | `"recipient"` | `{bech32_address}` | 27 | | transfer_tokens | `"amount"` | `{amount}` | 28 | | message | module | cronos | 29 | | message | action | TransferTokens | 30 | 31 | ## MsgUpdateTokenMapping 32 | 33 | | Type | Attribute Key | Attribute Value | 34 | | ------- | ------------- | ------------------ | 35 | | message | action | UpdateTokenMapping | 36 | -------------------------------------------------------------------------------- /x/cronos/spec/README.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # `cronos` 9 | 10 | ## Abstract 11 | 12 | This document defines the specification of the Cronos module. 13 | 14 | ## Contents 15 | 16 | 1. **[Concepts](01_concepts.md)** 17 | 2. **[State](02_state.md)** 18 | 3. **[State Transitions](03_state_transitions.md)** 19 | 4. **[Messages](04_messages.md)** 20 | 5. **[ABCI](05_abci.md)** 21 | 6. **[Events](06_events.md)** 22 | 7. **[Parameters](07_params.md)** 23 | -------------------------------------------------------------------------------- /x/cronos/types/codec.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/cosmos/cosmos-sdk/codec" 5 | cdctypes "github.com/cosmos/cosmos-sdk/codec/types" 6 | sdk "github.com/cosmos/cosmos-sdk/types" 7 | "github.com/cosmos/cosmos-sdk/types/msgservice" 8 | govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" 9 | // this line is used by starport scaffolding # 1 10 | ) 11 | 12 | func RegisterCodec(cdc *codec.LegacyAmino) { 13 | // this line is used by starport scaffolding # 2 14 | cdc.RegisterConcrete(&TokenMappingChangeProposal{}, "cronos/TokenMappingChangeProposal", nil) 15 | } 16 | 17 | func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { 18 | // this line is used by starport scaffolding # 3 19 | registry.RegisterImplementations( 20 | (*govtypes.Content)(nil), 21 | &TokenMappingChangeProposal{}, 22 | ) 23 | 24 | registry.RegisterImplementations((*sdk.Msg)(nil), 25 | &MsgConvertVouchers{}, 26 | &MsgTransferTokens{}, 27 | &MsgUpdateTokenMapping{}, 28 | &MsgTurnBridge{}, 29 | &MsgUpdatePermissions{}, 30 | ) 31 | 32 | msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) 33 | } 34 | 35 | var ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) 36 | -------------------------------------------------------------------------------- /x/cronos/types/errors.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | // DONTCOVER 4 | 5 | import ( 6 | "cosmossdk.io/errors" 7 | ) 8 | 9 | const ( 10 | codeErrIbcCroDenomEmpty = uint32(iota) + 2 // NOTE: code 1 is reserved for internal errors 11 | codeErrIbcCroDenomInvalid 12 | ) 13 | 14 | // x/cronos module sentinel errors 15 | var ( 16 | ErrIbcCroDenomEmpty = errors.Register(ModuleName, codeErrIbcCroDenomEmpty, "ibc cro denom is not set") 17 | ErrIbcCroDenomInvalid = errors.Register(ModuleName, codeErrIbcCroDenomInvalid, "ibc cro denom is invalid") 18 | // this line is used by starport scaffolding # ibc/errors 19 | ) 20 | -------------------------------------------------------------------------------- /x/cronos/types/events.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "fmt" 5 | 6 | sdk "github.com/cosmos/cosmos-sdk/types" 7 | ) 8 | 9 | const ( 10 | AttributeValueCategory = ModuleName 11 | 12 | AttributeKeyRecipient = "recipient" 13 | AttributeKeySender = "sender" 14 | AttributeKeyAmount = "amount" 15 | AttributeKeyReceiver = "receiver" 16 | AttributeKeyEthereumTokenContract = "ethereum_token_contract" 17 | 18 | // events 19 | EventTypeConvertVouchers = "convert_vouchers" 20 | EventTypeTransferTokens = "transfer_tokens" 21 | EventTypeEthereumSendToCosmosHandled = "ethereum_send_to_cosmos_handled" 22 | ) 23 | 24 | // NewConvertVouchersEvent constructs a new voucher convert sdk.Event 25 | // nolint: interfacer 26 | func NewConvertVouchersEvent(sender string, amount fmt.Stringer) sdk.Event { 27 | return sdk.NewEvent( 28 | EventTypeConvertVouchers, 29 | sdk.NewAttribute(AttributeKeySender, sender), 30 | sdk.NewAttribute(sdk.AttributeKeyAmount, amount.String()), 31 | ) 32 | } 33 | 34 | // NewTransferTokensEvent constructs a new transfer sdk.Event 35 | func NewTransferTokensEvent(sender string, recipient string, amount fmt.Stringer) sdk.Event { 36 | return sdk.NewEvent( 37 | EventTypeTransferTokens, 38 | sdk.NewAttribute(AttributeKeySender, sender), 39 | sdk.NewAttribute(AttributeKeyRecipient, recipient), 40 | sdk.NewAttribute(sdk.AttributeKeyAmount, amount.String()), 41 | ) 42 | } 43 | -------------------------------------------------------------------------------- /x/cronos/types/genesis.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | // this line is used by starport scaffolding # genesis/types/import 4 | // this line is used by starport scaffolding # ibc/genesistype/import 5 | 6 | // DefaultIndex is the default capability global index 7 | const DefaultIndex uint64 = 1 8 | 9 | // DefaultGenesis returns the default Capability genesis state 10 | func DefaultGenesis() *GenesisState { 11 | return &GenesisState{ 12 | Params: DefaultParams(), 13 | // this line is used by starport scaffolding # ibc/genesistype/default 14 | // this line is used by starport scaffolding # genesis/types/default 15 | } 16 | } 17 | 18 | // Validate performs basic genesis state validation returning an error upon any 19 | // failure. 20 | func (gs GenesisState) Validate() error { 21 | // this line is used by starport scaffolding # ibc/genesistype/validate 22 | 23 | // this line is used by starport scaffolding # genesis/types/validate 24 | 25 | return gs.Params.Validate() 26 | } 27 | -------------------------------------------------------------------------------- /x/cronos/types/genesis_test.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | ) 8 | 9 | func TestGenesisStateValidate(t *testing.T) { 10 | testCases := []struct { 11 | name string 12 | genesisState GenesisState 13 | expErr bool 14 | }{ 15 | { 16 | "valid genesisState", 17 | GenesisState{ 18 | Params: DefaultParams(), 19 | }, 20 | false, 21 | }, 22 | { 23 | "valid invalid IBC param", 24 | GenesisState{ 25 | Params: Params{ 26 | IbcCroDenom: "aaa", 27 | }, 28 | }, 29 | true, 30 | }, 31 | } 32 | 33 | for _, tc := range testCases { 34 | tc := tc 35 | t.Run(tc.name, func(t *testing.T) { 36 | err := tc.genesisState.Validate() 37 | 38 | if tc.expErr { 39 | require.Error(t, err) 40 | } else { 41 | require.NoError(t, err) 42 | } 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /x/cronos/types/query.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | codectypes "github.com/cosmos/cosmos-sdk/codec/types" 5 | ) 6 | 7 | func (m ReplayBlockRequest) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { 8 | for _, msg := range m.Msgs { 9 | if err := msg.UnpackInterfaces(unpacker); err != nil { 10 | return err 11 | } 12 | } 13 | return nil 14 | } 15 | -------------------------------------------------------------------------------- /x/cronos/types/tracer.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "math/big" 5 | "time" 6 | 7 | "github.com/ethereum/go-ethereum/common" 8 | "github.com/ethereum/go-ethereum/core/vm" 9 | ) 10 | 11 | type DummyTracer struct{} 12 | 13 | func NewDummyTracer() *DummyTracer { 14 | return &DummyTracer{} 15 | } 16 | 17 | func (dt DummyTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) { 18 | } 19 | 20 | func (dt DummyTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) { 21 | } 22 | 23 | func (dt DummyTracer) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error) { 24 | } 25 | func (dt DummyTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) {} 26 | -------------------------------------------------------------------------------- /x/e2ee/README.md: -------------------------------------------------------------------------------- 1 | e2ee a module for end-to-end encrypted messaging, user can register encryption keys on chain, and receive encrypted 2 | messages on/off chain. 3 | -------------------------------------------------------------------------------- /x/e2ee/autocli.go: -------------------------------------------------------------------------------- 1 | package e2ee 2 | 3 | import ( 4 | autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" 5 | ) 6 | 7 | // AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. 8 | func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { 9 | return &autocliv1.ModuleOptions{ 10 | Query: &autocliv1.ServiceCommandDescriptor{ 11 | Service: "e2ee.Query", 12 | RpcCommandOptions: []*autocliv1.RpcCommandOptions{ 13 | { 14 | RpcMethod: "Key", 15 | Use: "key [address]", 16 | Short: "Query an encryption key by address", 17 | PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}}, 18 | }, 19 | { 20 | RpcMethod: "Keys", 21 | Use: "keys [addresses] ...", 22 | Short: "Query a batch of encryption key by addresses", 23 | PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "addresses", Varargs: true}}, 24 | }, 25 | }, 26 | }, 27 | Tx: &autocliv1.ServiceCommandDescriptor{ 28 | Service: "e2ee.Msg", 29 | RpcCommandOptions: []*autocliv1.RpcCommandOptions{ 30 | { 31 | RpcMethod: "RegisterEncryptionKey", 32 | Use: "register-encryption-key [key]", 33 | Short: "Register encryption key stores an public key for asymmetric encryption with the user address.", 34 | PositionalArgs: []*autocliv1.PositionalArgDescriptor{ 35 | {ProtoField: "key"}, 36 | }, 37 | }, 38 | }, 39 | }, 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /x/e2ee/client/cli/cmd.go: -------------------------------------------------------------------------------- 1 | package cli 2 | 3 | import "github.com/spf13/cobra" 4 | 5 | func E2EECommand() *cobra.Command { 6 | cmd := &cobra.Command{ 7 | Use: "e2ee", 8 | Short: "End-to-end encryption commands", 9 | } 10 | 11 | cmd.AddCommand( 12 | KeygenCommand(), 13 | EncryptCommand(), 14 | DecryptCommand(), 15 | EncryptToValidatorsCommand(), 16 | PubKeyCommand(), 17 | ) 18 | 19 | return cmd 20 | } 21 | -------------------------------------------------------------------------------- /x/e2ee/client/cli/generate.go: -------------------------------------------------------------------------------- 1 | package cli 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "filippo.io/age" 8 | "github.com/spf13/cobra" 9 | 10 | "github.com/cosmos/cosmos-sdk/client" 11 | 12 | "github.com/crypto-org-chain/cronos/v2/x/e2ee/keyring" 13 | "github.com/crypto-org-chain/cronos/v2/x/e2ee/types" 14 | ) 15 | 16 | const FlagKeyringName = "keyring-name" 17 | 18 | func KeygenCommand() *cobra.Command { 19 | cmd := &cobra.Command{ 20 | Use: "keygen", 21 | Short: "Generates a new native X25519 key pair", 22 | Args: cobra.NoArgs, 23 | RunE: func(cmd *cobra.Command, args []string) error { 24 | clientCtx, err := client.GetClientQueryContext(cmd) 25 | if err != nil { 26 | return err 27 | } 28 | 29 | krName, err := cmd.Flags().GetString(FlagKeyringName) 30 | if err != nil { 31 | return err 32 | } 33 | 34 | kr, err := keyring.New("cronosd", clientCtx.Keyring.Backend(), clientCtx.HomeDir, os.Stdin) 35 | if err != nil { 36 | return err 37 | } 38 | 39 | k, err := age.GenerateX25519Identity() 40 | if err != nil { 41 | return err 42 | } 43 | 44 | if err := kr.Set(krName, []byte(k.String())); err != nil { 45 | return err 46 | } 47 | 48 | fmt.Println(k.Recipient()) 49 | return nil 50 | }, 51 | } 52 | 53 | cmd.Flags().String(FlagKeyringName, types.DefaultKeyringName, "The keyring name to use") 54 | 55 | return cmd 56 | } 57 | -------------------------------------------------------------------------------- /x/e2ee/client/cli/pubkey.go: -------------------------------------------------------------------------------- 1 | package cli 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "filippo.io/age" 8 | "github.com/cosmos/cosmos-sdk/client" 9 | "github.com/crypto-org-chain/cronos/v2/x/e2ee/keyring" 10 | "github.com/crypto-org-chain/cronos/v2/x/e2ee/types" 11 | "github.com/spf13/cobra" 12 | ) 13 | 14 | func PubKeyCommand() *cobra.Command { 15 | cmd := &cobra.Command{ 16 | Use: "pubkey", 17 | Short: "Show the recipient of current identity stored in keyring", 18 | Args: cobra.NoArgs, 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | clientCtx, err := client.GetClientQueryContext(cmd) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | krName, err := cmd.Flags().GetString(FlagKeyringName) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | kr, err := keyring.New("cronosd", clientCtx.Keyring.Backend(), clientCtx.HomeDir, os.Stdin) 31 | if err != nil { 32 | return err 33 | } 34 | 35 | bz, err := kr.Get(krName) 36 | if err != nil { 37 | return err 38 | } 39 | 40 | k, err := age.ParseX25519Identity(string(bz)) 41 | if err != nil { 42 | return err 43 | } 44 | 45 | fmt.Println(k.Recipient()) 46 | return nil 47 | }, 48 | } 49 | 50 | cmd.Flags().String(FlagKeyringName, types.DefaultKeyringName, "The keyring name to use") 51 | 52 | return cmd 53 | } 54 | -------------------------------------------------------------------------------- /x/e2ee/client/cli/tx.go: -------------------------------------------------------------------------------- 1 | package cli 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/cosmos/cosmos-sdk/client" 7 | "github.com/cosmos/cosmos-sdk/client/flags" 8 | "github.com/cosmos/cosmos-sdk/client/tx" 9 | "github.com/crypto-org-chain/cronos/v2/x/e2ee/types" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | // GetTxCmd returns the transaction commands for this module 14 | func GetTxCmd() *cobra.Command { 15 | cmd := &cobra.Command{ 16 | Use: types.ModuleName, 17 | Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), 18 | DisableFlagParsing: true, 19 | SuggestionsMinimumDistance: 2, 20 | RunE: client.ValidateCmd, 21 | } 22 | cmd.AddCommand(CmdRegisterAccount()) 23 | return cmd 24 | } 25 | 26 | func CmdRegisterAccount() *cobra.Command { 27 | cmd := &cobra.Command{ 28 | Use: "register-encryption-key [key]", 29 | Short: "Register encryption key stores an public key for asymmetric encryption with the user address.", 30 | Args: cobra.ExactArgs(1), 31 | RunE: func(cmd *cobra.Command, args []string) (err error) { 32 | clientCtx, err := client.GetClientTxContext(cmd) 33 | if err != nil { 34 | return err 35 | } 36 | msg := types.MsgRegisterEncryptionKey{ 37 | Address: clientCtx.GetFromAddress().String(), 38 | Key: args[0], 39 | } 40 | if err := msg.ValidateBasic(); err != nil { 41 | return err 42 | } 43 | return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) 44 | }, 45 | } 46 | 47 | flags.AddTxFlagsToCmd(cmd) 48 | 49 | return cmd 50 | } 51 | -------------------------------------------------------------------------------- /x/e2ee/keyring/keyring_test.go: -------------------------------------------------------------------------------- 1 | package keyring 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "testing" 7 | 8 | "filippo.io/age" 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/cosmos/cosmos-sdk/crypto/keyring" 12 | ) 13 | 14 | func TestKeyring(t *testing.T) { 15 | kr, err := New("cronosd", keyring.BackendTest, t.TempDir(), nil) 16 | require.NoError(t, err) 17 | 18 | identity, err := age.GenerateX25519Identity() 19 | require.NoError(t, err) 20 | 21 | var ciphertext []byte 22 | { 23 | dst := bytes.NewBuffer(nil) 24 | writer, err := age.Encrypt(dst, identity.Recipient()) 25 | require.NoError(t, err) 26 | writer.Write([]byte("test")) 27 | writer.Close() 28 | ciphertext = dst.Bytes() 29 | } 30 | 31 | require.NoError(t, kr.Set("test", []byte(identity.String()))) 32 | 33 | secret, err := kr.Get("test") 34 | require.NoError(t, err) 35 | 36 | identity, err = age.ParseX25519Identity(string(secret)) 37 | require.NoError(t, err) 38 | 39 | { 40 | reader, err := age.Decrypt(bytes.NewReader(ciphertext), identity) 41 | require.NoError(t, err) 42 | bz, err := io.ReadAll(reader) 43 | require.NoError(t, err) 44 | 45 | require.Equal(t, []byte("test"), bz) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /x/e2ee/types/codec.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/cosmos/cosmos-sdk/codec" 5 | "github.com/cosmos/cosmos-sdk/codec/types" 6 | sdk "github.com/cosmos/cosmos-sdk/types" 7 | "github.com/cosmos/cosmos-sdk/types/msgservice" 8 | ) 9 | 10 | // RegisterLegacyAminoCodec registers the necessary x/e2ee interfaces and concrete types 11 | // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. 12 | func RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {} 13 | 14 | func RegisterInterfaces(registry types.InterfaceRegistry) { 15 | registry.RegisterImplementations((*sdk.Msg)(nil), 16 | &MsgRegisterEncryptionKey{}, 17 | ) 18 | 19 | msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) 20 | } 21 | -------------------------------------------------------------------------------- /x/e2ee/types/genesis.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | // DefaultGenesis returns the default Capability genesis state 4 | func DefaultGenesis() *GenesisState { 5 | return &GenesisState{} 6 | } 7 | 8 | // Validate performs basic genesis state validation returning an error upon any 9 | // failure. 10 | func (gs GenesisState) Validate() error { 11 | for _, key := range gs.Keys { 12 | if err := key.Validate(); err != nil { 13 | return err 14 | } 15 | } 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /x/e2ee/types/keys.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | sdk "github.com/cosmos/cosmos-sdk/types" 5 | ) 6 | 7 | const ( 8 | // ModuleName defines the module name 9 | ModuleName = "e2ee" 10 | 11 | // StoreKey defines the primary module store key 12 | StoreKey = ModuleName 13 | 14 | // RouterKey is the message route for e2ee 15 | RouterKey = ModuleName 16 | ) 17 | 18 | const ( 19 | DefaultKeyringName = "e2ee-identity" 20 | ) 21 | 22 | const ( 23 | prefixEncryptionKey = iota + 1 24 | ) 25 | 26 | var KeyPrefixEncryptionKey = []byte{prefixEncryptionKey} 27 | 28 | func KeyPrefix(addr sdk.AccAddress) []byte { 29 | key := make([]byte, 1+len(addr)) 30 | key[0] = prefixEncryptionKey 31 | copy(key[1:], addr) 32 | return key 33 | } 34 | 35 | // Validate checks for address and key correctness. 36 | func (e EncryptionKeyEntry) Validate() error { 37 | if _, err := sdk.AccAddressFromBech32(e.Address); err != nil { 38 | return err 39 | } 40 | return ValidateRecipientKey(e.Key) 41 | } 42 | -------------------------------------------------------------------------------- /x/e2ee/types/msg.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | fmt "fmt" 5 | 6 | "filippo.io/age" 7 | sdk "github.com/cosmos/cosmos-sdk/types" 8 | ) 9 | 10 | var _ sdk.Msg = (*MsgRegisterEncryptionKey)(nil) 11 | 12 | func (m *MsgRegisterEncryptionKey) ValidateBasic() error { 13 | // validate bech32 format of Address 14 | if _, err := sdk.AccAddressFromBech32(m.Address); err != nil { 15 | return fmt.Errorf("invalid address: %s", err) 16 | } 17 | return ValidateRecipientKey(m.Key) 18 | } 19 | 20 | func ValidateRecipientKey(key string) error { 21 | _, err := age.ParseX25519Recipient(key) 22 | return err 23 | } 24 | --------------------------------------------------------------------------------