-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Sample 4337 Module #131
Added Sample 4337 Module #131
Conversation
Pull Request Test Coverage Report for Build 6847999103
💛 - Coveralls |
address payable entrypoint, | ||
uint256 missingAccountFunds | ||
) external override onlyEnabledPlugin(account) { | ||
require(functionHandlers[hex"3a871cdd"][account] == msg.sender); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats 0x3a871cdd
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the selector of validateUserOp
. This is veeeeery hacky (I talk about it in my findings I documented in #125 (comment)).
This is needed because doing the prefund transfer from a plugin requires a lookup in the registry which is not allowed for two reasons:
- 4337 bundlers do not accept such user operations
- The Safe{Core} Protocol spec forbids it 😛
I left a note in the finding to clean this up
*/ | ||
function handle(address account, address sender, uint256 value, bytes calldata data) external override returns (bytes memory result) { | ||
require(sender == entrypoint, "unsupported entrypoint"); | ||
require(value == 0, "not payable"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value variable is unused; does it make sense to omit the check and remove the argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is part of the interface of the ISafeProtocolFunctionHandler
. I think we could change it to not have a value, but that would be strange to me:
- I think fallbackhandlers should be able to emulate non-
payable
functions (so revert onvalue != 0
payable
fallback handlers should be able to read the amount ofEther
that was sent with the transaction to the account.
I would also argue this is a bit out of the scope of this PR.
I noticed that there's an inconsistency between file names Also, we have a separate repo for demos - https://github.com/5afe/safe-core-protocol-demo. Would it make sense to place it there? |
scripts/user-operation.ts
Outdated
const handler = await ethers.getContractAt("ISafeProtocol4337Handler", await module.getAddress()); | ||
const entrypoint = await ethers.getContractAt("EntryPoint", ENTRYPOINT); | ||
|
||
const account = await ethers.deployContract("TestExecutor", [await manager.getAddress()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to use an actual safe account here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, but it made the signing more complicated 😅. You could argue that the PoC was about ensuring that some account implementation paired with the Safe{Core} Protocol reference implementation could work with ERC-4337, so I don’t think its strictly necessary.
@mmv08 - fixed the file naming inconsistencies. |
Created an issue to track porting this code to the https://github.com/5afe/safe-core-protocol-demo repository. I’m going to close this PR for now as:
|
Note to reviewers: Since this is intended as a PoC to evaluate feasibility and not necessarily merged here, do not look over the changes in detail, just the overall structure and findings. Additional notes and findings are documented in #125 (comment)
Fixes #125
This PR adds a sample ERC-4337 integration as a plugin/function handler as described in the spec (see 5afe/safe-core-protocol-specs#64).
SafeProtocol4337Module.sol
module implementation acting both as a plugin and function handler.EntryPoint
implementation# using the docker-compose.yaml file from 5afe/playground-4337 docker compose up -d npx hardhat deploy --network localhost npx hardhat run scripts/user_operation.ts --network localhost
There was one notable change needed in order to get the Protocol contracts working with this plugin: