Summary
Incorrect calculation of the new voting power when lock is increased
Vulnerability Details
Following is increase lock function
function increase(uint256 amount) external nonReentrant whenNotPaused {
_lockState.increaseLock(msg.sender, amount);
_updateBoostState(msg.sender, locks[msg.sender].amount);
LockManager.Lock memory userLock = _lockState.locks[msg.sender];
(int128 newBias, int128 newSlope) = _votingState.calculateAndUpdatePower(
msg.sender,
userLock.amount + amount,
userLock.end
);
uint256 newPower = uint256(uint128(newBias));
_checkpointState.writeCheckpoint(msg.sender, newPower);
raacToken.safeTransferFrom(msg.sender, address(this), amount);
_mint(msg.sender, newPower - balanceOf(msg.sender));
emit LockIncreased(msg.sender, amount);
}
It calls increase lock function for msg.sender by increasing the lockj amount by amount value as follows
function increaseLock(
LockState storage state,
address user,
uint256 additionalAmount
) internal {
Lock storage lock = state.locks[user];
if (!lock.exists) revert LockNotFound();
if (lock.end <= block.timestamp) revert LockExpired();
if (lock.amount + additionalAmount > state.maxLockAmount) revert AmountExceedsLimit();
==> lock.amount += additionalAmount;
state.totalLocked += additionalAmount;
emit LockIncreased(user, additionalAmount);
}
So the user lock amount is updated initially
But when updation of voting power is done it wrongly adds amount to the user lock.amount leading to double increase in amount of locked tokens which is incorrect
(int128 newBias, int128 newSlope) = _votingState.calculateAndUpdatePower(
msg.sender,
===> userLock.amount + amount,
userLock.end
);
Due to this voting power increases by 2 times even when only half of the tokens were locked.
Impact
Incorrect voting power updated.
Tools Used
Recommendations
don't add amount to userLock.amount when calculating the new power.