Skip to main content
Menu
Advisories

Staking claims can be replayed against NotBondedPool after contract self-destruction

GHSA-C6XV-PPPP-RJW6Published Updated GitHub

Description

Cosmos EVM maps EVM contract addresses to Cosmos accounts and exposes native staking to EVM contracts through the staking precompile, including delegating and undelegating the bond denomination. When a contract self-destructs, the EVM StateDB commit deletes the underlying Cosmos auth account, but the staking state associated with that address — including unbonding delegations (UBDs) and their maturity-queue references — is stored independently and survives.

An unprivileged contract can exploit this to repeatedly debit the shared NotBondedPool module account without crediting anyone, effectively destroying the pooled funds that back honest users' unbonding claims. For a stale unbonding claim of X, an attacker can manufacture an arbitrary number of maturity-queue references to it and destroy up to the entire available NotBondedPool balance per cycle, leaving matured claims of ordinary users unpaid and the chain undercollateralized. The affected chain's SDK dependency contains the same queue and payout behavior, so the vulnerability depends only on permissionless contract deployment and the enabled staking precompile.

Details

When a contract executes SELFDESTRUCT, the EVM StateDB commit calls the keeper's DeleteAccount, which removes the corresponding Cosmos auth account (x/vm/keeper/statedb.go). However, staking state — delegations, redelegations, and unbonding delegations (UBDs) — is stored independently of the auth account and is not deleted or invalidated. A contract can therefore use the staking precompile to undelegate and create a pending unbonding claim, then self-destruct in the same transaction, leaving a mature unbonding claim owned by a nonexistent account.

At the claim's maturity time, staking EndBlock iterates the mature UBD queue and calls CompleteUnbonding. Bank payout first debits the amount from the shared NotBondedPool module account and only afterward validates the recipient; because the recipient account no longer exists, the transfer fails. The UBD is only persisted as removed after all payments succeed, so on failure the mature claim remains in store. EndBlock swallows the error and continues, so the pool debit is committed while nobody is credited and no burn occurs — the coins vanish and supply - sum(all bank balances) increases accordingly.

The maturity queue stores only a delegator/validator pair, and undelegation inserts queue references without deduplication; cancelling an unbonding removes or reduces the UBD entry but not the queue reference. An attacker can therefore recreate the same contract address via CREATE2, generate an arbitrary number of queue references pointing at the stored stale claim through repeated undelegation/cancellation, and self-destruct again. Each mature reference triggers another payout attempt: each one debits NotBondedPool before failing on the missing account, replaying the same claim. For a claim of X with N references and available pool balance P, the batch destroys X * min(N, floor(P / X)) — funds supplied by ordinary unbonding users, whose claims then go unpaid. The stale claim survives each cycle, so the attack is repeatable against future unbonding inflows, leaving the chain undercollateralized until bespoke state repair. A variant of the issue can also replay credited claims to steal pooled funds, and the depleted pool can additionally cause deterministic chain halts when later validator-set transitions require more funds than remain.

Patches

The fix makes DeleteAccount refuse to delete a contract account that still holds any staking positions — delegations, redelegations, or unbonding delegations — before clearing its balance and removing the auth account. Self-destructing such a contract now returns an error, so no orphaned staking claim can be created.

Chain operators must upgrade to v0.6.4 or v0.7.4 (or later).

Workarounds

Disabling the staking precompile (or restricting permissionless contract deployment) prevents the attack. Chains that require the precompile should upgrade; there is no other mitigation for funds already removed from the pool short of coordinated state repair or recapitalization.

References

Credits

Originally reported through the Cosmos bug bounty program by berndartmueller.

Please reach out to our security email, security@cosmoslabs.io to get further details, or via our bug bounty program immunefi.com/bug-bounty/cosmos to report known vulnerabilities.

Affected versions

References

GitHub · cosmos/evm