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

feat: Add Contract Metadata Standard #330

Merged
merged 8 commits into from
Mar 29, 2022
Merged

Conversation

BenKurrek
Copy link
Contributor

This is based on the discussion held outlining a way for auditing and viewing source code for a deployed smart contract.

There is no trivial way of finding the source code or author of a deployed smart contract. By having a standard that outlines how to view the source code of an arbitrary smart contract, an environment of openness and collaboration is created.

@render
Copy link

render bot commented Mar 3, 2022

@austinabell austinabell requested a review from 10d9e March 3, 2022 21:29
@agileurbanite
Copy link

👍

Co-authored-by: Damián Parrino <bucanero@users.noreply.github.com>
```ts
type ContractMetadata = {
version: string|null, // optional, commit hash being used for the currently deployed wasm. If the contract is not open-sourced, this could also be a numbering system for internal organization / tracking such as "1.0.0" and "2.1.0".
link: string|null, //optional, link to open source code such as a Github repository or a CID to somewhere on IPFS.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenKurrek @austinabell @MaximusHaximus what are your thoughts of adding a system field so we can get some info on what system helped generate the wasm as well. This way we can try to rebuild the wasm and compare the hashes for auditing purposes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

system: "local"|string,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, you would need architecture and toolchain version at least. Would the purpose of this be human-readable so someone could try to replicate it? You would also need some commit or version since the link doesn't specify repo links to commit that it was built with

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah ideally i want to be able to reference the source code and source dependencies to help with auditing the contract. Here's what polygon does which is pretty cool: https://polygonscan.com/address/0x217cF04C783818E5b15Ae0723b22Ee2415Ab5fe3#code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was assuming that the toolchain version would be kept in the Github repo. I don't really see the need to add a system field but would love other people's opinions

@agileurbanite
Copy link

Reading up on how others handle this can we also add:

linkReference: deployed address of address of other smart contracts on which the current smart contract has a dependency.
object: Current smart contract bytecode
opcodes: Operation codes that are human-readable low-level instructions.
sourceMap: source map is to match each contract instruction to the section of the source code from which it was generated.

@austinabell
Copy link
Contributor

Reading up on how others handle this can we also add:

linkReference: deployed address of address of other smart contracts on which the current smart contract has a dependency.
object: Current smart contract bytecode
opcodes: Operation codes that are human-readable low-level instructions.
sourceMap: source map is to match each contract instruction to the section of the source code from which it was generated.

address and contract code can all be pulled without this. (This method is suggesting as part of the contract). This would only be needed if this info was stored externally

opcodes doesn't apply. Assume you're comparing with solidity, but the wasm instructions aren't important and the imported functions can just be pulled from the wasm blob, so this is redundant.

source map there is no use for this currently, because they can be linked through just analyzing the wasm binary. Doesn't seem that useful in our case to add bloat to the standard

@agileurbanite
Copy link

Reading up on how others handle this can we also add:

linkReference: deployed address of address of other smart contracts on which the current smart contract has a dependency.
object: Current smart contract bytecode
opcodes: Operation codes that are human-readable low-level instructions.
sourceMap: source map is to match each contract instruction to the section of the source code from which it was generated.

address and contract code can all be pulled without this. (This method is suggesting as part of the contract). This would only be needed if this info was stored externally

opcodes doesn't apply. Assume you're comparing with solidity, but the wasm instructions aren't important and the imported functions can just be pulled from the wasm blob, so this is redundant.

source map there is no use for this currently, because they can be linked through just analyzing the wasm binary. Doesn't seem that useful in our case to add bloat to the standard

I'm mainly looking at this from an auditing and reference standpoint. Also having a sourceMap would be useful for debugging imo but can be wrong.

@austinabell
Copy link
Contributor

I'm mainly looking at this from an auditing and reference standpoint. Also having a sourceMap would be useful for debugging imo but can be wrong.

You can get this information from the wasm binary by just following the function export, so I don't see how any format would be more useful than this. Esp since if auditing the compiled code one would convert the wasm file into wat or use some tool that does this mapping for you

Comment on lines +22 to +24
type ContractMetadata = {
version: string|null, // optional, commit hash being used for the currently deployed wasm. If the contract is not open-sourced, this could also be a numbering system for internal organization / tracking such as "1.0.0" and "2.1.0".
link: string|null, //optional, link to open source code such as a Github repository or a CID to somewhere on IPFS.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding some sort of organization contact link as well that points to the website of the application, or the developers; potentially with more contact information!

The difference between it and link is that one is to discover the source code, and the other is to discover what is the preferred way to reach developers/community behind this smart contract.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this information could be found by utilizing the link since you can open issues or PRs on Github and follow or view the developers' public profiles. The case where I think this might be useful, is if the link is a CID to somewhere on IPFS since you don't have the same ability to reach out or view the developers as you do using Github.

thoughts? @austinabell @agileurbanite

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually go even further and provide three different fields (similar to crates.io): Homepage, Documentation and Repository + version (to pin the exact version and allow reproducing the exact same binary).

Some services like npm only have Homepage and Repository. (Maybe documentation is a bit too much).


## Motivation

There is no trivial way of finding the source code or author of a deployed smart contract. Having a standard that outlines how to view the source code of an arbitrary smart contract creates an environment of openness and collaboration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the main use cases of having this standard, is if we are able to reproduce the same binary after we have access to the source code. I'm wondering if as part of it we should add a proposal or advise about how we can achieve byte for byte reproducibility.

Having a standard for reproducibility can be useful for external tools to automatically verify the code.

This is hard in general, mostly because there is more than one stack that can be used to generate the contract binary (i.e today we support rust and assembly script). Relevant discussion on how to make this possible on rust: rust-lang/cargo#9506

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A link to a docker image could be sufficient.

Copy link
Contributor

@10d9e 10d9e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great reviews here - it looks like it's conceptually ready for Draft. @BenKurrek see below...

Copy link
Contributor

@10d9e 10d9e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenKurrek This is nice work. We now also need a formatted standard document as part of the new process. In this case, the standard would be neps/nep-0330.md. See process, template and nep success criteria for more details.

@agileurbanite
Copy link

@BenKurrek mind taking a look at @jlogelin comments above?

@BenKurrek
Copy link
Contributor Author

Hey @jlogelin @agileurbanite been crazy busy - i'll take a look. Thanks so much!

@BenKurrek BenKurrek requested review from agileurbanite, mfornet, bucanero and 10d9e and removed request for mikedotexe March 29, 2022 15:02
@BenKurrek
Copy link
Contributor Author

@jlogelin @agileurbanite @austinabell I just pushed the changes to adhere to the new process for adding new NEPs as per Jay's suggestions. Take a look and let me know what you think.

neps/nep-0330.md Show resolved Hide resolved
@10d9e 10d9e merged commit 4c5f2b3 into master Mar 29, 2022
@10d9e 10d9e deleted the ContractMetadataStandard branch March 29, 2022 18:55
@robert-zaremba robert-zaremba mentioned this pull request Dec 12, 2022
2 tasks
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

Successfully merging this pull request may close these issues.

7 participants