Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: store audit changes #11989

Merged
merged 3 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions store/firstlast.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
sdkkv "github.com/cosmos/cosmos-sdk/types/kv"
)

// Gets the first item.
// First gets the first item.
func First(st KVStore, start, end []byte) (kv sdkkv.Pair, ok bool) {
iter := st.Iterator(start, end)
if !iter.Valid() {
Expand All @@ -18,7 +18,7 @@ func First(st KVStore, start, end []byte) (kv sdkkv.Pair, ok bool) {
return sdkkv.Pair{Key: iter.Key(), Value: iter.Value()}, true
}

// Gets the last item. `end` is exclusive.
// Last gets the last item. `end` is exclusive.
func Last(st KVStore, start, end []byte) (kv sdkkv.Pair, ok bool) {
iter := st.ReverseIterator(end, start)
if !iter.Valid() {
Expand Down
2 changes: 1 addition & 1 deletion store/tools/ics23/iavl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ current value). This returns an error if the key does not exist in the tree.

`func CreateNonMembershipProof(tree *iavl.MutableTree, key []byte) (*proofs.CommitmentProof, error)`
produces a CommitmentProof that the given key doesn't exist in the iavl tree.
This returns an error if the key does not exist in the tree.
This returns an error if the key exists in the tree.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice


Generalized range proofs are lower in priority, as they are just an optimization of the
two basic proof types, and don't provide any additional capabilities.
Expand Down
4 changes: 2 additions & 2 deletions store/tools/ics23/iavl/helpers/helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Package helpers contains functions to build sample data for tests/testgen

In it's own package to avoid poluting the godoc for ics23-iavl
In it's own package to avoid polluting the godoc for ics23-iavl
*/
package helpers

Expand Down Expand Up @@ -56,7 +56,7 @@ func GenerateIavlResult(size int, loc tmproofs.Where) (*IavlResult, error) {
return res, nil
}

// GetKey this returns a key, on Left/Right/Middle
// GetKey returns a key, on Left/Right/Middle
func GetKey(allkeys [][]byte, loc tmproofs.Where) []byte {
if loc == tmproofs.Left {
return allkeys[0]
Expand Down
2 changes: 1 addition & 1 deletion store/tools/ics23/smt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It exposes a two main functions :
produces a CommitmentProof that the given key exists in the SMT (and contains the current value). This returns an error if the key does not exist in the tree.

`func CreateNonMembershipProof(tree *smt.SparseMerkleTree, key []byte, preimages PreimageMap) (*ics23.CommitmentProof, error)`
produces a CommitmentProof that the given key doesn't exist in the SMT. This returns an error if the key does not exist in the tree.
produces a CommitmentProof that the given key doesn't exist in the SMT. This returns an error if the key exists in the tree.
This relies on an auxiliary `PreimageMap` object which provides access to the preimages of all keys in the tree based on their (hashed) path ordering.


Expand Down
2 changes: 1 addition & 1 deletion store/tools/ics23/smt/helpers/helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Package helpers contains functions to build sample data for tests/testgen

In it's own package to avoid poluting the godoc for ics23-smt
In it's own package to avoid polluting the godoc for ics23-smt
*/
package helpers

Expand Down
19 changes: 8 additions & 11 deletions store/tools/ics23/smt/helpers/random.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package helpers

import (
crand "crypto/rand"
"encoding/binary"
"fmt"
rand "math/rand"
)

Expand All @@ -24,11 +21,11 @@ func randStr(n int) string {
return string(b)
}

func crandSeed() int64 {
var seed int64
err := binary.Read(crand.Reader, binary.BigEndian, &seed)
if err != nil {
panic(fmt.Sprintf("could not read random seed from crypto/rand: %v", err))
}
return seed
}
// func crandSeed() int64 {
// var seed int64
// err := binary.Read(crand.Reader, binary.BigEndian, &seed)
// if err != nil {
// panic(fmt.Sprintf("could not read random seed from crypto/rand: %v", err))
// }
// return seed
// }
4 changes: 2 additions & 2 deletions store/tracekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ func (tkv *Store) Has(key []byte) bool {
}

// Iterator implements the KVStore interface. It delegates the Iterator call
// the to the parent KVStore.
// to the parent KVStore.
func (tkv *Store) Iterator(start, end []byte) types.Iterator {
return tkv.iterator(start, end, true)
}

// ReverseIterator implements the KVStore interface. It delegates the
// ReverseIterator call the to the parent KVStore.
// ReverseIterator call to the parent KVStore.
func (tkv *Store) ReverseIterator(start, end []byte) types.Iterator {
return tkv.iterator(start, end, false)
}
Expand Down
6 changes: 3 additions & 3 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type StoreRename struct {
NewKey string `json:"new_key"`
}

// IsDeleted returns true if the given key should be added
// IsAdded returns true if the given key should be added
func (s *StoreUpgrades) IsAdded(key string) bool {
if s == nil {
return false
Expand Down Expand Up @@ -192,7 +192,7 @@ type CommitMultiStore interface {

// BasicKVStore is a simple interface to get/set data
type BasicKVStore interface {
// Get returns nil iff key doesn't exist. Panics on nil key.
// Get returns nil if key doesn't exist. Panics on nil key.
Get(key []byte) []byte

// Has checks if a key exists. Panics on nil key.
Expand Down Expand Up @@ -338,7 +338,7 @@ type StoreKey interface {
}

// CapabilityKey represent the Cosmos SDK keys for object-capability
// generation in the IBC protocol as defined in https://github.com/cosmos/ics/tree/master/spec/ics-005-port-allocation#data-structures
// generation in the IBC protocol as defined in https://github.com/cosmos/ibc/tree/master/spec/core/ics-005-port-allocation#data-structures
type CapabilityKey StoreKey

// KVStoreKey is used for accessing substores.
Expand Down
4 changes: 2 additions & 2 deletions store/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"github.com/cosmos/cosmos-sdk/types/kv"
)

// Iterator over all the keys with a certain prefix in ascending order
// KVStorePrefixIterator iterates over all the keys with a certain prefix in ascending order
func KVStorePrefixIterator(kvs KVStore, prefix []byte) Iterator {
return kvs.Iterator(prefix, PrefixEndBytes(prefix))
}

// Iterator over all the keys with a certain prefix in descending order.
// KVStoreReversePrefixIterator iterates over all the keys with a certain prefix in descending order.
func KVStoreReversePrefixIterator(kvs KVStore, prefix []byte) Iterator {
return kvs.ReverseIterator(prefix, PrefixEndBytes(prefix))
}
Expand Down
4 changes: 2 additions & 2 deletions store/types/validity.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package types

// Check if the key is valid(key is not nil)
// AssertValidKey checks if the key is valid(key is not nil)
func AssertValidKey(key []byte) {
if len(key) == 0 {
panic("key is nil")
}
}

// Check if the value is valid(value is not nil)
// AssertValidValue checks if the value is valid(value is not nil)
func AssertValidValue(value []byte) {
if value == nil {
panic("value is nil")
Expand Down