-
-
Notifications
You must be signed in to change notification settings - Fork 17
fix: cap endorsements to prevent endorsement-loop DoS #82
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -288,6 +288,23 @@ contract IdentityTokenTest is Test { | |||||||||||||||||||||||||||||||||||||||||||||
| assertEq(revokedAt, 0); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| function test_RevertIf_MaxEndorsementsReached() public { | ||||||||||||||||||||||||||||||||||||||||||||||
| vm.prank(alice); | ||||||||||||||||||||||||||||||||||||||||||||||
| uint256 aliceId = identityToken.mint(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| vm.prank(bob); | ||||||||||||||||||||||||||||||||||||||||||||||
| uint256 bobId = identityToken.mint(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| for (uint256 i = 0; i < 100; i++) { | ||||||||||||||||||||||||||||||||||||||||||||||
| vm.prank(alice); | ||||||||||||||||||||||||||||||||||||||||||||||
| identityToken.endorse(aliceId, bobId, keccak256(abi.encodePacked("Connection", i)), 0); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| vm.prank(alice); | ||||||||||||||||||||||||||||||||||||||||||||||
| vm.expectRevert(Errors.IndexOutOfBounds.selector); | ||||||||||||||||||||||||||||||||||||||||||||||
| identityToken.endorse(aliceId, bobId, keccak256(abi.encodePacked("Connection", uint256(100))), 0); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+298
to
+305
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Avoid hardcoded cap values in the boundary test. Use ♻️ Suggested test update- for (uint256 i = 0; i < 100; i++) {
+ uint256 maxEndorsements = identityToken.MAX_ENDORSEMENTS();
+ for (uint256 i = 0; i < maxEndorsements; i++) {
vm.prank(alice);
identityToken.endorse(aliceId, bobId, keccak256(abi.encodePacked("Connection", i)), 0);
}
vm.prank(alice);
vm.expectRevert(Errors.IndexOutOfBounds.selector);
- identityToken.endorse(aliceId, bobId, keccak256(abi.encodePacked("Connection", uint256(100))), 0);
+ identityToken.endorse(
+ aliceId,
+ bobId,
+ keccak256(abi.encodePacked("Connection", maxEndorsements)),
+ 0
+ );📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // --- deleteAttribute --- | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| function test_DeleteAttribute() public { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
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.
🧹 Nitpick | 🔵 Trivial
Expose the cap in
IIdentityTokenfor typed integrators.Consider adding the getter signature to the interface so clients compiled against
IIdentityTokencan discover the limit without implementation coupling.♻️ Suggested interface addition
🤖 Prompt for AI Agents