signal.zk 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. k = 14;
  2. field = "pallas";
  3. constant "Rlnv2Diff_Signal" {}
  4. witness "Rlnv2Diff_Signal" {
  5. Base identity_nullifier,
  6. Base identity_trapdoor,
  7. Base user_message_limit,
  8. # Inclusion proof, the leaf is the identity_commitment
  9. SparseMerklePath path,
  10. # The message hash
  11. Base x,
  12. Base message_id,
  13. Base epoch,
  14. }
  15. circuit "Rlnv2Diff_Signal" {
  16. # Identity inclusion proof
  17. identity_secret = poseidon_hash(identity_nullifier, identity_trapdoor);
  18. identity_secret_hash = poseidon_hash(identity_secret, user_message_limit);
  19. identity_commitment = poseidon_hash(identity_secret_hash);
  20. root = sparse_merkle_root(identity_commitment, path, identity_commitment);
  21. constrain_instance(root);
  22. # External nullifier is created from epoch and app identifier
  23. app_id = witness_base(1000);
  24. external_nullifier = poseidon_hash(epoch, app_id);
  25. constrain_instance(external_nullifier);
  26. # Calculating internal nullifier
  27. # a_0 = identity_secret_hash
  28. a_0 = poseidon_hash(identity_nullifier, identity_trapdoor);
  29. a_1 = poseidon_hash(a_0, external_nullifier, message_id);
  30. x_a_1 = base_mul(x, a_1);
  31. y = base_add(a_0, x_a_1);
  32. constrain_instance(x);
  33. constrain_instance(y);
  34. # Constrain message_id to be lower than actual message limit.
  35. less_than_strict(message_id, user_message_limit);
  36. internal_nullifier = poseidon_hash(a_1);
  37. constrain_instance(internal_nullifier);
  38. }