Advertisement
Guest User

Untitled

a guest
Jul 1st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. const accounts = 1
  2. const bits = 42
  3.  
  4. function forin (n, exp) {
  5. res = []
  6. for (var i = 0; i < n; i++) {
  7. res.push(exp(n))
  8. }
  9. return res
  10. }
  11.  
  12. const args = [
  13. forin(accounts, (n) => `private field commitment_${n}`).join(', '),
  14. forin(accounts, (n) => `private field[256] amount_${n}`).join(', '),
  15. forin(accounts, (n) => `private field amounts_${n}`).join(', '),
  16. forin(accounts, (n) => `private field[256] blinding_factor_${n}`).join(', '),
  17. `private field[${bits * accounts}] bits`,
  18. `public field total_amount`
  19. ].join(', ')
  20.  
  21. const HexpBits = BigInt('2417296792044260459589534796306265266991365743098572196690216026133643768250').toString(2).padStart(256, '0').split('')
  22.  
  23. const script = `
  24. import "ecc/edwardsAdd.code" as add
  25. import "ecc/edwardsScalarMult.code" as scalarMult
  26. import "ecc/babyjubjubParams.code" as jubjub
  27.  
  28. // ACCOUNTS = ${accounts}
  29. // BITS = ${bits}
  30. def main (${args}) -> (bool):
  31. G = jubjub()
  32. H = scalarMult([${HexpBits.join()}], [G[4], G[5]], G)
  33.  
  34. field sum_amount = 0
  35. field res = 0
  36. ${forin(accounts, (j) => `
  37. commitment_${j} == add(scalarMult(amount_${j}, [G[4], G[5]], G), scalarMult(blinding_factor_${j}, H, G), G)[0]
  38.  
  39. res = 0
  40. for field i in 0..${bits} do
  41. field bit = bits[i + j* ${bits}]
  42. bit * bit == bit
  43. res = res + bit * (2 ** i)
  44. endfor
  45.  
  46. amounts[${j}] == res
  47. sum_amount = sum_amount + res
  48.  
  49. return total_amount == sum_amount
  50. `)}`
  51.  
  52. console.log(script)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement