Documentation
¶
Index ¶
- Constants
- Variables
- func InnerHash(left, right []byte) []byte
- func LeafHash(key, value []byte) ([]byte, error)
- func ProofFromByteSlices(leaves [][]byte, index int) (rootHash []byte, inners []*ics23.InnerOp)
- type CommitID
- func (*CommitID) Descriptor() ([]byte, []int)
- func (m *CommitID) GetHash() []byte
- func (m *CommitID) GetVersion() int64
- func (cid *CommitID) IsZero() bool
- func (m *CommitID) Marshal() (dAtA []byte, err error)
- func (m *CommitID) MarshalTo(dAtA []byte) (int, error)
- func (m *CommitID) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*CommitID) ProtoMessage()
- func (m *CommitID) Reset()
- func (m *CommitID) Size() (n int)
- func (cid *CommitID) String() string
- func (m *CommitID) Unmarshal(dAtA []byte) error
- func (m *CommitID) XXX_DiscardUnknown()
- func (m *CommitID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *CommitID) XXX_Merge(src proto.Message)
- func (m *CommitID) XXX_Size() int
- func (m *CommitID) XXX_Unmarshal(b []byte) error
- type CommitInfo
- func (ci *CommitInfo) CommitID() *CommitID
- func (*CommitInfo) Descriptor() ([]byte, []int)
- func (m *CommitInfo) GetCommitHash() []byte
- func (ci *CommitInfo) GetStoreCommitID(storeKey []byte) *CommitID
- func (m *CommitInfo) GetStoreInfos() []*StoreInfo
- func (ci *CommitInfo) GetStoreProof(storeKey []byte) ([]byte, *CommitmentOp, error)
- func (m *CommitInfo) GetTimestamp() time.Time
- func (m *CommitInfo) GetVersion() int64
- func (ci *CommitInfo) Hash() []byte
- func (m *CommitInfo) Marshal() (dAtA []byte, err error)
- func (m *CommitInfo) MarshalTo(dAtA []byte) (int, error)
- func (m *CommitInfo) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*CommitInfo) ProtoMessage()
- func (m *CommitInfo) Reset()
- func (m *CommitInfo) Size() (n int)
- func (m *CommitInfo) String() string
- func (m *CommitInfo) Unmarshal(dAtA []byte) error
- func (m *CommitInfo) XXX_DiscardUnknown()
- func (m *CommitInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *CommitInfo) XXX_Merge(src proto.Message)
- func (m *CommitInfo) XXX_Size() int
- func (m *CommitInfo) XXX_Unmarshal(b []byte) error
- type CommitmentOp
- func ConvertCommitmentOp(inners []*ics23.InnerOp, key, value []byte) CommitmentOp
- func NewIAVLCommitmentOp(key []byte, proof *ics23.CommitmentProof) CommitmentOp
- func NewSMTCommitmentOp(key []byte, proof *ics23.CommitmentProof) CommitmentOp
- func NewSimpleMerkleCommitmentOp(key []byte, proof *ics23.CommitmentProof) CommitmentOp
- type StoreInfo
- func (*StoreInfo) Descriptor() ([]byte, []int)
- func (m *StoreInfo) GetCommitId() *CommitID
- func (si StoreInfo) GetHash() []byte
- func (m *StoreInfo) GetName() string
- func (m *StoreInfo) GetStructure() string
- func (m *StoreInfo) Marshal() (dAtA []byte, err error)
- func (m *StoreInfo) MarshalTo(dAtA []byte) (int, error)
- func (m *StoreInfo) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*StoreInfo) ProtoMessage()
- func (m *StoreInfo) Reset()
- func (m *StoreInfo) Size() (n int)
- func (m *StoreInfo) String() string
- func (m *StoreInfo) Unmarshal(dAtA []byte) error
- func (m *StoreInfo) XXX_DiscardUnknown()
- func (m *StoreInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *StoreInfo) XXX_Merge(src proto.Message)
- func (m *StoreInfo) XXX_Size() int
- func (m *StoreInfo) XXX_Unmarshal(b []byte) error
Constants ¶
const ( ProofOpIAVLCommitment = "ics23:iavl" ProofOpSimpleMerkleCommitment = "ics23:simple" ProofOpSMTCommitment = "ics23:smt" )
Proof operation types
Variables ¶
var ( ErrInvalidLengthCommitInfo = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowCommitInfo = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroupCommitInfo = fmt.Errorf("proto: unexpected end of group") )
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 ¶
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 ProofFromByteSlices ¶
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) GetVersion ¶
func (*CommitID) MarshalToSizedBuffer ¶
func (*CommitID) ProtoMessage ¶
func (*CommitID) ProtoMessage()
func (*CommitID) XXX_DiscardUnknown ¶
func (m *CommitID) XXX_DiscardUnknown()
func (*CommitID) XXX_Marshal ¶
func (*CommitID) XXX_Unmarshal ¶
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) 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) GetCommitId ¶
func (*StoreInfo) GetStructure ¶
func (*StoreInfo) MarshalToSizedBuffer ¶
func (*StoreInfo) ProtoMessage ¶
func (*StoreInfo) ProtoMessage()
func (*StoreInfo) XXX_DiscardUnknown ¶
func (m *StoreInfo) XXX_DiscardUnknown()