merkletree

package
v0.3.4-RC4 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: AGPL-3.0, AGPL-3.0-or-later Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// LeafTypeBalance specifies that leaf stores Balance
	LeafTypeBalance leafType = 0
	// LeafTypeNonce specifies that leaf stores Nonce
	LeafTypeNonce leafType = 1
	// LeafTypeCode specifies that leaf stores Code
	LeafTypeCode leafType = 2
	// LeafTypeStorage specifies that leaf stores Storage Value
	LeafTypeStorage leafType = 3
	// LeafTypeSCLength specifies that leaf stores Storage Value
	LeafTypeSCLength leafType = 4
)
View Source
const (
	// HashPoseidonAllZeroes represents the poseidon hash for an input with all
	// bits set to zero.
	HashPoseidonAllZeroes = "0xc71603f33a1144ca7953db0ab48808f4c4055e3364a246c33c18a9786cb0b359"
)

Variables

This section is empty.

Functions

func H4ToString

func H4ToString(h4 []uint64) string

H4ToString converts array of 4 Scalars of 64 bits into an hex string.

func KeyCodeLength

func KeyCodeLength(ethAddr common.Address) ([]byte, error)

KeyCodeLength returns the key of code length leaf: hk0: H([0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0]) key: H([ethAddr[0:4], ethAddr[4:8], ethAddr[8:12], ethAddr[12:16], ethAddr[16:20], 0, 4, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]

func KeyContractCode

func KeyContractCode(ethAddr common.Address) ([]byte, error)

KeyContractCode returns the key of contract code leaf: hk0: H([0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0]) key: H([ethAddr[0:4], ethAddr[4:8], ethAddr[8:12], ethAddr[12:16], ethAddr[16:20], 0, 2, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]

func KeyContractStorage

func KeyContractStorage(ethAddr common.Address, storagePos []byte) ([]byte, error)

KeyContractStorage returns the key of contract storage position leaf: hk0: H([stoPos[0:4], stoPos[4:8], stoPos[8:12], stoPos[12:16], stoPos[16:20], stoPos[20:24], stoPos[24:28], stoPos[28:32], [0, 0, 0, 0]) key: H([ethAddr[0:4], ethAddr[4:8], ethAddr[8:12], ethAddr[12:16], ethAddr[16:20], 0, 3, 0], [hk0[0], hk0[1], hk0[2], hk0[3])

func KeyEthAddrBalance

func KeyEthAddrBalance(ethAddr common.Address) ([]byte, error)

KeyEthAddrBalance returns the key of balance leaf: hk0: H([0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0]) key: H([ethAddr[0:4], ethAddr[4:8], ethAddr[8:12], ethAddr[12:16], ethAddr[16:20], 0, 0, 0], [hk0[0], hk0[1], hk0[2], hk0[3]])

func KeyEthAddrNonce

func KeyEthAddrNonce(ethAddr common.Address) ([]byte, error)

KeyEthAddrNonce returns the key of nonce leaf: hk0: H([0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0]) key: H([ethAddr[0:4], ethAddr[4:8], ethAddr[8:12], ethAddr[12:16], ethAddr[16:20], 0, 1, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]

func NewMTDBServiceClient

NewMTDBServiceClient creates a new MTDB client.

func ScalarToFilledByteSlice

func ScalarToFilledByteSlice(s *big.Int) []byte

ScalarToFilledByteSlice converts a *big.Int into an array of maxBigIntLen bytes.

func StringToh4

func StringToh4(str string) ([]uint64, error)

StringToh4 converts an hex string into array of 4 Scalars of 64 bits.

Types

type Config

type Config struct {
	// URI is the server URI.
	URI string `mapstructure:"URI"`
}

Config represents the configuration of the merkletree server.

type Key

type Key [32]byte

Key stores key of the leaf

type ProgramProof

type ProgramProof struct {
	// Data is the program proof data.
	Data []byte
}

ProgramProof is a proof generated on GetProgram operation.

type Proof

type Proof struct {
	// Root is the proof root.
	Root []uint64
	// Key is the proof key.
	Key []uint64
	// Value is the proof value.
	Value []uint64
}

Proof is a proof generated on Get operation.

type ResultCode

type ResultCode int64

ResultCode represents the result code.

const (
	// Unspecified is the code for unspecified result.
	Unspecified ResultCode = iota
	// Success is the code for success result.
	Success
	// KeyNotFound is the code for key not found result.
	KeyNotFound
	// DBError is the code for DB error result.
	DBError
	// InternalError is the code for internal error result.
	InternalError
)

type StateTree

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

StateTree provides methods to access and modify state in merkletree

func NewStateTree

func NewStateTree(client hashdb.HashDBServiceClient) *StateTree

NewStateTree creates new StateTree.

func (*StateTree) Flush

func (tree *StateTree) Flush(ctx context.Context, uuid string) error

Flush flushes all changes to the persistent storage.

func (*StateTree) GetBalance

func (tree *StateTree) GetBalance(ctx context.Context, address common.Address, root []byte) (*big.Int, error)

GetBalance returns balance.

func (*StateTree) GetCode

func (tree *StateTree) GetCode(ctx context.Context, address common.Address, root []byte) ([]byte, error)

GetCode returns code.

func (*StateTree) GetCodeHash

func (tree *StateTree) GetCodeHash(ctx context.Context, address common.Address, root []byte) ([]byte, error)

GetCodeHash returns code hash.

func (*StateTree) GetNonce

func (tree *StateTree) GetNonce(ctx context.Context, address common.Address, root []byte) (*big.Int, error)

GetNonce returns nonce.

func (*StateTree) GetStorageAt

func (tree *StateTree) GetStorageAt(ctx context.Context, address common.Address, position *big.Int, root []byte) (*big.Int, error)

GetStorageAt returns Storage Value at specified position.

func (*StateTree) SetBalance

func (tree *StateTree) SetBalance(ctx context.Context, address common.Address, balance *big.Int, root []byte, uuid string) (newRoot []byte, proof *UpdateProof, err error)

SetBalance sets balance.

func (*StateTree) SetCode

func (tree *StateTree) SetCode(ctx context.Context, address common.Address, code []byte, root []byte, uuid string) (newRoot []byte, proof *UpdateProof, err error)

SetCode sets smart contract code.

func (*StateTree) SetNonce

func (tree *StateTree) SetNonce(ctx context.Context, address common.Address, nonce *big.Int, root []byte, uuid string) (newRoot []byte, proof *UpdateProof, err error)

SetNonce sets nonce.

func (*StateTree) SetStorageAt

func (tree *StateTree) SetStorageAt(ctx context.Context, address common.Address, position *big.Int, value *big.Int, root []byte, uuid string) (newRoot []byte, proof *UpdateProof, err error)

SetStorageAt sets storage value at specified position.

type UpdateProof

type UpdateProof struct {
	// OldRoot is the update proof old root.
	OldRoot []uint64
	// NewRoot is the update proof new root.
	NewRoot []uint64
	// Key is the update proof key.
	Key []uint64
	// NewValue is the update proof new value.
	NewValue []uint64
}

UpdateProof is a proof generated on Set operation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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