Malicious seller forced break lockCapital()
A malicious seller can burn their NFT after buying protection, causing the protocol's lockCapital() function to revert because it calls ownerOf() on a burned token. This prevents the lending pool from moving to a late state, so all protections expire and the seller keeps the premium while buyers lose compensation.
bin2chen Follow with clems4ever
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-carapace-judging/issues/31
Found by
bin2chen, clems4ever
Summary
Malicious burn nft causes failure to lockCapital() ,seller steady earn PremiumAmount, buyer will be lost compensation
Vulnerability Detail
When the status of the lendingPool changes from Active to Late, the protocol will call ProtectionPool.lockCapital() to lock amount
lockCapital() will loop through the active protections to calculate the lockedAmount.
The code is as follows:
function lockCapital(address _lendingPoolAddress)
external
payable
override
onlyDefaultStateManager
whenNotPaused
returns (uint256 _lockedAmount, uint256 _snapshotId)
{
....
uint256 _length = activeProtectionIndexes.length();
for (uint256 i; i < _length; ) {
...
uint256 _remainingPrincipal = poolInfo
.referenceLendingPools
.calculateRemainingPrincipal( //<----------- calculate Remaining Principal
_lendingPoolAddress,
protectionInfo.buyer,
protectionInfo.purchaseParams.nftLpTokenId
);
The important thing inside is to calculate the _remainingPrincipal by referenceLendingPools.calculateRemainingPrincipal()
function calculateRemainingPrincipal(
address _lendingPoolAddress,
address _lender,
uint256 _nftLpTokenId
) public view override returns (uint256 _principalRemaining) {
...
if (_poolTokens.ownerOf(_nftLpTokenId) == _lender) { //<------------call ownerOf()
IPoolTokens.TokenInfo memory _tokenInfo = _poolTokens.getTokenInfo(
_nftLpTokenId
);
....
if (
_tokenInfo.pool == _lendingPoolAddress &&
_isJuniorTrancheId(_tokenInfo.tranche)
) {
_principalRemaining =
_tokenInfo.principalAmount -
_tokenInfo.principalRedeemed;
}
}
}
GoldfinchAdapter.calculateRemainingPrincipal() The current implementation will first determine if the ownerOf the NFTID is _lender
There is a potential problem here, if the NFTID has been burned, the ownerOf() will be directly revert, which will lead to calculateRemainingPrincipal() revert,and lockCapital() revert and can't change status from active to late
Let's see whether Goldfinch's implementation supports burn(NFTID), and whether ownerOf(NFTID) will revert
- PoolTokens has burn() method , if principalRedeemed==principalAmount you can burn it
contract PoolTokens is IPoolTokens, ERC721PresetMinterPauserAutoIdUpgradeSafe, HasAdmin, IERC2981 {
.....
function burn(uint256 tokenId) external virtual override whenNotPaused {
TokenInfo memory token = _getTokenInfo(tokenId);
bool canBurn = _isApprovedOrOwner(_msgSender(), tokenId);
bool fromTokenPool = _validPool(_msgSender()) && token.pool == _msgSender();
address owner = ownerOf(tokenId);
require(canBurn || fromTokenPool, "ERC721Burnable: caller cannot burn this token");
require(token.principalRedeemed == token.principalAmount, "Can only burn fully redeemed tokens");
_destroyAndBurn(tokenId);
emit TokenBurned(owner, token.pool, tokenId);
}
2.ownerOf() if nftid don't exists will revert with message "ERC721: owner query for nonexistent token"
contract ERC721UpgradeSafe is
Initializable,
ContextUpgradeSafe,
ERC165UpgradeSafe,
IERC721,
IERC721Metadata,
IERC721Enumerable
{
...
function ownerOf(uint256 tokenId) public view override returns (address) {
return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token");
}
If it can't changes to late, Won't lock the fund, seller steady earn PremiumAmount
So there are two risks
- normal buyer gives NFTID to burn(), he does not know that it will affect all protection of the lendingPool
- Malicious seller can buy a protection first, then burn it, so as to force all protection of the lendingPool to expire and get the PremiumAmount maliciously. buyer unable to obtain compensation
Suggested try catch for _poolTokens.ownerOf() If revert, it is assumed that the lender is not the owner
Impact
buyer will be lost compensation
Code Snippet
Tool used
Manual Review
Recommendation
try catch for _poolTokens.ownerOf() If revert, it is assumed that the lender is not the owner
Discussion
vnadoda
@clems4ev3r Fix for this issue: https://github.com/carapace-finance/credit-default-swaps-contracts/pull/64
clems4ev3r
Fix looks good
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the code calls ownerOf() on an NFT that may have been burned, and ownerOf() reverts for nonexistent tokens, causing the entire lockCapital() transaction to fail.
Impact
Buyers lose their compensation because the lending pool cannot transition to late, while the malicious seller keeps the premium; the text does not mention any defence that would limit this.
What the attacker needed
Seller holds a protection NFT; NFT is fully redeemed so it can be burned; lending pool later becomes late
The fix
The issue was fixed by wrapping the ownerOf() call in a try/catch so that a revert is treated as the lender not being the owner.
How it was found
- A seller buys a protection, receiving an NFT representing their position.
- The seller fully redeems the NFT's principal and then burns it.
- When the lending pool later becomes late, the protocol calls lockCapital().
- lockCapital() loops over active protections and calls calculateRemainingPrincipal(), which calls ownerOf() on the burned NFT.
- ownerOf() reverts because the token does not exist, so lockCapital() reverts and the pool cannot move to late.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a borrower fails to repay, the protocol tries to lock funds from protection sellers to compensate buyers. But if a seller destroys (burns) the digital receipt (NFT) for their position, the protocol's check crashes because it asks who owns a token that no longer exists. This crash stops the whole compensation process, letting the seller keep the premium and leaving buyers without cover.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.