From 0c0ffe4b2e577509e84a8cc8f9f6bc1f241d6ada Mon Sep 17 00:00:00 2001 From: Ryan Noble Date: Wed, 5 Feb 2025 15:35:45 +0200 Subject: [PATCH] Fix: Relocking min amount bypass (#575) ### Description [Hats issue #10](https://github.com/hats-finance/Mento-0x2a1b9b1f6fa7c2e73815a7dff0e1688767382694/issues/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. --- .../governance/locking/LockingRelock.sol | 2 +- test/unit/governance/Locking/relock.t.sol | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/contracts/governance/locking/LockingRelock.sol b/contracts/governance/locking/LockingRelock.sol index f8fdaa3..66e2e6f 100644 --- a/contracts/governance/locking/LockingRelock.sol +++ b/contracts/governance/locking/LockingRelock.sol @@ -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); @@ -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"); diff --git a/test/unit/governance/Locking/relock.t.sol b/test/unit/governance/Locking/relock.t.sol index 1676a3e..589be57 100644 --- a/test/unit/governance/Locking/relock.t.sol +++ b/test/unit/governance/Locking/relock.t.sol @@ -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); } @@ -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); + } }