CosmWasm / CosmWasm/wasmd

Save contract info before calling instantiate entrypoint

Open
#2,044 9 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
416
Forks
538
PR merge metrics
No merged PRs in 30d

Description

# Current behaviour

The [instantiate entrypoint is called](https://github.com/CosmWasm/wasmd/blob/91ee0f35a117b7de0be2e0ec81cdd018ad2183ab/x/wasm/keeper/keeper.go#L337) *before* the [contract info is stored](https://github.com/CosmWasm/wasmd/blob/91ee0f35a117b7de0be2e0ec81cdd018ad2183ab/x/wasm/keeper/keeper.go#L383).
This results in an error occuring if the contract tries to query that info inside the instantiate entrypoint.

# Expected behaviour

We should probably call the entrypoint *after* saving the info. That should make the data available to query inside the instantiate entrypoint. To me, it doesn't look like there is any specific reason for the current order and it is confusing and a somewhat inconsistent[^1].
We should just make sure that it gets reverted if the instantiate entrypoint errors. I think that should be the case automatically when returning an error, but a test for that would be good.

[^1]: See https://github.com/CosmWasm/cw-multi-test/issues/226 and https://discord.com/channels/737637324434833438/737643344712171600/1303704162298630186

Contributor guide

Open the contributing guide

Research direction

Start with x/wasm/keeper/keeper.go around the instantiate entrypoint and contract-info storage cited in the issue, then trace the error path. Add coverage for querying contract info during instantiation and for reverting the stored info when the entrypoint errors; done when both behaviors are verified by the relevant keeper tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, wasm
Domain
blockchain
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.