Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Demonstrate SafeECDSAPlugin in in-page wallet #97

Merged
merged 10 commits into from
Sep 20, 2023

Conversation

voltrevo
Copy link
Contributor

@voltrevo voltrevo commented Sep 19, 2023

Resolves #74

  • Uses deterministic addresses instead of relying on consistent config
  • Adds SafeECDSAFactory for creating a safe with the ecdsa plugin
  • Replaces initCode with just using SafeECDSAFactory (since you need to create 2 contracts anyway and 4337 won't let you do that with initCode so you need a separate creation step anyway)
  • Adds sendEth hardhat task and includes instructions in the readme to make setup easier and more clear
  • Updates to solidity 0.8.19 to enable create2 without assembly (and is more consistent with forge which is 0.8.20 on my machine, (I had other troubles with newer versions so I left it at 0.8.19))
  • Refactors the account logic out of EthereumApi so this happens via a common interface (IAccount)
  • Adds a new implementation of IAccount to support SafeECDSAAccount (SafeECDSAAccountWrapper)
  • Adds popup when creating the user's account allowing them to choose which account type they'd like to use

Screen Shot 2023-09-19 at 6 01 27 pm

@voltrevo voltrevo marked this pull request as ready for review September 19, 2023 08:02
@@ -16,7 +16,7 @@ function getRemappings() {

const config: HardhatUserConfig = {
solidity: {
version: "0.8.12",
version: "0.8.19",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably fine, but bumping solidity versions should be a considered step. If we're using a library that was audited for a particular version of compiler, we should keep that version of compiler in the list, and add any later additional versions (like we did in blswallet for blslibs).
(Related: #94)

short: 'Deploy account',
desc: [
'The current 4337 account type requires a separate deployment. Please',
'enter a private key or seed phraise with funds to do this.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*phrase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: #100

"account-abstraction": "github:eth-infinitism/account-abstraction#0.6.0",
"hardhat": "^2.17.3",
"openzeppelin-contracts": "github:openzeppelin/openzeppelin-contracts#v4.9.3",
"safe-contracts": "github:safe-global/safe-contracts#v1.4.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a curiosity, is there a preference to import from github vs a team's node release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there seems to be a small benefit - it allows you to use the same import paths as you do by default when using foundry. This makes compatibility easier because solidity doesn't have package management (as far as I know) so when your dependency has a dependency you need to install that yourself.

import {EntryPoint} from "@account-abstraction/contracts/core/EntryPoint.sol";
import {SimpleAccountFactory} from "@account-abstraction/contracts/samples/SimpleAccountFactory.sol";
import {EntryPoint} from "account-abstraction/contracts/core/EntryPoint.sol";
import {SimpleAccountFactory} from "account-abstraction/contracts/samples/SimpleAccountFactory.sol";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ not required to indicate from a node module?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. The @ is just a standard prefix for npm namespaces, eg @account-abstraction/contracts, but many npm packages don't use a namespace, eg ethers. When using hardhat, you're allowed to use any path beginning from node_modules.

): Promise<string> {
const ownerWallet = new ethers.Wallet(this.privateKey);

return await ownerWallet.signMessage(ethers.getBytes(userOpHash));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should verify _userOp corresponds to signed userOpHash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I wrote it this way because it's an internal tool and userOpHash is already available at the call site, so it's easier to just provide it rather than recalculating it.

Having said that, the call site looks like this:

      let userOpHash = await contracts.entryPoint.getUserOpHash(userOp);

      userOp.signature = await account.sign(userOp, userOpHash);

This means that the RPC node could get us to sign anything by lying about the userOpHash. We generally do put a lot of trust in the RPC node, but calculating the userOpHash locally is probably a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: #100

@jzaki jzaki mentioned this pull request Sep 19, 2023
Copy link
Contributor

@blakecduncan blakecduncan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Will merge and if there are any follow-ups I figure they can be done separately

@blakecduncan blakecduncan merged commit 78fed87 into main Sep 20, 2023
2 checks passed
@blakecduncan blakecduncan deleted the wax-74-use-safe-ecdsa-plugin branch September 20, 2023 19:08
@voltrevo
Copy link
Contributor Author

@blakecduncan A bit about squashing vs merging

Squashing vs merging

@voltrevo voltrevo mentioned this pull request Sep 21, 2023
voltrevo added a commit that referenced this pull request Oct 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Demonstrate SafeECDSAPlugin in in-page wallet
3 participants