proof

package
v2.0.0-...-0f7a4ef Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ProofOpIAVLCommitment         = "ics23:iavl"
	ProofOpSimpleMerkleCommitment = "ics23:simple"
	ProofOpSMTCommitment          = "ics23:smt"
)

Proof operation types

Variables

View Source
var (
	ErrInvalidLengthCommitInfo        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCommitInfo          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupCommitInfo = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (

	// SimpleMerkleSpec is the ics23 proof spec for simple merkle proofs.
	SimpleMerkleSpec = &ics23.ProofSpec{
		LeafSpec: &ics23.LeafOp{
			Prefix:       leafPrefix,
			PrehashKey:   ics23.HashOp_NO_HASH,
			PrehashValue: ics23.HashOp_SHA256,
			Hash:         ics23.HashOp_SHA256,
			Length:       ics23.LengthOp_VAR_PROTO,
		},
		InnerSpec: &ics23.InnerSpec{
			ChildOrder:      []int32{0, 1},
			MinPrefixLength: 1,
			MaxPrefixLength: 1,
			ChildSize:       32,
			Hash:            ics23.HashOp_SHA256,
		},
	}
)

Functions

func InnerHash

func InnerHash(left, right []byte) []byte

InnerHash computes the hash of an inner node as defined by ics23: https://github.com/cosmos/ics23/blob/go/v0.10.0/proto/cosmos/ics23/v1/proofs.proto#L130

func LeafHash

func LeafHash(key, value []byte) ([]byte, error)

LeafHash computes the hash of a leaf node.

func ProofFromByteSlices

func ProofFromByteSlices(leaves [][]byte, index int) (rootHash []byte, inners []*ics23.InnerOp)

ProofFromByteSlices computes the proof from the given leaves. An iteration will be performed for each level of the tree, where each iteration hashes together the bottom most nodes. If the length of the bottom most nodes is odd, then the last node will be saved for the next iteration.

Example: Iteration 1: n = 5 leaves = a, b, c, d, e. index = 2 (prove c)

Iteration 2: n = 3 leaves = ab, cd, e index = 1 (prove c, so index of cd)

Iteration 3: n = 2 leaves = abcd, e index = 0 (prove c, so index of abcd)

Final iteration: n = 1 leaves = abcde index = 0

The bitwise & operator allows us to determine if the index or length is odd or even. The bitwise ^ operator allows us to increment when the value is even and decrement when it is odd.

Types

type CommitID

type CommitID struct {
	Version int64  `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"`
	Hash    []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
}

CommitID defines the commitment information when a specific store is committed.

func (*CommitID) Descriptor

func (*CommitID) Descriptor() ([]byte, []int)

func (*CommitID) GetHash

func (m *CommitID) GetHash() []byte

func (*CommitID) GetVersion

func (m *CommitID) GetVersion() int64

func (*CommitID) IsZero

func (cid *CommitID) IsZero() bool

func (*CommitID) Marshal

func (m *CommitID) Marshal() (dAtA []byte, err error)

func (*CommitID) MarshalTo

func (m *CommitID) MarshalTo(dAtA []byte) (int, error)

func (*CommitID) MarshalToSizedBuffer

func (m *CommitID) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*CommitID) ProtoMessage

func (*CommitID) ProtoMessage()

func (*CommitID) Reset

func (m *CommitID) Reset()

func (*CommitID) Size

func (m *CommitID) Size() (n int)

func (*CommitID) String

func (cid *CommitID) String() string

func (*CommitID) Unmarshal

func (m *CommitID) Unmarshal(dAtA []byte) error

func (*CommitID) XXX_DiscardUnknown

func (m *CommitID) XXX_DiscardUnknown()

func (*CommitID) XXX_Marshal

func (m *CommitID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CommitID) XXX_Merge

func (m *CommitID) XXX_Merge(src proto.Message)

func (*CommitID) XXX_Size

func (m *CommitID) XXX_Size() int

func (*CommitID) XXX_Unmarshal

func (m *CommitID) XXX_Unmarshal(b []byte) error

type CommitInfo

type CommitInfo struct {
	Version    int64        `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"`
	StoreInfos []*StoreInfo `protobuf:"bytes,2,rep,name=store_infos,json=storeInfos,proto3" json:"store_infos,omitempty"`
	Timestamp  time.Time    `protobuf:"bytes,3,opt,name=timestamp,proto3,stdtime" json:"timestamp"`
	CommitHash []byte       `protobuf:"bytes,4,opt,name=commit_hash,json=commitHash,proto3" json:"commit_hash,omitempty"`
}

CommitInfo defines commit information used by the multi-store when committing a version/height.

func (*CommitInfo) CommitID

func (ci *CommitInfo) CommitID() *CommitID

func (*CommitInfo) Descriptor

func (*CommitInfo) Descriptor() ([]byte, []int)

func (*CommitInfo) GetCommitHash

func (m *CommitInfo) GetCommitHash() []byte

func (*CommitInfo) GetStoreCommitID

func (ci *CommitInfo) GetStoreCommitID(storeKey []byte) *CommitID

GetStoreCommitID returns the CommitID for the given store key.

func (*CommitInfo) GetStoreInfos

func (m *CommitInfo) GetStoreInfos() []*StoreInfo

func (*CommitInfo) GetStoreProof

func (ci *CommitInfo) GetStoreProof(storeKey []byte) ([]byte, *CommitmentOp, error)

GetStoreProof takes in a storeKey and returns a proof of the store key in addition to the root hash it should be proved against. If an empty string is provided, the first store based on lexographical ordering will be proved.

func (*CommitInfo) GetTimestamp

func (m *CommitInfo) GetTimestamp() time.Time

