Documentation ¶
Index ¶
- Constants
- func DeleteCensusTreeFromDatabase(kv db.Database, name string) (int, error)
- type Options
- type Tree
- func (t *Tree) Add(key, value []byte) error
- func (t *Tree) AddBatch(keys, values [][]byte) ([]int, error)
- func (t *Tree) BigIntToBytes(b *big.Int) []byte
- func (*Tree) BytesToBigInt(data []byte) *big.Int
- func (t *Tree) Close() error
- func (t *Tree) Dump() ([]byte, error)
- func (t *Tree) FromRoot(root []byte) (*Tree, error)
- func (t *Tree) GenProof(key []byte) ([]byte, []byte, error)
- func (t *Tree) Get(key []byte) ([]byte, error)
- func (t *Tree) GetCensusWeight() (*big.Int, error)
- func (t *Tree) Hash(data []byte) ([]byte, error)
- func (t *Tree) ImportDump(b []byte) error
- func (t *Tree) IterateLeaves(callback func(key, value []byte) bool) error
- func (t *Tree) Root() ([]byte, error)
- func (t *Tree) Size() (uint64, error)
- func (t *Tree) Type() models.Census_Type
- func (t *Tree) VerifyProof(key, value, proof, root []byte) (bool, error)
Constants ¶
const DefaultMaxKeyLen = DefaultMaxLevels / 8
DefaultMaxKeyLen is the maximum length of a census tree key is defined by the number of levels of the census tree. It is the number of bytes that can fit into 'n' bits, where 'n' is the number of levels of the census tree.
const DefaultMaxLevels = 160
DefaultMaxLevels is by default, the maximum number of levels will be 160, which allows to add up to 2^160 leaves to the tree, with keys with up to 20 bytes. However the number of levels could be set up during the tree initialization which allows to support uses cases with specific restrictions such as the zkweighted census, which needs to optimize some artifacts size that depends of the number of levels of the tree.
Variables ¶
This section is empty.
Functions ¶
func DeleteCensusTreeFromDatabase ¶ added in v1.4.0
DeleteCensusTreeFromDatabase removes all the database entries for the census identified by name. Caller must take care of potential data races, the census must be closed before calling this method. Returns the number of removed items.
Types ¶
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree implements the Merkle Tree used for census Concurrent updates to the tree.Tree can lead to losing some of the updates, so we don't expose the tree.Tree directly, and lock it in every method that updates it.
func New ¶ added in v1.3.0
New returns a new Tree, if there already is a Tree in the database, it will load it.
func (*Tree) Add ¶
Add adds a new key and value to the census merkle tree. The key must ideally be hashed with the tree function. If not, caller must ensure the key is inside the hashing function field. The value is considered the weight for the voter. So a serialized big.Int() is expected. Value must be inside the hashing function field too. If the census is indexed (indexAsKeysCensus), the value must be nil.
func (*Tree) BigIntToBytes ¶ added in v1.3.0
BigIntToBytes marshals a bigInt following the censusTree encoding rules
func (*Tree) BytesToBigInt ¶ added in v1.3.0
BytesToBigInt unmarshals a slice of bytes into a bigInt following the censusTree encoding rules
func (*Tree) FromRoot ¶ added in v1.3.0
FromRoot returns a new read-only Tree for the given root, that uses the same underlying db.
func (*Tree) GenProof ¶
GenProof generates a census proof for the provided key. The returned values are `value` and `siblings`. If the census is indexed, value will be equal to key.
func (*Tree) GetCensusWeight ¶ added in v1.3.0
GetCensusWeight returns the current weight of the census.
func (*Tree) Hash ¶ added in v1.3.0
Hash executes the tree hash function for input data and returns its output
func (*Tree) ImportDump ¶
ImportDump wraps t.tree.ImportDump while acquiring the lock.
func (*Tree) IterateLeaves ¶ added in v1.3.0
IterateLeaves wraps t.tree.IterateLeaves.
func (*Tree) Type ¶ added in v1.2.0
func (t *Tree) Type() models.Census_Type
Type returns the numeric identifier of the censustree implementation