Denial of service in smart contracts: when a function can't finish

A denial of service in a smart contract is a bug that lets someone stop a function from working, for a while or forever, so withdrawals, refunds, liquidations or upgrades can no longer run. It usually comes from a loop over a list anyone can grow, a payment to an address that can refuse it, or a condition that a single account can make false. Let users pull their own funds, bound every loop, and make sure no single caller or recipient can make a shared function revert.

Last updated . 6 minute read. By the QuillAudits Team.

How does a denial of service attack work on a smart contract?

It doesn't flood a server. It puts the contract in a state where a function always reverts or needs more gas than a block allows, so nobody can complete it. The common patterns:

  • Unbounded loops. A function walks a list that grows with use. The Solidity docs warn that loops without a fixed number of iterations can grow 'beyond the block gas limit', and once they do, the function can't run at all.
  • Push payments in a loop. One call pays many recipients, and a single recipient that reverts, or a send that fails, stops everyone being paid. SWC-113 advises against combining multiple calls in one transaction, 'especially when calls are executed as part of a loop'.
  • Conditions an outsider can break. A check such as require(address(this).balance == expected) fails as soon as someone forces Ether into the contract. SWC-132 says to 'avoid strict equality checks for the Ether balance in a contract'.
  • A forced revert at the right moment. A transaction that reverts if someone acts first, such as a permit that has already been used, can be blocked by anyone who sees it coming.
  • A missing actor. A function that only works while an admin key signs, a keeper runs or an oracle updates stops when they stop.

What does vulnerable code look like?

This auction refunds every bidder in one call. Anyone can add themselves to the list, and every refund must succeed for any of them to be paid.

Vulnerable: one refund loop that any bidder can block (illustrative, not audited code) AuctionRefunds.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

contract AuctionRefunds {
    address[] public bidders;
    mapping(address => uint256) public bids;
    bool public refunded;

    function bid() external payable {
        require(msg.value > 0, "no value");
        if (bids[msg.sender] == 0) bidders.push(msg.sender); // anyone can grow this list
        bids[msg.sender] += msg.value;
    }

    // Refunds everyone in one call. A bidder whose receive() reverts, or a list
    // too long for one block, stops every refund.
    function refundAll() external {
        require(!refunded, "already refunded");
        for (uint256 i = 0; i < bidders.length; i++) {
            address bidder = bidders[i];
            uint256 amount = bids[bidder];
            bids[bidder] = 0;
            (bool ok, ) = bidder.call{value: amount}("");
            require(ok, "refund failed");
        }
        refunded = true;
    }
}

An attacker bids once from a contract whose receive function always reverts. From then on refundAll reverts every time it reaches that bidder, and every other bidder's ETH stays in the contract. Thousands of tiny bids from fresh addresses reach the same result through the gas limit instead.

How do you fix it?

Let each bidder withdraw their own refund. A bidder who refuses Ether only blocks their own payment, and no loop has to fit in a block.

Fixed: each bidder pulls their own refund (illustrative, not audited code) PullRefunds.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

contract PullRefunds {
    address public immutable owner;
    mapping(address => uint256) public bids;
    bool public refundsOpen;

    constructor() {
        owner = msg.sender;
    }

    function bid() external payable {
        require(!refundsOpen, "auction closed");
        require(msg.value > 0, "no value");
        bids[msg.sender] += msg.value;
    }

    function openRefunds() external {
        require(msg.sender == owner, "not owner");
        refundsOpen = true;
    }

    // Only this bidder's own refund can fail here, and a failure leaves it owed.
    function withdrawRefund() external {
        require(refundsOpen, "refunds not open");
        uint256 amount = bids[msg.sender];
        require(amount > 0, "nothing to refund");
        bids[msg.sender] = 0;
        (bool ok, ) = msg.sender.call{value: amount}("");
        require(ok, "refund failed");
    }
}
  • Pull, don't push. Record what each account is owed and let it withdraw. The SWC-113 page links guidance titled 'Favor pull over push for external calls'.
  • Bound every loop, or process lists in pages with a stored cursor, so a long list costs more calls rather than an impossible one.
  • Track balances in variables, not with address(this).balance or a token's balanceOf, which anyone can change by sending funds.
  • Isolate each recipient's failure. If a batch must push payments, record a failed payment as owed and carry on, instead of reverting the batch.
  • Give admin-dependent paths a way out. Withdrawals should keep working when the protocol is paused for deposits, and emergency exits shouldn't depend on an oracle or a keeper.
  • Don't depend on someone else's call landing first. A function that reverts if a permit was already used should check the allowance and carry on.

