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.

59 lines
1.7 KiB

  1. package statedb
  2. import (
  3. "math/big"
  4. ethCommon "github.com/ethereum/go-ethereum/common"
  5. "github.com/hermeznetwork/hermez-node/common"
  6. "github.com/iden3/go-iden3-crypto/babyjub"
  7. "github.com/iden3/go-merkletree"
  8. )
  9. // GetIdxByEthAddr returns the smallest Idx in the StateDB for the given
  10. // Ethereum Address. Will return 0 in case that Idx is not found in the
  11. // StateDB.
  12. func (s *StateDB) GetIdxByEthAddr(addr ethCommon.Address) common.Idx {
  13. // TODO
  14. return common.Idx(0)
  15. }
  16. // GetIdxByBJJ returns the smallest Idx in the StateDB for the given BabyJubJub
  17. // PublicKey. Will return 0 in case that Idx is not found in the StateDB.
  18. func (s *StateDB) GetIdxByBJJ(pk *babyjub.PublicKey) common.Idx {
  19. // TODO
  20. return common.Idx(0)
  21. }
  22. // GetIdxByEthAddrBJJ returns the smallest Idx in the StateDB for the given
  23. // Ethereum Address AND the given BabyJubJub PublicKey. If `addr` is the zero
  24. // address, it's ignored in the query. If `pk` is nil, it's ignored in the
  25. // query. Will return 0 in case that Idx is not found in the StateDB.
  26. func (s *StateDB) GetIdxByEthAddrBJJ(addr ethCommon.Address, pk *babyjub.PublicKey) common.Idx {
  27. // TODO
  28. return common.Idx(0)
  29. }
  30. func siblingsToZKInputFormat(s []*merkletree.Hash) []*big.Int {
  31. b := make([]*big.Int, len(s))
  32. for i := 0; i < len(s); i++ {
  33. b[i] = s[i].BigInt()
  34. }
  35. return b
  36. }
  37. // BJJCompressedTo256BigInts returns a [256]*big.Int array with the bit
  38. // representation of the babyjub.PublicKeyComp
  39. func BJJCompressedTo256BigInts(pkComp babyjub.PublicKeyComp) [256]*big.Int {
  40. var r [256]*big.Int
  41. b := pkComp[:]
  42. for i := 0; i < 256; i++ {
  43. if b[i/8]&(1<<(i%8)) == 0 {
  44. r[i] = big.NewInt(0)
  45. } else {
  46. r[i] = big.NewInt(1)
  47. }
  48. }
  49. return r
  50. }