Skip to content
Smart contracts Write-up Intermediate

Exploring web3 Security A Step By Step Guide To Creating Proof Of Concepts For Previous Findings

The withdrawETHForKnot function in the Stakehouse contract allows node runners to withdraw ETH and then bans their public key, but it makes an external call before updating state, enabling reentrancy. An attacker could repeatedly reenter the function before their key is banned and drain funds.

Yuvarajan Follow

Published on infosecwriteups.com

Good day, hackers Are you new to auditing smart contracts? Are you the one who just began participating in Code4rena competitions?

Yuvarajan, on infosecwriteups.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 contract makes an external call to transfer ETH before marking the caller's public key as banned, violating the checks-effects-interactions pattern.

Impact

An attacker could drain ETH from the smart wallet by reentering before their public key is banned.

What the attacker needed

Be a node runner with a smart wallet; deploy a malicious contract

The fix

The function should follow the checks-effects-interactions pattern by banning the public key before transferring ETH.

How it was found

  1. Clone the repository and enter the directory.
  2. Compile the project with forge build using the hardhat compatibility flag.
  3. Write an exploit contract that calls withdrawETHForKnot and reenters from its receive function.
  4. Write a test case in the test folder to verify the exploit.
  5. Run the test with forge test.

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 on a blockchain that can hold and send money. Reentrancy is when a contract sends money to another contract, and that other contract immediately calls back into the first one before it has finished updating its records, so it can trick the first contract into sending money multiple times.

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 Yuvarajan

View all

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