-
Notifications
You must be signed in to change notification settings - Fork 0
EVM: Support 7702 delegator #44
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
Draft
facuspagnuolo
wants to merge
3
commits into
main
Choose a base branch
from
evm/support_7702_delegator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [submodule "packages/evm/lib/delegation-framework"] | ||
| path = packages/evm/lib/delegation-framework | ||
| url = https://github.com/MetaMask/delegation-framework.git | ||
| [submodule "packages/evm/lib/openzeppelin-contracts"] | ||
| path = packages/evm/lib/openzeppelin-contracts | ||
| url = https://github.com/OpenZeppelin/openzeppelin-contracts.git |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,8 @@ | |
| }, | ||
| "workspaces": { | ||
| "packages": [ | ||
| "packages/**" | ||
| "packages/evm", | ||
| "packages/svm" | ||
| ] | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/evm/contracts/test/smart-accounts/EIP7702StatelessDeleGatorMock.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.8.20; | ||
|
|
||
| import { DelegationManager } from 'delegation-framework/DelegationManager.sol'; | ||
| import { IEntryPoint, EIP7702StatelessDeleGator } from 'delegation-framework/EIP7702/EIP7702StatelessDeleGator.sol'; | ||
|
|
||
| contract EIP7702StatelessDeleGatorMock is EIP7702StatelessDeleGator { | ||
| constructor(address owner) EIP7702StatelessDeleGator(new DelegationManager(owner), IEntryPoint(address(0))) { | ||
| // solhint-disable-previous-line no-empty-blocks | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,17 @@ dotenv.config() | |
| const config: HardhatUserConfig = { | ||
| plugins: [hardhatVerify, hardhatToolboxMochaEthersPlugin], | ||
| solidity: { | ||
| profiles: { | ||
| default: { | ||
| compilers: [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you delete this? When trying to deploy without the profiles I get |
||
| { | ||
| version: '0.8.23', | ||
| settings: { | ||
| optimizer: { | ||
| enabled: true, | ||
| runs: 1000, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| version: '0.8.28', | ||
| settings: { | ||
| optimizer: { | ||
|
|
@@ -18,7 +27,7 @@ const config: HardhatUserConfig = { | |
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| networks: { | ||
| ethereum: { | ||
|
|
||
Submodule delegation-framework
added at
bfbdf9
Submodule openzeppelin-contracts
added at
e4f702
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| delegation-framework/=lib/delegation-framework/src/ | ||
| @openzeppelin/=lib/openzeppelin-contracts/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/types' | ||
|
|
||
| const { ethers } = await network.connect() | ||
|
|
||
| import { network } from 'hardhat' | ||
|
|
||
| const ROOT_AUTHORITY = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' | ||
|
|
||
| const DOMAIN = { | ||
| name: 'DelegationManager', | ||
| version: '1', | ||
| chainId: 0, | ||
| verifyingContract: '', | ||
| } | ||
|
|
||
| const DELEGATION_712_TYPES = { | ||
| Caveat: [ | ||
| { name: 'enforcer', type: 'address' }, | ||
| { name: 'terms', type: 'bytes' }, | ||
| ], | ||
| Delegation: [ | ||
| { name: 'delegate', type: 'address' }, | ||
| { name: 'delegator', type: 'address' }, | ||
| { name: 'authority', type: 'bytes32' }, | ||
| { name: 'caveats', type: 'Caveat[]' }, | ||
| { name: 'salt', type: 'uint256' }, | ||
| ], | ||
| } as const | ||
|
|
||
| const DELEGATION_ABI_TYPE = | ||
| 'tuple(address delegate,address delegator,bytes32 authority,tuple(address enforcer,bytes terms,bytes args)[] caveats,uint256 salt,bytes signature)' | ||
|
|
||
| export async function signDelegation( | ||
| user: HardhatEthersSigner, | ||
| delegate: string, | ||
| delegationManager: string | ||
| ): Promise<string> { | ||
| const chainId = (await ethers.provider.getNetwork()).chainId | ||
| const delegation = { | ||
| delegate, | ||
| delegator: user.address, | ||
| authority: ROOT_AUTHORITY, | ||
| caveats: [], | ||
| salt: 1n, | ||
| signature: '0x', | ||
| } | ||
|
|
||
| delegation.signature = await user.signTypedData( | ||
| { ...DOMAIN, chainId, verifyingContract: delegationManager }, | ||
| DELEGATION_712_TYPES, | ||
| { | ||
| delegate: delegation.delegate, | ||
| delegator: delegation.delegator, | ||
| authority: delegation.authority, | ||
| caveats: [], | ||
| salt: delegation.salt, | ||
| } | ||
| ) | ||
|
|
||
| const abi = ethers.AbiCoder.defaultAbiCoder() | ||
| return abi.encode([`${DELEGATION_ABI_TYPE}[]`], [[delegation]]) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You need to add this in the
isSmartAccountalso