Skip to content

arinaitweallan/ReentrancyLock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReentrancyLock: Transient storage edition

This contract provides a gas efficient reentrancy guard by leveraging EIP-1153 transient storage opcodes (tstore and tload). Unlike traditional guards that use permanent storage (sstore), this lock is automatically cleared at the end of the transaction, significantly reducing gas costs for users.

Key Features

  • Ultra gas efficient: Eliminates the "cold" vs "warm" storage costs associated with traditional reentrancy guards.

  • Automatic reset: Since it uses transient storage, the state is cleared at the end of every transaction, preventing "stuck" locks.

  • Minimal footprint: Uses assembly to interact directly with storage slots for maximum optimization.

Usage

  • Inherit from the ReentrancyLock contract.

  • Apply the cantReenter modifier to sensitive external or public functions.

import "./ReentrancyLock.sol";

contract MySecureContract is ReentrancyLock {
    
    function sensitiveWithdraw() external cantReenter {
        // function logic
    }
}

Security warning

Do not deploy this on chains that do not support the Cancun hardfork. On incompatible chains, the tstore and tload opcodes will cause the transaction to fail or behave unpredictably.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published