Wrong implementation causing some functions in
The registerGauge function in PoolVoter.sol checks if isPool[_asset] is true before adding the asset to the _pools array, but there is no setter to set isPool to true, so the array stays empty. As a result, the distribute and distributeEx functions that rely on the pool length become unusable.
- Disclosed after under an hour
29267 - [SC - High] Wrong implementation causing some functions in ...
Submitted on Mar 12th 2024 at 18:54:46 UTC by @EricTee for Boost | ZeroLend
Report ID: #29267
Report type: Smart Contract
Report severity: High
Target: https://github.com/zerolend/governance
Impacts:
- Unusable functions in governance/contracts/voter/PoolVoter.sol
Description
Brief/Intro
Some functions in governance/contracts/voter/PoolVoter.sol are unusable. Specifically, there is no setter for isPool variable to set certain address asset to true or false. As a result, the length of _pools will always be 0. PoolVoter::distribute and PoolVoter::distributeEx functions which rely on length of pool will become unusable.
Vulnerability Details
In PoolVoter::registerGauge:
function registerGauge(
address _asset,
address _gauge
) external onlyOwner returns (address) {
if (isPool[_asset]) {
_pools.push(_asset);
isPool[_asset] = true;
}
bribes[_gauge] = address(0);
gauges[_asset] = _gauge;
poolForGauge[_gauge] = _asset;
_updateFor(_gauge);
return _gauge;
}
The contract check for if (isPool[_asset]). However, there is no setter to let owner set certain _asset to true in isPool mapping variable. As a result, the length of pool will always be 0 and PoolVoter::distribute and PoolVoter::distributeEx functions which rely on length of pool will become unusable.
Impact Details
The impact of this issue is that PoolVoter::distribute and PoolVoter::distributeEx functions which rely on length of pool are unusable.
Consider making the following changes in PoolVoter::registerGauge:
function registerGauge(
address _asset,
address _gauge
) external onlyOwner returns (address) {
-- if (isPool[_asset]) {
++ if (!isPool[_asset]) {
_pools.push(_asset);
isPool[_asset] = true;
}
bribes[_gauge] = address(0);
gauges[_asset] = _gauge;
poolForGauge[_gauge] = _asset;
_updateFor(_gauge);
return _gauge;
}
References
https://github.com/zerolend/governance/blob/main/contracts/voter/PoolVoter.sol#L136
Proof of Concept
Manual Analysis
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
The condition in registerGauge is inverted: it checks if isPool[_asset] is true before adding the asset, but isPool is never set to true elsewhere, so the pool is never added.
Impact
The distribute and distributeEx functions that rely on the pool length are unusable.
What the attacker needed
Owner calls registerGauge
The fix
The condition should be changed to check if isPool[_asset] is false before adding the asset and setting it to true.
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 has a list of pools that should be filled when a new gauge is registered. The code only adds a pool if a flag is already true, but nothing ever sets that flag to true, so the list stays empty. Functions that loop over the list then do nothing or fail.
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.