Skip to content
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: Prevent NOPs on allacation and resetting #82

Merged
merged 8 commits into from
Nov 25, 2024
Merged

fix: Prevent NOPs on allacation and resetting #82

merged 8 commits into from
Nov 25, 2024

Conversation

bingen
Copy link
Contributor

@bingen bingen commented Nov 21, 2024

No description provided.

@bingen bingen self-assigned this Nov 21, 2024

// Explicit >= 0 checks for all values since we reset values below
_requireNoNegatives(_absoluteLQTYVotes);
_requireNoNegatives(_absoluteLQTYVetos);
// If the goal is to remove all votes from an initiative, including in _initiativesToReset is enough
_requireNoNOP(_absoluteLQTYVotes, _absoluteLQTYVetos);
Copy link
Contributor

@danielattilasimon danielattilasimon Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this renders the previous _requireNoNegatives() checks redundant, although we might want to revise the name and revert message of _requireNoNOP() if we eliminate them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? _requireNoNOP doesn’t prevent a negative value, only that for each pair at least one is positive.
Anyway, I was thinking we would remove _requireNoNegatives when we change the signature int88 to unsigned. It’s weird to call them absolute but allow them to be negative to then check they are not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I forgot it's ||.

Agree the interface should be unsigned.

@@ -5,6 +5,8 @@ pragma solidity ^0.8.24;
/// @param arr - List to check for dups
function _requireNoDuplicates(address[] calldata arr) pure {
uint256 arrLength = arr.length;
if (arrLength == 0) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@@ -929,6 +936,30 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
vm.stopPrank();
}

function _allocateNothing(address staker) internal {
Copy link
Contributor

@danielattilasimon danielattilasimon Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe _tryAllocateNothing() to emphasize that it's expected to fail? Or something along those lines.

Just reading the test cases, my first thought was: "how is _allocateNothing() different from _resetAllocation()?"

Copy link
Contributor

@danielattilasimon danielattilasimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I fixed the remaining broken tests.

@bingen bingen merged commit 7d3b9fb into main Nov 25, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants