set_v1.zk 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Intro:
  2. #
  3. # This is the source of ZK circuit.
  4. # It has 3 sections: constant, witness and circuit.
  5. # constant and witness describe the data the ZK statements are constraining.
  6. # 2 ** k is the maximum nubmer of rows in the circuit.
  7. k = 11;
  8. field = "pallas";
  9. # Section to declare constants used in the circuit.
  10. # "Set_V1" is the namepsace of circuit.
  11. # It is the namespace for storing verifying key onchain.
  12. constant "Set_V1" {}
  13. # Witness is the inputs to the circuit, both public and private.
  14. witness "Set_V1" {
  15. # An instance of `Base` is a field element, which is a member of
  16. # the finite field F_p where
  17. # p = 0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001
  18. #
  19. # Private input a user generates locally.
  20. Base secret,
  21. # Whether to lock the name.
  22. Base lock,
  23. # Whether to set in the canonical root name registry.
  24. Base root,
  25. # The name.
  26. Base key,
  27. # The value the name resolves to or
  28. # the next sub name registry (i.e. an account).
  29. Base value,
  30. }
  31. circuit "Set_V1" {
  32. # var = statement(var_or_witness1, var_or_witness2, ...);
  33. account = poseidon_hash(secret);
  34. # `constrain_instance` requires the value be provided as public input.
  35. constrain_instance(account);
  36. constrain_instance(lock);
  37. constrain_instance(root);
  38. constrain_instance(key);
  39. constrain_instance(value);
  40. # Check whether `lock` and `root` are of {0, 1}.
  41. bool_check(lock);
  42. bool_check(root);
  43. }
  44. # The mental model for what this circuit does.
  45. #
  46. # # Prove
  47. #
  48. # The prove API is essentially: prove(proving_key, witness) -> proof
  49. #
  50. # The prover provides the circuit, and generates the proving key. The proving key essentially
  51. # encodes the circuit but does not include information for the witness, so it is
  52. # the same across different witnesses (and therefore proofs) but unique per circuit.
  53. #
  54. # # Verify
  55. #
  56. # The verifying API is essentially: verify(verifying_key, proof, public_inputs) -> {T, F}
  57. #
  58. # The verifier provides the circuit, and generates the verifying key. The verifying key similarly
  59. # encodes only the circuit, and not the public inputs or the proof. The verifying key is the same
  60. # across different proofs but unique per circuit.
  61. #
  62. # For more info, you can try this zk intro:
  63. # https:#learn.0xparc.org/materials/circom/learning-group-1/circom-1