commitment

package
v0.0.0-...-c80a3f0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyBinRootHash, _ = hex.DecodeString("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
	EmptyBinCodeHash, _ = hex.DecodeString("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
)
View Source
var (
	EmptyRootHash, _ = hex.DecodeString("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
	EmptyCodeHash, _ = hex.DecodeString("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
)

Functions

func CompactedKeyToHex

func CompactedKeyToHex(compact []byte) []byte

Types

type BinPatriciaHashed

type BinPatriciaHashed struct {
	// contains filtered or unexported fields
}

BinHashed implements commitment based on patricia merkle tree with radix 16, with keys pre-hashed by keccak256

func NewBinPatriciaHashed

func NewBinPatriciaHashed(accountKeyLen int,
	branchFn func(prefix []byte) ([]byte, error),
	accountFn func(plainKey []byte, cell *Cell) error,
	storageFn func(plainKey []byte, cell *Cell) error,
) *BinPatriciaHashed

func (*BinPatriciaHashed) EncodeCurrentState

func (bph *BinPatriciaHashed) EncodeCurrentState(buf []byte) ([]byte, error)

Encode current state of hph into bytes

func (*BinPatriciaHashed) ProcessUpdates

func (bph *BinPatriciaHashed) ProcessUpdates(plainKeys, hashedKeys [][]byte, updates []Update) (rootHash []byte, branchNodeUpdates map[string]BranchData, err error)

func (*BinPatriciaHashed) Reset

func (bph *BinPatriciaHashed) Reset()

Reset allows BinPatriciaHashed instance to be reused for the new commitment calculation

func (*BinPatriciaHashed) ResetFns

func (bph *BinPatriciaHashed) ResetFns(
	branchFn func(prefix []byte) ([]byte, error),
	accountFn func(plainKey []byte, cell *Cell) error,
	storageFn func(plainKey []byte, cell *Cell) error,
)

func (*BinPatriciaHashed) ReviewKeys

func (bph *BinPatriciaHashed) ReviewKeys(plainKeys, hashedKeys [][]byte) (rootHash []byte, branchNodeUpdates map[string]BranchData, err error)

func (*BinPatriciaHashed) RootHash

func (bph *BinPatriciaHashed) RootHash() ([]byte, error)

func (*BinPatriciaHashed) SetState

func (bph *BinPatriciaHashed) SetState(buf []byte) error

buf expected to be encoded hph state. Decode state and set up hph to that state.

func (*BinPatriciaHashed) SetTrace

func (bph *BinPatriciaHashed) SetTrace(trace bool)

func (*BinPatriciaHashed) Variant

func (bph *BinPatriciaHashed) Variant() TrieVariant

type BinaryCell

type BinaryCell struct {
	Nonce      uint64
	Balance    uint256.Int
	CodeHash   [length.Hash]byte // hash of the bytecode
	Storage    [length.Hash]byte
	StorageLen int
	Delete     bool
	// contains filtered or unexported fields
}

type BranchData

type BranchData []byte

func EncodeBranch

func EncodeBranch(bitmap, touchMap, afterMap uint16, retriveCell func(nibble int, skip bool) (*Cell, error)) (branchData BranchData, lastNibble int, err error)

func (BranchData) DecodeCells

func (branchData BranchData) DecodeCells() (touchMap, afterMap uint16, row [16]*Cell, err error)

func (BranchData) ExtractPlainKeys

func (branchData BranchData) ExtractPlainKeys() (accountPlainKeys [][]byte, storagePlainKeys [][]byte, err error)

ExtractPlainKeys parses branchData and extract the plain keys for accounts and storage in the same order they appear witjin the branchData

func (BranchData) IsComplete

func (branchData BranchData) IsComplete() bool

IsComplete determines whether given branch data is complete, meaning that all information about all the children is present Each of 16 children of a branch node have two attributes touch - whether this child has been modified or deleted in this branchData (corresponding bit in touchMap is set) after - whether after this branchData application, the child is present in the tree or not (corresponding bit in afterMap is set)

func (BranchData) MergeHexBranches

func (branchData BranchData) MergeHexBranches(branchData2 BranchData, newData []byte) (BranchData, error)

MergeHexBranches combines two branchData, number 2 coming after (and potentially shadowing) number 1

func (BranchData) ReplacePlainKeys

func (branchData BranchData) ReplacePlainKeys(accountPlainKeys [][]byte, storagePlainKeys [][]byte, newData []byte) (BranchData, error)

func (BranchData) String

func (branchData BranchData) String() string

type BranchMerger

type BranchMerger struct {
	// contains filtered or unexported fields
}

func NewHexBranchMerger

func NewHexBranchMerger(capacity uint64) *BranchMerger

func (*BranchMerger) Merge

func (m *BranchMerger) Merge(branch1 BranchData, branch2 BranchData) (BranchData, error)

MergeHexBranches combines two branchData, number 2 coming after (and potentially shadowing) number 1

type Cell

type Cell struct {
	Balance uint256.Int
	Nonce   uint64

	StorageLen int

	CodeHash [length.Hash]byte // hash of the bytecode
	Storage  [length.Hash]byte

	Delete bool
	// contains filtered or unexported fields
}

type HexPatriciaHashed

type HexPatriciaHashed struct {
	// contains filtered or unexported fields
}

HexPatriciaHashed implements commitment based on patricia merkle tree with radix 16, with keys pre-hashed by keccak256

func NewHexPatriciaHashed

func NewHexPatriciaHashed(accountKeyLen int,
	branchFn func(prefix []byte) ([]byte, error),
	accountFn func(plainKey []byte, cell *Cell) error,
	storageFn func(plainKey []byte, cell *Cell) error,
) *HexPatriciaHashed

func (*HexPatriciaHashed) EncodeCurrentState

func (hph *HexPatriciaHashed) EncodeCurrentState(buf []byte) ([]byte, error)

Encode current state of hph into bytes

func (*HexPatriciaHashed) ProcessUpdates

func (hph *HexPatriciaHashed) ProcessUpdates(plainKeys, hashedKeys [][]byte, updates []Update) (rootHash []byte, branchNodeUpdates map[string]BranchData, err error)

func (*HexPatriciaHashed) Reset

func (hph *HexPatriciaHashed) Reset()

Reset allows HexPatriciaHashed instance to be reused for the new commitment calculation

func (*HexPatriciaHashed) ResetFns

func (hph *HexPatriciaHashed) ResetFns(
	branchFn func(prefix []byte) ([]byte, error),
	accountFn func(plainKey []byte, cell *Cell) error,
	storageFn func(plainKey []byte, cell *Cell) error,
)

func (*HexPatriciaHashed) ReviewKeys

func (hph *HexPatriciaHashed) ReviewKeys(plainKeys, hashedKeys [][]byte) (rootHash []byte, branchNodeUpdates map[string]BranchData, err error)

func (*HexPatriciaHashed) RootHash

func (hph *HexPatriciaHashed) RootHash() ([]byte, error)

func (*HexPatriciaHashed) SetState

func (hph *HexPatriciaHashed) SetState(buf []byte) error

buf expected to be encoded hph state. Decode state and set up hph to that state.

func (*HexPatriciaHashed) SetTrace

func (hph *HexPatriciaHashed) SetTrace(trace bool)

func (*HexPatriciaHashed) Variant

func (hph *HexPatriciaHashed) Variant() TrieVariant

type PartFlags

type PartFlags uint8
const (
	HashedKeyPart    PartFlags = 1
	AccountPlainPart PartFlags = 2
	StoragePlainPart PartFlags = 4
	HashPart         PartFlags = 8
)

type Trie

type Trie interface {
	// RootHash produces root hash of the trie
	RootHash() (hash []byte, err error)

	// Variant returns commitment trie variant
	Variant() TrieVariant

	// Reset Drops everything from the trie
	Reset()

	ReviewKeys(pk, hk [][]byte) (rootHash []byte, branchNodeUpdates map[string]BranchData, err error)

	ProcessUpdates(pk, hk [][]byte, updates []Update) (rootHash []byte, branchNodeUpdates map[string]BranchData, err error)

	ResetFns(
		branchFn func(prefix []byte) ([]byte, error),
		accountFn func(plainKey []byte, cell *Cell) error,
		storageFn func(plainKey []byte, cell *Cell) error,
	)

	// Makes trie more verbose
	SetTrace(bool)
}

Trie represents commitment variant.

func InitializeTrie

func InitializeTrie(tv TrieVariant) Trie

type TrieVariant

type TrieVariant string
const (
	// VariantHexPatriciaTrie used as default commitment approach
	VariantHexPatriciaTrie TrieVariant = "hex-patricia-hashed"
	// VariantBinPatriciaTrie - Experimental mode with binary key representation
	VariantBinPatriciaTrie TrieVariant = "bin-patricia-hashed"
)

type Update

type Update struct {
	Flags             UpdateFlags
	Balance           uint256.Int
	Nonce             uint64
	CodeHashOrStorage [length.Hash]byte
	ValLength         int
}

func (*Update) Decode

func (u *Update) Decode(buf []byte, pos int) (int, error)

func (*Update) DecodeForStorage

func (u *Update) DecodeForStorage(enc []byte)

func (*Update) Encode

func (u *Update) Encode(buf []byte, numBuf []byte) []byte

func (*Update) String

func (u *Update) String() string

type UpdateFlags

type UpdateFlags uint8
const (
	CODE_UPDATE    UpdateFlags = 1
	DELETE_UPDATE  UpdateFlags = 2
	BALANCE_UPDATE UpdateFlags = 4
	NONCE_UPDATE   UpdateFlags = 8
	STORAGE_UPDATE UpdateFlags = 16
)

func (UpdateFlags) String

func (uf UpdateFlags) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL