arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
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// GetIdxByEthAddr returns the smallest Idx in the StateDB for the given
13// Ethereum Address. Will return 0 in case that Idx is not found in the
14// StateDB.
15func (s *StateDB) GetIdxByEthAddr(addr ethCommon.Address) common.Idx {
16	// TODO
17	return common.Idx(0)
18}
19
20// GetIdxByBJJ returns the smallest Idx in the StateDB for the given BabyJubJub
21// PublicKey. Will return 0 in case that Idx is not found in the StateDB.
22func (s *StateDB) GetIdxByBJJ(pk *babyjub.PublicKey) common.Idx {
23	// TODO
24	return common.Idx(0)
25}
26
27// GetIdxByEthAddrBJJ returns the smallest Idx in the StateDB for the given
28// Ethereum Address AND the given BabyJubJub PublicKey. If `addr` is the zero
29// address, it's ignored in the query.  If `pk` is nil, it's ignored in the
30// query.  Will return 0 in case that Idx is not found in the StateDB.
31func (s *StateDB) GetIdxByEthAddrBJJ(addr ethCommon.Address, pk *babyjub.PublicKey) common.Idx {
32	// TODO
33	return common.Idx(0)
34}
35
36func siblingsToZKInputFormat(s []*merkletree.Hash) []*big.Int {
37	b := make([]*big.Int, len(s))
38	for i := 0; i < len(s); i++ {
39		b[i] = s[i].BigInt()
40	}
41	return b
42}
43
44// BJJCompressedTo256BigInts returns a [256]*big.Int array with the bit
45// representation of the babyjub.PublicKeyComp
46func BJJCompressedTo256BigInts(pkComp babyjub.PublicKeyComp) [256]*big.Int {
47	var r [256]*big.Int
48	b := pkComp[:]
49
50	for i := 0; i < 256; i++ {
51		if b[i/8]&(1<<(i%8)) == 0 {
52			r[i] = big.NewInt(0)
53		} else {
54			r[i] = big.NewInt(1)
55		}
56	}
57
58	return r
59}