set_v1.zk 2.2 KB

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