transience icon indicating copy to clipboard operation
transience copied to clipboard

Feat: reentrancy protection with optional parameter

Open pegahcarter opened this issue 1 year ago • 5 comments

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.

pegahcarter avatar Jun 18 '24 22:06 pegahcarter

May I work on this issue?

ShubhSensei avatar Jun 20 '24 12:06 ShubhSensei

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!

0xfuturistic avatar Jun 22 '24 22:06 0xfuturistic

@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

    • Then increment and decrement functions have to be deleted
    • Also, have to make changes in the Test file
  2. Make a new modifier in the TransientContext contract itself

what should I do?

ShubhSensei avatar Jun 23 '24 06:06 ShubhSensei

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

pegahcarter avatar Jun 23 '24 14:06 pegahcarter

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

0xfuturistic avatar Jun 25 '24 01:06 0xfuturistic