-
Notifications
You must be signed in to change notification settings - Fork 38
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: edge case namespace merkle tree #277
Conversation
WalkthroughThe modifications involve a refinement in the logic for node calculation within the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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 (2)
- src/lib/tree/namespace/NamespaceMerkleTree.sol (2 hunks)
- src/lib/tree/namespace/test/NamespaceMerkleTree.t.sol (4 hunks)
Additional comments: 17
src/lib/tree/namespace/NamespaceMerkleTree.sol (2)
109-109: The change in the condition within the
if
statement from(1 << (height - heightOffset - 1))
to(1 << (height - 1))
is intended to correct the edge case identified by Ottersec. Ensure that this change does not introduce any off-by-one errors or other unintended consequences in the calculation of the subtree index.122-122: The adjustment of the proof's sideNodes length check from
(proof.sideNodes.length <= height - 1)
to(proof.sideNodes.length <= height - heightOffset - 1)
is critical for the integrity of the proof verification. It is important to validate that this change correctly handles the edge case without affecting other valid proofs.src/lib/tree/namespace/test/NamespaceMerkleTree.t.sol (15)
256-285: The test function
testVerifyLeafFiveOfEight
is well-structured and follows the pattern of the other test functions. It's testing the verification of a specific leaf in a merkle tree with eight leaves. Ensure that the test cases cover all possible edge cases and that the test data used is representative of real-world scenarios to ensure thorough testing.287-318: The test function
testVerifyLeafFourOfEight
is similar to the previous one, testing another leaf's verification in the same merkle tree. It's important to check that the test data changes accordingly and that the assertions are correct for the specific case being tested.320-351: The test function
testVerifyLeafThreeOfEight
is consistent with the other test functions in structure and purpose. It's crucial that the test functions are not only correct but also meaningful. The test should fail if the expected behavior is not met, which is a critical aspect of test-driven development.353-382: The test function
testVerifyLeafFiveOfSeven
introduces a different number of leaves in the merkle tree, which is good for testing different scenarios. It's important to ensure that the test functions are independent and can be run in any order without affecting each other.384-408: The test function
testVerifyLeafNineOfTen
is testing a larger merkle tree with ten leaves. This is a good practice to test the scalability of the verification function. It's also important to ensure that the test functions are efficient and do not take an excessive amount of time to run, especially when dealing with larger data sets.410-444: The test function
testVerifyLeafTwelveOfThirteen
is testing an even larger merkle tree. It's important to note that as the number of leaves increases, the complexity of the merkle tree also increases. The tests should be designed to catch any potential issues that could arise from this increased complexity.446-470: The test function
testVerifyLeafThirteenOfThirteen
is testing the verification of the last leaf in a merkle tree with thirteen leaves. This is a boundary case and is important for ensuring the correctness of the merkle tree implementation at its limits.472-496: The test function
testVerifyInternalNodeOneAndTwoOfFour
is testing the verification of internal nodes, which is a critical part of ensuring the integrity of the merkle tree. It's important to ensure that the internal node verification is as robust as the leaf verification.498-519: The test function
testVerifyInternalNodeOneAndTwoOfThree
is another test for internal node verification, this time with a different number of leaves. This variation in test cases helps ensure that the verification function works correctly under different scenarios.520-520: The test function
testVerifyInnerLeafIsRoot
is testing a special case where the leaf itself is the root of the merkle tree. This is an edge case and it's good to see it being tested explicitly.520-520: The test function
testVerifyInnerFalseForStartingHeightZero
is testing the behavior of the verification function when the starting height is zero. This is an important negative test case to ensure that the function handles incorrect inputs gracefully.253-523: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [520-561]
The test function
testVerifyInnerFalseForTooLargeKey
is testing the behavior when the key is larger than the number of leaves. This is another negative test case that is important for ensuring the function's robustness against invalid inputs.
- 558-564: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [520-581]
The test function
testVerifyInnerFalseForIncorrectProofLength
is testing the verification function's behavior when the proof length is incorrect. This is a critical test for ensuring that the function does not accept invalid proofs.
520-520: The test function
testVerifyInnerOneOfEight
is testing the verification of an internal node in a merkle tree with eight leaves. This is a good test for ensuring that the verification function works correctly for internal nodes as well as leaves.520-520: The test function
testVerifyInnerSevenOfEight
is similar to the previous test but for a different internal node. It's important to test all internal nodes, especially in larger merkle trees, to ensure complete coverage.
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/tree/namespace/test/NamespaceMerkleTree.t.sol (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/lib/tree/namespace/test/NamespaceMerkleTree.t.sol
@@ -252,6 +252,271 @@ contract NamespaceMerkleTreeTest is DSTest { | |||
assertTrue(isValid); | |||
} | |||
|
|||
function testVerifyLeafFiveOfEight() external { |
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.
as you said we should figure out these tests are needed and document why they are needed so when they fail in the future we can better fix things
so we should create an issue imo to do so later, as I'm not sure we want to block on it due to the time constraints
Overview
This fixes an edge case with the
verifyInner
for the NMT implementation. It is the fix forOS-CLST-ADV-01
from the Ottersec audit.Special thanks for Ottersec on providing the test cases and the fix.
Checklist
Summary by CodeRabbit
Refactor
Tests