TempleGold

TempleDAO
Foundry
25,000 USDC
View results
Submission Details
Severity: medium
Invalid

Delegation and Voting Mechanism

Summary

Vulnerability Details

The delegation and voting mechanism might not handle edge cases correctly, such as repeated delegation changes or the same delegatee being set multiple times. This could lead to incorrect vote balances and potential manipulation of the voting power.

https://github.com/Cyfrin/2024-07-templegold/blob/57a3e597e9199f9e9e0c26aab2123332eb19cc28/protocol/contracts/templegold/TempleGoldStaking.sol#L543C1-L572C6

function _delegate(address delegator, address delegatee) internal {
address currentDelegate = delegates[delegator];
uint256 delegatorBalance = _balances[delegator];
delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(
address srcRep,
address dstRep,
uint256 amount
) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
uint256 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? _checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld - amount;
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
uint256 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? _checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld + amount;
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}

Repeating Delegation to Self: The attacker repeatedly delegates their voting power back to themselves, potentially increasing their voting weight each time.

Delegating to Multiple Addresses: Another strategy could involve delegating to multiple addresses quickly, exploiting any inconsistencies in the contract's handling of multiple delegations.

Simultaneous Delegation Race Condition: Exploiting race conditions where simultaneous transactions might lead to unexpected or inconsistent updates in the delegation status.

Impact

Alice repeatedly delegates to herself or changes delegates rapidly.

  • This could potentially lead to incorrect vote balances or manipulation of the voting system.

Tools Used

Recommendations

Rate Limiting and Comprehensive Checks for Delegation: Implement rate limiting for delegation changes and ensure that repeated delegation to the same address is handled correctly.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.