├── .circleci └── config.yml ├── .editorconfig ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .mergify.yml ├── .prettierignore ├── .prettierrc.json ├── .vscode └── settings.json ├── CHANGELOG-pre1.0.0.md ├── CHANGELOG.md ├── Cargo.lock ├── Cargo.toml ├── EntryPoints.md ├── IBC.md ├── LICENSE ├── MIGRATING.md ├── NOTICE ├── README.md ├── SECURITY.md ├── SEMANTICS.md ├── codecov.yml ├── contracts ├── README.md ├── burner │ ├── .cargo │ │ └── config │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ ├── schema │ │ ├── burner.json │ │ └── raw │ │ │ ├── instantiate.json │ │ │ └── migrate.json │ ├── src │ │ ├── bin │ │ │ └── schema.rs │ │ ├── contract.rs │ │ ├── lib.rs │ │ └── msg.rs │ └── tests │ │ └── integration.rs ├── crypto-verify │ ├── .cargo │ │ └── config │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ ├── schema │ │ ├── crypto-verify.json │ │ └── raw │ │ │ ├── instantiate.json │ │ │ ├── query.json │ │ │ ├── response_to_list_verification_schemes.json │ │ │ ├── response_to_verify_cosmos_signature.json │ │ │ ├── response_to_verify_ethereum_text.json │ │ │ ├── response_to_verify_ethereum_transaction.json │ │ │ ├── response_to_verify_secp256_r1_signature.json │ │ │ ├── response_to_verify_tendermint_batch.json │ │ │ ├── response_to_verify_tendermint_signature.json │ │ │ └── response_to_verify_webauthn.json │ ├── src │ │ ├── bin │ │ │ └── schema.rs │ │ ├── contract.rs │ │ ├── ethereum.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ └── webauthn.rs │ └── tests │ │ └── integration.rs ├── cyberpunk │ ├── .cargo │ │ └── config │ ├── Cargo.lock │ ├── Cargo.toml │ ├── schema │ │ ├── cyberpunk.json │ │ └── raw │ │ │ ├── execute.json │ │ │ ├── instantiate.json │ │ │ ├── migrate.json │ │ │ ├── query.json │ │ │ ├── response_to_denom.json │ │ │ ├── response_to_denoms.json │ │ │ ├── response_to_mirror_env.json │ │ │ └── sudo.json │ ├── src │ │ ├── bin │ │ │ └── schema.rs │ │ ├── contract.rs │ │ ├── errors.rs │ │ ├── lib.rs │ │ └── msg.rs │ └── tests │ │ └── integration.rs ├── empty │ ├── .cargo │ │ └── config │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ ├── schema │ │ └── empty.json │ ├── src │ │ ├── bin │ │ │ └── schema.rs │ │ └── lib.rs │ └── tests │ │ └── integration.rs ├── floaty │ ├── .cargo │ │ └── config │ ├── .vscode │ │ └── settings.json │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ ├── schema │ │ ├── floaty.json │ │ └── raw │ │ │ ├── execute.json │ │ │ ├── instantiate.json │ │ │ ├── migrate.json │ │ │ ├── query.json │ │ │ ├── response_to_instructions.json │ │ │ ├── response_to_other_balance.json │ │ │ ├── response_to_random_args_for.json │ │ │ ├── response_to_run.json │ │ │ ├── response_to_verifier.json │ │ │ └── sudo.json │ ├── src │ │ ├── bin │ │ │ └── schema.rs │ │ ├── contract.rs │ │ ├── floats.rs │ │ ├── instructions.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ └── state.rs │ └── tests │ │ └── integration.rs ├── hackatom │ ├── .cargo │ │ └── config │ ├── Cargo.lock │ ├── Cargo.toml │ ├── schema │ │ ├── hackatom.json │ │ └── raw │ │ │ ├── execute.json │ │ │ ├── instantiate.json │ │ │ ├── migrate.json │ │ │ ├── query.json │ │ │ ├── response_to_get_int.json │ │ │ ├── response_to_other_balance.json │ │ │ ├── response_to_recurse.json │ │ │ ├── response_to_verifier.json │ │ │ └── sudo.json │ ├── src │ │ ├── bin │ │ │ └── schema.rs │ │ ├── contract.rs │ │ ├── errors.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ └── state.rs │ └── tests │ │ └── integration.rs ├── ibc-reflect-send │ ├── .cargo │ │ └── config │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ ├── schema │ │ ├── ibc-reflect-send.json │ │ ├── ibc │ │ │ ├── acknowledgement_msg_balances.json │ │ │ ├── acknowledgement_msg_dispatch.json │ │ │ ├── acknowledgement_msg_who_am_i.json │ │ │ └── packet_msg.json │ │ └── raw │ │ │ ├── execute.json │ │ │ ├── instantiate.json │ │ │ ├── migrate.json │ │ │ ├── query.json │ │ │ ├── response_to_account.json │ │ │ ├── response_to_admin.json │ │ │ ├── response_to_list_accounts.json │ │ │ └── sudo.json │ ├── src │ │ ├── bin │ │ │ └── schema.rs │ │ ├── contract.rs │ │ ├── ibc.rs │ │ ├── ibc_msg.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ └── state.rs │ └── tests │ │ └── integration.rs ├── ibc-reflect │ ├── .cargo │ │ └── config │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ ├── schema │ │ ├── ibc-reflect.json │ │ ├── ibc │ │ │ ├── acknowledgement_msg_balances.json │ │ │ ├── acknowledgement_msg_dispatch.json │ │ │ ├── acknowledgement_msg_who_am_i.json │ │ │ └── packet_msg.json │ │ └── raw │ │ │ ├── instantiate.json │ │ │ ├── migrate.json │ │ │ ├── query.json │ │ │ ├── response_to_account.json │ │ │ └── response_to_list_accounts.json │ ├── src │ │ ├── bin │ │ │ └── schema.rs │ │ ├── contract.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ └── state.rs │ └── tests │ │ └── integration.rs ├── queue │ ├── .cargo │ │ └── config │ ├── Cargo.lock │ ├── Cargo.toml │ ├── schema │ │ ├── queue.json │ │ └── raw │ │ │ ├── execute.json │ │ │ ├── instantiate.json │ │ │ ├── migrate.json │ │ │ ├── query.json │ │ │ ├── response_to_count.json │ │ │ ├── response_to_list.json │ │ │ ├── response_to_open_iterators.json │ │ │ ├── response_to_reducer.json │ │ │ ├── response_to_sum.json │ │ │ └── sudo.json │ ├── src │ │ ├── bin │ │ │ └── schema.rs │ │ ├── contract.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ └── state.rs │ └── tests │ │ └── integration.rs ├── reflect │ ├── .cargo │ │ └── config │ ├── .editorconfig │ ├── .gitignore │ ├── Cargo.lock │ ├── Cargo.toml │ ├── LICENSE │ ├── NOTICE │ ├── README.md │ ├── schema │ │ ├── raw │ │ │ ├── execute.json │ │ │ ├── instantiate.json │ │ │ ├── migrate.json │ │ │ ├── query.json │ │ │ ├── response_to_capitalized.json │ │ │ ├── response_to_chain.json │ │ │ ├── response_to_owner.json │ │ │ ├── response_to_raw.json │ │ │ ├── response_to_sub_msg_result.json │ │ │ └── sudo.json │ │ └── reflect.json │ ├── src │ │ ├── bin │ │ │ └── schema.rs │ │ ├── contract.rs │ │ ├── errors.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ ├── state.rs │ │ └── testing.rs │ └── tests │ │ └── integration.rs ├── staking │ ├── .cargo │ │ └── config │ ├── Cargo.lock │ ├── Cargo.toml │ ├── LICENSE │ ├── NOTICE │ ├── README.md │ ├── schema │ │ ├── raw │ │ │ ├── execute.json │ │ │ ├── instantiate.json │ │ │ ├── migrate.json │ │ │ ├── query.json │ │ │ ├── response_to_balance.json │ │ │ ├── response_to_claims.json │ │ │ ├── response_to_investment.json │ │ │ ├── response_to_token_info.json │ │ │ └── sudo.json │ │ └── staking.json │ ├── src │ │ ├── bin │ │ │ └── schema.rs │ │ ├── contract.rs │ │ ├── errors.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ └── state.rs │ └── tests │ │ └── integration.rs └── virus │ ├── .cargo │ └── config │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ ├── schema │ ├── raw │ │ ├── execute.json │ │ └── instantiate.json │ └── virus.json │ ├── src │ ├── bin │ │ └── schema.rs │ ├── contract.rs │ ├── errors.rs │ ├── lib.rs │ └── msg.rs │ └── tests │ └── integration.rs ├── deny.toml ├── devtools ├── build_min.sh ├── check_contracts_fast.sh ├── check_contracts_full.sh ├── check_contracts_medium.sh ├── check_workspace.sh ├── clean.sh ├── clean_contracts.sh ├── deadlinks.py ├── format_md.sh ├── format_sh.sh ├── format_yml.sh ├── release_checks.sh ├── test_workspace.sh └── update_crate.sh ├── docs ├── CAPABILITIES-BUILT-IN.md ├── CAPABILITIES.md ├── ERROR_HANDLING.md ├── FEATURES.md ├── GAS.md ├── MESSAGE_TYPES.md ├── MSRV.md ├── PINNING.md ├── STORAGE_KEYS.md ├── USING_COSMWASM_STD.md ├── idl.md └── simulate_riffle_shuffle.py └── packages ├── check ├── Cargo.toml ├── README.md ├── src │ └── main.rs └── tests │ └── cosmwasm_check_tests.rs ├── core ├── .cargo │ └── config ├── Cargo.toml ├── README.md ├── src │ ├── __internal.rs │ ├── addresses.rs │ ├── binary.rs │ ├── encoding.rs │ ├── errors │ │ ├── backtrace.rs │ │ ├── core_error.rs │ │ ├── mod.rs │ │ ├── recover_pubkey_error.rs │ │ ├── system_error.rs │ │ └── verification_error.rs │ ├── forward_ref.rs │ ├── hex_binary.rs │ ├── lib.rs │ ├── math │ │ ├── conversion.rs │ │ ├── decimal.rs │ │ ├── decimal256.rs │ │ ├── fraction.rs │ │ ├── int128.rs │ │ ├── int256.rs │ │ ├── int512.rs │ │ ├── int64.rs │ │ ├── isqrt.rs │ │ ├── mod.rs │ │ ├── num_consts.rs │ │ ├── signed_decimal.rs │ │ ├── signed_decimal_256.rs │ │ ├── uint128.rs │ │ ├── uint256.rs │ │ ├── uint512.rs │ │ └── uint64.rs │ ├── testing │ │ ├── assertions.rs │ │ └── mod.rs │ └── timestamp.rs └── testdata │ └── instantiate2_addresses.json ├── crypto ├── Cargo.toml ├── README.md ├── benches │ └── main.rs ├── src │ ├── backtrace.rs │ ├── ecdsa.rs │ ├── ed25519.rs │ ├── errors.rs │ ├── identity_digest.rs │ ├── lib.rs │ ├── secp256k1.rs │ └── secp256r1.rs ├── testdata │ ├── 186-4ecdsatestvectors │ │ ├── Readme.txt │ │ └── SigGen.txt │ ├── ed25519_tests.json │ ├── extract_sig_gen.sh │ ├── rootberg │ │ ├── README.md │ │ ├── ecdsa_secp256k1_keccak256_raw.json │ │ ├── ecdsa_secp256k1_sha_256_raw.json │ │ ├── ecdsa_secp256r1_keccak256_raw.json │ │ └── ecdsa_secp256r1_sha_256_raw.json │ ├── secp256k1_tests.json │ ├── secp256r1_tests.json │ └── wycheproof │ │ ├── README.md │ │ ├── ecdsa_secp256k1_sha256_test.json │ │ ├── ecdsa_secp256k1_sha3_256_test.json │ │ ├── ecdsa_secp256k1_sha3_512_test.json │ │ ├── ecdsa_secp256k1_sha512_test.json │ │ ├── ecdsa_secp256r1_sha256_test.json │ │ ├── ecdsa_secp256r1_sha3_256_test.json │ │ ├── ecdsa_secp256r1_sha3_512_test.json │ │ └── ecdsa_secp256r1_sha512_test.json └── tests │ ├── hashers.rs │ ├── rootberg.rs │ ├── rootberg_secp256k1.rs │ ├── rootberg_secp256r1.rs │ ├── wycheproof.rs │ ├── wycheproof_secp256k1.rs │ └── wycheproof_secp256r1.rs ├── derive ├── Cargo.toml ├── README.md └── src │ └── lib.rs ├── go-gen ├── Cargo.toml ├── README.md ├── src │ ├── go.rs │ ├── main.rs │ ├── schema.rs │ └── utils.rs └── tests │ ├── cosmwasm_std__AllBalanceResponse.go │ ├── cosmwasm_std__AllDelegationsResponse.go │ ├── cosmwasm_std__AllDenomMetadataResponse.go │ ├── cosmwasm_std__AllValidatorsResponse.go │ ├── cosmwasm_std__BalanceResponse.go │ ├── cosmwasm_std__BankMsg.go │ ├── cosmwasm_std__BankQuery.go │ ├── cosmwasm_std__BondedDenomResponse.go │ ├── cosmwasm_std__CodeInfoResponse.go │ ├── cosmwasm_std__ContractInfoResponse.go │ ├── cosmwasm_std__DelegationResponse.go │ ├── cosmwasm_std__DelegationRewardsResponse.go │ ├── cosmwasm_std__DelegationTotalRewardsResponse.go │ ├── cosmwasm_std__DelegatorValidatorsResponse.go │ ├── cosmwasm_std__DelegatorWithdrawAddressResponse.go │ ├── cosmwasm_std__DenomMetadataResponse.go │ ├── cosmwasm_std__DistributionMsg.go │ ├── cosmwasm_std__DistributionQuery.go │ ├── cosmwasm_std__GovMsg.go │ ├── cosmwasm_std__IbcMsg.go │ ├── cosmwasm_std__IbcQuery.go │ ├── cosmwasm_std__StakingMsg.go │ ├── cosmwasm_std__StakingQuery.go │ ├── cosmwasm_std__SupplyResponse.go │ ├── cosmwasm_std__ValidatorResponse.go │ ├── cosmwasm_std__WasmMsg.go │ └── cosmwasm_std__WasmQuery.go ├── schema-derive ├── Cargo.toml ├── README.md └── src │ ├── cw_serde.rs │ ├── error.rs │ ├── generate_api.rs │ ├── lib.rs │ ├── query_responses.rs │ └── query_responses │ └── context.rs ├── schema ├── .gitignore ├── Cargo.toml ├── README.md ├── src │ ├── casing.rs │ ├── export.rs │ ├── idl.rs │ ├── lib.rs │ ├── query_response.rs │ ├── remove.rs │ └── schema_for.rs └── tests │ └── idl.rs ├── std ├── .cargo │ └── config ├── Cargo.toml ├── README.md └── src │ ├── assertions.rs │ ├── checksum.rs │ ├── coin.rs │ ├── coins.rs │ ├── conversion.rs │ ├── deps.rs │ ├── exports.rs │ ├── ibc.rs │ ├── import_helpers.rs │ ├── imports.rs │ ├── iterator.rs │ ├── lib.rs │ ├── memory.rs │ ├── metadata.rs │ ├── never.rs │ ├── pagination.rs │ ├── panic.rs │ ├── prelude.rs │ ├── query │ ├── bank.rs │ ├── distribution.rs │ ├── ibc.rs │ ├── mod.rs │ ├── query_response.rs │ ├── staking.rs │ └── wasm.rs │ ├── results │ ├── contract_result.rs │ ├── cosmos_msg.rs │ ├── empty.rs │ ├── events.rs │ ├── mod.rs │ ├── query.rs │ ├── response.rs │ ├── submessages.rs │ └── system_result.rs │ ├── sections.rs │ ├── serde.rs │ ├── stdack.rs │ ├── storage.rs │ ├── storage_keys │ ├── length_prefixed.rs │ └── mod.rs │ ├── testing │ ├── mock.rs │ └── mod.rs │ ├── traits.rs │ └── types.rs └── vm ├── Cargo.toml ├── README.md ├── benches └── main.rs ├── examples ├── heap_profiling.rs ├── module_size.rs ├── module_size.sh └── multi_threaded_cache.rs ├── src ├── backend.rs ├── cache.rs ├── calls.rs ├── capabilities.rs ├── compatibility.rs ├── conversion.rs ├── environment.rs ├── errors │ ├── backtrace.rs │ ├── communication_error.rs │ ├── mod.rs │ ├── region_validation_error.rs │ └── vm_error.rs ├── filesystem.rs ├── imports.rs ├── instance.rs ├── lib.rs ├── limited.rs ├── memory.rs ├── modules │ ├── cached_module.rs │ ├── file_system_cache.rs │ ├── in_memory_cache.rs │ ├── mod.rs │ ├── pinned_memory_cache.rs │ └── versioning.rs ├── parsed_wasm.rs ├── sections.rs ├── serde.rs ├── size.rs ├── static_analysis.rs ├── testing │ ├── calls.rs │ ├── instance.rs │ ├── mock.rs │ ├── mod.rs │ ├── querier.rs │ └── storage.rs └── wasm_backend │ ├── compile.rs │ ├── engine.rs │ ├── gatekeeper.rs │ ├── limiting_tunables.rs │ └── mod.rs └── testdata ├── README.md ├── corrupted.wasm ├── cyberpunk.wasm ├── cyberpunk_rust170.wasm ├── empty.wasm ├── floaty.wasm ├── floaty_0.16.wasm ├── floaty_1.0.wasm ├── floaty_1.2.wasm ├── floaty_2.0.wasm ├── hackatom.wasm ├── hackatom_0.10.wasm ├── hackatom_0.11.wasm ├── hackatom_0.12.wasm ├── hackatom_0.14.wasm ├── hackatom_0.15.wasm ├── hackatom_0.16.wasm ├── hackatom_0.7.wasm ├── hackatom_0.8.wasm ├── hackatom_0.9.wasm ├── hackatom_1.0.wasm ├── hackatom_1.2.wasm ├── ibc_reflect.wasm ├── ibc_reflect_0.14.wasm ├── ibc_reflect_0.15.wasm ├── ibc_reflect_0.16.wasm ├── ibc_reflect_1.0.wasm └── ibc_reflect_1.2.wasm /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.rs] 11 | indent_size = 4 12 | 13 | [*.py] 14 | indent_size = 4 15 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Contract Development 2 | 3 | # Pushes to long living branches and all PRs 4 | on: 5 | push: 6 | branches: 7 | - main 8 | - 0.[0-9]+ 9 | pull_request: 10 | 11 | env: 12 | RUST_BACKTRACE: 1 13 | 14 | jobs: 15 | test-hackatom: 16 | name: ${{ matrix.build }} 17 | runs-on: ${{ matrix.os }} 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | include: 22 | - build: macOS 23 | os: macOS-latest 24 | - build: Windows 25 | os: windows-latest 26 | defaults: 27 | run: 28 | shell: bash 29 | working-directory: ./contracts/hackatom 30 | steps: 31 | - name: Checkout sources 32 | uses: actions/checkout@v4 33 | - name: Install Rust 34 | uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: 1.73.0 37 | targets: wasm32-unknown-unknown 38 | - name: Build hackatom wasm 39 | run: cargo wasm --locked 40 | - name: Unit Test hackatom 41 | run: cargo unit-test --locked 42 | - name: Integration Test hackatom 43 | run: cargo integration-test --locked 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # macOS 2 | .DS_Store 3 | 4 | # Text file backups 5 | **/*.rs.bk 6 | 7 | # Build results 8 | target/ 9 | artifacts/ 10 | 11 | # IDEs 12 | .idea/ 13 | *.iml 14 | 15 | # Auto-gen 16 | .cargo-ok 17 | 18 | # Log files (e.g. memory profiling) 19 | *.log 20 | dhat-heap.json 21 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # Used for *.md formatting in devtools/format_md.sh 2 | target/ 3 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "overrides": [ 3 | { 4 | "files": "*.md", 5 | "options": { 6 | "proseWrap": "always" 7 | } 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.cargo.features": [ 3 | "abort", 4 | "stargate", 5 | "staking", 6 | "cosmwasm_2_0" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["packages/*"] 3 | exclude = ["contracts"] 4 | 5 | # Resolver has to be set explicitely in workspaces 6 | # due to https://github.com/rust-lang/cargo/issues/9956 7 | resolver = "2" 8 | 9 | [workspace.package] 10 | version = "2.0.1" 11 | 12 | [workspace.dependencies] 13 | schemars = "0.8.4" 14 | serde = { version = "1.0.192", default-features = false, features = ["derive", "alloc"] } 15 | 16 | [workspace.metadata.release] 17 | shared-version = true 18 | tag-message = "chore: Release cosmwasm v{{version}}" 19 | tag-name = "v{{version}}" 20 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Jehan Tremback 2 | Copyright 2019-2021 Confio OÜ 3 | Copyright 2019-2020 Simon Warta 4 | Copyright 2021 Confio GmbH 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | This repository is maintained by Confio as part of the CosmWasm stack. Please 4 | see https://github.com/CosmWasm/advisories/blob/main/SECURITY.md for our 5 | security policy. 6 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | threshold: 0.05% 8 | patch: 9 | default: 10 | threshold: 0.05% 11 | 12 | ignore: 13 | - "contracts" 14 | # Disabled due to "cargo_tarpaulin: Failed to get test coverage! Error: Failed to run tests: Error running test - SIGILL raised in 5835" 15 | - "packages/vm" 16 | 17 | flags: 18 | cosmwasm-crypto: 19 | paths: 20 | - packages/crypto/ 21 | cosmwasm-derive: 22 | paths: 23 | - packages/derive/ 24 | cosmwasm-schema: 25 | paths: 26 | - packages/schema/ 27 | cosmwasm-schema-derive: 28 | paths: 29 | - packages/schema-derive/ 30 | cosmwasm-std: 31 | paths: 32 | - packages/std/ 33 | -------------------------------------------------------------------------------- /contracts/burner/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/burner/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "burner" 3 | version = "0.0.0" 4 | authors = ["Ethan Frey ", "Simon Warta "] 5 | edition = "2021" 6 | publish = false 7 | license = "Apache-2.0" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [lib] 12 | crate-type = ["cdylib", "rlib"] 13 | 14 | [profile.release] 15 | opt-level = 3 16 | debug = false 17 | rpath = false 18 | lto = true 19 | debug-assertions = false 20 | codegen-units = 1 21 | panic = 'abort' 22 | incremental = false 23 | overflow-checks = true 24 | 25 | [features] 26 | # Add feature "cranelift" to default if you need 32 bit or ARM support 27 | default = [] 28 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 29 | cranelift = ["cosmwasm-vm/cranelift"] 30 | 31 | 32 | [dependencies] 33 | cosmwasm-schema = { path = "../../packages/schema" } 34 | cosmwasm-std = { path = "../../packages/std", features = ["iterator", "cosmwasm_1_4"] } 35 | schemars = "0.8.12" 36 | serde = { version = "1.0.103", default-features = false, features = ["derive"] } 37 | 38 | [dev-dependencies] 39 | cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] } 40 | -------------------------------------------------------------------------------- /contracts/burner/README.md: -------------------------------------------------------------------------------- 1 | # Burner Contract 2 | 3 | This is a simple contract to demonstrate using migrations to shutdown (or 4 | "burn") contracts using the migration feature added in CosmWasm 0.9. 5 | 6 | This contract cannot be installed directly (via `instantiate`), but is only 7 | designed to be used for `migrate`. When migrating any existing contract to this 8 | burner contract, we delete all storage and send all bank tokens to a specified 9 | address, doing a basic cleanup of the contract. 10 | 11 | You can use this contract as-is, or fork it and customize it more if you want to 12 | do more detailed cleanup. 13 | -------------------------------------------------------------------------------- /contracts/burner/schema/burner.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract_name": "burner", 3 | "contract_version": "0.0.0", 4 | "idl_version": "1.0.0", 5 | "instantiate": { 6 | "$schema": "http://json-schema.org/draft-07/schema#", 7 | "title": "InstantiateMsg", 8 | "description": "A placeholder where we don't take any input", 9 | "type": "object", 10 | "additionalProperties": false 11 | }, 12 | "execute": null, 13 | "query": null, 14 | "migrate": { 15 | "$schema": "http://json-schema.org/draft-07/schema#", 16 | "title": "MigrateMsg", 17 | "type": "object", 18 | "required": [ 19 | "payout" 20 | ], 21 | "properties": { 22 | "delete": { 23 | "description": "Optional amount of items to delete in this call. If it is not provided, nothing will be deleted. You can delete further items in a subsequent execute call.", 24 | "default": 0, 25 | "type": "integer", 26 | "format": "uint32", 27 | "minimum": 0.0 28 | }, 29 | "payout": { 30 | "description": "The address we send all remaining balance to", 31 | "type": "string" 32 | } 33 | }, 34 | "additionalProperties": false 35 | }, 36 | "sudo": null, 37 | "responses": null 38 | } 39 | -------------------------------------------------------------------------------- /contracts/burner/schema/raw/instantiate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "InstantiateMsg", 4 | "description": "A placeholder where we don't take any input", 5 | "type": "object", 6 | "additionalProperties": false 7 | } 8 | -------------------------------------------------------------------------------- /contracts/burner/schema/raw/migrate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "MigrateMsg", 4 | "type": "object", 5 | "required": [ 6 | "payout" 7 | ], 8 | "properties": { 9 | "delete": { 10 | "description": "Optional amount of items to delete in this call. If it is not provided, nothing will be deleted. You can delete further items in a subsequent execute call.", 11 | "default": 0, 12 | "type": "integer", 13 | "format": "uint32", 14 | "minimum": 0.0 15 | }, 16 | "payout": { 17 | "description": "The address we send all remaining balance to", 18 | "type": "string" 19 | } 20 | }, 21 | "additionalProperties": false 22 | } 23 | -------------------------------------------------------------------------------- /contracts/burner/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | 3 | use burner::msg::{InstantiateMsg, MigrateMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | migrate: MigrateMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/burner/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod msg; 3 | -------------------------------------------------------------------------------- /contracts/burner/src/msg.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | 3 | #[cw_serde] 4 | pub struct MigrateMsg { 5 | /// The address we send all remaining balance to 6 | pub payout: String, 7 | /// Optional amount of items to delete in this call. 8 | /// If it is not provided, nothing will be deleted. 9 | /// You can delete further items in a subsequent execute call. 10 | #[serde(default)] 11 | pub delete: u32, 12 | } 13 | 14 | /// A placeholder where we don't take any input 15 | #[cw_serde] 16 | pub struct InstantiateMsg {} 17 | 18 | #[cw_serde] 19 | pub enum ExecuteMsg { 20 | /// Cleans up the given number of state elements. 21 | /// Call this multiple times to increamentally clean up state. 22 | Cleanup { 23 | /// The number of state elements to delete. 24 | /// 25 | /// Set this to None for unlimited cleanup (if your state is small or you are feeling YOLO) 26 | limit: Option, 27 | }, 28 | } 29 | -------------------------------------------------------------------------------- /contracts/crypto-verify/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/crypto-verify/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "crypto-verify" 3 | version = "0.0.0" 4 | authors = ["Mauro Lacy "] 5 | edition = "2021" 6 | publish = false 7 | license = "Apache-2.0" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [lib] 12 | crate-type = ["cdylib", "rlib"] 13 | 14 | [profile.release] 15 | opt-level = 3 16 | debug = false 17 | rpath = false 18 | lto = true 19 | debug-assertions = false 20 | codegen-units = 1 21 | panic = 'abort' 22 | incremental = false 23 | overflow-checks = true 24 | 25 | [features] 26 | # Add feature "cranelift" to default if you need 32 bit or ARM support 27 | default = [] 28 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 29 | cranelift = ["cosmwasm-vm/cranelift"] 30 | 31 | [dependencies] 32 | base64 = "0.22.0" 33 | cosmwasm-schema = { path = "../../packages/schema" } 34 | cosmwasm-std = { path = "../../packages/std", features = ["cosmwasm_2_1", "iterator"] } 35 | hex = "0.4" 36 | p256 = { version = "0.13.2", default-features = false, features = ["alloc", "ecdsa"] } 37 | rlp = "0.5" 38 | schemars = "0.8.12" 39 | serde = { version = "1.0.103", default-features = false, features = ["derive"] } 40 | sha2 = "0.10" 41 | sha3 = "0.10" 42 | 43 | [dev-dependencies] 44 | cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] } 45 | hex-literal = "0.4.1" 46 | -------------------------------------------------------------------------------- /contracts/crypto-verify/README.md: -------------------------------------------------------------------------------- 1 | # Crypto Verify Contract 2 | 3 | This is a simple contract to demonstrate cryptographic signature verification 4 | from contracts. 5 | 6 | ECDSA Secp256k1 parameters are currently supported. Ed25519 support is upcoming. 7 | 8 | ## Formats 9 | 10 | Input formats are serialized byte slices for Message, Signature, and Public Key. 11 | 12 | ### secp256k1: 13 | 14 | - Message: A serialized message. It will be hashed by the contract using 15 | SHA-256, and the hashed value will be fed to the verification function. 16 | - Signature: Serialized signature, in "compact" Cosmos format (64 bytes). 17 | Ethereum DER needs to be converted. 18 | - Public Key: Compressed (33 bytes) or uncompressed (65 bytes) serialized public 19 | key, in SEC format. 20 | 21 | Output is a boolean value indicating if verification succeeded or not. 22 | 23 | ## Remarks 24 | 25 | In case of an error (wrong or unsupported inputs), the current implementation 26 | returns an error, which can be easily handled by the contract, or returned to 27 | the client. 28 | -------------------------------------------------------------------------------- /contracts/crypto-verify/schema/raw/instantiate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "InstantiateMsg", 4 | "type": "object", 5 | "additionalProperties": false 6 | } 7 | -------------------------------------------------------------------------------- /contracts/crypto-verify/schema/raw/response_to_list_verification_schemes.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ListVerificationsResponse", 4 | "type": "object", 5 | "required": [ 6 | "verification_schemes" 7 | ], 8 | "properties": { 9 | "verification_schemes": { 10 | "type": "array", 11 | "items": { 12 | "type": "string" 13 | } 14 | } 15 | }, 16 | "additionalProperties": false 17 | } 18 | -------------------------------------------------------------------------------- /contracts/crypto-verify/schema/raw/response_to_verify_cosmos_signature.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "VerifyResponse", 4 | "type": "object", 5 | "required": [ 6 | "verifies" 7 | ], 8 | "properties": { 9 | "verifies": { 10 | "type": "boolean" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/crypto-verify/schema/raw/response_to_verify_ethereum_text.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "VerifyResponse", 4 | "type": "object", 5 | "required": [ 6 | "verifies" 7 | ], 8 | "properties": { 9 | "verifies": { 10 | "type": "boolean" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/crypto-verify/schema/raw/response_to_verify_ethereum_transaction.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "VerifyResponse", 4 | "type": "object", 5 | "required": [ 6 | "verifies" 7 | ], 8 | "properties": { 9 | "verifies": { 10 | "type": "boolean" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/crypto-verify/schema/raw/response_to_verify_secp256_r1_signature.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "VerifyResponse", 4 | "type": "object", 5 | "required": [ 6 | "verifies" 7 | ], 8 | "properties": { 9 | "verifies": { 10 | "type": "boolean" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/crypto-verify/schema/raw/response_to_verify_tendermint_batch.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "VerifyResponse", 4 | "type": "object", 5 | "required": [ 6 | "verifies" 7 | ], 8 | "properties": { 9 | "verifies": { 10 | "type": "boolean" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/crypto-verify/schema/raw/response_to_verify_tendermint_signature.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "VerifyResponse", 4 | "type": "object", 5 | "required": [ 6 | "verifies" 7 | ], 8 | "properties": { 9 | "verifies": { 10 | "type": "boolean" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/crypto-verify/schema/raw/response_to_verify_webauthn.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "VerifyResponse", 4 | "type": "object", 5 | "required": [ 6 | "verifies" 7 | ], 8 | "properties": { 9 | "verifies": { 10 | "type": "boolean" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/crypto-verify/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | 3 | use crypto_verify::msg::{InstantiateMsg, QueryMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | query: QueryMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/crypto-verify/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | mod ethereum; 3 | pub mod msg; 4 | mod webauthn; 5 | -------------------------------------------------------------------------------- /contracts/cyberpunk/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/cyberpunk/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cyberpunk" 3 | version = "0.0.0" 4 | authors = ["Tomasz Kurcz "] 5 | edition = "2021" 6 | publish = false 7 | license = "Apache-2.0" 8 | 9 | [lib] 10 | crate-type = ["cdylib", "rlib"] 11 | 12 | [profile.release] 13 | opt-level = 3 14 | debug = false 15 | rpath = false 16 | lto = true 17 | debug-assertions = false 18 | codegen-units = 1 19 | panic = 'abort' 20 | incremental = false 21 | overflow-checks = true 22 | 23 | [features] 24 | # Add feature "cranelift" to default if you need 32 bit or ARM support 25 | default = [] 26 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 27 | cranelift = ["cosmwasm-vm/cranelift"] 28 | 29 | [dependencies] 30 | cosmwasm-schema = { path = "../../packages/schema" } 31 | cosmwasm-std = { path = "../../packages/std", default-features = false, features = ["std", "abort", "cosmwasm_1_3"] } 32 | rust-argon2 = "2.1" 33 | thiserror = "1.0.26" 34 | 35 | [dev-dependencies] 36 | cosmwasm-vm = { path = "../../packages/vm", default-features = false } 37 | tempfile = "3.1.0" 38 | -------------------------------------------------------------------------------- /contracts/cyberpunk/schema/raw/instantiate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "InstantiateMsg", 4 | "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", 5 | "type": "object", 6 | "additionalProperties": false 7 | } 8 | -------------------------------------------------------------------------------- /contracts/cyberpunk/schema/raw/migrate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ExecuteMsg", 4 | "oneOf": [ 5 | { 6 | "description": "Hashes some data. Uses CPU and memory, but no external calls.", 7 | "type": "object", 8 | "required": [ 9 | "argon2" 10 | ], 11 | "properties": { 12 | "argon2": { 13 | "type": "object", 14 | "required": [ 15 | "mem_cost", 16 | "time_cost" 17 | ], 18 | "properties": { 19 | "mem_cost": { 20 | "description": "The amount of memory requested (KB).", 21 | "type": "integer", 22 | "format": "uint32", 23 | "minimum": 0.0 24 | }, 25 | "time_cost": { 26 | "description": "The number of passes.", 27 | "type": "integer", 28 | "format": "uint32", 29 | "minimum": 0.0 30 | } 31 | }, 32 | "additionalProperties": false 33 | } 34 | }, 35 | "additionalProperties": false 36 | }, 37 | { 38 | "description": "Returns the env for testing", 39 | "type": "object", 40 | "required": [ 41 | "mirror_env" 42 | ], 43 | "properties": { 44 | "mirror_env": { 45 | "type": "object", 46 | "additionalProperties": false 47 | } 48 | }, 49 | "additionalProperties": false 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /contracts/cyberpunk/schema/raw/query.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "QueryMsg", 4 | "oneOf": [ 5 | { 6 | "description": "Returns the env for testing", 7 | "type": "object", 8 | "required": [ 9 | "mirror_env" 10 | ], 11 | "properties": { 12 | "mirror_env": { 13 | "type": "object", 14 | "additionalProperties": false 15 | } 16 | }, 17 | "additionalProperties": false 18 | }, 19 | { 20 | "description": "Queries `AllDenomMetadata` from the bank module repeatedly and returns all entries", 21 | "type": "object", 22 | "required": [ 23 | "denoms" 24 | ], 25 | "properties": { 26 | "denoms": { 27 | "type": "object", 28 | "additionalProperties": false 29 | } 30 | }, 31 | "additionalProperties": false 32 | }, 33 | { 34 | "description": "Queries `DenomMetadata` from the bank module and returns the result", 35 | "type": "object", 36 | "required": [ 37 | "denom" 38 | ], 39 | "properties": { 40 | "denom": { 41 | "type": "object", 42 | "required": [ 43 | "denom" 44 | ], 45 | "properties": { 46 | "denom": { 47 | "type": "string" 48 | } 49 | }, 50 | "additionalProperties": false 51 | } 52 | }, 53 | "additionalProperties": false 54 | } 55 | ] 56 | } 57 | -------------------------------------------------------------------------------- /contracts/cyberpunk/schema/raw/response_to_denom.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "DenomMetadata", 4 | "description": "Replicates the cosmos-sdk bank module Metadata type", 5 | "type": "object", 6 | "required": [ 7 | "base", 8 | "denom_units", 9 | "description", 10 | "display", 11 | "name", 12 | "symbol", 13 | "uri", 14 | "uri_hash" 15 | ], 16 | "properties": { 17 | "base": { 18 | "type": "string" 19 | }, 20 | "denom_units": { 21 | "type": "array", 22 | "items": { 23 | "$ref": "#/definitions/DenomUnit" 24 | } 25 | }, 26 | "description": { 27 | "type": "string" 28 | }, 29 | "display": { 30 | "type": "string" 31 | }, 32 | "name": { 33 | "type": "string" 34 | }, 35 | "symbol": { 36 | "type": "string" 37 | }, 38 | "uri": { 39 | "type": "string" 40 | }, 41 | "uri_hash": { 42 | "type": "string" 43 | } 44 | }, 45 | "additionalProperties": false, 46 | "definitions": { 47 | "DenomUnit": { 48 | "description": "Replicates the cosmos-sdk bank module DenomUnit type", 49 | "type": "object", 50 | "required": [ 51 | "aliases", 52 | "denom", 53 | "exponent" 54 | ], 55 | "properties": { 56 | "aliases": { 57 | "type": "array", 58 | "items": { 59 | "type": "string" 60 | } 61 | }, 62 | "denom": { 63 | "type": "string" 64 | }, 65 | "exponent": { 66 | "type": "integer", 67 | "format": "uint32", 68 | "minimum": 0.0 69 | } 70 | }, 71 | "additionalProperties": false 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /contracts/cyberpunk/schema/raw/sudo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ExecuteMsg", 4 | "oneOf": [ 5 | { 6 | "description": "Hashes some data. Uses CPU and memory, but no external calls.", 7 | "type": "object", 8 | "required": [ 9 | "argon2" 10 | ], 11 | "properties": { 12 | "argon2": { 13 | "type": "object", 14 | "required": [ 15 | "mem_cost", 16 | "time_cost" 17 | ], 18 | "properties": { 19 | "mem_cost": { 20 | "description": "The amount of memory requested (KB).", 21 | "type": "integer", 22 | "format": "uint32", 23 | "minimum": 0.0 24 | }, 25 | "time_cost": { 26 | "description": "The number of passes.", 27 | "type": "integer", 28 | "format": "uint32", 29 | "minimum": 0.0 30 | } 31 | }, 32 | "additionalProperties": false 33 | } 34 | }, 35 | "additionalProperties": false 36 | }, 37 | { 38 | "description": "Returns the env for testing", 39 | "type": "object", 40 | "required": [ 41 | "mirror_env" 42 | ], 43 | "properties": { 44 | "mirror_env": { 45 | "type": "object", 46 | "additionalProperties": false 47 | } 48 | }, 49 | "additionalProperties": false 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /contracts/cyberpunk/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use cosmwasm_std::Empty; 3 | 4 | use cyberpunk::msg::{ExecuteMsg, QueryMsg}; 5 | 6 | fn main() { 7 | write_api! { 8 | instantiate: Empty, 9 | query: QueryMsg, 10 | execute: ExecuteMsg, 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /contracts/cyberpunk/src/errors.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::StdError; 2 | use thiserror::Error; 3 | 4 | #[derive(Error, Debug, PartialEq)] 5 | pub enum ContractError { 6 | #[error("{0}")] 7 | /// this is needed so we can use `bucket.load(...)?` and have it auto-converted to the custom error 8 | Std(#[from] StdError), 9 | } 10 | -------------------------------------------------------------------------------- /contracts/cyberpunk/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod errors; 3 | pub mod msg; 4 | -------------------------------------------------------------------------------- /contracts/cyberpunk/src/msg.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::{cw_serde, QueryResponses}; 2 | 3 | #[cw_serde] 4 | pub enum ExecuteMsg { 5 | /// Hashes some data. Uses CPU and memory, but no external calls. 6 | Argon2 { 7 | /// The amount of memory requested (KB). 8 | mem_cost: u32, 9 | /// The number of passes. 10 | time_cost: u32, 11 | }, 12 | /// Infinite loop to burn cpu cycles (only run when metering is enabled) 13 | CpuLoop {}, 14 | /// Infinite loop making storage calls (to test when their limit hits) 15 | StorageLoop {}, 16 | /// Infinite loop reading and writing memory 17 | MemoryLoop {}, 18 | /// Infinite loop sending message to itself 19 | MessageLoop {}, 20 | /// Allocate large amounts of memory without consuming much gas 21 | AllocateLargeMemory { pages: u32 }, 22 | /// Trigger a panic to ensure framework handles gracefully 23 | Panic {}, 24 | /// In contrast to Panic, this does not use the panic handler. 25 | /// 26 | /// From : 27 | /// "Generates the unreachable instruction, which causes an unconditional trap." 28 | Unreachable {}, 29 | /// Returns the env for testing 30 | MirrorEnv {}, 31 | /// Does a bit of work and calls debug 32 | Debug {}, 33 | /// Does nothing. This can be used for baseline contract execution performance measurements. 34 | Noop {}, 35 | } 36 | 37 | #[cw_serde] 38 | #[derive(QueryResponses)] 39 | pub enum QueryMsg { 40 | /// Returns the env for testing 41 | #[returns(cosmwasm_std::Env)] 42 | MirrorEnv {}, 43 | 44 | /// Queries `AllDenomMetadata` from the bank module repeatedly and returns all entries 45 | #[returns(Vec)] 46 | Denoms {}, 47 | 48 | /// Queries `DenomMetadata` from the bank module and returns the result 49 | #[returns(cosmwasm_std::DenomMetadata)] 50 | Denom { denom: String }, 51 | } 52 | -------------------------------------------------------------------------------- /contracts/empty/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/empty/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "empty" 3 | version = "0.0.0" 4 | authors = ["Christoph Otter "] 5 | edition = "2021" 6 | publish = false 7 | license = "Apache-2.0" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [lib] 12 | crate-type = ["cdylib", "rlib"] 13 | 14 | [profile.release] 15 | opt-level = 3 16 | debug = false 17 | rpath = false 18 | lto = true 19 | debug-assertions = false 20 | codegen-units = 1 21 | panic = 'abort' 22 | incremental = false 23 | overflow-checks = true 24 | 25 | [features] 26 | # Add feature "cranelift" to default if you need 32 bit or ARM support 27 | default = [] 28 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 29 | cranelift = ["cosmwasm-vm/cranelift"] 30 | 31 | [dependencies] 32 | cosmwasm-schema = { path = "../../packages/schema" } 33 | cosmwasm-std = { path = "../../packages/std", features = ["iterator"] } 34 | schemars = "0.8.12" 35 | 36 | [dev-dependencies] 37 | cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] } 38 | -------------------------------------------------------------------------------- /contracts/empty/README.md: -------------------------------------------------------------------------------- 1 | # Empty Contract 2 | 3 | This is a minimal contract to test against. It has no functionality and only has 4 | the minimum required to be a valid contract. 5 | -------------------------------------------------------------------------------- /contracts/empty/schema/empty.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract_name": "empty", 3 | "contract_version": "0.0.0", 4 | "idl_version": "1.0.0", 5 | "instantiate": null, 6 | "execute": null, 7 | "query": null, 8 | "migrate": null, 9 | "sudo": null, 10 | "responses": null 11 | } 12 | -------------------------------------------------------------------------------- /contracts/empty/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | 3 | fn main() { 4 | write_api! {} 5 | } 6 | -------------------------------------------------------------------------------- /contracts/empty/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Make sure to reexport cosmwasm_std, so the standard entry points are kept in the final wasm 2 | pub use cosmwasm_std; 3 | -------------------------------------------------------------------------------- /contracts/empty/tests/integration.rs: -------------------------------------------------------------------------------- 1 | //! This integration test tries to run and call the generated wasm. 2 | //! It depends on a Wasm build being available, which you can create with `cargo wasm`. 3 | //! Then running `cargo integration-test` will validate we can properly call into that generated Wasm. 4 | //! 5 | //! You can easily convert unit tests to integration tests. 6 | //! 1. First copy them over verbatum, 7 | //! 2. Then change 8 | //! let mut deps = mock_dependencies(20, &[]); 9 | //! to 10 | //! let mut deps = mock_instance(WASM, &[]); 11 | //! 3. If you access raw storage, where ever you see something like: 12 | //! deps.storage.get(CONFIG_KEY).expect("no data stored"); 13 | //! replace it with: 14 | //! deps.with_storage(|store| { 15 | //! let data = store.get(CONFIG_KEY).expect("no data stored"); 16 | //! //... 17 | //! }); 18 | //! 4. Anywhere you see query(&deps, ...) you must replace it with query(&mut deps, ...) 19 | 20 | use cosmwasm_vm::testing::mock_instance; 21 | 22 | // This line will test the output of cargo wasm 23 | static WASM: &[u8] = include_bytes!("../target/wasm32-unknown-unknown/release/empty.wasm"); 24 | // You can uncomment this line instead to test productionified build from rust-optimizer 25 | // static WASM: &[u8] = include_bytes!("../contract.wasm"); 26 | 27 | #[test] 28 | fn validation_succeeds() { 29 | mock_instance(WASM, &[]); 30 | } 31 | -------------------------------------------------------------------------------- /contracts/floaty/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/floaty/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.cargo.target": "wasm32-unknown-unknown", 3 | "rust-analyzer.cargo.extraEnv": { 4 | "RUSTFLAGS": "-C target-feature=+nontrapping-fptoint" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /contracts/floaty/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "floaty" 3 | version = "0.0.0" 4 | authors = ["Ethan Frey "] 5 | edition = "2021" 6 | publish = false 7 | license = "Apache-2.0" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [lib] 12 | crate-type = ["cdylib", "rlib"] 13 | 14 | [profile.release] 15 | opt-level = 3 16 | debug = false 17 | rpath = false 18 | lto = true 19 | debug-assertions = false 20 | codegen-units = 1 21 | panic = 'abort' 22 | incremental = false 23 | overflow-checks = true 24 | 25 | [features] 26 | # Add feature "cranelift" to default if you need 32 bit or ARM support 27 | default = [] 28 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 29 | cranelift = ["cosmwasm-vm/cranelift"] 30 | 31 | [dependencies] 32 | cosmwasm-schema = { path = "../../packages/schema" } 33 | cosmwasm-std = { path = "../../packages/std" } 34 | schemars = "0.8.12" 35 | serde = { version = "1.0.103", default-features = false, features = ["derive"] } 36 | rand_chacha = { version = "0.3.1", default-features = false } 37 | 38 | [dev-dependencies] 39 | cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] } 40 | -------------------------------------------------------------------------------- /contracts/floaty/README.md: -------------------------------------------------------------------------------- 1 | # Floaty Contract 2 | 3 | This contract contains all WebAssembly floating point instructions. It is used 4 | for testing the floating point support. 5 | 6 | In order to compile it, you need a nightly version of Rust and enable the 7 | `nontrapping-fptoint` target-feature. This allows the usage of 8 | [some more conversion instructions](https://github.com/WebAssembly/spec/blob/main/proposals/nontrapping-float-to-int-conversion/Overview.md). 9 | To do this, run: 10 | 11 | ```sh 12 | RUSTFLAGS="-C link-arg=-s -C target-feature=+nontrapping-fptoint" cargo wasm 13 | ``` 14 | -------------------------------------------------------------------------------- /contracts/floaty/schema/raw/execute.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ExecuteMsg", 4 | "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", 5 | "type": "object" 6 | } 7 | -------------------------------------------------------------------------------- /contracts/floaty/schema/raw/instantiate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "InstantiateMsg", 4 | "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", 5 | "type": "object", 6 | "additionalProperties": false 7 | } 8 | -------------------------------------------------------------------------------- /contracts/floaty/schema/raw/migrate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ExecuteMsg", 4 | "oneOf": [ 5 | { 6 | "description": "Releasing all funds in the contract to the beneficiary. This is the only \"proper\" action of this demo contract.", 7 | "type": "object", 8 | "required": [ 9 | "release" 10 | ], 11 | "properties": { 12 | "release": { 13 | "type": "object", 14 | "additionalProperties": false 15 | } 16 | }, 17 | "additionalProperties": false 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /contracts/floaty/schema/raw/response_to_instructions.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "Array_of_String", 4 | "type": "array", 5 | "items": { 6 | "type": "string" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /contracts/floaty/schema/raw/response_to_other_balance.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "AllBalanceResponse", 4 | "type": "object", 5 | "required": [ 6 | "amount" 7 | ], 8 | "properties": { 9 | "amount": { 10 | "description": "Returns all non-zero coins held by this account.", 11 | "type": "array", 12 | "items": { 13 | "$ref": "#/definitions/Coin" 14 | } 15 | } 16 | }, 17 | "definitions": { 18 | "Coin": { 19 | "type": "object", 20 | "required": [ 21 | "amount", 22 | "denom" 23 | ], 24 | "properties": { 25 | "amount": { 26 | "$ref": "#/definitions/Uint128" 27 | }, 28 | "denom": { 29 | "type": "string" 30 | } 31 | } 32 | }, 33 | "Uint128": { 34 | "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", 35 | "type": "string" 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/floaty/schema/raw/response_to_random_args_for.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "Array_of_Value", 4 | "type": "array", 5 | "items": { 6 | "$ref": "#/definitions/Value" 7 | }, 8 | "definitions": { 9 | "Value": { 10 | "oneOf": [ 11 | { 12 | "type": "object", 13 | "required": [ 14 | "u32" 15 | ], 16 | "properties": { 17 | "u32": { 18 | "type": "integer", 19 | "format": "uint32", 20 | "minimum": 0.0 21 | } 22 | }, 23 | "additionalProperties": false 24 | }, 25 | { 26 | "type": "object", 27 | "required": [ 28 | "u64" 29 | ], 30 | "properties": { 31 | "u64": { 32 | "type": "integer", 33 | "format": "uint64", 34 | "minimum": 0.0 35 | } 36 | }, 37 | "additionalProperties": false 38 | }, 39 | { 40 | "type": "object", 41 | "required": [ 42 | "f32" 43 | ], 44 | "properties": { 45 | "f32": { 46 | "type": "integer", 47 | "format": "uint32", 48 | "minimum": 0.0 49 | } 50 | }, 51 | "additionalProperties": false 52 | }, 53 | { 54 | "type": "object", 55 | "required": [ 56 | "f64" 57 | ], 58 | "properties": { 59 | "f64": { 60 | "type": "integer", 61 | "format": "uint64", 62 | "minimum": 0.0 63 | } 64 | }, 65 | "additionalProperties": false 66 | } 67 | ] 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /contracts/floaty/schema/raw/response_to_run.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "Value", 4 | "oneOf": [ 5 | { 6 | "type": "object", 7 | "required": [ 8 | "u32" 9 | ], 10 | "properties": { 11 | "u32": { 12 | "type": "integer", 13 | "format": "uint32", 14 | "minimum": 0.0 15 | } 16 | }, 17 | "additionalProperties": false 18 | }, 19 | { 20 | "type": "object", 21 | "required": [ 22 | "u64" 23 | ], 24 | "properties": { 25 | "u64": { 26 | "type": "integer", 27 | "format": "uint64", 28 | "minimum": 0.0 29 | } 30 | }, 31 | "additionalProperties": false 32 | }, 33 | { 34 | "type": "object", 35 | "required": [ 36 | "f32" 37 | ], 38 | "properties": { 39 | "f32": { 40 | "type": "integer", 41 | "format": "uint32", 42 | "minimum": 0.0 43 | } 44 | }, 45 | "additionalProperties": false 46 | }, 47 | { 48 | "type": "object", 49 | "required": [ 50 | "f64" 51 | ], 52 | "properties": { 53 | "f64": { 54 | "type": "integer", 55 | "format": "uint64", 56 | "minimum": 0.0 57 | } 58 | }, 59 | "additionalProperties": false 60 | } 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /contracts/floaty/schema/raw/response_to_verifier.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "VerifierResponse", 4 | "type": "object", 5 | "required": [ 6 | "verifier" 7 | ], 8 | "properties": { 9 | "verifier": { 10 | "type": "string" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/floaty/schema/raw/sudo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ExecuteMsg", 4 | "oneOf": [ 5 | { 6 | "description": "Releasing all funds in the contract to the beneficiary. This is the only \"proper\" action of this demo contract.", 7 | "type": "object", 8 | "required": [ 9 | "release" 10 | ], 11 | "properties": { 12 | "release": { 13 | "type": "object", 14 | "additionalProperties": false 15 | } 16 | }, 17 | "additionalProperties": false 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /contracts/floaty/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | 3 | use cosmwasm_std::Empty; 4 | use floaty::msg::QueryMsg; 5 | 6 | fn main() { 7 | write_api! { 8 | instantiate: Empty, 9 | query: QueryMsg, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/floaty/src/contract.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{ 2 | entry_point, to_json_binary, Deps, DepsMut, Empty, Env, MessageInfo, QueryResponse, Response, 3 | StdResult, 4 | }; 5 | use rand_chacha::rand_core::SeedableRng; 6 | 7 | #[cfg(target_arch = "wasm32")] 8 | use crate::instructions::run_instruction; 9 | use crate::{ 10 | instructions::{random_args_for, Value, FLOAT_INSTRUCTIONS}, 11 | msg::QueryMsg, 12 | }; 13 | 14 | #[entry_point] 15 | pub fn instantiate( 16 | _deps: DepsMut, 17 | _env: Env, 18 | _info: MessageInfo, 19 | _msg: Empty, 20 | ) -> Result { 21 | Ok(Response::default()) 22 | } 23 | 24 | #[entry_point] 25 | pub fn query(_deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { 26 | match msg { 27 | QueryMsg::RandomArgsFor { instruction, seed } => { 28 | let mut rng = rand_chacha::ChaChaRng::seed_from_u64(seed); 29 | to_json_binary(&random_args_for(&instruction, &mut rng)) 30 | } 31 | QueryMsg::Instructions {} => to_json_binary(&FLOAT_INSTRUCTIONS.to_vec()), 32 | QueryMsg::Run { instruction, args } => to_json_binary(&query_run(&instruction, args)?), 33 | } 34 | } 35 | 36 | #[cfg_attr(not(target_arch = "wasm32"), allow(unused_variables))] 37 | fn query_run(instruction: &str, args: Vec) -> StdResult { 38 | #[cfg(not(target_arch = "wasm32"))] 39 | panic!(); 40 | 41 | #[cfg(target_arch = "wasm32")] 42 | { 43 | let result = run_instruction(instruction, &args); 44 | Ok(result) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/floaty/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(target_arch = "wasm32", feature(asm_experimental_arch))] 2 | 3 | pub mod contract; 4 | pub(crate) mod floats; 5 | mod instructions; 6 | pub mod msg; 7 | pub mod state; 8 | -------------------------------------------------------------------------------- /contracts/floaty/src/msg.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::{cw_serde, QueryResponses}; 2 | 3 | use crate::instructions::Value; 4 | 5 | #[cw_serde] 6 | pub enum ValueType { 7 | Float, 8 | Int, 9 | } 10 | 11 | #[cw_serde] 12 | #[derive(QueryResponses)] 13 | pub enum QueryMsg { 14 | /// Returns valid random arguments for the given instruction 15 | #[returns(Vec)] 16 | RandomArgsFor { instruction: String, seed: u64 }, 17 | /// Returns a list of all instructions 18 | #[returns(Vec)] 19 | Instructions {}, 20 | /// Runs the given instruction with the given arguments and returns the result 21 | #[returns(Value)] 22 | Run { 23 | instruction: String, 24 | args: Vec, 25 | }, 26 | } 27 | -------------------------------------------------------------------------------- /contracts/floaty/src/state.rs: -------------------------------------------------------------------------------- 1 | use schemars::JsonSchema; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | use cosmwasm_std::Addr; 5 | 6 | pub const CONFIG_KEY: &[u8] = b"config"; 7 | 8 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] 9 | pub struct State { 10 | pub verifier: Addr, 11 | pub beneficiary: Addr, 12 | pub funder: Addr, 13 | } 14 | -------------------------------------------------------------------------------- /contracts/floaty/tests/integration.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_vm::testing::mock_instance; 2 | 3 | // This line will test the output of cargo wasm 4 | static WASM: &[u8] = include_bytes!("../target/wasm32-unknown-unknown/release/floaty.wasm"); 5 | // You can uncomment this line instead to test productionified build from rust-optimizer 6 | // static WASM: &[u8] = include_bytes!("../contract.wasm"); 7 | 8 | #[test] 9 | fn validation_succeeds() { 10 | mock_instance(WASM, &[]); 11 | } 12 | -------------------------------------------------------------------------------- /contracts/hackatom/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/hackatom/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hackatom" 3 | version = "0.0.0" 4 | authors = ["Ethan Frey "] 5 | edition = "2021" 6 | publish = false 7 | license = "Apache-2.0" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [lib] 12 | crate-type = ["cdylib", "rlib"] 13 | 14 | [profile.release] 15 | opt-level = 3 16 | debug = false 17 | rpath = false 18 | lto = true 19 | debug-assertions = false 20 | codegen-units = 1 21 | panic = 'abort' 22 | incremental = false 23 | overflow-checks = true 24 | 25 | [features] 26 | # Add feature "cranelift" to default if you need 32 bit or ARM support 27 | default = [] 28 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 29 | cranelift = ["cosmwasm-vm/cranelift"] 30 | 31 | [dependencies] 32 | cosmwasm-schema = { path = "../../packages/schema" } 33 | cosmwasm-std = { path = "../../packages/std", default-features = false, features = ["std", "abort"] } 34 | schemars = "0.8.12" 35 | serde = { version = "1.0.103", default-features = false, features = ["derive"] } 36 | sha2 = "0.10" 37 | thiserror = "1.0.26" 38 | 39 | [dev-dependencies] 40 | cosmwasm-vm = { path = "../../packages/vm", default-features = false } 41 | -------------------------------------------------------------------------------- /contracts/hackatom/schema/raw/instantiate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "InstantiateMsg", 4 | "type": "object", 5 | "required": [ 6 | "beneficiary", 7 | "verifier" 8 | ], 9 | "properties": { 10 | "beneficiary": { 11 | "type": "string" 12 | }, 13 | "verifier": { 14 | "type": "string" 15 | } 16 | }, 17 | "additionalProperties": false 18 | } 19 | -------------------------------------------------------------------------------- /contracts/hackatom/schema/raw/migrate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "MigrateMsg", 4 | "description": "MigrateMsg allows a privileged contract administrator to run a migration on the contract. In this (demo) case it is just migrating from one hackatom code to the same code, but taking advantage of the migration step to set a new validator.\n\nNote that the contract doesn't enforce permissions here, this is done by blockchain logic (in the future by blockchain governance)", 5 | "type": "object", 6 | "required": [ 7 | "verifier" 8 | ], 9 | "properties": { 10 | "verifier": { 11 | "type": "string" 12 | } 13 | }, 14 | "additionalProperties": false 15 | } 16 | -------------------------------------------------------------------------------- /contracts/hackatom/schema/raw/response_to_get_int.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "IntResponse", 4 | "type": "object", 5 | "required": [ 6 | "int" 7 | ], 8 | "properties": { 9 | "int": { 10 | "type": "integer", 11 | "format": "uint32", 12 | "minimum": 0.0 13 | } 14 | }, 15 | "additionalProperties": false 16 | } 17 | -------------------------------------------------------------------------------- /contracts/hackatom/schema/raw/response_to_other_balance.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "AllBalanceResponse", 4 | "type": "object", 5 | "required": [ 6 | "amount" 7 | ], 8 | "properties": { 9 | "amount": { 10 | "description": "Returns all non-zero coins held by this account.", 11 | "type": "array", 12 | "items": { 13 | "$ref": "#/definitions/Coin" 14 | } 15 | } 16 | }, 17 | "additionalProperties": false, 18 | "definitions": { 19 | "Coin": { 20 | "type": "object", 21 | "required": [ 22 | "amount", 23 | "denom" 24 | ], 25 | "properties": { 26 | "amount": { 27 | "$ref": "#/definitions/Uint128" 28 | }, 29 | "denom": { 30 | "type": "string" 31 | } 32 | }, 33 | "additionalProperties": false 34 | }, 35 | "Uint128": { 36 | "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", 37 | "type": "string" 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /contracts/hackatom/schema/raw/response_to_recurse.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "RecurseResponse", 4 | "type": "object", 5 | "required": [ 6 | "hashed" 7 | ], 8 | "properties": { 9 | "hashed": { 10 | "description": "hashed is the result of running sha256 \"work+1\" times on the contract's human address", 11 | "allOf": [ 12 | { 13 | "$ref": "#/definitions/Binary" 14 | } 15 | ] 16 | } 17 | }, 18 | "additionalProperties": false, 19 | "definitions": { 20 | "Binary": { 21 | "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", 22 | "type": "string" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /contracts/hackatom/schema/raw/response_to_verifier.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "VerifierResponse", 4 | "type": "object", 5 | "required": [ 6 | "verifier" 7 | ], 8 | "properties": { 9 | "verifier": { 10 | "type": "string" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/hackatom/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | 3 | use hackatom::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SudoMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | query: QueryMsg, 9 | execute: ExecuteMsg, 10 | sudo: SudoMsg, 11 | migrate: MigrateMsg, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /contracts/hackatom/src/errors.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::StdError; 2 | use thiserror::Error; 3 | 4 | #[derive(Error, Debug, PartialEq)] 5 | pub enum HackError { 6 | #[error("{0}")] 7 | /// this is needed so we can use `bucket.load(...)?` and have it auto-converted to the custom error 8 | Std(#[from] StdError), 9 | // this is whatever we want 10 | #[error("Unauthorized")] 11 | Unauthorized {}, 12 | } 13 | -------------------------------------------------------------------------------- /contracts/hackatom/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod errors; 3 | pub mod msg; 4 | pub mod state; 5 | -------------------------------------------------------------------------------- /contracts/hackatom/src/state.rs: -------------------------------------------------------------------------------- 1 | use schemars::JsonSchema; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | use cosmwasm_std::Addr; 5 | 6 | pub const CONFIG_KEY: &[u8] = b"config"; 7 | 8 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] 9 | pub struct State { 10 | pub verifier: Addr, 11 | pub beneficiary: Addr, 12 | pub funder: Addr, 13 | } 14 | -------------------------------------------------------------------------------- /contracts/ibc-reflect-send/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/ibc-reflect-send/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ibc-reflect-send" 3 | version = "0.0.0" 4 | authors = ["Ethan Frey "] 5 | edition = "2021" 6 | publish = false 7 | license = "Apache-2.0" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [lib] 12 | crate-type = ["cdylib", "rlib"] 13 | 14 | [profile.release] 15 | opt-level = 3 16 | debug = false 17 | rpath = false 18 | lto = true 19 | debug-assertions = false 20 | codegen-units = 1 21 | panic = 'abort' 22 | incremental = false 23 | overflow-checks = true 24 | 25 | [features] 26 | # Add feature "cranelift" to default if you need 32 bit or ARM support 27 | default = [] 28 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 29 | cranelift = ["cosmwasm-vm/cranelift"] 30 | 31 | [dependencies] 32 | cosmwasm-schema = { path = "../../packages/schema" } 33 | cosmwasm-std = { path = "../../packages/std", features = ["iterator", "staking", "stargate"] } 34 | schemars = "0.8.12" 35 | serde = { version = "1.0.103", default-features = false, features = ["derive"] } 36 | 37 | [dev-dependencies] 38 | cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator", "stargate"] } 39 | -------------------------------------------------------------------------------- /contracts/ibc-reflect-send/schema/ibc/acknowledgement_msg_dispatch.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "AcknowledgementMsgDispatch", 4 | "description": "A custom acknowledgement type. The success type `T` depends on the PacketMsg variant.\n\nThis could be refactored to use [StdAck] at some point. However, it has a different success variant name (\"ok\" vs. \"result\") and a JSON payload instead of a binary payload.\n\n[StdAck]: https://github.com/CosmWasm/cosmwasm/issues/1512", 5 | "oneOf": [ 6 | { 7 | "type": "object", 8 | "required": [ 9 | "ok" 10 | ], 11 | "properties": { 12 | "ok": { 13 | "type": "null" 14 | } 15 | }, 16 | "additionalProperties": false 17 | }, 18 | { 19 | "type": "object", 20 | "required": [ 21 | "error" 22 | ], 23 | "properties": { 24 | "error": { 25 | "type": "string" 26 | } 27 | }, 28 | "additionalProperties": false 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /contracts/ibc-reflect-send/schema/ibc/acknowledgement_msg_who_am_i.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "AcknowledgementMsgWhoAmI", 4 | "description": "A custom acknowledgement type. The success type `T` depends on the PacketMsg variant.\n\nThis could be refactored to use [StdAck] at some point. However, it has a different success variant name (\"ok\" vs. \"result\") and a JSON payload instead of a binary payload.\n\n[StdAck]: https://github.com/CosmWasm/cosmwasm/issues/1512", 5 | "oneOf": [ 6 | { 7 | "type": "object", 8 | "required": [ 9 | "ok" 10 | ], 11 | "properties": { 12 | "ok": { 13 | "$ref": "#/definitions/WhoAmIResponse" 14 | } 15 | }, 16 | "additionalProperties": false 17 | }, 18 | { 19 | "type": "object", 20 | "required": [ 21 | "error" 22 | ], 23 | "properties": { 24 | "error": { 25 | "type": "string" 26 | } 27 | }, 28 | "additionalProperties": false 29 | } 30 | ], 31 | "definitions": { 32 | "WhoAmIResponse": { 33 | "description": "This is the success response we send on ack for PacketMsg::WhoAmI. Return the caller's account address on the remote chain", 34 | "type": "object", 35 | "required": [ 36 | "account" 37 | ], 38 | "properties": { 39 | "account": { 40 | "type": "string" 41 | } 42 | }, 43 | "additionalProperties": false 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/ibc-reflect-send/schema/raw/instantiate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "InstantiateMsg", 4 | "description": "This needs no info. Owner of the contract is whoever signed the InstantiateMsg.", 5 | "type": "object", 6 | "additionalProperties": false 7 | } 8 | -------------------------------------------------------------------------------- /contracts/ibc-reflect-send/schema/raw/query.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "QueryMsg", 4 | "oneOf": [ 5 | { 6 | "type": "object", 7 | "required": [ 8 | "admin" 9 | ], 10 | "properties": { 11 | "admin": { 12 | "type": "object", 13 | "additionalProperties": false 14 | } 15 | }, 16 | "additionalProperties": false 17 | }, 18 | { 19 | "type": "object", 20 | "required": [ 21 | "list_accounts" 22 | ], 23 | "properties": { 24 | "list_accounts": { 25 | "type": "object", 26 | "additionalProperties": false 27 | } 28 | }, 29 | "additionalProperties": false 30 | }, 31 | { 32 | "type": "object", 33 | "required": [ 34 | "account" 35 | ], 36 | "properties": { 37 | "account": { 38 | "type": "object", 39 | "required": [ 40 | "channel_id" 41 | ], 42 | "properties": { 43 | "channel_id": { 44 | "type": "string" 45 | } 46 | }, 47 | "additionalProperties": false 48 | } 49 | }, 50 | "additionalProperties": false 51 | } 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /contracts/ibc-reflect-send/schema/raw/response_to_admin.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "AdminResponse", 4 | "type": "object", 5 | "required": [ 6 | "admin" 7 | ], 8 | "properties": { 9 | "admin": { 10 | "type": "string" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/ibc-reflect-send/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use std::env::current_dir; 2 | 3 | use cosmwasm_schema::{export_schema, export_schema_with_title, schema_for, write_api}; 4 | 5 | use ibc_reflect_send::ibc_msg::{ 6 | AcknowledgementMsg, BalancesResponse, DispatchResponse, PacketMsg, WhoAmIResponse, 7 | }; 8 | use ibc_reflect_send::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; 9 | 10 | fn main() { 11 | // Clear & write standard API 12 | write_api! { 13 | instantiate: InstantiateMsg, 14 | execute: ExecuteMsg, 15 | query: QueryMsg, 16 | } 17 | 18 | // Schemas for inter-contract communication 19 | let mut out_dir = current_dir().unwrap(); 20 | out_dir.push("schema"); 21 | out_dir.push("ibc"); 22 | export_schema(&schema_for!(PacketMsg), &out_dir); 23 | export_schema_with_title( 24 | &schema_for!(AcknowledgementMsg), 25 | &out_dir, 26 | "AcknowledgementMsgBalances", 27 | ); 28 | export_schema_with_title( 29 | &schema_for!(AcknowledgementMsg), 30 | &out_dir, 31 | "AcknowledgementMsgDispatch", 32 | ); 33 | export_schema_with_title( 34 | &schema_for!(AcknowledgementMsg), 35 | &out_dir, 36 | "AcknowledgementMsgWhoAmI", 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /contracts/ibc-reflect-send/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod ibc; 3 | pub mod ibc_msg; 4 | pub mod msg; 5 | pub mod state; 6 | -------------------------------------------------------------------------------- /contracts/ibc-reflect/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/ibc-reflect/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ibc-reflect" 3 | version = "0.0.0" 4 | authors = ["Ethan Frey "] 5 | edition = "2021" 6 | publish = false 7 | license = "Apache-2.0" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [lib] 12 | crate-type = ["cdylib", "rlib"] 13 | 14 | [profile.release] 15 | opt-level = 3 16 | debug = false 17 | rpath = false 18 | lto = true 19 | debug-assertions = false 20 | codegen-units = 1 21 | panic = 'abort' 22 | incremental = false 23 | overflow-checks = true 24 | 25 | [features] 26 | # Add feature "cranelift" to default if you need 32 bit or ARM support 27 | default = [] 28 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 29 | cranelift = ["cosmwasm-vm/cranelift"] 30 | 31 | [dependencies] 32 | cosmwasm-schema = { path = "../../packages/schema" } 33 | cosmwasm-std = { path = "../../packages/std", features = ["iterator", "stargate", "cosmwasm_2_0"] } 34 | schemars = "0.8.12" 35 | serde = { version = "1.0.103", default-features = false, features = ["derive"] } 36 | 37 | [dev-dependencies] 38 | cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator", "stargate"] } 39 | -------------------------------------------------------------------------------- /contracts/ibc-reflect/schema/ibc/acknowledgement_msg_dispatch.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "AcknowledgementMsgDispatch", 4 | "description": "A custom acknowledgement type. The success type `T` depends on the PacketMsg variant.\n\nThis could be refactored to use [StdAck] at some point. However, it has a different success variant name (\"ok\" vs. \"result\") and a JSON payload instead of a binary payload.\n\n[StdAck]: https://github.com/CosmWasm/cosmwasm/issues/1512", 5 | "oneOf": [ 6 | { 7 | "type": "object", 8 | "required": [ 9 | "ok" 10 | ], 11 | "properties": { 12 | "ok": { 13 | "type": "null" 14 | } 15 | }, 16 | "additionalProperties": false 17 | }, 18 | { 19 | "type": "object", 20 | "required": [ 21 | "error" 22 | ], 23 | "properties": { 24 | "error": { 25 | "type": "string" 26 | } 27 | }, 28 | "additionalProperties": false 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /contracts/ibc-reflect/schema/ibc/acknowledgement_msg_who_am_i.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "AcknowledgementMsgWhoAmI", 4 | "description": "A custom acknowledgement type. The success type `T` depends on the PacketMsg variant.\n\nThis could be refactored to use [StdAck] at some point. However, it has a different success variant name (\"ok\" vs. \"result\") and a JSON payload instead of a binary payload.\n\n[StdAck]: https://github.com/CosmWasm/cosmwasm/issues/1512", 5 | "oneOf": [ 6 | { 7 | "type": "object", 8 | "required": [ 9 | "ok" 10 | ], 11 | "properties": { 12 | "ok": { 13 | "$ref": "#/definitions/WhoAmIResponse" 14 | } 15 | }, 16 | "additionalProperties": false 17 | }, 18 | { 19 | "type": "object", 20 | "required": [ 21 | "error" 22 | ], 23 | "properties": { 24 | "error": { 25 | "type": "string" 26 | } 27 | }, 28 | "additionalProperties": false 29 | } 30 | ], 31 | "definitions": { 32 | "WhoAmIResponse": { 33 | "description": "This is the success response we send on ack for PacketMsg::WhoAmI. Return the caller's account address on the remote chain", 34 | "type": "object", 35 | "required": [ 36 | "account" 37 | ], 38 | "properties": { 39 | "account": { 40 | "type": "string" 41 | } 42 | }, 43 | "additionalProperties": false 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/ibc-reflect/schema/raw/instantiate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "InstantiateMsg", 4 | "description": "Just needs to know the code_id of a reflect contract to spawn sub-accounts", 5 | "type": "object", 6 | "required": [ 7 | "reflect_code_id" 8 | ], 9 | "properties": { 10 | "reflect_code_id": { 11 | "type": "integer", 12 | "format": "uint64", 13 | "minimum": 0.0 14 | } 15 | }, 16 | "additionalProperties": false 17 | } 18 | -------------------------------------------------------------------------------- /contracts/ibc-reflect/schema/raw/migrate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "MigrateMsg", 4 | "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", 5 | "type": "object", 6 | "additionalProperties": false 7 | } 8 | -------------------------------------------------------------------------------- /contracts/ibc-reflect/schema/raw/query.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "QueryMsg", 4 | "oneOf": [ 5 | { 6 | "description": "Returns (reflect) account that is attached to this channel, or none.", 7 | "type": "object", 8 | "required": [ 9 | "account" 10 | ], 11 | "properties": { 12 | "account": { 13 | "type": "object", 14 | "required": [ 15 | "channel_id" 16 | ], 17 | "properties": { 18 | "channel_id": { 19 | "type": "string" 20 | } 21 | }, 22 | "additionalProperties": false 23 | } 24 | }, 25 | "additionalProperties": false 26 | }, 27 | { 28 | "description": "Returns all (channel, reflect_account) pairs. No pagination - this is a test contract", 29 | "type": "object", 30 | "required": [ 31 | "list_accounts" 32 | ], 33 | "properties": { 34 | "list_accounts": { 35 | "type": "object", 36 | "additionalProperties": false 37 | } 38 | }, 39 | "additionalProperties": false 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /contracts/ibc-reflect/schema/raw/response_to_account.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "AccountResponse", 4 | "type": "object", 5 | "properties": { 6 | "account": { 7 | "type": [ 8 | "string", 9 | "null" 10 | ] 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/ibc-reflect/schema/raw/response_to_list_accounts.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ListAccountsResponse", 4 | "type": "object", 5 | "required": [ 6 | "accounts" 7 | ], 8 | "properties": { 9 | "accounts": { 10 | "type": "array", 11 | "items": { 12 | "$ref": "#/definitions/AccountInfo" 13 | } 14 | } 15 | }, 16 | "additionalProperties": false, 17 | "definitions": { 18 | "AccountInfo": { 19 | "type": "object", 20 | "required": [ 21 | "account", 22 | "channel_id" 23 | ], 24 | "properties": { 25 | "account": { 26 | "type": "string" 27 | }, 28 | "channel_id": { 29 | "type": "string" 30 | } 31 | }, 32 | "additionalProperties": false 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /contracts/ibc-reflect/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use std::env::current_dir; 2 | 3 | use cosmwasm_schema::{export_schema, export_schema_with_title, schema_for, write_api}; 4 | use cosmwasm_std::Empty; 5 | 6 | use ibc_reflect::msg::{ 7 | AcknowledgementMsg, BalancesResponse, DispatchResponse, InstantiateMsg, PacketMsg, QueryMsg, 8 | WhoAmIResponse, 9 | }; 10 | 11 | fn main() { 12 | // Clear & write standard API 13 | write_api! { 14 | instantiate: InstantiateMsg, 15 | query: QueryMsg, 16 | migrate: Empty, 17 | } 18 | 19 | // Schemas for inter-contract communication 20 | let mut out_dir = current_dir().unwrap(); 21 | out_dir.push("schema"); 22 | out_dir.push("ibc"); 23 | export_schema(&schema_for!(PacketMsg), &out_dir); 24 | export_schema_with_title( 25 | &schema_for!(AcknowledgementMsg), 26 | &out_dir, 27 | "AcknowledgementMsgBalances", 28 | ); 29 | export_schema_with_title( 30 | &schema_for!(AcknowledgementMsg), 31 | &out_dir, 32 | "AcknowledgementMsgDispatch", 33 | ); 34 | export_schema_with_title( 35 | &schema_for!(AcknowledgementMsg), 36 | &out_dir, 37 | "AcknowledgementMsgWhoAmI", 38 | ); 39 | } 40 | -------------------------------------------------------------------------------- /contracts/ibc-reflect/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod msg; 3 | pub mod state; 4 | -------------------------------------------------------------------------------- /contracts/queue/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/queue/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "queue" 3 | version = "0.0.0" 4 | authors = ["Simon Warta ", "Ethan Frey "] 5 | edition = "2021" 6 | publish = false 7 | license = "Apache-2.0" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [lib] 12 | crate-type = ["cdylib", "rlib"] 13 | 14 | [profile.release] 15 | opt-level = 3 16 | debug = false 17 | rpath = false 18 | lto = true 19 | debug-assertions = false 20 | codegen-units = 1 21 | panic = 'abort' 22 | incremental = false 23 | overflow-checks = true 24 | 25 | [features] 26 | # Add feature "cranelift" to default if you need 32 bit or ARM support 27 | default = [] 28 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 29 | cranelift = ["cosmwasm-vm/cranelift"] 30 | # this is to demonstrate conditional entry-points for cosmwasm-plus style 31 | library = [] 32 | 33 | [dependencies] 34 | cosmwasm-schema = { path = "../../packages/schema" } 35 | # cosmwasm_1_4 is enabled here for more efficient `range_keys` and `range_values` 36 | cosmwasm-std = { path = "../../packages/std", features = ["iterator", "cosmwasm_1_4"] } 37 | schemars = "0.8.12" 38 | serde = { version = "1.0.103", default-features = false, features = ["derive"] } 39 | 40 | [dev-dependencies] 41 | cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] } 42 | -------------------------------------------------------------------------------- /contracts/queue/schema/raw/execute.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ExecuteMsg", 4 | "oneOf": [ 5 | { 6 | "type": "object", 7 | "required": [ 8 | "enqueue" 9 | ], 10 | "properties": { 11 | "enqueue": { 12 | "type": "object", 13 | "required": [ 14 | "value" 15 | ], 16 | "properties": { 17 | "value": { 18 | "type": "integer", 19 | "format": "int32" 20 | } 21 | }, 22 | "additionalProperties": false 23 | } 24 | }, 25 | "additionalProperties": false 26 | }, 27 | { 28 | "type": "object", 29 | "required": [ 30 | "dequeue" 31 | ], 32 | "properties": { 33 | "dequeue": { 34 | "type": "object", 35 | "additionalProperties": false 36 | } 37 | }, 38 | "additionalProperties": false 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /contracts/queue/schema/raw/instantiate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "InstantiateMsg", 4 | "type": "object", 5 | "additionalProperties": false 6 | } 7 | -------------------------------------------------------------------------------- /contracts/queue/schema/raw/migrate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "MigrateMsg", 4 | "type": "object", 5 | "additionalProperties": false 6 | } 7 | -------------------------------------------------------------------------------- /contracts/queue/schema/raw/response_to_count.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "CountResponse", 4 | "type": "object", 5 | "required": [ 6 | "count" 7 | ], 8 | "properties": { 9 | "count": { 10 | "type": "integer", 11 | "format": "uint32", 12 | "minimum": 0.0 13 | } 14 | }, 15 | "additionalProperties": false 16 | } 17 | -------------------------------------------------------------------------------- /contracts/queue/schema/raw/response_to_list.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ListResponse", 4 | "type": "object", 5 | "required": [ 6 | "early", 7 | "empty", 8 | "late" 9 | ], 10 | "properties": { 11 | "early": { 12 | "description": "List all IDs lower than 0x20", 13 | "type": "array", 14 | "items": { 15 | "type": "integer", 16 | "format": "uint32", 17 | "minimum": 0.0 18 | } 19 | }, 20 | "empty": { 21 | "description": "List an empty range, both bounded", 22 | "type": "array", 23 | "items": { 24 | "type": "integer", 25 | "format": "uint32", 26 | "minimum": 0.0 27 | } 28 | }, 29 | "late": { 30 | "description": "List all IDs starting from 0x20", 31 | "type": "array", 32 | "items": { 33 | "type": "integer", 34 | "format": "uint32", 35 | "minimum": 0.0 36 | } 37 | } 38 | }, 39 | "additionalProperties": false 40 | } 41 | -------------------------------------------------------------------------------- /contracts/queue/schema/raw/response_to_open_iterators.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "Empty", 4 | "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", 5 | "type": "object", 6 | "additionalProperties": false 7 | } 8 | -------------------------------------------------------------------------------- /contracts/queue/schema/raw/response_to_reducer.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ReducerResponse", 4 | "type": "object", 5 | "required": [ 6 | "counters" 7 | ], 8 | "properties": { 9 | "counters": { 10 | "type": "array", 11 | "items": { 12 | "type": "array", 13 | "items": [ 14 | { 15 | "type": "integer", 16 | "format": "int32" 17 | }, 18 | { 19 | "type": "integer", 20 | "format": "int32" 21 | } 22 | ], 23 | "maxItems": 2, 24 | "minItems": 2 25 | } 26 | } 27 | }, 28 | "additionalProperties": false 29 | } 30 | -------------------------------------------------------------------------------- /contracts/queue/schema/raw/response_to_sum.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "SumResponse", 4 | "type": "object", 5 | "required": [ 6 | "sum" 7 | ], 8 | "properties": { 9 | "sum": { 10 | "type": "integer", 11 | "format": "int32" 12 | } 13 | }, 14 | "additionalProperties": false 15 | } 16 | -------------------------------------------------------------------------------- /contracts/queue/schema/raw/sudo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ExecuteMsg", 4 | "oneOf": [ 5 | { 6 | "type": "object", 7 | "required": [ 8 | "enqueue" 9 | ], 10 | "properties": { 11 | "enqueue": { 12 | "type": "object", 13 | "required": [ 14 | "value" 15 | ], 16 | "properties": { 17 | "value": { 18 | "type": "integer", 19 | "format": "int32" 20 | } 21 | }, 22 | "additionalProperties": false 23 | } 24 | }, 25 | "additionalProperties": false 26 | }, 27 | { 28 | "type": "object", 29 | "required": [ 30 | "dequeue" 31 | ], 32 | "properties": { 33 | "dequeue": { 34 | "type": "object", 35 | "additionalProperties": false 36 | } 37 | }, 38 | "additionalProperties": false 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /contracts/queue/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | 3 | use queue::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | query: QueryMsg, 9 | execute: ExecuteMsg, 10 | migrate: MigrateMsg, 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /contracts/queue/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod msg; 3 | pub mod state; 4 | -------------------------------------------------------------------------------- /contracts/queue/src/msg.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::{cw_serde, QueryResponses}; 2 | 3 | #[cw_serde] 4 | pub enum ExecuteMsg { 5 | // Enqueue will add some value to the end of list 6 | Enqueue { value: i32 }, 7 | // Dequeue will remove value from start of the list 8 | Dequeue {}, 9 | } 10 | 11 | #[cw_serde] 12 | pub struct InstantiateMsg {} 13 | 14 | #[cw_serde] 15 | pub struct MigrateMsg {} 16 | 17 | #[cw_serde] 18 | #[derive(QueryResponses)] 19 | pub enum QueryMsg { 20 | // how many items are in the queue 21 | #[returns(CountResponse)] 22 | Count {}, 23 | // total of all values in the queue 24 | #[returns(SumResponse)] 25 | Sum {}, 26 | // Reducer holds open two iterators at once 27 | #[returns(ReducerResponse)] 28 | Reducer {}, 29 | #[returns(ListResponse)] 30 | List {}, 31 | /// Opens the given number of iterators for no reason other than testing. 32 | /// Returns and `Empty` response. 33 | #[returns(cosmwasm_std::Empty)] 34 | OpenIterators { count: u32 }, 35 | } 36 | 37 | #[cw_serde] 38 | pub struct CountResponse { 39 | pub count: u32, 40 | } 41 | 42 | #[cw_serde] 43 | pub struct SumResponse { 44 | pub sum: i32, 45 | } 46 | 47 | #[cw_serde] 48 | // the Vec contains pairs for every element in the queue 49 | // (value of item i, sum of all elements where value > value[i]) 50 | pub struct ReducerResponse { 51 | pub counters: Vec<(i32, i32)>, 52 | } 53 | 54 | #[cw_serde] 55 | pub struct ListResponse { 56 | /// List an empty range, both bounded 57 | pub empty: Vec, 58 | /// List all IDs lower than 0x20 59 | pub early: Vec, 60 | /// List all IDs starting from 0x20 61 | pub late: Vec, 62 | } 63 | -------------------------------------------------------------------------------- /contracts/queue/src/state.rs: -------------------------------------------------------------------------------- 1 | use schemars::JsonSchema; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | // we store one entry for each item in the queue 5 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] 6 | pub struct Item { 7 | pub value: i32, 8 | } 9 | -------------------------------------------------------------------------------- /contracts/reflect/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/reflect/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.rs] 11 | indent_size = 4 12 | -------------------------------------------------------------------------------- /contracts/reflect/.gitignore: -------------------------------------------------------------------------------- 1 | # Build results 2 | /target 3 | 4 | # Text file backups 5 | **/*.rs.bk 6 | 7 | # macOS 8 | .DS_Store 9 | 10 | # IDEs 11 | *.iml 12 | .idea 13 | -------------------------------------------------------------------------------- /contracts/reflect/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "reflect" 3 | version = "0.0.0" 4 | authors = ["Ethan Frey "] 5 | edition = "2021" 6 | publish = false 7 | description = "Reflect messages to use for test cases - based on cw-mask" 8 | license = "Apache-2.0" 9 | 10 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [profile.release] 16 | opt-level = 3 17 | debug = false 18 | rpath = false 19 | lto = true 20 | debug-assertions = false 21 | codegen-units = 1 22 | panic = 'abort' 23 | incremental = false 24 | overflow-checks = true 25 | 26 | [features] 27 | # Add feature "cranelift" to default if you need 32 bit or ARM support 28 | default = [] 29 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 30 | cranelift = ["cosmwasm-vm/cranelift"] 31 | 32 | [dependencies] 33 | cosmwasm-schema = { path = "../../packages/schema" } 34 | cosmwasm-std = { path = "../../packages/std", default-features = false, features = ["std", "staking", "stargate", "cosmwasm_2_0"] } 35 | schemars = "0.8.12" 36 | serde = { version = "1.0.103", default-features = false, features = ["derive"] } 37 | thiserror = "1.0.26" 38 | 39 | [dev-dependencies] 40 | cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["stargate"] } 41 | -------------------------------------------------------------------------------- /contracts/reflect/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Ethan Frey 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /contracts/reflect/schema/raw/instantiate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "InstantiateMsg", 4 | "type": "object", 5 | "additionalProperties": false 6 | } 7 | -------------------------------------------------------------------------------- /contracts/reflect/schema/raw/response_to_capitalized.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "CapitalizedResponse", 4 | "type": "object", 5 | "required": [ 6 | "text" 7 | ], 8 | "properties": { 9 | "text": { 10 | "type": "string" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/reflect/schema/raw/response_to_chain.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ChainResponse", 4 | "type": "object", 5 | "required": [ 6 | "data" 7 | ], 8 | "properties": { 9 | "data": { 10 | "$ref": "#/definitions/Binary" 11 | } 12 | }, 13 | "additionalProperties": false, 14 | "definitions": { 15 | "Binary": { 16 | "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", 17 | "type": "string" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /contracts/reflect/schema/raw/response_to_owner.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "OwnerResponse", 4 | "type": "object", 5 | "required": [ 6 | "owner" 7 | ], 8 | "properties": { 9 | "owner": { 10 | "type": "string" 11 | } 12 | }, 13 | "additionalProperties": false 14 | } 15 | -------------------------------------------------------------------------------- /contracts/reflect/schema/raw/response_to_raw.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "RawResponse", 4 | "type": "object", 5 | "required": [ 6 | "data" 7 | ], 8 | "properties": { 9 | "data": { 10 | "description": "The returned value of the raw query. Empty data can be the result of a non-existent key or an empty value. We cannot differentiate those two cases in cross contract queries.", 11 | "allOf": [ 12 | { 13 | "$ref": "#/definitions/Binary" 14 | } 15 | ] 16 | } 17 | }, 18 | "additionalProperties": false, 19 | "definitions": { 20 | "Binary": { 21 | "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", 22 | "type": "string" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /contracts/reflect/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | 3 | use reflect::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | query: QueryMsg, 9 | execute: ExecuteMsg, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/reflect/src/errors.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::StdError; 2 | use thiserror::Error; 3 | 4 | #[derive(Error, Debug, PartialEq)] 5 | pub enum ReflectError { 6 | #[error("{0}")] 7 | // let thiserror implement From for you 8 | Std(#[from] StdError), 9 | // this is whatever we want 10 | #[error("Permission denied: the sender is not the current owner")] 11 | NotCurrentOwner { expected: String, actual: String }, 12 | #[error("Messages empty. Must reflect at least one message")] 13 | MessagesEmpty, 14 | } 15 | -------------------------------------------------------------------------------- /contracts/reflect/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | mod errors; 3 | pub mod msg; 4 | pub mod state; 5 | 6 | #[cfg(not(target_arch = "wasm32"))] 7 | pub mod testing; 8 | -------------------------------------------------------------------------------- /contracts/reflect/src/state.rs: -------------------------------------------------------------------------------- 1 | use schemars::JsonSchema; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | use cosmwasm_std::{ 5 | from_json, 6 | storage_keys::{namespace_with_key, to_length_prefixed}, 7 | to_json_vec, Addr, Reply, StdError, StdResult, Storage, 8 | }; 9 | 10 | const CONFIG_KEY: &[u8] = b"config"; 11 | const RESULT_PREFIX: &[u8] = b"result"; 12 | 13 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] 14 | pub struct State { 15 | pub owner: Addr, 16 | } 17 | 18 | pub fn load_reply(storage: &dyn Storage, id: u64) -> StdResult { 19 | storage 20 | .get(&namespace_with_key(&[RESULT_PREFIX], &id.to_be_bytes())) 21 | .ok_or_else(|| StdError::not_found(format!("reply {id}"))) 22 | .and_then(from_json) 23 | } 24 | 25 | pub fn save_reply(storage: &mut dyn Storage, id: u64, reply: &Reply) -> StdResult<()> { 26 | storage.set( 27 | &namespace_with_key(&[RESULT_PREFIX], &id.to_be_bytes()), 28 | &to_json_vec(reply)?, 29 | ); 30 | Ok(()) 31 | } 32 | 33 | pub fn remove_reply(storage: &mut dyn Storage, id: u64) { 34 | storage.remove(&namespace_with_key(&[RESULT_PREFIX], &id.to_be_bytes())); 35 | } 36 | 37 | pub fn load_config(storage: &dyn Storage) -> StdResult { 38 | storage 39 | .get(&to_length_prefixed(CONFIG_KEY)) 40 | .ok_or_else(|| StdError::not_found("config")) 41 | .and_then(from_json) 42 | } 43 | 44 | pub fn save_config(storage: &mut dyn Storage, item: &State) -> StdResult<()> { 45 | storage.set(&to_length_prefixed(CONFIG_KEY), &to_json_vec(item)?); 46 | Ok(()) 47 | } 48 | -------------------------------------------------------------------------------- /contracts/staking/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/staking/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "staking" 3 | version = "0.0.0" 4 | authors = ["Ethan Frey "] 5 | edition = "2021" 6 | publish = false 7 | license = "Apache-2.0" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [lib] 12 | crate-type = ["cdylib", "rlib"] 13 | 14 | [profile.release] 15 | opt-level = 3 16 | debug = false 17 | rpath = false 18 | lto = true 19 | debug-assertions = false 20 | codegen-units = 1 21 | panic = 'abort' 22 | incremental = false 23 | overflow-checks = true 24 | 25 | [features] 26 | # Add feature "cranelift" to default if you need 32 bit or ARM support 27 | default = [] 28 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 29 | cranelift = ["cosmwasm-vm/cranelift"] 30 | 31 | [dependencies] 32 | cosmwasm-schema = { path = "../../packages/schema" } 33 | cosmwasm-std = { path = "../../packages/std", default-features = false, features = ["std", "staking"] } 34 | schemars = "0.8.12" 35 | serde = { version = "1.0.103", default-features = false, features = ["derive"] } 36 | snafu = "0.8.2" 37 | 38 | [dev-dependencies] 39 | cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["staking"] } 40 | -------------------------------------------------------------------------------- /contracts/staking/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Ethan Frey 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /contracts/staking/README.md: -------------------------------------------------------------------------------- 1 | # Staking Derivatives 2 | 3 | This is a sample contract that releases a minimal form of staking derivatives. 4 | This is to be used for integration tests and as a foundation for other to build 5 | more complex logic upon. 6 | 7 | ## Functionality 8 | 9 | On one side, this acts as a simplified ERC20-like token, holding a list of 10 | balances for multiple addresses, and exposing queries and transfers (no 11 | allowances and "transfer from" to focus the logic on the staking stuff). 12 | However, it has no initial balance. Instead, it mints and burns them based on 13 | delegations. 14 | 15 | For such a "bonding curve" we expose two additional message types. A "bond" 16 | message sends native staking tokens to the contract to be bonded to a validator 17 | and credits the user with the appropriate amount of derivative tokens. Likewise 18 | you can burn some of your derivative tokens, and the contract will unbond the 19 | proportional amount of stake to the user's account (after typical 21-day 20 | unbonding period). 21 | 22 | To show an example of charging for such a service, we allow the contract owner 23 | to take a small exit tax, thus maybe 98% of the tokens will be unbonded and sent 24 | to the original account, and 2% of the tokens are not unbonded, but rather 25 | transferred to the owners account. (The ownership can also be transferred). 26 | 27 | ## Using this project 28 | 29 | You should check out [Developing](./Developing.md) to explain more on how to run 30 | tests and develop code. Or go through the 31 | [online tutorial](https://book.cosmwasm.com/index.html) to get a better feel of 32 | how to develop. 33 | -------------------------------------------------------------------------------- /contracts/staking/schema/raw/response_to_balance.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "BalanceResponse", 4 | "type": "object", 5 | "required": [ 6 | "balance" 7 | ], 8 | "properties": { 9 | "balance": { 10 | "$ref": "#/definitions/Uint128" 11 | } 12 | }, 13 | "additionalProperties": false, 14 | "definitions": { 15 | "Uint128": { 16 | "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", 17 | "type": "string" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /contracts/staking/schema/raw/response_to_claims.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ClaimsResponse", 4 | "type": "object", 5 | "required": [ 6 | "claims" 7 | ], 8 | "properties": { 9 | "claims": { 10 | "$ref": "#/definitions/Uint128" 11 | } 12 | }, 13 | "additionalProperties": false, 14 | "definitions": { 15 | "Uint128": { 16 | "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", 17 | "type": "string" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /contracts/staking/schema/raw/response_to_token_info.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "TokenInfoResponse", 4 | "description": "TokenInfoResponse is info to display the derivative token in a UI", 5 | "type": "object", 6 | "required": [ 7 | "decimals", 8 | "name", 9 | "symbol" 10 | ], 11 | "properties": { 12 | "decimals": { 13 | "description": "decimal places of the derivative token (for UI)", 14 | "type": "integer", 15 | "format": "uint8", 16 | "minimum": 0.0 17 | }, 18 | "name": { 19 | "description": "name of the derivative token", 20 | "type": "string" 21 | }, 22 | "symbol": { 23 | "description": "symbol / ticker of the derivative token", 24 | "type": "string" 25 | } 26 | }, 27 | "additionalProperties": false 28 | } 29 | -------------------------------------------------------------------------------- /contracts/staking/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | 3 | use staking::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | query: QueryMsg, 9 | execute: ExecuteMsg, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/staking/src/errors.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::StdError; 2 | use snafu::Snafu; 3 | 4 | #[derive(Snafu, Debug)] 5 | #[snafu(context(suffix(false)), visibility(pub(crate)))] 6 | pub enum StakingError { 7 | /// this is needed so we can use `bucket.load(...)?` and have it auto-converted to the custom error 8 | #[snafu(display("StdError: {}", original))] 9 | Std { original: StdError }, 10 | #[snafu(display("Unauthorized"))] 11 | Unauthorized { backtrace: Option }, 12 | } 13 | 14 | impl From for StakingError { 15 | fn from(original: StdError) -> Self { 16 | Std { original }.build() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /contracts/staking/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | mod errors; 3 | pub mod msg; 4 | pub mod state; 5 | -------------------------------------------------------------------------------- /contracts/virus/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | integration-test = "test --test integration" 6 | schema = "run --bin schema" 7 | -------------------------------------------------------------------------------- /contracts/virus/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "virus" 3 | version = "0.0.0" 4 | authors = ["Simon Warta "] 5 | edition = "2021" 6 | publish = false 7 | license = "Apache-2.0" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [lib] 12 | crate-type = ["cdylib", "rlib"] 13 | 14 | [profile.release] 15 | opt-level = 3 16 | debug = false 17 | rpath = false 18 | lto = true 19 | debug-assertions = false 20 | codegen-units = 1 21 | panic = 'abort' 22 | incremental = false 23 | overflow-checks = true 24 | 25 | [features] 26 | # Add feature "cranelift" to default if you need 32 bit or ARM support 27 | default = [] 28 | # Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines. 29 | cranelift = ["cosmwasm-vm/cranelift"] 30 | 31 | [dependencies] 32 | cosmwasm-schema = { path = "../../packages/schema" } 33 | cosmwasm-std = { path = "../../packages/std", features = ["cosmwasm_1_2"] } 34 | schemars = "0.8.12" 35 | serde = { version = "1.0.103", default-features = false, features = ["derive"] } 36 | thiserror = "1.0.26" 37 | 38 | [dev-dependencies] 39 | cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] } 40 | -------------------------------------------------------------------------------- /contracts/virus/README.md: -------------------------------------------------------------------------------- 1 | # Virus contract 2 | 3 | A contract that clones itself over various levels. 4 | -------------------------------------------------------------------------------- /contracts/virus/schema/raw/execute.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "ExecuteMsg", 4 | "oneOf": [ 5 | { 6 | "type": "object", 7 | "required": [ 8 | "spread" 9 | ], 10 | "properties": { 11 | "spread": { 12 | "type": "object", 13 | "required": [ 14 | "levels", 15 | "parent_path" 16 | ], 17 | "properties": { 18 | "levels": { 19 | "description": "The number of levels of spreading. When set to 0, the contract performs a no-op.", 20 | "type": "integer", 21 | "format": "uint32", 22 | "minimum": 0.0 23 | }, 24 | "parent_path": { 25 | "description": "A slash separated path to the instance creating this one. The root is the empty string.", 26 | "type": "string" 27 | } 28 | }, 29 | "additionalProperties": false 30 | } 31 | }, 32 | "additionalProperties": false 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /contracts/virus/schema/raw/instantiate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "title": "InstantiateMsg", 4 | "type": "object", 5 | "additionalProperties": false 6 | } 7 | -------------------------------------------------------------------------------- /contracts/virus/schema/virus.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract_name": "virus", 3 | "contract_version": "0.0.0", 4 | "idl_version": "1.0.0", 5 | "instantiate": { 6 | "$schema": "http://json-schema.org/draft-07/schema#", 7 | "title": "InstantiateMsg", 8 | "type": "object", 9 | "additionalProperties": false 10 | }, 11 | "execute": { 12 | "$schema": "http://json-schema.org/draft-07/schema#", 13 | "title": "ExecuteMsg", 14 | "oneOf": [ 15 | { 16 | "type": "object", 17 | "required": [ 18 | "spread" 19 | ], 20 | "properties": { 21 | "spread": { 22 | "type": "object", 23 | "required": [ 24 | "levels", 25 | "parent_path" 26 | ], 27 | "properties": { 28 | "levels": { 29 | "description": "The number of levels of spreading. When set to 0, the contract performs a no-op.", 30 | "type": "integer", 31 | "format": "uint32", 32 | "minimum": 0.0 33 | }, 34 | "parent_path": { 35 | "description": "A slash separated path to the instance creating this one. The root is the empty string.", 36 | "type": "string" 37 | } 38 | }, 39 | "additionalProperties": false 40 | } 41 | }, 42 | "additionalProperties": false 43 | } 44 | ] 45 | }, 46 | "query": null, 47 | "migrate": null, 48 | "sudo": null, 49 | "responses": null 50 | } 51 | -------------------------------------------------------------------------------- /contracts/virus/src/bin/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | 3 | use virus::msg::{ExecuteMsg, InstantiateMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | execute: ExecuteMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/virus/src/errors.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{Instantiate2AddressError, StdError}; 2 | use thiserror::Error; 3 | 4 | #[derive(Error, Debug, PartialEq)] 5 | pub enum ContractError { 6 | #[error("{0}")] 7 | /// this is needed so we can use `bucket.load(...)?` and have it auto-converted to the custom error 8 | Std(#[from] StdError), 9 | #[error("{0}")] 10 | Instantiate2Address(#[from] Instantiate2AddressError), 11 | } 12 | -------------------------------------------------------------------------------- /contracts/virus/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | mod errors; 3 | pub mod msg; 4 | -------------------------------------------------------------------------------- /contracts/virus/src/msg.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | 3 | #[cw_serde] 4 | pub struct InstantiateMsg {} 5 | 6 | #[cw_serde] 7 | pub enum ExecuteMsg { 8 | Spread { 9 | /// A slash separated path to the instance creating this one. 10 | /// The root is the empty string. 11 | parent_path: String, 12 | /// The number of levels of spreading. When set to 0, the contract performs a no-op. 13 | levels: u32, 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /contracts/virus/tests/integration.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /devtools/build_min.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | rm Cargo.lock 6 | cargo +nightly build -Zminimal-versions 7 | 8 | for contract_dir in contracts/*/; do 9 | ( 10 | cd "$contract_dir" 11 | rm Cargo.lock 12 | cargo +nightly build -Zminimal-versions 13 | ) 14 | done 15 | -------------------------------------------------------------------------------- /devtools/check_contracts_fast.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | for contract_dir in contracts/*/; do 6 | ( 7 | cd "$contract_dir" 8 | cargo fmt 9 | mkdir -p target/wasm32-unknown-unknown/release/ 10 | touch target/wasm32-unknown-unknown/release/"$(basename "$contract_dir" | tr - _)".wasm 11 | cargo check --tests 12 | ) 13 | done 14 | -------------------------------------------------------------------------------- /devtools/check_contracts_full.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | GLOBIGNORE="contracts/floaty/" 6 | for contract_dir in contracts/*/; do 7 | ( 8 | cd "$contract_dir" 9 | cargo fmt 10 | mkdir -p target/wasm32-unknown-unknown/release/ 11 | touch target/wasm32-unknown-unknown/release/"$(basename "$contract_dir" | tr - _)".wasm 12 | cargo check --tests 13 | cargo unit-test 14 | touch src/*.rs # Needed because check and clippy share the same build cache such that clippy warnings are hidden when check wrote to the build cache 15 | cargo clippy --all-targets -- -D warnings 16 | cargo schema 17 | cargo wasm 18 | cargo integration-test 19 | ) 20 | done 21 | -------------------------------------------------------------------------------- /devtools/check_contracts_medium.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | GLOBIGNORE="contracts/floaty/" 6 | for contract_dir in contracts/*/; do 7 | ( 8 | cd "$contract_dir" 9 | cargo fmt 10 | mkdir -p target/wasm32-unknown-unknown/release/ 11 | touch target/wasm32-unknown-unknown/release/"$(basename "$contract_dir" | tr - _)".wasm 12 | cargo check --tests 13 | cargo unit-test 14 | touch src/*.rs # Needed because check and clippy share the same build cache such that clippy warnings are hidden when check wrote to the build cache 15 | cargo clippy --all-targets -- -D warnings 16 | cargo schema 17 | cargo wasm-debug 18 | ) 19 | done 20 | -------------------------------------------------------------------------------- /devtools/check_workspace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | cargo fmt 6 | (cd packages/crypto && cargo check && cargo clippy --all-targets -- -D warnings) 7 | (cd packages/derive && cargo check && cargo clippy --all-targets -- -D warnings) 8 | ( 9 | cd packages/std 10 | # default, min, all 11 | cargo check 12 | cargo check --no-default-features --features std 13 | cargo check --features std,abort,iterator,staking,stargate,cosmwasm_1_2 14 | cargo wasm-debug 15 | cargo wasm-debug --features std,iterator,staking,stargate 16 | cargo clippy --all-targets --features std,iterator,staking,stargate -- -D warnings 17 | ) 18 | (cd packages/schema && cargo build && cargo clippy --all-targets -- -D warnings) 19 | (cd packages/schema-derive && cargo build && cargo clippy --all-targets -- -D warnings) 20 | (cd packages/vm && cargo build --features iterator,stargate && cargo clippy --all-targets --features iterator,stargate -- -D warnings) 21 | (cd packages/check && cargo build && cargo clippy --all-targets -- -D warnings) 22 | -------------------------------------------------------------------------------- /devtools/clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | (cd packages/std && cargo clean) 6 | (cd packages/crypto && cargo clean) 7 | (cd packages/schema && cargo clean) 8 | (cd packages/vm && cargo clean) 9 | -------------------------------------------------------------------------------- /devtools/clean_contracts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | for contract_dir in contracts/*/; do 6 | (cd "$contract_dir" && cargo clean) 7 | done 8 | -------------------------------------------------------------------------------- /devtools/format_md.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | # Running with -c makes the script only validate instead of editing in place. 6 | op="write" 7 | while getopts c option; do 8 | case "${option}" in 9 | c) op="check" ;; 10 | *) ;; 11 | esac 12 | done 13 | 14 | npx prettier@2.7.1 --$op "./**/*.md" 15 | -------------------------------------------------------------------------------- /devtools/format_sh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | # Running with -c makes the script only validate instead of editing in place. 6 | op="w" 7 | while getopts c option; do 8 | case "${option}" in 9 | c) op="d" ;; 10 | *) ;; 11 | esac 12 | done 13 | 14 | shfmt -$op devtools packages 15 | -------------------------------------------------------------------------------- /devtools/format_yml.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | # Running with -c makes the script only validate instead of editing in place. 6 | op="write" 7 | while getopts c option; do 8 | case "${option}" in 9 | c) op="check" ;; 10 | *) ;; 11 | esac 12 | done 13 | 14 | npx prettier@2.7.1 --$op "./**/*.yml" 15 | -------------------------------------------------------------------------------- /devtools/release_checks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Move to the workspace root 4 | WORKSPACE_PATH=$(dirname $(cargo locate-project --workspace --message-format=plain)) 5 | cd $WORKSPACE_PATH 6 | 7 | cargo build 8 | 9 | for contract_dir in contracts/*/; do 10 | (cd "$contract_dir" && cargo build) 11 | done 12 | -------------------------------------------------------------------------------- /devtools/test_workspace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | cargo fmt 6 | (cd packages/crypto && cargo test) 7 | (cd packages/std && cargo test --features iterator,cosmwasm_1_2) 8 | (cd packages/schema && cargo test) 9 | (cd packages/schema-derive && cargo test) 10 | (cd packages/vm && cargo test --features iterator,stargate) 11 | -------------------------------------------------------------------------------- /devtools/update_crate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset -o pipefail 3 | command -v shellcheck >/dev/null && shellcheck "$0" 4 | 5 | CRATE_NAME="$1" 6 | 7 | # Update root Cargo.lock 8 | cargo update -p "$CRATE_NAME" 9 | 10 | for contract_dir in contracts/*/; do 11 | ( 12 | cd "$contract_dir" 13 | cargo update -p "$CRATE_NAME" 14 | ) 15 | done 16 | -------------------------------------------------------------------------------- /docs/CAPABILITIES-BUILT-IN.md: -------------------------------------------------------------------------------- 1 | # Built-in capabilities 2 | 3 | Since capabilities can be created between contract and environment, we don't 4 | know them all in the VM. This is a list of all built-in capabilities, but chains 5 | might define others. 6 | 7 | - `iterator` is for storage backends that allow range queries. Not all types of 8 | databases do that. There are trees that don't allow it and Secret Network does 9 | not support iterators for other technical reasons. 10 | - `stargate` is for messages and queries that came with the Cosmos SDK upgrade 11 | "Stargate". It primarily includes protobuf messages and IBC support. 12 | - `staking` is for chains with the Cosmos SDK staking module. There are Cosmos 13 | chains that don't use this (e.g. Tgrade). 14 | - `cosmwasm_1_1` enables the `BankQuery::Supply` query. Only chains running 15 | CosmWasm `1.1.0` or higher support this. 16 | - `cosmwasm_1_2` enables the `GovMsg::VoteWeighted` and `WasmMsg::Instantiate2` 17 | messages. Only chains running CosmWasm `1.2.0` or higher support this. 18 | - `cosmwasm_1_3` enables the `BankQuery::AllDenomMetadata`, 19 | `BankQuery::DenomMetadata` and `DistributionQuery::DelegatorWithdrawAddress` 20 | queries, as well as `DistributionMsg::FundCommunityPool`. Only chains running 21 | CosmWasm `1.3.0` or higher support this. 22 | - `cosmwasm_1_4` enables the `DistributionQuery::DelegationRewards`, 23 | `DistributionQuery::DelegationTotalRewards` and 24 | `DistributionQuery::DelegatorValidators` queries. Only chains running CosmWasm 25 | `1.4.0` or higher support this. 26 | - `cosmwasm_2_0` enables `CosmosMsg::Any` and `QueryRequest::Grpc`. Only chains 27 | running CosmWasm `2.0.0` or higher support this. 28 | -------------------------------------------------------------------------------- /docs/FEATURES.md: -------------------------------------------------------------------------------- 1 | Features have been renamed to capabilities. See 2 | [CAPABILITIES.md](./CAPABILITIES.md) in the same folder. 3 | -------------------------------------------------------------------------------- /docs/MSRV.md: -------------------------------------------------------------------------------- 1 | # Minimum Supported Rust Version (MSRV) 2 | 3 | We try to keep the range of supported Rust compiler versions as wide as possible 4 | to avoid unnecessary inconvenience for contract developers. However, we give up 5 | all strong MSRV guarantees as the Rust ecosystem currently makes it impossible 6 | to do so. See e.g. 7 | 8 | - https://github.com/rust-lang/api-guidelines/issues/252 9 | - https://github.com/CosmWasm/cosmwasm/issues/1244 10 | - https://github.com/wasmerio/wasmer/issues/2819 11 | - https://github.com/CosmWasm/cosmwasm/issues/1204 12 | -------------------------------------------------------------------------------- /docs/simulate_riffle_shuffle.py: -------------------------------------------------------------------------------- 1 | import functools 2 | 3 | # Create a function that executed f recusively n times, i.e. f**n 4 | def power(f, n): 5 | functions = [f for _ in range(n)] 6 | def compose2(f, g): 7 | return lambda x: f(g(x)) 8 | return functools.reduce(compose2, functions, lambda x: x) 9 | 10 | # Rotate input to the left by n positions 11 | def rotate_left(input, n): 12 | return input[n:] + input[0:n] 13 | 14 | def riffle_shuffle(input): 15 | left = input[0:len(input)//2] 16 | right = input[len(input)//2:] 17 | i = 0 18 | out = "" 19 | while i < len(input)//2: 20 | out += right[i] + left[i] 21 | i += 1 22 | return out 23 | 24 | values = [ 25 | "alice123----------------", # 0 26 | "alice485----------------", # 1 27 | "aliceimwunderland521----", # 2 28 | "bob1--------------------", # 3 29 | "bob123------------------", # 4 30 | "bob485------------------", # 5 31 | "bob511------------------", # 6 32 | "creator-----------------", # 7 33 | ] 34 | 35 | def digit_sum(input): 36 | def value(char): 37 | if char == "-": 38 | return 0 39 | else: 40 | return ord(char) 41 | return sum([value(c) for c in input]) 42 | 43 | shuffle = power(riffle_shuffle, 18) 44 | rotated = [rotate_left(v, digit_sum(v) % 24) for v in values] 45 | rotated_shuffled = [shuffle(r) for r in rotated] 46 | shuffled = [shuffle(v) for v in values] 47 | 48 | print("Original:\n" + "\n".join(sorted(values))) 49 | print() 50 | # digit_sums = [str(digit_sum(v) % 24) for v in values] 51 | # print("Digit sums:\n" + "\n".join(digit_sums)) 52 | # print() 53 | print("Rotated:\n" + "\n".join(sorted(rotated))) 54 | print() 55 | print("Shuffled:\n" + "\n".join(sorted(shuffled))) 56 | print() 57 | print("Rotated+Shuffled:\n" + "\n".join(sorted(rotated_shuffled))) 58 | -------------------------------------------------------------------------------- /packages/check/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cosmwasm-check" 3 | version.workspace = true 4 | authors = ["Mauro Lacy "] 5 | edition = "2021" 6 | description = "A CLI tool for verifying CosmWasm smart contracts" 7 | repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/check" 8 | license = "Apache-2.0" 9 | 10 | [dependencies] 11 | anyhow = "1.0.57" 12 | clap = "4" 13 | colored = "2.1.0" 14 | cosmwasm-vm = { path = "../vm", version = "=2.0.1" } 15 | cosmwasm-std = { path = "../std", version = "=2.0.1" } 16 | 17 | [dev-dependencies] 18 | assert_cmd = "2.0.12" 19 | predicates = "3" 20 | -------------------------------------------------------------------------------- /packages/check/README.md: -------------------------------------------------------------------------------- 1 | # cosmwasm-check 2 | 3 | It allows checking if the Wasm binary is a proper smart contract that's ready to 4 | be uploaded to the blockchain. 5 | 6 | ## Installation 7 | 8 | ```sh 9 | cargo install cosmwasm-check 10 | ``` 11 | 12 | ## Usage 13 | 14 | Get help and info: 15 | 16 | ```sh 17 | cosmwasm-check -h 18 | ``` 19 | 20 | Check some contracts: 21 | 22 | ```sh 23 | cosmwasm-check artifacts/hackatom.wasm artifacts/burner.wasm 24 | ``` 25 | 26 | Check an entire directory of contracts (shell dependent): 27 | 28 | ```sh 29 | cosmwasm-check artifacts/*.wasm 30 | ``` 31 | 32 | Check if a contract would ran on a blockchain with a specific set of 33 | capabilities: 34 | 35 | ```sh 36 | cosmwasm-check --available-capabilities iterator,osmosis,friendship artifacts/hackatom.wasm 37 | ``` 38 | 39 | ## License 40 | 41 | This package is part of the cosmwasm repository, licensed under the Apache 42 | License 2.0 (see [NOTICE](https://github.com/CosmWasm/cosmwasm/blob/main/NOTICE) 43 | and [LICENSE](https://github.com/CosmWasm/cosmwasm/blob/main/LICENSE)). 44 | -------------------------------------------------------------------------------- /packages/core/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | no-std = "build --release --lib --target thumbv7em-none-eabi" 3 | wasm = "build --release --lib --target wasm32-unknown-unknown" 4 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 5 | unit-test = "test --lib" 6 | -------------------------------------------------------------------------------- /packages/core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cosmwasm-core" 3 | version.workspace = true 4 | edition = "2021" 5 | description = "Components of cosmwasm-std that can be used in no_std environments" 6 | repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/core" 7 | license = "Apache-2.0" 8 | readme = "README.md" 9 | 10 | [package.metadata.release] 11 | release = false 12 | 13 | [dependencies] 14 | base64 = { version = "0.22.0", default-features = false, features = ["alloc"] } 15 | bnum = "0.11.0" 16 | cosmwasm-crypto = { version = "2.0.1", path = "../crypto" } 17 | derive_more = { version = "1.0.0-beta.6", default-features = false, features = ["display", "from"] } 18 | hex = { version = "0.4.3", default-features = false, features = ["alloc"] } 19 | schemars = { version = "0.8.16", optional = true } 20 | serde = { version = "1.0.197", default-features = false, features = ["alloc", "derive"] } 21 | sha2 = { version = "0.10.8", default-features = false } 22 | static_assertions = "1.1.0" 23 | thiserror = { version = "1.0.26", optional = true } 24 | 25 | [features] 26 | std = ["dep:schemars", "dep:thiserror"] 27 | 28 | [dev-dependencies] 29 | # Cyclic dependencies for doc tests.. 30 | cosmwasm-std = { path = "../std", version = "2.0.1" } 31 | crc32fast = { version = "1.4.0", default-features = false } 32 | hex-literal = "0.4.1" 33 | serde_json = "1.0.114" 34 | -------------------------------------------------------------------------------- /packages/core/README.md: -------------------------------------------------------------------------------- 1 | # cosmwasm-core 2 | 3 | [![cosmwasm-core on crates.io](https://img.shields.io/crates/v/cosmwasm-core.svg)](https://crates.io/crates/cosmwasm-core) 4 | 5 | This crate contains components of cosmwasm-std that can be used in a 6 | [no_std environment](https://docs.rust-embedded.org/book/intro/no-std.html). All 7 | symbols are re-exported by cosmwasm-std, such that contract developers don't 8 | need to add this dependency directly. It is recommended to only use cosmwasm-std 9 | whenever possible. 10 | 11 | ## License 12 | 13 | This package is part of the cosmwasm repository, licensed under the Apache 14 | License 2.0 (see [NOTICE](https://github.com/CosmWasm/cosmwasm/blob/main/NOTICE) 15 | and [LICENSE](https://github.com/CosmWasm/cosmwasm/blob/main/LICENSE)). 16 | -------------------------------------------------------------------------------- /packages/core/src/__internal.rs: -------------------------------------------------------------------------------- 1 | //! 2 | //! # ⚠ DO NOT DEPEND ON THIS AS AN OUTSIDE CONSUMER 3 | //! 4 | //! **THIS MODULE IS SEMVER EXEMPT AND ONLY MEANT TO SHARE TYPES BETWEEN CORE AND STD** 5 | //! 6 | //! Module for re-exporting implementation details from `core` to `std` 7 | //! 8 | 9 | pub use crate::__internal__forward_ref_partial_eq as forward_ref_partial_eq; 10 | -------------------------------------------------------------------------------- /packages/core/src/errors/mod.rs: -------------------------------------------------------------------------------- 1 | mod backtrace; 2 | mod core_error; 3 | mod recover_pubkey_error; 4 | mod system_error; 5 | mod verification_error; 6 | 7 | pub(crate) use backtrace::{impl_from_err, BT}; 8 | pub use core_error::{ 9 | CheckedFromRatioError, CheckedMultiplyFractionError, CheckedMultiplyRatioError, 10 | CoinFromStrError, CoinsError, ConversionOverflowError, CoreError, CoreResult, 11 | DivideByZeroError, DivisionError, OverflowError, OverflowOperation, RoundDownOverflowError, 12 | RoundUpOverflowError, 13 | }; 14 | pub use recover_pubkey_error::RecoverPubkeyError; 15 | pub use system_error::SystemError; 16 | pub use verification_error::VerificationError; 17 | -------------------------------------------------------------------------------- /packages/core/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! cosmwasm-core contains components of cosmwasm-std that can be used in a no_std environment. 2 | //! All symbols are re-exported by cosmwasm-std, such that contract developers don't need to 3 | //! add this dependency directly. It is recommended to only use cosmwasm-std whenever possible. 4 | 5 | #![cfg_attr(not(feature = "std"), no_std)] 6 | 7 | #[macro_use] 8 | extern crate alloc; 9 | 10 | #[cfg(test)] 11 | extern crate std; // allow for file I/O during tests 12 | 13 | mod addresses; 14 | mod binary; 15 | mod encoding; 16 | mod errors; 17 | mod forward_ref; 18 | mod hex_binary; 19 | mod math; 20 | mod timestamp; 21 | 22 | #[doc(hidden)] 23 | pub mod __internal; 24 | 25 | use crate::__internal__forward_ref_partial_eq as forward_ref_partial_eq; 26 | 27 | pub use crate::addresses::{instantiate2_address, Addr, CanonicalAddr, Instantiate2AddressError}; 28 | pub use crate::binary::Binary; 29 | pub use crate::encoding::{from_base64, from_hex, to_base64, to_hex}; 30 | pub use crate::errors::{ 31 | CheckedFromRatioError, CheckedMultiplyFractionError, CheckedMultiplyRatioError, 32 | CoinFromStrError, CoinsError, ConversionOverflowError, CoreError, CoreResult, 33 | DivideByZeroError, DivisionError, OverflowError, OverflowOperation, RecoverPubkeyError, 34 | RoundDownOverflowError, RoundUpOverflowError, SystemError, VerificationError, 35 | }; 36 | pub use crate::hex_binary::HexBinary; 37 | pub use crate::math::{ 38 | Decimal, Decimal256, Decimal256RangeExceeded, DecimalRangeExceeded, Fraction, Int128, Int256, 39 | Int512, Int64, Isqrt, SignedDecimal, SignedDecimal256, SignedDecimal256RangeExceeded, 40 | SignedDecimalRangeExceeded, Uint128, Uint256, Uint512, Uint64, 41 | }; 42 | pub use crate::timestamp::Timestamp; 43 | 44 | /// Exposed for testing only 45 | /// Both unit tests and integration tests are compiled to native code, so everything in here does not need to compile to Wasm. 46 | #[cfg(not(target_arch = "wasm32"))] 47 | pub mod testing; 48 | -------------------------------------------------------------------------------- /packages/core/src/math/num_consts.rs: -------------------------------------------------------------------------------- 1 | /// Crate internal trait for all our signed and unsigned number types 2 | pub(crate) trait NumConsts { 3 | const MAX: Self; 4 | const MIN: Self; 5 | const ZERO: Self; 6 | const ONE: Self; 7 | } 8 | -------------------------------------------------------------------------------- /packages/core/src/testing/mod.rs: -------------------------------------------------------------------------------- 1 | mod assertions; 2 | 3 | pub use assertions::assert_approx_eq_impl; 4 | #[cfg(test)] 5 | pub use assertions::assert_hash_works_impl; 6 | -------------------------------------------------------------------------------- /packages/crypto/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cosmwasm-crypto" 3 | version.workspace = true 4 | authors = ["Mauro Lacy "] 5 | edition = "2021" 6 | description = "Crypto bindings for cosmwasm contracts" 7 | repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/crypto" 8 | license = "Apache-2.0" 9 | 10 | [features] 11 | default = [] 12 | std = ["dep:thiserror"] 13 | 14 | [lib] 15 | # See https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options 16 | bench = false 17 | 18 | [dependencies] 19 | derive_more = { version = "1.0.0-beta.6", default-features = false, features = ["display", "from"] } 20 | k256 = { version = "0.13.3", default-features = false, features = ["ecdsa"] } 21 | ed25519-zebra = { version = "4.0.3", default-features = false } 22 | digest = "0.10" 23 | rand_core = "0.6" 24 | # Not used directly, but needed to bump transitive dependency, see: https://github.com/CosmWasm/cosmwasm/pull/1899 for details. 25 | ecdsa = "0.16.2" 26 | p256 = { version = "0.13.2", default-features = false, features = ["ecdsa"] } 27 | thiserror = { version = "1.0.26", optional = true } 28 | 29 | [dev-dependencies] 30 | criterion = "0.5.1" 31 | rand_core = { version = "0.6", features = ["getrandom"] } 32 | serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] } 33 | serde_json = "1.0.40" 34 | sha2 = "0.10" 35 | sha3 = "0.10" 36 | hex = { version = "0.4", features = ["serde"] } 37 | hex-literal = "0.4.1" 38 | english-numbers = "0.3" 39 | 40 | [[bench]] 41 | name = "main" 42 | harness = false 43 | -------------------------------------------------------------------------------- /packages/crypto/README.md: -------------------------------------------------------------------------------- 1 | # CosmWasm Crypto 2 | 3 | [![cosmwasm-crypto on crates.io](https://img.shields.io/crates/v/cosmwasm-crypto.svg)](https://crates.io/crates/cosmwasm-crypto) 4 | 5 | This crate implements cryptography-related functions, so that they can be 6 | available for both, the [cosmwasm-vm](`https://crates.io/crates/cosmwasm-vm`) 7 | and [cosmwasm-std](`https://crates.io/crates/cosmwasm-std`) crates. 8 | 9 | ## Implementations 10 | 11 | - `secp256k1_verify()`: Digital signature verification using the ECDSA secp256k1 12 | scheme, for Cosmos signature / public key formats. 13 | - `secp256r1_verify()`: Digital signature verification using the ECDSA secp256r1 14 | scheme, for Cosmos signature / public key formats. 15 | - `ed25519_verify()`: Digital signature verification using the EdDSA ed25519 16 | scheme, for Tendermint signature / public key formats. 17 | - `ed25519_batch_verify()`: Batch digital signature verification using the EdDSA 18 | ed25519 scheme, for Tendermint signature / public key formats. 19 | 20 | ## Benchmarking 21 | 22 | ``` 23 | cd packages/crypto 24 | cargo bench 25 | ``` 26 | 27 | ## License 28 | 29 | This package is part of the cosmwasm repository, licensed under the Apache 30 | License 2.0 (see [NOTICE](https://github.com/CosmWasm/cosmwasm/blob/main/NOTICE) 31 | and [LICENSE](https://github.com/CosmWasm/cosmwasm/blob/main/LICENSE)). 32 | -------------------------------------------------------------------------------- /packages/crypto/src/backtrace.rs: -------------------------------------------------------------------------------- 1 | use alloc::boxed::Box; 2 | use core::fmt::{Debug, Display, Formatter, Result}; 3 | 4 | /// This wraps an actual backtrace to achieve two things: 5 | /// - being able to fill this with a stub implementation in `no_std` environments 6 | /// - being able to use this in conjunction with [`thiserror::Error`] 7 | pub struct BT(Box); 8 | 9 | impl BT { 10 | #[track_caller] 11 | pub fn capture() -> Self { 12 | // in case of no_std, we can fill with a stub here 13 | #[cfg(feature = "std")] 14 | { 15 | #[cfg(target_arch = "wasm32")] 16 | return BT(Box::new(std::backtrace::Backtrace::disabled())); 17 | #[cfg(not(target_arch = "wasm32"))] 18 | return BT(Box::new(std::backtrace::Backtrace::capture())); 19 | } 20 | #[cfg(not(feature = "std"))] 21 | { 22 | BT(Box::new(Stub)) 23 | } 24 | } 25 | } 26 | 27 | trait Printable: Debug + Display {} 28 | impl Printable for T where T: Debug + Display {} 29 | 30 | impl Debug for BT { 31 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { 32 | Debug::fmt(&self.0, f) 33 | } 34 | } 35 | 36 | impl Display for BT { 37 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { 38 | Display::fmt(&self.0, f) 39 | } 40 | } 41 | 42 | #[allow(unused)] 43 | struct Stub; 44 | 45 | impl Debug for Stub { 46 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { 47 | write!(f, "") 48 | } 49 | } 50 | 51 | impl Display for Stub { 52 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { 53 | write!(f, "") 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /packages/crypto/src/ecdsa.rs: -------------------------------------------------------------------------------- 1 | /// Max length of a message hash for secp256k1 verification in bytes. 2 | /// This is typically a 32 byte output of e.g. SHA-256 or Keccak256. In theory shorter values 3 | /// are possible but currently not supported by the implementation. Let us know when you need them. 4 | pub const MESSAGE_HASH_MAX_LEN: usize = 32; 5 | 6 | /// ECDSA (secp256k1) parameters 7 | /// Length of a serialized signature 8 | pub const ECDSA_SIGNATURE_LEN: usize = 64; 9 | 10 | /// Length of a serialized compressed public key 11 | pub(crate) const ECDSA_COMPRESSED_PUBKEY_LEN: usize = 33; 12 | /// Length of a serialized uncompressed public key 13 | pub(crate) const ECDSA_UNCOMPRESSED_PUBKEY_LEN: usize = 65; 14 | /// Max length of a serialized public key 15 | pub const ECDSA_PUBKEY_MAX_LEN: usize = ECDSA_UNCOMPRESSED_PUBKEY_LEN; 16 | -------------------------------------------------------------------------------- /packages/crypto/src/identity_digest.rs: -------------------------------------------------------------------------------- 1 | //! Dummy 256-bits Digest impl. 2 | //! This digest stores/accepts a value of the proper length. 3 | //! To be used for / with already hashed values, just to comply with the Digest contract. 4 | //! 5 | //! Adapted from `sha2` [sha256.rs](https://github.com/RustCrypto/hashes/blob/master/sha2/src/sha256.rs) 6 | use digest::consts::U32; 7 | use digest::generic_array::GenericArray; 8 | use digest::{FixedOutput, HashMarker, Output, OutputSizeUser, Reset, Update}; 9 | 10 | /// The 256-bits identity container 11 | #[derive(Clone, Default)] 12 | pub struct Identity256 { 13 | array: GenericArray, 14 | } 15 | 16 | impl Update for Identity256 { 17 | fn update(&mut self, hash: &[u8]) { 18 | assert_eq!(hash.as_ref().len(), 32); 19 | self.array = *GenericArray::from_slice(hash); 20 | } 21 | } 22 | 23 | impl OutputSizeUser for Identity256 { 24 | type OutputSize = U32; 25 | } 26 | 27 | impl FixedOutput for Identity256 { 28 | fn finalize_into(self, out: &mut Output) { 29 | *out = self.array; 30 | } 31 | } 32 | 33 | impl HashMarker for Identity256 {} 34 | 35 | impl Reset for Identity256 { 36 | fn reset(&mut self) { 37 | *self = Self::default(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/crypto/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! The crypto crate is intended to be used in internal crates / utils. 2 | //! Please don't use any of these types directly, as 3 | //! they might change frequently, or be removed in the future. 4 | //! This crate does not adhere to semantic versioning. 5 | 6 | #![cfg_attr(not(feature = "std"), no_std)] 7 | 8 | extern crate alloc; 9 | 10 | #[cfg(test)] 11 | extern crate std; // allow for file I/O during tests 12 | 13 | mod backtrace; 14 | mod ecdsa; 15 | mod ed25519; 16 | mod errors; 17 | mod identity_digest; 18 | mod secp256k1; 19 | mod secp256r1; 20 | 21 | #[doc(hidden)] 22 | pub use crate::ecdsa::{ECDSA_PUBKEY_MAX_LEN, ECDSA_SIGNATURE_LEN, MESSAGE_HASH_MAX_LEN}; 23 | #[doc(hidden)] 24 | pub use crate::ed25519::EDDSA_PUBKEY_LEN; 25 | #[doc(hidden)] 26 | pub use crate::ed25519::{ed25519_batch_verify, ed25519_verify}; 27 | #[doc(hidden)] 28 | pub use crate::errors::{CryptoError, CryptoResult}; 29 | #[doc(hidden)] 30 | pub use crate::secp256k1::{secp256k1_recover_pubkey, secp256k1_verify}; 31 | #[doc(hidden)] 32 | pub use crate::secp256r1::{secp256r1_recover_pubkey, secp256r1_verify}; 33 | pub(crate) use backtrace::BT; 34 | -------------------------------------------------------------------------------- /packages/crypto/testdata/186-4ecdsatestvectors/Readme.txt: -------------------------------------------------------------------------------- 1 | Example test files for FIPS 186-3 ECDSA 2 | Updated May 5, 2015 to include examples for truncated SHAs and to remove SigGen P-192, K-163, and B-163 curves and to remove SHA1 3 | 4 | 5 | 1. The files with extension '.rsp' are response files in the proper format for 6 | CAVS validation. 7 | 8 | a. SigVer.rsp contains examples of every curve with SHA1, SHA224, SHA256, SHA384, and SHA512. 9 | b. SigVer_TruncatedSHAs.rsp contains examples of every curve with the truncated 10 | SHAs - SHA512/224 and SHA512/256. 11 | 12 | 2. The file SigGen.txt contains values for ECDSA signature generation for every curve with SHA224, SHA256, SHA384, and SHA512. The file SigGen_TruncatedSHAs.txt contains values for ECDSA signature generation for every curve with the truncated SHAs - SHA512/224 and SHA512/256. 13 | 14 | a. These txt files contain values for ECDSA signature generation with the 15 | following additional values needed to calculate r and s as in Section 6.4: 16 | 1. 'd' -- The private key. 17 | 18 | 2. 'k' -- The Per-message secret number (PMSN) used to compute (r, s). 19 | See Section 6.3 and Appendix B.5 for more information on the PMSN. -------------------------------------------------------------------------------- /packages/crypto/testdata/extract_sig_gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function usage() { 4 | echo "Usage: $0 [-c|--curves] [-h|--hashes] .txt [CURVE] [HASH]" 5 | echo "Eg.: $0 186-4ecdsatestvectors/SigGen.txt P-256 SHA-224" 6 | exit 1 7 | } 8 | 9 | CURVES=0 10 | HASHES=0 11 | while [[ $# -gt 0 ]]; do 12 | KEY="$1" 13 | case $KEY in 14 | -c | --curves) 15 | CURVES=1 16 | shift 17 | ;; 18 | -h | --hashes) 19 | HASHES=1 20 | shift 21 | ;; 22 | *) 23 | break 24 | ;; 25 | esac 26 | done 27 | 28 | SIGGEN="$1" 29 | [ -z "$SIGGEN" ] && usage 30 | [ $CURVES -eq 1 ] && grep '^\[' "$SIGGEN" | cut -f2 -d[ | cut -f1 -d, | sort -u 31 | [ $HASHES -eq 1 ] && grep '^\[' "$SIGGEN" | cut -f1 -d] | cut -f2 -d, | sort -u 32 | [ $CURVES -eq 1 ] || [ $HASHES -eq 1 ] && exit 0 33 | 34 | CURVE="$2" 35 | [ -z "$CURVE" ] && CURVE="P-256" 36 | HASH="$3" 37 | [ -z "$HASH" ] && HASH="SHA-256" 38 | 39 | cat $SIGGEN | 40 | sed 's/ //' | 41 | sed -n -E "/^\[$CURVE,$HASH\]/,/^\[/{s/\[$CURVE,$HASH\]/\[/;s/^Msg = *([^ ]*)/ {\n \"message\": \"\1\",/;/^Qx =/{N;s/^Qx = *([^ ]*)\nQy = *([^ ]*)/ \"pubkey\": \"04\1\2\",/};/^R =/{N;s/^R = *([^ ]*)\nS = *([^ ]*)/ \"signature\": \"\1\2\"\n\ },/};s/^\[.*\]/\]/;p}" | 42 | grep -E '[[{}"]|]' | 43 | tac | 44 | sed '2s/},/}/' | 45 | tac 46 | -------------------------------------------------------------------------------- /packages/crypto/testdata/rootberg/README.md: -------------------------------------------------------------------------------- 1 | # Rootberg test data 2 | 3 | This folder contains test vectors from 4 | [Project Rootberg](https://github.com/bleichenbacher-daniel/Rooterberg) to 5 | increase the test coverage of public key recovery implementations. 6 | 7 | This test data is used by integration tests in `test/rootberg_*.rs`. 8 | 9 | ## Update 10 | 11 | To ensure integrity of the files and update them to the latest version, run this 12 | from the repo root: 13 | 14 | ```sh 15 | (cd packages/crypto/testdata/rootberg \ 16 | && curl -sSL https://github.com/bleichenbacher-daniel/Rooterberg/raw/main/ecdsa/ecdsa_secp256k1_keccak256_raw.json > ecdsa_secp256k1_keccak256_raw.json \ 17 | && curl -sSL https://github.com/bleichenbacher-daniel/Rooterberg/raw/main/ecdsa/ecdsa_secp256k1_sha_256_raw.json > ecdsa_secp256k1_sha_256_raw.json \ 18 | && curl -sSL https://github.com/bleichenbacher-daniel/Rooterberg/raw/main/ecdsa/ecdsa_secp256r1_keccak256_raw.json > ecdsa_secp256r1_keccak256_raw.json \ 19 | && curl -sSL https://github.com/bleichenbacher-daniel/Rooterberg/raw/main/ecdsa/ecdsa_secp256r1_sha_256_raw.json > ecdsa_secp256r1_sha_256_raw.json \ 20 | ) 21 | ``` 22 | -------------------------------------------------------------------------------- /packages/crypto/testdata/wycheproof/README.md: -------------------------------------------------------------------------------- 1 | # Wycheproof test data 2 | 3 | This folder contains test vectors from 4 | [Project Wycheproof](https://github.com/google/wycheproof) to increase the test 5 | coverage of signature verification implementations. 6 | 7 | This test data is used by integration tests in `test/wycheproof_*.rs`. 8 | 9 | ## Update 10 | 11 | To ensure integrity of the files and update them to the latest version, run this 12 | from the repo root: 13 | 14 | ```sh 15 | (cd packages/crypto/testdata/wycheproof \ 16 | && curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256r1_sha256_test.json > ecdsa_secp256r1_sha256_test.json \ 17 | && curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256r1_sha512_test.json > ecdsa_secp256r1_sha512_test.json \ 18 | && curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256r1_sha3_256_test.json > ecdsa_secp256r1_sha3_256_test.json \ 19 | && curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256r1_sha3_512_test.json > ecdsa_secp256r1_sha3_512_test.json \ 20 | && curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256k1_sha256_test.json > ecdsa_secp256k1_sha256_test.json \ 21 | && curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256k1_sha512_test.json > ecdsa_secp256k1_sha512_test.json \ 22 | && curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256k1_sha3_256_test.json > ecdsa_secp256k1_sha3_256_test.json \ 23 | && curl -sSL https://github.com/google/wycheproof/raw/master/testvectors_v1/ecdsa_secp256k1_sha3_512_test.json > ecdsa_secp256k1_sha3_512_test.json \ 24 | ) 25 | ``` 26 | -------------------------------------------------------------------------------- /packages/crypto/tests/hashers.rs: -------------------------------------------------------------------------------- 1 | // only some of the hashers are used in each test file, so some will be unused 2 | #![allow(unused)] 3 | 4 | use digest::Digest; 5 | use sha2::{Sha256, Sha512}; 6 | use sha3::{Keccak256, Sha3_256, Sha3_512}; 7 | 8 | pub fn sha256(data: &[u8]) -> [u8; 32] { 9 | Sha256::digest(data).into() 10 | } 11 | 12 | pub fn keccak_256(data: &[u8]) -> [u8; 32] { 13 | Keccak256::digest(data).into() 14 | } 15 | 16 | // ecdsa_secp256k1_sha512 requires truncating to 32 bytes 17 | pub fn sha512(data: &[u8]) -> [u8; 32] { 18 | let hash = Sha512::digest(data).to_vec(); 19 | hash[..32].try_into().unwrap() 20 | } 21 | 22 | pub fn sha3_256(data: &[u8]) -> [u8; 32] { 23 | Sha3_256::digest(data).into() 24 | } 25 | 26 | // ecdsa_secp256k1_sha3_512 requires truncating to 32 bytes 27 | pub fn sha3_512(data: &[u8]) -> [u8; 32] { 28 | let hash = Sha3_512::digest(data).to_vec(); 29 | hash[..32].try_into().unwrap() 30 | } 31 | -------------------------------------------------------------------------------- /packages/crypto/tests/wycheproof.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | #[derive(Deserialize, Debug)] 4 | #[serde(rename_all = "camelCase")] 5 | pub struct File { 6 | pub number_of_tests: usize, 7 | pub test_groups: Vec, 8 | } 9 | 10 | #[derive(Deserialize, Debug)] 11 | #[serde(rename_all = "camelCase")] 12 | pub struct TestGroup { 13 | pub public_key: Key, 14 | pub tests: Vec, 15 | } 16 | 17 | #[derive(Deserialize, Debug)] 18 | #[serde(rename_all = "camelCase")] 19 | pub struct Key { 20 | pub uncompressed: String, 21 | } 22 | 23 | #[derive(Deserialize, Debug)] 24 | #[serde(rename_all = "camelCase")] 25 | pub struct TestCase { 26 | pub tc_id: u32, 27 | pub comment: String, 28 | pub msg: String, 29 | pub sig: String, 30 | // "acceptable", "valid" or "invalid" 31 | pub result: String, 32 | } 33 | 34 | pub fn read_file(path: &str) -> File { 35 | use std::fs::File; 36 | use std::io::BufReader; 37 | 38 | // Open the file in read-only mode with buffer. 39 | let file = File::open(path).unwrap(); 40 | let reader = BufReader::new(file); 41 | 42 | serde_json::from_reader(reader).unwrap() 43 | } 44 | -------------------------------------------------------------------------------- /packages/derive/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cosmwasm-derive" 3 | version.workspace = true 4 | authors = ["Simon Warta "] 5 | edition = "2021" 6 | description = "A package for auto-generated code used for CosmWasm contract development. This is shipped as part of cosmwasm-std. Do not use directly." 7 | repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/derive" 8 | license = "Apache-2.0" 9 | readme = "README.md" 10 | 11 | [lib] 12 | proc-macro = true 13 | 14 | [features] 15 | default = [] 16 | 17 | [dependencies] 18 | proc-macro2 = "1.0.79" 19 | quote = "1.0.35" 20 | syn = { version = "2", features = ["full"] } 21 | 22 | [dev-dependencies] 23 | # Needed for testing docs 24 | # "What's even more fun, Cargo packages actually can have cyclic dependencies. 25 | # "(a package can have an indirect dev-dependency on itself)" 26 | # https://users.rust-lang.org/t/does-cargo-support-cyclic-dependencies/35666/3 27 | cosmwasm-std = { version = "2.0.1", path = "../std" } 28 | -------------------------------------------------------------------------------- /packages/derive/README.md: -------------------------------------------------------------------------------- 1 | # cosmwasm-derive 2 | 3 | [![cosmwasm-derive on crates.io](https://img.shields.io/crates/v/cosmwasm-derive.svg)](https://crates.io/crates/cosmwasm-derive) 4 | 5 | A package for auto-generated code used for CosmWasm contract development. This 6 | is shipped as part of cosmwasm-std. Do not use directly. 7 | 8 | ## License 9 | 10 | This package is part of the cosmwasm repository, licensed under the Apache 11 | License 2.0 (see [NOTICE](https://github.com/CosmWasm/cosmwasm/blob/main/NOTICE) 12 | and [LICENSE](https://github.com/CosmWasm/cosmwasm/blob/main/LICENSE)). 13 | -------------------------------------------------------------------------------- /packages/go-gen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "go-gen" 3 | authors = ["Christoph Otter "] 4 | version = "0.1.0" 5 | edition = "2021" 6 | publish = false 7 | 8 | [dependencies] 9 | cosmwasm-std = { version = "2.0.1", path = "../std", features = ["cosmwasm_2_0", "staking", "stargate"] } 10 | cosmwasm-schema = { version = "2.0.1", path = "../schema" } 11 | anyhow = "1" 12 | Inflector = "0.11.4" 13 | indenter = "0.3.3" 14 | schemars = { workspace = true } 15 | -------------------------------------------------------------------------------- /packages/go-gen/README.md: -------------------------------------------------------------------------------- 1 | # JsonSchema Go Type Generator 2 | 3 | This is an internal utility to generate Go types from `cosmwasm-std`'s query 4 | response types. These types can then be used in 5 | [wasmvm](https://github.com/CosmWasm/wasmvm). 6 | 7 | ## Usage 8 | 9 | Adjust the query / response type you want to generate in `src/main.rs` and run: 10 | `cargo run -p go-gen` 11 | 12 | ## Limitations 13 | 14 | Only basic structs and enums are supported. Tuples and enum variants with 0 or 15 | more than 1 parameters don't work, for example. 16 | 17 | ## License 18 | 19 | This package is part of the cosmwasm repository, licensed under the Apache 20 | License 2.0 (see [NOTICE](https://github.com/CosmWasm/cosmwasm/blob/main/NOTICE) 21 | and [LICENSE](https://github.com/CosmWasm/cosmwasm/blob/main/LICENSE)). 22 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__AllBalanceResponse.go: -------------------------------------------------------------------------------- 1 | // AllBalancesResponse is the expected response to AllBalancesQuery 2 | type AllBalancesResponse struct { 3 | Amount Array[Coin] `json:"amount"` 4 | } 5 | 6 | // Coin is a string representation of the sdk.Coin type (more portable than sdk.Int) 7 | type Coin struct { 8 | Amount string `json:"amount"` // string encoing of decimal value, eg. "12.3456" 9 | Denom string `json:"denom"` // type, eg. "ATOM" 10 | } 11 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__AllDelegationsResponse.go: -------------------------------------------------------------------------------- 1 | // AllDelegationsResponse is the expected response to AllDelegationsQuery 2 | type AllDelegationsResponse struct { 3 | Delegations Array[Delegation] `json:"delegations"` 4 | } 5 | 6 | // Coin is a string representation of the sdk.Coin type (more portable than sdk.Int) 7 | type Coin struct { 8 | Amount string `json:"amount"` // string encoing of decimal value, eg. "12.3456" 9 | Denom string `json:"denom"` // type, eg. "ATOM" 10 | } 11 | 12 | type Delegation struct { 13 | Amount Coin `json:"amount"` 14 | Delegator string `json:"delegator"` 15 | Validator string `json:"validator"` 16 | } 17 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__AllValidatorsResponse.go: -------------------------------------------------------------------------------- 1 | // AllValidatorsResponse is the expected response to AllValidatorsQuery 2 | type AllValidatorsResponse struct { 3 | Validators Array[Validator] `json:"validators"` 4 | } 5 | 6 | type Validator struct { 7 | Address string `json:"address"` 8 | // decimal string, eg "0.02" 9 | Commission string `json:"commission"` 10 | // decimal string, eg "0.02" 11 | MaxChangeRate string `json:"max_change_rate"` 12 | // decimal string, eg "0.02" 13 | MaxCommission string `json:"max_commission"` 14 | } 15 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__BalanceResponse.go: -------------------------------------------------------------------------------- 1 | // BalanceResponse is the expected response to BalanceQuery 2 | type BalanceResponse struct { 3 | Amount Coin `json:"amount"` 4 | } 5 | 6 | // Coin is a string representation of the sdk.Coin type (more portable than sdk.Int) 7 | type Coin struct { 8 | Amount string `json:"amount"` // string encoing of decimal value, eg. "12.3456" 9 | Denom string `json:"denom"` // type, eg. "ATOM" 10 | } 11 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__BankMsg.go: -------------------------------------------------------------------------------- 1 | // SendMsg contains instructions for a Cosmos-SDK/SendMsg 2 | // It has a fixed interface here and should be converted into the proper SDK format before dispatching 3 | type SendMsg struct { 4 | Amount Array[Coin] `json:"amount"` 5 | ToAddress string `json:"to_address"` 6 | } 7 | 8 | // BurnMsg will burn the given coins from the contract's account. 9 | // There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper. 10 | // Important if a contract controls significant token supply that must be retired. 11 | type BurnMsg struct { 12 | Amount Array[Coin] `json:"amount"` 13 | } 14 | 15 | type BankMsg struct { 16 | Send *SendMsg `json:"send,omitempty"` 17 | Burn *BurnMsg `json:"burn,omitempty"` 18 | } 19 | 20 | // Coin is a string representation of the sdk.Coin type (more portable than sdk.Int) 21 | type Coin struct { 22 | Amount string `json:"amount"` // string encoing of decimal value, eg. "12.3456" 23 | Denom string `json:"denom"` // type, eg. "ATOM" 24 | } 25 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__BankQuery.go: -------------------------------------------------------------------------------- 1 | type SupplyQuery struct { 2 | Denom string `json:"denom"` 3 | } 4 | 5 | type BalanceQuery struct { 6 | Address string `json:"address"` 7 | Denom string `json:"denom"` 8 | } 9 | 10 | type AllBalancesQuery struct { 11 | Address string `json:"address"` 12 | } 13 | 14 | type DenomMetadataQuery struct { 15 | Denom string `json:"denom"` 16 | } 17 | 18 | type AllDenomMetadataQuery struct { 19 | // Pagination is an optional argument. 20 | // Default pagination will be used if this is omitted 21 | Pagination *PageRequest `json:"pagination,omitempty"` 22 | } 23 | 24 | type BankQuery struct { 25 | Supply *SupplyQuery `json:"supply,omitempty"` 26 | Balance *BalanceQuery `json:"balance,omitempty"` 27 | AllBalances *AllBalancesQuery `json:"all_balances,omitempty"` 28 | DenomMetadata *DenomMetadataQuery `json:"denom_metadata,omitempty"` 29 | AllDenomMetadata *AllDenomMetadataQuery `json:"all_denom_metadata,omitempty"` 30 | } 31 | 32 | // Simplified version of the cosmos-sdk PageRequest type 33 | type PageRequest struct { 34 | // Key is a value returned in PageResponse.next_key to begin 35 | // querying the next page most efficiently. Only one of offset or key 36 | // should be set. 37 | Key []byte `json:"key"` 38 | // Limit is the total number of results to be returned in the result page. 39 | // If left empty it will default to a value to be set by each app. 40 | Limit uint32 `json:"limit"` 41 | // Reverse is set to true if results are to be returned in the descending order. 42 | Reverse bool `json:"reverse"` 43 | } -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__BondedDenomResponse.go: -------------------------------------------------------------------------------- 1 | type BondedDenomResponse struct { 2 | Denom string `json:"denom"` 3 | } -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__CodeInfoResponse.go: -------------------------------------------------------------------------------- 1 | type CodeInfoResponse struct { 2 | Checksum Checksum `json:"checksum"` // before wasmvm 2.0.0, this was `omitempty` (https://github.com/CosmWasm/wasmvm/issues/471) 3 | CodeID uint64 `json:"code_id"` 4 | Creator string `json:"creator"` 5 | } 6 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__ContractInfoResponse.go: -------------------------------------------------------------------------------- 1 | type ContractInfoResponse struct { 2 | // Set to the admin who can migrate contract, if any 3 | Admin string `json:"admin,omitempty"` 4 | CodeID uint64 `json:"code_id"` 5 | Creator string `json:"creator"` 6 | // Set if the contract is IBC enabled 7 | IBCPort string `json:"ibc_port,omitempty"` 8 | Pinned bool `json:"pinned"` 9 | } -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__DelegationResponse.go: -------------------------------------------------------------------------------- 1 | // DelegationResponse is the expected response to DelegationsQuery 2 | type DelegationResponse struct { 3 | Delegation *FullDelegation `json:"delegation,omitempty"` 4 | } 5 | 6 | // Coin is a string representation of the sdk.Coin type (more portable than sdk.Int) 7 | type Coin struct { 8 | Amount string `json:"amount"` // string encoing of decimal value, eg. "12.3456" 9 | Denom string `json:"denom"` // type, eg. "ATOM" 10 | } 11 | 12 | type FullDelegation struct { 13 | AccumulatedRewards Array[Coin] `json:"accumulated_rewards"` 14 | Amount Coin `json:"amount"` 15 | CanRedelegate Coin `json:"can_redelegate"` 16 | Delegator string `json:"delegator"` 17 | Validator string `json:"validator"` 18 | } 19 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__DelegationRewardsResponse.go: -------------------------------------------------------------------------------- 1 | // See 2 | type DelegationRewardsResponse struct { 3 | Rewards Array[DecCoin] `json:"rewards"` // in wasmvm, this has type `[]DecCoin` 4 | } 5 | 6 | // A coin type with decimal amount. Modeled after the Cosmos SDK's [DecCoin](https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/base/v1beta1/coin.proto#L32-L41) type 7 | type DecCoin struct { 8 | Amount string `json:"amount"` 9 | Denom string `json:"denom"` 10 | } 11 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__DelegationTotalRewardsResponse.go: -------------------------------------------------------------------------------- 1 | // See 2 | type DelegationTotalRewardsResponse struct { 3 | Rewards Array[DelegatorReward] `json:"rewards"` // in wasmvm, this has type `[]DelegatorReward` 4 | Total Array[DecCoin] `json:"total"` // in wasmvm, this has type `[]DecCoin` 5 | } 6 | 7 | // A coin type with decimal amount. Modeled after the Cosmos SDK's [DecCoin](https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/base/v1beta1/coin.proto#L32-L41) type 8 | type DecCoin struct { 9 | Amount string `json:"amount"` 10 | Denom string `json:"denom"` 11 | } 12 | 13 | type DelegatorReward struct { 14 | Reward Array[DecCoin] `json:"reward"` // in wasmvm, this has type `[]DecCoin` 15 | ValidatorAddress string `json:"validator_address"` 16 | } 17 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__DelegatorValidatorsResponse.go: -------------------------------------------------------------------------------- 1 | // See 2 | type DelegatorValidatorsResponse struct { 3 | Validators Array[string] `json:"validators"` // in wasmvm, this has type `[]string` 4 | } 5 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__DelegatorWithdrawAddressResponse.go: -------------------------------------------------------------------------------- 1 | type DelegatorWithdrawAddressResponse struct { 2 | WithdrawAddress string `json:"withdraw_address"` 3 | } 4 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__DistributionMsg.go: -------------------------------------------------------------------------------- 1 | // SetWithdrawAddressMsg is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). 2 | // `delegator_address` is automatically filled with the current contract's address. 3 | type SetWithdrawAddressMsg struct { 4 | // Address contains the `delegator_address` of a MsgSetWithdrawAddress 5 | Address string `json:"address"` 6 | } 7 | 8 | // WithdrawDelegatorRewardMsg is translated to a [MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). 9 | // `delegator_address` is automatically filled with the current contract's address. 10 | type WithdrawDelegatorRewardMsg struct { 11 | // Validator contains `validator_address` of a MsgWithdrawDelegatorReward 12 | Validator string `json:"validator"` 13 | } 14 | 15 | // FundCommunityPoolMsg is translated to a [MsgFundCommunityPool](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#LL69C1-L76C2). 16 | // `depositor` is automatically filled with the current contract's address 17 | type FundCommunityPoolMsg struct { 18 | // Amount is the list of coins to be send to the community pool 19 | Amount Array[Coin] `json:"amount"` 20 | } 21 | 22 | type DistributionMsg struct { 23 | SetWithdrawAddress *SetWithdrawAddressMsg `json:"set_withdraw_address,omitempty"` 24 | WithdrawDelegatorReward *WithdrawDelegatorRewardMsg `json:"withdraw_delegator_reward,omitempty"` 25 | FundCommunityPool *FundCommunityPoolMsg `json:"fund_community_pool,omitempty"` 26 | } 27 | 28 | // Coin is a string representation of the sdk.Coin type (more portable than sdk.Int) 29 | type Coin struct { 30 | Amount string `json:"amount"` // string encoing of decimal value, eg. "12.3456" 31 | Denom string `json:"denom"` // type, eg. "ATOM" 32 | } 33 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__DistributionQuery.go: -------------------------------------------------------------------------------- 1 | type DelegatorWithdrawAddressQuery struct { 2 | DelegatorAddress string `json:"delegator_address"` 3 | } 4 | type DelegationRewardsQuery struct { 5 | DelegatorAddress string `json:"delegator_address"` 6 | ValidatorAddress string `json:"validator_address"` 7 | } 8 | type DelegationTotalRewardsQuery struct { 9 | DelegatorAddress string `json:"delegator_address"` 10 | } 11 | type DelegatorValidatorsQuery struct { 12 | DelegatorAddress string `json:"delegator_address"` 13 | } 14 | 15 | type DistributionQuery struct { 16 | // See 17 | DelegatorWithdrawAddress *DelegatorWithdrawAddressQuery `json:"delegator_withdraw_address,omitempty"` 18 | // See 19 | DelegationRewards *DelegationRewardsQuery `json:"delegation_rewards,omitempty"` 20 | // See 21 | DelegationTotalRewards *DelegationTotalRewardsQuery `json:"delegation_total_rewards,omitempty"` 22 | // See 23 | DelegatorValidators *DelegatorValidatorsQuery `json:"delegator_validators,omitempty"` 24 | } -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__GovMsg.go: -------------------------------------------------------------------------------- 1 | type VoteMsg struct { 2 | // Option is the vote option. 3 | // 4 | // This used to be called "vote", but was changed for consistency with Cosmos SDK. 5 | // The old name is still supported for backwards compatibility. 6 | Option voteOption `json:"option"` 7 | ProposalID uint64 `json:"proposal_id"` // in wasmvm, this is `ProposalId` 8 | } 9 | 10 | type VoteWeightedMsg struct { 11 | Options Array[WeightedVoteOption] `json:"options"` // in wasmvm, this has type `[]WeightedVoteOption` 12 | ProposalID uint64 `json:"proposal_id"` // in wasmvm, this is `ProposalId` 13 | } 14 | 15 | type GovMsg struct { 16 | // This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address. 17 | Vote *VoteMsg `json:"vote,omitempty"` 18 | /// This maps directly to [MsgVoteWeighted](https://github.com/cosmos/cosmos-sdk/blob/v0.45.8/proto/cosmos/gov/v1beta1/tx.proto#L66-L78) in the Cosmos SDK with voter set to the contract address. 19 | VoteWeighted *VoteWeightedMsg `json:"vote_weighted,omitempty"` 20 | } 21 | 22 | type WeightedVoteOption struct { 23 | Option voteOption `json:"option"` 24 | // Weight is a Decimal string, e.g. "0.25" for 25% 25 | Weight string `json:"weight"` 26 | } 27 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__IbcMsg.go: -------------------------------------------------------------------------------- 1 | type TransferMsg struct { 2 | Amount Coin `json:"amount"` 3 | ChannelID string `json:"channel_id"` 4 | Memo string `json:"memo,omitempty"` // this is not yet in wasmvm, but will be soon 5 | Timeout IBCTimeout `json:"timeout"` 6 | ToAddress string `json:"to_address"` 7 | } 8 | type SendPacketMsg struct { 9 | ChannelID string `json:"channel_id"` 10 | Data []byte `json:"data"` 11 | Timeout IBCTimeout `json:"timeout"` 12 | } 13 | type CloseChannelMsg struct { 14 | ChannelID string `json:"channel_id"` 15 | } 16 | 17 | type IBCMsg struct { 18 | Transfer *TransferMsg `json:"transfer,omitempty"` 19 | SendPacket *SendPacketMsg `json:"send_packet,omitempty"` 20 | CloseChannel *CloseChannelMsg `json:"close_channel,omitempty"` 21 | } 22 | 23 | // Coin is a string representation of the sdk.Coin type (more portable than sdk.Int) 24 | type Coin struct { 25 | Amount string `json:"amount"` // string encoing of decimal value, eg. "12.3456" 26 | Denom string `json:"denom"` // type, eg. "ATOM" 27 | } 28 | 29 | // IBCTimeout is the timeout for an IBC packet. At least one of block and timestamp is required. 30 | type IBCTimeout struct { 31 | Block *IBCTimeoutBlock `json:"block,omitempty"` // in wasmvm, this does not have "omitempty" 32 | // Nanoseconds since UNIX epoch 33 | Timestamp *Uint64 `json:"timestamp,omitempty"` 34 | } 35 | 36 | // IBCTimeoutBlock Height is a monotonically increasing data type 37 | // that can be compared against another Height for the purposes of updating and 38 | // freezing clients. 39 | // Ordering is (revision_number, timeout_height) 40 | type IBCTimeoutBlock struct { 41 | // block height after which the packet times out. 42 | // the height within the given revision 43 | Height uint64 `json:"height"` 44 | // the version that the client is currently on 45 | // (eg. after reseting the chain this could increment 1 as height drops to 0) 46 | Revision uint64 `json:"revision"` 47 | } 48 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__IbcQuery.go: -------------------------------------------------------------------------------- 1 | type PortIDQuery struct { 2 | } 3 | 4 | // ListChannelsQuery is an IBCQuery that lists all channels that are bound to a given port. 5 | // If `PortID` is unset, this list all channels bound to the contract's port. 6 | // Returns a `ListChannelsResponse`. 7 | // This is the counterpart of [IbcQuery::ListChannels](https://github.com/CosmWasm/cosmwasm/blob/v0.14.0-beta1/packages/std/src/ibc.rs#L70-L73). 8 | type ListChannelsQuery struct { 9 | // optional argument 10 | PortID string `json:"port_id,omitempty"` 11 | } 12 | 13 | type ChannelQuery struct { 14 | ChannelID string `json:"channel_id"` 15 | // optional argument 16 | PortID string `json:"port_id,omitempty"` 17 | } 18 | 19 | // IBCQuery defines a query request from the contract into the chain. 20 | // This is the counterpart of [IbcQuery](https://github.com/CosmWasm/cosmwasm/blob/v0.14.0-beta1/packages/std/src/ibc.rs#L61-L83). 21 | type IBCQuery struct { 22 | PortID *PortIDQuery `json:"port_id,omitempty"` 23 | ListChannels *ListChannelsQuery `json:"list_channels,omitempty"` 24 | Channel *ChannelQuery `json:"channel,omitempty"` 25 | } 26 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__StakingMsg.go: -------------------------------------------------------------------------------- 1 | type DelegateMsg struct { 2 | Amount Coin `json:"amount"` 3 | Validator string `json:"validator"` 4 | } 5 | type UndelegateMsg struct { 6 | Amount Coin `json:"amount"` 7 | Validator string `json:"validator"` 8 | } 9 | type RedelegateMsg struct { 10 | Amount Coin `json:"amount"` 11 | DstValidator string `json:"dst_validator"` 12 | SrcValidator string `json:"src_validator"` 13 | } 14 | 15 | type StakingMsg struct { 16 | Delegate *DelegateMsg `json:"delegate,omitempty"` 17 | Undelegate *UndelegateMsg `json:"undelegate,omitempty"` 18 | Redelegate *RedelegateMsg `json:"redelegate,omitempty"` 19 | } 20 | 21 | // Coin is a string representation of the sdk.Coin type (more portable than sdk.Int) 22 | type Coin struct { 23 | Amount string `json:"amount"` // string encoing of decimal value, eg. "12.3456" 24 | Denom string `json:"denom"` // type, eg. "ATOM" 25 | } 26 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__StakingQuery.go: -------------------------------------------------------------------------------- 1 | type BondedDenomQuery struct { // does not exist in wasmvm, but is an anonymous struct instead 2 | } 3 | 4 | type AllDelegationsQuery struct { 5 | Delegator string `json:"delegator"` 6 | } 7 | 8 | type DelegationQuery struct { 9 | Delegator string `json:"delegator"` 10 | Validator string `json:"validator"` 11 | } 12 | 13 | type AllValidatorsQuery struct { 14 | } 15 | 16 | type ValidatorQuery struct { 17 | /// Address is the validator's address (e.g. cosmosvaloper1...) 18 | Address string `json:"address"` 19 | } 20 | 21 | type StakingQuery struct { 22 | BondedDenom *BondedDenomQuery `json:"bonded_denom,omitempty"` 23 | AllDelegations *AllDelegationsQuery `json:"all_delegations,omitempty"` 24 | Delegation *DelegationQuery `json:"delegation,omitempty"` 25 | AllValidators *AllValidatorsQuery `json:"all_validators,omitempty"` 26 | Validator *ValidatorQuery `json:"validator,omitempty"` 27 | } -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__SupplyResponse.go: -------------------------------------------------------------------------------- 1 | // SupplyResponse is the expected response to SupplyQuery 2 | type SupplyResponse struct { 3 | Amount Coin `json:"amount"` 4 | } 5 | 6 | // Coin is a string representation of the sdk.Coin type (more portable than sdk.Int) 7 | type Coin struct { 8 | Amount string `json:"amount"` // string encoing of decimal value, eg. "12.3456" 9 | Denom string `json:"denom"` // type, eg. "ATOM" 10 | } -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__ValidatorResponse.go: -------------------------------------------------------------------------------- 1 | // ValidatorResponse is the expected response to ValidatorQuery 2 | type ValidatorResponse struct { 3 | Validator *Validator `json:"validator"` // serializes to `null` when unset which matches Rust's Option::None serialization 4 | } 5 | 6 | type Validator struct { 7 | Address string `json:"address"` 8 | // decimal string, eg "0.02" 9 | Commission string `json:"commission"` 10 | // decimal string, eg "0.02" 11 | MaxChangeRate string `json:"max_change_rate"` 12 | // decimal string, eg "0.02" 13 | MaxCommission string `json:"max_commission"` 14 | } 15 | -------------------------------------------------------------------------------- /packages/go-gen/tests/cosmwasm_std__WasmQuery.go: -------------------------------------------------------------------------------- 1 | 2 | // SmartQuery response is raw bytes ([]byte) 3 | type SmartQuery struct { 4 | // Bech32 encoded sdk.AccAddress of the contract 5 | ContractAddr string `json:"contract_addr"` 6 | Msg []byte `json:"msg"` 7 | } 8 | 9 | // RawQuery response is raw bytes ([]byte) 10 | type RawQuery struct { 11 | // Bech32 encoded sdk.AccAddress of the contract 12 | ContractAddr string `json:"contract_addr"` 13 | Key []byte `json:"key"` 14 | } 15 | 16 | type ContractInfoQuery struct { 17 | // Bech32 encoded sdk.AccAddress of the contract 18 | ContractAddr string `json:"contract_addr"` 19 | } 20 | 21 | type CodeInfoQuery struct { 22 | CodeID uint64 `json:"code_id"` 23 | } 24 | 25 | type WasmQuery struct { 26 | Smart *SmartQuery `json:"smart,omitempty"` 27 | Raw *RawQuery `json:"raw,omitempty"` 28 | ContractInfo *ContractInfoQuery `json:"contract_info,omitempty"` 29 | CodeInfo *CodeInfoQuery `json:"code_info,omitempty"` 30 | } -------------------------------------------------------------------------------- /packages/schema-derive/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cosmwasm-schema-derive" 3 | version.workspace = true 4 | authors = ["Tomasz Kurcz "] 5 | edition = "2021" 6 | description = "Derive macros for cosmwasm-schema" 7 | repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/schema" 8 | license = "Apache-2.0" 9 | 10 | [dependencies] 11 | proc-macro2 = "1" 12 | quote = "1" 13 | syn = { version = "2", features = ["extra-traits", "full", "printing"] } 14 | 15 | [lib] 16 | proc-macro = true 17 | -------------------------------------------------------------------------------- /packages/schema-derive/README.md: -------------------------------------------------------------------------------- 1 | # CosmWasm Schema Derive Macros 2 | 3 | [![cosmwasm-schema-derive on crates.io](https://img.shields.io/crates/v/cosmwasm-schema-derive.svg)](https://crates.io/crates/cosmwasm-schema-derive) 4 | 5 | This is where all macros related to the 6 | [`cosmwasm-schema`](https://crates.io/crates/cosmwasm-schema) crate live. You 7 | almost certainly don't want to add this crate as an explicit dependency in your 8 | project, but rather import the macros through `cosmwasm-schema`. 9 | 10 | ## License 11 | 12 | This package is part of the cosmwasm repository, licensed under the Apache 13 | License 2.0 (see [NOTICE](https://github.com/CosmWasm/cosmwasm/blob/main/NOTICE) 14 | and [LICENSE](https://github.com/CosmWasm/cosmwasm/blob/main/LICENSE)). 15 | -------------------------------------------------------------------------------- /packages/schema-derive/src/error.rs: -------------------------------------------------------------------------------- 1 | macro_rules! bail { 2 | ($span_src:expr, $msg:literal) => {{ 3 | return Err($crate::error::error_message!($span_src, $msg)); 4 | }}; 5 | } 6 | 7 | macro_rules! error_message { 8 | ($span_src:expr, $msg:literal) => {{ 9 | ::syn::Error::new(::syn::spanned::Spanned::span(&{ $span_src }), $msg) 10 | }}; 11 | } 12 | 13 | macro_rules! fallible_macro { 14 | ( 15 | $( 16 | #[ $( $attribute_decl:tt )* ] 17 | )* 18 | pub fn $macro_name:ident ( $( $params:tt )* ) -> syn::Result<$inner_return:path> { 19 | $( $fn_body:tt )* 20 | } 21 | ) => { 22 | $( 23 | #[ $( $attribute_decl )* ] 24 | )* 25 | pub fn $macro_name ( $( $params )* ) -> $inner_return { 26 | let result = move || -> ::syn::Result<_> { 27 | $( $fn_body )* 28 | }; 29 | 30 | match result() { 31 | Ok(val) => val, 32 | Err(err) => err.into_compile_error().into(), 33 | } 34 | } 35 | } 36 | } 37 | 38 | pub(crate) use bail; 39 | pub(crate) use error_message; 40 | pub(crate) use fallible_macro; 41 | -------------------------------------------------------------------------------- /packages/schema-derive/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod cw_serde; 2 | mod error; 3 | mod generate_api; 4 | mod query_responses; 5 | 6 | use self::error::fallible_macro; 7 | use quote::ToTokens; 8 | use syn::parse_macro_input; 9 | 10 | fallible_macro! { 11 | #[proc_macro_derive(QueryResponses, attributes(returns, query_responses))] 12 | pub fn query_responses_derive( 13 | input: proc_macro::TokenStream, 14 | ) -> syn::Result { 15 | let input = syn::parse(input)?; 16 | let expanded = query_responses::query_responses_derive_impl(input)?; 17 | 18 | Ok(expanded.into_token_stream().into()) 19 | } 20 | } 21 | 22 | #[proc_macro] 23 | pub fn write_api(input: proc_macro::TokenStream) -> proc_macro::TokenStream { 24 | let input = parse_macro_input!(input as generate_api::Options); 25 | let expanded = generate_api::write_api_impl(input).into_token_stream(); 26 | 27 | proc_macro::TokenStream::from(expanded) 28 | } 29 | 30 | #[proc_macro] 31 | pub fn generate_api(input: proc_macro::TokenStream) -> proc_macro::TokenStream { 32 | let input = parse_macro_input!(input as generate_api::Options); 33 | let expanded = generate_api::generate_api_impl(&input).into_token_stream(); 34 | 35 | proc_macro::TokenStream::from(expanded) 36 | } 37 | 38 | fallible_macro! { 39 | #[proc_macro_attribute] 40 | pub fn cw_serde( 41 | attr: proc_macro::TokenStream, 42 | input: proc_macro::TokenStream, 43 | ) -> syn::Result { 44 | let options = syn::parse(attr)?; 45 | let input = syn::parse(input)?; 46 | 47 | let expanded = cw_serde::cw_serde_impl(options, input)?; 48 | 49 | Ok(expanded.into_token_stream().into()) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /packages/schema/.gitignore: -------------------------------------------------------------------------------- 1 | # This folder is generated and updated by doc tests 2 | # (cargo test --doc write_api) 3 | # but not something we need to have versioned. 4 | schema/ 5 | -------------------------------------------------------------------------------- /packages/schema/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cosmwasm-schema" 3 | version.workspace = true 4 | authors = ["Simon Warta ", "Ethan Frey "] 5 | edition = "2021" 6 | description = "A dev-dependency for CosmWasm contracts to generate JSON Schema files." 7 | repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/schema" 8 | license = "Apache-2.0" 9 | 10 | [dependencies] 11 | cosmwasm-schema-derive = { version = "=2.0.1", path = "../schema-derive" } 12 | schemars = { workspace = true } 13 | serde = { workspace = true } 14 | serde_json = "1.0.40" 15 | thiserror = "1.0.26" 16 | 17 | [dev-dependencies] 18 | anyhow = "1.0.57" 19 | cosmwasm-std = { version = "2.0.1", path = "../std" } 20 | semver = "1" 21 | tempfile = "3" 22 | -------------------------------------------------------------------------------- /packages/schema/README.md: -------------------------------------------------------------------------------- 1 | # CosmWasm Schema 2 | 3 | [![cosmwasm-schema on crates.io](https://img.shields.io/crates/v/cosmwasm-schema.svg)](https://crates.io/crates/cosmwasm-schema) 4 | 5 | A dev-dependency for CosmWasm contracts to generate JSON Schema files. 6 | 7 | ## License 8 | 9 | This package is part of the cosmwasm repository, licensed under the Apache 10 | License 2.0 (see [NOTICE](https://github.com/CosmWasm/cosmwasm/blob/main/NOTICE) 11 | and [LICENSE](https://github.com/CosmWasm/cosmwasm/blob/main/LICENSE)). 12 | -------------------------------------------------------------------------------- /packages/schema/src/casing.rs: -------------------------------------------------------------------------------- 1 | pub fn to_snake_case(name: &str) -> String { 2 | let mut out = String::new(); 3 | for (index, ch) in name.char_indices() { 4 | if index != 0 && ch.is_uppercase() { 5 | out.push('_'); 6 | } 7 | out.push(ch.to_ascii_lowercase()); 8 | } 9 | out 10 | } 11 | 12 | #[cfg(test)] 13 | mod tests { 14 | use super::*; 15 | 16 | #[test] 17 | fn to_snake_case_leaves_snake_case_untouched() { 18 | assert_eq!(to_snake_case(""), ""); 19 | assert_eq!(to_snake_case("a"), "a"); 20 | assert_eq!(to_snake_case("abc"), "abc"); 21 | assert_eq!(to_snake_case("a_bc"), "a_bc"); 22 | } 23 | 24 | #[test] 25 | fn to_snake_case_works_for_camel_case() { 26 | assert_eq!(to_snake_case("Foobar"), "foobar"); 27 | assert_eq!(to_snake_case("FooBar"), "foo_bar"); 28 | assert_eq!(to_snake_case("ABC"), "a_b_c"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/schema/src/export.rs: -------------------------------------------------------------------------------- 1 | //! Export schema to file 2 | 3 | use std::fs::write; 4 | use std::path::Path; 5 | 6 | use schemars::schema::RootSchema; 7 | 8 | use crate::casing::to_snake_case; 9 | 10 | /// Exports a schema, auto-generating filename based on the metadata title of the generated schema. 11 | pub fn export_schema(schema: &RootSchema, out_dir: &Path) { 12 | let title = schema 13 | .schema 14 | .metadata 15 | .as_ref() 16 | .map(|b| b.title.clone().unwrap_or_else(|| "untitled".to_string())) 17 | .unwrap_or_else(|| "unknown".to_string()); 18 | write_schema(schema, out_dir, &title); 19 | } 20 | 21 | /// Use this if you want to override the auto-detected name of the object. 22 | /// very useful when creating an alias for a type-alias. 23 | pub fn export_schema_with_title(schema: &RootSchema, out_dir: &Path, title: &str) { 24 | let mut schema = schema.clone(); 25 | // set the title explicitly on the schema's metadata 26 | if let Some(metadata) = &mut schema.schema.metadata { 27 | metadata.title = Some(title.to_string()); 28 | } 29 | write_schema(&schema, out_dir, title); 30 | } 31 | 32 | /// Writes schema to file. Overwrites existing file. 33 | /// Panics on any error writing out the schema. 34 | fn write_schema(schema: &RootSchema, out_dir: &Path, title: &str) { 35 | // first, we set the title as we wish 36 | let path = out_dir.join(format!("{}.json", to_snake_case(title))); 37 | let json = serde_json::to_string_pretty(schema).unwrap(); 38 | write(&path, json + "\n").unwrap(); 39 | println!("Created {}", path.to_str().unwrap()); 40 | } 41 | -------------------------------------------------------------------------------- /packages/schema/src/schema_for.rs: -------------------------------------------------------------------------------- 1 | /// Generates a [`RootSchema`](crate::schemars::schema::RootSchema) for the given type using default settings. 2 | /// 3 | /// The type must implement [`JsonSchema`](crate::schemars::JsonSchema). 4 | /// 5 | /// The schema version is strictly `draft-07`. 6 | /// 7 | /// # Example 8 | /// ``` 9 | /// use cosmwasm_schema::schema_for; 10 | /// use schemars::JsonSchema; 11 | /// 12 | /// #[derive(JsonSchema)] 13 | /// struct MyStruct { 14 | /// foo: i32, 15 | /// } 16 | /// 17 | /// let my_schema = schema_for!(MyStruct); 18 | /// ``` 19 | #[macro_export] 20 | macro_rules! schema_for { 21 | ($type:ty) => {{ 22 | let mut schema = $crate::schemars::gen::SchemaGenerator::new( 23 | $crate::schemars::gen::SchemaSettings::draft07(), 24 | ) 25 | .into_root_schema_for::<$type>(); 26 | 27 | struct Visitor; 28 | impl $crate::schemars::visit::Visitor for Visitor { 29 | fn visit_schema_object(&mut self, schema: &mut $crate::schemars::schema::SchemaObject) { 30 | $crate::schemars::visit::visit_schema_object(self, schema); 31 | 32 | if let Some(ref mut validation) = schema.object { 33 | validation.additional_properties = Some(Box::new(false.into())); 34 | } 35 | } 36 | } 37 | 38 | $crate::schemars::visit::visit_root_schema(&mut Visitor, &mut schema); 39 | 40 | schema 41 | }}; 42 | ($_:expr) => { 43 | compile_error!("The argument to `schema_for!` is not a type.") 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /packages/std/.cargo/config: -------------------------------------------------------------------------------- 1 | [alias] 2 | wasm = "build --release --lib --target wasm32-unknown-unknown" 3 | wasm-debug = "build --lib --target wasm32-unknown-unknown" 4 | unit-test = "test --lib" 5 | -------------------------------------------------------------------------------- /packages/std/README.md: -------------------------------------------------------------------------------- 1 | # cosmwasm 2 | 3 | [![cosmwasm-std on crates.io](https://img.shields.io/crates/v/cosmwasm-std.svg)](https://crates.io/crates/cosmwasm-std) 4 | 5 | The standard library for building CosmWasm smart contracts. Code in this package 6 | is compiled into the smart contract. 7 | 8 | ## License 9 | 10 | This package is part of the cosmwasm repository, licensed under the Apache 11 | License 2.0 (see [NOTICE](https://github.com/CosmWasm/cosmwasm/blob/main/NOTICE) 12 | and [LICENSE](https://github.com/CosmWasm/cosmwasm/blob/main/LICENSE)). 13 | -------------------------------------------------------------------------------- /packages/std/src/conversion.rs: -------------------------------------------------------------------------------- 1 | /// Converts an input of type usize to u32. 2 | /// 3 | /// On 32 bit platforms such as wasm32 this is just a safe cast. 4 | /// On other platforms the conversion panics for values larger than 5 | /// `u32::MAX`. 6 | #[inline] 7 | pub fn force_to_u32(input: usize) -> u32 { 8 | #[cfg(target_pointer_width = "32")] 9 | { 10 | // usize = u32 on this architecture 11 | input as u32 12 | } 13 | #[cfg(not(target_pointer_width = "32"))] 14 | { 15 | input.try_into().expect("Input exceeds u32 range") 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/std/src/import_helpers.rs: -------------------------------------------------------------------------------- 1 | /// Returns the four most significant bytes 2 | #[allow(dead_code)] // only used in Wasm builds 3 | #[inline] 4 | pub fn from_high_half(data: u64) -> u32 { 5 | (data >> 32).try_into().unwrap() 6 | } 7 | 8 | /// Returns the four least significant bytes 9 | #[allow(dead_code)] // only used in Wasm builds 10 | #[inline] 11 | pub fn from_low_half(data: u64) -> u32 { 12 | (data & 0xFFFFFFFF).try_into().unwrap() 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use super::*; 18 | 19 | #[test] 20 | fn from_high_half_works() { 21 | assert_eq!(from_high_half(0), 0); 22 | assert_eq!(from_high_half(0x1122334455667788), 0x11223344); 23 | } 24 | 25 | #[test] 26 | fn from_low_haf_works() { 27 | assert_eq!(from_low_half(0), 0); 28 | assert_eq!(from_low_half(0x1122334455667788), 0x55667788); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/std/src/iterator.rs: -------------------------------------------------------------------------------- 1 | use crate::StdError; 2 | 3 | /// A record of a key-value storage that is created through an iterator API. 4 | /// The first element (key) is always raw binary data. The second element 5 | /// (value) is binary by default but can be changed to a custom type. This 6 | /// allows contracts to reuse the type when deserializing database records. 7 | pub type Record> = (Vec, V); 8 | 9 | #[derive(Copy, Clone, PartialEq, Eq)] 10 | // We assign these to integers to provide a stable API for passing over FFI (to wasm and Go) 11 | pub enum Order { 12 | Ascending = 1, 13 | Descending = 2, 14 | } 15 | 16 | impl TryFrom for Order { 17 | type Error = StdError; 18 | 19 | fn try_from(value: i32) -> Result { 20 | match value { 21 | 1 => Ok(Order::Ascending), 22 | 2 => Ok(Order::Descending), 23 | _ => Err(StdError::generic_err("Order must be 1 or 2")), 24 | } 25 | } 26 | } 27 | 28 | impl From for i32 { 29 | fn from(original: Order) -> i32 { 30 | original as _ 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/std/src/metadata.rs: -------------------------------------------------------------------------------- 1 | use schemars::JsonSchema; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | use crate::prelude::*; 5 | 6 | /// Replicates the cosmos-sdk bank module Metadata type 7 | #[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)] 8 | pub struct DenomMetadata { 9 | pub description: String, 10 | pub denom_units: Vec, 11 | pub base: String, 12 | pub display: String, 13 | pub name: String, 14 | pub symbol: String, 15 | pub uri: String, 16 | pub uri_hash: String, 17 | } 18 | 19 | /// Replicates the cosmos-sdk bank module DenomUnit type 20 | #[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)] 21 | pub struct DenomUnit { 22 | pub denom: String, 23 | pub exponent: u32, 24 | pub aliases: Vec, 25 | } 26 | -------------------------------------------------------------------------------- /packages/std/src/never.rs: -------------------------------------------------------------------------------- 1 | /// Never can never be instantiated. This can be used in places 2 | /// where we want to ensure that no error is returned, such as 3 | /// the `ibc_packet_receive` entry point. 4 | /// 5 | /// In contrast to `Empty`, this does not have a JSON schema 6 | /// and cannot be used for message and query types. 7 | /// 8 | /// Once the ! type is stable, this is not needed anymore. 9 | /// See . 10 | /// 11 | /// ## Examples 12 | /// 13 | /// When using `Never` in a `Result`, we can unwrap in a type-safe way: 14 | /// 15 | /// ``` 16 | /// use cosmwasm_std::Never; 17 | /// 18 | /// pub fn safe_unwrap(res: Result) -> T { 19 | /// match res { 20 | /// Ok(value) => value, 21 | /// Err(err) => match err {}, 22 | /// } 23 | /// } 24 | /// 25 | /// let res: Result = Ok(5); 26 | /// assert_eq!(safe_unwrap(res), 5); 27 | /// ``` 28 | pub enum Never {} 29 | 30 | // The Debug implementation is needed to allow the use of `Result::unwrap`. 31 | impl core::fmt::Debug for Never { 32 | fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 33 | // Unreachable because no instance of Never can exist 34 | match *self {} 35 | } 36 | } 37 | 38 | // The Display implementation is needed to fulfill the ToString requirement of 39 | // entry point errors: `Result, E>` with `E: ToString`. 40 | impl core::fmt::Display for Never { 41 | fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 42 | // Unreachable because no instance of Never can exist 43 | match *self {} 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/std/src/pagination.rs: -------------------------------------------------------------------------------- 1 | use schemars::JsonSchema; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | use crate::Binary; 5 | 6 | /// Simplified version of the PageRequest type for pagination from the cosmos-sdk 7 | #[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)] 8 | pub struct PageRequest { 9 | pub key: Option, 10 | pub limit: u32, 11 | pub reverse: bool, 12 | } 13 | -------------------------------------------------------------------------------- /packages/std/src/panic.rs: -------------------------------------------------------------------------------- 1 | /// Installs a panic handler that aborts the contract execution 2 | /// and sends the panic message and location to the host. 3 | /// 4 | /// This overrides any previous panic handler. See 5 | /// for details. 6 | #[cfg(all(feature = "abort", target_arch = "wasm32"))] 7 | pub fn install_panic_handler() { 8 | use super::imports::handle_panic; 9 | std::panic::set_hook(Box::new(|info| { 10 | // E.g. "panicked at 'oh no (a = 3)', src/contract.rs:51:5" 11 | let full_message = info.to_string(); 12 | handle_panic(&full_message); 13 | })); 14 | } 15 | -------------------------------------------------------------------------------- /packages/std/src/prelude.rs: -------------------------------------------------------------------------------- 1 | pub use alloc::boxed::Box; 2 | pub use alloc::string::{String, ToString}; 3 | pub use alloc::vec::Vec; 4 | -------------------------------------------------------------------------------- /packages/std/src/query/query_response.rs: -------------------------------------------------------------------------------- 1 | use core::fmt::Debug; 2 | 3 | use serde::de::DeserializeOwned; 4 | 5 | /// A marker trait for query response types. 6 | /// 7 | /// Those types have in common that they should be `#[non_exhaustive]` in order 8 | /// to allow adding fields in a backwards compatible way. In contracts they are 9 | /// only constructed through deserialization. We want to make it hard for 10 | /// contract developers to construct those types themselves as this is most likely 11 | /// not what they should do. 12 | /// 13 | /// In hosts they are constructed as follows: 14 | /// - wasmvm: Go types with the same JSON layout 15 | /// - multi-test/cw-sdk: create a default instance and mutate the fields 16 | /// 17 | /// This trait is crate-internal and can change any time. 18 | #[allow(dead_code)] // This is used to statically ensure all the types have a shared set of traits 19 | pub(crate) trait QueryResponseType: DeserializeOwned + Debug + PartialEq + Clone {} 20 | -------------------------------------------------------------------------------- /packages/std/src/results/empty.rs: -------------------------------------------------------------------------------- 1 | use schemars::JsonSchema; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | /// An empty struct that serves as a placeholder in different places, 5 | /// such as contracts that don't set a custom message. 6 | /// 7 | /// It is designed to be expressable in correct JSON and JSON Schema but 8 | /// contains no meaningful data. Previously we used enums without cases, 9 | /// but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451) 10 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, Default)] 11 | pub struct Empty {} 12 | 13 | #[cfg(test)] 14 | mod tests { 15 | use super::*; 16 | 17 | use crate::{from_json, to_json_vec}; 18 | 19 | #[test] 20 | fn empty_can_be_instantiated() { 21 | let instance = Empty::default(); 22 | assert_eq!(instance, Empty {}); 23 | } 24 | 25 | #[test] 26 | fn empty_can_be_instantiated_serialized_and_deserialized() { 27 | let instance = Empty {}; 28 | let serialized = to_json_vec(&instance).unwrap(); 29 | assert_eq!(serialized, b"{}"); 30 | 31 | let deserialized: Empty = from_json(b"{}").unwrap(); 32 | assert_eq!(deserialized, instance); 33 | 34 | let deserialized: Empty = from_json(b"{\"stray\":\"data\"}").unwrap(); 35 | assert_eq!(deserialized, instance); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/std/src/results/mod.rs: -------------------------------------------------------------------------------- 1 | //! This module contains the messages that are sent from the contract to the VM as an execution result 2 | 3 | mod contract_result; 4 | mod cosmos_msg; 5 | mod empty; 6 | mod events; 7 | mod query; 8 | mod response; 9 | mod submessages; 10 | mod system_result; 11 | 12 | pub use contract_result::ContractResult; 13 | #[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))] 14 | pub use cosmos_msg::WeightedVoteOption; 15 | pub use cosmos_msg::{ 16 | wasm_execute, wasm_instantiate, AnyMsg, BankMsg, CosmosMsg, CustomMsg, WasmMsg, 17 | }; 18 | #[cfg(feature = "staking")] 19 | pub use cosmos_msg::{DistributionMsg, StakingMsg}; 20 | #[cfg(feature = "stargate")] 21 | pub use cosmos_msg::{GovMsg, VoteOption}; 22 | pub use empty::Empty; 23 | pub use events::{attr, Attribute, Event}; 24 | pub use query::QueryResponse; 25 | pub use response::Response; 26 | pub use submessages::{MsgResponse, Reply, ReplyOn, SubMsg, SubMsgResponse, SubMsgResult}; 27 | pub use system_result::SystemResult; 28 | -------------------------------------------------------------------------------- /packages/std/src/results/query.rs: -------------------------------------------------------------------------------- 1 | pub type QueryResponse = cosmwasm_core::Binary; 2 | -------------------------------------------------------------------------------- /packages/std/src/storage_keys/mod.rs: -------------------------------------------------------------------------------- 1 | mod length_prefixed; 2 | 3 | // Please note that the entire storage_keys module is public. So be careful 4 | // when adding elements here. 5 | pub use length_prefixed::{namespace_with_key, to_length_prefixed, to_length_prefixed_nested}; 6 | -------------------------------------------------------------------------------- /packages/std/src/testing/mod.rs: -------------------------------------------------------------------------------- 1 | #![cfg(not(target_arch = "wasm32"))] 2 | 3 | // Exposed for testing only 4 | // Both unit tests and integration tests are compiled to native code, so everything in here does not need to compile to Wasm. 5 | 6 | mod mock; 7 | 8 | pub use cosmwasm_core::testing::*; 9 | 10 | #[cfg(feature = "cosmwasm_1_3")] 11 | pub use mock::DistributionQuerier; 12 | #[cfg(feature = "staking")] 13 | pub use mock::StakingQuerier; 14 | pub use mock::{ 15 | mock_dependencies, mock_dependencies_with_balance, mock_dependencies_with_balances, mock_env, 16 | mock_info, mock_wasmd_attr, BankQuerier, MockApi, MockQuerier, MockQuerierCustomHandlerResult, 17 | MockStorage, MOCK_CONTRACT_ADDR, 18 | }; 19 | #[cfg(feature = "stargate")] 20 | pub use mock::{ 21 | mock_ibc_channel, mock_ibc_channel_close_confirm, mock_ibc_channel_close_init, 22 | mock_ibc_channel_connect_ack, mock_ibc_channel_connect_confirm, mock_ibc_channel_open_init, 23 | mock_ibc_channel_open_try, mock_ibc_packet_ack, mock_ibc_packet_recv, mock_ibc_packet_timeout, 24 | }; 25 | -------------------------------------------------------------------------------- /packages/vm/examples/module_size.rs: -------------------------------------------------------------------------------- 1 | use std::fs::File; 2 | use std::io::Read; 3 | use std::mem; 4 | 5 | use clap::{Arg, Command}; 6 | 7 | use cosmwasm_vm::internals::{compile, make_compiling_engine}; 8 | use wasmer::{Engine, Module}; 9 | 10 | pub fn main() { 11 | let matches = Command::new("Module size estimation") 12 | .version("0.0.4") 13 | .author("Mauro Lacy ") 14 | .arg( 15 | Arg::new("WASM") 16 | .help("Wasm file to read and compile") 17 | .required(true) 18 | .index(1), 19 | ) 20 | .get_matches(); 21 | 22 | // File 23 | let path: &String = matches.get_one("WASM").expect("Error parsing file name"); 24 | let mut file = File::open(path).unwrap(); 25 | mem::drop(matches); 26 | 27 | // Read wasm 28 | let mut wasm = Vec::::new(); 29 | file.read_to_end(&mut wasm).unwrap(); 30 | mem::drop(file); 31 | 32 | // Report wasm size 33 | let wasm_size = wasm.len(); 34 | println!("wasm size: {wasm_size} bytes"); 35 | 36 | // Compile module 37 | let engine = make_compiling_engine(None); 38 | let module = compile(&engine, &wasm).unwrap(); 39 | mem::drop(wasm); 40 | 41 | let serialized = module.serialize().unwrap(); 42 | mem::drop(module); 43 | 44 | // Deserialize module 45 | let module = module_deserialize(&engine, &serialized); 46 | mem::drop(serialized); 47 | 48 | // Report (serialized) module size 49 | let serialized = module.serialize().unwrap(); 50 | mem::drop(module); 51 | let ser_size = serialized.len(); 52 | println!("module size (serialized): {ser_size} bytes"); 53 | println!( 54 | "(serialized) module size ratio: {:.2}", 55 | ser_size as f32 / wasm_size as f32 56 | ); 57 | } 58 | 59 | #[inline(never)] 60 | fn module_deserialize(engine: &Engine, serialized: &[u8]) -> Module { 61 | unsafe { Module::deserialize(&engine, serialized) }.unwrap() 62 | } 63 | -------------------------------------------------------------------------------- /packages/vm/examples/module_size.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Uses valgrind's massif tool to compute heap memory consumption of compiled modules. 3 | # For a wasmer `Module`, it has been determined that this method underestimates the size 4 | # of the module significanty. 5 | set -e 6 | 7 | MAX_SNAPSHOTS=1000 8 | 9 | WASM="$1" 10 | [ -z "$WASM" ] && echo "Usage: $0 .wasm" && exit 1 11 | 12 | PROFILE="release" 13 | MEM_UTIL="valgrind --tool=massif --max-snapshots=$MAX_SNAPSHOTS" 14 | SUM_UTIL="ms_print" 15 | 16 | PROG=$(basename $0 .sh) 17 | BASE_DIR=$(dirname $0)/.. 18 | 19 | # Look for the useful info 20 | FNS="module_compile module_deserialize" 21 | 22 | BIN="$BASE_DIR/../../target/$PROFILE/examples/$PROG" 23 | 24 | RESULTS="$BASE_DIR/$PROG.log" 25 | SUMMARY="$BASE_DIR/ms_print.log" 26 | 27 | if [ "$PROFILE" = "release" ]; then 28 | RUSTFLAGS="-g" cargo build --release --example $PROG 29 | else 30 | cargo build --example $PROG 31 | fi 32 | 33 | $MEM_UTIL --massif-out-file=$RESULTS $BIN $WASM 34 | $SUM_UTIL $RESULTS >$SUMMARY 35 | 36 | for FN in $FNS; do 37 | # Try to compute $FN() total (heap) bytes 38 | LAST_LINE=$(grep -n "::$FN " $SUMMARY | tail -1 | cut -f1 -d:) 39 | if [ -z "$LAST_LINE" ]; then 40 | echo -n "'$FN' not found. " 41 | [ $MAX_SNAPSHOTS -lt 1000 ] && echo "Try increasing MAX_SNAPSHOTS (current: $MAX_SNAPSHOTS, max: 1000). " || echo "Try again." 42 | continue 43 | fi 44 | TOTAL_LINES=$(wc -l $SUMMARY | cut -f1 -d\ ) 45 | START_LINE=$((TOTAL_LINES - $LAST_LINE + 1)) 46 | echo -n "module size ($FN): " 47 | tac $SUMMARY | sed -n "$START_LINE,/^ n /p" | grep "::$FN " | cut -f2 -d\( | cut -f1 -d\) | sort -u | sed 's/,//g;s/B//' | sed ':a;N;s/\n/+/;ta' | bc -l | sed 's/$/ bytes/' 48 | done 49 | -------------------------------------------------------------------------------- /packages/vm/src/errors/backtrace.rs: -------------------------------------------------------------------------------- 1 | use core::fmt::{Debug, Display, Formatter, Result}; 2 | use std::backtrace::Backtrace; 3 | 4 | /// This wraps an actual backtrace to allow us to use this in conjunction with [`thiserror::Error`] 5 | pub struct BT(Box); 6 | 7 | impl BT { 8 | #[track_caller] 9 | pub fn capture() -> Self { 10 | BT(Box::new(Backtrace::capture())) 11 | } 12 | } 13 | 14 | impl Debug for BT { 15 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { 16 | Debug::fmt(&self.0, f) 17 | } 18 | } 19 | 20 | impl Display for BT { 21 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { 22 | Display::fmt(&self.0, f) 23 | } 24 | } 25 | 26 | /// This macro implements `From` for a given error type to a given error type where 27 | /// the target error has a `backtrace` field. 28 | /// This is meant as a replacement for `thiserror`'s `#[from]` attribute, which does not 29 | /// work with our custom backtrace wrapper. 30 | macro_rules! impl_from_err { 31 | ($from:ty, $to:ty, $map:path) => { 32 | impl From<$from> for $to { 33 | fn from(err: $from) -> Self { 34 | $map { 35 | source: err, 36 | backtrace: $crate::errors::backtrace::BT::capture(), 37 | } 38 | } 39 | } 40 | }; 41 | } 42 | pub(crate) use impl_from_err; 43 | -------------------------------------------------------------------------------- /packages/vm/src/errors/mod.rs: -------------------------------------------------------------------------------- 1 | mod backtrace; 2 | mod communication_error; 3 | mod region_validation_error; 4 | mod vm_error; 5 | 6 | pub(crate) use backtrace::{impl_from_err, BT}; 7 | pub use communication_error::CommunicationError; 8 | pub use region_validation_error::RegionValidationError; 9 | pub use vm_error::VmError; 10 | 11 | pub type CommunicationResult = core::result::Result; 12 | pub type RegionValidationResult = core::result::Result; 13 | pub type VmResult = core::result::Result; 14 | -------------------------------------------------------------------------------- /packages/vm/src/filesystem.rs: -------------------------------------------------------------------------------- 1 | use std::{fs::create_dir_all, path::Path}; 2 | 3 | #[derive(Debug)] 4 | pub struct MkdirPFailure; 5 | 6 | /// An implementation for `mkdir -p`. 7 | /// 8 | /// This is a thin wrapper around fs::create_dir_all that 9 | /// hides all OS specific error messages to ensure they don't end up 10 | /// breaking consensus. 11 | pub fn mkdir_p(path: &Path) -> Result<(), MkdirPFailure> { 12 | create_dir_all(path).map_err(|_e| MkdirPFailure) 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use tempfile::TempDir; 18 | 19 | use super::*; 20 | 21 | #[test] 22 | fn mkdir_p_works() { 23 | let tmp_root = TempDir::new().unwrap(); 24 | 25 | // Can create 26 | let path = tmp_root.path().join("something"); 27 | assert!(!path.is_dir()); 28 | mkdir_p(&path).unwrap(); 29 | assert!(path.is_dir()); 30 | 31 | // Can be called on existing dir 32 | let path = tmp_root.path().join("something else"); 33 | assert!(!path.is_dir()); 34 | mkdir_p(&path).unwrap(); 35 | assert!(path.is_dir()); 36 | mkdir_p(&path).unwrap(); // no-op 37 | assert!(path.is_dir()); 38 | 39 | // Fails for dir with null 40 | let path = tmp_root.path().join("something\0with NULL"); 41 | mkdir_p(&path).unwrap_err(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/vm/src/modules/cached_module.rs: -------------------------------------------------------------------------------- 1 | use wasmer::{Engine, Module}; 2 | 3 | /// Some manual tests on Simon's machine showed that Engine is roughly 3-5 KB big, 4 | /// so give it a constant 10 KiB estimate. 5 | #[inline] 6 | pub fn engine_size_estimate() -> usize { 7 | 10 * 1024 8 | } 9 | 10 | #[derive(Debug, Clone)] 11 | pub struct CachedModule { 12 | pub module: Module, 13 | /// The runtime engine to run this module. Ideally we could use a single engine 14 | /// for all modules but the memory issue described in 15 | /// requires using one engine per module as a workaround. 16 | pub engine: Engine, 17 | /// The estimated size of this element in memory. 18 | /// Since the cached modules are just [rkyv](https://rkyv.org/) dumps of the Module 19 | /// instances, we use the file size of the module on disk (not the Wasm!) 20 | /// as an estimate for this. 21 | /// 22 | /// Between CosmWasm 1.4 (Wasmer 4) and 1.5.2, Store/Engine were not cached. This lead to a 23 | /// memory consumption problem. From 1.5.2 on, Module and Engine are cached and Store is created 24 | /// from Engine on demand. 25 | /// 26 | /// The majority of the Module size is the Artifact which is why we use the module filesize as the estimate. 27 | /// Some manual tests on Simon's machine showed that Engine is roughly 3-5 KB big, so give it a constant 28 | /// estimate: [`engine_size_estimate`]. 29 | pub size_estimate: usize, 30 | } 31 | -------------------------------------------------------------------------------- /packages/vm/src/modules/mod.rs: -------------------------------------------------------------------------------- 1 | mod cached_module; 2 | mod file_system_cache; 3 | mod in_memory_cache; 4 | mod pinned_memory_cache; 5 | mod versioning; 6 | 7 | pub use cached_module::CachedModule; 8 | pub use file_system_cache::FileSystemCache; 9 | pub use in_memory_cache::InMemoryCache; 10 | pub use pinned_memory_cache::PinnedMemoryCache; 11 | pub use versioning::current_wasmer_module_version; 12 | -------------------------------------------------------------------------------- /packages/vm/src/testing/mod.rs: -------------------------------------------------------------------------------- 1 | // The external interface is `use cosmwasm_vm::testing::X` for all integration testing symbols, no matter where they live internally. 2 | 3 | mod calls; 4 | mod instance; 5 | mod mock; 6 | mod querier; 7 | mod storage; 8 | 9 | pub use calls::{execute, instantiate, migrate, query, reply, sudo}; 10 | #[cfg(feature = "stargate")] 11 | pub use calls::{ 12 | ibc_channel_close, ibc_channel_connect, ibc_channel_open, ibc_packet_ack, ibc_packet_receive, 13 | ibc_packet_timeout, 14 | }; 15 | pub use instance::{ 16 | mock_instance, mock_instance_options, mock_instance_with_balances, 17 | mock_instance_with_failing_api, mock_instance_with_gas_limit, mock_instance_with_options, 18 | test_io, MockInstanceOptions, 19 | }; 20 | pub use mock::{ 21 | mock_backend, mock_backend_with_balances, mock_env, mock_info, MockApi, MOCK_CONTRACT_ADDR, 22 | }; 23 | pub use querier::MockQuerier; 24 | pub use storage::MockStorage; 25 | -------------------------------------------------------------------------------- /packages/vm/src/wasm_backend/compile.rs: -------------------------------------------------------------------------------- 1 | use wasmer::{Engine, Module}; 2 | 3 | use crate::errors::VmResult; 4 | 5 | /// Compiles a given Wasm bytecode into a module. 6 | pub fn compile(engine: &Engine, code: &[u8]) -> VmResult { 7 | let module = Module::new(&engine, code)?; 8 | Ok(module) 9 | } 10 | 11 | #[cfg(test)] 12 | mod tests { 13 | use super::*; 14 | use crate::wasm_backend::make_compiling_engine; 15 | 16 | static CONTRACT: &[u8] = include_bytes!("../../testdata/floaty.wasm"); 17 | 18 | #[test] 19 | fn contract_with_floats_passes_check() { 20 | let engine = make_compiling_engine(None); 21 | assert!(compile(&engine, CONTRACT).is_ok()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/vm/src/wasm_backend/mod.rs: -------------------------------------------------------------------------------- 1 | mod compile; 2 | mod engine; 3 | mod gatekeeper; 4 | mod limiting_tunables; 5 | 6 | #[cfg(test)] 7 | pub use engine::make_compiler_config; 8 | 9 | pub use compile::compile; 10 | pub use engine::{make_compiling_engine, make_runtime_engine}; 11 | -------------------------------------------------------------------------------- /packages/vm/testdata/README.md: -------------------------------------------------------------------------------- 1 | # Test data 2 | 3 | The contracts here are compilations of the Hackatom contract. 4 | 5 | ## contract.wasm 6 | 7 | Is a symbolic link to a recent hackatom contract. 8 | 9 | ## corrupted.wasm 10 | 11 | A corrupted contract files, created by 12 | 13 | ```sh 14 | cp contract.wasm corrupted.wasm 15 | printf '\x11\x11\x11\x11\x11\x11\x11\x11' | dd of=corrupted.wasm bs=1 seek=1000 count=8 conv=notrunc 16 | ``` 17 | -------------------------------------------------------------------------------- /packages/vm/testdata/corrupted.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/corrupted.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/cyberpunk.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/cyberpunk.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/cyberpunk_rust170.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/cyberpunk_rust170.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/empty.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/empty.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/floaty.wasm: -------------------------------------------------------------------------------- 1 | floaty_1.2.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/floaty_0.16.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/floaty_0.16.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/floaty_1.0.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/floaty_1.0.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/floaty_1.2.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/floaty_1.2.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/floaty_2.0.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/floaty_2.0.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom.wasm: -------------------------------------------------------------------------------- 1 | hackatom_1.2.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom_0.10.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/hackatom_0.10.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom_0.11.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/hackatom_0.11.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom_0.12.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/hackatom_0.12.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom_0.14.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/hackatom_0.14.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom_0.15.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/hackatom_0.15.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom_0.16.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/hackatom_0.16.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom_0.7.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/hackatom_0.7.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom_0.8.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/hackatom_0.8.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom_0.9.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/hackatom_0.9.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom_1.0.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/hackatom_1.0.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/hackatom_1.2.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/hackatom_1.2.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/ibc_reflect.wasm: -------------------------------------------------------------------------------- 1 | ibc_reflect_1.2.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/ibc_reflect_0.14.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/ibc_reflect_0.14.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/ibc_reflect_0.15.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/ibc_reflect_0.15.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/ibc_reflect_0.16.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/ibc_reflect_0.16.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/ibc_reflect_1.0.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/ibc_reflect_1.0.wasm -------------------------------------------------------------------------------- /packages/vm/testdata/ibc_reflect_1.2.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirmaChain/cosmwasm/a35b0189a7a6320236bdb482ff4a56bd943ea643/packages/vm/testdata/ibc_reflect_1.2.wasm --------------------------------------------------------------------------------