Skip to content

Commit 2d4155d

Browse files
committed
cleanup
1 parent 961da85 commit 2d4155d

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

script/Initialize.s.sol

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {console} from "forge-std/console.sol";
66
import {CoinbaseSmartWallet} from "../lib/smart-wallet/src/CoinbaseSmartWallet.sol";
77
import {EIP7702Proxy} from "../src/EIP7702Proxy.sol";
88
import {ECDSA} from "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol";
9+
910
/**
1011
* This script tests an upgraded EOA by verifying ownership and executing an ETH transfer
1112
*
@@ -19,7 +20,7 @@ import {ECDSA} from "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.s
1920
* - PROXY_TEMPLATE_ADDRESS_ODYSSEY: Address of the deployed proxy template on Odyssey
2021
*
2122
* Running instructions:
22-
*
23+
*
2324
* Local testing:
2425
* ```bash
2526
* forge script script/Initialize.s.sol --rpc-url http://localhost:8545 --broadcast --ffi
@@ -33,20 +34,26 @@ import {ECDSA} from "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.s
3334
contract Initialize is Script {
3435
// Anvil's default funded accounts (for local testing)
3536
address constant _ANVIL_EOA = 0x70997970C51812dc3A010C7d01b50e0d17dc79C8;
36-
uint256 constant _ANVIL_EOA_PK = 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d;
37+
uint256 constant _ANVIL_EOA_PK =
38+
0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d;
3739
// Using another Anvil account as the new owner
38-
address constant _ANVIL_NEW_OWNER = 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC;
39-
uint256 constant _ANVIL_NEW_OWNER_PK = 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a;
40+
address constant _ANVIL_NEW_OWNER =
41+
0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC;
42+
uint256 constant _ANVIL_NEW_OWNER_PK =
43+
0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a;
4044
// Using the deployer account as recipient for test transactions
41-
address constant _ANVIL_DEPLOYER = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
42-
uint256 constant _ANVIL_DEPLOYER_PK = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80;
45+
address constant _ANVIL_DEPLOYER =
46+
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
47+
uint256 constant _ANVIL_DEPLOYER_PK =
48+
0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80;
4349

4450
// Chain IDs
4551
uint256 constant _ANVIL_CHAIN_ID = 31337;
4652
uint256 constant _ODYSSEY_CHAIN_ID = 911867;
4753

4854
// Deterministic proxy address for Anvil environment
49-
address constant _PROXY_ADDRESS_ANVIL = 0x2d95f129bCEbD5cF7f395c7B34106ac1DCfb0CA9;
55+
address constant _PROXY_ADDRESS_ANVIL =
56+
0x2d95f129bCEbD5cF7f395c7B34106ac1DCfb0CA9;
5057

5158
function run() external {
5259
// Determine which environment we're in
@@ -84,7 +91,10 @@ contract Initialize is Script {
8491
console.log("Using proxy template at:", proxyAddr);
8592

8693
// First verify the EOA has code
87-
require(address(eoa).code.length > 0, "EOA not upgraded yet! Run UpgradeEOA.s.sol first");
94+
require(
95+
address(eoa).code.length > 0,
96+
"EOA not upgraded yet! Run UpgradeEOA.s.sol first"
97+
);
8898
console.log("[OK] Verified EOA has been upgraded");
8999

90100
// Create and sign the initialize data with just the new owner
@@ -93,28 +103,30 @@ contract Initialize is Script {
93103
bytes memory initArgs = abi.encode(owners);
94104
bytes32 initHash = keccak256(abi.encode(proxyAddr, initArgs));
95105
(uint8 v, bytes32 r, bytes32 s) = vm.sign(eoaPk, initHash);
96-
106+
97107
bytes memory initSignature = abi.encodePacked(r, s, v);
98-
108+
99109
// Try to recover ourselves before sending
100110
address recovered = ECDSA.recover(initHash, initSignature);
101111
console.log("Recovered:", recovered);
102112
require(recovered == eoa, "Signature recovery failed - wrong signer");
103113

104114
// Start broadcast with EOA's private key to call initialize
105115
vm.startBroadcast(eoaPk);
106-
116+
107117
// Try to initialize, but handle the case where it's already initialized
108118
try EIP7702Proxy(payable(eoa)).initialize(initArgs, initSignature) {
109119
console.log("[OK] Successfully initialized the smart wallet");
110120
} catch Error(string memory reason) {
111121
console.log("[INFO] Initialize call reverted with reason:", reason);
112122
} catch (bytes memory) {
113-
console.log("[INFO] Initialization failed: EOA may already have been initialized");
123+
console.log(
124+
"[INFO] Initialization failed: EOA may already have been initialized"
125+
);
114126
}
115127

116128
vm.stopBroadcast();
117-
129+
118130
// Verify ownership for the new owner
119131
CoinbaseSmartWallet smartWallet = CoinbaseSmartWallet(payable(eoa));
120132
bool isNewOwner = smartWallet.isOwnerAddress(newOwner);
@@ -128,13 +140,13 @@ contract Initialize is Script {
128140
console.log("Deployer balance before:", deployerBalanceBefore);
129141

130142
vm.startBroadcast(newOwnerPk);
131-
143+
132144
// Empty calldata for a simple ETH transfer
133145
bytes memory callData = "";
134146
smartWallet.execute(
135-
payable(deployer), // target: sending to the deployer
136-
amount, // value: amount of ETH to send
137-
callData // data: empty for simple ETH transfer
147+
payable(deployer), // target: sending to the deployer
148+
amount, // value: amount of ETH to send
149+
callData // data: empty for simple ETH transfer
138150
);
139151

140152
uint256 deployerBalanceAfter = deployer.balance;
@@ -147,4 +159,4 @@ contract Initialize is Script {
147159

148160
vm.stopBroadcast();
149161
}
150-
}
162+
}

script/UpgradeEOA.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity ^0.8.0;
2+
pragma solidity ^0.8.23;
33

44
import {Script} from "forge-std/Script.sol";
55
import {console} from "forge-std/console.sol";

src/EIP7702Proxy.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity ^0.8.0;
2+
pragma solidity ^0.8.23;
33

44
import {Proxy} from "openzeppelin-contracts/contracts/proxy/Proxy.sol";
55
import {ERC1967Utils} from "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol";

test/EIP7702Proxy/coinbaseImplementation.t.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ contract CoinbaseImplementationTest is Test {
172172
vm.assume(amount > 0 && amount <= 100 ether);
173173

174174
vm.deal(address(_eoa), amount);
175+
vm.deal(recipient, 0);
175176

176177
vm.prank(_newOwner);
177178
wallet.execute(

0 commit comments

Comments
 (0)