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 find proofs used inside `SmartContract` when `name` is between `"` #628

Closed emlautarom1 closed 3 months ago

emlautarom1 commented 4 months ago

Describe the bug

If a SmartContract uses a proof generated by a ZkProgram it is possible for zk deploy to fail to find the ZkProgram.

Steps to Reproduce

  1. Create a ZkProgram in the top level (ex. src/my-zk-program.ts). Ensure that the program uses " (double quotes) for its name (ex. const MyZkProgram = ZkProgram({ name: "MyZkProgram", ...)
  2. Create a SmartContract that uses a proof generated by ZkProgram as input.
  3. Configure the deployment of the contract using the zk config command.
  4. 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.
✖ Generate verification key (takes 10-30 sec)
  TypeError: Cannot destructure property 'zkProgramFile' of '(intermediate value)' as it is undefined.
TypeError: Cannot destructure property 'zkProgramFile' of '(intermediate value)' as it is undefined.
    at getZkProgram (file:///home/emlautarom1/.nvm/versions/node/v21.6.1/lib/node_modules/zkapp-cli/src/lib/deploy.js:756:9)
    at async generateVerificationKey (file:///home/emlautarom1/.nvm/versions/node/v21.6.1/lib/node_modules/zkapp-cli/src/lib/deploy.js:549:19)
    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)

The issue lies in the following line:

https://github.com/o1-labs/zkapp-cli/blob/c166e4a46430d89ec96af6ff496188054a7a2d61/src/lib/deploy.js#L730-L734

The regex used to find the proof is incomplete, only finding ZkPrograms where the name is between ' (single quotes) and not between " (double quotes).

I believe it's a terrible approach to try to do this regular expressions but if done like that then the regex should at least be flexible enough to accept all valid quotes in JavaScript, that is ', " and ` (single, double and backtick).

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

annoyance

Additional Information

The hard part was figuring out that this was the error. As a workaround, change the name property in the ZkProgram to use ' instead.

ymekuria commented 4 months ago

Thanks for posting the issue. We will take a look.