Reproduced Exploit
Lend: cross-chain repayment updates the wrong borrow balance
Chain
Other
Category
untagged
Date
Jan 1970
Source
AuditVault
EVM Playground
Source-level debugger — step opcodes and Solidity in sync
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. No backend, no live RPC.
Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: CrossChainRouter.sol#L368. Standalone Foundry PoC and full write-up: 58393-lend-cross-chain-repayment-updates-the-wrong-borrow-balance_exp in the
evm-hack-registrymirror.
Vulnerability classes: vuln/logic · vuln/reward-accounting
Reproduction: a faithful minimal reproduction of the vulnerable finding — the vulnerable
repayBorrowInternalbody is reproduced verbatim (marked@>) with faithful minimal doubles; local deploy, no fork.
Root cause#
A cross-chain repayment flows through CoreRouter.repayBorrowInternal(). It correctly reads the debt from the cross-chain accounting (borrowWithInterest) when _isSameChain == false, but then it updates the same-chain borrow-balance slot instead of the cross-chain crossChainBorrow/crossChainCollateral records. The vulnerable function is reproduced verbatim:
function repayBorrowInternal(
address borrower,
address liquidator,
uint256 _amount,
address _lToken,
bool _isSameChain
) internal {
address _token = lendStorage.lTokenToUnderlying(_lToken);
LTokenInterface(_lToken).accrueInterest();
uint256 borrowedAmount;
if (_isSameChain) {
borrowedAmount = lendStorage.borrowWithInterestSame(borrower, _lToken);
} else {
borrowedAmount = lendStorage.borrowWithInterest(borrower, _lToken);
}
require(borrowedAmount > 0, "Borrowed amount is 0");
uint256 repayAmountFinal = _amount == type(uint256).max ? borrowedAmount : _amount;
IERC20(_token).safeTransferFrom(liquidator, address(this), repayAmountFinal);
// ... repay on the lToken ...
@> lendStorage.updateBorrowBalance(borrower, _lToken, ...); // updates the SAME-CHAIN borrow slot even when _isSameChain == false
}
Because the same-chain slot is written for a cross-chain repay, the cross-chain debt record is never cleared — the borrower's paid-off cross-chain debt lingers, and an unrelated same-chain balance is corrupted.
Why it's exploitable here#
- A borrower has an outstanding cross-chain borrow tracked in
crossChainBorrow. repayCrossChainBorrow→repayBorrowInternal(_isSameChain = false)reads the correct cross-chain debt and pulls the repayment.- The update writes the same-chain borrow slot rather than the cross-chain record, so the cross-chain debt is left intact and a same-chain slot is wrongly mutated.
- Accounting diverges from reality — the repaid cross-chain debt can be repaid/settled again and the same-chain record is corrupted.
Attack path#
Marked-line walkthrough (Playground)#
The EVM Playground pins each step to the exact executed source line in 0xbd4fd5a3…:
- L73 — SafeERC20 pulls repay funds: CoreRouter routes the cross-chain repayment through
SafeERC20.safeTransferFrom, pulling the repay amount from the liquidator. - L74 — Underlying tokens transferred in:
token.transferFrommoves the full cross-chain debt from the liquidator to CoreRouter so the repay can settle. - L232 — One router for both repays: CoreRouter funnels same-chain
repayBorrowand cross-chainrepayCrossChainLiquidationinto the same internal path. - L245 — Same-chain slot holds real debt:
repayBorrowis the same-chain entry that legitimately owns the borrow-balance slot — the very slot the vulnerable update writes. - L277 — Cross-chain debt resolved as target: Inside
repayBorrowInternal,borrowedAmountis read from the cross-chain debt viaborrowWithInterest. - L301 — Wrong borrow slot updated: Root cause: a cross-chain repay (
_isSameChain == false) settles the cross-chain debt but writes the same-chain borrow slot, leaving the cross-chain record uncleared.
PoC#
Registry (Foundry, local deploy — verbatim vulnerable source + harm-asserting test):
cd 58393-lend-cross-chain-repayment-updates-the-wrong-borrow-balance_exp
forge test -vvv
The browser Playground replays the same synthetic opcode-for-opcode and measures the harm: a cross-chain repayment leaves the cross-chain debt uncleared while corrupting the same-chain balance. Both gates are green (registry forge test PASS + Playground _verify-poc VERDICT: PASS).
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 58393-lend-cross-chain-repayment-updates-the-wrong-borrow-balance_exp (evm-hack-registry mirror).
- AuditVault finding: CrossChainRouter.sol#L368.
- Upstream DeFiHackLabs PoC directory: src/test.
Alerts & third-party analyses
- DeFiHackLabs incident explorer: search "Lend: cross-chain repayment updates the wrong borrow balance".
- 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.