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
- type CommitInfo
- func (ci *CommitInfo) CommitID() CommitID
- func (ci *CommitInfo) GetStoreCommitID(storeKey []byte) CommitID
- func (ci *CommitInfo) GetStoreProof(storeKey []byte) ([]byte, *CommitmentOp, error)
- func (m *CommitInfo) GetVersion() uint64
- func (ci *CommitInfo) Hash() []byte
- func (ci *CommitInfo) Marshal() ([]byte, error)
- func (ci *CommitInfo) Unmarshal(buf []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
Constants ¶
const ( ProofOpIAVLCommitment = "ics23:iavl" ProofOpSimpleMerkleCommitment = "ics23:simple" ProofOpSMTCommitment = "ics23:smt" )
Proof operation types
Variables ¶
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 CommitInfo ¶
type CommitInfo struct { Version uint64 StoreInfos []StoreInfo Timestamp time.Time CommitHash []byte }
CommitInfo defines commit information used by the multi-store when committing a version/height.
func (*CommitInfo) CommitID ¶
func (ci *CommitInfo) CommitID() CommitID
func (*CommitInfo) GetStoreCommitID ¶
func (ci *CommitInfo) GetStoreCommitID(storeKey []byte) CommitID
GetStoreCommitID returns the CommitID for the given store key.
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) GetVersion ¶
func (m *CommitInfo) GetVersion() uint64
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 (ci *CommitInfo) Marshal() ([]byte, error)
Marshal returns the encoded byte representation of CommitInfo. NOTE: CommitInfo is encoded as follows: - version (uvarint) - timestamp (varint) - number of stores (uvarint) - for each store:
- store name (bytes)
- store hash (bytes)
- store commit structure (bytes)
func (*CommitInfo) Unmarshal ¶
func (ci *CommitInfo) Unmarshal(buf []byte) error
Unmarshal unmarshals the encoded byte representation of CommitInfo.
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.