Skip to content

Commit

Permalink
Merge pull request #64 from etherspot/session-keys-module
Browse files Browse the repository at this point in the history
`ERC20SessionKeyValidator` Module
  • Loading branch information
cryptonoyaiba authored May 20, 2024
2 parents 57b88f5 + 8761978 commit dfef1e4
Show file tree
Hide file tree
Showing 365 changed files with 86,940 additions and 254 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ node_modules

# Hardhat
.hardhat
typings
coverage.json

# IDEs
Expand Down
19 changes: 19 additions & 0 deletions DEPLOYMENTS_MODULAR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Contract Deployments

## Mainnets

| Contract Name | Network | Contract Address | Transaction Hash |
| --- | --- | --- | --- |
| `ModularEtherspotWallet` | | []() | []() |
| `ModularEtherspotWalletFactory` | | []() | []() |
| `Bootstrap` | | []() | []() |
| `MultipleOwnerECDSAValidator` | | []() | []() |

## Testnets

| Contract Name | Network | Contract Address | Transaction Hash |
| --- | --- | --- | --- |
| `ModularEtherspotWallet` | `sepolia` | [0x917398df969752a7d94725740918f38e4b8eecec](https://sepolia.etherscan.io/address/0x917398df969752a7d94725740918f38e4b8eecec) | [0x983a9141f38e7e1a1a70cfe9354eb5e6d61dd39e228990b80146c175a1928d6e](https://sepolia.etherscan.io/tx/0x983a9141f38e7e1a1a70cfe9354eb5e6d61dd39e228990b80146c175a1928d6e) |
| `ModularEtherspotWalletFactory` | `sepolia` | [0x77e4288a4b15893f520f15c262a07df9866904e4](https://sepolia.etherscan.io/address/0x77e4288a4b15893f520f15c262a07df9866904e4) | [0x0f4b4f53a2654e34e7b0a3aad01f9a90d711df2af1d3d9d8a2e70a63c36bc254](https://sepolia.etherscan.io/tx/0x0f4b4f53a2654e34e7b0a3aad01f9a90d711df2af1d3d9d8a2e70a63c36bc254) |
| `Bootstrap` | `sepolia` | [0x4f695ad7694863c8280fcebf2cb220e361ce4ea0](https://sepolia.etherscan.io/address/0x4f695ad7694863c8280fcebf2cb220e361ce4ea0) | [0xc69aed3fd25ef9bd66c42903dd855cd363d703f03049be9fb3a2fdf0c75ecfb1](https://sepolia.etherscan.io/tx/0xc69aed3fd25ef9bd66c42903dd855cd363d703f03049be9fb3a2fdf0c75ecfb1) |
| `MultipleOwnerECDSAValidator` | `sepolia` | [0x1e714c551fe6234b6ee406899ec3be9234ad2124](https://sepolia.etherscan.io/address/0x1e714c551fe6234b6ee406899ec3be9234ad2124) | [0x1b56d1e32cb12d16b3878eed660ae23eb454cd3e84ae9e88d8ed40d0d0c5e6f8](https://sepolia.etherscan.io/tx/0x1b56d1e32cb12d16b3878eed660ae23eb454cd3e84ae9e88d8ed40d0d0c5e6f8) |
File renamed without changes.
13 changes: 13 additions & 0 deletions MODULAR_ETHERSPOT_WALLET_GAS_CONSUMPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
| onInstall | 22812 | 22812 | 22812 | 22812 | 48 |
| validateUserOp | 6568 | 7176 | 7244 | 7515 | 6 |

| ERC20SessionKeyValidator.sol | | | | | |
|---------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 1297006 | 6014 | | | | |
| Function Name | min | avg | median | max | # calls |
| checkSessionKeyPaused | 744 | 744 | 744 | 744 | 2 |
| disableSessionKey | 30926 | 30926 | 30926 | 30926 | 2 |
| enableSessionKey | 67518 | 132245 | 138694 | 138754 | 11 |
| getAssociatedSessionKeys | 1309 | 1309 | 1309 | 1309 | 1 |
| getSessionKeyData | 1609 | 1609 | 1609 | 1609 | 7 |
| rotateSessionKey | 124571 | 124571 | 124571 | 124571 | 1 |
| toggleSessionKeyPause | 27002 | 27002 | 27002 | 27002 | 1 |

| ModularEtherspotWallet.sol | | | | | |
|----------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/5fd328716234c289581a8ec2c341af6c.json"
"buildInfo": "../../../../build-info/11e946ee2480cfa4c23fb74059dc998f.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/5fd328716234c289581a8ec2c341af6c.json"
"buildInfo": "../../../../build-info/11e946ee2480cfa4c23fb74059dc998f.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/5fd328716234c289581a8ec2c341af6c.json"
"buildInfo": "../../../../../build-info/11e946ee2480cfa4c23fb74059dc998f.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/5fd328716234c289581a8ec2c341af6c.json"
"buildInfo": "../../../../../build-info/11e946ee2480cfa4c23fb74059dc998f.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/5fd328716234c289581a8ec2c341af6c.json"
"buildInfo": "../../../../../build-info/11e946ee2480cfa4c23fb74059dc998f.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/5fd328716234c289581a8ec2c341af6c.json"
"buildInfo": "../../../../build-info/11e946ee2480cfa4c23fb74059dc998f.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/5fd328716234c289581a8ec2c341af6c.json"
"buildInfo": "../../../../build-info/11e946ee2480cfa4c23fb74059dc998f.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/5fd328716234c289581a8ec2c341af6c.json"
"buildInfo": "../../../../build-info/11e946ee2480cfa4c23fb74059dc998f.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/5fd328716234c289581a8ec2c341af6c.json"
"buildInfo": "../../../../build-info/11e946ee2480cfa4c23fb74059dc998f.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/5fd328716234c289581a8ec2c341af6c.json"
"buildInfo": "../../../../../build-info/11e946ee2480cfa4c23fb74059dc998f.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/5fd328716234c289581a8ec2c341af6c.json"
"buildInfo": "../../../../../build-info/11e946ee2480cfa4c23fb74059dc998f.json"
}
59 changes: 59 additions & 0 deletions docs/ERC20_SESSION_KEY_VALIDATOR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## ERC20SessionKeyValidator

The `ERC20SessionKeyValidator` is a Solidity smart contract that implements the `IValidator` interface from the `IERC7579Module` contract. It is designed to validate user operations (UserOps) for ERC20 token transfers and approvals based on pre-configured session keys.

### Features

- Allows wallet owners to enable and disable session keys for specific ERC20 tokens.
- Supports setting spending limits, validity periods, and pausability for each session key.
- Validates UserOps against the configured session key parameters before execution.
- Provides functions to manage session keys, including rotation and pause/unpause.
- Implements EIP-712 for signature verification.

### Events

- `ERC20SKV_SessionKeyEnabled(address sessionKey, address wallet)`: Emitted when a new session key is enabled for a wallet.
- `ERC20SKV_SessionKeyDisabled(address sessionKey, address wallet)`: Emitted when a session key is disabled for a wallet.

### Errors

- `ERC20SKV_InvalidSessionKey()`: Thrown when the provided session key is invalid or expired.
- `ERC20SKV_SessionPaused(address sessionKey)`: Thrown when the provided session key is currently paused.
- `ERC20SKV_UnsuportedToken()`: Thrown when the target contract is not the configured token for the session key.
- `ERC20SKV_UnsupportedSelector(bytes4 selectorUsed)`: Thrown when the function selector is not supported by the session key.
- `ERC20SKV_UnsupportedInterface()`: Thrown when the target contract does not support the required interface for the session key.
- `ERC20SKV_SessionKeySpendLimitExceeded()`: Thrown when the requested transfer amount exceeds the spending limit of the session key.
- `ERC20SKV_InsufficientApprovalAmount()`: Thrown when the approval amount is insufficient for the requested transfer.
- `NotImplemented()`: Thrown for unimplemented functions.

### Structs

- `SessionData`: Stores the configuration data for a session key, including the token address, interface ID, function selector, spending limit, validity period, and pause status.

### Functions

- `enableSessionKey(bytes calldata _sessionData)`: Enables a new session key for the caller's wallet with the provided configuration data.
- `disableSessionKey(address _session)`: Disables the specified session key for the caller's wallet.
- `rotateSessionKey(address _oldSessionKey, bytes calldata _newSessionData)`: Disables the old session key and enables a new one with the provided configuration data.
- `toggleSessionKeyPause(address _sessionKey)`: Toggles the pause status of the specified session key for the caller's wallet.
- `checkSessionKeyPaused(address _sessionKey)`: Checks if the specified session key is currently paused for the caller's wallet.
- `validateSessionKeyParams(address _sessionKey, PackedUserOperation calldata userOp)`: Validates the provided UserOp against the configuration of the specified session key.
- `getAssociatedSessionKeys()`: Returns an array of session keys associated with the caller's wallet.
- `getSessionKeyData(address _sessionKey)`: Returns the configuration data for the specified session key and the caller's wallet.
- `validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash)`: Validates the provided UserOp using the EIP-712 signature and session key parameters.
- `isModuleType(uint256 moduleTypeId)`: Checks if the contract is a validator module type.
- `onInstall(bytes calldata data)`: Required by the `IValidator` interface but not implemented.
- `onUninstall(bytes calldata data)`: Required by the `IValidator` interface but not implemented.
- `isValidSignatureWithSender(address sender, bytes32 hash, bytes calldata data)`: Required by the `IValidator` interface but not implemented.
- `isInitialized(address smartAccount)`: Required by the `IValidator` interface but not implemented.

### Internal Functions

- `_digest(bytes calldata _data)`: Internal function that extracts the function selector, target contract, recipient, sender, and amount from the provided calldata.
- `_domainSeparator()`: Internal function that calculates the EIP-712 domain separator for signature verification.
- `_domainNameAndVersion()`: Internal function that returns the contract name and version for the EIP-712 domain separator.

### Usage

To use the `ERC20SessionKeyValidator` contract, wallet owners can enable session keys with specific configurations for ERC20 token transfers and approvals. The contract will validate UserOps against the configured session key parameters before execution, ensuring that the requested operation is within the allowed limits and validity period.

File renamed without changes.
15 changes: 12 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ out = "out"
libs = ["node_modules", "lib"]
test = "test/foundry"
cache_path = "forge_cache"
gas_reports = [
"ModularEtherspotWallet",
"ModularEtherspotWalletFactory",
"MultipleOwnerECDSAValidator",
"ERC20SessionKeyValidator",
"ModuleIsolationHook",
]


[rpc_endpoints]
goerli = "${ALCHEMY_GOERLI_RPC_URL}"
goerli = "${GOERLI_RPC_URL}"
sepolia = "${SEPOLIA_RPC_URL}"

[etherscan]
goerli = { key = "${ETHERSCAN_API_KEY}" }

goerli = { key = "${ETHERSCAN_API_KEY}" }
sepolia = { key = "${ETHERSCAN_API_KEY}" }
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import '@nomicfoundation/hardhat-toolbox';
import '@nomicfoundation/hardhat-foundry';
import '@openzeppelin/hardhat-upgrades';
import 'hardhat-deploy';
import 'hardhat-exposed';
// import 'hardhat-exposed';
import { compilers, networks, etherscan } from './config';

const config: HardhatUserConfig = {
Expand Down
Loading

0 comments on commit dfef1e4

Please sign in to comment.