0xsergen / reentrancy-attack

Smart contracts and tests for re-entrancy attack workshop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Re-entrancy Attack

This project consists of two basic staking smart contracts (one of them is vulnerable to re-entrancy attack) and one attack smart contract. The test file is to show the the importance of safety.

Run Locally

To get started with this project, clone this repo and follow these commands in your terminal:

Clone the project

  git clone git clone https://github.com/0xsergen/reentrancy-attack.git

Go to the directory of project

  cd reentrancy-attack 

Install dependencies

  yarn install

Run the test

  npx hardhat test test/Attack.js

You should see similar output.

  Re-entrancy Attack
User1 deposited 5 ETH to VulnerableStaking.
User2 deposited 5 ETH to VulnerableStaking.
VulnerableStaking has 10 ETH now.
Attacker will attack to VulnerableStaking now.
ETH balance of Staking Contract is 0.0
    ✔ Should hack vulnerable staking contract
User1 deposited 5 ETH to SafeStaking.
User2 deposited 5 ETH to SafeStaking.
SafeStaking has 10 ETH now.
Attacker will attack to VulnerableStaking now.
ETH balance of Staking Contract is 10.0
    ✔ Should NOT hack safe staking contract

  2 passing

You can check and modify test/Attack.js to try different scenarios.

About

Smart contracts and tests for re-entrancy attack workshop


Languages

Language:JavaScript 68.1%Language:Solidity 31.9%