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: Relocking min amount bypass #575

Merged
merged 7 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/governance/locking/LockingRelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ abstract contract LockingRelock is LockingBase {
uint32 newCliff,
uint32 toTime
) internal view {
require(newAmount > 0, "zero amount");
require(newAmount >= 1e18, "amount is less than minimum");
require(newCliff <= MAX_CLIFF_PERIOD, "cliff too big");
require(newSlopePeriod <= MAX_SLOPE_PERIOD, "slope period too big");
require(newSlopePeriod > 0, "slope period equal 0");
Expand Down
31 changes: 30 additions & 1 deletion test/unit/governance/Locking/relock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ contract Relock_LockingTest is LockingTest {
lockId = locking.lock(alice, alice, 38e18, 4, 3);
_incrementBlock(2 * weekInBlocks);

vm.expectRevert("zero amount");
vm.expectRevert("amount is less than minimum");
vm.prank(alice);
locking.relock(lockId, alice, 0, 5, 1);
}
Expand Down Expand Up @@ -646,4 +646,33 @@ contract Relock_LockingTest is LockingTest {
assertEq(mentoToken.balanceOf(bob), 100e18);
assertEq(mentoToken.balanceOf(charlie), 100e18);
}

function test_relock_whenAmountLessThanMinimum_shouldRevert() public {
mentoToken.mint(alice, 100e18);

vm.prank(alice);
lockId = locking.lock(alice, alice, 30e18, 3, 3);

// Wait until lock expires so residue is 0
_incrementBlock(6 * weekInBlocks);

// Try to relock with amount less than minimum (1e18)
vm.expectRevert("amount is less than minimum");
vm.prank(alice);
locking.relock(lockId, alice, 0.5e18, 3, 3);
}

function test_relock_whenAmountIsMinimum_shouldRelockSuccessfully() public {
mentoToken.mint(alice, 100e18);

vm.prank(alice);
lockId = locking.lock(alice, alice, 30e18, 3, 3);

// Wait until lock expires so residue is 0
_incrementBlock(6 * weekInBlocks);

// Should succeed with amount = minimum
vm.prank(alice);
locking.relock(lockId, alice, 1e18, 3, 3);
}
}
Loading