-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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
Include metadata with solc compiler outputs #3606
Conversation
Thank you for your contribution! Your commits seem to not adhere to the repository coding standards
Please check the contribution guidelines for more details. This message was auto-generated by https://gitcop.com |
@@ -146,6 +147,10 @@ func runsolc(cmd *exec.Cmd, source string) (map[string]*Contract, error) { | |||
if err := json.Unmarshal([]byte(info.Devdoc), &devdoc); err != nil { | |||
return nil, fmt.Errorf("solc: error reading dev doc: %v", err) | |||
} | |||
var metadata interface{} | |||
if err := json.Unmarshal([]byte(info.Metadata), &metadata); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be backwards-compatible if you put if info.Metadata != "" { ... }
around the json.Unmarshal call. Please add this.
Thank you for your contribution! Your commits seem to not adhere to the repository coding standards
Please check the contribution guidelines for more details. This message was auto-generated by https://gitcop.com |
@fjl Hi. I've made the change you requested. Unfortunately, it's not enough to restore compatibility with older compiler versions. The issue is that older versions of
To fix this, I think we'd have to make sure to run I'd be glad to give that a shot, if you think it a good approach. (i'm sorry not to "just do it™", but this is the first time I've pretended to program in |
Thank you for your contribution! Your commits seem to not adhere to the repository coding standards
Please check the contribution guidelines for more details. This message was auto-generated by https://gitcop.com |
@fjl OK. So we now check the solidity version prior to the first compilation, and cache the compiler-appropriate solidity command-line params. We initialize/access the cached params under mutex, to ensure there are no race conditions between initialization and concurrent access. The code now behaves correctly under any 0.4.x compiler. Here is a jsonrpc compilation under 0.4.6, which does not support metadata. A
Here is the same under metadata-supporting 0.4.7.
There is an issue with the metadata. It is correct, but it should probably be emitted as a simple JSON string rather than in its full JSON to avoid ambiguities about ordering, spacing, and escaping. To verify the hash from this output, you have to unescape \u003cstdin\u003e to . A JSON string would be more elaborately escaped, but it could be unambiguously decoded and hashed. Neither this PR nor the current version support 0.3. compilers due to a separate issue. 0.3.x compilers don't accept
Here is the same attempt (with solidity version 0.3.5-5f97274a) under the current master branch:
I'd be glad to address this issue, but it should probably be a separate PR. |
Ensures that we can decode to a set of bytes that will be consistent with the swarm hash embedded in the code, without worrying about ambiguities of spacing, ordering, or escaping.
Thank you for your contribution! Your commits seem to not adhere to the repository coding standards
Please check the contribution guidelines for more details. This message was auto-generated by https://gitcop.com |
@fjl I've modified the PR to encode the full metadata file as a JSON string, that when parsed according to JSON rules yields the precise metadata file consistent with the embedded swarm hash. (Before the metadata was emitted as a JSON object, creating potential ambiguities spacing, ordering, and unescaping.) Under older compilers (>=0.4.0) an empty string is now emitted. Under solidity 0.4.8:
Under solidity 0.4.6:
I think this is probably the best way to go. A case could be made for emitting the JSON object rather than an escaped string: An object is more natural and manipulable, the rules to canonicalize to the hashed bytes are well specified so clients can undo any ambiguity. Alternatively, a case could be made for emitting the metadata as hex-encoded bytes, because that's the least ambiguous way of specifying the hash-consistent bytestring. Escaped-JSON-within-a-JSON-string is arguably a nice compromise -- the emitted metadata remains human readable, but it is easily and unambiguously convertable to hash-consistent bytes by any JSON parser. I'll leave this here until I hear from you. go can be fun. who knew? Thanks for the opportunity to play. |
Sorry, didn't find the time to look at this yet. |
@fjl i'm sorry to pester, no terrible rush, but a gentle ping. whether this way or some other way, working on some dev tooling that uses i apologize again for the hassle. you guys are a cut above the rest in actually implementing services for dev-tools, which is a real help. |
Bad news: eth_compileSolidity has been removed (#3740) due do overwhelming support for ethereum/EIPs#209 by core developers. We'll bring it back under a different name if needed. If your dev tooling is written in Go, you can still use the common/compiler package though ;) |
Superseded by #3786 |
Recent versions of
solc
now append a swarm hash of a metadata file to generated contract code, in order eventually to permit a kind of "reflection" on deployed contracts, as users become able look-up a file that includes ABI, reference to source and compiler-version to verify the code deployed, etc.This file is quite detailed, including information not available in any of the other compiler-generated artifact. Clients of
geth
would not in general be able to reconstruct a correctly hashing metadata file from other sources.This (trivial) PR has
geth
executesolc
with command-line arguments that provoke metadata generation along with the artifacts already expected.A serious downside of this PR is that it makes no attempt to remain compatible with older versions of
solc
. Attempts to compile viageth
using older versions ofsolc
will fail.Swarm hashes have been appended to generated code since Solidity version 0.4.7.