GithubHelp home page GithubHelp logo

finschia / wasmd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cosmwasm/wasmd

1.0 0.0 9.0 24.8 MB

Basic cosmos-sdk app with web assembly smart contracts

License: Other

Shell 1.19% Go 97.95% Makefile 0.62% Dockerfile 0.24%

wasmd's Introduction

Wasm Zone

codecov Go Report Card license LoC

This repository hosts Wasmd, the first implementation of a cosmos zone with wasm smart contracts enabled.

This code was forked from the cosmwasm/wasmd repository as a basis and cosmwasm/wasmd was forked from the cosmos/gaia repository, and then we change x/wasm. However, the wasmd binary should function just like gaiad except for the addition of the x/wasm module.

Note: Requires Go 1.20+

For critical security issues & disclosure, see SECURITY.md.

Compatibility with CosmWasm contracts

Compatibility

A VM can support one or more contract-VM interface versions. The interface version is communicated by the contract via a Wasm export. This is the current compatibility list:

Finschia/wasmd cosmwasm/wasmd Finschia/wasmvm cosmwasm/wasmvm Finschia/cosmwasm-vm Finschia/cosmwasm-std cosmwasm/cosmwasm-vm cosmwasm/cosmwasm-std
0.3 0.29.1 v1.1.1-0.12.0 v1.1.1 1.1.9+0.9.0 1.1.9
0.2 0.29.1 v1.1.1-0.11.6 v1.1.1 1.1.9+0.8.1 1.1.9
0.29 v1.1.0 1.0-1.1
0.28 v1.0.0 1.0-1.1
0.1 0.27 v1.0.0-0.10.0 v1.0.0 1.0
0.26 1.0.0-beta10 1.0
0.25 1.0.0-beta10 1.0
0.24 1.0.0-beta7 1.0.0-beta6 1.0
0.23 1.0.0-beta5 1.0
0.22 1.0.0-beta5 1.0
0.21 1.0.0-beta2 1.0
0.20 1.0.0-beta 1.0
0.19 0.16 0.16
0.18 0.16 0.16
0.17 0.14 0.14
0.16 0.14 0.14
0.15 0.13 0.11-0.13
0.14 0.13 0.11-0.13
0.13 0.12 0.11-0.13
0.12 0.12 0.11-0.13
0.11 0.11 0.11-0.13
0.10 0.10 0.10
0.9 0.9 0.9
0.8 0.8 0.8

Note: cosmwasm_std v1.0 means it supports contracts compiled by any v1.0.0-betaX or 1.0.x. It will also run contracts compiled with 1.x assuming they don't opt into any newer features. The 1.x cosmwasm_vm will support all contracts with 1.0 <= version <= 1.x.

Note that cosmwasm-std version defines which contracts are compatible with this system. The wasm code uploaded must have been compiled with one of the supported cosmwasm-std versions, or will be rejected upon upload (with some error message about "contract too old?" or "contract too new?"). cosmwasm-vm version defines the runtime used. It is a breaking change to switch runtimes (you will need to organize a chain upgrade). As of cosmwasm-vm 0.13 we are using wasmer 1.0, which is significantly more performant than the older versions.

Supported Systems

The supported systems are limited by the dlls created in wasmvm. In particular, we only support MacOS and Linux. However, M1 macs are not fully supported. (Experimental support was merged with wasmd 0.24) For linux, the default is to build for glibc, and we cross-compile with CentOS 7 to provide backwards compatibility for glibc 2.12+. This includes all known supported distributions using glibc (CentOS 7 uses 2.12, obsolete Debian Jessy uses 2.19).

As of 0.9.0 we support muslc Linux systems, in particular Alpine linux, which is popular in docker distributions. Note that we do not store the static muslc build in the repo, so you must compile this yourself, and pass -tags muslc. Please look at the Dockerfile for an example of how we build a static Go binary for muslc. (Or just use this Dockerfile for your production setup).

Stability

This is beta software It is run in some production systems, but we cannot yet provide a stability guarantee and have not yet gone through and audit of this codebase. Note that the CosmWasm smart contract framework used by wasmd is in a 1.0 release candidate as of March 2022, with stability guarantee and addressing audit results.

As of wasmd 0.22, we will work to provide upgrade paths for this module for projects running a non-forked version on their live networks. If there are Cosmos SDK upgrades, you will have to run their migration code for their modules. If we change the internal storage of x/wasm we will provide a function to migrate state that can be called by an x/upgrade handler.

