Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1 borrower enforcer underflow #26

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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