signal.zk 1003 B

12345678910111213141516171819202122232425262728293031323334353637
  1. k = 13;
  2. constant "RlnSignal" {}
  3. witness "RlnSignal" {
  4. Base secret_key,
  5. MerklePath identity_path,
  6. Uint32 identity_leaf_pos,
  7. # These are public so have to be properly constructed
  8. Base message_hash, # x
  9. Base epoch,
  10. Base rln_identifier,
  11. }
  12. circuit "RlnSignal" {
  13. constrain_instance(epoch);
  14. constrain_instance(rln_identifier);
  15. constrain_instance(message_hash);
  16. # This has to be the same constant used outside
  17. identity_derivation_path = witness_base(11);
  18. nullifier_derivation_path = witness_base(12);
  19. identity_commit = poseidon_hash(identity_derivation_path, secret_key);
  20. root = merkle_root(identity_leaf_pos, identity_path, identity_commit);
  21. constrain_instance(root);
  22. external_nullifier = poseidon_hash(epoch, rln_identifier);
  23. a_1 = poseidon_hash(secret_key, external_nullifier);
  24. internal_nullifier = poseidon_hash(nullifier_derivation_path, a_1);
  25. constrain_instance(internal_nullifier);
  26. y_a = base_mul(a_1, message_hash);
  27. y = base_add(y_a, secret_key);
  28. constrain_instance(y);
  29. }