-
Notifications
You must be signed in to change notification settings - Fork 45
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
[Part 2 of 2] feat: minor tweaks (add unchecked) #31
Conversation
SettlementGuard.accountDelta(msg.sender, currency, amount.toInt128()); | ||
unchecked { | ||
SettlementGuard.accountDelta(msg.sender, currency, amount.toInt128()); | ||
currency.transfer(to, amount); |
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.
Not sure whether there are any security issues .
Now we update the reservesOfVault after transfer token.
But after we merge the PR 33(reserveOf transient) , should be fine.
unchecked { | ||
SettlementGuard.accountDelta(msg.sender, currency, -(amount.toInt128())); | ||
_mint(to, currency, amount); | ||
} |
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.
- amount is positive
- if
amount.toInt128
doesn't revert, then amount is a valid int128 - combine 1 & 2, converting from positive to negative will never go overflow
SettlementGuard.accountDelta(msg.sender, currency, -(amount.toInt128())); | ||
currency.transfer(to, amount); | ||
unchecked { | ||
SettlementGuard.accountDelta(msg.sender, currency, -(amount.toInt128())); |
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.
same reason as mint
if (amount == 0) amount = (-SettlementGuard.getCurrencyDelta(target, currency)).toUint256(); | ||
SettlementGuard.accountDelta(msg.sender, currency, -(amount.toInt128())); | ||
SettlementGuard.accountDelta(target, currency, amount.toInt128()); | ||
} | ||
} | ||
|
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.
- amount is positive
SettlementGuard.getCurrencyDelta(target, currency)
cant be over int128 otherwise it will revert in line 144
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.
looks good, @chefburger since this PR was originally raised on my end, can you approve so we can merge? thx
unchecked
to reduce gas