Skip to content
DoS Audit finding Intermediate

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"

Solidity
        _addCategory(toCategory("protocol-owned-treasury"), true, 0xb600c5e2, 0x00000000); // getProtocolOwnedTreasuryOhm()`

but when call getReservesByCategory() , don't check submoduleReservesSelector!=bytes4(0) and direct call submoduleReservesSelector

Solidity
    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

Solidity
    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")
        );
    }
CONSOLE
 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

https://github.com/sherlock-audit/2023-11-olympus/blob/main/bophades/src/modules/SPPLY/OlympusSupply.sol#L541

Tool used

Manual Review

Recommendation

Diff
    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

The original report as published on Sherlock, by bin2chen. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. Set up the submodules in the test environment.
  2. Mint treasury tokens that are not expected to be counted.
  3. Call the reserves lookup for the protocol-owned-treasury category.
  4. 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.

More by bin2chen

View all

139 more disclosed reports, best first.

More from Olympus RBS 2.0

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.