Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in query curve_info for cw20-bonding #2

Open
shiki-tak opened this issue Oct 22, 2021 · 14 comments
Open

Error in query curve_info for cw20-bonding #2

shiki-tak opened this issue Oct 22, 2021 · 14 comments

Comments

@shiki-tak
Copy link

I tried cw20-bonding and got the following error.

❯ CURVEINFO='{"curve_info":{}}'
❯ wasmd query wasm contract-state smart $CONTRACT "$CURVEINFO" --output json 
Error: rpc error: code = InvalidArgument desc = Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: unreachable: query wasm contract failed: invalid request

Conditions

  • Only query "CurveInfo" will cause an error.
  • Doesn't happen when "CurveType" is "Constant", but happens after "Buy" for "Linear" and "SquareRoot".(Before "Buy", no error occurs.)
  • cw-plus v0.10.0
  • wasmd v0.20.0
@maurolacy
Copy link

Interesting. It would be good if you provide the data you're using / a path for reproducing this.

Perhaps it can be encoded as a unit test, or in any case, an integration test.

@shiki-tak
Copy link
Author

Thanks for your reply.
I got error when I set the "INIT" as follows.

In addition, I haven't tried all the different cases, but...
When decimals, reserve_decimals, scale = 6, there is no error even if the curve_type is square_root.

~/dev/cw-plus tags/v0.10.0
❯ INIT='{"name": "bonding_curves_token","symbol": "BCT", "decimals": 18, "reserve_denom": "ucosm", "reserve_decimals": 18, "curve_type": {"square_root":{"slope":"1", "scale":18}}}' 

~/dev/cw-plus tags/v0.10.0
❯ wasmd tx wasm instantiate $CODE_ID "$INIT" --home ~/.wasmd --keyring-backend test --keyring-dir ~/.wasmd_keys --from alice --label "bonding curves token" --chain-id localnet --gas-prices 1.2ucosm --gas auto --gas-adjustment 1.3 -y
gas estimate: 191782
{"height":"49","txhash":"432AE3896C06F9D8631B45F9BF5E74701126357353EF25BAFEDE9802C9A0316F","data":"0A3C0A0B696E7374616E7469617465122D0A2B7761736D3179796361303878716467766A7A3070736735367A3637656A6839786D73366C34396E74777730","raw_log":"[{\"events\":[{\"type\":\"instantiate\",\"attributes\":[{\"key\":\"_contract_address\",\"value\":\"wasm1yyca08xqdgvjz0psg56z67ejh9xms6l49ntww0\"},{\"key\":\"code_id\",\"value\":\"1\"}]},{\"type\":\"message\",\"attributes\":[{\"key\":\"action\",\"value\":\"instantiate\"},{\"key\":\"module\",\"value\":\"wasm\"},{\"key\":\"sender\",\"value\":\"wasm10zyagjxmqjh2jn3sstpe7e2jkh430g6w6yqn7w\"}]}]}]","logs":[{"events":[{"type":"instantiate","attributes":[{"key":"_contract_address","value":"wasm1yyca08xqdgvjz0psg56z67ejh9xms6l49ntww0"},{"key":"code_id","value":"1"}]},{"type":"message","attributes":[{"key":"action","value":"instantiate"},{"key":"module","value":"wasm"},{"key":"sender","value":"wasm10zyagjxmqjh2jn3sstpe7e2jkh430g6w6yqn7w"}]}]}],"gas_wanted":"191782","gas_used":"160641"}

~/dev/cw-plus tags/v0.10.0
❯ CONTRACT=$(wasmd query wasm list-contract-by-code $CODE_ID $NODE --output json | jq -r '.contracts[-1]')

~/dev/cw-plus tags/v0.10.0
❯ wasmd query wasm contract-state smart $CONTRACT "$CURVEINFO" $NODE --output json
{"data":{"reserve":"0","supply":"0","spot_price":"0","reserve_denom":"ucosm"}}

