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

Cannot deploy a `SmartContract` that uses multiple proofs #629

Open emlautarom1 opened 4 months ago

emlautarom1 commented 4 months ago

Describe the bug

All SmartContracts can use ZkPrograms proofs as inputs, and ZkPrograms can use other ZkPrograms proofs as inputs. Currently, it's impossible to deploy a SmartContract that makes use of such dependency tree.

Steps to Reproduce

  1. Create a basic ZkProgram with a single method. We'll call it Foo.
  2. Create a second ZkProgram that has a single method that takes a Foo proof as input. We'll call it Bar.
  3. Create a SmartContract that uses a Bar proof as input.
  4. Configure the deployment of the contract using the zk config command.
  5. Try to deploy the contract using the zk deploy command.

You should get the following stack trace:

✔ Build project
✔ Generate build.json
✔ Choose smart contract
  The 'MySmartContract' smart contract will be used
  for this deploy alias as specified in config.json.
Debugger attached.
✖ Generate verification key (takes 10-30 sec)
  Error: Bar.compile() depends on Foo, but we cannot find compilation output for Foo.
Try to run Foo.compile() first.
Error: Bar.compile() depends on Foo, but we cannot find compilation output for Foo.
Try to run Foo.compile() first.
    at file:///home/emlautarom1/dev/my-zk-app/node_modules/o1js/dist/node/lib/proof-system.js:432:23
    at Array.map (<anonymous>)
    at picklesRuleFromFunction (file:///home/emlautarom1/dev/my-zk-app/node_modules/o1js/dist/node/lib/proof-system.js:425:36)
    at file:///home/emlautarom1/dev/my-zk-app/node_modules/o1js/dist/node/lib/proof-system.js:299:53
    at Array.map (<anonymous>)
    at compileProgram (file:///home/emlautarom1/dev/my-zk-app/node_modules/o1js/dist/node/lib/proof-system.js:299:29)
    at Object.compile (file:///home/emlautarom1/dev/my-zk-app/node_modules/o1js/dist/node/lib/proof-system.js:150:58)
    at generateVerificationKey (file:///home/emlautarom1/.nvm/versions/node/v21.6.1/lib/node_modules/zkapp-cli/src/lib/deploy.js:551:23)
    at async file:///home/emlautarom1/.nvm/versions/node/v21.6.1/lib/node_modules/zkapp-cli/src/lib/deploy.js:274:7
    at async step (file:///home/emlautarom1/.nvm/versions/node/v21.6.1/lib/node_modules/zkapp-cli/src/lib/helpers.js:17:20)
    at async deploy (file:///home/emlautarom1/.nvm/versions/node/v21.6.1/lib/node_modules/zkapp-cli/src/lib/deploy.js:270:41)
    at async Object.handler (file:///home/emlautarom1/.nvm/versions/node/v21.6.1/lib/node_modules/zkapp-cli/src/bin/index.js:130:30)

On https://github.com/o1-labs/zkapp-cli/pull/547 support was added to deploy SmartContracts that use ZkPrograms proofs as inputs but it seems like there was no consideration for dependencies between ZkPrograms during the compilation process.

When testing this smart contract we don't face this issue since we're in control over the compilation order but this is not the case when using the CLI.

System Info

System:
  OS: Linux 6.8 Fedora Linux 39 (Workstation Edition)
  CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
Binaries:
  Node: 21.6.1 - ~/.nvm/versions/node/v21.6.1/bin/node
  Yarn: 1.22.21 - /usr/local/bin/yarn
  npm: 10.2.4 - ~/.nvm/versions/node/v21.6.1/bin/npm
npmPackages:
  o1js: ^0.17.0 => 0.17.0 
npmGlobalPackages:
  zkapp-cli: 0.20.0

Severity

blocking all usage

Additional Information

No response

ymekuria commented 4 months ago

Thanks for all your feedback @emlautarom1. I agree the cli deploy needs to be updated to be flexible enough to handle dependency trees similar to what you mentioned.