safe-global / safe-smart-account

Safe allows secure management of blockchain assets.
https://safe.global
GNU Lesser General Public License v3.0
1.88k stars 927 forks source link

ERC-4337 Factory Support for `setupModules()` #568

Closed dancoombs closed 1 year ago

dancoombs commented 1 year ago

Context / issue

setupModules makes a call to gasLeft() that is invalid in the ERC-4337 protocol during validation. To make use of the ERC-4337 factory pattern, the factory must adhere to the validation rules. Thus, the factory cannot call setupModules with a to address to setup its modules.

https://github.com/safe-global/safe-contracts/blob/ad9b3190d4889abeeaa02c5c05138d9c327f2460/contracts/base/ModuleManager.sol#L38

https://eips.ethereum.org/EIPS/eip-4337#specification-1

An example factory that uses this pattern and is currently invalid:

https://github.com/eth-infinitism/account-abstraction/blob/abff2aca61a8f0934e533d0d352978055fddbd96/contracts/samples/gnosis/GnosisAccountFactory.sol#L42

Proposed solution

It seems like the gasLeft() could either be replaced with type(uint256).max (like is done in the same file) or, gasLeft() can be pushed down such that the GAS opcode occurs before CALL or DELEGATECALL which is valid in ERC-4337.

Could push the call down here: https://github.com/safe-global/safe-contracts/blob/ad9b3190d4889abeeaa02c5c05138d9c327f2460/contracts/base/Executor.sol#L31

rmeissner commented 1 year ago

Related to https://github.com/safe-global/safe-contracts/issues/459

KK68HK67 commented 2 months ago

Jag har ingen aning av vad sommar hänt om jag har gjort fel så ber jag så mycket om ursäkt mvh Kai det här är till den artikeln nedan för.