Coder Social home page Coder Social logo

transience's Introduction

✨ Transience

A Solidity library for transient storage

Transience is a Solidity library for safely managing transient storage in smart contracts. It stores values by call depth, allowing reentrancy-aware functions that ensure isolated storage across reentrant calls.

Features

  • Transient Storage: Transience offers methods for writing and reading transient storage without having to use assembly/Yul.

  • Reentrancy Awareness: Transience keeps track of the current call depth, preventing a reentrant function call from overwriting its parent's transient storage location.

How It Works

Transience uses a unique slot identifier and the current call depth to determine a distinct storage location. The library provides two main functions:

  • get(bytes32 _slot): Retrieves the value in transient storage corresponding to _slot at the current call depth.
  • set(bytes32 _slot, uint256 _value): Sets _value as the value in transient storage corresponding to _slot at the current call depth.

The TransientReentrancyAware contract offers a reentrantAware modifier that automatically increments and decrements the call depth when entering and exiting a function, ensuring isolation from calls at other call depths (i.e., from a reentrant call).

Getting Started

  1. Install the library in your Solidity project
forge install ethereum-optimism/transience
  1. Import the library's contracts in your smart contract
import {TransientContext, TransientReentrancyAware} from "transience/src/TransientContext.sol";
  1. Inherit from TransientReentrancyAware to access the reentrantAware modifier
  2. Use get(bytes32 _slot) and set(bytes32 _slot, uint256 _value) to retrieve and set values in transient storage

Contribute & Feedback

Feel free to raise an issue, suggest a feature, or even fork the repository for personal tweaks. If you'd like to contribute, please fork the repository and make changes as you'd like. Pull requests are warmly welcome.

transience's People

Contributors

0xfuturistic 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.