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

Outputting of ast and bytecode is inconsistent #5758

Closed
BlinkyStitt opened this issue Jan 7, 2019 · 7 comments
Closed

Outputting of ast and bytecode is inconsistent #5758

BlinkyStitt opened this issue Jan 7, 2019 · 7 comments

Comments

@BlinkyStitt
Copy link

I am using solc to compile some external contracts and then pass these files to truffle for my repo in an external compile step.

I have it working, but it requires some workarounds that I don't think should be necessary. Truffle requires both the abi and the bytecode.

$ solc-0.5.2 --help
...
Output Components:
  --ast                AST of all source files.
  --ast-json           AST of all source files in JSON format.
  --ast-compact-json   AST of all source files in a compact JSON format.
  --asm                EVM assembly of the contracts.
  --asm-json           EVM assembly of the contracts in JSON format.
  --opcodes            Opcodes of the contracts.
  --bin                Binary of the contracts in hex.
  --bin-runtime        Binary of the runtime part of the contracts in hex.
  --abi                ABI specification of the contracts.
  --hashes             Function signature hashes of the contracts.
  --userdoc            Natspec user documentation of all contracts.
  --devdoc             Natspec developer documentation of all contracts.
  --metadata           Combined Metadata JSON whose Swarm hash is stored 
                       on-chain.

There is no --bytecode flag, so I had to switch to using --standard-json which allows outputing "evm.bytecode.object": (More detail on how I did this at trufflesuite/truffle#1607)

But I just ran into another problem; the json output doesn't have an ast section at all. I've tried setting outputSelection to ["*"], ["abi", "ast", "evm"], ["abi", "legacyAST", "evm"] and a few other combinations, but none of them included the ast.

For now I'm compiling twice. Once with --ast-json to get the ast, and once with --standard-json to get the bytecode (which I have to prepend with "0x"). Let me know if I should open this as a seperate issue.

This whole process seems more complicated than it should be. What am I missing?

Specification

  1. Add --bytecode flag to solc that outputs the evm.bytecode.object. I'm not sure if it should be prefixed with 0x or not. Truffle expects the prefix and expects no new-lines.
  2. Fix ast missing from JSON output
@chriseth
Copy link
Contributor

chriseth commented Jan 7, 2019

You need an output selector of "" for the ast.

@chriseth
Copy link
Contributor

chriseth commented Jan 7, 2019

Also, the --bytecode flag you are looking for is called --bin.

@BlinkyStitt
Copy link
Author

BlinkyStitt commented Jan 8, 2019 via email

@BlinkyStitt
Copy link
Author

Oh. I think the output is different because the optimizer runs are different!

@BlinkyStitt
Copy link
Author

Prefixing the output of --bin with "0x" made truffle happy. I'll open an issue with them.

Can you explain why an empty looking selector enables the ast? Is that intentional? It should probably be documented since the docs make it look like "ast" will work.

@chriseth
Copy link
Contributor

chriseth commented Jan 8, 2019

We recently clarified that in the documentation: https://solidity.readthedocs.io/en/develop/using-the-compiler.html#input-description

The reason is that the AST is associated with a source file and not a contract within the source file, so you use "fileName": { "": ["ast"]}.

Please tell me if the explanation in the documentation is still insufficient.

@BlinkyStitt
Copy link
Author

BlinkyStitt commented Jan 8, 2019 via email

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

No branches or pull requests

2 participants