~/dev/cw-plus tags/v0.10.0
❯ wasmd tx wasm execute $CONTRACT "$BUY" --home ~/.wasmd --keyring-backend test --keyring-dir ~/.wasmd_keys --from alice --amount 10ucosm --chain-id localnet --gas-prices 1.2ucosm --gas auto --gas-adjustment 1.3 -y
gas estimate: 176326
{"height":"52","txhash":"35D63C13AB8CC91381E6BAA600ED5C9AABA377C5C711FCC358759F667CBB6103","data":"0A090A0765786563757465","raw_log":"[{\"events\":[{\"type\":\"execute\",\"attributes\":[{\"key\":\"_contract_address\",\"value\":\"wasm1yyca08xqdgvjz0psg56z67ejh9xms6l49ntww0\"}]},{\"type\":\"message\",\"attributes\":[{\"key\":\"action\",\"value\":\"execute\"},{\"key\":\"module\",\"value\":\"wasm\"},{\"key\":\"sender\",\"value\":\"wasm10zyagjxmqjh2jn3sstpe7e2jkh430g6w6yqn7w\"}]},{\"type\":\"transfer\",\"attributes\":[{\"key\":\"recipient\",\"value\":\"wasm1yyca08xqdgvjz0psg56z67ejh9xms6l49ntww0\"},{\"key\":\"sender\",\"value\":\"wasm10zyagjxmqjh2jn3sstpe7e2jkh430g6w6yqn7w\"},{\"key\":\"amount\",\"value\":\"10ucosm\"}]},{\"type\":\"wasm\",\"attributes\":[{\"key\":\"_contract_address\",\"value\":\"wasm1yyca08xqdgvjz0psg56z67ejh9xms6l49ntww0\"},{\"key\":\"action\",\"value\":\"buy\"},{\"key\":\"from\",\"value\":\"wasm10zyagjxmqjh2jn3sstpe7e2jkh430g6w6yqn7w\"},{\"key\":\"reserve\",\"value\":\"10\"},{\"key\":\"supply\",\"value\":\"6082000000000000000\"}]}]}]","logs":[{"events":[{"type":"execute","attributes":[{"key":"_contract_address","value":"wasm1yyca08xqdgvjz0psg56z67ejh9xms6l49ntww0"}]},{"type":"message","attributes":[{"key":"action","value":"execute"},{"key":"module","value":"wasm"},{"key":"sender","value":"wasm10zyagjxmqjh2jn3sstpe7e2jkh430g6w6yqn7w"}]},{"type":"transfer","attributes":[{"key":"recipient","value":"wasm1yyca08xqdgvjz0psg56z67ejh9xms6l49ntww0"},{"key":"sender","value":"wasm10zyagjxmqjh2jn3sstpe7e2jkh430g6w6yqn7w"},{"key":"amount","value":"10ucosm"}]},{"type":"wasm","attributes":[{"key":"_contract_address","value":"wasm1yyca08xqdgvjz0psg56z67ejh9xms6l49ntww0"},{"key":"action","value":"buy"},{"key":"from","value":"wasm10zyagjxmqjh2jn3sstpe7e2jkh430g6w6yqn7w"},{"key":"reserve","value":"10"},{"key":"supply","value":"6082000000000000000"}]}]}],"gas_wanted":"176326","gas_used":"148751"}

~/dev/cw-plus tags/v0.10.0
❯ wasmd query wasm contract-state smart $CONTRACT "$CURVEINFO" $NODE --output json
Error: rpc error: code = InvalidArgument desc = Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: unreachable: query wasm contract failed: invalid request

@maurolacy
Copy link

I think this may be an overflow when converting from our Decimal to rust-decimal' s Decimal. There's a panic there that we're not currently handling / avoiding.

Thanks for the report. We will fix this asap.

@maurolacy maurolacy self-assigned this Oct 26, 2021
@ethanfrey
Copy link
Member

ah, 18 decimals... this causes all kinds of math overflows.

Why do you use that (besides habit from Ethereum)?

I mean, 6 or 9 decimals seems to suffice for almost any project.
The smallest measurement I have seen in use in Ethereum is GigaWei (for gas prices), which effectively is 9 decimal places.
Bitcoin works on 8, and still seems to be fine with that, even with $60.000/BTC (and 16 satoshi to $0.01)

@maurolacy
Copy link

We can still avoid panic when converting, basically by checking / limiting the range of allowed values / decimal places.

@shiki-tak
Copy link
Author

I don't have to plan to use 18 decimals.
I think a check or limit to avoid panic is sufficient.

@ethanfrey
Copy link
Member

I fully agree... a readable error message to the user is always better than a panic.

Removing the error condition (precision limit) can be discussed if there is a clear need. We would need to eg use u256 internally for all calculations, which may be a good idea? But checks/limits are 💯 need

@ethanfrey
Copy link
Member

btw, cw20-bonding was written like 1 year ago and just updated to match versions.
It could probably use some care and cleanup in general.
If you are planning to deploy something on this to production, it would be good to revisit it and feel free to raise issues (and PRs 😄 ) on any points that seem a bit questionable.

I think I have an outstanding issue to allow cw20 as the input tokens, not just native

@ethanfrey ethanfrey transferred this issue from CosmWasm/cw-plus Dec 28, 2021
@albttx
Copy link

albttx commented Mar 31, 2022

Hello, i'm having the same issue. i'm working with U256...

here is some debug logs:

