Function foreclosureTimeUser returns a shorter user’s foreclosure time than expected
The treasury contract's foreclosure-time calculation mixed the user's last rent calculation timestamp with a deposit-derived duration, so the resulting foreclosure time was earlier than it should be. This could cause incorrect determination of the new owner of a card when foreclosure is evaluated.
Submitted by shw
The function foreclosureTimeUser of RCTreasury underestimates the user’s foreclosure time if the current time is not the user’s last rent calculation time. The underestimation of the foreclosure time could cause wrong results when determining the new owner of the card.
The variable timeLeftOfDeposit at line 668 is calculated based on depositAbleToWithdraw(_user), the user’s deposit minus the rent from the last rent calculation to the current time. Thus, the variable timeLeftOfDeposit indicates the time left of deposit, starting from now. However, at line 672, the foreclosureTimeWithoutNewCard is calculated by timeLeftOfDeposit plus the user’s last rent calculation time instead of the current time. As a result, the user’s foreclosure time is reduced. From another perspective, the rent between the last rent calculation time and the current time is counted twice.
Recommend changing depositAbleToWithdraw(_user) at line 669 to user[_user].deposit. Or, change user[_user].lastRentCalc at both line 672 and 678 to block.timestamp.
Splidge (Reality Cards) confirmed and resolved:
phew, this was one to wrap your head around. I went with the first recommended mitigation because I believe the second one could causes issues if the user had already foreclosed,
depositAbleToWithdrawwould return 0 and soforeclosureTimeWithoutNewCardwould incorrectly show asblock.timestamp. Fix implemented hereReally nice spot this one. Many thanks for such an in-depth look into the maths.
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 foreclosure time was computed by adding a duration measured from the current time to the user's last rent calculation timestamp, effectively counting the rent between those two points twice.
Impact
The user's foreclosure time is underestimated, which could produce wrong results when determining the new owner of the card.
What the attacker needed
User has an active deposit; current time differs from last rent calculation
The fix
The project changed the deposit lookup to use the raw user deposit instead of the withdrawable amount, and the fix was implemented.
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.
A smart contract keeps track of how long a user's deposit will last before they lose their card. The code worked out the remaining time correctly but then added it to an old timestamp instead of the current time, so the deadline came out too early. That could make the contract pick the wrong new owner.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.