Skip to content

Commit 71b815e

Browse files
committed
fix: fix stack too deep error
1 parent 3256ce1 commit 71b815e

File tree

3 files changed

+147
-95
lines changed

3 files changed

+147
-95
lines changed

test/End2End.t.sol

Lines changed: 112 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.12;
33

4+
import {Vm} from "forge-std/Vm.sol";
5+
import {stdJson} from "forge-std/StdJson.sol";
46
import {Test, console2 as console} from "forge-std/Test.sol";
57
import {OperatorLib} from "./utils/OperatorLib.sol";
6-
import {CoreDeployLib} from "./utils/CoreDeployLib.sol";
78
import {UpgradeableProxyLib} from "./unit/UpgradeableProxyLib.sol";
89
import {MiddlewareDeployLib} from "./utils/MiddlewareDeployLib.sol";
910
import {BN254} from "../src/libraries/BN254.sol";
@@ -31,8 +32,26 @@ import {IStrategyFactory} from "eigenlayer-contracts/src/contracts/interfaces/IS
3132
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
3233

3334
contract End2EndForkTest is Test {
35+
using stdJson for string;
3436
using OperatorLib for *;
3537

38+
struct DeploymentData {
39+
address delegationManager;
40+
address avsDirectory;
41+
address allocationManager;
42+
address strategyManager;
43+
address eigenPodManager;
44+
address rewardsCoordinator;
45+
address eigenPodBeacon;
46+
address pauserRegistry;
47+
address strategyFactory;
48+
address strategyBeacon;
49+
address eigenStrategy;
50+
address eigen;
51+
address backingEigen;
52+
address permissionController;
53+
}
54+
3655
struct ConfigData {
3756
address admin;
3857
address token;
@@ -88,7 +107,7 @@ contract End2EndForkTest is Test {
88107
function testEndToEndSetup_M2Migration() public {
89108
(
90109
OperatorLib.Operator[] memory operators,
91-
CoreDeployLib.DeploymentData memory coreDeployment,
110+
DeploymentData memory coreDeployment,
92111
MiddlewareDeployLib.MiddlewareDeployData memory middlewareDeployment,
93112
ConfigData memory middlewareConfig
94113
) = _setupInitialState();
@@ -107,20 +126,54 @@ contract End2EndForkTest is Test {
107126
_executeSlashing(operators, middlewareConfig, middlewareDeployment);
108127
}
109128

129+
function _deployMiddlewareWithCore(
130+
address proxyAdmin,
131+
address owner
132+
)
133+
internal
134+
returns (
135+
MiddlewareDeployLib.MiddlewareDeployData memory middleware,
136+
DeploymentData memory core
137+
)
138+
{
139+
string memory rpcUrl = vm.envString("HOLESKY_RPC_URL");
140+
vm.createSelectFork(rpcUrl);
141+
// Read core deployment data from json
142+
core = _readCoreDeploymentJson("./script/config", 17000, "preprod");
143+
144+
// Deploy proxies
145+
middleware = MiddlewareDeployLib.deployEmptyProxies(proxyAdmin);
146+
147+
// Deploy pauser registry
148+
middleware.pauserRegistry = MiddlewareDeployLib.deployPauserRegistry(proxyAdmin);
149+
150+
// Upgrade the proxies
151+
MiddlewareDeployLib.upgradeRegistriesM2Coordinator(
152+
core.delegationManager, core.avsDirectory, core.allocationManager, middleware
153+
);
154+
MiddlewareDeployLib.ugpradeServiceManager(
155+
core.avsDirectory, core.rewardsCoordinator, core.allocationManager, middleware, owner
156+
);
157+
MiddlewareDeployLib.upgradeM2Coordinator(core.allocationManager, middleware, owner);
158+
159+
return (middleware, core);
160+
}
161+
110162
function _setupInitialState()
111163
internal
112164
returns (
113165
OperatorLib.Operator[] memory operators,
114-
CoreDeployLib.DeploymentData memory coreDeployment,
166+
DeploymentData memory coreDeployment,
115167
MiddlewareDeployLib.MiddlewareDeployData memory middlewareDeployment,
116168
ConfigData memory middlewareConfig
117169
)
118170
{
119-
// Fork Holesky testnet
120-
string memory rpcUrl = vm.envString("HOLESKY_RPC_URL");
121-
vm.createSelectFork(rpcUrl);
122-
// Read core deployment data from json
123-
coreDeployment = CoreDeployLib.readCoreDeploymentJson("./script/config", 17000, "preprod");
171+
middlewareConfig.proxyAdmin = UpgradeableProxyLib.deployProxyAdmin();
172+
middlewareConfig.admin = address(this);
173+
174+
// Deploy middleware with core
175+
(middlewareDeployment, coreDeployment) =
176+
deployMiddlewareWithCore(middlewareConfig.proxyAdmin, middlewareConfig.admin);
124177

125178
// // Create 5 operators using helper function
126179
operators = _createOperators(5, 100);
@@ -129,8 +182,6 @@ contract End2EndForkTest is Test {
129182
(address token, address strategy) = _deployTokenAndStrategy(coreDeployment.strategyFactory);
130183

131184
// Setup middleware deployment data
132-
middlewareConfig.proxyAdmin = UpgradeableProxyLib.deployProxyAdmin();
133-
middlewareConfig.admin = address(this);
134185
middlewareConfig.numQuorums = 1;
135186
middlewareConfig.operatorParams = new uint256[](3);
136187
middlewareConfig.operatorParams[0] = 10;
@@ -140,10 +191,6 @@ contract End2EndForkTest is Test {
140191
middlewareConfig.token = token;
141192
middlewareConfig.operators = _getAndSortOperators(operators);
142193

143-
middlewareDeployment = MiddlewareDeployLib.deployMiddlewareWithCore(
144-
middlewareConfig.proxyAdmin, middlewareConfig.admin, coreDeployment
145-
);
146-
147194
vm.startPrank(middlewareDeployment.serviceManager);
148195
AllocationManager(coreDeployment.allocationManager).updateAVSMetadataURI(
149196
middlewareDeployment.serviceManager, "metadata"
@@ -194,7 +241,7 @@ contract End2EndForkTest is Test {
194241

195242
function _setupOperatorsAndTokens(
196243
OperatorLib.Operator[] memory operators,
197-
CoreDeployLib.DeploymentData memory coreDeployment,
244+
DeploymentData memory coreDeployment,
198245
ConfigData memory middlewareConfig
199246
) internal {
200247
// Verify and register operators
@@ -243,7 +290,7 @@ contract End2EndForkTest is Test {
243290
function _setupFirstQuorumAndOperatorSet(
244291
OperatorLib.Operator[] memory operators,
245292
ConfigData memory middlewareConfig,
246-
CoreDeployLib.DeploymentData memory coreDeployment,
293+
DeploymentData memory coreDeployment,
247294
MiddlewareDeployLib.MiddlewareDeployData memory middlewareDeployment
248295
) internal {
249296
vm.startPrank(middlewareConfig.admin);
@@ -297,7 +344,7 @@ contract End2EndForkTest is Test {
297344
function _setupSecondQuorumAndOperatorSet(
298345
OperatorLib.Operator[] memory operators,
299346
ConfigData memory middlewareConfig,
300-
CoreDeployLib.DeploymentData memory coreDeployment,
347+
DeploymentData memory coreDeployment,
301348
MiddlewareDeployLib.MiddlewareDeployData memory middlewareDeployment
302349
) internal {
303350
// Create second quorum
@@ -354,7 +401,7 @@ contract End2EndForkTest is Test {
354401

355402
function _setupOperatorAllocations(
356403
OperatorLib.Operator[] memory operators,
357-
CoreDeployLib.DeploymentData memory coreDeployment,
404+
DeploymentData memory coreDeployment,
358405
MiddlewareDeployLib.MiddlewareDeployData memory middlewareDeployment,
359406
address strategy
360407
) internal {
@@ -439,4 +486,51 @@ contract End2EndForkTest is Test {
439486

440487
return registeredOperators;
441488
}
489+
490+
function _readCoreDeploymentJson(
491+
string memory path,
492+
uint256 chainId
493+
) internal returns (DeploymentData memory) {
494+
string memory filePath = string(abi.encodePacked(path, "/", vm.toString(chainId), ".json"));
495+
return _parseZeusJson(filePath);
496+
}
497+
498+
function _readCoreDeploymentJson(
499+
string memory path,
500+
uint256 chainId,
501+
string memory environment
502+
) internal returns (DeploymentData memory) {
503+
string memory filePath =
504+
string(abi.encodePacked(path, "/", vm.toString(chainId), "-", environment, ".json"));
505+
return _parseZeusJson(filePath);
506+
}
507+
508+
function _parseZeusJson(
509+
string memory filePath
510+
) internal returns (DeploymentData memory) {
511+
string memory json = vm.readFile(filePath);
512+
require(vm.exists(filePath), "Deployment file does not exist");
513+
DeploymentData memory deploymentData;
514+
515+
deploymentData.delegationManager =
516+
json.readAddress(".ZEUS_DEPLOYED_DelegationManager_Proxy");
517+
deploymentData.avsDirectory = json.readAddress(".ZEUS_DEPLOYED_AVSDirectory_Proxy");
518+
deploymentData.strategyManager = json.readAddress(".ZEUS_DEPLOYED_StrategyManager_Proxy");
519+
deploymentData.allocationManager =
520+
json.readAddress(".ZEUS_DEPLOYED_AllocationManager_Proxy");
521+
deploymentData.eigenPodManager = json.readAddress(".ZEUS_DEPLOYED_EigenPodManager_Proxy");
522+
deploymentData.rewardsCoordinator =
523+
json.readAddress(".ZEUS_DEPLOYED_RewardsCoordinator_Proxy");
524+
deploymentData.eigenPodBeacon = json.readAddress(".ZEUS_DEPLOYED_EigenPod_Beacon");
525+
deploymentData.pauserRegistry = json.readAddress(".ZEUS_DEPLOYED_PauserRegistry_Impl");
526+
deploymentData.strategyFactory = json.readAddress(".ZEUS_DEPLOYED_StrategyFactory_Proxy");
527+
deploymentData.strategyBeacon = json.readAddress(".ZEUS_DEPLOYED_StrategyBase_Beacon");
528+
deploymentData.eigenStrategy = json.readAddress(".ZEUS_DEPLOYED_EigenStrategy_Proxy");
529+
deploymentData.eigen = json.readAddress(".ZEUS_DEPLOYED_Eigen_Proxy");
530+
deploymentData.backingEigen = json.readAddress(".ZEUS_DEPLOYED_BackingEigen_Proxy");
531+
deploymentData.permissionController =
532+
json.readAddress(".ZEUS_DEPLOYED_PermissionController_Proxy");
533+
534+
return deploymentData;
535+
}
442536
}

test/utils/CoreDeployLib.sol

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ library CoreDeployLib {
124124
address strategyBeacon;
125125
address rewardsCoordinator;
126126
address permissionController;
127-
address eigenStrategy;
128-
address eigen;
129-
address backingEigen;
130127
}
131128

132129
function deployContracts(
@@ -350,51 +347,4 @@ library CoreDeployLib {
350347
deployments.rewardsCoordinator, rewardsCoordinatorImpl, upgradeCall
351348
);
352349
}
353-
354-
function readCoreDeploymentJson(
355-
string memory path,
356-
uint256 chainId
357-
) internal returns (DeploymentData memory) {
358-
string memory filePath = string(abi.encodePacked(path, "/", vm.toString(chainId), ".json"));
359-
return parseZeusJson(filePath);
360-
}
361-
362-
function readCoreDeploymentJson(
363-
string memory path,
364-
uint256 chainId,
365-
string memory environment
366-
) internal returns (DeploymentData memory) {
367-
string memory filePath =
368-
string(abi.encodePacked(path, "/", vm.toString(chainId), "-", environment, ".json"));
369-
return parseZeusJson(filePath);
370-
}
371-
372-
function parseZeusJson(
373-
string memory filePath
374-
) internal returns (DeploymentData memory) {
375-
string memory json = vm.readFile(filePath);
376-
require(vm.exists(filePath), "Deployment file does not exist");
377-
DeploymentData memory deploymentData;
378-
379-
deploymentData.delegationManager =
380-
json.readAddress(".ZEUS_DEPLOYED_DelegationManager_Proxy");
381-
deploymentData.avsDirectory = json.readAddress(".ZEUS_DEPLOYED_AVSDirectory_Proxy");
382-
deploymentData.strategyManager = json.readAddress(".ZEUS_DEPLOYED_StrategyManager_Proxy");
383-
deploymentData.allocationManager =
384-
json.readAddress(".ZEUS_DEPLOYED_AllocationManager_Proxy");
385-
deploymentData.eigenPodManager = json.readAddress(".ZEUS_DEPLOYED_EigenPodManager_Proxy");
386-
deploymentData.rewardsCoordinator =
387-
json.readAddress(".ZEUS_DEPLOYED_RewardsCoordinator_Proxy");
388-
deploymentData.eigenPodBeacon = json.readAddress(".ZEUS_DEPLOYED_EigenPod_Beacon");
389-
deploymentData.pauserRegistry = json.readAddress(".ZEUS_DEPLOYED_PauserRegistry_Impl");
390-
deploymentData.strategyFactory = json.readAddress(".ZEUS_DEPLOYED_StrategyFactory_Proxy");
391-
deploymentData.strategyBeacon = json.readAddress(".ZEUS_DEPLOYED_StrategyBase_Beacon");
392-
deploymentData.eigenStrategy = json.readAddress(".ZEUS_DEPLOYED_EigenStrategy_Proxy");
393-
deploymentData.eigen = json.readAddress(".ZEUS_DEPLOYED_Eigen_Proxy");
394-
deploymentData.backingEigen = json.readAddress(".ZEUS_DEPLOYED_BackingEigen_Proxy");
395-
deploymentData.permissionController =
396-
json.readAddress(".ZEUS_DEPLOYED_PermissionController_Proxy");
397-
398-
return deploymentData;
399-
}
400350
}

test/utils/MiddlewareDeployLib.sol

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,6 @@ library MiddlewareDeployLib {
119119
return result;
120120
}
121121

122-
function deployMiddlewareWithCore(
123-
address proxyAdmin,
124-
address owner,
125-
CoreDeployLib.DeploymentData memory core
126-
) internal returns (MiddlewareDeployData memory result) {
127-
// Deploy proxies
128-
result = deployEmptyProxies(proxyAdmin);
129-
130-
// Deploy pauser registry
131-
result.pauserRegistry = _deployPauserRegistry(proxyAdmin);
132-
133-
// Upgrade the proxies
134-
upgradeRegistriesM2Coordinator(core, result);
135-
ugpradeServiceManager(core, result, owner);
136-
upgradeM2Coordinator(core, result, owner);
137-
138-
return result;
139-
}
140-
141122
function deployEmptyProxies(
142123
address proxyAdmin
143124
) internal returns (MiddlewareDeployData memory proxies) {
@@ -190,15 +171,17 @@ library MiddlewareDeployLib {
190171
}
191172

192173
function upgradeRegistriesM2Coordinator(
193-
CoreDeployLib.DeploymentData memory core,
174+
address delegationManager,
175+
address avsDirectory,
176+
address allocationManager,
194177
MiddlewareDeployData memory deployments
195178
) internal {
196179
address stakeRegistryImpl = address(
197180
new StakeRegistry(
198181
IRegistryCoordinator(deployments.registryCoordinator),
199-
IDelegationManager(core.delegationManager),
200-
IAVSDirectory(core.avsDirectory),
201-
IAllocationManager(core.allocationManager)
182+
IDelegationManager(delegationManager),
183+
IAVSDirectory(avsDirectory),
184+
IAllocationManager(allocationManager)
202185
)
203186
);
204187
UpgradeableProxyLib.upgrade(deployments.stakeRegistry, stakeRegistryImpl);
@@ -216,6 +199,31 @@ library MiddlewareDeployLib {
216199
UpgradeableProxyLib.upgrade(deployments.socketRegistry, socketRegistryImpl);
217200
}
218201

202+
function ugpradeServiceManager(
203+
address avsDirectory,
204+
address rewardsCoordinator,
205+
address allocationManager,
206+
MiddlewareDeployData memory deployment,
207+
address admin
208+
) internal {
209+
address impl = address(
210+
new ServiceManagerMock(
211+
IAVSDirectory(avsDirectory),
212+
IRewardsCoordinator(rewardsCoordinator),
213+
IRegistryCoordinator(deployment.registryCoordinator),
214+
IStakeRegistry(deployment.stakeRegistry),
215+
IPermissionController(deployment.permissionController),
216+
IAllocationManager(allocationManager)
217+
)
218+
);
219+
bytes memory serviceManagerUpgradeCall =
220+
abi.encodeCall(ServiceManagerMock.initialize, (admin, admin));
221+
222+
UpgradeableProxyLib.upgradeAndCall(
223+
deployment.serviceManager, impl, serviceManagerUpgradeCall
224+
);
225+
}
226+
219227
function ugpradeServiceManager(
220228
CoreDeployLib.DeploymentData memory core,
221229
MiddlewareDeployData memory deployment,
@@ -240,7 +248,7 @@ library MiddlewareDeployLib {
240248
}
241249

242250
function upgradeM2Coordinator(
243-
CoreDeployLib.DeploymentData memory core,
251+
address allocationManager,
244252
MiddlewareDeployData memory deployment,
245253
address admin
246254
) internal {
@@ -251,7 +259,7 @@ library MiddlewareDeployLib {
251259
IBLSApkRegistry(deployment.blsApkRegistry),
252260
IIndexRegistry(deployment.indexRegistry),
253261
ISocketRegistry(deployment.socketRegistry),
254-
IAllocationManager(core.allocationManager),
262+
IAllocationManager(allocationManager),
255263
IPauserRegistry(deployment.pauserRegistry)
256264
)
257265
);
@@ -312,9 +320,9 @@ library MiddlewareDeployLib {
312320
UpgradeableProxyLib.upgrade(deployments.instantSlasher, instantSlasherImpl);
313321
}
314322

315-
function _deployPauserRegistry(
323+
function deployPauserRegistry(
316324
address admin
317-
) private returns (address) {
325+
) internal returns (address) {
318326
address[] memory pausers = new address[](2);
319327
pausers[0] = admin;
320328
pausers[1] = admin;

0 commit comments

Comments
 (0)