Documentation ¶
Index ¶
- Constants
- Variables
- func Hash(node Node) []byte
- func IsEmptyNode(node Node) bool
- func IsNibble(nibble byte) bool
- func Keccak256(data ...[]byte) []byte
- func PrefixMatchedLen(node1 []Nibble, node2 []Nibble) int
- func Serialize(node Node) []byte
- func ToBytes(ns []Nibble) []byte
- func VerifyProof(rootHash []byte, key []byte, proof Proof) (value []byte, err error)
- type BranchNode
- func (b BranchNode) HasValue() bool
- func (b BranchNode) Hash() []byte
- func (b BranchNode) Raw() []interface{}
- func (b *BranchNode) RemoveBranch(nibble Nibble)
- func (b *BranchNode) RemoveValue()
- func (b BranchNode) Serialize() []byte
- func (b *BranchNode) SetBranch(nibble Nibble, node Node)
- func (b *BranchNode) SetValue(value []byte)
- type ExtensionNode
- type LeafNode
- type Nibble
- type Node
- type Proof
- type ProofDB
- type Transaction
- type Trie
Constants ¶
const EthereumRootHash = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
Variables ¶
var ( EmptyNodeRaw = []byte{} EmptyNodeHash, _ = hex.DecodeString(EthereumRootHash) )
Functions ¶
func IsEmptyNode ¶
func PrefixMatchedLen ¶
[0,1,2,3], [0,1,2] => 3 [0,1,2,3], [0,1,2,3] => 4 [0,1,2,3], [0,1,2,3,4] => 4
func ToBytes ¶
ToBytes converts a slice of nibbles to a byte slice assuming the nibble slice has even number of nibbles.
func VerifyProof ¶
VerifyProof verify the proof for the given key under the given root hash using go-ethereum's VerifyProof implementation. It returns the value for the key if the proof is valid, otherwise error will be returned
Types ¶
type BranchNode ¶
BranchNode each node can have up to 16 branches
func NewBranchNode ¶
func NewBranchNode() *BranchNode
func (BranchNode) HasValue ¶
func (b BranchNode) HasValue() bool
func (BranchNode) Hash ¶
func (b BranchNode) Hash() []byte
func (BranchNode) Raw ¶
func (b BranchNode) Raw() []interface{}
func (*BranchNode) RemoveBranch ¶
func (b *BranchNode) RemoveBranch(nibble Nibble)
func (*BranchNode) RemoveValue ¶
func (b *BranchNode) RemoveValue()
func (BranchNode) Serialize ¶
func (b BranchNode) Serialize() []byte
func (*BranchNode) SetBranch ¶
func (b *BranchNode) SetBranch(nibble Nibble, node Node)
func (*BranchNode) SetValue ¶
func (b *BranchNode) SetValue(value []byte)
type ExtensionNode ¶
In the MPT, there is one more type of nodes apart from the branch nodes and the leaf nodes. They are extension nodes. An extension node is an optimized node of the branch node. In the Ethereum state, quite frequently, there are branch nodes that have only one child node. This is the reason why the MPT compresses branch nodes that contain only one child into extension nodes that have a path and the hash of the child.
func NewExtensionNode ¶
func NewExtensionNode(nibbles []Nibble, next Node) *ExtensionNode
func (ExtensionNode) Hash ¶
func (e ExtensionNode) Hash() []byte
func (ExtensionNode) Raw ¶
func (e ExtensionNode) Raw() []interface{}
func (ExtensionNode) Serialize ¶
func (e ExtensionNode) Serialize() []byte
type LeafNode ¶
func NewLeafNodeFromBytes ¶
func NewLeafNodeFromKeyValue ¶
func NewLeafNodeFromNibbles ¶
type Nibble ¶
type Nibble byte
1 nibble == 4 bit == 0.5 byte
func FromNibbleByte ¶
func FromNibbleBytes ¶
nibbles contain one nibble per byte
func FromString ¶
func ToPrefixed ¶
ToPrefixed add nibble prefix to a slice of nibbles to make its length even the prefix indicts whether a node is a leaf node.
type Node ¶
type Node interface { Hash() []byte Raw() []interface{} }
Key-values of the Ethereum state are used as paths on the MPT. Nibble is the unit used to distinguish key values in the MPT, so each node can have up to 16 branches. Additionally, since a node has its own value, a branch node is an array of 17 items composed of 1 node value and 16 branches.
type Proof ¶
type Proof interface { // Put inserts the given value into the key-value data store. Put(key []byte, value []byte) error // Delete removes the key from the key-value data store. Delete(key []byte) error // Has retrieves if a key is present in the key-value data store. Has(key []byte) (bool, error) // Get retrieves the given key if it's present in the key-value data store. Get(key []byte) ([]byte, error) }
type ProofDB ¶
type ProofDB struct {
// contains filtered or unexported fields
}
func NewProofDB ¶
func NewProofDB() *ProofDB
type Transaction ¶
type Transaction struct { AccountNonce uint64 `json:"nonce" ` Price *big.Int `json:"gasPrice" ` GasLimit uint64 `json:"gas" ` Recipient *common.Address `json:"to" ` Amount *big.Int `json:"value" ` Payload []byte `json:"input" ` // Signature values V *big.Int `json:"v" ` R *big.Int `json:"r" ` S *big.Int `json:"s" ` }
func (Transaction) GetRLP ¶
func (t Transaction) GetRLP() ([]byte, error)
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
func (*Trie) Put ¶
Put adds a key value pair to the trie In general, the rule is: - When stopped at an EmptyNode, replace it with a new LeafNode with the remaining path. - When stopped at a LeafNode, convert it to an ExtensionNode and add a new branch and a new LeafNode. - When stopped at an ExtensionNode, convert it to another ExtensionNode with shorter path and create a new BranchNode points to the ExtensionNode.