The APIs are pretty stable, but we cannot guarantee their stability until we reach v1.0. However, we will provide a way for you to hard-fork your way to v1.0.

Thank you to all projects who have run this code in your mainnets and testnets and given feedback to improve stability.

Encoding

The used cosmos-sdk version is in transition migrating from amino encoding to protobuf for state. So are we now.

We use standard cosmos-sdk encoding (amino) for all sdk Messages. However, the message body sent to all contracts, as well as the internal state is encoded using JSON. Cosmwasm allows arbitrary bytes with the contract itself responsible for decoding. For better UX, we often use json.RawMessage to contain these bytes, which enforces that it is valid json, but also give a much more readable interface. If you want to use another encoding in the contracts, that is a relatively minor change to wasmd but would currently require a fork. Please open an issue if this is important for your use case.

Quick Start

make install
make test

if you are using a linux without X or headless linux, look at this article or #31.

Protobuf

The protobuf files for this project are published automatically to the buf repository to make integration easier:

wasmd version buf tag
0.26.x 51931206dbe09529c1819a8a2863d291035a2549

Generate protobuf

make proto-gen

The generators are executed within a Docker container, now.

Runtime flags

We provide a number of variables in app/app.go that are intended to be set via -ldflags -X ... compile-time flags. This enables us to avoid copying a new binary directory over for each small change to the configuration.

Available flags:

  • -X github.com/Finschia/wasmd/app.NodeDir=.corald - set the config/data directory for the node (default ~/.wasmd)
  • -X github.com/Finschia/wasmd/app.Bech32Prefix=coral - set the bech32 prefix for all accounts (default wasm)
  • -X github.com/Finschia/wasmd/app.ProposalsEnabled=true - enable all x/wasm governance proposals (default false)
  • -X github.com/Finschia/wasmd/app.EnableSpecificProposals=MigrateContract,UpdateAdmin,ClearAdmin - enable a subset of the x/wasm governance proposal types (overrides ProposalsEnabled)

Examples:

  • wasmd is a generic, permissionless version using the cosmos bech32 prefix

Compile Time Parameters

Besides those above variables (meant for custom wasmd compilation), there are a few more variables which we allow blockchains to customize, but at compile time. If you build your own chain and import x/wasm, you can adjust a few items via module parameters, but a few others did not fit in that, as they need to be used by stateless ValidateBasic(). Thus, we made them public var and these can be overridden in the app.go file of your custom chain.

  • wasmtypes.MaxLabelSize = 64 to set the maximum label size on instantiation (default 128)
  • wasmtypes.MaxWasmSize=777000 to set the max size of compiled wasm to be accepted (default 819200)

Genesis Configuration

