Skip to content

Commit

Permalink
Fix: Relocking min amount bypass (#575)
Browse files Browse the repository at this point in the history
### Description

[Hats issue
#10](hats-finance#10)
identified that in the event of relocking a completed lock, there was no
minimum check that was present in a standard lock, this was given the
assumption that relocking would only occur on non expired locks.
  • Loading branch information
RyRy79261 authored Feb 5, 2025
1 parent 6694b35 commit 0c0ffe4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/governance/locking/LockingRelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ abstract contract LockingRelock is LockingBase {
uint32 newSlopePeriod,
uint32 newCliff
) external returns (uint256) {
require(newAmount >= 1e18, "amount is less than minimum");
require(newDelegate != address(0), "delegate is zero");

address account = verifyLockOwner(id);
Expand Down Expand Up @@ -67,7 +68,6 @@ abstract contract LockingRelock is LockingBase {
uint32 newCliff,
uint32 toTime
) internal view {
require(newAmount > 0, "zero amount");
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
27 changes: 26 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,29 @@ 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);

_incrementBlock(6 * weekInBlocks);

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);

_incrementBlock(6 * weekInBlocks);

vm.prank(alice);
locking.relock(lockId, alice, 1e18, 3, 3);
}
}

0 comments on commit 0c0ffe4

Please sign in to comment.