func (*CommitInfo) GetVersion

func (m *CommitInfo) GetVersion() int64

func (*CommitInfo) Hash

func (ci *CommitInfo) Hash() []byte

Hash returns the root hash of all committed stores represented by CommitInfo, sorted by store name/key.

func (*CommitInfo) Marshal

func (m *CommitInfo) Marshal() (dAtA []byte, err error)

func (*CommitInfo) MarshalTo

func (m *CommitInfo) MarshalTo(dAtA []byte) (int, error)

func (*CommitInfo) MarshalToSizedBuffer

func (m *CommitInfo) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*CommitInfo) ProtoMessage

func (*CommitInfo) ProtoMessage()

func (*CommitInfo) Reset

func (m *CommitInfo) Reset()

func (*CommitInfo) Size

func (m *CommitInfo) Size() (n int)

func (*CommitInfo) String

func (m *CommitInfo) String() string

func (*CommitInfo) Unmarshal

func (m *CommitInfo) Unmarshal(dAtA []byte) error

func (*CommitInfo) XXX_DiscardUnknown

func (m *CommitInfo) XXX_DiscardUnknown()

func (*CommitInfo) XXX_Marshal

func (m *CommitInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CommitInfo) XXX_Merge

func (m *CommitInfo) XXX_Merge(src proto.Message)

func (*CommitInfo) XXX_Size

func (m *CommitInfo) XXX_Size() int

func (*CommitInfo) XXX_Unmarshal

func (m *CommitInfo) XXX_Unmarshal(b []byte) error

type CommitmentOp

type CommitmentOp struct {
	Type  string
	Key   []byte
	Spec  *ics23.ProofSpec
	Proof *ics23.CommitmentProof
}

CommitmentOp implements merkle.ProofOperator by wrapping an ics23 CommitmentProof. It also contains a Key field to determine which key the proof is proving. NOTE: CommitmentProof currently can either be ExistenceProof or NonexistenceProof

Type and Spec are classified by the kind of merkle proof it represents allowing the code to be reused by more types. Spec is never on the wire, but mapped from type in the code.

func ConvertCommitmentOp

func ConvertCommitmentOp(inners []*ics23.InnerOp, key, value []byte) CommitmentOp

ConvertCommitmentOp converts the given merkle proof into an CommitmentOp.

func NewIAVLCommitmentOp

func NewIAVLCommitmentOp(key []byte, proof *ics23.CommitmentProof) CommitmentOp

func NewSMTCommitmentOp

func NewSMTCommitmentOp(key []byte, proof *ics23.CommitmentProof) CommitmentOp

func NewSimpleMerkleCommitmentOp

func NewSimpleMerkleCommitmentOp(key []byte, proof *ics23.CommitmentProof) CommitmentOp

func (CommitmentOp) GetKey

func (op CommitmentOp) GetKey() []byte

func (CommitmentOp) Run

func (op CommitmentOp) Run(args [][]byte) ([][]byte, error)

Run takes in a list of arguments and attempts to run the proof op against these arguments. Returns the root wrapped in [][]byte if the proof op succeeds with given args. If not, it will return an error.

CommitmentOp will accept args of length 1 or length 0. If length 1 args is passed in, then CommitmentOp will attempt to prove the existence of the key with the value provided by args[0] using the embedded CommitmentProof and returns the CommitmentRoot of the proof. If length 0 args is passed in, then CommitmentOp will attempt to prove the absence of the key in the CommitmentOp and return the CommitmentRoot of the proof.

type StoreInfo

type StoreInfo struct {
	Name      string    `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	CommitId  *CommitID `protobuf:"bytes,2,opt,name=commit_id,json=commitId,proto3" json:"commit_id,omitempty"`
	Structure string    `protobuf:"bytes,3,opt,name=structure,proto3" json:"structure,omitempty"`
}

StoreInfo defines store-specific commit information. It contains a reference between a store name and the commit ID.

func (*StoreInfo) Descriptor

func (*StoreInfo) Descriptor() ([]byte, []int)

func (*StoreInfo) GetCommitId

func (m *StoreInfo) GetCommitId() *CommitID

func (StoreInfo) GetHash

func (si StoreInfo) GetHash() []byte

func (*StoreInfo) GetName

func (m *StoreInfo) GetName() string

func (*StoreInfo) GetStructure

func (m *StoreInfo) GetStructure() string

func (*StoreInfo) Marshal

func (m *StoreInfo) Marshal() (dAtA []byte, err error)

func (*StoreInfo) MarshalTo

func (m *StoreInfo) MarshalTo(dAtA []byte) (int, error)

func (*StoreInfo) MarshalToSizedBuffer

func (m *StoreInfo) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*StoreInfo) ProtoMessage

func (*StoreInfo) ProtoMessage()

func (*StoreInfo) Reset

func (m *StoreInfo) Reset()

func (*StoreInfo) Size

func (m *StoreInfo) Size() (n int)

func (*StoreInfo) String

func (m *StoreInfo) String() string

func (*StoreInfo) Unmarshal

func (m *StoreInfo) Unmarshal(dAtA []byte) error

func (*StoreInfo) XXX_DiscardUnknown

func (m *StoreInfo) XXX_DiscardUnknown()

func (*StoreInfo) XXX_Marshal

func (m *StoreInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*StoreInfo) XXX_Merge

func (m *StoreInfo) XXX_Merge(src proto.Message)

func (*StoreInfo) XXX_Size

func (m *StoreInfo) XXX_Size() int

func (*StoreInfo) XXX_Unmarshal

func (m *StoreInfo) XXX_Unmarshal(b []byte) error

Directories

Path Synopsis
v1

Jump to

Keyboard shortcuts

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