We strongly suggest to limit the max block gas in the genesis and not use the default value (-1 for infinite).

  "consensus_params": {
    "block": {
      "max_gas": "SET_YOUR_MAX_VALUE",  

Tip: if you want to lock this down to a permisisoned network, the following script can edit the genesis file to only allow permissioned use of code upload or instantiating. (Make sure you set app.ProposalsEnabled=true in this binary):

sed -i 's/permission": "Everybody"/permission": "Nobody"/' .../config/genesis.json

Contributors

Much thanks to all who have contributed to this project, from this app, to the cosmwasm framework, to example contracts and documentation. Or even testing the app and bringing up critical issues. The following have helped bring this project to life:

Sorry if I forgot you from this list, just contact me or add yourself in a PR :)

wasmd's People

Contributors

170210 avatar alessio avatar alexanderbez avatar alpe avatar anilcse avatar assafmo avatar da1suk8 avatar dependabot-preview[bot] avatar dependabot[bot] avatar ethanfrey avatar faddat avatar fedekunze avatar fkneeland-figure avatar gamarin2 avatar jhernandezb avatar kokeshim0chi avatar loloicci avatar orkunkl avatar pinosu avatar puneet2019 avatar reuvenpo avatar rigelrozanski avatar sabau avatar sahith-narahari avatar shiki-tak avatar sunnya97 avatar tac0turtle avatar the-frey avatar webmaster128 avatar zemyblue avatar

Stargazers

 avatar

wasmd's Issues

Not good condition to handle MsgStoreCodeAndInstantiateContract

if err != nil && strings.Contains(err.Error(), "MsgStoreCodeAndInstantiateContract") {

This handler case is caused by "x/wasm/handler"'s "ErrorMsg". This condition is true when the message contains "MsgStoreCodeAndInstantiateContract" even if the message kind is not "MsgStoreCodeAndInstantiateContract".

Change it the condition is true iff the message kind is "MsgStoreCodeAndInstantiateContract".

Version bump to wasmd v0.50.0

This issue is related to #121

I have conducted operational verification using the current commit hash with the versions from Finschia/cosmwasm#342 and Finschia/wasmvm#139.

Remaining CI error

  • TestZeroHeightGenesis (appplus/export_test.go)
  • TestOnRecvPacket (x/wasm/ibc_test.go) - prefix error
  • TestParseVerificationFlags (x/wasm/client/cli/tx_test.go) - prefix error
  • TestGenesisInit (x/wasm/keeper/genesis_test.go)
  • TestImportContractWithCodeHistoryPreserved (x/wasm/keeper/genesis_test.go)
  • TestInstantiate (x/wasm/keeper/keeper_test.go) - address error
  • TestExecute (x/wasm/keeper/keeper_test.go) - address error
  • TestSudo (x/wasm/keeper/keeper_test.go) - address error
  • TestQueryAllContractState (x/wasm/keeper/keeper_test.go)
  • TestQueryRawContractState (x/wasm/keeper/querier_test.go)
  • TestQueryCode (x/wasm/keeper/querier_test.go)
  • TestQueryCodeList (x/wasm/keeper/querier_test.go)
  • TestQueryPinnedCodes (x/wasm/keeper/querier_test.go)
  • TestQueryCodeInfo (x/wasm/keeper/querier_test.go) - prefix error
  • TestQueryCodeInfoList (x/wasm/keeper/querier_test.go) - prefix error
  • TestDispatchSubMsgErrorHandling (x/wasm/keeper/submsg_test.go)
  • TestModuleMigrations (x/wasm/keeper/migrations_integration_test.go)
  • TestCodeValidateBasic (x/wasm/types/genesis_test.go)
  • TestHandleStoreAndInstantiate (x/wasmplus/module_test.go ONLY Finschia) - address error
  • TestErrorsCreateAndInstantiate (x/wasmplus/module_test.go ONLY Finschia)
  • TestHandleNonPlusWasmCreate (x/wasmplus/module_test.go ONLY Finschia)
  • TestGenesisExportImport (x/wasmplus/keeoer/genesis_test.go ONLY Finschia)

MsgStoreCodeAndInstantiateContract amino signature verify fail

MsgStoreCodeAndInstantiateContract amino signature verify fails because wrong amino codec is being used in MsgStoreCodeAndInstantiateContract::GetSignBytes(). Now wasm's amino codec is being used not wasmplus's amino codec.
https://github.com/line/wasmd/blob/main/x/wasmplus/types/tx.go#L54

And I got one more error.
https://github.com/line/wasmd/blob/main/x/wasmplus/types/codec.go#L19
when registering amino msg in codec, amino message type name is wrong.
currently "wasm/StoreCodeAndInstantiateContract", this should be "wasm/MsgStoreCodeAndInstantiateContract" like other messages.

Add `wasmvm.GoAPI` field to the keeper structure

The method #36 cannot be executed in x/wasm alone, because it uses the x/wasmplus functionality within x/wasm.

Then, instead of pluskeeper, which was added in #36, add an interface of wasmvm.GoAPI to the structure of keeper.
This allows the implementation of this interface to freely change the contents of the API.

wasmvm module not exist

When I run wasmd start, wasmvm module not exist error is occurred.

$ ./build/wasmd start
Error: wasmvm module not exist
Usage:
  wasmd start [flags]

commit hash: 577e450 (main branch)

Propose methods to completely separate the functions of dynamic_link into wasmplus

At present #22, only partial separation has been made for dynamic link branch of wasmd, so consider how to do this.


The following methods were used for implementation.

In #36, moved dynamic_link branch functionality to wasmplus.

It is implemented in the following way.

  1. Define the interface of the function defined in x/wasmplus/keeper.go in x/wasm/keeper.go.
  2. In x/wasm, functions and variables to be exposed to the outside world are defined as other variables in exported_*.go, in order to reduce differences from the original.
  3. Access the functions defined in x/wasmplus/api.go via the interface in x/wasm/keeper.go.

Refactoring message_sever integration test

Invalid address for call_callable_point or validate_dynamic_link_interface causes panic

Now we use MustAccAddressFromBech32 for converting bech32 string to account address in

contractAddr := sdk.MustAccAddressFromBech32(contractAddrStr)

and

contractAddr := sdk.MustAccAddressFromBech32(contractAddrStr)

.

It panics if the bech32 string is an invalid address.

https://github.com/Finschia/finschia-sdk/blob/d8ceec3131bbc09eae61437a532298bb77356033/types/address.go#L162

We should use AccAddressFromBech32 and do error handling for them.

Enable the use of wasmplus's `IsInactiveContract()` in cosmwasmAPI

In the dynamic_link branch separated process, the following function of wasmplus cannot be used in the #22 separated method due to circular reference problems.

Separation must be done by another method

func (k Keeper) IsInactiveContract(ctx sdk.Context, contractAddress sdk.AccAddress) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(types.GetInactiveContractKey(contractAddress))
}

TestExecuteManualInactiveContractFailure does not check whether the contract is active or not

func TestExecuteManualInactiveContractFailure(t *testing.T) {
ctx, keepers := CreateTestInput(t, false, AvailableCapabilities)
keeper := keepers.ContractKeeper
deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000))
topUp := sdk.NewCoins(sdk.NewInt64Coin("denom", 5000))
creator := keepers.Faucet.NewFundedRandomAccount(ctx, deposit...)
fred := keepers.Faucet.NewFundedRandomAccount(ctx, topUp...)
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)
contractID, _, err := keeper.Create(ctx, creator, wasmCode, nil)
require.NoError(t, err)
_, _, bob := keyPubAddr()
initMsg := HackatomExampleInitMsg{
Verifier: fred,
Beneficiary: bob,
}
initMsgBz, err := json.Marshal(initMsg)
require.NoError(t, err)
addr, _, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract 3", deposit)
require.NoError(t, err)
require.Equal(t, "link14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sgf2vn8", addr.String())
}

