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

Post audit changes Part 1 #23

Merged
merged 12 commits into from
Jul 8, 2024
Merged

Post audit changes Part 1 #23

merged 12 commits into from
Jul 8, 2024

Conversation

JanKuczma
Copy link
Collaborator

The first part of the changes recommended in #22 and #18

  • Change the D calculation
  • return Precision error when D calculation takes more than MAX_ITERATIONS
  • fix rate not updating due to || used in update_rates(...)
  • add bunch of useful comments to the code

@JanKuczma JanKuczma requested review from ggawryal, woocash2 and deuszx July 8, 2024 07:15
Copy link
Contributor

@deuszx deuszx left a comment

Choose a reason for hiding this comment

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

LGTM but let's give the honours to the people that found the bugs :)

JanKuczma and others added 2 commits July 8, 2024 09:47
Co-authored-by: deuszx <95355183+deuszx@users.noreply.github.com>
@JanKuczma JanKuczma changed the title Post audit changed Part 1 Post audit changes Part 1 Jul 8, 2024
Copy link
Contributor

@woocash2 woocash2 left a comment

Choose a reason for hiding this comment

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

very nice 👍

Copy link

@ggawryal ggawryal left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -718,7 +723,7 @@ pub mod stable_pool {
let current_time = self.env().block_timestamp();
let mut rate_changed = false;
for rate in self.pool.token_rates.iter_mut() {
rate_changed = rate_changed || rate.update_rate_no_cache(current_time);
rate_changed = rate.update_rate_no_cache(current_time) || rate_changed;
Copy link

Choose a reason for hiding this comment

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

I'd prefer | there anyway, as (1) Using || in expressions used in assignments is usually asking for troubles (someone might fork the repo and add some new condition after rate_changed, which would be bad), and (2) I'm not sure if the gas cost of || wouldn't be greater, because of conditional jumps (probably in nanoscale, but still).
But it's correct and contracts are non-upgradeable, so up to you :P

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally like || more than bitwise |

  • It's more clear
  • When using |, rate_changed would have to have a number type (| shouldn't be applicable to bool) and this is weird
  • Optimization of | sounds negligible

I can also propose an alternative which is 100% clear 😛

if rate.update_rate_no_cache(current_time) {
  rate_changed = true;
}

@JanKuczma JanKuczma merged commit 852dde8 into main Jul 8, 2024
1 check passed
@JanKuczma JanKuczma deleted the post-audit branch July 8, 2024 11:55
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.

4 participants