Chapter 1: The Vault Contract – The Re-entrancy Heist

The Code Nexus hummed with the quiet electricity of concentrated minds. Holographic displays flickered in every direction, casting pale blue light across rows of workstations where young developers hunched over floating keyboards, their fingers dancing through the air as they manipulated lines of code that existed nowhere and everywhere at once.

Elara stood at the front of the main presentation area, her heart racing with the familiar thrill of public demonstration. At seventeen, she was one of the youngest developers to command this space, but she’d earned it. The Vault wasn’t just another project—it was her masterpiece, her legacy, her proof that she belonged among the best.

“Alright everyone, settle in,” she called out, her voice carrying easily through the open-plan space. A dozen faces turned toward her, some familiar, some new. The weekly Code Nexus showcase was where developers presented their work, and today, Elara had the spotlight.

She activated the main holographic display, and lines of code materialized in the air before her—elegant, precise, beautiful in their logic. The Vault’s smart contract glowed in crisp white text against a dark background, key functions highlighted in soft green.

“Welcome to The Vault,” she began, a confident smile playing at her lips. “For those who don’t know, The Vault is a savings protocol built on the Stellaris blockchain. Users deposit their tokens, earn competitive interest rates, and can withdraw at any time. Simple. Elegant. And, most importantly, absolutely secure.”

A murmur of appreciation rippled through the small crowd. The Vault had been making waves in the developer community—fifty thousand users, nearly forty-seven million tokens in deposits. It was the kind of success that made other developers take notice.

“Let me show you why it works,” Elara continued, gesturing at the code. “This is the core withdrawal function—the heart of the entire protocol.”

She highlighted a block of code, and it expanded, showing its structure in detail:

function withdraw(uint256 amount) external {
    require(balances[msg.sender] >= amount, "Insufficient balance");
    (bool success, ) = msg.sender.call{value: amount}("");
    require(success, "Transfer failed");
    balances[msg.sender] -= amount;
}

“See how clean this is?” Elara said, her voice filled with pride. “We send the funds to the user, then update their balance. Efficient, minimal gas cost, and completely atomic—the whole thing executes in a single transaction.”

A hand went up in the back. It was Kai, a younger developer who’d been coming to the Nexus for only a few months. He had the earnest, slightly anxious look of someone about to ask a question he wasn’t sure was smart.

“Yes, Kai?”

“Um, doesn’t the order matter?” Kai asked, frowning at the code. “Shouldn’t you update the balance first, then send the funds?”

Elara’s smile tightened almost imperceptibly. She’d heard this question before, always from people who didn’t fully understand how blockchain transactions worked.

“Great question,” she said, though her tone carried a hint of condescension. “But here’s the thing—the order of execution is atomic. It doesn’t matter whether we update the balance first or send the funds first because the whole thing happens in one transaction. There’s no gap where someone could exploit it.”

She clicked a button, and a visualization appeared: a single block on a chain, containing the entire withdrawal function executing in sequence.

“See? It’s all or nothing. If the transfer fails, the whole transaction reverts. There’s no partial state. That’s the beauty of blockchain.”

Kai nodded, still looking slightly uncertain but not willing to push further. Elara moved on, satisfied that she’d addressed the concern.

“Now, I know some of you might be thinking about re-entrancy attacks,” she said, her voice taking on a slightly dismissive edge. “Don’t worry—I’ve got that covered too.”

She expanded another section of code:

modifier noReentrant() {
    require(!locked, "Reentrant call detected");
    locked = true;
    _;
    locked = false;
}

“The re-entrancy guard,” she announced, as if unveiling a trophy. “This modifier locks the withdrawal function during execution. If someone tries to call it again before the first call completes, the transaction reverts. It’s a standard security measure that I implemented from day one.”

She scanned the room, daring anyone to challenge her. No one did. The confidence in her voice was absolute.

“The Vault has passed three independent security audits,” she continued, projecting a summary onto the main display. “AuditOne, ChainSafe, and BlockProof all gave it their highest rating. Twenty thousand lines of code, zero critical vulnerabilities.”

She paused, letting that sink in. Three audits was overkill for most projects, but Elara had wanted to be thorough. The Vault was going to be her calling card, the project that established her reputation as the next generation of smart contract developers.

“The auditors specifically praised the re-entrancy guard as ‘industry best practice,'” she added, reading from the report. “So, to answer your concern, Kai—I’ve thought of everything.”

