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

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

Merged
merged 53 commits into from
Mar 8, 2024

Conversation

ymekuria
Copy link
Collaborator

@ymekuria ymekuria commented Dec 22, 2023

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.

… of the user-specified ZkProgram

The function `findZkProgramFile` is added to the `deploy.js` file. This function takes in two parameters: `buildPath` and `zkProgramName`. It uses a glob pattern to find all files matching the `buildPath` pattern. It then searches for a specific pattern in each file to find the user-specified zkprogram. If a match is found, it returns the file name of the zkprogram.

This function is useful for finding the file name of the zkprogram that needs to be compiled in the deployment process.
…able name assigned to the zkProgram with the matching name argument
… a smart contract that verifies it.

The `deploy` function in `deploy.js` now compiles the specified `zkProgram` that the smart contract verifies before deployment.
… to zkProgramNameArg for clarity and improved semantics
…r each deployed contract

It modifies the deploy function to store the value of the zkProgramNameArg variable in the cache object for each deployed contract. This change allows for easy access to the zkProgramNameArg value when needed.
…o improve performance and reduce redundant computations
…ed by computing its digest and comparing it with the cached digest
@ymekuria ymekuria self-assigned this Jan 9, 2024
…ecessary parameters for generating verification key
…riable from 'res' to 'networkResponse' for clarity
…m build path and project root

The getZkProgram function is added to the deploy.js file. This function is responsible for retrieving the zk program from the specified build path and project root. It takes in the build path, project root, and zk program name as arguments. This function will be used to find the file name of the smart contract to be deployed.
…rogram function

By extracting this logic into a separate function, we improve code readability and maintainability. It also eliminates code duplication, as the same logic was previously duplicated in two places within the `generateVerificationKey` function.
The findZkPrograms function was no longer being used in the deploy.js file. It was responsible for finding the user-specified name for every exported instance of `ZkProgram` in the build directory. Since it was not being used, it was removed to improve code readability and maintainability.
@shimkiv shimkiv self-requested a review March 5, 2024 10:44
Copy link
Member

@shimkiv shimkiv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not able to deploy one used in target issue #377.

src/lib/deploy.js Outdated Show resolved Hide resolved
src/lib/deploy.js Show resolved Hide resolved
@ymekuria ymekuria merged commit 87a1c99 into main Mar 8, 2024
12 checks passed
@ymekuria ymekuria deleted the feature/deploy-zkprogram branch March 8, 2024 01:12
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

Successfully merging this pull request may close these issues.

Make deploy work for smart contracts that depend on a ZkProgram
2 participants