Skip to content
Smart contracts Write-up Beginner

Exploring a Web3 Smart Contract Issue: Gas Exploitation via Unchecked Loops

A batch airdrop function in a smart contract let anyone call it and accepted an unlimited number of addresses, so a caller could pass thousands of addresses and make the loop consume all available gas. This could make the contract unusable or lock ETH through failed execution.

vinaysati Follow

Published on vinaysati.medium.com

This content is meant purely for learning and research purposes. Avoid testing vulnerabilities on public blockchains.

Vinaysati, on vinaysati.medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The airdrop function had no access control and no cap on the length of the user-supplied address array, so the loop could be driven past the gas limit.

Impact

A caller could exhaust gas and cause the contract to become unusable or lock ETH through failed execution; the text describes this as a simulation in a test environment, not a live exploit.

What the attacker needed

Ability to call the airdrop function; no access control on the function

The fix

The function should be restricted to authorised callers and should cap or batch the number of addresses it processes.

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 write-up has not been written yet. The Original tab links to the source.

A smart contract is a program that runs on a blockchain. This one had a function that paid out tokens to a list of addresses in a loop, and it never checked who was calling or how long the list was. Anyone could send a huge list, so the loop ran until it used up all the allowed processing effort (gas) and the transaction failed.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by vinaysati

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.