Skip to content
DoS Audit finding Intermediate

removeValidator() and removeMinter() may fail due to exceeding gas limit

The removeValidator and removeMinter functions use unbounded loops over arrays that can grow large, so calling them may fail if the array size makes the transaction exceed the block gas limit. An attacker could potentially cause these functions to become unusable by increasing the array size, though the report does not demonstrate a concrete attack.

oyc_109 Follow

Originally disclosed on Code4rena

Submitted by oyc_109, also found by 0x4non, Chom, ladboy233, Lambda, lukris02, pashov, Respx, and V_B

https://github.com/code-423n4/2022-09-frax/blob/55ea6b1ef3857a277e2f47d42029bc0f3d6f9173/src/OperatorRegistry.sol#L113-L118

https://github.com/code-423n4/2022-09-frax/blob/55ea6b1ef3857a277e2f47d42029bc0f3d6f9173/src/ERC20/ERC20PermitPermissionedMint.sol#L84-L89

Vulnerability Details

removeValidator() and removeMinter() may fail due to exceeding gas limit

https://github.com/code-423n4/2022-09-frax/blob/55ea6b1ef3857a277e2f47d42029bc0f3d6f9173/src/OperatorRegistry.sol#L113-L118

            for (uint256 i = 0; i < original_validators.length; ++i) {
                if (i != remove_idx) {
                    validators.push(original_validators[i]);
                }
            }

https://github.com/code-423n4/2022-09-frax/blob/55ea6b1ef3857a277e2f47d42029bc0f3d6f9173/src/ERC20/ERC20PermitPermissionedMint.sol#L84-L89

        for (uint i = 0; i < minters_array.length; i++){
            if (minters_array[i] == minter_address) {
                minters_array[i] = address(0); // This will leave a null in the array and keep the indices the same
                break;
            }
        }

The removeValidator() is used to remove a validator from the array validators.

There is an unbounded loop in removeValidator() such that if the validators array gets sufficiently large, this function call will fail due to exceeding the gas limit.

The same issue exists in the removeMinter() function. If minters_array gets large, the function call will fail.

FortisFortuna (Frax) commented:

Technically correct, but in practice, the number of minters will always remain low. If it becomes an issue, we can designate one minter as a “pre-minter” that has a batch of tokens minted to it beforehand, then auxiliary contracts can connect to that instead of ERC20PermitPermissionedMint.sol instead.

0xean (judge) commented:

I think Medium is appropriate here, given this could impact the functionality of the protocol.

Trust (warden) commented:

Wouldn’t call this a risk to the functionality of the protocol, because sender can always send enough gas, and validator array gets truncated every time on is popped for use.

Unbounded for-loops should be handled with care but not sure a realistic impact can be demonstrated here to qualify for Medium.


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

The functions removeValidator and removeMinter could become uncallable if the arrays grow large, potentially disrupting the protocol's ability to remove validators or minters, though the report notes that in practice the number of minters is expected to remain low.

What the attacker needed

Arrays grow large enough to exceed gas limit

The fix

The functions should be redesigned to avoid unbounded loops, for example by using a mapping or by limiting the array size, so that removal operations do not depend on the total number of entries.

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.

In blockchain smart contracts, every operation costs 'gas', and there is a maximum amount of gas allowed per transaction. If a function loops over a list that can grow very long, the gas cost can exceed that maximum, causing the function to always fail. This report points out that two functions that remove items from lists have this problem, so they might become unusable if the lists get too big.

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 oyc_109

View all

3 more disclosed reports, best first.

More from Frax Ether Liquid Staking contest

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.