sei-protocol/sei-cosmos

Bug: Incorrect Use of Append Function in StoreKeys Method

yuxuan-xie opened this issue · 0 comments

Hello Team,
During a recent code review, I found a persistent bug in the StoreKeys method of our Store struct.

func (rs *Store) StoreKeys() []types.StoreKey {
	res := make([]types.StoreKey, len(rs.keysByName))
	for _, sk := range rs.keysByName {
		res = append(res, sk)
	}
	return res
}

The code can be found at

res := make([]types.StoreKey, len(rs.keysByName))

This is a common bug with respect to append. The original code piece are actually appending new keys at the end of some zero-values, thus doubling the slice size.