Skip to content
Business logic Audit finding Intermediate

RateLimiter: incorrect infinite -> finite bucket transition

When a rate-limiter bucket is switched from a finite duration to an infinite one (duration zero) and back to finite, the stored capacity is not recalculated, so the bucket keeps its old, lower capacity instead of being restored to full. This can cause a temporary denial of service because legitimate consumption is rejected until the bucket refills.

ustas Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#49437 [SC-Insight] `RateLimiter`: incorrect infinite -> finite bucket transition

Submitted on Jul 15th 2025 at 23:42:49 UTC by @ustas for Audit Comp | Folks Smart Contract Library

Description

Description

The documentation for the RateLimiter contract specifies that a bucket with duration = 0 is considered an infinite bucket, meaning it should not be subject to capacity limits. For these buckets, core functions like _update_capacity, _consume_amount, and _fill_amount become no-ops, and has_capacity always returns True, effectively disabling the rate-limiting checks.

However, the transition of a finite bucket to an infinite one will keep the state variables limit and current_capacity without change, preserving the previous state. When an infinite bucket is then transitioned back to finite, the state variables will be simply unfreezed without the imitation of the rate limit change calculations from the infinite to a normal value.

Remediation

Add a special case to the _update_rate_duration function to fully restore the capacity if the previous duration value was 0, as any finite rate limit is always smaller than the infinity.

Proof of Concept

Proof of Concept

A visual example:

Finite bucket A

In storage
    Limit: 100
    Duration: 100
    Current capacity: 77

Effective
    Limit: 100
    Duration: 100
    Current capacity: 77

After the transition to infinity:

Infinite bucket A

In storage
    Limit: 100
    Duration: 0
    Current capacity: 77

Effective
    Limit: infinite
    Duration: 0
    Current capacity: infinite

After the transition back to finite:

Finite bucket A

In storage
    Limit: 100
    Duration: 100
    Current capacity: 77

Effective
    Limit: 100
    Duration: 100
    Current capacity: 77

While the correct values would be:

Finite bucket A

In storage
    Limit: 100
    Duration: 100
    Current capacity: 100

Effective
    Limit: 100
    Duration: 100
    Current capacity: 100

Representing the transition from the infinite limits to the previous limited ones.

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

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 duration-update routine does not reset the stored capacity when moving from an infinite bucket (duration zero) back to a finite one, so the stale capacity value is reused.

Impact

A bucket switched back to a finite limit starts with its old, lower capacity, which could cause a temporary denial of service for more than one block until it refills.

What the attacker needed

Bucket switched to infinite then back; admin changes rate duration

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 rate limiter is a counter that stops someone doing something too often, like a bucket that holds a limited amount of credit and slowly refills. This code lets an administrator switch a bucket to 'unlimited' and later back to a normal limit, but when switching back it forgets to refill the bucket, so it starts almost empty. That means normal users can be wrongly blocked for a while.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by ustas

View all

2 more disclosed reports, best first.

More from Folks Smart Contract Library

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.