Reproduced Exploit

OpenTrade: initiateRollover trusts an arbitrary prior loan

initiateRollover is onlyPoolController and passes priorLoan into calculateRollover with no check. That function adds principal() and interest() from whatever address it was given. The active loan would report 110. The controller passes a contract whose principal() is the pool's token balance. The p…

Sep 2023•Ethereum•input-validation•3 min read

Loss

1000 USDC moves from the pool to the controller's loan. The active loan was only 110

Chain

Ethereum

Category

input-validation

Date

Sep 2023

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

The attack is replayed in an in-browser EVM preloaded with the exact dumped fork state. The execution tree shows every call; step by Solidity line or by opcode across all depths — source, Stack, Memory, Storage, Balances (native / ERC-20 / NFT), Transient storage and Return value stay in sync. Click a tree node, opcode, or source line to jump. Query opens a search over the trace: previous and next writes, balance changes and calls, breakpoints, and a diff of everything that changed between two steps. No backend, no live RPC.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 47890-loan-address-validation-ottersec-none-opentrade-pdf. Standalone Foundry PoC and full write-up: 47890-loan-address-validation-ottersec-none-opentrade-pdf_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/input-validation/missing · vuln/logic/missing-validation

Key info#

FieldValue
Loss1000 USDC moves from the pool to the controller's loan. The active loan was only 110
Vulnerable contractPool.initiateRollover
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2023-09
Compilersolc 0.8.27, cancun, via IR
Bug classpriorLoan is not the active loan

TL;DR#

initiateRollover is onlyPoolController and passes priorLoan into calculateRollover with no check. That function adds principal() and interest() from whatever address it was given. The active loan would report 110. The controller passes a contract whose principal() is the pool's token balance. The pool transfers 1000 USDC to the controller's new loan and is left empty.

The vulnerable code#

SOLIDITY
function initiateRollover(address loan, address priorLoan) external onlyPoolController {
    (assetsFromPriorToNextLoan) = calculateRollover(priorLoan); // @> VULN: priorLoan is not required to be the active loan
    liquidity.transfer(loan, assetsFromPriorToNextLoan);
}

OtterSec's patch requires priorLoan == activeLoan before the call.

Root cause#

calculateRollover trusts the loan for the numbers that size a token transfer. The only caller gate is the pool controller. The controller is supposed to roll the active loan, not to choose the oracle for how much cash leaves the pool. Without the equality check, the controller picks both the number and the recipient.

Preconditions#

  • The pool holds 1000 of the liquidity asset.
  • The active loan's principal plus interest is 110.
  • The caller is the pool controller and can deploy a contract with principal() and interest().

Attack walkthrough#

  1. Read the honest rollover: 110.
  2. Call initiateRollover(adminLoan, fakeLoan).
  3. fakeLoan.principal() returns token.balanceOf(pool), which is 1000. Interest is 0.
  4. The pool transfers 1000 to adminLoan.
  5. The pool balance is 0. The excess over the honest figure is 890.

Diagrams#

flowchart TD A["Pool holds 1000 and the active loan is 110"] --> B["Controller calls initiateRollover with a fake priorLoan"] B --> C["VULN calculateRollover reads principal from that address"] C --> D["Fake principal equals the pool balance"] D --> E["Pool transfers 1000 to the controller's loan"] E --> F["Lenders' cash is gone and the honest figure was 110"]

Impact#

Lenders' 1000 USDC is pulled out in one call. A rollover that passes the real active loan moves 110 and leaves 890 in the pool. The controller is a privileged role, and the missing check is what turns that role into an unbounded withdrawal.

Remediation#

Require priorLoan == activeLoan (and the destination loan to be the requested loan) before calculateRollover, as in the OtterSec patch.

How to reproduce#

BASH
cd 47890-loan-address-validation-ottersec-none-opentrade-pdf_exp
forge test -vv

Sources#


Sources & further analysis#

Reproductions & code

Alerts & third-party analyses

  • Web3Sec X hacked database: search.
  • Rekt leaderboard: search.
  • Solodit incident search: search.

These dashboards index community alerts tweets, post-mortems, and independent write-ups. Reach them through the protocol name above to cross-check this reproduction against other analyses.