Skip to content

Commit

Permalink
Add diagrams for 7702, minor text update
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed Nov 28, 2024
1 parent c7a1f98 commit 86771c2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
Binary file added assets/diagram-7702-approach-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/diagram-7702-approach-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/diagram-7702-approach-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 29 additions & 11 deletions pages/advanced/eip-7702/7702-safe.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Callout } from 'nextra/components'

# Safe and EIP-7702

EIP-7702 does not specify how to initialise the storage of the account but only gives a way to set the code of the account.
Expand All @@ -10,21 +12,10 @@ Existing Safe contracts cannot be used with EIP-7702, because of following reaso

## Possible approaches

### Modified safe singleton

In this approach, a derived version of Safe Singleton aka `SafeEIP7702` overrides the `setup` function and reverts when called.
Instead, a new function `setupEIP7702` in the contract has a `signature` parameter. The default owner will be set to the address of the EOA account that is delegating to this Singleton contract with a threshold of 1.

[SafeEIP7702](https://github.com/safe-global/safe-smart-account/blob/feature/eip-7702/contracts/experimental/SafeEIP7702.sol)

Because of no proxy contract in this approach, the storage slot 0 remains unused. Safe Transaction Service and other services that depend on the value at storage slot 0 will not work with this approach.


### Modified safe proxy

[SafeEIP7702Proxy](https://github.com/5afe/safe-eip7702/blob/main/safe-eip7702-contracts/contracts/SafeEIP7702Proxy.sol)


This approach uses a derived proxy contract from [Safe Proxy](https://github.com/5afe/safe-eip7702/blob/main/safe-eip7702-contracts/contracts/SafeEIP7702Proxy.sol) with following changes:
1. The constructor of the `SafeEIP7702Proxy` contract has an additional parameter `setupDataHash` which is the hash of the `setup` function call data. Thus, the address of the proxy contract also depends on the `setupDataHash` and not just the `singleton` contract address.
Proxy contract uses this hash to verify that the `setup` function parameter values are unchanged during initialised of storage.
Expand All @@ -36,9 +27,36 @@ Proxy contract uses this hash to verify that the `setup` function parameter valu
This approach has a gas overhead as a new proxy contract has to be deployed for each EOA account as the setupDataHash will be possibly unique for each user.
But, using this approach users can use the existing Safe Wallet UI with minor modifications and import the EOA account as a Safe account.

![diagram-7702-approach-1](../../../assets/diagram-7702-approach-1.png)

Follow the instructions here to use this approach to set code in EOA: https://github.com/5afe/safe-eip7702/tree/main/safe-eip7702-contracts#execute-scripts

### Modified safe singleton

In this approach, a derived version of Safe Singleton aka `SafeEIP7702` overrides the `setup` function and reverts when called.
Instead, a new function `setupEIP7702` in the contract has a `signature` parameter. The default owner will be set to the address of the EOA account that is delegating to this Singleton contract with a threshold of 1.

[SafeEIP7702](https://github.com/safe-global/safe-smart-account/blob/feature/eip-7702/contracts/experimental/SafeEIP7702.sol)

Because of no proxy contract in this approach, the storage slot 0 remains unused. Safe Transaction Service and other services that depend on the value at storage slot 0 will not work with this approach.

![diagram-7702-approach-2](../../../assets/diagram-7702-approach-2.png)

### SafeLite

[SafeLite](https://github.com/5afe/safe-eip7702/blob/main/safe-eip7702-contracts/contracts/experimental/SafeLite.sol) is a lite version of Safe and compatible with EIP-7702. The contract does not have a proxy and does not need any initialisation.
SafeLite supports ERC-4337 and hence can use features such as sponsored transactions, and even batch transactions. SafeLite also supports ERC-1271 for contract-based signatures.
SafeLite is not compatible with the existing Safe Wallet UI as it does not use the same storage layout as the existing Safe contracts.
It does not have the features of the existing Safe contracts such as Modules, Fallback Handler, Guards.

![diagram-7702-approach-3](../../../assets/diagram-7702-approach-3.png)

<Callout type='error' emoji='‼️'>
All the above approaches are experimental and the contracts are not yet audited. Use them at your own risk.
</Callout>

#### Other resources

- [Demo with SafeEIP7702Proxy](https://github.com/user-attachments/assets/ae77c03a-1c73-47b8-9769-f5e7c1fee095)
- [Code walk through](https://www.youtube.com/watch?v=dx4mk6tKHCo)
- [Slides](https://docs.google.com/presentation/d/12j90QkVx_A-iAZ14mnx6ztsafqqsth3NWZpxp3LV2cQ/edit#slide=id.p)
4 changes: 2 additions & 2 deletions pages/advanced/eip-7702/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Setting Code for the EOA
Once the EOA signs the hash, an authorization list is sent to the EVM node through a new transaction type, the set code
transaction, introduced in EIP-7702.

The EVM node then:
The execution client then performs the following checks:

- Verifies the signature.
- Checks the account's nonce.
- Confirms the chain ID.
- Confirms the chain ID (`0` or the current chain ID).

If all checks pass, the execution client sets the EOA's code in the format `(0xef0100 ++ address)`.

Expand Down

0 comments on commit 86771c2

Please sign in to comment.