clober-dex / coupon-finance

Coupon Finance Solidity Contracts
Other
1 stars 0 forks source link

Clarify `endTime()` returned is exclusive #107

Closed detectivekim closed 11 months ago

detectivekim commented 1 year ago

Details

It isn’t immediately clear whether the endTime() value returned is inclusive or exclusive. Based on its usage in _getLiquidationAmount(), one can infer that it is exclusive: if position.expiredWith.endTime() <= block.timestamp for ascertaining position expiry status. However, the exclusivity of the endTime value breaks the inverse property: f◦f−1(x) = x. What we have is _timestampToEpoch(_epochToTimestamp(epoch)) = epoch + 1, which isn’t intuitive.

Mitigation

Consider making endTime() inclusive instead, where _epochToTimestamp() returns a second lesser.

return (
    (months & 0xffff) + 365 * (year - 1970) + (year - 1969) / 4 - (year -
    1901) / 100 + (year - 1601) / 400
- ) * SECONDS_PER_DAY;
+ ) * SECONDS_PER_DAY - 1;

Otherwise, make it clear that endTime() is exclusive.