provable-things / ethereum-api

Provable API for Ethereum smart contracts
https://docs.provable.xyz/#ethereum
MIT License
801 stars 427 forks source link

Compiling provableAPI.sol with Truffle yields 43 MB of JSON #95

Open zippoxer opened 5 years ago

zippoxer commented 5 years ago

Issue

Compiling provableAPI.sol yields 43 MB of JSON (6 files weighing ~7mb each).

Implications

For those of us who love Ganache, those huge JSON files cause Ganache UI to freeze as it tries to parse the compiled contracts, making it completely unusable.

I really want to work with Provable, but I can't ;-(

Reproduce

  1. Unbox truffle-starter
  2. Run truffle compile
  3. See these 6 fat JSON files in the build/contracts directory:
7.2M    build/contracts/Buffer.json
7.2M    build/contracts/CBOR.json
7.2M    build/contracts/OracleAddrResolverI.json
7.2M    build/contracts/ProvableI.json
7.2M    build/contracts/solcChecker.json
7.2M    build/contracts/usingProvable.json

This bloat can be attributed to the AST and legacyAST attributes, which contain the same 7 million bytes in each of the 6 JSON files.

My Environment

Note: Successfully reproduced in WSL (Ubuntu).


Is there another way to compile the Provable contract without getting this bloat?

D-Nice commented 5 years ago

Thanks for this report. We generally had used ganache cli / truffle so this was never an apparent issue to us. We'll probably have to discuss with the team working on the ganache UI if this is something they can rectify, as I don't know the likelihood of us being able to compress parts in the API without providing something akin to a lightweight version of it.

cliffhall commented 5 years ago

Verified with truffle on Mac that it does generate all those fat ABIs. However you only deploy usingProvable.sol and your own contracts AFAIK.

Example:

const contracts = [
  artifacts.require('./EthPrice.sol'),
  artifacts.require('./usingProvable')
]

module.exports = deployer =>
  contracts.map(contract =>
    deployer.deploy(contract))

Still it's monster. It would be, IMHO, better to split the functionality up like Open Zeppelin so that a person can pick and choose the bits they need and not have to deploy (and pay gas for) that monolithic contract.

gskapka commented 5 years ago

Compiling provableAPI.sol yields 43 MB of JSON (6 files weighing ~7mb each). those huge JSON files cause Ganache UI to freeze

@zippoxer These are Truffle Artifacts and are something over which we have no control. The awesome guys over at Truffle are aware of this issue and are working on it. You can track it via this issue here.

 


 

that monolithic contract.

@cliffhall Whilst the provableAPI.sol may indeed appear large, notice that the vast majority of it are function overloads of the myriad query types. Notice too that said vast majority are private functions, which means only those functions you inherit in your own contract get compiled. This means that you're deploying only what your contract uses.

cliffhall commented 5 years ago

@gskapka Thanks for the speedy response. I verified that it's not actually necessary to deploy the usingProvable contract as is done in the TruffleStarter demo. And in that case, the EthPrice.json abi is only 109kb. So it seems we can safely disregard these ABI artifacts.

zippoxer commented 5 years ago

@cliffhall IIRC even if you don't deploy it, you import it in EthPrice.json, so those heavy artifacts are still in the build/contracts directory, which cripples Ganache. Is it not your experience?

cliffhall commented 5 years ago

@zippoxer EthPrice.json is only 109kb. The artifacts are generated, true, but you could probably make a watcher process that deletes them with gulp or something if you're concerned about that. I was only concerned that I didn't have to actually deploy (and pay gas for) a 7MB contract :)

But no, it doesn't cause ganache any worries, because the artifacts are never deployed. EthPrice.json actually has all the stuff in it from the library that it uses.