Logical Error in Timestamp Condition for Option Renewal `BorrowLib.getOptionFeesToPay()`
The renewal eligibility check in BorrowLib.getOptionFeesToPay() uses a logical AND between two timestamp comparisons that can never both be true, so the check never reverts. An attacker can call renewOptions() at any time, outside the intended 15-to-30-day window.
0xAadi Follow with 0xAristos, 0xundiscover and 15 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/834
Found by
0xAadi, 0xAristos, 0xundiscover, Audinarey, KungFuPanda, LordAlive, ParthMandale, futureHack, itcruiser00, nuthan2x, smartkelvin, tedox, theweb3mechanic, tjonair, valuevalk, volodya, wellbyt3, xKeywordx
Summary
A logical error exists in the BorrowLib.getOptionFeesToPay() function's timestamp condition, which is intended to enforce a renewal window for options. The current implementation uses a logical AND (&&) that results in an impossible condition, potentially leading impossible eligibility check to renew position for users.
Root Cause
The issue is found in the following code snippet within the getOptionFeesToPay() function:
// check the user is eligible to renew position
if (
block.timestamp <
@> depositDetail.optionsRenewedTimeStamp + 15 days &&
block.timestamp >
depositDetail.optionsRenewedTimeStamp + 30 days
) revert IBorrowing.Borrow_DeadlinePassed();
The condition uses a logical AND (&&), requiring the timestamp to be both less than 15 days and more than 30 days after optionsRenewedTimeStamp, which is logically impossible.
This results in the condition never being true, potentially allowing renewals outside the intended window.
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
- The attacker calls the
renewOptions()function at any time, regardless of the intended renewal window. - Due to the logical AND (&&) condition, the check for the renewal window never triggers a revert, as no timestamp can satisfy both conditions simultaneously.
- The attacker successfully renews the options outside the intended 15 to 30-day window.
Impact
The intended enforcement of a renewal window is not functioning as expected, allowing renewals at any time. This could lead to unauthorized renewals.
PoC
No response
Mitigation
Change the condition to use a logical OR (||) to correctly enforce the renewal window:
// check the user is eligible to renew position
if (
block.timestamp <
- depositDetail.optionsRenewedTimeStamp + 15 days &&
+ depositDetail.optionsRenewedTimeStamp + 15 days ||
block.timestamp >
depositDetail.optionsRenewedTimeStamp + 30 days
) revert IBorrowing.Borrow_DeadlinePassed();
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
Impact
The intended enforcement of a renewal window is not functioning as expected, allowing renewals at any time, which could lead to unauthorized renewals.
What the attacker needed
None
The fix
The condition should be changed to use a logical OR (||) so that the renewal window is correctly enforced.
How it was found
- The attacker calls the renewOptions() function at any time, regardless of the intended renewal window.
- The renewal window check never reverts because no timestamp can satisfy both conditions.
- The attacker successfully renews the options outside the intended 15 to 30-day window.
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 has a rule that options can only be renewed between 15 and 30 days after the last renewal. The code that enforces this rule uses 'AND' instead of 'OR', so it asks for a time that is both before 15 days and after 30 days at once, which can never happen. Because the check never triggers, anyone can renew whenever they like.
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.