VotingEscrow._moveTokenDelegates() would work abnormally while called more than once for same Rep in one block
Summary
The current implementation of VotingEscrow._moveTokenDelegates() can not process the situation that a Rep's delegated NFT list is changed more than once in one block.
Vulnerability Detail
Please pay attention on L1373 and L1423, the nextSrcRepNum would be _nCheckPoints - 1 if a second try in one block (timestamp keeps same) to update checkpoints for same Rep, which results in srcRepOld and srcRepNew points to the same storage. Then, the for loop for coping token IDs (L1378~1383) becomes flawed. As srcRepOld.length (L1378) increases by 1 after each push(), which incurs dead loop and burn all available gas.
KingNFT
Medium
VotingEscrow._moveTokenDelegates()
would work abnormally while called more than once for sameRep
in one blockSummary
The current implementation of
VotingEscrow._moveTokenDelegates()
can not process the situation that aRep
's delegated NFT list is changed more than once in one block.Vulnerability Detail
Please pay attention on
L1373
andL1423
, thenextSrcRepNum
would be_nCheckPoints - 1
if a second try in one block (timestamp
keeps same) to updatecheckpoints
for sameRep
, which results insrcRepOld
andsrcRepNew
points to the samestorage
. Then, thefor
loop for coping token IDs (L1378~1383
) becomes flawed. AssrcRepOld.length
(L1378) increases by1
after eachpush()
, which incurs dead loop and burn all available gas.Impact
Transactions from users with same
Reps
would fail unexpectedly and all available gas is burned.Code Snippet
https://github.com/sherlock-audit/2024-06-velocimeter/blob/63818925987a5115a80eff4bd12578146a844cfd/v4-contracts/contracts/VotingEscrow.sol#L1362
Tool used
Manual Review
Recommendation
Adding a special process logic for this situation
Duplicate of #228