transmissions11 / solmate

Modern, opinionated, and gas optimized building blocks for smart contract development.
GNU Affero General Public License v3.0
3.94k stars 648 forks source link

ReentrancyGuard doesn't work as intended with Clones #219

Open PraneshASP opened 2 years ago

PraneshASP commented 2 years ago

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!

transmissions11 commented 2 years ago

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