Skip to content

Commit a06f385

Browse files
committed
remove blocking fallback pre-initialization
1 parent 5e898e3 commit a06f385

File tree

3 files changed

+4
-41
lines changed

3 files changed

+4
-41
lines changed

src/EIP7702Proxy.sol

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ contract EIP7702Proxy is Proxy {
2424
/// @notice Function selector on the implementation that is guarded from direct calls
2525
bytes4 immutable guardedInitializer;
2626

27-
/// @dev Storage slot with the initialized flag, calculated via ERC-7201
28-
bytes32 internal constant INITIALIZED_SLOT =
29-
keccak256(
30-
abi.encode(uint256(keccak256("EIP7702Proxy.initialized")) - 1)
31-
) & ~bytes32(uint256(0xff));
32-
3327
/// @notice Emitted when the initialization signature is invalid
3428
error InvalidSignature();
3529

@@ -55,11 +49,6 @@ contract EIP7702Proxy is Proxy {
5549
guardedInitializer = initializer;
5650
}
5751

58-
/// @dev Checks if proxy has been initialized by checking the initialized flag
59-
function _isInitialized() internal view returns (bool) {
60-
return StorageSlot.getBooleanSlot(INITIALIZED_SLOT).value;
61-
}
62-
6352
/// @notice Initializes the proxy and implementation with a signed payload
6453
///
6554
/// @dev Signature must be from this contract's address
@@ -78,9 +67,6 @@ contract EIP7702Proxy is Proxy {
7867
address recovered = ECDSA.recover(hash, signature);
7968
if (recovered != address(this)) revert InvalidSignature();
8069

81-
// Set initialized flag before upgrading
82-
StorageSlot.getBooleanSlot(INITIALIZED_SLOT).value = true;
83-
8470
// Set the ERC-1967 implementation slot, emit Upgraded event, call the initializer
8571
ERC1967Utils.upgradeToAndCall(
8672
initialImplementation,
@@ -100,9 +86,6 @@ contract EIP7702Proxy is Proxy {
10086
bytes32 hash,
10187
bytes calldata signature
10288
) external returns (bytes4) {
103-
// Check initialization status first
104-
if (!_isInitialized()) revert ProxyNotInitialized();
105-
10689
// First try delegatecall to implementation
10790
(bool success, bytes memory result) = _implementation().delegatecall(
10891
msg.data
@@ -133,15 +116,17 @@ contract EIP7702Proxy is Proxy {
133116
/// @dev Handles ERC-1271 signature validation by enforcing an ecrecover check if signatures fail `isValidSignature` check
134117
/// @dev Guards a specified initializer function from being called directly
135118
function _fallback() internal override {
136-
if (!_isInitialized()) revert ProxyNotInitialized();
137-
138119
// block guarded initializer from being called
139120
if (msg.sig == guardedInitializer) revert InvalidInitializer();
140121

141122
_delegate(_implementation());
142123
}
143124

125+
/// @notice Returns the implementation address, falling back to the initial implementation if the ERC-1967 implementation slot is not set
126+
/// @return The implementation address
144127
function _implementation() internal view override returns (address) {
128+
if (ERC1967Utils.getImplementation() == address(0))
129+
return initialImplementation;
145130
return ERC1967Utils.getImplementation();
146131
}
147132

test/EIP7702Proxy/delegate.t.sol

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,4 @@ contract DelegateTest is EIP7702ProxyBase {
127127
vm.expectRevert(EIP7702Proxy.ProxyNotInitialized.selector);
128128
uninitProxy.call(data);
129129
}
130-
131-
function test_reverts_whenCallingBeforeInitialization() public {
132-
// Deploy a fresh proxy without initializing it
133-
address payable uninitProxy = payable(makeAddr("uninitProxy"));
134-
_deployProxy(uninitProxy);
135-
136-
vm.expectRevert(EIP7702Proxy.ProxyNotInitialized.selector);
137-
MockImplementation(payable(uninitProxy)).owner();
138-
}
139130
}

test/EIP7702Proxy/isValidSignature.t.sol

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,6 @@ contract FailingImplementationTest is IsValidSignatureTestBase {
114114
);
115115
assertEq(result, ERC1271_FAIL_VALUE, "Should reject empty signature");
116116
}
117-
118-
function test_reverts_whenCalledBeforeInitialization() public {
119-
// Deploy a fresh proxy without initializing
120-
address payable uninitProxy = payable(makeAddr("uninitProxy"));
121-
_deployProxy(uninitProxy);
122-
123-
// Try to call isValidSignature
124-
bytes32 hash = keccak256("test message");
125-
bytes memory signature = new bytes(65);
126-
127-
vm.expectRevert(EIP7702Proxy.ProxyNotInitialized.selector);
128-
EIP7702Proxy(uninitProxy).isValidSignature(hash, signature);
129-
}
130117
}
131118

132119
/**

0 commit comments

Comments
 (0)