Inconsistent logic of increase unlock time to the expired locks
The increaseUnlockTime function inconsistently allows expired locks to be extended only when the lock is delegated to another address, while blocking it otherwise. An attacker could delegate an expired lock to bypass the check, extend the lock, and then undelegate to regain voting power.
Originally disclosed on Code4rena
Submitted by KIntern_NA, also found by ak1, cryptphi, and scaraven
Can not prevent expired locks being extended.
Proof of Concept
https://github.com/code-423n4/2022-08-fiatdao/blob/main/contracts/VotingEscrow.sol#L493-L523
Call function function increaseUnlockTime() with an expired lock (locked[msg.sender].end < block.timestamp)
- Case 1: if sender’s lock was not delegated to another address, function will be revert because of the requirement
https://github.com/code-423n4/2022-08-fiatdao/blob/main/contracts/VotingEscrow.sol#L511
- Case 2: if sender’s lock was delegated to another address, function will not check anything and the lock can be extended.
But in case 1, sender’s lock was not delegated to another, the sender can delegate to new address with end time of lock equal to new end time. After that he can call increaseUnlockTime() and move to case 2. Then sender can undelegate and the lock will be extended, and sender will take back vote power.
Here is the script :
describe("voting escrow", async () => {
it("increase unlock time issue", async () => {
await createSnapshot(provider);
//alice creates lock
let lockTime = WEEK + (await getTimestamp());
await ve.connect(alice).createLock(lockAmount, lockTime);
// bob creates lock
lockTime = 50 * WEEK + (await getTimestamp());
await ve.connect(bob).createLock(10 ** 8, lockTime);
//pass 1 week, alice's lock is expired
await ethers.provider.send("evm_mine", [await getTimestamp() + WEEK]);
expect(await ve.balanceOf(alice.address)).to.eq(0);
//alice can not increase unlock timme
await expect(ve.connect(alice).increaseUnlockTime(lockTime)).to.be.revertedWith("Lock expired");
//alice delegate to bob then can increase unlock time
await ve.connect(alice).delegate(bob.address);
await expect(ve.connect(alice).increaseUnlockTime(lockTime)).to.not.be.reverted;
//alice delegate back herself
await ve.connect(alice).delegate(alice.address);
expect(await ve.balanceOf(alice.address)).to.gt(0);
});
Recommended Mitigation Steps
In every cases, expired locks should able to be extended -> should remove line VotingEscrow.sol#L511.
lacoop6tu (FIAT DAO) confirmed
Justin Goro (judge) commented:
Very good report, especially because of that script.
IllIllI (warden) reviewed mitigation:
The sponsor addressed the finding with the fix for Issue 4. The fix chosen was to not allow the increasing of lock time or non-self re-delegation if the delegatee’s lock has expired. The fix didn’t require the undelegate flavor to duplicate the blocklist check since
msg.senderis already checked by thecheckBlocklistmodifier. The refactored code properly re-used some variables rather than duplicating the allocations done in the delegation/re-delegation case in order to save some gas. The refactoring introduced a new issue, [M.N-01], described below in the Mitigation Review section.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could extend an expired lock and regain voting power, potentially manipulating governance.
What the attacker needed
An expired lock; ability to delegate
The fix
The expiry check should be applied consistently, regardless of delegation status, by removing the conditional check.
How it was found
- Create a lock that expires after one week.
- Wait for the lock to expire.
- Attempt to call increaseUnlockTime and observe it reverts with 'Lock expired'.
- Delegate the expired lock to another address.
- Call increaseUnlockTime again and observe it succeeds.
- Delegate back to yourself and confirm the lock is extended and voting power is restored.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract lets people lock tokens for a period and get voting power. Normally, once the lock expires, you cannot extend it. But the code has a loophole: if you temporarily delegate your lock to someone else, the expiry check is skipped, so you can extend an expired lock and then take back control.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.