stake_v1.zk 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. k = 13;
  2. field = "pallas";
  3. constant "RLN_Stake_V1" {
  4. EcFixedPointBase NULLIFIER_K,
  5. }
  6. witness "RLN_Stake_V1" {
  7. # The RLN identity nullifier
  8. Base identity_nullifier,
  9. # The RLN identity trapdoor
  10. Base identity_trapdoor,
  11. # The staked coin value
  12. Base stake_value,
  13. # The staked coin token ID
  14. Base stake_token_id,
  15. # The staked coin spend hook
  16. Base stake_spend_hook,
  17. # The staked coin user data
  18. Base stake_user_data,
  19. # Unique serial number corresponding to the staked coin
  20. Base stake_blind,
  21. }
  22. circuit "RLN_Stake_V1" {
  23. # Derive the public key for the coin
  24. identity_secret = poseidon_hash(identity_nullifier, identity_trapdoor);
  25. identity_stake_public = ec_mul_base(identity_secret, NULLIFIER_K);
  26. # Derive and constrain the identity commitment
  27. identity_commitment = poseidon_hash(identity_secret);
  28. constrain_instance(identity_commitment);
  29. # Construct and reveal the staked coin.
  30. # This must be the same coin in the corresponding Money output.
  31. # We reveal everything except the derived `identity_stake_public`.
  32. C = poseidon_hash(
  33. ec_get_x(identity_stake_public),
  34. ec_get_y(identity_stake_public),
  35. stake_value,
  36. stake_token_id,
  37. stake_spend_hook,
  38. stake_user_data,
  39. stake_blind,
  40. );
  41. constrain_instance(C);
  42. # Reveal the staked value
  43. constrain_instance(stake_value);
  44. # Reveal the token ID
  45. constrain_instance(stake_token_id);
  46. # Reveal the spend_hook
  47. constrain_instance(stake_spend_hook);
  48. # Reveal the user_data
  49. constrain_instance(stake_user_data);
  50. # Reveal the coin blind
  51. constrain_instance(stake_blind);
  52. }