GithubHelp home page GithubHelp logo

solidstate-network / diamond-storage-preimage-attack Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 134 KB

Proof-of-concept of a diamond storage preimage attack ๐Ÿ’Ž ๐Ÿ’ฅ

Shell 1.76% TypeScript 43.67% Solidity 54.57%
diamond eth ether ethereum evm harhat keccak keccak256 preimage proxy

diamond-storage-preimage-attack's Introduction

Diamond Storage Preimage Attack

Proof-of-concept of a diamond storage preimage attack.

Description

This attack can be executed by crafting a particular seed string for the purpose of calculating a diamond storage slot. This seed consists of 64 bytes and can be thought of as a string composed of two 32-byte substrings.

The first of these substrings (substring A) is human-readable:

'diamond.storage.thirtytwobytestr'

Here's its hex representation:

0x6469616d6f6e642e73746f726167652e74686972747974776f62797465737472

The second substring (substring B) is composed of zero-bytes and therefore has no valid string representation:

0x0000000000000000000000000000000000000000000000000000000000000000

The 64-byte seed is hashed, and the result is used as the storage slot for a diamond storage struct.

Now, a mapping is defined at storage slot 0, matching the value of substring B. Accessing this mapping using substring A as a key is equivalent to accessing the diamond storage struct due to the way mapping storage slots are calculated.

Instructions

Install dependencies via Yarn:

yarn install

Compile contracts via Hardhat:

yarn run hardhat compile

Run the tests to demonstrate the attack:

yarn run hardhat test

diamond-storage-preimage-attack's People

Contributors

itsnickbarry avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.