A smattering of applause went through the room. Elara basked in it, feeling the familiar warmth of recognition. This was what she’d worked for, what she’d sacrificed late nights and missed social events to achieve.

She pulled up The Vault’s dashboard on another screen—a beautiful interface showing real-time statistics:

Total Value Locked: $47,382,194.83**
**Active Users: 51,247**
**Interest Accrued (24h): $12,847.91

Withdrawals (24h): 142

“Fifty-one thousand users,” she said, her voice softening with genuine emotion. “That’s fifty-one thousand people who trust The Vault with their savings. Fifty-one thousand people who are earning passive income because of the code I wrote.”

She scrolled through the recent activity, showing the kinds of transactions that flowed through The Vault every day:

User: mira.eth → Withdrawn: 2,450 tokens
User: carlos.eth → Deposited: 10,000 tokens
User: david.eth → Earned Interest: 43.27 tokens

“The Vault has already become a lifeline for working families,” she continued, her voice rising with passion. “Teachers, nurses, single parents—they’re using The Vault to save for university, for houses, for their children’s futures. That’s why security matters. That’s why I’m so careful.”

She caught herself, realizing she was getting emotional. She took a breath and smiled.

“Anyway,” she said, returning to a more professional tone, “that’s The Vault. Simple, secure, and changing lives. I’m happy to answer any questions.”

For the next fifteen minutes, she fielded technical questions about gas optimization, interest calculation methods, and her choice of compiler version. She answered each one with authority, never hesitating, never uncertain. The Vault was her domain, and she knew it inside and out.

The session ended with more applause, and Elara felt a surge of satisfaction as she powered down the holographic display. People came up to congratulate her, to ask follow-up questions, to tell her they’d been following The Vault’s success.

“You’re going places, Elara,” one of the senior mentors said, clapping her on the shoulder. “You should be proud.”

“Thank you,” she said, genuinely pleased. “I am.”


The rest of the afternoon passed in a blur of code reviews and emails. Elara settled back into her workstation—a corner space with three floating screens arranged in a semicircle around her chair. One screen showed The Vault’s live metrics, another displayed the codebase, and the third was her inbox, which was perpetually overflowing with messages.

She loved her setup. The Code Nexus had provided state-of-the-art equipment for its top developers, and Elara had definitely earned her place among them. The programmable holographic surfaces let her arrange information exactly as she needed it, and the neural interface allowed her to scroll through code with just a thought.

She spent the next hour reviewing a minor update to the interest calculation function. It was a small optimization, barely noticeable to users, but Elara took pride in the details. She’d pored over every line of The Vault’s code dozens of times, searching for any inefficiency, any edge case, any possibility of failure.

Her attention to detail was why The Vault was so successful. Her users could sleep soundly knowing their savings were protected by code that had been scrutinized more thoroughly than most enterprise software.

“A second review, just to be sure,” she muttered, scrolling through the updated function again.

She caught herself, almost amused at her own thoroughness. She’d already reviewed this code three times, but she couldn’t help it. The Vault was her baby. She wanted it to be perfect.

Her eyes drifted to the live dashboard. Fifty-one thousand users. Forty-seven million tokens. It was hard to believe sometimes. When she’d started building The Vault, she’d hoped for a few hundred users—enough to prove her concept, enough to get her foot in the door of the industry. The scale of what she’d built was almost overwhelming.

She pulled up the messages from users, as she often did when she needed motivation. There was one from a user named Mira:

“Thank you so much for creating The Vault. I’m a teacher, and my daughter’s university fund is growing so much faster than it ever did in a traditional bank account. You’ve changed our lives.”

Elara felt a lump in her throat. She read another:

“I’m a nurse working double shifts to save for a house. The Vault is helping me get there faster than I ever thought possible. Thank you for building something so safe and reliable.” – Carlos

And another:

“My wife passed away last year. I’m a single father now, raising two kids on my own. The inheritance I put in The Vault is generating income that helps me provide for them. I can’t tell you what that means to me. – David”

Elara leaned back in her chair, staring at those words. Safe and reliable. Changed our lives. These weren’t just users. These were real people with real hopes and fears. People who trusted her.

She took a deep breath, feeling the weight of that trust. It was both exhilarating and terrifying. She’d built something that mattered, something that was genuinely making the world better. But it also meant that she could never, ever make a mistake.

