Skip to content

Aboudoc/Signature-Replay-attack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Reentrancy Attack

project_description
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Product Name Screen Shot

(back to top)

Built With

  • Hardhat
  • Ethers

(back to top)

Getting Started

To get a local copy up and running follow these simple example steps.

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

  • npm

    npm install npm@latest -g
  • hardhat

    npm install --save-dev hardhat
    npm install @nomiclabs/hardhat-ethers @nomiclabs/hardhat-waffle

    run:

    npx hardhat

Installation

  1. Clone the repo
    git clone https://github.com/Aboudoc/Signature-Replay-Attack-demo.git.git
  2. Install NPM packages
    npm install

(back to top)

Usage

If you need testnet funds, use the Alchemy testnet faucet.

This project shows the Signature Replay Attack and how to to be safe with signature verification

To learn how to verify a signature, check this repo: Verify-signature-demo

There are 2 ETH in SignatureReplay contract.

Owner of SignatureReplay will sign a signature to approve your contract to withdraw 1 ETH.

There are 2 ETH in SignatureReplay contract. Drain all ETH from it.

Signature Replay Attack

Sometimes in smart contracts it is necessary to perform signature verification to improve usability and gas cost. However, consideration needs to be taken when implementing signature verification. To protect against Signature Replay Attacks, the contract should only be allowing new hashes to be processed. This prevents malicious users from replaying another users signature multiple times.

To be extra safe with signature verification, follow these recommendations:

  • Store every message hash processed by the contract, then check messages hashes against the existing ones before executing the function.
  • Include the address of the contract in the hash to ensure that the message is only used in a single contract.
  • Never generate the message hash including the signature.

To go further, learn more about Replay Attack Vulnerability in Ethereum Smart Contracts Introduced by transferProxy()

Signature Malleability

Often, people assume that the use of a cryptographic signature system in smart contracts verifies that signatures are unique, however, this isn't the case. Signatures in Ethereum can be altered without the private key and remain valid. For example, elliptic key cryptography consists of three variables: v, r, and s and if these values are modified in just the right way, you can obtain a valid signature with an invalid private key.

To avoid the problem of signature malleability, never use a signature in a signed message hash to check if previously signed messages have been processed by the contract because malicious users can find your signature and recreate it.

Further reading

Sources

(back to top)

Roadmap

  • deploy on goerli and test by signing off chain using metamask

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  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

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Reda Aboutika - @twitter - reda.aboutika@gmail.com

Project Link: https://github.com/Aboudoc/Signature-Replay-Attack-demo.git

(back to top)

Acknowledgments

(back to top)

Releases

No releases published

Packages

No packages published