Skip to content

Commit

Permalink
v1 borrower enforcer underflow
Browse files Browse the repository at this point in the history
  • Loading branch information
0xgregthedev committed Jan 3, 2024
1 parent dea12a7 commit 064d3d8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/enforcers/AstariaV1BorrowerEnforcer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 064d3d8

Please sign in to comment.