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

[Part 2 of 2] feat: minor tweaks (add unchecked) #31

Merged
merged 11 commits into from
Jun 5, 2024
Merged

Conversation

ChefMist
Copy link
Collaborator

  • add unchecked to reduce gas

@ChefMist ChefMist changed the title [Part 2 of 2] Feat/tweaks v2 [Part 2 of 2] feat: minor tweaks v2 May 2, 2024
@ChefMist ChefMist changed the title [Part 2 of 2] feat: minor tweaks v2 [Part 2 of 2] feat: minor tweaks May 2, 2024
@ChefMist ChefMist changed the title [Part 2 of 2] feat: minor tweaks [Part 2 of 2] feat: minor tweaks (add unchecked) May 2, 2024
@ChefSnoopy
Copy link
Collaborator

Screenshot 2024-05-08 at 11 41 36

Need to format the codes

Base automatically changed from feat/tweaks to main May 8, 2024 04:56
@ChefMist ChefMist requested a review from chefburger May 8, 2024 04:57
@ChefMist ChefMist requested a review from ChefSnoopy May 8, 2024 05:00
SettlementGuard.accountDelta(msg.sender, currency, amount.toInt128());
unchecked {
SettlementGuard.accountDelta(msg.sender, currency, amount.toInt128());
currency.transfer(to, amount);
Copy link
Collaborator

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.

ChefSnoopy
ChefSnoopy previously approved these changes May 9, 2024
unchecked {
SettlementGuard.accountDelta(msg.sender, currency, -(amount.toInt128()));
_mint(to, currency, amount);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. amount is positive
  2. if amount.toInt128 doesn't revert, then amount is a valid int128
  3. 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()));
Copy link
Collaborator

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());
}
}

Copy link
Collaborator

@chefburger chefburger Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. amount is positive
  2. SettlementGuard.getCurrencyDelta(target, currency) cant be over int128 otherwise it will revert in line 144

Copy link
Collaborator Author

@ChefMist ChefMist left a 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

@ChefMist ChefMist merged commit be69354 into main Jun 5, 2024
2 checks passed
@ChefMist ChefMist deleted the feat/tweaks-v2 branch June 5, 2024 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants