for (uint256 i = 1; i < len;) {
// grab current share
uint256 share = shares[i];
// locked balance for this NFT is percentage of shares * total locked balance
uint256 _lockedBalance = share * lockedBalance / totalShares;
// fetch new tokenId to mint
uint256 newTokenId = _incrementAndGetTokenId();
// store new tokenId in tokenIds array
tokenIds[i] = newTokenId;
// store timeststamp for new token
$._mintingTimestamp[newTokenId] = mintingTimestamp;
// mint new token
_mint(owner, newTokenId);
// update lock info for new token
_updateLock(newTokenId, _lockedBalance, remainingVestingDuration);
// subtract locked balance from total balance
unchecked {
remainingBalance -= _lockedBalance;
++i;
}
}
Recommendation:
We advise the $.tokenId value to be read once at the beginning, to be locally incremented, and to finally be written to after the for loop concludes and the total token IDs are known.
RWV-04C: Inefficient Increment of Token IDs
Description:
The
RWAVotingEscrow::split
function will update the$.tokenId
counter multiple times redundantly via theRWAVotingEscrow::_incrementAndGetTokenId
function.Example:
Recommendation:
We advise the
$.tokenId
value to be read once at the beginning, to be locally incremented, and to finally be written to after thefor
loop concludes and the total token IDs are known.