ethereum-optimism / transience

A Solidity library for transient storage management ✨
38 stars 3 forks source link

Feat: reentrancy protection with optional parameter #1

Open pegahcarter opened 2 weeks ago

pegahcarter commented 2 weeks ago

The current solution is a minimal reentrant modifier with some get/set helpers. With the state of the code today, a project which imports this repo would be required to add a few LoC to properly protect against reentrancy.

I propose implementing something similar to https://soliditylang.org/blog/2024/01/26/transient-storage/ to give inheritance flexibility in locking functions with particular keys. This should work similarly to how vyper provides reentrancy protection.

ShubhSensei commented 1 week ago

May I work on this issue?

0xfuturistic commented 1 week ago

great idea, @pegahcarter. perhaps we could add a new modifier (e., nonreentrant()) to the library that allows for transient reentrancy protection as you described. @ShubhSensei you can definitely make a PR!

ShubhSensei commented 1 week ago

@0xfuturistic There are 2 ways to do it

1) Modify the current modifier in the TransientReentrancyAware by using a transient lock with a specific key

2) Make a new modifier in the TransientContext contract itself

what should I do?

pegahcarter commented 1 week ago

@ShubhSensei let's keep everything as-is and add this feature as a new modifier (2).

0xfuturistic commented 1 week ago

agreed with you @pegahcarter, and thanks for the PR @ShubhSensei! just left a comment re:tests