Submitted by JCN, also found by 0xPhantom
A user can create a position by calling the create function or by simply sending the NFT to the vault via safeTransferFrom. Both of those methods will trigger the V3Vault::onERC721Received function:
V3Vault::onERC721Received
The loan for this position (loans[tokenId]) is instantiated with 0 debt and the NFT is added to storage:
V3Vault::_addTokenToOwner
At this point, the user has only instantiated their position and has not borrowed against it, meaning the positions debt is 0. Additionally, the V3Vault::_repay function does not require the amount to repay a positions debt to be non-zero. Thus, the following will occur when a malicious actor repays the non-existent debt of the newly created position with 0 value:
V3Vault::_repay
As we can see above, repaying an empty position with 0 amount will result in the protocol believing that the loan is being fully repaid (see line 1004). Therefore, the _cleanupLoan internal function will be invoked, which will remove the position from storage and send the NFT back to the user:
V3Vault::_cleanupLoan
Since the users NFT is no longer in the vault, any attempts by the user to borrow against the prematurely removed position will result in a revert since the position is now non-existent.
Users newly created positions can be prematurely removed from the vault before the users can borrow against that position. This would result in the user wasting gas as they attempt to borrow against a non-existence position and are then forced to re-create the position.
Note that sophisticated users are able to bypass this griefing attack by submitting the create and borrow calls in one transaction. However, seeing as there are explicit functions used to first create a position and then to borrow against it, average users can be consistently griefed when they follow this expected flow.
Place the following test inside of the V3Vault.t.sol and run with forge test --mc V3VaultIntegrationTest --mt testGriefNewPosition:
I would recommend validating the amount parameter in the repay function and reverting if amount == 0. Additionally, there can be an explicit reversion if the loan attempting to be repaid currently has 0 debt.
kalinbas (Revert) confirmed
Revert mitigated:
Status: Mitigation Confirmed. Full details in reports from thank_you, b0g0 and ktg.
