Reproduced Exploit
LEND: a cross-chain repayment erases a same-chain debt of 1,000
repayBorrowInternal computes borrowedAmount from the cross-chain record when _isSameChain is false, repays that record, and then still runs the block that updates same-chain debt. A repayment of 100 equals the cross-chain borrowed amount, so delete sameChainDebt removes a separate 1,000 loan. The b…
Loss
Repaying a 100-token cross-chain loan deletes a 1,000-token same-chain debt. The borrower keeps the 1,000. Le…
Chain
Ethereum
Category
logic
Date
May 2025
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. 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.
Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 58385-h-16-coreroutersols-repayborrowinternal-incorrectly-updates. Standalone Foundry PoC and full write-up: 58385-h-16-coreroutersols-repayborrowinternal-incorrectly-updates_exp in the
evm-hack-registrymirror.
Vulnerability classes:
vuln/logic/state-update·vuln/access-control/missing-auth
Key info#
| Field | Value |
|---|---|
| Loss | Repaying a 100-token cross-chain loan deletes a 1,000-token same-chain debt. The borrower keeps the 1,000. Lenders have no record left to collect |
| Vulnerable contract | CoreRouter.repayBorrowInternal |
| Attacker EOA | 0x1111111111111111111111111111111111111111 (the borrower) |
| Attack contract | Exploit |
| Attack tx | Exploit.run() |
| Chain / block / date | Ethereum model · block 0 · 2025-05 |
| Compiler | solc 0.8.27, cancun |
| Bug class | The same-chain balance update is not guarded by _isSameChain |
TL;DR#
repayBorrowInternal computes borrowedAmount from the cross-chain record when _isSameChain is false, repays that record, and then still runs the block that updates same-chain debt. A repayment of 100 equals the cross-chain borrowed amount, so delete sameChainDebt removes a separate 1,000 loan. The borrower keeps those 1,000 tokens. The fixed path, which skips the same-chain write, leaves the 1,000 debt in place.
The vulnerable code#
if (!_isSameChain) {
crossChainDebt[borrower] = borrowedAmount - repayAmountFinal;
}
if (repayAmountFinal == borrowedAmount) {
delete sameChainDebt[borrower]; // @> VULN: this delete runs even when _isSameChain is false
delete borrowedAsset[borrower];
}
- if (repayAmountFinal == borrowedAmount) {
- delete sameChainDebt[borrower];
- delete borrowedAsset[borrower];
- }
+ if (_isSameChain && repayAmountFinal == borrowedAmount) {
+ delete sameChainDebt[borrower];
+ delete borrowedAsset[borrower];
+ }
Root cause#
Same-chain and cross-chain debts are different storage slots, but the cleanup after a repayment always writes the same-chain slot. Equality is tested against the cross-chain amount, so a full cross-chain repay looks like a full same-chain repay.
Preconditions#
- The borrower has a same-chain debt of 1,000 and has received those tokens.
- The borrower has a separate cross-chain debt of 100 and has received those tokens.
- The caller repays exactly 100 with
_isSameChain == false.
Attack walkthrough#
borrowrecords same-chain debt of 1,000 and sends 1,000 tokens.borrowForCrossChainrecords 100 and sends 100 tokens.repayBorrow(..., false)pays 100 back.delete sameChainDebtruns because 100 equals the cross-chain borrowed amount.- The borrower still holds the 1,000 same-chain proceeds.
- Recorded same-chain debt is 0. The pool holds 1,000 and cannot collect the erased loan.
Diagrams#
Impact#
Lenders who funded the 1,000 same-chain loan lose that claim. The borrower keeps the tokens. One cross-chain repayment was enough. The control repayment leaves sameChainDebt at 1,000.
How to reproduce#
cd 58385-h-16-coreroutersols-repayborrowinternal-incorrectly-updates_exp
forge test -vv
Sources#
- AuditVault finding: https://github.com/Auditware/AuditVault/blob/main/findings/58385-h-16-coreroutersols-repayborrowinternal-incorrectly-updates.md
- Sherlock judging issue 782: https://github.com/sherlock-audit/2025-05-lend-audit-contest-judging/issues/782
CoreRouter.repayBorrowInternal: https://github.com/sherlock-audit/2025-05-lend-audit-contest/blob/main/Lend-V2/src/LayerZero/CoreRouter.sol#L459
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 58385-h-16-coreroutersols-repayborrowinternal-incorrectly-updates_exp (evm-hack-registry mirror).
- AuditVault finding: 58385-h-16-coreroutersols-repayborrowinternal-incorrectly-updates.
Alerts & third-party analyses
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.