signal.zk 995 B

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