re-al-Foundation / rwa-contracts

0 stars 0 forks source link

[VEV-05C] Unconditional Configuration of Vesting Duration #106

Closed chasebrownn closed 5 months ago

chasebrownn commented 5 months ago

VEV-05C: Unconditional Configuration of Vesting Duration

Type Severity Location
Gas Optimization VotingEscrowVesting.sol:L160

Description:

The VotingEscrowVesting::withdraw function will perform a redundant call to RWAVotingEscrow::updateVestingDuration when the remainingTime is 0.

Example:

/**
 * @dev Withdraws a VotingEscrow token back to the depositor after the vesting period. The function restores the
 * remaining vesting duration and transfers the token back to the depositor.
 *
 * @param receiver The address to receive the withdrawn VotingEscrow token.
 * @param tokenId The identifier of the VotingEscrow token to be withdrawn.
 */
function withdraw(address receiver, uint256 tokenId) external nonReentrant {
    if (depositors[tokenId] != msg.sender) {
        revert NotAuthorized(msg.sender);
    }

    VestingSchedule storage tokenSchedule = vestingSchedules[tokenId];
    uint256 endTime = tokenSchedule.endTime;
    uint256 remainingTime;

    if (endTime > block.timestamp) {
        unchecked {
            remainingTime = endTime - block.timestamp;
        }
    }

    _removeTokenFromDepositorEnumeration(msg.sender, tokenId);

    delete vestingSchedules[tokenId];

    votingEscrow.updateVestingDuration(tokenId, remainingTime);
    votingEscrow.transferFrom(address(this), receiver, tokenId);
}

Recommendation:

We advise an if conditional to wrap the function invocation, ensuring that it is performed solely when it needs to and thereby optimizing the gas cost of the VotingEscrowVesting::withdraw function.

chasebrownn commented 5 months ago

Acknowledged