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

Commit

Permalink
Break out Safe plugins to specific directories
Browse files Browse the repository at this point in the history
Update plugins README.
Fix sleep duration env var in rpc check.
  • Loading branch information
jacque006 committed Jul 18, 2024
1 parent 3a3c850 commit 9d0c4cc
Show file tree
Hide file tree
Showing 26 changed files with 55 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
run: ./script/start.sh &

- name: Wait for bundler at port 3000
run: RPC_URL='localhost:3000' SLEEP_DURATION=1 ./script/wait-for-rpc.sh
run: RPC_URL='localhost:3000' SLEEP_DURATION_SECONDS=1 ./script/wait-for-rpc.sh

- name: Run hardhat integration tests
run: yarn hardhat test
38 changes: 27 additions & 11 deletions packages/plugins/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
TODO link to other module bootstrapping repos, mention this is mainly safe
# Plugins

maybe ideas in here for cool new plugins to build?
Experimental plugins, modules, components for use with [ERC-4337](https://eips.ethereum.org/EIPS/eip-4337) (`v0.7.0`) compatible smart contract accounts. Most are currently built on top of Safe.
These plugins are in a pre-alpha state and are not ready for production use. They are intended for experimentation.

one pager in hackmd or somewher else
- AA libs
- module bootstrapping
This package is a hybrid Foundry & Hardhat project. Foundry is used for unit & integration testing, with Hardhat for end-to-end testing & examples of using a plugin in JavaScript/TypeScript runtime.

# Plugins
## When you should use this package

- If you are building a ERC-4337 plugin, module, or component and want end-to-end tooling & testing harnesses to make sure your it is compatible within the ERC-4337/Ethereum AA ecosystem. These can include but are not limited to:
- Validation
- Account Recovery
- Paymasters
- If you are building a module for an ERC-4437 Safe.
- If you are interested in experimenting with calldata compression. See also [the compression package](../compression/).
- If you have an interesting idea to integrate a novel cryptographic primitive or zero knowledge proof into the Ethereum AA ecosystem and want a place to start.

Please note, these plugins are in a pre-alpha state and are not ready for production use. In their current state, the plugins are meant for testing and experimentation.
## When you shouldn't use this package

# Getting Started
If you are developing a plugin/module for use with an ERC-4337 module spec, such as:
- ERC-7579, use https://docs.rhinestone.wtf/modulekit as a base instead.
- ERC-6900, use https://www.erc6900.io/build-a-plugin as a base instead.

## Getting Started

1. `cd packages/plugins`
2. Run `yarn submodules` to initialize git submodules
3. Run `yarn` to install hardhat dependencies
4. Run `forge install` to install foundry dependencies
5. Run `cp .env.example .env` to create an `.env` file with the values from `.env.example`

## Build & generate Typechain definitions
### Build & generate Typechain definitions

```bash
yarn build
```

## Forge tests
### Forge tests

```bash
forge test --no-match-path test/unit/safe/SafeZkEmailRecoveryPlugin.t.sol -vvv
```

## Hardhat tests
### Hardhat tests

To run the hardhat tests, you'll need to run a geth node & bundler as some of them are integration tests:

Expand All @@ -47,3 +58,8 @@ To run the hardhat tests, you'll need to run a geth node & bundler as some of th
```bash
yarn hardhat test
```

### Things to keep in mind

- When writing Hardhat tests in the [e2e directory](./test/e2e/), DO NOT USE the `hre` ([Hardhat Runtime Environment](https://hardhat.org/hardhat-runner/docs/advanced/hardhat-runtime-environment)) when deploying contracts & interacting on chain. We do not use the normal internal Hardhat runtime as we need to run against a local geth instance & bundler to fully simulate the ERC-4337 flow end-to-end.
- Be mindful of the [opcode & storage limitations imposed by ERC-4337](https://eips.ethereum.org/EIPS/eip-7562).
2 changes: 1 addition & 1 deletion packages/plugins/script/wait-for-rpc.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

RPC_URL="${RPC_URL:=localhost:8545}"
SLEEP_DURATION_SECONDS="${SLEEP_DURATION:=0.1}"
SLEEP_DURATION_SECONDS="${SLEEP_DURATION_SECONDS:=0.1}"

max_tries=100
counter=0
Expand Down
1 change: 0 additions & 1 deletion packages/plugins/src/safe/README.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {SafeProxy} from "safe-contracts/contracts/proxies/SafeProxy.sol";

import {EntryPoint} from "account-abstraction/core/EntryPoint.sol";

import {SafeAnonAadhaarPlugin} from "./SafeAnonAadhaarPlugin.sol";
import {SafeAnonAadhaarPlugin} from "../validators/SafeAnonAadhaarPlugin.sol";

/*//////////////////////////////////////////////////////////////////////////
THIS CONTRACT IS STILL IN ACTIVE DEVELOPMENT. NOT FOR PRODUCTION USE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {SafeProxy} from "safe-contracts/contracts/proxies/SafeProxy.sol";

import {EntryPoint} from "account-abstraction/core/EntryPoint.sol";

import {SafeCompressionPlugin} from "./SafeCompressionPlugin.sol";
import {IDecompressor} from "../compression/decompressors/IDecompressor.sol";
import {SafeCompressionPlugin} from "../validators/SafeCompressionPlugin.sol";
import {IDecompressor} from "../../compression/decompressors/IDecompressor.sol";

/*//////////////////////////////////////////////////////////////////////////
THIS CONTRACT IS STILL IN ACTIVE DEVELOPMENT. NOT FOR PRODUCTION USE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {SafeProxy} from "safe-contracts/contracts/proxies/SafeProxy.sol";

import {EntryPoint} from "account-abstraction/core/EntryPoint.sol";

import {SafeECDSAPlugin} from "./SafeECDSAPlugin.sol";
import {SafeECDSAPlugin} from "../validators/SafeECDSAPlugin.sol";

/*//////////////////////////////////////////////////////////////////////////
THIS CONTRACT IS STILL IN ACTIVE DEVELOPMENT. NOT FOR PRODUCTION USE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {ISafe} from "./utils/Safe4337Base.sol";
import {ISafe} from "../utils/Safe4337Base.sol";
import {EmailAccountRecoveryRouter} from "./EmailAccountRecoveryRouter.sol";
import {EmailAccountRecovery} from "ether-email-auth/packages/contracts/src/EmailAccountRecovery.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity >=0.7.0 <0.9.0;
pragma abicoder v2;

import {Safe4337Base, SIG_VALIDATION_FAILED} from "./utils/Safe4337Base.sol";
import {Safe4337Base, SIG_VALIDATION_FAILED} from "../utils/Safe4337Base.sol";
import {IEntryPoint, PackedUserOperation} from "account-abstraction/interfaces/IEntryPoint.sol";
import {IAnonAadhaar} from "./utils/anonAadhaar/interfaces/IAnonAadhaar.sol";
import {IAnonAadhaar} from "../utils/anonAadhaar/interfaces/IAnonAadhaar.sol";

interface ISafe {
function enableModule(address module) external;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {IEntryPoint, PackedUserOperation} from "account-abstraction/interfaces/I
import {BLS} from "account-abstraction/samples/bls/lib/hubble-contracts/contracts/libs/BLS.sol";
import {IBLSAccount} from "account-abstraction/samples/bls/IBLSAccount.sol";

import {Safe4337Base, ISafe} from "./utils/Safe4337Base.sol";
import {Safe4337Base, ISafe} from "../utils/Safe4337Base.sol";

/*//////////////////////////////////////////////////////////////////////////
THIS CONTRACT IS STILL IN ACTIVE DEVELOPMENT. NOT FOR PRODUCTION USE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {BLS} from "account-abstraction/samples/bls/lib/hubble-contracts/contract
import {IBLSAccount} from "account-abstraction/samples/bls/IBLSAccount.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

import {Safe4337Base, ISafe, SIG_VALIDATION_FAILED} from "./utils/Safe4337Base.sol";
import {WaxLib as W} from "../compression/WaxLib.sol";
import {IDecompressor} from "../compression/decompressors/IDecompressor.sol";
import {Safe4337Base, ISafe, SIG_VALIDATION_FAILED} from "../utils/Safe4337Base.sol";
import {WaxLib as W} from "../../compression/WaxLib.sol";
import {IDecompressor} from "../../compression/decompressors/IDecompressor.sol";

/*//////////////////////////////////////////////////////////////////////////
THIS CONTRACT IS STILL IN ACTIVE DEVELOPMENT. NOT FOR PRODUCTION USE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.7.0 <0.9.0;
pragma abicoder v2;

import {Safe4337Base, SIG_VALIDATION_FAILED} from "./utils/Safe4337Base.sol";
import {Safe4337Base, SIG_VALIDATION_FAILED} from "../utils/Safe4337Base.sol";
import {IEntryPoint, PackedUserOperation} from "account-abstraction/interfaces/IEntryPoint.sol";
import {PackedUserOperation} from "account-abstraction/interfaces/IEntryPoint.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pragma solidity >=0.8.0 <0.9.0;
import {HandlerContext} from "safe-contracts/contracts/handler/HandlerContext.sol";
import {BaseAccount} from "account-abstraction/core/BaseAccount.sol";
import {IEntryPoint, PackedUserOperation} from "account-abstraction/interfaces/IEntryPoint.sol";
import {WebAuthn} from "../primitives/WebAuthn.sol";
import {WebAuthn} from "../../primitives/WebAuthn.sol";

import {Safe4337Base, SIG_VALIDATION_FAILED} from "./utils/Safe4337Base.sol";
import {Safe4337Base, SIG_VALIDATION_FAILED} from "../utils/Safe4337Base.sol";

/*//////////////////////////////////////////////////////////////////////////
THIS CONTRACT IS STILL IN ACTIVE DEVELOPMENT. NOT FOR PRODUCTION USE
Expand Down
135 changes: 0 additions & 135 deletions packages/plugins/test/e2e/SafeZKPPasswordPlugin.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity ^0.8.12;
import "forge-std/Test.sol";
import "forge-std/console2.sol";
import {TestHelper} from "../../unit/utils/TestHelper.sol";
import {SafeZkEmailRecoveryPlugin, RecoveryRequest, GuardianRequest} from "../../../src/safe/SafeZkEmailRecoveryPlugin.sol";
import {IEmailAccountRecovery} from "../../../src/safe/EmailAccountRecoveryRouter.sol";
import {SafeZkEmailRecoveryPlugin, RecoveryRequest, GuardianRequest} from "../../../src/safe/recovery/SafeZkEmailRecoveryPlugin.sol";
import {IEmailAccountRecovery} from "../../../src/safe/recovery/EmailAccountRecoveryRouter.sol";
import {MockGroth16Verifier} from "../../../src/safe/utils/MockGroth16Verifier.sol";
import {Safe} from "safe-contracts/contracts/Safe.sol";
import {SafeProxy} from "safe-contracts/contracts/proxies/SafeProxy.sol";
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/test/unit/safe/SafeBlsPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "forge-std/Test.sol";
import "forge-std/console2.sol";
import {TestHelper} from "../utils/TestHelper.sol";
import {SafeBlsPluginHarness} from "../utils/SafeBlsPluginHarness.sol";
import {SafeBlsPlugin} from "../../../src/safe/SafeBlsPlugin.sol";
import {SafeBlsPlugin} from "../../../src/safe/validators/SafeBlsPlugin.sol";
import {Safe4337Base} from "../../../src/safe/utils/Safe4337Base.sol";
import {BLSSignatureAggregator} from "account-abstraction/samples/bls/BLSSignatureAggregator.sol";

Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/test/unit/safe/SafeECDSAPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "forge-std/Test.sol";
import "forge-std/console2.sol";
import {TestHelper} from "../utils/TestHelper.sol";
import {SafeECDSAPluginHarness} from "../utils/SafeECDSAPluginHarness.sol";
import {SafeECDSAPlugin} from "../../../src/safe/SafeECDSAPlugin.sol";
import {SafeECDSAPlugin} from "../../../src/safe/validators/SafeECDSAPlugin.sol";
import {Safe4337Base} from "../../../src/safe/utils/Safe4337Base.sol";

/* solhint-disable func-name-mixedcase */
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/test/unit/safe/SafeECDSARecoveryPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity ^0.8.12;
import "forge-std/Test.sol";
import "forge-std/console2.sol";
import {TestHelper} from "../utils/TestHelper.sol";
import {SafeECDSARecoveryPlugin, ECDSARecoveryStorage} from "../../../src/safe/SafeECDSARecoveryPlugin.sol";
import {SafeECDSAPlugin} from "../../../src/safe/SafeECDSAPlugin.sol";
import {SafeECDSARecoveryPlugin, ECDSARecoveryStorage} from "../../../src/safe/recovery/SafeECDSARecoveryPlugin.sol";
import {SafeECDSAPlugin} from "../../../src/safe/validators/SafeECDSAPlugin.sol";
import {Safe} from "safe-contracts/contracts/Safe.sol";
import {SafeProxy} from "safe-contracts/contracts/proxies/SafeProxy.sol";
import {ECDSA} from "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol";
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/test/unit/safe/SafeWebAuthnPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "forge-std/Test.sol";
import "forge-std/console2.sol";
import {TestHelper} from "../utils/TestHelper.sol";
import {SafeWebAuthnPluginHarness} from "../utils/SafeWebAuthnPluginHarness.sol";
import {SafeWebAuthnPlugin} from "../../../src/safe/SafeWebAuthnPlugin.sol";
import {SafeWebAuthnPlugin} from "../../../src/safe/validators/SafeWebAuthnPlugin.sol";
import {Safe4337Base} from "../../../src/safe/utils/Safe4337Base.sol";
import {PackedUserOperation} from "account-abstraction/interfaces/IEntryPoint.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.12;
import "forge-std/Test.sol";
import "forge-std/console2.sol";
import {TestHelper} from "../utils/TestHelper.sol";
import {SafeZkEmailRecoveryPlugin, RecoveryRequest} from "../../../src/safe/SafeZkEmailRecoveryPlugin.sol";
import {SafeZkEmailRecoveryPlugin, RecoveryRequest} from "../../../src/safe/recovery/SafeZkEmailRecoveryPlugin.sol";
import {SafeZkEmailRecoveryPluginHarness} from "../utils/SafeZkEmailRecoveryPluginHarness.sol";
import {Safe} from "safe-contracts/contracts/Safe.sol";
import {SafeProxy} from "safe-contracts/contracts/proxies/SafeProxy.sol";
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/test/unit/utils/SafeBlsPluginHarness.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;

import {SafeBlsPlugin} from "../../../src/safe/SafeBlsPlugin.sol";
import {SafeBlsPlugin} from "../../../src/safe/validators/SafeBlsPlugin.sol";

/** Helper contract to expose internal functions for testing */
contract SafeBlsPluginHarness is SafeBlsPlugin {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;

import {SafeECDSAPlugin} from "../../../src/safe/SafeECDSAPlugin.sol";
import {SafeECDSAPlugin} from "../../../src/safe/validators/SafeECDSAPlugin.sol";

/** Helper contract to expose internal functions for testing */
contract SafeECDSAPluginHarness is SafeECDSAPlugin {
Expand Down
Loading

0 comments on commit 9d0c4cc

Please sign in to comment.