-
Notifications
You must be signed in to change notification settings - Fork 10
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
Bit packing step 1 #46
Conversation
Changes to gas cost
🧾 Summary (20% most significant diffs)
Full diff report 👇
|
LCOV of commit
|
src/Protocol.sol
Outdated
@@ -527,10 +546,10 @@ contract Protocol is IProtocol, ContinuousIndexing, ERC712 { | |||
if (penaltyBase_ == 0) return; | |||
|
|||
// Save penalization interval to not double charge for the same missed periods again | |||
_penalizedUntilTimestamps[minter_] = penalizedUntil_; | |||
_minterBasics[minter_].penalizedUntilTimestamp = UIntMath.safe48(penalizedUntil_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should happen when computing penalizedUntil_
in _getPenaltyBaseAndTimeForMissedCollateralUpdates()
and this function should return an uint48
.
_minterBasics[minter_].penalizedUntilTimestamp = UIntMath.safe48(penalizedUntil_); | |
_minterBasics[minter_].penalizedUntilTimestamp = penalizedUntil_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disagree on this one. It is used once, compared to _getPrincipalValue. If this function returns uint48 , then all internal functions should accept and return uintxx for consistency.
The simplicity of approach working with uint256 and casting to exact data type when storing won't exist anymore and most likely will require readjustment of public interfaces too.
Co-authored-by: Pierrick Turelier <pierrick@turelier.com>
Co-authored-by: Pierrick Turelier <pierrick@turelier.com>
src/Protocol.sol
Outdated
_pendingCollateralRetrievals[msg.sender][retrievalId_] = collateral_; | ||
uint128 safeCollateral_ = UIntMath.safe128(collateral_); | ||
_minterBasics[msg.sender].totalPendingRetrievals += safeCollateral_; | ||
_pendingCollateralRetrievals[msg.sender][UIntMath.safe48(retrievalId_)] = safeCollateral_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overflow check is cheap, but I agree with @PierrickGT. if we overflow the retrieval id's, then the system is broken anyway.
Bit-packing obvious things to get easy gains.
Picked approach - interfaces and interactions in
uint256
, internal storage fields -uintxx
. Add safe conversions via introducedUintMath
library.