-
Notifications
You must be signed in to change notification settings - Fork 931
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
Optimize TickBitmap.flipTick
using assembly
#653
Conversation
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.
Love it! Just a couple of things :)
vm.expectRevert(abi.encodeWithSelector(TickBitmap.TickMisaligned.selector, tick, tickSpacing)); | ||
bitmap.flipTick(tick, tickSpacing); | ||
} else { | ||
bool initialized = isInitialized(tick, tickSpacing); |
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.
i think initialized
is always going to be false because the bitmap is empty at the beginning. So this test is only testing false->true flipping.
Should be enough just to add another 2 lines where you call flip again and check it
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.
Added.
test/libraries/TickBitmap.t.sol
Outdated
function isInitialized(int24 tick, int24 tickSpacing) internal view returns (bool) { | ||
unchecked { | ||
int24 compressed = tick / tickSpacing; | ||
if (tick < 0 && tick % tickSpacing != 0) compressed--; // round towards negative infinity |
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.
why do you have to subtract 1? why cant it just be the solidity that was previously in TickBitmap
?
(int16 wordPos, uint8 bitPos) = position(tick / tickSpacing);
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.
That's the first two lines of nextInitializedTickWithinOneWord
, which I factored out to a compress
function in #654.
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.
but for flipTick
theres a requirement that (tick % tickSpacing != 0) otherwise it reverts, so this line feels out of place here? Not sure what I'm missing
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.
Do you mean isInitialized
should return false
instead of rounding if tick % tickSpacing != 0
?
A new fuzz test function `test_fuzz_flipTick` has been added to the TickBitmap library for improved testing accuracy. Additionally, the `isInitialized` function has been re-implemented to enhance its precision and correctness.
76d1dd9
to
ab3c411
Compare
A refactoring was done in the TickBitmap test file which includes changing import paths and renaming a test function. A new fuzz test case on testing the next initialized tick within one word, but on an empty bitmap, was also added. This contributes to verifying the accuracy of tick operations under more extensive scenarios.
Related Issue
Which issue does this pull request resolve?
Description of changes
This pull request is a part of #560 in an effort to ease the review process. It focuses on the
flipTick
function in theTickBitmap
library.