o1-labs / zkapp-cli

CLI to create a zkApp (zero-knowledge app) for Mina Protocol
https://docs.minaprotocol.com/zkapps/how-to-write-a-zkapp
Apache License 2.0
114 stars 43 forks source link

Add support to deploy smart contracts that verify ZkProgram proofs #547

Closed ymekuria closed 6 months ago

ymekuria commented 9 months ago

Description

This PR adds the functionality to the zkApp-CLI to enable a user to deploy smart contracts that verify ZkProgram proofs. Previously during the deploy flow, the zkApp-CLI would compile the smart contract to be deployed, but was not able to detect and compile any ZkPrograms who's proofs are verified in the Smart contract.

zk deploy berkeley
✔ Build project
✔ Generate build.json
✔ Choose smart contract
  The 'GameOfLife' smart contract will be used
  for this deploy alias as specified in config.json.
✖ Generate verification key (takes 10-30 sec)
  Error: GameOfLife.compile() depends on Program0, but we cannot find compilation output for Program0.
Try to run Program0.compile() first.

This issue blocked all users from deploying Smart contracts that verify ZkProgram proofs the zkApp-CLI. This feature has been increasingly requested by many people in the community as ZkProgram usage has increased, and will unlock the ability to more rapidly build and iterate with Zkprogram's.

Solution

The CLI can now detect if a smart contract verifies a ZkProgram proof, and compiles the necessary ZkProgram. Additionaly,ZkProgram compile caching was added so the CLI only compiles when necessary, improving the deploy speed and overall DX. This was accomplished by computing the ZkProgram digest and adding it to the cache to determine when it is necessary to recompile. Computing the digest is much less expensive and time consuming than compiling the ZkProgram.

Closes #377

Testing

The improvements introduced in this PR have been by tested by generating and deploying smart contracts that verify ZkProgram proofs zkapp-CLI and running the full e2e testing suite.