@@ -3,7 +3,7 @@ pragma solidity ^0.8.23;
33
44import {EIP7702ProxyBase} from "../base/EIP7702ProxyBase.sol " ;
55import {EIP7702Proxy} from "../../src/EIP7702Proxy.sol " ;
6- import {MockImplementation} from "../mocks/MockImplementation.sol " ;
6+ import {MockImplementation, RevertingInitializerMockImplementation } from "../mocks/MockImplementation.sol " ;
77import {ECDSA} from "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol " ;
88
99contract InitializeTest is EIP7702ProxyBase {
@@ -73,4 +73,53 @@ contract InitializeTest is EIP7702ProxyBase {
7373 vm.expectRevert (EIP7702Proxy.InvalidSignature.selector );
7474 EIP7702Proxy (_eoa).initialize (initArgs, signature);
7575 }
76+
77+ function testRevertsWhenInitializerDelegatecallFails () public {
78+ // Deploy reverting implementation
79+ _implementation = new RevertingInitializerMockImplementation ();
80+ _initSelector = RevertingInitializerMockImplementation
81+ .initialize
82+ .selector ;
83+
84+ // Deploy proxy normally first to get the correct immutable values
85+ _proxy = new EIP7702Proxy (address (_implementation), _initSelector);
86+
87+ // Get the proxy's runtime code
88+ bytes memory proxyCode = address (_proxy).code;
89+
90+ // Etch the proxy code at the EOA's address
91+ vm.etch (_eoa, proxyCode);
92+
93+ // Try to initialize with valid signature but reverting implementation
94+ bytes memory initArgs = _createInitArgs (_newOwner);
95+ bytes memory signature = _signInitData (_EOA_PRIVATE_KEY, initArgs);
96+
97+ vm.expectRevert ("InitializerReverted " );
98+ EIP7702Proxy (_eoa).initialize (initArgs, signature);
99+ }
100+
101+ function testRevertsWhenSignatureReplayedWithDifferentProxy () public {
102+ // Get signature for first proxy
103+ bytes memory initArgs = _createInitArgs (_newOwner);
104+ bytes memory signature = _signInitData (_EOA_PRIVATE_KEY, initArgs);
105+
106+ // Deploy a second proxy with same implementation
107+ address payable secondProxy = payable (address (0xBEEF ));
108+ _deployProxy (secondProxy);
109+
110+ // Try to use same signature with different proxy
111+ vm.expectRevert (EIP7702Proxy.InvalidSignature.selector );
112+ EIP7702Proxy (secondProxy).initialize (initArgs, signature);
113+ }
114+
115+ function testRevertsWhenSignatureReplayedWithDifferentArgs () public {
116+ // Get signature for first initialization args
117+ bytes memory initArgs = _createInitArgs (_newOwner);
118+ bytes memory signature = _signInitData (_EOA_PRIVATE_KEY, initArgs);
119+
120+ // Try to use same signature with different args
121+ bytes memory differentArgs = _createInitArgs (address (0xBEEF ));
122+ vm.expectRevert (EIP7702Proxy.InvalidSignature.selector );
123+ EIP7702Proxy (_eoa).initialize (differentArgs, signature);
124+ }
76125}
0 commit comments