Skip to content
Access control Audit finding Intermediate

Exposed _removeCredIdPerAddress & _addCredIdPerAddress allows anyone to cause issues to current holders as well as upcoming ones

Two internal bookkeeping functions for tracking cred IDs per address were declared public, so anyone could call them for any address. An attacker could corrupt or bloat a victim's cred ID list, causing their transactions to fail or making removal of cred IDs revert.

0xrex Follow with 0xrex, debo and 35 others

Originally disclosed on Code4rena

Submitted by 0xrex, also found by 0xrex, debo, JustUzair, CodeCop, NerfZeri, 0xkaox (1, 2), 0xc0ffEE, th3l1ghtd3m0n, kn0t, TopStar, waydou, eLSeR17 (1, 2), 0xrafaelnicolau, onthehunt11, mjcpwns, nikolap, lu1gi, rscodes, EaglesSecurity, CAUsr, OpaBatyo (1, 2), kuprum (1, 2), Inspecktor, avoloder, McToady, unnamed, hail_the_lord, 54thMass, sweetbluesugarlatte, 41uve12, Taiger, Falendar, pfapostol, 0xAkira, timatc, Monstitude, 20centclub, NexusAudits, 10ap17, MrPotatoMagic, KupiaSec, and JanuaryPersimmon2024 (1, 2)

The _addCredIdPerAddress and _removeCredIdPerAddress allows anyone to interrupt users who are attempting to hold cred shares & sell already held cred shares.

Proof of Concept

Anyone can force several scenarios some of such as making the following:

  • _credIdsPerAddress huge with non-existent credIds that then lead to issues.
  • Forcing a block gas limit for chains whose gas fees are cheap such as Base, Avax C-Chain, etc.
  • Repeatedly forcing new cred share holders’ transactions to fail with a combination of removing the credIds then adding them right after.
  • They can re-order the credId indexes forcing the function to revert when trying to remove cred ID’s per addresses:
// Get the index of the credId to remove
        uint256 indexToRemove = _credIdsPerAddressCredIdIndex[sender_][credId_];
        // Check if the index is valid
        if (indexToRemove >= _credIdsPerAddress[sender_].length) revert IndexOutofBounds();

        // Verify that the credId at the index matches the one we want to remove
        uint256 credIdToRemove = _credIdsPerAddress[sender_][indexToRemove];
        if (credId_ != credIdToRemove) revert WrongCredId();
function _addCredIdPerAddress(uint256 credId_, address sender_) public {
        // Add the new credId to the array
        _credIdsPerAddress[sender_].push(credId_);
        // Store the index of the new credId
        _credIdsPerAddressCredIdIndex[sender_][credId_] = _credIdsPerAddressArrLength[sender_];
        // Increment the array length counter
        _credIdsPerAddressArrLength[sender_]++;
    }

    // Function to remove a credId from the address's list
    function _removeCredIdPerAddress(uint256 credId_, address sender_) public {
        // Check if the array is empty
        if (_credIdsPerAddress[sender_].length == 0) revert EmptyArray();

        // Get the index of the credId to remove
        uint256 indexToRemove = _credIdsPerAddressCredIdIndex[sender_][credId_];
        // Check if the index is valid
        if (indexToRemove >= _credIdsPerAddress[sender_].length) revert IndexOutofBounds();

        // Verify that the credId at the index matches the one we want to remove
        uint256 credIdToRemove = _credIdsPerAddress[sender_][indexToRemove];
        if (credId_ != credIdToRemove) revert WrongCredId();

        // Get the last element in the array
        uint256 lastIndex = _credIdsPerAddress[sender_].length - 1;
        uint256 lastCredId = _credIdsPerAddress[sender_][lastIndex];
        // Move the last element to the position of the element we're removing
        _credIdsPerAddress[sender_][indexToRemove] = lastCredId;

        // Update the index of the moved element, if it's not the one we're removing
        if (indexToRemove < lastIndex) {
            _credIdsPerAddressCredIdIndex[sender_][lastCredId] = indexToRemove;
        }

        // Remove the last element (which is now a duplicate)
        _credIdsPerAddress[sender_].pop();

        // Remove the index mapping for the removed credId
        delete _credIdsPerAddressCredIdIndex[sender_][credIdToRemove];

        // Decrement the array length counter, if it's greater than 0
        if (_credIdsPerAddressArrLength[sender_] > 0) {
            _credIdsPerAddressArrLength[sender_]--;
        }
    }

Recommended Mitigation Steps

Make both functions internal rather than public.

Assessed type

DoS

ZaK3939 (Phi) confirmed

0xDjango (judge) increased severity to High


The original report as published on Code4rena, by 0xrex. 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 two bookkeeping functions were declared public instead of internal, so external callers could modify any address's cred ID array and index mapping.

Impact

An attacker could cause current and future cred holders' transactions to fail, bloat storage with non-existent cred IDs, and potentially hit block gas limits on cheap chains.

What the attacker needed

Ability to send transactions to the contract

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 functions that only the contract itself should use to keep a list of which items each user owns. Here those functions were left open so any outside person could call them and change someone else's list. That lets an attacker mess up the list so the real owner's later actions fail.

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 0xrex

View all

1 more disclosed report, best first.

More from Phi

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.