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

Implement circomlib-mpc 0.1 #14

Open
brech1 opened this issue Jan 11, 2024 · 9 comments
Open

Implement circomlib-mpc 0.1 #14

brech1 opened this issue Jan 11, 2024 · 9 comments
Assignees
Milestone

Comments

@brech1
Copy link
Collaborator

brech1 commented Jan 11, 2024

Implement our version of circomlib in order to support basic functions.

This is needed due to circomlib being done to work with R1CS, not working for execution.

@namnc
Copy link
Owner

namnc commented Mar 24, 2024

circomlib has not been updated for 2 years, we can keep it as a submodule here and work on circomlib-mpc

@brech1 brech1 self-assigned this Apr 1, 2024
@brech1 brech1 removed their assignment Apr 12, 2024
@brech1
Copy link
Collaborator Author

brech1 commented Apr 12, 2024

@namnc namnc self-assigned this May 8, 2024
@namnc namnc removed the Release 0.1 label May 8, 2024
@namnc namnc added this to the Release 0.1 milestone May 8, 2024
@voltrevo
Copy link
Collaborator

I'd love to get more into circom and help out with this issue. Can we put a list together of what "basic functions" we'd like to accomplish for this issue?

@namnc
Copy link
Owner

namnc commented May 17, 2024

Sure, here's the thing. Within circomlib we can categorize the templates into 2 types: crypto and non crypto. Crypto = template for cryptographic primitives such as ECDSA or Poseidon. Non-crypto = template for scalar-based primitives such as comparators, sign, switcher.

For crypto type we have to wait for typing as we need to describe the computation in mod p. For non-crypto type we can divide the templates into two sub-categories as well: binary-based and arithmetic-based. Again the binary-based type we have to wait to typing as we need to describe the computation in mod 2. I think what is left for 0.1 is the arithmetic-based templates that are:
0. I think these need no change at all: mux1.circom ... mux4.circom and switcher.circom.

  1. The following is a bit tricky https://github.com/iden3/circomlib/blob/cff5ab6288b55ef23602221694a6a38a0239dcc0/circuits/comparators.circom

As we support equality check and also comparison in our interpreter, i.e. we just add a gate for the ==, <, >, <=, >= we can just scrap all of the comparators templates. If one write a new circom program for MPC then they can just use the ops directly.

The whole point of this issue is to allow one to run MPC with a circom program that was written for zk using the templates above (with the bit decomposition thingy). This issue presents two challenges:

  • bit decomposition requires binary typing (0.2)
  • comparator templates describe a low level method of doing comparison using binary representation of a number, we ideally want this to be done with our "translator"/"optimizer" from a circom-gate (front-end, intuitive such as LT, GT, EQ, etc. and back-end agnostic) to a native-gate supported by back-end (e.g. only NOT, XOR and AND), which means the comparator templates might not make use of the best of the back-end (e.g. EQ, LT, etc. are native in MP-SPDZ).

I don't know (if there is and what is) a clean way to solve this.

@voltrevo ^^^

@namnc
Copy link
Owner

namnc commented May 17, 2024

I think we can push the tricky part to 0.2 (with typing so everything is natural).

@namnc
Copy link
Owner

namnc commented May 17, 2024

This could be related, ZK vs MPC for division.
Say we want to do a divided by b (a >= b)
In MPC we just write q <== a \ b
in ZK we write q <-- a \ b; r <-- a - b * q; a === b * q + r

My idea would be to wrap this in a template says template divide() with input a, b and provide a ZK and an MPC version and the interpreter should find the correct file to point to:
For MPC we can have q and potentially r as an output (so we need also r <== a % b)
For ZK we can have q as input and r as input and then do as above.

e.g.
ZK version: https://github.com/socathie/circomlib-ml/blob/c82b3072d7946a76487a8c1be463fc407045391c/circuits/Dense.circom#L24
MPC version: https://github.com/namnc/circomlib-ml-patches/blob/master/circuits/Dense.circom.patch

@brech1
Copy link
Collaborator Author

brech1 commented May 27, 2024

So should we perhaps split this issue or keep this one for the 0.1 release (with @voltrevo assigned) and then create a new one for later versions?

@namnc
Copy link
Owner

namnc commented May 27, 2024

Makes sense, once we have the good integration this should proceed faster.

@namnc namnc changed the title Implement circomlib-mpc Implement circomlib-mpc 0.1 May 28, 2024
@namnc
Copy link
Owner

namnc commented May 28, 2024

Changed to ciromlib-mpc 0.1

@namnc namnc assigned voltrevo and unassigned namnc Jun 3, 2024
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

No branches or pull requests

3 participants