Skip to content

JSON interface description#1387

Merged
chriseth merged 26 commits intodevelopfrom
json-interface
Feb 9, 2017
Merged

JSON interface description#1387
chriseth merged 26 commits intodevelopfrom
json-interface

Conversation

@axic
Copy link
Contributor

@axic axic commented Nov 16, 2016

Follow up #1129. (Moved from #645 to a common branch.)

Todo:

abi: [ /* abi definition */ ],
userdoc: [],
devdoc: [],
natspec: [ /* user documentation comments */ ]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing natspec from here, only keeping userdoc / devdoc.

"dir/file.sol": {keccax: "0xabc..."},
"xkcd": {swarm: "0x456..."}
},
// This is a subset of the regular compiler input
Copy link
Contributor Author

Choose a reason for hiding this comment

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

settings is up to the intrepretation of the compiler defined by the language and compiler fields.

"official") at a registry contract.

{
version: "1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add comment: this is the version of the metadata spec.

{
version: "1",
language: "Solidity",
compiler: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

compiler is language specific.

language: "Solidity",
compiler: {
commit: "55db20e32c97098d13230ab7500758e8e3b31d64",
version: "soljson-2313-2016-12-12",
Copy link
Contributor Author

@axic axic Nov 16, 2016

Choose a reason for hiding this comment

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

Must equal to the compiler semver version. Required field.

version: "1",
language: "Solidity",
compiler: {
commit: "55db20e32c97098d13230ab7500758e8e3b31d64",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove, the semver version includes the commit.

compiler: {
commit: "55db20e32c97098d13230ab7500758e8e3b31d64",
version: "soljson-2313-2016-12-12",
keccak: "0x123..."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

keccak256 hash of the actual compiler. Optional field.


{
version: "1",
language: "Solidity",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Required field.

// This is a subset of the regular compiler input
sources:
{
"abc": {keccak: "0x456..."}, // here, sources are always given by hash
Copy link
Contributor Author

@axic axic Nov 16, 2016

Choose a reason for hiding this comment

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

The supported fields are:

  • keccak256: a hash of the file. Recommended in every case, but if content is specified it has very little benefit.
  • content: the actual file content as a string.
  • url: a way to retrieve the file. It can be (but not limited to):
    • http:// or https:// (ie. github)
    • bzz:// or bzzr://
    • ipfs:

Copy link
Contributor

Choose a reason for hiding this comment

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

if you have url specified and content is not specified it should be mandated to have keccak256.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The key (filename) is an identifier for a source file. Cannot contain a colon. It used by fields in the settings.

optimizer: {enabled: true, runs: 500},
compilationTarget: "myFile.sol:MyContract",
libraries: {
"def:MyLib": "0x123123..."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add comment that entries are source keys and contract names plus the on-chain address of the 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.

Split out to be a map of key and library:

libraries: {
  "def": {
    "MyLib": "0x123123..."
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect.

Copy link
Contributor

Choose a reason for hiding this comment

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

We currently do not have file-based libraries, that should be changed in the near future, but we might also just allow libraries: { "MyLib": "0x123"} for now.

{
sources:
{
// the keys here are the "global" names of the source files, imports can use other files via remappings (see below)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What applies to sources in metadata applies here. Two differences:

  • keccak256 is used to verify the content after acquiring it
  • file: as a url is supported

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about supporting keccak256 and urls. The compiler will then (in some defined order) query the caller for each url and hash, until the file is retrieved or the options are exhausted.

Input Description
-----------------

QUESTION: How to specific file-reading callback? - probably not as part of json input
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The read callback will receive the url as specified in the sources list.

message: "Invalid keyword" // mandatory
}
]
contracts: {
Copy link
Contributor Author

@axic axic Nov 16, 2016

Choose a reason for hiding this comment

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

This contains all the compiled outputs. It can be limited/filtered by the compilationTarget setting.

// (axic) what is remapping doing exactly?
optimizer: {enabled: true, runs: 500},
// if given, only compiles this contract, can also be an array. If only a contract name is given, tries to find it if unique.
compilationTarget: "myFile.sol:MyContract",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

compilationTarget:

  • can be an array
  • if no contract name is specified, all contracts in that file are considered
  • it can refer to a key and contract name which is not part of the sources, but will be loaded during parsing the sources

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We remove this, as it is superseded by outputSelection.

},
// The following can be used to restrict the fields the compiler will output.
// (axic)
outputSelection: [
Copy link
Contributor Author

@axic axic Nov 16, 2016

Choose a reason for hiding this comment

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

Merging compilation target and output selection:

"*": {
  "*": [ "abi", "asm" ]
}

"def": {
  "MyContract": [ "abi", "opcodes" ]
}

"*": {
  "*": [ "srcmap" ]
}

"*": {
  "": [ "ast", "formal" ]
}

Empty contract name refers to the file itself, while the star refers to all of the contracts.

outputSelection is a hashmap of the above. If no outputSelection is defined, then the compiler loads and does type checking, but will not generate any outputs apart from errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ast and formal are file-level and if they are needed, an additional empty-string entry is needed.

sourceList: ["source1.sol", "source2.sol"], // this is important for source references both in the ast as well as in the srcmap in the contract
sources: {
"source1.sol": {
"AST": { ... }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fields are:

  • keccak256
  • id (used in source maps)
  • ast

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chriseth if the AST is a JSON object, what is the hash referring to?

formal: {
"why3": "..."
},
sourceList: ["source1.sol", "source2.sol"], // this is important for source references both in the ast as well as in the srcmap in the 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.

This is superseded by the id in sources.

"abi", "evm.assembly", "evm.bytecode", ..., "why3", "ewasm.wasm"
]
outputSelection: {
abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,srcmap,srcmap-runtime,userdoc
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Output types:

  • abi
  • ast (as a JSON object)
  • evm.assembly
  • ...

To be defined soon.

Copy link
Contributor Author

@axic axic Dec 23, 2016

Choose a reason for hiding this comment

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

  • ast - AST of all source files
  • why3 - Translated source suitable for formal
  • abi - ABI
  • userdoc - User Doc
  • devdoc - Dev Doc
  • metadata - Metadata
  • evm.ir - New assembly format before desugaring (not supported atm)
  • evm.assembly - New assembly format after desugaring (not supported atm)
  • evm.asm - current asm
  • evm.asmJSON - current asmjson
  • evm.opcodes - current opcodes
  • evm.methodIdentifiers - the current "hashes" / "functionHashes"
  • evm.gasEstimates - current --gas and "gasEstimates"
  • evm.bytecode - current --bin or bytecode
  • evm.deployedBytecode - current --bin-runtime or runtimeBytecode

--clone-bin is removed.

{
remappings: [":g/dir"],
optimizer: {enabled: true, runs: 500},
compilationTarget: "myFile.sol:MyContract",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Split out to a be a map of key and contract:

compilationTarget: { "myFile.sol": "MyContract }

Copy link
Contributor

Choose a reason for hiding this comment

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

++

@axic
Copy link
Contributor Author

axic commented Nov 17, 2016

@chriseth @VoR0220 updated the metadata output.

Note that the actual bytecode is not part of the metadata because the hash
of the metadata structure will be included in the bytecode itself.

This requires the compiler to be able to compute the hash of its own binary,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This section should be removed.

}
},
functionHashes:
metadata: // see below
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mention that, contrary to the rest of the fields, this is not a JSON object, but a stringified JSON. This is because serialisation differences might result in different output and thus metadata hash.

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 wonder if we should call this metadata (which is kind of vague) or come with an actual name for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should actually refer to the metadata section in miscellaneous.rst (once #1386 is merged).

{
"myFile.sol": {
"keccak256": "0x123...",
"url": "bzzr://0x56..."
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this does usually not have a 0x prefix.

language: "Solidity",
// Required field, the contents are specific to the language
compiler: {
name: "solc",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not part of the implementation.

@pipermerriam
Copy link
Contributor

🎂 !!!! This is great. Thank you for all the work you've put into this. It's going to be a major improvement.

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.

5 participants