Sitelet https://github.com/robertodf99/account/commit/87a191d489811ef1e9254af366308a0f4c20cc84
Skip to content

Commit 87a191d

Browse files
authored
Simplify, new EIP7702 tailored proxy, redeploy (ithacaxyz#20)
1 parent 4bfc71e commit 87a191d

5 files changed

Lines changed: 20 additions & 28 deletions

File tree

‎deployments.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ https://odyssey-explorer.ithaca.xyz/address/0x307AF7d28AfEE82092aA95D35644898311
66

77
Delegation (proxy):
88

9-
https://odyssey-explorer.ithaca.xyz/address/0x7DFc6Ae9c532EC324Ecd5ce027c425767fcDa757
9+
https://odyssey-explorer.ithaca.xyz/address/0xF9a8529Bb95ac7707129700f06343338E4767A27

‎script/DeployDelegation.s.sol‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ pragma solidity ^0.8.4;
33

44
import {Script} from "forge-std/Script.sol";
55
import "../src/Delegation.sol";
6+
import {EIP7702Proxy} from "solady/accounts/EIP7702Proxy.sol";
67
import {ERC1967Factory} from "solady/utils/ERC1967Factory.sol";
78
import {ERC1967FactoryConstants} from "solady/utils/ERC1967FactoryConstants.sol";
89

910
contract DeployDelegationScript is Script {
1011
function run() external {
1112
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
1213
address deployer = vm.createWallet(deployerPrivateKey).addr;
13-
ERC1967Factory erc1967Factory = ERC1967Factory(ERC1967FactoryConstants.ADDRESS);
14-
address implementation = 0x2F1114bF790f7115822F1aAEF740A74Ffe19A0aC;
15-
bytes32 salt = bytes32(uint256(1));
14+
address implementation = 0x4Ee65f4CEd87Ff98fd40627Ac19C159E99C9D295;
1615
vm.startBroadcast(deployerPrivateKey);
17-
erc1967Factory.deployDeterministic(implementation, deployer, salt);
16+
new EIP7702Proxy{salt: bytes32(0)}(implementation, deployer);
1817
vm.stopBroadcast();
1918
}
2019
}

‎script/UpgradeDelegation.s.sol‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ pragma solidity ^0.8.4;
33

44
import {Script} from "forge-std/Script.sol";
55
import "../src/Delegation.sol";
6-
import {ERC1967Factory} from "solady/utils/ERC1967Factory.sol";
7-
import {ERC1967FactoryConstants} from "solady/utils/ERC1967FactoryConstants.sol";
6+
7+
interface IEIP7702ProxyWithAdminABI {
8+
function implementation() external view returns (address);
9+
function admin() external view returns (address);
10+
function changeAdmin(address) external returns (bool);
11+
function upgrade(address) external returns (bool);
12+
function bad() external;
13+
}
814

915
contract UpgradeDelegationScript is Script {
1016
function run() external {
1117
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
12-
address deployer = vm.createWallet(deployerPrivateKey).addr;
13-
ERC1967Factory erc1967Factory = ERC1967Factory(ERC1967FactoryConstants.ADDRESS);
14-
address proxy = 0x7DFc6Ae9c532EC324Ecd5ce027c425767fcDa757;
15-
address newImplementation = 0xEC90b0d19f7CA925445cbBaA85F90958C60501A1;
18+
// address deployer = vm.createWallet(deployerPrivateKey).addr;
19+
address proxy = 0xF9a8529Bb95ac7707129700f06343338E4767A27;
20+
address newImplementation = 0x4Ee65f4CEd87Ff98fd40627Ac19C159E99C9D295;
1621
vm.startBroadcast(deployerPrivateKey);
17-
erc1967Factory.upgradeAndCall(proxy, newImplementation, "");
22+
IEIP7702ProxyWithAdminABI(proxy).upgrade(newImplementation);
1823
vm.stopBroadcast();
1924
}
2025
}

‎src/Delegation.sol‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import {P256} from "solady/utils/P256.sol";
1212
import {WebAuthn} from "solady/utils/WebAuthn.sol";
1313
import {LibStorage} from "solady/utils/LibStorage.sol";
1414
import {EnumerableSetLib} from "solady/utils/EnumerableSetLib.sol";
15+
import {CallContextChecker} from "solady/utils/CallContextChecker.sol";
1516
import {GuardedExecutor} from "./GuardedExecutor.sol";
1617
import {TokenTransferLib} from "./TokenTransferLib.sol";
1718

1819
/// @title Delegation
1920
/// @notice A delegation contract for EOAs with EIP7702.
20-
contract Delegation is EIP712, GuardedExecutor {
21+
contract Delegation is EIP712, GuardedExecutor, CallContextChecker {
2122
using EfficientHashLib for bytes32[];
2223
using EnumerableSetLib for *;
2324
using LibBytes for LibBytes.BytesStorage;
@@ -489,7 +490,7 @@ contract Delegation is EIP712, GuardedExecutor {
489490
if (!_getDelegationStorage().approvedImplementations.contains(target)) {
490491
revert Unauthorized();
491492
}
492-
_checkOnlyERC7702();
493+
_checkOnlyEIP7702Authority();
493494
assembly ("memory-safe") {
494495
let m := mload(0x40)
495496
calldatacopy(m, data.offset, data.length)
@@ -503,19 +504,6 @@ contract Delegation is EIP712, GuardedExecutor {
503504
super.execute(mode, executionData);
504505
}
505506

506-
/// @dev Requires that the call context is on an EOA with ERC7702 code.
507-
/// This excludes regular proxies and the implementation itself.
508-
/// This helps to protect the proxy and the implementation from vandalism.
509-
function _checkOnlyERC7702() internal view virtual {
510-
assembly ("memory-safe") {
511-
let thisCodeSize := extcodesize(address())
512-
extcodecopy(address(), 0x00, 0x00, 0x20)
513-
let hasPrefix := eq(0xef0100, shr(232, mload(0x00)))
514-
// The account must have the ERC7702 prefix and a codesize of 1..23 (inclusive) bytes.
515-
if iszero(and(hasPrefix, lt(sub(thisCodeSize, 1), 23))) { revert(0x00, 0x00) }
516-
}
517-
}
518-
519507
/// @dev Supported modes:
520508
/// - `0x01000000000000000000...`: Single batch. Does not support optional `opData`.
521509
/// - `0x01000000000078210001...`: Single batch. Supports optional `opData`.

0 commit comments

Comments
 (0)