Documentation
¶
Index ¶
- Constants
- Variables
- func NewEmptyNodeReader() nodeReader
- func RunOnTempTriePedersen(height uint8, do func(*Trie) error) error
- func RunOnTempTriePoseidon(height uint8, do func(*Trie) error) error
- func VerifyProof(root, key *felt.Felt, proof *ProofNodeSet, hash crypto.HashFn) (felt.Felt, error)
- func VerifyRangeProof(rootHash, first *felt.Felt, keys, values []*felt.Felt, proof *ProofNodeSet) (bool, error)
- type MissingNodeError
- type Path
- type ProofNodeSet
- type TestNodeDatabase
- type Trie
- func New(id trieutils.TrieID, height uint8, hashFn crypto.HashFn, ...) (*Trie, error)
- func NewEmpty(height uint8, hashFn crypto.HashFn) *Trie
- func NewEmptyPedersen() (*Trie, error)
- func NewEmptyPoseidon() (*Trie, error)
- func NewFromRootHash(id trieutils.TrieID, height uint8, hashFn crypto.HashFn, ...) (*Trie, error)
- func (t *Trie) Commit() (felt.Felt, *trienode.NodeSet)
- func (t *Trie) Copy() *Trie
- func (t *Trie) Delete(key *felt.Felt) error
- func (t *Trie) FeltToPath(f *felt.Felt) Path
- func (t *Trie) Get(key *felt.Felt) (felt.Felt, error)
- func (t *Trie) GetRangeProof(leftKey, rightKey *felt.Felt, proofSet *ProofNodeSet) error
- func (t *Trie) Hash() (felt.Felt, error)
- func (t *Trie) HashFn() crypto.HashFn
- func (t *Trie) Prove(key *felt.Felt, proof *ProofNodeSet) error
- func (t *Trie) String() string
- func (t *Trie) Update(key, value *felt.Felt) error
Constants ¶
const ( PathScheme dbScheme = iota + 1 HashScheme )
Variables ¶
var ( ErrCommitted = errors.New("trie is committed") ErrEmptyRange = errors.New("empty range") )
Functions ¶
func NewEmptyNodeReader ¶
func NewEmptyNodeReader() nodeReader
func VerifyProof ¶
VerifyProof verifies that a proof path is valid for a given key in a binary trie. It walks through the proof nodes, verifying each step matches the expected path to reach the key.
The proof is considered invalid if:
- Any proof node is missing from the node set
- Any node's computed hash doesn't match its expected hash
- The path bits don't match the key bits
- The proof ends before processing all key bits
func VerifyRangeProof ¶
Types ¶
type MissingNodeError ¶
type MissingNodeError struct {
// contains filtered or unexported fields
}
func (*MissingNodeError) Error ¶
func (e *MissingNodeError) Error() string
type ProofNodeSet ¶
func NewProofNodeSet ¶
func NewProofNodeSet() *ProofNodeSet
type TestNodeDatabase ¶
type TestNodeDatabase struct {
// contains filtered or unexported fields
}
func NewTestNodeDatabase ¶
func NewTestNodeDatabase(disk db.KeyValueStore, scheme dbScheme) TestNodeDatabase
func (*TestNodeDatabase) NodeReader ¶
func (d *TestNodeDatabase) NodeReader(id trieutils.TrieID) (database.NodeReader, error)
func (*TestNodeDatabase) Update ¶
func (d *TestNodeDatabase) Update(root, parent *felt.Felt, nodes *trienode.MergeNodeSet) error
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
func New ¶
func New( id trieutils.TrieID, height uint8, hashFn crypto.HashFn, nodeDB database.NodeDatabase, ) (*Trie, error)
Creates a new trie, with the arguments: - id: the trie id - height: the height of the trie, 251 for contract and class trie - hashFn: the hash function to use - nodeDB: database interface, which provides methods to read and write trie nodes
func NewEmptyPedersen ¶
func NewEmptyPoseidon ¶
func NewFromRootHash ¶ added in v0.14.6
func NewFromRootHash( id trieutils.TrieID, height uint8, hashFn crypto.HashFn, nodeDB database.NodeDatabase, rootHash *felt.Felt, ) (*Trie, error)
Similar to New, creates a new trie, but additionally takes one more argument: - rootHash: the root hash of the trie (provided only for hash scheme of trieDB, needed to properly recreate the trie)
func (*Trie) Commit ¶
Collapses the trie into a single hash node and flush the node changes to the database.
func (*Trie) FeltToPath ¶
Converts a Felt value into a Path representation suitable to use as a trie key with the specified height.
func (*Trie) Get ¶
Retrieves the value associated with the given key. Returns felt.Zero if the key doesn't exist. May update the trie's internal structure if nodes need to be resolved.
func (*Trie) GetRangeProof ¶
func (t *Trie) GetRangeProof(leftKey, rightKey *felt.Felt, proofSet *ProofNodeSet) error
GetRangeProof generates a range proof for the given range of keys. The proof contains the proof nodes on the path from the root to the closest ancestor of the left and right keys.
func (*Trie) Hash ¶
Returns the root hash of the trie. Calling this method will also cache the hash of each node in the trie.
func (*Trie) Prove ¶
func (t *Trie) Prove(key *felt.Felt, proof *ProofNodeSet) error
Prove generates a Merkle proof for a given key in the trie. The result contains the proof nodes on the path from the root to the leaf. The value is included in the proof if the key is present in the trie. If the key is not present, the proof will contain the nodes on the path to the closest ancestor.