Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield
Description
Brief/Intro
The VotingEscrow.merge interface can merge two $veToken. It checks voted[_from] to ensure that _from $veToken has not voted in the current epoch. However, this check is not comprehensive enough because the user can call Voter.reset to claim $FLUX without setting voted[_from] to true.
Vulnerability Details
Please see the following code. Users can call Voter.reset to receive $FLUX. This interface will call VotingEscrow.abstain to set voted[_tokenId] to false. Moreover, the onlyNewEpoch modifier limits each _tokenId to only call the interface once per epoch. Next we use VotingEscrow.merge to bypass this limit.
Please look at the following code. The VotingEscrow.merge interface can merge two $veToken into one. It only checks voted[_from] but not voter.lastVoted(_from). In other words, we first call Voter.reset(_from) and then merge _from $veToken into another $veToken to continue receiving $FLUX.
///// https://github.com/alchemix-finance/alchemix-v2-dao/blob/f1007439ad3a32e412468c4c42f62f676822dc1f/src/VotingEscrow.sol#L618-L622
functionmerge(uint256_from,uint256_to) external {require(!voted[_from],"voting in progress for token");require(_from != _to,"must be different tokens");require(_isApprovedOrOwner(msg.sender, _from),"not approved or owner");require(_isApprovedOrOwner(msg.sender, _to),"not approved or owner");
This is a brief description of the attack. Please see the PoC code for details.
The attacker owns $veTokenA and calls Voter.reset on $veTokenA. The attacker will receive $FLUX once
The attacker creates a new $veTokenTemp worth 1 wei of $BPT. 1 wei $BPT cost is ~0
The attacker merges $veTokenA into $veTokenTemp
Now treat $veTokenTemp as $veTokenA and go back to the step1
Repeat the above steps to receive unlimited $FLUX
Suggested fix
Check whether the _from $veToken has voted
function merge(uint256 _from, uint256 _to) external {+ require((block.timestamp / DURATION) * DURATION > IVoter(voter).lastVoted(_from)); require(!voted[_from], "voting in progress for token"); require(_from != _to, "must be different tokens"); require(_isApprovedOrOwner(msg.sender, _from), "not approved or owner"); require(_isApprovedOrOwner(msg.sender, _to), "not approved or owner");