Skip to content
Business logic Audit finding Beginner

Consider emitting BucketConsumed for infinite buckets in RateLimiter

The RateLimiter contract's _consume_amount method returns early for infinite buckets without emitting a BucketConsumed event. An off-chain system monitoring these events would never see consumption from infinite buckets, which could be misleading.

Blobism Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#48747 [SC-Insight] Consider emitting BucketConsumed for infinite buckets in RateLimiter

Submitted on Jul 7th 2025 at 15:05:33 UTC by @Blobism for Audit Comp | Folks Smart Contract Library

Description

Brief/Intro

The RateLimiter method _consume_amount currently does not emit a BucketConsumed event. An off-chain system monitoring these events would never see consumption from infinite buckets, which could be misleading.

Vulnerability Details

The _consume_amount method has an early return for infinite buckets (buckets with zero duration), shown below. It would be ideal to either emit a BucketConsumed event at the early return, or clearly specify in the documentation that these events will not be emitted for infinite buckets.

Python
def _consume_amount(self, bucket_id: Bytes32, amount: UInt256) -> None:
    """Consumes an amount inside a bucket.

    Args:
        bucket_id: The bucket to consume from.
        amount: The amount to consume.

    Raises:
        AssertionError: If the bucket is unknown.
        AssertionError: If there is insufficient capacity.
    """
    # fails if bucket is unknown
    self._update_capacity(bucket_id)

    # ignore if duration is zero
    rate_limit_bucket = self._get_bucket(bucket_id)
    if not rate_limit_bucket.duration.native:
        #                      <-------------- consider emitting BucketConsumed here
        return

    # ensure there is enough capacity
    assert amount <= rate_limit_bucket.current_capacity, "Insufficient capacity to consume"

    # consume amount
    new_capacity = rate_limit_bucket.current_capacity.native - amount.native
    self.rate_limit_buckets[bucket_id].current_capacity = ARC4UInt256(new_capacity)
    emit(BucketConsumed(bucket_id, amount))

Impact Details

This is an insight for a code/documentation improvement, but does not have any security implications aside from impacting off-chain monitoring systems.

References

See contracts/library/RateLimiter.py

Proof of Concept

Proof of Concept

Observing the early return above should be sufficient to see that the event is not emitted for infinite buckets.

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

The early return for buckets with zero duration skips the event emission that occurs for finite buckets.

Impact

This is an insight for a code/documentation improvement, but does not have any security implications aside from impacting off-chain monitoring systems.

What the attacker needed

None

The fix

The code should either emit a BucketConsumed event at the early return or clearly document that these events will not be emitted for infinite buckets.

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 can emit events, which are like public notifications that off-chain programs listen to. Here, when a rate-limit bucket has no time limit (infinite), the contract skips the notification, so monitoring tools miss that usage happened. This is not a security flaw, just a design gap that could confuse monitoring.

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 Blobism

View all

19 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.