hermez-node/db/statedb/utils.go
db/statedb/utils.goRaw
1package statedb
2
3import (
4 "math/big"
5
6 ethCommon "github.com/ethereum/go-ethereum/common"
7 "github.com/hermeznetwork/hermez-node/common"
8 "github.com/iden3/go-iden3-crypto/babyjub"
9 "github.com/iden3/go-merkletree"
10)
11
12// TODO
13func (s *StateDB) getIdxByEthAddr(addr ethCommon.Address) common.Idx {
14 return common.Idx(0)
15}
16
17// TODO
18func (s *StateDB) getIdxByBJJ(pk *babyjub.PublicKey) common.Idx {
19 return common.Idx(0)
20}
21
22func siblingsToZKInputFormat(s []*merkletree.Hash) []*big.Int {
23 b := make([]*big.Int, len(s))
24 for i := 0; i < len(s); i++ {
25 b[i] = s[i].BigInt()
26 }
27 return b
28}
29
30// BJJCompressedTo256BigInts returns a [256]*big.Int array with the bit
31// representation of the babyjub.PublicKeyComp
32func BJJCompressedTo256BigInts(pkComp babyjub.PublicKeyComp) [256]*big.Int {
33 var r [256]*big.Int
34 b := pkComp[:]
35
36 for i := 0; i < 256; i++ {
37 if b[i/8]&(1<<(i%8)) == 0 {
38 r[i] = big.NewInt(0)
39 } else {
40 r[i] = big.NewInt(1)
41 }
42 }
43
44 return r
45}