How has a denial of service locked real funds?

Protocol Akutars (AkuDreams auction)
Date 22 April 2022
Chain Ethereum
Loss 11,539.5 ETH, more than $34M, locked permanently
What happened The AkuDreams Dutch auction refunded bidders in one loop, processRefunds, which BlockSec showed a bidder contract could stop by reverting when it received ETH, the pattern in the vulnerable code above. A second check locked the proceeds for good: claimProjectFunds required refundProgress to be at least totalBids, and because it compared against the wrong counter, BlockSec found the condition could never be met. The 11,539.5 ETH raised stayed in the contract with no function able to move it.
Sources BlockSec, The Block

Nobody took the money. The first bug let one account stop everyone's refunds; the second needed no attacker at all. Both are denial of service in the sense of this page: a function that other people depend on and that can no longer finish. The Block reported the lock the day after the auction, on 23 April 2022.

Which SWC and OWASP entries cover denial of service?

Entry Title What it says
SWC-113 DoS with Failed Call External calls can fail accidentally or deliberately; don't combine several in one transaction, especially in a loop
SWC-128 DoS With Block Gas Limit Be careful with arrays that grow over time, and avoid actions that loop over a whole data structure
SWC-132 Unexpected Ether balance Contracts misbehave when they assume an exact Ether balance; avoid strict equality on it
SWC-126 Insufficient Gas Griefing A relayer can forward too little gas for a sub-call; only trust relayers you choose, or require enough gas

The OWASP Smart Contract Top 10 (2025) lists the class as SC10, Denial of Service (DoS) Attacks.

What should a reviewer check?

  • List the functions that must always work: withdrawals, refunds, repayments, liquidations, unpause and emergency exits.
  • For each, can one account, one recipient or one token make it revert?
  • Does any of them loop over a list that users can add to? What is the largest the list can get, and does the loop still fit in a block?
  • Do they make external calls inside loops, and does one failure revert the whole call?
  • Do any conditions compare against address(this).balance or a token balance with ==?
  • Does any of them depend on an admin, a keeper or an oracle that might stop?
  • Are there tests with a recipient that always reverts, a recipient that burns all its gas, and lists at the largest size an attacker could build?

How does QuillShield check for denial of service?

A denial of service is a statement about every possible caller: no single account should be able to block a function others depend on. QuillShield's full audit runs over the Solidity codebase in your Foundry project, builds a security graph of the code and lists the invariants it must keep, then hands every finding to a separate reviewer agent whose job is to disprove it. A finding that survives arrives with the exact lines, the impact, a recommended fix and, for full audits, a proof of concept.

Name the functions that must always work, and the keepers and oracles you rely on, in the context you can add before the audit, next to the whitepaper, trust assumptions and privileged roles. After the audit QuillShield checks every pull request on GitHub or GitLab.com against the security graph, so a loop or a push payment added with a later feature is reviewed the same way.

If you would rather have QuillAudits auditors run it for you, talk to an auditor. Otherwise start free and see the exact price before anything is charged.

FAQ

Is a smart contract denial of service the same as a network DDoS?

No. Nobody floods a server. The contract ends up in a state where a function always reverts or needs more gas than a block allows, and it stays that way until code or state changes.

Can a denial of service bug lose funds?

Yes, when the blocked function is the only way out: a withdrawal, a refund, a repayment that avoids liquidation, or an unpause. Funds that can't move are lost to their owners even if nobody took them.

Is gas griefing a denial of service?

It's a close relative. A relayer forwards too little gas, so a sub-call fails while the outer call succeeds. SWC-126 covers it as Insufficient Gas Griefing.

How do I test for denial of service in Foundry?

Add a recipient contract whose receive always reverts, grow every user-controlled list to the size an attacker could reach, and assert that each withdrawal, refund and liquidation path still completes for everyone else.

Sources

QuillShield is building the security layer between AI and money, so you can keep shipping between audits.

Sign-up is free, and new accounts get $50 in credit, good for up to half of an order.

  1. 1Sign up and import a repo
  2. 2See the exact price before anything is charged
  3. 3Approve it, and the audit starts