
Reproducing a Cosmos EVM Vesting-Balance Underflow Across Ledger Layers
When an EVM-compatible chain also maintains Cosmos account balances, a balance change can cross two ledgers—and a bug in either the accounting source or the reconciliation step can turn a staking operation into a catastrophic balance corruption. The TAC incident described a specific failure chain: staking locked vesting tokens reduced the EVM spendable balance below zero, the result wrapped, and commit-time reconciliation changed the real staking-pool balance without applying the protocol-account guard used elsewhere.
You can reproduce the arithmetic and reconciliation failure with a small Solidity model, but Solidity alone cannot reproduce the Cosmos module’s bank, staking, or commit behavior. Treat the model as a focused regression test; verify the actual fix against the affected chain binary and its module integration tests.
Environment and baseline specifications
The incident described in TAC’s September 2026 post-mortem affected a shared Cosmos EVM module. The source does not identify an exact module release, Solidity compiler version, or advisory/CVE identifier. Do not infer one: pin the affected and patched Cosmos node revisions from the chain operator’s incident artifacts before attempting a binary-level reproduction.
For the EVM-side arithmetic model below, use Solidity ^0.8.24, Foundry, and the Cancun EVM. The model deliberately uses unchecked to represent the wraparound behavior the incident describes; normal Solidity 0.8 checked subtraction would revert instead. This is a behavioral test harness, not a claim that the original defect was implemented in a Solidity contract.
Example foundry.toml:
[profile.default]
src = "src"
test = "test"
solc_version = "0.8.24"
evm_version = "cancun"
optimizer = true
optimizer_runs = 200
Use the chain’s actual Cosmos SDK and Cosmos EVM dependencies for the node-level reproduction. The source context does not provide their versions, so a Foundry dependency cannot substitute for pinning the production module revision.
The vulnerable mechanism: two ledgers, one wrong balance
In a Cosmos EVM chain, an account’s balance may be represented both in the Cosmos-side bank/staking state and in EVM-facing account state. In the incident’s reported sequence:
- A user staked tokens that were locked by a vesting schedule.
- The Cosmos staking operation acted on those tokens, but the EVM-side adjustment used the account’s spendable balance.
- Because the staked amount was locked, spendable balance could be zero. The EVM-side deduction nevertheless proceeded and wrapped below zero.
- The resulting enormous EVM balance could be transferred to the staking pool.
- At commit, reconciliation altered Cosmos-side balances to match EVM-side balances. The protocol-account guard did not cover this reconciliation path.
The critical distinction is between total account balance and spendable balance. A vesting account can own tokens that are not transferable, while still having a nonzero total balance. Staking changes the location or accounting status of tokens; it must not be validated by subtracting the stake from an unrelated zero spendable balance.
A Solidity sketch of the dangerous arithmetic is:
function recordStake(uint256 spendable, uint256 amount)
internal pure returns (uint256)
{
// Models a legacy unchecked subtraction in an EVM accounting layer.
unchecked {
return spendable - amount;
}
}
If spendable == 0 and amount == 1, the result is type(uint256).max. In production, the defect is not fixed merely by putting a checked subtraction in a Solidity contract: the balance source and the Cosmos-to-EVM reconciliation path must also be corrected.
Minimal Foundry reproduction
This harness models the two relevant properties: an unchecked deduction from spendable balance, and a commit step that trusts the EVM ledger when reconciling a protected pool. It is intentionally small so a regression test can target the arithmetic and the missing guard separately.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract DualLedgerModel {
mapping(address => uint256) public evmBalance;
mapping(address => uint256) public cosmosBalance;
address public immutable pool;
constructor(address pool_) {
pool = pool_;
}
function stakeLocked(
address account,
uint256 spendable,
uint256 amount
) external {
// The Cosmos staking action is not represented here. This line models
// the faulty EVM-side deduction from spendable balance.
uint256 next;
unchecked {
next = spendable - amount;
}
evmBalance[account] = next;
}
function send(address from, address to, uint256 amount) external {
require(evmBalance[from] >= amount, "insufficient EVM balance");
unchecked {
evmBalance[from] -= amount;
evmBalance[to] += amount;
}
}
function reconcile(address account) external {
// Vulnerable abstraction: commit applies an EVM balance to Cosmos
// state without checking whether account is protocol-controlled.
cosmosBalance[account] = evmBalance[account];
}
function reconcilePool() external {
reconcile(pool);
}
}
A direct regression test should assert both the wrap and the failure to protect the pool:
function test_lockedStakeWrapsAndCanReachPool() public {
address attacker = address(0xA11CE);
uint256 lockedStake = 1;
model.stakeLocked(attacker, 0, lockedStake);
assertEq(model.evmBalance(attacker), type(uint256).max);
uint256 poolBalance = model.evmBalance(address(pool));
uint256 amount = type(uint256).max - poolBalance;
model.send(attacker, address(pool), amount);
model.reconcilePool();
// This assertion captures the unsafe behavior, not the desired invariant.
assertEq(model.cosmosBalance(address(pool)), model.evmBalance(address(pool)));
}
The full incident involved further balance movements and chain commit semantics; this model does not reproduce the staking module, bank keeper, transaction cache, or validator-controlled halt. Its purpose is to make the wraparound and unguarded reconciliation assumptions explicit. For a node-level reproducer, replay the same transaction against an isolated instance of the affected binary and patched binary, then compare EVM account state, Cosmos bank balances, staking-pool balance, and total supply.
Production fix: correct the source and guard the sink
A robust fix has to address all three reported defects, not just the arithmetic symptom.
Use the correct accounting quantity. A staking operation must validate and update the appropriate total or locked balance, rather than subtracting the staked amount from spendable balance when that value does not represent the funds being staked. Keep vesting schedules and staking locks explicit in the accounting model; do not treat “not spendable” as “not owned.”
Reject underflow. The EVM-side balance update must fail atomically if the relevant balance is insufficient. Do not use unchecked subtraction, saturating subtraction, or a conversion that silently wraps. In Go or another node implementation, use checked arithmetic and propagate the error through the transaction cache so no partial staking or EVM-state changes commit.
Enforce protocol-account invariants at every mutation boundary. A guard applied only to one balance-change path is incomplete if EVM transfers can later be copied into Cosmos state at commit. Validate protected accounts during reconciliation, and reject a commit that would create an invalid pool balance. The check must be applied to the final state transition, not only to the earlier operation that initiated it.
The desired invariant is stronger than “balances do not wrap”:
For every successful transaction, each Cosmos account balance reconciles to its permitted EVM balance, and protocol-controlled accounts cannot be altered through an unguarded commit path.
That invariant should be checked alongside total supply and staking liabilities. Related cross-ledger accounting concerns also arise when normal token transfers cross module boundaries; see Preventing ERC-20 Return Value Assumptions in Solidity for a separate example of why callers must not assume external token operations succeeded as intended.
Quantitative trade-offs
The following gas figures are structural, not benchmarks for the TAC node. The Solidity harness uses ordinary EVM operations; Cosmos keeper and commit costs depend on the specific chain binary and state backend.
| Approach | Underflow behavior | Guard coverage | Cost or complexity |
|---|---|---|---|
| Unchecked spendable subtraction | Wraps modulo \(2^{256}\) | None at reconciliation | One subtraction; unsafe |
| Checked subtraction only | Reverts on insufficient input | Does not fix wrong balance source or missed commit guard | Revert path; incomplete |
| Correct balance source plus checked update | Rejects invalid stake accounting | Depends on reconciliation guard | Constant-time accounting |
| Correct source, checked update, guarded commit | Rejects invalid state transition | Covers both EVM and Cosmos mutation paths | Constant-time checks; strongest invariant |
The key trade-off is not a meaningful per-transaction gas saving: these are node-level correctness checks, and the dominant cost is typically state access and execution. Removing a guard to save a small constant amount of work is unacceptable when it allows a protected pool to be reconciled to an attacker-controlled value.
Differential verification: test the node, not just the model
A useful regression workflow compares the same exploit transaction against two pinned builds:
- Start isolated chains from identical genesis state, including a vesting account with locked tokens and a funded staking pool.
- Replay the transaction sequence against the affected revision and the patched revision.
- Capture the EVM account balances before and after each operation, Cosmos bank balances, staking state, and total supply.
- Require the patched build to reject the invalid transition atomically: no attacker balance increase, no pool loss, and no supply change.
- Run the ordinary staking and vesting suites to ensure valid staking of unlocked and locked funds still follows the intended policy.
For the Solidity arithmetic harness:
forge test --match-test test_lockedStakeWrapsAndCanReachPool -vvvv
forge test --fuzz-runs 10000
For the actual Cosmos module, use the repository’s pinned test command and preserve the exact binary, genesis, and transaction bytes as regression artifacts. Do not claim a Solidity fuzz test proves the Cosmos commit path safe. The source report says the exploit was reproduced against the live mainnet binary on an isolated network and that the patched replay reverted; that binary-level differential is the relevant acceptance test.
Also test boundary values: zero stake, stake equal to the relevant balance, one unit above it, fully locked vesting balance, partially vested balance, and a pool whose balance is zero. Assert atomicity after every expected failure. If rounding or denomination conversion occurs between modules, test values immediately below and above conversion boundaries; arithmetic drift across layers can compound balance mismatches, as illustrated by Reproducing Balancer Stable-Pool Rounding Drift with Foundry.
Finally, test the guard through each state mutation route: direct EVM transfer, staking and unstaking, module-originated balance updates, and end-of-transaction reconciliation. The reported incident’s protocol-account filter existed, but did not protect the path that mattered. A test that exercises only the guarded path can pass while the vulnerable commit route remains open.
Production pitfalls
A Solidity uint256 wrap is well-defined modulo \(2^{256}\) inside an unchecked block. That does not mean every Cosmos implementation uses Solidity arithmetic: reproduce the exact node code and integer conversion semantics rather than assuming the EVM contract language defines module behavior.
Likewise, “no mint” does not mean “no accounting corruption.” The TAC report describes a drain in which the pool’s backing decreased while the attacker’s balance increased, with total supply unchanged. Therefore, test conservation and backing invariants in addition to total supply.
Do not patch only the attacker-facing staking entry point. The report’s third defect was that the protocol-account filter did not cover direct EVM balance changes followed by commit-time reconciliation. Audit the full mutation graph, including cached state, module keepers, and commit hooks. If a chain supports upgrades, verify that the fix is active on every validator before resuming block production.
For broader cross-layer invariant design, see Modeling Vesting-Balance Invariants Across Cosmos SDK and EVM State.
Frequently Asked Questions (FAQ)
Does Solidity 0.8 prevent the Cosmos EVM vesting-balance underflow?
Solidity 0.8 checks ordinary arithmetic by default, but the incident concerned a shared Cosmos EVM module and its cross-ledger accounting path. A Solidity harness can model the wrap using unchecked; it cannot establish how a particular node revision performs subtraction or reconciliation.
What exact vulnerability ID was assigned to the TAC Cosmos EVM incident?
The supplied TAC post-mortem does not state a CVE, SOL identifier, or other public advisory ID. Do not attach an unrelated identifier; use the affected and patched module revisions documented by the chain and upstream maintainers.
What should a patched build prove in a differential replay?
The patched build should reject the invalid transaction atomically, leaving the attacker’s balance, staking-pool backing, and total supply unchanged. It should also pass valid vesting and staking tests, including cases where locked and spendable balances differ.