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

fix(TwabLib): prevent account.cardianlity from exceeding max cardinality #153

Merged
merged 2 commits into from
Oct 6, 2021

Conversation

kamescg
Copy link
Contributor

@kamescg kamescg commented Oct 5, 2021

Prevent the Account specific cardinality from exceeding the MAX_CARDINALITY. The ring buffer length is limited by MAX_CARDINALITY. IF the account.cardinality exceeds the max cardinality, new observations would be incorrectly set or the
observation would be out of "bounds" of the ring buffer.

Once reached the AccountDetails.cardinality will continue to be equal to max cardinality.

@kamescg kamescg self-assigned this Oct 5, 2021
@kamescg kamescg added the bug Something isn't working label Oct 5, 2021
// AccountDetails.cardinality will continue to be equal to max cardinality.
if(_accountDetails.cardinality < MAX_CARDINALITY) {
_accountDetails.cardinality += 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is simple code, but I'd love to have this tested. It's mission-critical.

Can you:

  1. extract lines 362 - 373 into a separate pure function that's called pushObservation(AccountDetails, uint256 cardinality) that returns a new Account details.
  2. expose the function in the harness

Test that it correctly wraps and caps the cardinality

Copy link
Contributor

Choose a reason for hiding this comment

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

if it's not clear: also use the pure function instead of the code at 362 - 373!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Affirmative @asselstine - great feedback for this one. Will test'ify this bit of code.

@asselstine asselstine merged commit 0370b9b into master Oct 6, 2021
@asselstine asselstine deleted the pool-1678-twablib-prevent-incrementation-of branch October 6, 2021 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants