You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

  1. package txprocessor
  2. import (
  3. "math/big"
  4. "github.com/hermeznetwork/hermez-node/common"
  5. "github.com/iden3/go-iden3-crypto/babyjub"
  6. "github.com/iden3/go-merkletree"
  7. )
  8. func siblingsToZKInputFormat(s []*merkletree.Hash) []*big.Int {
  9. b := make([]*big.Int, len(s))
  10. for i := 0; i < len(s); i++ {
  11. b[i] = s[i].BigInt()
  12. }
  13. return b
  14. }
  15. // BJJCompressedTo256BigInts returns a [256]*big.Int array with the bit
  16. // representation of the babyjub.PublicKeyComp
  17. func BJJCompressedTo256BigInts(pkComp babyjub.PublicKeyComp) [256]*big.Int {
  18. var r [256]*big.Int
  19. b := pkComp[:]
  20. for i := 0; i < 256; i++ {
  21. if b[i/8]&(1<<(i%8)) == 0 {
  22. r[i] = big.NewInt(0)
  23. } else {
  24. r[i] = big.NewInt(1)
  25. }
  26. }
  27. return r
  28. }
  29. // formatAccumulatedFees returns an array of [nFeeAccounts]*big.Int containing
  30. // the balance of each FeeAccount, taken from the 'collectedFees' map, in the
  31. // order of the 'orderTokenIDs'
  32. func formatAccumulatedFees(collectedFees map[common.TokenID]*big.Int, orderTokenIDs []*big.Int) []*big.Int {
  33. accFeeOut := make([]*big.Int, len(orderTokenIDs))
  34. for i := 0; i < len(orderTokenIDs); i++ {
  35. tokenID := common.TokenIDFromBigInt(orderTokenIDs[i])
  36. if _, ok := collectedFees[tokenID]; ok {
  37. accFeeOut[i] = new(big.Int).Set(collectedFees[tokenID])
  38. } else {
  39. accFeeOut[i] = big.NewInt(0)
  40. }
  41. }
  42. return accFeeOut
  43. }