diff --git a/contracts/script/IncredibleSquaringDeployer.s.sol b/contracts/script/IncredibleSquaringDeployer.s.sol index 3e486ec0..8eb40a8d 100644 --- a/contracts/script/IncredibleSquaringDeployer.s.sol +++ b/contracts/script/IncredibleSquaringDeployer.s.sol @@ -12,13 +12,20 @@ import {StrategyBaseTVLLimits} from "@eigenlayer/contracts/strategies/StrategyBa import "@eigenlayer/test/mocks/EmptyContract.sol"; import "@eigenlayer-middleware/src/RegistryCoordinator.sol" as regcoord; -import {IBLSApkRegistry, IIndexRegistry, IStakeRegistry} from "@eigenlayer-middleware/src/RegistryCoordinator.sol"; +import { + IBLSApkRegistry, + IIndexRegistry, + IStakeRegistry +} from "@eigenlayer-middleware/src/RegistryCoordinator.sol"; import {BLSApkRegistry} from "@eigenlayer-middleware/src/BLSApkRegistry.sol"; import {IndexRegistry} from "@eigenlayer-middleware/src/IndexRegistry.sol"; import {StakeRegistry} from "@eigenlayer-middleware/src/StakeRegistry.sol"; import "@eigenlayer-middleware/src/OperatorStateRetriever.sol"; import {IRewardsCoordinator} from "@eigenlayer/contracts/interfaces/IRewardsCoordinator.sol"; -import {IncredibleSquaringServiceManager, IServiceManager} from "../src/IncredibleSquaringServiceManager.sol"; +import { + IncredibleSquaringServiceManager, + IServiceManager +} from "../src/IncredibleSquaringServiceManager.sol"; import {IncredibleSquaringTaskManager} from "../src/IncredibleSquaringTaskManager.sol"; import {IIncredibleSquaringTaskManager} from "../src/IIncredibleSquaringTaskManager.sol"; import "../src/ERC20Mock.sol"; @@ -75,23 +82,32 @@ contract IncredibleSquaringDeployer is Script, Utils, Test { function run() external { // Eigenlayer contracts string memory eigenlayerDeployedContracts = readOutput("eigenlayer_deployment_output"); - IStrategyManager strategyManager = - IStrategyManager(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.strategyManager")); - IDelegationManager delegationManager = - IDelegationManager(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.delegation")); - IAVSDirectory avsDirectory = - IAVSDirectory(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.avsDirectory")); - ProxyAdmin eigenLayerProxyAdmin = - ProxyAdmin(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.eigenLayerProxyAdmin")); - PauserRegistry eigenLayerPauserReg = - PauserRegistry(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.eigenLayerPauserReg")); + IStrategyManager strategyManager = IStrategyManager( + stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.strategyManager") + ); + IDelegationManager delegationManager = IDelegationManager( + stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.delegation") + ); + IAVSDirectory avsDirectory = IAVSDirectory( + stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.avsDirectory") + ); + ProxyAdmin eigenLayerProxyAdmin = ProxyAdmin( + stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.eigenLayerProxyAdmin") + ); + PauserRegistry eigenLayerPauserReg = PauserRegistry( + stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.eigenLayerPauserReg") + ); StrategyBaseTVLLimits baseStrategyImplementation = StrategyBaseTVLLimits( - stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.baseStrategyImplementation") + stdJson.readAddress( + eigenlayerDeployedContracts, ".addresses.baseStrategyImplementation" + ) + ); + IRewardsCoordinator rewardsCoordinator = IRewardsCoordinator( + stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.rewardsCoordinator") ); - IRewardsCoordinator rewardsCoordinator = - IRewardsCoordinator(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.rewardsCoordinator")); - operationsMultisig = stdJson.readAddress(eigenlayerDeployedContracts, ".parameters.operationsMultisig"); + operationsMultisig = + stdJson.readAddress(eigenlayerDeployedContracts, ".parameters.operationsMultisig"); address incredibleSquaringCommunityMultisig = msg.sender; address incredibleSquaringPauser = msg.sender; @@ -132,7 +148,9 @@ contract IncredibleSquaringDeployer is Script, Utils, Test { // TODO(samlaf): any reason why we are using the strategybase with tvl limits instead of just using strategybase? // the maxPerDeposit and maxDeposits below are just arbitrary values. emit log_named_address("baseStrategyImplementation", address(baseStrategyImplementation)); - emit log_named_bytes("baseStrategyImplementation code", address(baseStrategyImplementation).code); + emit log_named_bytes( + "baseStrategyImplementation code", address(baseStrategyImplementation).code + ); erc20MockStrategy = StrategyBaseTVLLimits( address( new TransparentUpgradeableProxy( @@ -173,7 +191,8 @@ contract IncredibleSquaringDeployer is Script, Utils, Test { address[] memory pausers = new address[](2); pausers[0] = incredibleSquaringPauser; pausers[1] = incredibleSquaringCommunityMultisig; - incredibleSquaringPauserReg = new PauserRegistry(pausers, incredibleSquaringCommunityMultisig); + incredibleSquaringPauserReg = + new PauserRegistry(pausers, incredibleSquaringCommunityMultisig); } EmptyContract emptyContract = new EmptyContract(); @@ -185,22 +204,46 @@ contract IncredibleSquaringDeployer is Script, Utils, Test { * not yet deployed, we give these proxies an empty contract as the initial implementation, to act as if they have no code. */ incredibleSquaringServiceManager = IncredibleSquaringServiceManager( - address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), "")) + address( + new TransparentUpgradeableProxy( + address(emptyContract), address(incredibleSquaringProxyAdmin), "" + ) + ) ); incredibleSquaringTaskManager = IncredibleSquaringTaskManager( - address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), "")) + address( + new TransparentUpgradeableProxy( + address(emptyContract), address(incredibleSquaringProxyAdmin), "" + ) + ) ); registryCoordinator = regcoord.RegistryCoordinator( - address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), "")) + address( + new TransparentUpgradeableProxy( + address(emptyContract), address(incredibleSquaringProxyAdmin), "" + ) + ) ); blsApkRegistry = IBLSApkRegistry( - address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), "")) + address( + new TransparentUpgradeableProxy( + address(emptyContract), address(incredibleSquaringProxyAdmin), "" + ) + ) ); indexRegistry = IIndexRegistry( - address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), "")) + address( + new TransparentUpgradeableProxy( + address(emptyContract), address(incredibleSquaringProxyAdmin), "" + ) + ) ); stakeRegistry = IStakeRegistry( - address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), "")) + address( + new TransparentUpgradeableProxy( + address(emptyContract), address(incredibleSquaringProxyAdmin), "" + ) + ) ); operatorStateRetriever = new OperatorStateRetriever(); @@ -210,19 +253,22 @@ contract IncredibleSquaringDeployer is Script, Utils, Test { stakeRegistryImplementation = new StakeRegistry(registryCoordinator, delegationManager); incredibleSquaringProxyAdmin.upgrade( - TransparentUpgradeableProxy(payable(address(stakeRegistry))), address(stakeRegistryImplementation) + TransparentUpgradeableProxy(payable(address(stakeRegistry))), + address(stakeRegistryImplementation) ); blsApkRegistryImplementation = new BLSApkRegistry(registryCoordinator); incredibleSquaringProxyAdmin.upgrade( - TransparentUpgradeableProxy(payable(address(blsApkRegistry))), address(blsApkRegistryImplementation) + TransparentUpgradeableProxy(payable(address(blsApkRegistry))), + address(blsApkRegistryImplementation) ); indexRegistryImplementation = new IndexRegistry(registryCoordinator); incredibleSquaringProxyAdmin.upgrade( - TransparentUpgradeableProxy(payable(address(indexRegistry))), address(indexRegistryImplementation) + TransparentUpgradeableProxy(payable(address(indexRegistry))), + address(indexRegistryImplementation) ); } @@ -283,7 +329,11 @@ contract IncredibleSquaringDeployer is Script, Utils, Test { } incredibleSquaringServiceManagerImplementation = new IncredibleSquaringServiceManager( - avsDirectory, rewardsCoordinator, registryCoordinator, stakeRegistry, incredibleSquaringTaskManager + avsDirectory, + rewardsCoordinator, + registryCoordinator, + stakeRegistry, + incredibleSquaringTaskManager ); // Third, upgrade the proxy contracts to use the correct implementation contracts and initialize them. incredibleSquaringProxyAdmin.upgrade( @@ -314,14 +364,20 @@ contract IncredibleSquaringDeployer is Script, Utils, Test { vm.serializeAddress(deployed_addresses, "erc20Mock", address(erc20Mock)); vm.serializeAddress(deployed_addresses, "erc20MockStrategy", address(erc20MockStrategy)); vm.serializeAddress( - deployed_addresses, "credibleSquaringServiceManager", address(incredibleSquaringServiceManager) + deployed_addresses, + "credibleSquaringServiceManager", + address(incredibleSquaringServiceManager) ); vm.serializeAddress( deployed_addresses, "credibleSquaringServiceManagerImplementation", address(incredibleSquaringServiceManagerImplementation) ); - vm.serializeAddress(deployed_addresses, "credibleSquaringTaskManager", address(incredibleSquaringTaskManager)); + vm.serializeAddress( + deployed_addresses, + "credibleSquaringTaskManager", + address(incredibleSquaringTaskManager) + ); vm.serializeAddress( deployed_addresses, "credibleSquaringTaskManagerImplementation", @@ -329,13 +385,17 @@ contract IncredibleSquaringDeployer is Script, Utils, Test { ); vm.serializeAddress(deployed_addresses, "registryCoordinator", address(registryCoordinator)); vm.serializeAddress( - deployed_addresses, "registryCoordinatorImplementation", address(registryCoordinatorImplementation) + deployed_addresses, + "registryCoordinatorImplementation", + address(registryCoordinatorImplementation) + ); + string memory deployed_addresses_output = vm.serializeAddress( + deployed_addresses, "operatorStateRetriever", address(operatorStateRetriever) ); - string memory deployed_addresses_output = - vm.serializeAddress(deployed_addresses, "operatorStateRetriever", address(operatorStateRetriever)); // serialize all the data - string memory finalJson = vm.serializeString(parent_object, deployed_addresses, deployed_addresses_output); + string memory finalJson = + vm.serializeString(parent_object, deployed_addresses, deployed_addresses_output); writeOutput(finalJson, "credible_squaring_avs_deployment_output"); } diff --git a/contracts/script/utils/Utils.sol b/contracts/script/utils/Utils.sol index 89b60e01..b23c8b75 100644 --- a/contracts/script/utils/Utils.sol +++ b/contracts/script/utils/Utils.sol @@ -10,9 +10,14 @@ import "forge-std/StdJson.sol"; contract Utils is Script { // Note that this function will only work for the ERC20Mock that has a public mint function - function _mintTokens(address strategyAddress, address[] memory tos, uint256[] memory amounts) internal { + function _mintTokens( + address strategyAddress, + address[] memory tos, + uint256[] memory amounts + ) internal { for (uint256 i = 0; i < tos.length; i++) { - ERC20Mock underlyingToken = ERC20Mock(address(StrategyBase(strategyAddress).underlyingToken())); + ERC20Mock underlyingToken = + ERC20Mock(address(StrategyBase(strategyAddress).underlyingToken())); underlyingToken.mint(tos[i], amounts[i]); } } diff --git a/contracts/src/IIncredibleSquaringTaskManager.sol b/contracts/src/IIncredibleSquaringTaskManager.sol index 3e6f3063..d6dc7c01 100644 --- a/contracts/src/IIncredibleSquaringTaskManager.sol +++ b/contracts/src/IIncredibleSquaringTaskManager.sol @@ -52,8 +52,11 @@ interface IIncredibleSquaringTaskManager { // FUNCTIONS // NOTE: this function creates a new task. - function createNewTask(uint256 numberToBeSquared, uint32 quorumThresholdPercentage, bytes calldata quorumNumbers) - external; + function createNewTask( + uint256 numberToBeSquared, + uint32 quorumThresholdPercentage, + bytes calldata quorumNumbers + ) external; /// @notice Returns the current 'taskNumber' for the middleware function taskNumber() external view returns (uint32); diff --git a/contracts/src/IncredibleSquaringServiceManager.sol b/contracts/src/IncredibleSquaringServiceManager.sol index 4ed67c21..7789757a 100644 --- a/contracts/src/IncredibleSquaringServiceManager.sol +++ b/contracts/src/IncredibleSquaringServiceManager.sol @@ -29,7 +29,9 @@ contract IncredibleSquaringServiceManager is ServiceManagerBase { IRegistryCoordinator _registryCoordinator, IStakeRegistry _stakeRegistry, IIncredibleSquaringTaskManager _incredibleSquaringTaskManager - ) ServiceManagerBase(_avsDirectory, _rewardsCoordinator, _registryCoordinator, _stakeRegistry) { + ) + ServiceManagerBase(_avsDirectory, _rewardsCoordinator, _registryCoordinator, _stakeRegistry) + { incredibleSquaringTaskManager = _incredibleSquaringTaskManager; } diff --git a/contracts/src/IncredibleSquaringTaskManager.sol b/contracts/src/IncredibleSquaringTaskManager.sol index c1db29c8..be85560f 100644 --- a/contracts/src/IncredibleSquaringTaskManager.sol +++ b/contracts/src/IncredibleSquaringTaskManager.sol @@ -7,7 +7,10 @@ import "@eigenlayer/contracts/permissions/Pausable.sol"; import "@eigenlayer-middleware/src/interfaces/IServiceManager.sol"; import {BLSApkRegistry} from "@eigenlayer-middleware/src/BLSApkRegistry.sol"; import {RegistryCoordinator} from "@eigenlayer-middleware/src/RegistryCoordinator.sol"; -import {BLSSignatureChecker, IRegistryCoordinator} from "@eigenlayer-middleware/src/BLSSignatureChecker.sol"; +import { + BLSSignatureChecker, + IRegistryCoordinator +} from "@eigenlayer-middleware/src/BLSSignatureChecker.sol"; import {OperatorStateRetriever} from "@eigenlayer-middleware/src/OperatorStateRetriever.sol"; import "@eigenlayer-middleware/src/libraries/BN254.sol"; import "./IIncredibleSquaringTaskManager.sol"; @@ -58,16 +61,19 @@ contract IncredibleSquaringTaskManager is _; } - constructor(IRegistryCoordinator _registryCoordinator, uint32 _taskResponseWindowBlock) - BLSSignatureChecker(_registryCoordinator) - { + constructor( + IRegistryCoordinator _registryCoordinator, + uint32 _taskResponseWindowBlock + ) BLSSignatureChecker(_registryCoordinator) { TASK_RESPONSE_WINDOW_BLOCK = _taskResponseWindowBlock; } - function initialize(IPauserRegistry _pauserRegistry, address initialOwner, address _aggregator, address _generator) - public - initializer - { + function initialize( + IPauserRegistry _pauserRegistry, + address initialOwner, + address _aggregator, + address _generator + ) public initializer { _initializePauser(_pauserRegistry, UNPAUSE_ALL); _transferOwnership(initialOwner); _setAggregator(_aggregator); @@ -84,10 +90,11 @@ contract IncredibleSquaringTaskManager is /* FUNCTIONS */ // NOTE: this function creates new task, assigns it a taskId - function createNewTask(uint256 numberToBeSquared, uint32 quorumThresholdPercentage, bytes calldata quorumNumbers) - external - onlyTaskGenerator - { + function createNewTask( + uint256 numberToBeSquared, + uint32 quorumThresholdPercentage, + bytes calldata quorumNumbers + ) external onlyTaskGenerator { // create a new task struct Task memory newTask; newTask.numberToBeSquared = numberToBeSquared; @@ -132,7 +139,10 @@ contract IncredibleSquaringTaskManager is // check the BLS signature (QuorumStakeTotals memory quorumStakeTotals, bytes32 hashOfNonSigners) = checkSignatures( - keccak256(abi.encode(taskResponse)), quorumNumbers, taskCreatedBlock, nonSignerStakesAndSignature + keccak256(abi.encode(taskResponse)), + quorumNumbers, + taskCreatedBlock, + nonSignerStakesAndSignature ); // check that signatories own at least a threshold percentage of each quorum @@ -146,9 +156,11 @@ contract IncredibleSquaringTaskManager is ); } - TaskResponseMetadata memory taskResponseMetadata = TaskResponseMetadata(uint32(block.number), hashOfNonSigners); + TaskResponseMetadata memory taskResponseMetadata = + TaskResponseMetadata(uint32(block.number), hashOfNonSigners); // updating the storage with task response - allTaskResponses[taskResponse.referenceTaskIndex] = keccak256(abi.encode(taskResponse, taskResponseMetadata)); + allTaskResponses[taskResponse.referenceTaskIndex] = + keccak256(abi.encode(taskResponse, taskResponseMetadata)); // emitting event emit TaskResponded(taskResponse, taskResponseMetadata); @@ -170,9 +182,12 @@ contract IncredibleSquaringTaskManager is uint32 referenceTaskIndex = taskResponse.referenceTaskIndex; uint256 numberToBeSquared = task.numberToBeSquared; // some logical checks - require(allTaskResponses[referenceTaskIndex] != bytes32(0), "Task hasn't been responded to yet"); require( - allTaskResponses[referenceTaskIndex] == keccak256(abi.encode(taskResponse, taskResponseMetadata)), + allTaskResponses[referenceTaskIndex] != bytes32(0), "Task hasn't been responded to yet" + ); + require( + allTaskResponses[referenceTaskIndex] + == keccak256(abi.encode(taskResponse, taskResponseMetadata)), "Task response does not match the one recorded in the contract" ); require( @@ -181,12 +196,14 @@ contract IncredibleSquaringTaskManager is ); require( - uint32(block.number) <= taskResponseMetadata.taskRespondedBlock + TASK_CHALLENGE_WINDOW_BLOCK, + uint32(block.number) + <= taskResponseMetadata.taskRespondedBlock + TASK_CHALLENGE_WINDOW_BLOCK, "The challenge period for this task has already expired." ); // logic for checking whether challenge is valid or not - bool isResponseCorrect = ((numberToBeSquared * numberToBeSquared) == taskResponse.numberSquared); + bool isResponseCorrect = + ((numberToBeSquared * numberToBeSquared) == taskResponse.numberSquared); // if response was correct, no slashing happens so we return if (isResponseCorrect == true) { @@ -195,7 +212,8 @@ contract IncredibleSquaringTaskManager is } // get the list of hash of pubkeys of operators who weren't part of the task response submitted by the aggregator - bytes32[] memory hashesOfPubkeysOfNonSigningOperators = new bytes32[](pubkeysOfNonSigningOperators.length); + bytes32[] memory hashesOfPubkeysOfNonSigningOperators = + new bytes32[](pubkeysOfNonSigningOperators.length); for (uint256 i = 0; i < pubkeysOfNonSigningOperators.length; i++) { hashesOfPubkeysOfNonSigningOperators[i] = pubkeysOfNonSigningOperators[i].hashG1Point(); } diff --git a/contracts/test/CredibleSquaringTaskManager.t.sol b/contracts/test/CredibleSquaringTaskManager.t.sol index 1c7be0e5..a1f37529 100644 --- a/contracts/test/CredibleSquaringTaskManager.t.sol +++ b/contracts/test/CredibleSquaringTaskManager.t.sol @@ -4,7 +4,8 @@ pragma solidity ^0.8.12; import "../src/IncredibleSquaringServiceManager.sol" as incsqsm; import {IncredibleSquaringTaskManager} from "../src/IncredibleSquaringTaskManager.sol"; import {BLSMockAVSDeployer} from "@eigenlayer-middleware/test/utils/BLSMockAVSDeployer.sol"; -import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import {TransparentUpgradeableProxy} from + "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; contract IncredibleSquaringTaskManagerTest is BLSMockAVSDeployer { incsqsm.IncredibleSquaringServiceManager sm; @@ -30,7 +31,11 @@ contract IncredibleSquaringTaskManagerTest is BLSMockAVSDeployer { address(tmImplementation), address(proxyAdmin), abi.encodeWithSelector( - tm.initialize.selector, pauserRegistry, registryCoordinatorOwner, aggregator, generator + tm.initialize.selector, + pauserRegistry, + registryCoordinatorOwner, + aggregator, + generator ) ) )