getReservesByCategory() when useSubmodules =true and submoduleReservesSelector=bytes4(0) will revert
A category can be configured with submodules enabled but an empty reserves selector, and the reserves lookup then calls the submodule with that empty selector, which reverts. As a result, reserves for such a category cannot be retrieved at all.
bin2chen Follow with dany.armstrong90, lemonmon and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-11-olympus-judging/issues/149
Found by
bin2chen, dany.armstrong90, lemonmon, rvierdiiev
Summary
in getReservesByCategory()
Lack of check data.submoduleReservesSelector!=""
when call submodule.staticcall(abi.encodeWithSelector(data.submoduleReservesSelector)); will revert
Vulnerability Detail
when _addCategory()
if useSubmodules==true, submoduleMetricSelector must not empty
and submoduleReservesSelector can empty (bytes4(0))
like "protocol-owned-treasury"
_addCategory(toCategory("protocol-owned-treasury"), true, 0xb600c5e2, 0x00000000); // getProtocolOwnedTreasuryOhm()`
but when call getReservesByCategory() , don't check submoduleReservesSelector!=bytes4(0) and direct call submoduleReservesSelector
function getReservesByCategory(
Category category_
) external view override returns (Reserves[] memory) {
...
// If category requires data from submodules, count all submodules and their sources.
len = (data.useSubmodules) ? submodules.length : 0;
...
for (uint256 i; i < len; ) {
address submodule = address(_getSubmoduleIfInstalled(submodules[i]));
(bool success, bytes memory returnData) = submodule.staticcall(
abi.encodeWithSelector(data.submoduleReservesSelector)
);
this way , when call like getReservesByCategory(toCategory("protocol-owned-treasury") will revert
POC
add to SUPPLY.v1.t.sol
function test_getReservesByCategory_includesSubmodules_treasury() public {
_setUpSubmodules();
// Add OHM/gOHM in the treasury (which will not be included)
ohm.mint(address(treasuryAddress), 100e9);
gohm.mint(address(treasuryAddress), 1e18); // 1 gOHM
// Categories already defined
uint256 expectedBptDai = BPT_BALANCE.mulDiv(
BALANCER_POOL_DAI_BALANCE,
BALANCER_POOL_TOTAL_SUPPLY
);
uint256 expectedBptOhm = BPT_BALANCE.mulDiv(
BALANCER_POOL_OHM_BALANCE,
BALANCER_POOL_TOTAL_SUPPLY
);
// Check reserves
SPPLYv1.Reserves[] memory reserves = moduleSupply.getReservesByCategory(
toCategory("protocol-owned-treasury")
);
}
forge test -vv --match-test test_getReservesByCategory_includesSubmodules_treasury
Running 1 test for src/test/modules/SPPLY/SPPLY.v1.t.sol:SupplyTest
[FAIL. Reason: SPPLY_SubmoduleFailed(0xeb502B1d35e975321B21cCE0E8890d20a7Eb289d, 0x0000000000000000000000000000000000000000000000000000000000000000)] test_getReservesByCategory_includesSubmodules_treasury() (gas: 4774197
Impact
some category can't get Reserves
Code Snippet
Tool used
Manual Review
Recommendation
function getReservesByCategory(
Category category_
) external view override returns (Reserves[] memory) {
...
CategoryData memory data = categoryData[category_];
uint256 categorySubmodSources;
// If category requires data from submodules, count all submodules and their sources.
- len = (data.useSubmodules) ? submodules.length : 0;
+ len = (data.useSubmodules && data.submoduleReservesSelector!=bytes4(0)) ? submodules.length : 0;
Discussion
0xJem
Good catch! Thank you for the clear explanation and test case, too.
0xrusowsky
https://github.com/OlympusDAO/bophades/pull/262
IAm0x52
Fix looks good, exactly as suggested
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 reserves lookup does not check whether the category's submodule reserves selector is empty before calling it on each submodule.
Impact
Some categories cannot return their reserves, so any consumer of that data gets a failed call instead of a result.
What the attacker needed
A category configured with useSubmodules true; an empty submodule reserves selector
The fix
The lookup was fixed to only iterate submodules when the category uses submodules and has a non-empty reserves selector.
How it was found
- Set up the submodules in the test environment.
- Mint treasury tokens that are not expected to be counted.
- Call the reserves lookup for the protocol-owned-treasury category.
- Observe the call reverting with a submodule failure.
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 can be told to gather data from helper contracts called submodules. Here a category was set up to use helpers but without saying which function on them to call, so the lookup made an empty call that failed and the whole query errored out. The fix is to skip the helpers when no function is specified.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.