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
2.7 KiB

1 year ago
1 year ago
  1. # protogalaxy-poc
  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, 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. witnesses.push(witness_i);
  37. instances.push(instance_i);
  38. }
  39. // set the initial random betas
  40. let beta = Fr::rand(&mut rng);
  41. let betas = powers_of_beta(beta, t);
  42. // Prover folds the instances and witnesses
  43. let (F_coeffs, K_coeffs, folded_instance, folded_witness) = Folding::<G1Projective>::prover(
  44. &mut transcript_p,
  45. &r1cs,
  46. instance.clone(),
  47. witness,
  48. instances.clone(),
  49. witnesses,
  50. );
  51. // verifier folds the instances
  52. let folded_instance_v = Folding::<G1Projective>::verifier(
  53. &mut transcript_v,
  54. &r1cs,
  55. instance,
  56. instances,
  57. F_coeffs,
  58. K_coeffs,
  59. );
  60. // check that the folded instance satisfies the relation
  61. assert!(check_instance(&r2cs, folded_instance, folded_witness));
  62. ```
  63. (see the actual code for more details)