-
Notifications
You must be signed in to change notification settings - Fork 40
fix: off by one slice bug #254
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
Conversation
WalkthroughThe changes primarily focus on enhancing the Changes
Poem
TipsChat with CodeRabbit Bot (
|
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/lib/verifier/DAVerifier.sol (1 hunks)
Additional comments: 1
src/lib/verifier/DAVerifier.sol (1)
- 238-244: The fix for the off-by-one error looks good. It correctly adjusts the index for the
out
array to ensure that the elements from_data
are correctly sliced and assigned to theout
array. However, it would be good to add a check to ensure that_begin
is less than or equal to_end
to avoid potential issues.+ if (_begin > _end) { + revert("Invalid range: _begin is greater than _end"); + }
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/lib/verifier/DAVerifier.sol (1 hunks)
Files skipped from review due to trivial changes (1)
- src/lib/verifier/DAVerifier.sol
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/lib/verifier/DAVerifier.sol (3 hunks)
Additional comments: 2
src/lib/verifier/DAVerifier.sol (2)
64-70: The addition of the
InvalidRange
error code is a good practice for handling invalid range inputs in theslice
function.109-121: The
slice
function is now being used to extract a subset of shares from_sharesProof.data
. The error handling for theslice
function is correctly implemented.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/lib/verifier/DAVerifier.sol (3 hunks)
Additional comments: 3
src/lib/verifier/DAVerifier.sol (3)
64-71: The addition of new error codes
InvalidRange
andOutOfBoundsRange
is a good practice for better error handling and debugging.111-123: The error handling in the
verifySharesProof
function has been updated to check for errors when slicing the data. This is a good practice as it ensures that the function behaves correctly even when it encounters unexpected input or state.240-259: The
slice
function has been updated to return a tuple ofbytes[]
andErrorCodes
. This is a good practice as it allows the function to communicate more information about its execution, specifically any errors that occurred. The function now checks if the provided range is valid and within the bounds of the_data
array, which improves the robustness of the function.- function slice(bytes[] memory _data, uint256 _begin, uint256 _end) internal pure returns (bytes[] memory) + function slice(bytes[] memory _data, uint256 _begin, uint256 _end) internal pure returns (bytes[] memory, ErrorCodes)
bytes[] memory out = new bytes[](_end-_begin); | ||
for (uint256 i = _begin; i < _end; i++) { | ||
out[i] = _data[i]; | ||
out[i - _begin] = _data[i]; |
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.
Can you add a test that hits this codepath and would have caught the bug?
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.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/lib/verifier/test/DAVerifier.t.sol (1 hunks)
Additional comments: 3
src/lib/verifier/test/DAVerifier.t.sol (3)
197-209: The test
testValidSlice
is well written and covers the expected behavior of theslice
function when provided with valid input. It checks both the returned slice and the error code.211-221: The test
testInvalidSliceBeginEnd
correctly checks the behavior of theslice
function when_begin
is greater than_end
. It verifies that the appropriate error code is returned.223-235: The test
testOutOfBoundsSlice
checks the behavior of theslice
function when the slice range is out of bounds. It verifies that the appropriate error code is returned in both cases.
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.
lgtm but I'll defer to others for solidity things
Overview
Checklist
Summary by CodeRabbit