Make mock for bankplus module of finschia-sdk

Description

The current version of wasmd depends on the bankplus feature, which is an original functionality of the finschia-sdk.
Since the finschia-sdk is currently undergoing a version bump, we will use mocks to handle this dependency in the meantime.

This PR related to Finschia/finschia-sdk#1195, Finschia/finschia-sdk#1212

The parts that use bankplus are located in the following files:

  • app/app.go
  • appplus/app.go
  • x/wasm/keeper/genesis_test.go
  • x/wasm/keeper/options_test.go
  • x/wasm/keeper/test_common.go
  • x/wasmplus/keeper/genesis_test.go
  • x/wasmplus/keeper/keeper.go
  • x/wasmplus/keeper/test_common.go

The NewBaseKeeper interface will be modified as follows:

Before:
func NewBaseKeeper(
	cdc codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace,
	blockedAddr map[string]bool, deactMultiSend bool,
) BaseKeeper
After: 
func NewBaseKeeper(
	cdc codec.Codec, storeService store.KVStoreService, ak types.AccountKeeper,
	blockedAddr map[string]bool, deactMultiSend bool, authority string, logger log.Logger,
) BaseKeeper

Redesign `callablePointSDKEventAttributes` function

This function came from #26.

It's a bit weird that the callstack comes first, so move it to the tail.

func callablePointSDKEventAttributes(customAttributes []wasmvmtypes.EventAttribute, contractAddr sdk.AccAddress, callstack []byte) ([]sdk.Attribute, error) {
attrs, err := wasmkeeper.ContractSDKEventAttributes(customAttributes, contractAddr)
if err != nil {
return nil, err
}
// attrs[0] is addr
attrs = append([]sdk.Attribute{attrs[0], sdk.NewAttribute(wasmplustypes.AttributeKeyCallstack, string(callstack))}, attrs[1:]...)
return attrs, nil
}

bump up wasmd v0.31

bump up to cosmwasm/wasmd v0.31

dependency

  • cosmwasm/wasmvm: v1.2.0
  • cosmwasm/cosmwasm-std: v1.0-1.2

Research about standard interface detection.

Summary

Research about standard interface detection.

  • Research on function that can replace EVM's function selector.
  • Defining standard interface detection protocol.
  • Suggest a way to use an external library like inheritance from wasm.

Problem Definition

We need to know whether a specific smart contract supports a specific protocol, so that the smart contract can be excute and searched without errors in other smart contracts. For this purpose, in the case of EVM, the function of a function selector is provided. Let's see if there is a function that can replace EVM's function selector function that can distinguish a specific function from the wasm binary even in wasm of lbm-sdk.

If that feature doesn't exist, find out how to replace it.

Inheritance is not supported like EVM throught rustlang, the smart contract development language of cosmwasm. Then, we also suggest how to make a protocol such as ERC-165 a library so that other smart contract developers can use it.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.