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

Reference Contract Schema on chain #1043

Open
JakeHartnell opened this issue Oct 8, 2022 · 9 comments
Open

Reference Contract Schema on chain #1043

JakeHartnell opened this issue Oct 8, 2022 · 9 comments

Comments

@JakeHartnell
Copy link

So many developers build tools on top of CosmWasm have complained to me that there is no way to get the contract schema, and no reference to it on chain.

User story: As a developer, I would like to be able to query the contract's schema on chain.

With the latest version of cosmwasm-schema we're generating nice single file schemas. I see two viable paths for getting a first version of this shipped:

  • When uploading a code id, add a --schema option that takes a schema-url which could simply be the IPFS address of the schema
  • Extend cw2 to have a reference to a scheme-url

I will note that verification of the contract code and schema is a separate problem. Have a lot of devs asking for this, and would like to get something for them soon.

Related: #241

@josefleventon
Copy link

Much needed feature +1

@pyramation
Copy link
Contributor

this would be great for codegen! If there is a way to do this would open up a lot of new and interesting ways to interact with contracts 🛠

@alpe
Copy link
Contributor

alpe commented Oct 10, 2022

Thanks @JakeHartnell for bringing this topic up again. It is important and will improve dev and users experience when integrated well into common tooling.

Though our experience with on chain urls was not great in the past. The field was either empty or not filled with useful information. But this may be a lack of spec and tooling.
Driving this forward, let's make this an epic and collect more details, other consumers and use cases for this data.
How should the data look like that is linked too?

@JakeHartnell
Copy link
Author

Thanks @JakeHartnell for bringing this topic up again. It is important and will improve dev and users experience when integrated well into common tooling.

Though our experience with on chain urls was not great in the past. The field was either empty or not filled with useful information. But this may be a lack of spec and tooling. Driving this forward, let's make this an epic and collect more details, other consumers and use cases for this data. How should the data look like that is linked too?

The data should be the generated jsonschema of a contract, basically the output of cosmwasm-schema.

Use cases:

  • Code gen
  • Default contract interaction UI for block explorers, etc.
  • Indexers

We want to use it with DAO DAO to provide a default contract interaction UI. If the field is empty, we could handle that, same if it doesn't return the correct information. We are working on a code-id registry that could provide needed verification.

Most important to me is having someway to include a reference to the schema or the schema itself on-chain, personally I thinking an optional --schema-url when storing the contract wasm would be sufficient for a V1 as it's better than nothing.

@ethanfrey
Copy link
Member

ethanfrey commented Oct 10, 2022

personally I thinking an optional --schema-url when storing the contract wasm would be sufficient for a V1 as it's better than nothing.

problem with this, is we need to make backwards compatibility for all chains from now on for this field.

blockchains are immutable unless they run some migrations. x/wasm doesn't even have control of how it is deployed. so, adding fields to drop them later is not so good.

We had discussed this long ago (much before we had this community or level of tooling). We can revisit it, but it would be good to read such discussions (yes, both from 2020):

The feeling was that it was too inflexible to do in x/wasm and some service (either off-chain or inside a contract) would be much better way to experiment and iterate. Once a workable solution was found, we could move it into x/wasm.

@JakeHartnell
Copy link
Author

I think doing it inside a contract with something like cw2 could be a great short term approach.

@ethanfrey
Copy link
Member

Seems a bit wasteful, in that we only need to store this once per code id, rather than write state each contract, but it does seem a very easy to deploy opt-in solution. And each contract could opt-out later on.

Do you want to raise an issue on cw-plus to discuss how to do so?
I think we can require the schema, store it in some predefined key (like cw2, but different), and then add a build.rs file that compiles the schema and inserts the schema object into the binary.

Happy to have a discussion with @uint on that over in cw-plus

@uint
Copy link

uint commented Oct 11, 2022

Oh, cool. "Self-describing" contracts are exciting!

@arcayne
Copy link

arcayne commented Oct 17, 2022

Adding to the conversation from a usability perspective, from a subset of the issue being discussed.

Current pain

No way clear way to give communities all the ingredients to verify stored codes:

  • Link to source code
  • Checksum

Too big doses of trust without it.

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

No branches or pull requests

7 participants