solmate icon indicating copy to clipboard operation
solmate copied to clipboard

ReentrancyGuard doesn't work as intended with Clones

Open PraneshASP opened this issue 3 years ago • 1 comments

Hi,

I was trying to deploy contracts (Factory pattern) via OpenZeppelin's Clones library. My implementation contract uses Solmate's ReentrancyGuard. When I was trying to execute some methods on the cloned contract that has the nonReentrant modifier, it always reverts with the following error:

Error: VM Exception while processing transaction: reverted with reason string 'REENTRANCY'

Possible workaround: Change the condition from require(locked == 1, "REENTRANCY"); to require(locked < 2, "REENTRANCY"); so that it doesn't affect the gas cost and it also becomes compatible with Clones by default by eliminating the necessity of manually setting the storage slot to 1. Not sure if its the correct solution for the issue^^

Is it worth creating a PR for this?
Please let me know your thoughts.

Thanks!

PraneshASP avatar May 01 '22 10:05 PraneshASP

note to self: check with sam if this is safe (90% sure it is)

transmissions11 avatar Jun 09 '22 05:06 transmissions11