github.com/CosmWasm/wasmd/x/wasm/keeper.Keeper.execute
github.com/CosmWasm/[email protected]/x/wasm/keeper/keeper.go:355
github.com/CosmWasm/wasmd/x/wasm/keeper.PermissionedKeeper.Execute
github.com/CosmWasm/[email protected]/x/wasm/keeper/contract_keeper.go:50
github.com/CosmWasm/wasmd/x/wasm/keeper.msgServer.ExecuteContract
github.com/CosmWasm/[email protected]/x/wasm/keeper/msg_server.go:93
github.com/CosmWasm/wasmd/x/wasm/types._Msg_ExecuteContract_Handler.func1
github.com/CosmWasm/[email protected]/x/wasm/types/tx.pb.go:784
github.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter).RegisterService.func2.1
github.com/cosmos/[email protected]/baseapp/msg_service_router.go:113
github.com/CosmWasm/wasmd/x/wasm/types._Msg_ExecuteContract_Handler
github.com/CosmWasm/[email protected]/x/wasm/types/tx.pb.go:786
github.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter).RegisterService.func2
github.com/cosmos/[email protected]/baseapp/msg_service_router.go:117
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runMsgs
github.com/cosmos/[email protected]/baseapp/baseapp.go:720
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx
github.com/cosmos/[email protected]/baseapp/baseapp.go:677
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).DeliverTx
github.com/cosmos/[email protected]/baseapp/abci.go:276
github.com/tendermint/tendermint/abci/client.(*localClient).DeliverTxAsync
github.com/tendermint/[email protected]/abci/client/local_client.go:93
github.com/tendermint/tendermint/proxy.(*appConnConsensus).DeliverTxAsync
github.com/tendermint/[email protected]/proxy/app_conn.go:85
github.com/tendermint/tendermint/state.execBlockOnProxyApp
github.com/tendermint/[email protected]/state/execution.go:320
github.com/tendermint/tendermint/state.(*BlockExecutor).ApplyBlock
github.com/tendermint/[email protected]/state/execution.go:140
github.com/tendermint/tendermint/consensus.(*State).finalizeCommit
github.com/tendermint/[email protected]/consensus/state.go:1638
github.com/tendermint/tendermint/consensus.(*State).tryFinalizeCommit
github.com/tendermint/[email protected]/consensus/state.go:1547
github.com/tendermint/tendermint/consensus.(*State).enterCommit.func1
github.com/tendermint/[email protected]/consensus/state.go:1482
github.com/tendermint/tendermint/consensus.(*State).enterCommit
github.com/tendermint/[email protected]/consensus/state.go:1520
github.com/tendermint/tendermint/consensus.(*State).addVote
github.com/tendermint/[email protected]/consensus/state.go:2135
github.com/tendermint/tendermint/consensus.(*State).tryAddVote
github.com/tendermint/[email protected]/consensus/state.go:1933
github.com/tendermint/tendermint/consensus.(*State).handleMsg
github.com/tendermint/[email protected]/consensus/state.go:839
github.com/tendermint/tendermint/consensus.(*State).receiveRoutine
github.com/tendermint/[email protected]/consensus/state.go:783
failed to execute message; message index: 0:

Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: unreachable: execute wasm contract failed" module=state

@ghost
Copy link

ghost commented May 15, 2022

I am also having trouble executing a message on cosmwasm contract, and I am getting the same exact method in the OP:

Error: rpc error: code = InvalidArgument desc = Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: unreachable: query wasm contract failed: invalid request

I am estimating the gas for a MsgExecute on a custom contract.
I've battle tested the contract locally and am at 90% test coverage, this only happens after the contract is deployed.

Is there any way to get a better error message or some stacktrace?

@rashid3011
Copy link

I am getting this error,
Error: rpc error: code = InvalidArgument desc = unable to resolve type URL /cosmwasm.wasm.v1beta1.MsgStoreCode: tx parse error: invalid request

for this setup command from cosmwasm document
RES=$(wasmd tx wasm store target/wasm32-unknown-unknown/release/cw_nameservice.wasm --from fred $TXFLAG -y)

can anyone help me out in resolving?

@dusterbloom
Copy link

Hi,
I am also getting the same error when trying to upload data to a contract from a .csv file

CREATE='{"create_graph_from_file":{"filepath": "../AllEdges_Test.csv"}}
wasmd tx wasm execute $CONTRACT "$CREATE" --from admin $TXFLAG -y

I get the following error:

Error: rpc error: code = InvalidArgument desc = failed to execute message; message index: 0: Error 
 calling the VM: 
Error executing Wasm: Wasmer runtime error:
 RuntimeError: unreachable: execute wasm contract failed: invalid request

@ethanfrey
Copy link
Member

If you use a cosmwasm 1.0.0 (no more rc) VM, ie. wasmd 0.27 or something that imports it, there is help.

Add features = ["abort"] to cosmwasm-std in your Cargo.toml and rebuild the wasm file.
Then it will give you a better error message

See "But there's more..." in this article https://medium.com/cosmwasm/cosmwasm-1-0-0-finalized-fadc148f9e18

@dusterbloom
Copy link

I am upgrading to wasmd 0.27 and cw 1.0.0 to try and see.
I managed to add abort adding this to Cargo.toml

[features]
abort = []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants