resources/STATE_VULNERABILITY_PATTERNS.md · 24000
rformance benefit and risks nil-pointer dereference
- [ ]
cosmossdk.io/collectionsframework: deterministic key encoding (custom key codecs produce consistent bytes),IndexedMapsecondary indexes in sync, noRemove/SetduringWalkiteration (fix: #24460), prefix/range queries used correctly - [ ] Encoding enforced as early as possible — in msg server handler or protobuf definition (
stringin protobuf enforces UTF-8). Careful with invalid UTF-8 string length - [ ] Invalid encoding in input does not halt chain
- [ ] MustUnmarshal usage is safe
- [ ]
MsgUpdateParamshandlers validate parameter bounds — invalid params (rate > 100%, negative values, zero denominators) can be silently set via governance and cause issues inBeginBlock/EndBlock - [ ] Default values are safe:
- Configurable parameters are set explicitly or default values are reviewed
- Initial (genesis) system parameters are validated. Safety checks exist for parameters that get updated from "null" only after the first block (Umee issue)
gettermethods do not return valid values on errors — they should panic or return nil
- [ ] Amino (
LegacyAmino) only for backward compatibility (legacy JSON signing, CLI proposals). New modules use protobuf exclusively - [ ] If Ethereum addresses used, NOT using
HexToAddress(does not verify format, ignores errors) - [ ]
AnteHandlers enforce non-zero fee to prevent spam. See Cosmos discussion - [ ] Parsing of empty
Coin(s)considers any amount of extra whitespace — relevant source. For example, checkingmsg.Funds == "" || msg.Funds == "0"is incomplete; use the SDK's parsing functions instead of manual string comparison
22 EVENTS & LOGGING (INCLUDING CacheContext EVENT LEAK)
Description: Events are critical for indexers, relayers, and monitoring tools. Incorrect event handling breaks the ecosystem. A particularly dangerous pattern is the CacheContext event leak: when CacheContext is used to tentatively execute operations, state changes are correctly rolled back on failure, but events are still emitted to the parent context. Off-chain systems (bridges, indexers) trusting events without verifying on-chain state can be exploited.
Detection Patterns:
// VULNERABLE: CacheContext event leak (Huckleberry, Finding 4)
func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) exported.Acknowledgement {
cacheCtx, writeFn := ctx.CacheContext()
// Execute in cached context — emits events to cacheCtx
err := k.processPacket(cacheCtx, packet)
if err != nil {
// State is rolled back (writeFn not called)
// BUT events from cacheCtx are still visible to parent context!
return channeltypes.NewErrorAcknowledgement(err)
}
writeFn()
return channeltypes.NewResultAcknowledgement([]byte{1})
}
// Bridge monitors see valid deposit events for transfers that never happened
// Attacker gets credited on the bridge without tokens actually moving
What to Check:
- [ ] Enough event logs to debug on-chain transactions
- [ ] Events NOT generated for failed transactions — Huckleberry: IBC Event Hallucinations
- [ ]
CacheContextusage reviewed: events emitted in cached context are visible even ifwriteFnis never called — state rolls back but events persist - [ ] Off-chain systems (bridges, indexers, relayers) do NOT rely solely on events without verifying on-chain state
- [ ] Custom IBC
OnRecvPacketthat returns error ack does not emit misleading deposit/transfer events - [ ] No log injection possible
References:
23 DEPRECATED MODULES
As of v0.53.5+. Flag usage and advise migration.
x/crisis(Invariant type) — deprecated, will be removed. Use simulations (simsxframework in v0.53+) and property-based tests insteadx/nft— deprecated (#24575), moving to cosmos-legacyx/group— deprecated (#24571), moving to cosmos-legacy. EndBlocker had chain-halt bugs (GHSA-47ww-ff84-4jrg, GHSA-x5vx-95h7-rv4p, fixed v0.50.12/v0.53.0)x/params— deprecated, modules use direct keeper param storage viacollectionsValidateBasic()— deprecated and facultative (viaHasValidateBasicinterface). Validation belongs in msg server handlers- ed25519 tx signing — added in v0.53.0 (#24030). Chains should explicitly decide which key types to permit. Unlike secp256k1, ed25519 is not compatible with Ledger hardware wallets without custom apps