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

Remove circomlibjs dependency in favor of zk-kit #1911

Merged
merged 9 commits into from
Oct 1, 2024
Merged

Conversation

artwyman
Copy link
Member

@artwyman artwyman commented Oct 1, 2024

Minimalist approach to switching away from circomlibjs in order to eliminate its massive poseidon_constants from our bundle size. This drops the bundle size in my measurements from 9.4MB to 6.4MB.

Functionality remains unchanged (validated by pre-existing backward compatibility tests), with one known exception. The EdDSA PCD now only supports "messages" (bigint arrays) of sizes in the set {1, 2, 3, 12, 13}. Other sizes will throw an error at proving time. This is because poseidon-lite also has a set of constants (albeit much smaller than circomlibjs) needed for each size. There are comments in the code explaining why each size was selected.

Two things explicitly not done, given the minimalist approach:

  • This PR doesn't attempt to unify/centralize uses of zk-kit/poseidon-lite into a single package. Instead the old EdDSA PCDs use the appropriate zk-kit/poseidon-lite libraries directly.
  • This PR also doesn't change the format (in code, or in serialization) of EdDSA keys to match the new form used by PODs. All externally-visible formats are kept unchanged.

@@ -19,6 +19,23 @@
"port": 4321,
"restart": true,
"cwd": "${workspaceRoot}"
},
{
Copy link
Member Author

Choose a reason for hiding this comment

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

Borrowed this from #1790.
It doesn't work for all utests (it depends on the path depth between the test file and package.json) but it works on many of them, and it's only useful if it's in the repo, so I think it's worth merging.

@artwyman artwyman changed the title [WIP] Remove circomlibjs dependency in favor of zk-kit Remove circomlibjs dependency in favor of zk-kit Oct 1, 2024
@artwyman artwyman requested a review from robknight October 1, 2024 03:38
@artwyman artwyman marked this pull request as ready for review October 1, 2024 03:38
@artwyman artwyman self-assigned this Oct 1, 2024
@artwyman
Copy link
Member Author

artwyman commented Oct 1, 2024

Note that there is still a devDependency on circomlibjs in @pcd/pod's unit tests, for the set of compatibility tests which validates that zk-kit and circomlibjs remain compatible with each other. I think it's good that these remain so we don't accidentally introduce any incompatibilities, and so we have the option to switch back should we ever decide it's worth it (e.g. for higher performance).

@robknight
Copy link
Member

Looks good to me! The bundle size impact will be great for new users.

@artwyman artwyman added this pull request to the merge queue Oct 1, 2024
Merged via the queue into main with commit ff6793c Oct 1, 2024
1 check passed
@artwyman artwyman deleted the artwman/circomlibjs branch October 1, 2024 19:13
rrrliu pushed a commit that referenced this pull request Oct 8, 2024
Minimalist approach to switching away from circomlibjs in order to
eliminate its massive poseidon_constants from our bundle size. This
drops the bundle size in my measurements from 9.4MB to 6.4MB.

Functionality remains unchanged (validated by pre-existing backward
compatibility tests), with one known exception. The EdDSA PCD now only
supports "messages" (bigint arrays) of sizes in the set {1, 2, 3, 12,
13}. Other sizes will throw an error at proving time. This is because
poseidon-lite also has a set of constants (albeit much smaller than
circomlibjs) needed for each size. There are comments in the code
explaining why each size was selected.

Two things explicitly not done, given the minimalist approach:

- This PR doesn't attempt to unify/centralize uses of
zk-kit/poseidon-lite into a single package. Instead the old EdDSA PCDs
use the appropriate zk-kit/poseidon-lite libraries directly.
- This PR also doesn't change the format (in code, or in serialization)
of EdDSA keys to match the new form used by PODs. All externally-visible
formats are kept unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants