Skip to content
Access control Audit finding Advanced

auth collision possible

The access control contract uses four-byte function selectors as role identifiers, so a function whose selector equals the root role's selector would grant root privileges. An attacker who could add a module with such a function could obtain full authorisation for the project.

Yield Witch v2 contest

Originally disclosed on Code4rena

The auth mechanism of AccessControl.sol uses function selectors (msg.sig) as a (unique) role definition. Also the _moduleCall allows the code to be extended.

Suppose an attacker wants to add the innocent-looking function ”left_branch_block(uint32) “in a new module. Suppose this module is added via _moduleCall, and the attacker gets authorization for the innocent function.

This function happens to have a signature of 0x00000000, which is equal to the root authorization. In this way, the attacker could get authorization for the entire project.

Note: it’s pretty straightforward to generate function names for any signature value; you can just brute force it because it’s only 4 bytes.

Recommend not allowing third parties to define or suggest new modules and double-checking the function signatures of new functions of a new module for collisions.

albertocuestacanada (Yield) confirmed:

The execution of any auth function will only happen after a governance process or by a contract that has gone through a thorough review and governance process.

We are aware that new modules can have complete control of the Ladle, and for that reason, the addition of new modules would be subject to the highest level of scrutiny. Checking for signature collisions is a good item to add to that process.

In addition to that, I would implement two changes in AccessControl.sol so that giving ROOT access is explicit.

    function grantRole(bytes4 role, address account) external virtual admin(role) {
        require(role != ROOT, "Not ROOT role");
        _grantRole(role, account);
    }
>
    function grantRoot(address account) external virtual admin(ROOT) {
        _grantRole(ROOT, account);
    }

However, given that this could be exploited only through a malicious governance exploit, I would reduce the risk to “Low.”

albertocuestacanada (Yield) acknowledged:

After further thinking, instead of preventing auth collisions in the smart contracts, we will add CI checks for this specific issue instead.

The original report as published on Code4rena. 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

Root cause

Likely the access control design reused four-byte function selectors as role identifiers, allowing a collision between a new function's selector and the root role.

Impact

An attacker could gain root authorisation for the entire project, but the maintainer notes this could only be exploited through a malicious governance exploit and rates the risk as low.

What the attacker needed

Ability to add a new module; governance approval of the module

The fix

The project decided to add continuous integration checks for selector collisions rather than changing the contracts, and the maintainer also suggested making root grants explicit and checking new module signatures.

How it was found

  1. The attacker proposes a new module containing an innocuous-looking function.
  2. The function's selector is crafted to equal the root authorisation value.
  3. The module is added through the module-call mechanism.
  4. The attacker obtains authorisation for the innocent function, which is actually root authorisation.

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 often identify functions by a short four-byte code called a selector. This project also used those same codes as permission names, so a function with the same code as the top-level permission would be treated as having that permission. An attacker who could add a new function could therefore gain full control.

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 from Yield Witch v2 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.