From 064d3d8e1582a10ba8bfb394750e0bdf06ba704c Mon Sep 17 00:00:00 2001 From: GregTheDev Date: Wed, 3 Jan 2024 07:53:19 -0700 Subject: [PATCH] v1 borrower enforcer underflow --- src/enforcers/AstariaV1BorrowerEnforcer.sol | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/enforcers/AstariaV1BorrowerEnforcer.sol b/src/enforcers/AstariaV1BorrowerEnforcer.sol index ecded5f..eabe314 100644 --- a/src/enforcers/AstariaV1BorrowerEnforcer.sol +++ b/src/enforcers/AstariaV1BorrowerEnforcer.sol @@ -120,19 +120,18 @@ contract AstariaV1BorrowerEnforcer is BorrowerEnforcer { // Will revert if startTime > endTime uint256 duration = v1Details.endTime - v1Details.startTime; - uint256 elapsed; + uint256 elapsed = block.timestamp - v1Details.startTime; uint256 remaining; - unchecked { - // block.timestamp <= endTime && startTime < endTime, can't overflow - elapsed = block.timestamp - v1Details.startTime; + assembly ("memory-safe") { // block.timestamp <= endTime, can't underflow - remaining = duration - elapsed; + remaining := sub(duration, elapsed) } // Calculate rate with a linear growth // Weight startRate by the remaining time, and endRate by the elapsed time uint256 totalBeforeDivision = (v1Details.startRate * remaining) + (endRate * elapsed); assembly ("memory-safe") { + // duration > 0, as startTime != endTime and endTime - startTime did not underflow currentRate := div(totalBeforeDivision, duration) } }