Cover photo

The Gas-Powered Nightmare: When Your Modifier Hates You

Fabian Owuor

Fabian Owuor

“I Spent 1 ETH on Gas and All I Got Was This Infinite Loop”

Subtitle:
How one innocent-looking Solidity modifier taught me that trust issues begin at the {.

The False Sense of Security

There I was, minding my own business, writing a harmless smart contract like a responsible developer. Everything was going fine… until I met Trap.sol.

modifier gasTrap() {
    while (true) {}
    _;
}

I thought, “Cool name. Probably just a fancy access control check, right?”

Wrong.
So, so wrong.

The Deception

function run() public gasTrap {
    // Never executes
}

See this? This is what betrayal looks like in EVM bytecode.
You’d think run() would run. But instead, it sprints through your gas allowance and crashes like a DeFi protocol on Twitter rumors.

Little did I know, run() is a black hole for gas. It doesn’t just burn your gas — it vaporizes your optimism. The moment I called it, MetaMask made a face like:

How I Lost 0.3 ETH in 3 Seconds

I clicked “Confirm.”
I waited.
And then... nothing.

Nothing but the echo of gas fees screaming as they were sacrificed to the Ethereum gods.

When the transaction finally failed, I received no error message. Just a quiet void and an empty wallet.

The blockchain didn’t say “invalid operation.” It said:

“You knew what you did.”

The Forensics Report

Upon deep analysis (and crying into my Remix tab), I realized:

  • The modifier traps you before the function runs.

  • It doesn’t revert.

  • It doesn’t continue.

  • It just loops.

  • Forever.

  • Like that one friend who always “forgets” to pay their share of gas (but IRL).

This modifier isn't a security feature. It's a philosophical statement about the futility of existence in the EVM.

Bonus: What You Could Use It For

  • Fake security layers: “No hacker shall pass… or user. Or even yourself.”

  • Rage Quit DAO: Anyone who tries to rage quit just gets rage looped.

  • Gas burning rituals: Vitalik approves (probably not).

  • Art installations on-chain titled “The Function That Never Was.”

Moral of the Story

Never trust a modifier named gasTrap.
Never copy code from weird forums at 3AM.
And always test on testnet unless you want your wallet to look like a tumbleweed.

Epilogue

I now sleep with one eye open and require(false, "Are you sure?") in every contract I write. My modifiers now ask politely.

You’ve been warned.
Trap.sol is real. And it wants your gas.

The Gas-Powered Nightmare: When Your Modifier Hates You