You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
3.0 KiB

1 year ago
1 year ago
1 year ago
  1. # protogalaxy-poc [![Test](https://github.com/arnaucube/protogalaxy-poc/workflows/Test/badge.svg)](https://github.com/arnaucube/protogalaxy-poc/actions?query=workflow%3ATest)
  2. Proof of concept implementation of ProtoGalaxy (https://eprint.iacr.org/2023/1106.pdf) using [arkworks](https://github.com/arkworks-rs).
  3. > Do not use in production.
  4. Thanks to [Liam Eagen](https://twitter.com/LiamEagen) and [Ariel Gabizon](https://twitter.com/rel_zeta_tech) for their kind explanations.
  5. This code has been done in the context of the research on folding schemes in [0xPARC](https://0xparc.org).
  6. ![protogalaxy img from Wikipedia](https://upload.wikimedia.org/wikipedia/commons/thumb/4/49/Stellar_Fireworks_Finale.jpg/303px-Stellar_Fireworks_Finale.jpg)
  7. (img: protogalaxies colliding, [from Wikipedia](https://en.wikipedia.org/wiki/File:Stellar_Fireworks_Finale.jpg))
  8. ## Details
  9. Implementation of ProtoGalaxy's scheme described in section 4 of the paper.
  10. Current version implements the folding on prover & verifier and it works for k-to-1 instances and with multiple iterations, but it is not optimized.
  11. Next steps in terms of implementation include: F(X) O(n) construction following Claim 4.4, compute K(X) in O(kd log(kd)M + ndkC) as described in Claim 4.5, add tests folding in multiple iterations and also in a tree approach, add the decider and integrate with some existing R1CS tooling for the R1CS & witness generation.
  12. ### Usage
  13. Example of folding k+1 instances:
  14. ```rust
  15. // assume we have:
  16. // an R1CS instance 'r1cs'
  17. // a valid witness 'w' from our running instance
  18. // k valid 'witnesses' to be fold
  19. // compute the committed instance for our running witness
  20. let phi = Pedersen::<G1Projective>::commit(&pedersen_params, &witness.w, &witness.r_w);
  21. let instance = CommittedInstance::<G1Projective> {
  22. phi,
  23. betas: betas.clone(),
  24. e: Fr::zero(),
  25. };
  26. // compute the k committed instances to be fold
  27. let mut instances: Vec<CommittedInstance<G1Projective>> = Vec::new();
  28. for i in 0..k {
  29. let phi_i =
  30. Pedersen::<G1Projective>::commit(&pedersen_params, &witnesses[i].w, &witnesses[i].r_w);
  31. let instance_i = CommittedInstance::<G1Projective> {
  32. phi: phi_i,
  33. betas: betas.clone(),
  34. e: Fr::zero(),
  35. };
  36. instances.push(instance_i);
  37. }
  38. // set the initial random betas
  39. let beta = Fr::rand(&mut rng);
  40. let betas = powers_of_beta(beta, t);
  41. // Prover folds the instances and witnesses
  42. let (F_coeffs, K_coeffs, folded_instance, folded_witness) = Folding::<G1Projective>::prover(
  43. &mut transcript_p,
  44. &r1cs,
  45. instance.clone(),
  46. witness,
  47. instances.clone(),
  48. witnesses,
  49. );
  50. // verifier folds the instances
  51. let folded_instance_v = Folding::<G1Projective>::verifier(
  52. &mut transcript_v,
  53. &r1cs,
  54. instance,
  55. instances,
  56. F_coeffs,
  57. K_coeffs,
  58. );
  59. // check that the folded instance satisfies the relation
  60. assert!(check_instance(&r2cs, folded_instance, folded_witness));
  61. // now, the folded instance & witness can be folded again with n other instances.
  62. ```
  63. (see the actual code for more details)