getVotingPower Is Not Equipped To Handle On-Chain Voting
The getVotingPower function calculates voting power based on the current sNOTE balance and total supply without using a checkpointing mechanism. An attacker could vote, transfer their sNOTE to another account, and vote again, effectively double voting.
Submitted by leastwood
As NOTE continues to be staked in the sNOTE contract, it is important that Notional’s governance is able to correctly handle on-chain voting by calculating the relative power sNOTE has in terms of its equivalent NOTE amount.
getVotingPower is a useful function in tracking the relative voting power a staker has, however, it does not utilise any checkpointing mechanism to ensure the user’s voting power is a snapshot of a specific block number. As a result, it would be possible to manipulate a user’s voting power by casting a vote on-chain and then have them transfer their sNOTE to another account to then vote again.
Proof of Concept
https://github.com/code-423n4/2022-01-notional/blob/main/contracts/sNOTE.sol#L271-L293
function getVotingPower(uint256 sNOTEAmount) public view returns (uint256) {
// Gets the BPT token price (in ETH)
uint256 bptPrice = IPriceOracle(address(BALANCER_POOL_TOKEN)).getLatest(IPriceOracle.Variable.BPT_PRICE);
// Gets the NOTE token price (in ETH)
uint256 notePrice = IPriceOracle(address(BALANCER_POOL_TOKEN)).getLatest(IPriceOracle.Variable.PAIR_PRICE);
// Since both bptPrice and notePrice are denominated in ETH, we can use
// this formula to calculate noteAmount
// bptBalance * bptPrice = notePrice * noteAmount
// noteAmount = bptPrice/notePrice * bptBalance
uint256 priceRatio = bptPrice * 1e18 / notePrice;
uint256 bptBalance = BALANCER_POOL_TOKEN.balanceOf(address(this));
// Amount_note = Price_NOTE_per_BPT * BPT_supply * 80% (80/20 pool)
uint256 noteAmount = priceRatio * bptBalance * 80 / 100;
// Reduce precision down to 1e8 (NOTE token)
// priceRatio and bptBalance are both 1e18 (1e36 total)
// we divide by 1e28 to get to 1e8
noteAmount /= 1e28;
return (noteAmount * sNOTEAmount) / totalSupply();
}
Recommended Mitigation Steps
Consider implementing a getPriorVotingPower function which takes in a blockNumber argument and returns the correct balance at that specific block.
Great find, voting power snapshots would also make the system more resilient to manipulation, e.g. by using flashloans.
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
Root cause
Likely the getVotingPower function calculates voting power using the current sNOTE balance and total supply without recording a checkpoint at a specific block number.
What the attacker needed
Attacker has sNOTE tokens; on-chain voting is active
The fix
The function should be changed to use a checkpointing mechanism that returns the voting power at a specific block number, for example by implementing a getPriorVotingPower function.
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.
In many voting systems, your voting power is based on how many tokens you hold at a specific moment. If the system checks your balance each time you vote, you could vote, move your tokens to a friend, and let them vote too. This report says the function that calculates voting power does not take a snapshot at a fixed time, so this trick is possible.
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.