# Vesting account preemption attack preventing future contract deployment

Attacker pre-creates a PermanentLockedAccount at a deterministic future contract address, so deployment stores bytecode without a codeHash, orphaning the contract and locking funds.

- Payout: Audit contest
- Severity: high
- Program: Nibiru
- Found by: gh8eo
- Disclosed: 2025-02-24
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-11-nibiru-findings/issues/60
- Library page: https://bugbountylibrary.com/r/c4%3A2024-11-nibiru%3AH-01
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:business-logic

**Target:** Cosmos SDK vesting module / EVM contract deployment (x/evm statedb)
**Root cause:** EVM and Cosmos addresses share the same byte space, so a vesting account can occupy an address the EVM would use for a contract. SetAccount only writes codeHash when the account implements EthAccountI; a PermanentLockedAccount does not, so deployed bytecode is stored but unreachable.
**Steps:**
1. Victim deploys Factory contract; child addresses are deterministic via `crypto.CreateAddress(factoryAddr, nonce)`.
2. Attacker computes the next child address, e.g. `crypto.CreateAddress(factoryAddr, 1)`.
3. Attacker calls `MsgCreatePermanentLockedAccount` (CLI: `nibid tx vesting create-permanent-locked-account <childAddr> 10unibi --from attacker`) targeting that address.
4. Victim calls `makeChild` on Factory; tx succeeds and bytecode is written to state.
5. `GetAccount(childAddr).CodeHash == evm.EmptyCodeHash`; calls to the child execute no code (code is nil), so funds sent with deployment are locked.
6. Repeat across nonces in a loop to block all future child deployments.
**How found:** Code-reading of `SetAccount` in x/evm/keeper/statedb.go showed codeHash is only set for EthAccountI; combined with the observation that EVM and Cosmos addresses share bytes and contract addresses are deterministic, the researcher hypothesized a vesting account could squat a future contract address.
**Exploitation:** Attacker only needs gas to create permanent locked accounts at predictable addresses. Because contract addresses derive from deployer address + nonce, the attacker front-runs deployment by registering the address as a vesting account; subsequent deployments succeed but produce orphaned bytecode with no codeHash, making the contract and any attached funds permanently inaccessible.
**Escalation:** Looping over many nonces lets the attacker block every future child contract of a factory, and targeting ecosystem-critical addresses (e.g. planned LayerZero/Uniswap deployments) can orphan high-value contracts.
**Insight:** When an EVM is bolted onto a Cosmos-style account system, check whether non-EVM account types can occupy addresses the EVM treats as contracts; deterministic CREATE addresses (deployer+nonce) make such squatting front-runnable, and any account-type check that gates codeHash assignment is a squatting primitive.

## Proof of concept (copied exactly from the original report)

**Go test creating permanent locked account at predicted child address**

```
expectedChildAddr := crypto.CreateAddress(factoryAddr, 1)
	var msgServer vestingtypes.MsgServer
	msgServer = vesting.NewMsgServerImpl(deps.App.AccountKeeper, deps.App.BankKeeper)
	lockedCoin := sdk.NewInt64Coin("unibi", 100)
	lockResp, err := msgServer.CreatePermanentLockedAccount(deps.Ctx, vestingtypes.NewMsgCreatePermanentLockedAccount(
		attacker.NibiruAddr,
		eth.EthAddrToNibiruAddr(expectedChildAddr),
		sdk.Coins{lockedCoin},
	))
	s.Require().NoError(err)
	s.Require().NotNil(lockResp)
```

**CLI command to create permanent locked account**

```
nibid tx vesting create-permanent-locked-account nibi136uvp9vz8qplx4rc32fpju5natuacvvgau96c6 10unibi --from attacker
```