The Vault was her responsibility. Her legacy. Her proof to the world—and to herself—that she was capable of great things.

She glanced at her inbox, ready to finally dig into the mountain of messages she’d been ignoring. Most were routine: user support requests, partnership inquiries, the usual noise of running a successful protocol.

But one message caught her eye.

The subject line read: “URGENT: Security Concern with The Vault”

Elara sighed. Not this again. She seemed to get at least one of these a week—someone who’d found a “critical vulnerability” that was actually just a misunderstanding of how the code worked. The auditors had assured her that The Vault was secure. Three independent firms couldn’t all be wrong.

Still, she opened the message. It was from an address she didn’t recognize: ronen.sol. The body of the email was brief but surprisingly detailed:

“Elara,

I’ve been analyzing The Vault’s codebase and have identified what I believe is a serious re-entrancy vulnerability. While the withdrawal function is protected by a re-entrancy guard, I’ve found that a secondary function—updateUserInterest()—lacks the same protection. An attacker could use this function to bypass the guard and execute a cross-function re-entrancy attack, draining funds recursively.

I’ve attached a proof-of-concept demonstrating the exploit. I strongly recommend you review this immediately and implement a fix.

I’m not asking for a bounty. I’m asking you to protect your users.

Regards,
Ronen”

Elara stared at the message, her initial irritation slowly giving way to something else—a flicker of unease. She’d dismissed the “order matters” question from Kai earlier, but this was different. This was a detailed claim from someone who’d clearly done their research.

She opened the attachment. It was a proof-of-concept contract, well-written and carefully commented. The code demonstrated exactly how an attacker could use updateUserInterest() to trigger a recursive withdrawal loop, bypassing the re-entrancy guard on the main withdrawal function.

Elara felt a cold knot form in her stomach.

No, she told herself firmly. That’s not how it works. The guard locks the entire contract state, not just individual functions. Even if updateUserInterest() doesn’t have the modifier, the locked variable is shared across the contract.

She read the proof-of-concept again, more carefully this time. And then she saw it.

The attacker wouldn’t call withdraw() directly from the malicious contract’s receive function. Instead, they’d use updateUserInterest() as the entry point, which would call withdraw() internally. Since the guard only checked withdraw() itself, the recursion would be allowed.

It was a subtle attack vector—so subtle that even three audits had missed it.

Elara’s hands felt cold. She pulled up The Vault’s code, scrolling to the updateUserInterest() function. She’d written this months ago, during a late-night coding session. It was supposed to be a minor administrative function for updating interest rates. She hadn’t thought it needed the re-entrancy guard because it didn’t directly change user balances.

The code stared back at her, damning in its simplicity:

function updateUserInterest(address user) external {
    InterestData storage data = interestData[user];
    data.lastUpdate = block.timestamp;
    uint256 pending = calculatePendingInterest(user);
    data.pendingInterest = pending;
}

No guard. No nonReentrant modifier. And nested inside it, an internal call to a function that did change balances.

She could see it now, clear as day. The attack would work. An attacker could deposit a small amount, then call updateUserInterest() to trigger the vulnerable path. The malicious contract’s receive function would then call updateUserInterest() again, and again, and again, draining funds from The Vault faster than anyone could stop it.

Her hand trembled as she tabbed back to Ronen’s email.

Please review this immediately and implement a fix.

She should respond. She should thank him, tell him she’d look into it, maybe even ask for more details. That was the responsible thing to do.

But something stopped her. A voice in her head—maybe pride, maybe fear—whispered that she’d be admitting she’d made a mistake. That her perfect code wasn’t perfect. That she’d missed something so fundamental that three independent security audits had missed it too.

No, she thought. The auditors would have caught this. They went through every function, every interaction. If there was a vulnerability here, they would have found it.

She read Ronen’s proof-of-concept again, looking for flaws. There had to be something she was missing. The auditors had praised her security measures. They’d specifically highlighted the re-entrancy guard as a best practice.

She found what she was looking for: a small oversight in the proof-of-concept. The attacker would need to call updateUserInterest() from a contract that had a balance in The Vault, and the function didn’t allow arbitrary addresses to be updated—it was restricted to the caller’s own address.

Wait, she thought. That does limit the attack. An attacker would have to deposit tokens first, and then use their own address to trigger the recursion.

