Addressed Certora's concern with the weighted average calculation#722
Merged
jalextowle merged 3 commits intomainfrom Jan 15, 2024
Merged
Conversation
Closed
Hyperdrive Gas Benchmark
This comment was automatically generated by workflow using github-action-benchmark. |
jrhea
reviewed
Jan 12, 2024
Contributor
jrhea
left a comment
There was a problem hiding this comment.
I'm a little slow here. Does it just fail for really small inputs? I think I see how assertGe(updatedAverage, average.min(delta)); could fail with small inputs due to precision loss. i don't see how the other condition would. just curious if you ran into that.
also, is there a pathological issue with the subtraction path that we need to deal with?
Collaborator
jrhea
approved these changes
Jan 12, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #561.
This PR adds a test that verifies that$\alpha$ is the current average, $\omega$ is the current total weight, $\delta$ is new value, and $\omega_{\delta}$ is the weight of the new value, we expect the following to hold:
updateWeightedAveragesatisfies the property of "computing an average" that Certora mentioned during their review last year. Assuming thatWhen I initially ran the test, this property did not hold on some of the inputs. Since this is an important property that we want to hold and since it's not very expensive to force to be the case, I went ahead and added an explicit clamp to ensure that the average stays in range.
It's worth noting that this property doesn't hold when removing values from the weighted average, so I left that path unchanged.