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.

52 lines
1.4 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 { //nolint:gomnd
  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,
  33. coordIdxs []common.Idx) []*big.Int {
  34. accFeeOut := make([]*big.Int, len(orderTokenIDs))
  35. for i := 0; i < len(accFeeOut); i++ {
  36. accFeeOut[i] = big.NewInt(0)
  37. }
  38. for i := 0; i < len(coordIdxs); i++ {
  39. tokenID := common.TokenIDFromBigInt(orderTokenIDs[i])
  40. if _, ok := collectedFees[tokenID]; ok {
  41. accFeeOut[i] = new(big.Int).Set(collectedFees[tokenID])
  42. }
  43. }
  44. return accFeeOut
  45. }