But even as she thought it, she realized it wasn’t a real limitation. An attacker could easily deposit a small amount of tokens—just enough to have a balance in The Vault—and then execute the attack. The deposit would be dwarfed by the millions they’d steal.

The cold knot in her stomach tightened.

She closed Ronen’s email without responding. She couldn’t deal with this right now. She had a showcase presentation later that week, and her schedule was packed. The vulnerability, if it even existed, could wait.

She’d look into it properly when she had time. Maybe after the showcase. Maybe she’d run it by one of the auditors.

But for now, she pushed the unease to the back of her mind and went back to her code review. The Vault was secure. The audits said so. Three of them.

She was being paranoid.


The evening sun was setting over the city, painting the sky in shades of orange and purple, when Elara finally packed up her workstation. She’d spent the last few hours going over the interest calculation code again, making small optimizations, testing edge cases.

She’d also, she admitted to herself, avoided opening Ronen’s email again.

Her phone buzzed as she was putting on her jacket. A message from a friend: “Celebrating at the Sky Lounge tonight. You coming? You’ve earned it after that presentation.”

Elara smiled. A night out sounded perfect. A chance to forget about code and vulnerabilities and emails from concerned strangers. She’d been working too hard lately, obsessing over every detail of The Vault. She deserved a break.

“On my way,” she typed back.

She stepped out of The Code Nexus and into the cool evening air. The city sparkled around her, lights flickering to life as darkness crept across the sky. She breathed deeply, letting the stress of the day slowly ebb away.

In her pocket, her phone buzzed again. Another message. This time from an unknown number.

“Please read my email. Your users are at risk.” – Unknown

Elara’s heart skipped a beat. The message was clearly from the same person—Ronen. How had he gotten her personal number? She’d never given it out publicly.

He’s a hacker, she realized. Of course he’s good at finding people’s contact information.

She looked at the message, her thumb hovering over the reply button. She should respond. She should tell him she’d looked at his proof-of-concept and would take it seriously.

But she didn’t. She pocketed the phone and walked toward the Sky Lounge, trying to push the whole thing out of her mind.

She’d deal with it tomorrow. Or the day after. Or whenever she had time.

It was probably nothing, anyway. Just another overeager developer looking for attention.


The Sky Lounge was buzzing when Elara arrived. Music pulsed through the speakers, and holographic projections danced across the ceiling, creating an atmosphere of controlled chaos. Friends called out to her from across the room, raising glasses in salute.

“There she is!” Maya, one of her closest friends, grabbed her arm and pulled her toward the bar. “The queen of smart contracts herself. Did you see your presentation? Absolutely crushed it.”

Elara felt herself relaxing as the familiar energy of the lounge washed over her. This was what she needed—friends, music, a chance to feel normal for a few hours.

“Thanks,” she said, accepting a drink. “I was pretty nervous, honestly. So many people watching.”

“As if,” Maya laughed. “You were born for that stage. You had everyone eating out of your hand.”

Elara smiled, letting the praise wash over her. She’d earned it. The Vault was everything she’d dreamed it could be, and more. Fifty-one thousand users trusting her code with their savings. Three audits confirming her security measures. A reputation that was growing by the day.

Everything was perfect.

But even as she laughed and talked and celebrated with her friends, a small part of her mind was elsewhere. It was scrolling through code, examining the updateUserInterest() function, trying to convince itself that the vulnerability wasn’t real.

She pushed the thought away, forcing herself to focus on the present moment. She’d worked hard. She deserved this.

Hours later, as she stumbled home through the quiet streets, her phone buzzed one more time. She’d almost forgotten about it, lost in the haze of celebration.

She pulled it out, squinting at the screen.

The message was from an address she didn’t recognize. It was short, chillingly simple, and it made her blood run cold:

“Thank you for the tip. The Vault is mine.”

Table of contents:
Introduction
Chapter 1: The Vault Contract
Chapter 2: A Withdrawal Request <<<<<< NEXT
Chapter 3: The Recursive Call
Chapter 4: Draining the Treasury
Chapter 5: The Frozen Audit Log
Chapter 6: The Emergency Pause
Chapter 7: A Time-Locked Patch
Chapter 8: The White Hat Rescue
Chapter 9: The Forked Recovery
Chapter 10: Code Is Not Trust

Loading



Dear reader, love our creation? Support us moving forward