mint.pism 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # :set syntax=pism
  2. # :source ../scripts/pism.vim
  3. constant G_VCV FixedGenerator
  4. constant G_VCR FixedGenerator
  5. constant CRH_IVK BlakePersonalization
  6. #constant JUBJUB_FR_CAPACITY BinarySize
  7. #constant NOTE_COMMIT PedersenPersonalization
  8. contract mint_contract
  9. # Value commitment
  10. param value U64
  11. param randomness_value Fr
  12. param serial Fr
  13. param randomness_coin Fr
  14. param public Point
  15. start
  16. # Witness input values
  17. u64_as_binary_le value param:value
  18. fr_as_binary_le randomness_value param:randomness_value
  19. fr_as_binary_le serial param:serial
  20. fr_as_binary_le randomness_coin param:randomness_coin
  21. witness public param:public
  22. assert_not_small_order public
  23. # Make value commitment
  24. # V = v * G_VCV + r * G_VCR
  25. ec_mul_const vcv value G_VCV
  26. ec_mul_const rcv randomness_value G_VCR
  27. ec_add cv vcv rcv
  28. # emit cv
  29. emit_ec cv
  30. # Make the coin
  31. # C = Hash(public_key, value, serial, randomness_coin)
  32. # Build the preimage to hash
  33. alloc_binary preimage
  34. # public_key
  35. ec_repr repr_public public
  36. binary_extend preimage repr_public
  37. # value
  38. binary_extend preimage value
  39. # Fr values are 252 bits so we need to pad it with extra 0s
  40. # to match the Rust values which are 256 bits
  41. {% macro binary_put_fr(binary, var) -%}
  42. binary_extend {{ binary }} {{ var }}
  43. {% for n in range(4) %}
  44. alloc_const_bit zero_bit false
  45. binary_push {{ binary }} zero_bit
  46. {% endfor %}
  47. {%- endmacro %}
  48. # serial
  49. {{ binary_put_fr("preimage", "serial") }}
  50. # randomness_coin
  51. {{ binary_put_fr("preimage", "randomness_coin") }}
  52. # Public key: SubgroupPoint = 256 bits
  53. # Value: u64 = 64 bits
  54. # Serial: Fr = 252 + 4 bits padding
  55. # Randomness coin Fr = 252 + 4 bits padding
  56. # TOTAL: 832 bits for preimage
  57. static_assert_binary_size preimage 832
  58. blake2s coin preimage CRH_IVK
  59. emit_binary coin
  60. end