Skip to content

πŸ›‘οΈExplore and learn about common Ethereum smart contract vulnerabilities through practical examples and Foundry tests.

Notifications You must be signed in to change notification settings

zeroaddresss/smart-contract-vulnerabilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Smart Contract Vulnerabilities πŸ›‘οΈ

License: MIT Solidity Foundry

A comprehensive collection of smart contract vulnerabilities and attack vectors, designed to educate developers about common security pitfalls in Ethereum smart contracts .

πŸš€ Key Features

  • Educational resource for blockchain developers and security researchers
  • Practical examples of common smart contract vulnerabilities
  • Detailed explanations of each vulnerability and its potential impact
  • Foundry test suite demonstrating exploit scenarios

πŸ—οΈ Vulnerabilities Covered

  1. On-Chain Data Exposure
  2. Signature Replay Attacks
  3. Denial of Service (DoS)
  4. tx.origin Phishing
  5. Reentrancy
  6. Force-feeding Ether
  7. WETH Permit Vulnerability

🚦 Quick Start

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/zeroaddresss/smart-contract-vulnerabilities.git
    cd smart-contract-vulnerabilities
    
  2. Install dependencies:

    forge install
    
  3. Build the project:

    forge build
    
  4. Run tests:

    forge test
    

πŸ” Vulnerability Examples and Tests

Each vulnerability comes with a corresponding Foundry test that demonstrates the exploit. You can run individual tests using:

forge test --mt testFunctionName

For example, to run the test for the Reentrancy vulnerability:

forge test --mt testAttackerCanDrainEther

To run all tests:

forge test

πŸ› οΈ Vulnerability Breakdown

On-Chain Data Exposure

Demonstrates how private data stored on-chain can be accessed by anyone.

Vulnerability: src/OnChainData.sol Test: test/OnChainDataTest.t.sol

Signature Replay Attacks

Shows how signatures can be reused in multiple transactions if not properly handled.

Vulnerability: src/SignatureReplay.sol Test: test/SignatureReplay.t.sol

Denial of Service (DoS)

Illustrates how a contract can be rendered unusable by exploiting its logic.

Vulnerability: src/DoS.sol Test: test/DosTest.t.sol

tx.origin Phishing

Demonstrates the dangers of using tx.origin for authorization.

Vulnerability: src/TxOrigin.sol Test: test/TxOrigin.t.sol

Reentrancy

Shows how a contract can be drained of funds through recursive calls.

Vulnerability: src/Reentrancy.sol Test: test/ReentrancyTest.t.sol

Force-feeding Ether

Illustrates how a contract can be forced to receive Ether, potentially disrupting its logic.

Vulnerability: src/ForceEther.sol Test: test/ForceEtherTest.t.sol

WETH Permit Vulnerability

Demonstrates a vulnerability specific to WETH contracts lacking a permit function.

Vulnerability: src/WETHPermit.sol Test: test/WETHPermitTest.t.sol

πŸ—‚οΈ Project Structure

smart-contract-vulnerabilities/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ OnChainData.sol
β”‚   β”œβ”€β”€ SignatureReplay.sol
β”‚   β”œβ”€β”€ DoS.sol
β”‚   β”œβ”€β”€ TxOrigin.sol
β”‚   β”œβ”€β”€ Reentrancy.sol
β”‚   β”œβ”€β”€ ForceEther.sol
β”‚   └── WETHPermit.sol
β”œβ”€β”€ test/
β”‚   β”œβ”€β”€ OnChainDataTest.t.sol
β”‚   β”œβ”€β”€ SignatureReplay.t.sol
β”‚   β”œβ”€β”€ DosTest.t.sol
β”‚   β”œβ”€β”€ TxOrigin.t.sol
β”‚   β”œβ”€β”€ ReentrancyTest.t.sol
β”‚   β”œβ”€β”€ ForceEtherTest.t.sol
β”‚   └── WETHPermitTest.t.sol
└── README.md

πŸ› οΈ Dependencies

  • Solidity ^0.8.26
  • Foundry
  • OpenZeppelin Contracts

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ§ͺ Testing

Run the test suite using Foundry:

forge test

For verbose output:

forge test -vvvvv

πŸ“‹ Roadmap

  • Add more vulnerability examples
  • Implement mitigation strategies for each vulnerability

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • OpenZeppelin for their secure contract implementations
  • Ethereum community for ongoing research in smart contract security

βœ‰οΈ Contact

[email protected] - zeroaddresss - zeroaddresss

Project Link: https://github.com/zeroaddresss/smart-contract-vulnerabilities


⚠️ Disclaimer: This project is for educational purposes only. Do not use vulnerable code in production environments.

About

πŸ›‘οΈExplore and learn about common Ethereum smart contract vulnerabilities through practical examples and Foundry tests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published