From 2d84e54eecb30f1f46ee29d61157df16cd2bbe6d Mon Sep 17 00:00:00 2001 From: noel Date: Tue, 15 Oct 2024 18:09:56 +0900 Subject: [PATCH] style: format contract codes --- .../script/IncredibleSquaringDeployer.s.sol | 268 +++++------------- contracts/script/utils/Utils.sol | 70 ++--- contracts/src/ERC20Mock.sol | 68 +---- .../src/IIncredibleSquaringTaskManager.sol | 24 +- .../src/IncredibleSquaringServiceManager.sol | 7 +- .../src/IncredibleSquaringTaskManager.sol | 107 +++---- .../test/CredibleSquaringTaskManager.t.sol | 15 +- 7 files changed, 146 insertions(+), 413 deletions(-) diff --git a/contracts/script/IncredibleSquaringDeployer.s.sol b/contracts/script/IncredibleSquaringDeployer.s.sol index e455112c..9271a169 100644 --- a/contracts/script/IncredibleSquaringDeployer.s.sol +++ b/contracts/script/IncredibleSquaringDeployer.s.sol @@ -38,10 +38,8 @@ contract IncredibleSquaringDeployer is Script, Utils { uint32 public constant TASK_RESPONSE_WINDOW_BLOCK = 30; uint32 public constant TASK_DURATION_BLOCKS = 0; // TODO: right now hardcoding these (this address is anvil's default address 9) - address public constant AGGREGATOR_ADDR = - 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720; - address public constant TASK_GENERATOR_ADDR = - 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720; + address public constant AGGREGATOR_ADDR = 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720; + address public constant TASK_GENERATOR_ADDR = 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720; // ERC20 and Strategy: we need to deploy this erc20, create a strategy for it, and whitelist this strategy in the strategymanager @@ -70,60 +68,31 @@ contract IncredibleSquaringDeployer is Script, Utils { IServiceManager public incredibleSquaringServiceManagerImplementation; IncredibleSquaringTaskManager public incredibleSquaringTaskManager; - IIncredibleSquaringTaskManager - public incredibleSquaringTaskManagerImplementation; + IIncredibleSquaringTaskManager public incredibleSquaringTaskManagerImplementation; 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" - ) - ); + 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")); StrategyBaseTVLLimits baseStrategyImplementation = StrategyBaseTVLLimits( - stdJson.readAddress( - eigenlayerDeployedContracts, - ".addresses.baseStrategyImplementation" - ) - ); + stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.baseStrategyImplementation") + ); address credibleSquaringCommunityMultisig = msg.sender; address credibleSquaringPauser = msg.sender; vm.startBroadcast(); _deployErc20AndStrategyAndWhitelistStrategy( - eigenLayerProxyAdmin, - eigenLayerPauserReg, - baseStrategyImplementation, - strategyManager + eigenLayerProxyAdmin, eigenLayerPauserReg, baseStrategyImplementation, strategyManager ); _deployCredibleSquaringContracts( delegationManager, @@ -163,10 +132,7 @@ contract IncredibleSquaringDeployer is Script, Utils { strats[0] = erc20MockStrategy; bool[] memory thirdPartyTransfersForbiddenValues = new bool[](1); thirdPartyTransfersForbiddenValues[0] = false; - strategyManager.addStrategiesToDepositWhitelist( - strats, - thirdPartyTransfersForbiddenValues - ); + strategyManager.addStrategiesToDepositWhitelist(strats, thirdPartyTransfersForbiddenValues); } function _deployCredibleSquaringContracts( @@ -179,7 +145,7 @@ contract IncredibleSquaringDeployer is Script, Utils { // Adding this as a temporary fix to make the rest of the script work with a single strategy // since it was originally written to work with an array of strategies IStrategy[1] memory deployedStrategyArray = [strat]; - uint numStrategies = deployedStrategyArray.length; + uint256 numStrategies = deployedStrategyArray.length; // deploy proxy admin for ability to upgrade proxy contracts incredibleSquaringProxyAdmin = new ProxyAdmin(); @@ -189,10 +155,7 @@ contract IncredibleSquaringDeployer is Script, Utils { address[] memory pausers = new address[](2); pausers[0] = credibleSquaringPauser; pausers[1] = incredibleSquaringCommunityMultisig; - incredibleSquaringPauserReg = new PauserRegistry( - pausers, - incredibleSquaringCommunityMultisig - ); + incredibleSquaringPauserReg = new PauserRegistry(pausers, incredibleSquaringCommunityMultisig); } EmptyContract emptyContract = new EmptyContract(); @@ -204,90 +167,44 @@ contract IncredibleSquaringDeployer is Script, Utils { * 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(); // Second, deploy the *implementation* contracts, using the *proxy contracts* as inputs { - stakeRegistryImplementation = new StakeRegistry( - registryCoordinator, - delegationManager - ); + stakeRegistryImplementation = new StakeRegistry(registryCoordinator, delegationManager); incredibleSquaringProxyAdmin.upgrade( - TransparentUpgradeableProxy(payable(address(stakeRegistry))), - address(stakeRegistryImplementation) + TransparentUpgradeableProxy(payable(address(stakeRegistry))), address(stakeRegistryImplementation) ); - blsApkRegistryImplementation = new BLSApkRegistry( - registryCoordinator - ); + blsApkRegistryImplementation = new BLSApkRegistry(registryCoordinator); incredibleSquaringProxyAdmin.upgrade( - TransparentUpgradeableProxy(payable(address(blsApkRegistry))), - address(blsApkRegistryImplementation) + TransparentUpgradeableProxy(payable(address(blsApkRegistry))), address(blsApkRegistryImplementation) ); - indexRegistryImplementation = new IndexRegistry( - registryCoordinator - ); + indexRegistryImplementation = new IndexRegistry(registryCoordinator); incredibleSquaringProxyAdmin.upgrade( - TransparentUpgradeableProxy(payable(address(indexRegistry))), - address(indexRegistryImplementation) + TransparentUpgradeableProxy(payable(address(indexRegistry))), address(indexRegistryImplementation) ); } @@ -299,49 +216,38 @@ contract IncredibleSquaringDeployer is Script, Utils { ); { - uint numQuorums = 1; + uint256 numQuorums = 1; // for each quorum to setup, we need to define // QuorumOperatorSetParam, minimumStakeForQuorum, and strategyParams - regcoord.IRegistryCoordinator.OperatorSetParam[] - memory quorumsOperatorSetParams = new regcoord.IRegistryCoordinator.OperatorSetParam[]( - numQuorums - ); - for (uint i = 0; i < numQuorums; i++) { + regcoord.IRegistryCoordinator.OperatorSetParam[] memory quorumsOperatorSetParams = + new regcoord.IRegistryCoordinator.OperatorSetParam[](numQuorums); + for (uint256 i = 0; i < numQuorums; i++) { // hard code these for now - quorumsOperatorSetParams[i] = regcoord - .IRegistryCoordinator - .OperatorSetParam({ - maxOperatorCount: 10000, - kickBIPsOfOperatorStake: 15000, - kickBIPsOfTotalStake: 100 - }); + quorumsOperatorSetParams[i] = regcoord.IRegistryCoordinator.OperatorSetParam({ + maxOperatorCount: 10000, + kickBIPsOfOperatorStake: 15000, + kickBIPsOfTotalStake: 100 + }); } // set to 0 for every quorum uint96[] memory quorumsMinimumStake = new uint96[](numQuorums); - IStakeRegistry.StrategyParams[][] - memory quorumsStrategyParams = new IStakeRegistry.StrategyParams[][]( - numQuorums - ); - for (uint i = 0; i < numQuorums; i++) { - quorumsStrategyParams[i] = new IStakeRegistry.StrategyParams[]( - numStrategies - ); - for (uint j = 0; j < numStrategies; j++) { - quorumsStrategyParams[i][j] = IStakeRegistry - .StrategyParams({ - strategy: deployedStrategyArray[j], - // setting this to 1 ether since the divisor is also 1 ether - // therefore this allows an operator to register with even just 1 token - // see https://github.com/Layr-Labs/eigenlayer-middleware/blob/m2-mainnet/src/StakeRegistry.sol#L484 - // weight += uint96(sharesAmount * strategyAndMultiplier.multiplier / WEIGHTING_DIVISOR); - multiplier: 1 ether - }); + IStakeRegistry.StrategyParams[][] memory quorumsStrategyParams = + new IStakeRegistry.StrategyParams[][](numQuorums); + for (uint256 i = 0; i < numQuorums; i++) { + quorumsStrategyParams[i] = new IStakeRegistry.StrategyParams[](numStrategies); + for (uint256 j = 0; j < numStrategies; j++) { + quorumsStrategyParams[i][j] = IStakeRegistry.StrategyParams({ + strategy: deployedStrategyArray[j], + // setting this to 1 ether since the divisor is also 1 ether + // therefore this allows an operator to register with even just 1 token + // see https://github.com/Layr-Labs/eigenlayer-middleware/blob/m2-mainnet/src/StakeRegistry.sol#L484 + // weight += uint96(sharesAmount * strategyAndMultiplier.multiplier / WEIGHTING_DIVISOR); + multiplier: 1 ether + }); } } incredibleSquaringProxyAdmin.upgradeAndCall( - TransparentUpgradeableProxy( - payable(address(registryCoordinator)) - ), + TransparentUpgradeableProxy(payable(address(registryCoordinator))), address(registryCoordinatorImplementation), abi.encodeWithSelector( regcoord.RegistryCoordinator.initialize.selector, @@ -359,29 +265,20 @@ contract IncredibleSquaringDeployer is Script, Utils { } incredibleSquaringServiceManagerImplementation = new IncredibleSquaringServiceManager( - avsDirectory, - registryCoordinator, - stakeRegistry, - incredibleSquaringTaskManager + avsDirectory, registryCoordinator, stakeRegistry, incredibleSquaringTaskManager ); // Third, upgrade the proxy contracts to use the correct implementation contracts and initialize them. incredibleSquaringProxyAdmin.upgrade( - TransparentUpgradeableProxy( - payable(address(incredibleSquaringServiceManager)) - ), + TransparentUpgradeableProxy(payable(address(incredibleSquaringServiceManager))), address(incredibleSquaringServiceManagerImplementation) ); - incredibleSquaringTaskManagerImplementation = new IncredibleSquaringTaskManager( - registryCoordinator, - TASK_RESPONSE_WINDOW_BLOCK - ); + incredibleSquaringTaskManagerImplementation = + new IncredibleSquaringTaskManager(registryCoordinator, TASK_RESPONSE_WINDOW_BLOCK); // Third, upgrade the proxy contracts to use the correct implementation contracts and initialize them. incredibleSquaringProxyAdmin.upgradeAndCall( - TransparentUpgradeableProxy( - payable(address(incredibleSquaringTaskManager)) - ), + TransparentUpgradeableProxy(payable(address(incredibleSquaringTaskManager))), address(incredibleSquaringTaskManagerImplementation), abi.encodeWithSelector( incredibleSquaringTaskManager.initialize.selector, @@ -396,58 +293,31 @@ contract IncredibleSquaringDeployer is Script, Utils { string memory parent_object = "parent object"; string memory deployed_addresses = "addresses"; + vm.serializeAddress(deployed_addresses, "erc20Mock", address(erc20Mock)); + vm.serializeAddress(deployed_addresses, "erc20MockStrategy", address(erc20MockStrategy)); 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", address(incredibleSquaringTaskManagerImplementation) ); + vm.serializeAddress(deployed_addresses, "registryCoordinator", address(registryCoordinator)); vm.serializeAddress( - deployed_addresses, - "registryCoordinator", - address(registryCoordinator) - ); - vm.serializeAddress( - deployed_addresses, - "registryCoordinatorImplementation", - address(registryCoordinatorImplementation) - ); - string memory deployed_addresses_output = vm.serializeAddress( - deployed_addresses, - "operatorStateRetriever", - address(operatorStateRetriever) + deployed_addresses, "registryCoordinatorImplementation", address(registryCoordinatorImplementation) ); + 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 9310c761..6b8f041e 100644 --- a/contracts/script/utils/Utils.sol +++ b/contracts/script/utils/Utils.sol @@ -10,22 +10,14 @@ import "forge-std/StdJson.sol"; contract Utils is Script { // Note that this fct 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]); } } - function convertBoolToString( - bool input - ) public pure returns (string memory) { + function convertBoolToString(bool input) public pure returns (string memory) { if (input) { return "true"; } else { @@ -33,21 +25,16 @@ contract Utils is Script { } } - function convertOperatorStatusToString( - IRegistryCoordinator.OperatorStatus operatorStatus - ) public pure returns (string memory) { - if ( - operatorStatus == - IRegistryCoordinator.OperatorStatus.NEVER_REGISTERED - ) { + function convertOperatorStatusToString(IRegistryCoordinator.OperatorStatus operatorStatus) + public + pure + returns (string memory) + { + if (operatorStatus == IRegistryCoordinator.OperatorStatus.NEVER_REGISTERED) { return "NEVER_REGISTERED"; - } else if ( - operatorStatus == IRegistryCoordinator.OperatorStatus.REGISTERED - ) { + } else if (operatorStatus == IRegistryCoordinator.OperatorStatus.REGISTERED) { return "REGISTERED"; - } else if ( - operatorStatus == IRegistryCoordinator.OperatorStatus.DEREGISTERED - ) { + } else if (operatorStatus == IRegistryCoordinator.OperatorStatus.DEREGISTERED) { return "DEREGISTERED"; } else { return "UNKNOWN"; @@ -55,45 +42,24 @@ contract Utils is Script { } // Forge scripts best practice: https://book.getfoundry.sh/tutorials/best-practices#scripts - function readInput( - string memory inputFileName - ) internal view returns (string memory) { - string memory inputDir = string.concat( - vm.projectRoot(), - "/script/input/" - ); + function readInput(string memory inputFileName) internal view returns (string memory) { + string memory inputDir = string.concat(vm.projectRoot(), "/script/input/"); string memory chainDir = string.concat(vm.toString(block.chainid), "/"); string memory file = string.concat(inputFileName, ".json"); return vm.readFile(string.concat(inputDir, chainDir, file)); } - function readOutput( - string memory outputFileName - ) internal view returns (string memory) { - string memory inputDir = string.concat( - vm.projectRoot(), - "/script/output/" - ); + function readOutput(string memory outputFileName) internal view returns (string memory) { + string memory inputDir = string.concat(vm.projectRoot(), "/script/output/"); string memory chainDir = string.concat(vm.toString(block.chainid), "/"); string memory file = string.concat(outputFileName, ".json"); return vm.readFile(string.concat(inputDir, chainDir, file)); } - function writeOutput( - string memory outputJson, - string memory outputFileName - ) internal { - string memory outputDir = string.concat( - vm.projectRoot(), - "/script/output/" - ); + function writeOutput(string memory outputJson, string memory outputFileName) internal { + string memory outputDir = string.concat(vm.projectRoot(), "/script/output/"); string memory chainDir = string.concat(vm.toString(block.chainid), "/"); - string memory outputFilePath = string.concat( - outputDir, - chainDir, - outputFileName, - ".json" - ); + string memory outputFilePath = string.concat(outputDir, chainDir, outputFileName, ".json"); vm.writeJson(outputJson, outputFilePath); } } diff --git a/contracts/src/ERC20Mock.sol b/contracts/src/ERC20Mock.sol index de379fce..7115c2ae 100644 --- a/contracts/src/ERC20Mock.sol +++ b/contracts/src/ERC20Mock.sol @@ -51,9 +51,7 @@ contract ERC20Mock is Context, IERC20 { /** * @dev See {IERC20-balanceOf}. */ - function balanceOf( - address account - ) public view virtual override returns (uint256) { + function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } @@ -69,10 +67,7 @@ contract ERC20Mock is Context, IERC20 { * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ - function transfer( - address to, - uint256 amount - ) public virtual override returns (bool) { + function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; @@ -81,10 +76,7 @@ contract ERC20Mock is Context, IERC20 { /** * @dev See {IERC20-allowance}. */ - function allowance( - address owner, - address spender - ) public view virtual override returns (uint256) { + function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } @@ -98,10 +90,7 @@ contract ERC20Mock is Context, IERC20 { * * - `spender` cannot be the zero address. */ - function approve( - address /*spender*/, - uint256 /*amount*/ - ) public virtual override returns (bool) { + function approve(address, /*spender*/ uint256 /*amount*/ ) public virtual override returns (bool) { return true; } @@ -121,11 +110,7 @@ contract ERC20Mock is Context, IERC20 { * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ - function transferFrom( - address from, - address to, - uint256 amount - ) public virtual override returns (bool) { + function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) { _transfer(from, to, amount); return true; } @@ -144,20 +129,13 @@ contract ERC20Mock is Context, IERC20 { * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ - function _transfer( - address from, - address to, - uint256 amount - ) internal virtual { + function _transfer(address from, address to, uint256 amount) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); - require( - _balances[from] >= amount, - "ERC20: transfer amount exceeds balance" - ); + require(_balances[from] >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = _balances[from] - amount; // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by @@ -170,7 +148,8 @@ contract ERC20Mock is Context, IERC20 { _afterTokenTransfer(from, to, amount); } - /** @dev Creates `amount` tokens and assigns them to `account`, increasing + /** + * @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. @@ -232,11 +211,7 @@ contract ERC20Mock is Context, IERC20 { * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ - function _approve( - address owner, - address spender, - uint256 amount - ) internal virtual { + function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); @@ -252,17 +227,10 @@ contract ERC20Mock is Context, IERC20 { * * Might emit an {Approval} event. */ - function _spendAllowance( - address owner, - address spender, - uint256 amount - ) internal virtual { + function _spendAllowance(address owner, address spender, uint256 amount) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { - require( - currentAllowance >= amount, - "ERC20: insufficient allowance" - ); + require(currentAllowance >= amount, "ERC20: insufficient allowance"); } } @@ -280,11 +248,7 @@ contract ERC20Mock is Context, IERC20 { * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ - function _beforeTokenTransfer( - address from, - address to, - uint256 amount - ) internal virtual {} + function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes @@ -300,9 +264,5 @@ contract ERC20Mock is Context, IERC20 { * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ - function _afterTokenTransfer( - address from, - address to, - uint256 amount - ) internal virtual {} + function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {} } diff --git a/contracts/src/IIncredibleSquaringTaskManager.sol b/contracts/src/IIncredibleSquaringTaskManager.sol index f57faa36..232dd4f4 100644 --- a/contracts/src/IIncredibleSquaringTaskManager.sol +++ b/contracts/src/IIncredibleSquaringTaskManager.sol @@ -7,25 +7,16 @@ interface IIncredibleSquaringTaskManager { // EVENTS event NewTaskCreated(uint32 indexed taskIndex, Task task); - event TaskResponded( - TaskResponse taskResponse, - TaskResponseMetadata taskResponseMetadata - ); + event TaskResponded(TaskResponse taskResponse, TaskResponseMetadata taskResponseMetadata); event TaskCompleted(uint32 indexed taskIndex); - event TaskChallengedSuccessfully( - uint32 indexed taskIndex, - address indexed challenger - ); + event TaskChallengedSuccessfully(uint32 indexed taskIndex, address indexed challenger); - event TaskChallengedUnsuccessfully( - uint32 indexed taskIndex, - address indexed challenger - ); + event TaskChallengedUnsuccessfully(uint32 indexed taskIndex, address indexed challenger); event AggregatorUpdated(address indexed oldAggregator, address indexed newAggregator); - + event GeneratorUpdated(address indexed oldGenerator, address indexed newGenerator); // STRUCTS @@ -61,11 +52,8 @@ interface IIncredibleSquaringTaskManager { // FUNCTIONS // NOTE: this function creates 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 aaf2bfea..c0877056 100644 --- a/contracts/src/IncredibleSquaringServiceManager.sol +++ b/contracts/src/IncredibleSquaringServiceManager.sol @@ -12,8 +12,7 @@ import "@eigenlayer-middleware/src/ServiceManagerBase.sol"; contract IncredibleSquaringServiceManager is ServiceManagerBase { using BytesLib for bytes; - IIncredibleSquaringTaskManager - public immutable incredibleSquaringTaskManager; + IIncredibleSquaringTaskManager public immutable incredibleSquaringTaskManager; /// @notice when applied to a function, ensures that the function is only callable by the `registryCoordinator`. modifier onlyIncredibleSquaringTaskManager() { @@ -43,9 +42,7 @@ contract IncredibleSquaringServiceManager is ServiceManagerBase { /// @notice Called in the event of challenge resolution, in order to forward a call to the Slasher, which 'freezes' the `operator`. /// @dev The Slasher contract is under active development and its interface expected to change. /// We recommend writing slashing logic without integrating with the Slasher at this point in time. - function freezeOperator( - address operatorAddr - ) external onlyIncredibleSquaringTaskManager { + function freezeOperator(address operatorAddr) external onlyIncredibleSquaringTaskManager { // slasher.freezeOperator(operatorAddr); } } diff --git a/contracts/src/IncredibleSquaringTaskManager.sol b/contracts/src/IncredibleSquaringTaskManager.sol index 85fbefd0..e07f5571 100644 --- a/contracts/src/IncredibleSquaringTaskManager.sol +++ b/contracts/src/IncredibleSquaringTaskManager.sol @@ -46,7 +46,6 @@ contract IncredibleSquaringTaskManager is address public aggregator; address public generator; - modifier onlyAggregator() { require(msg.sender == aggregator, "Aggregator must be the caller"); _; @@ -59,19 +58,16 @@ 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); @@ -88,11 +84,10 @@ 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; @@ -118,8 +113,7 @@ contract IncredibleSquaringTaskManager is // check that the task is valid, hasn't been responsed yet, and is being responsed in time require( - keccak256(abi.encode(task)) == - allTaskHashes[taskResponse.referenceTaskIndex], + keccak256(abi.encode(task)) == allTaskHashes[taskResponse.referenceTaskIndex], "supplied task does not match the one recorded in the contract" ); // some logical checks @@ -128,8 +122,7 @@ contract IncredibleSquaringTaskManager is "Aggregator has already responded to the task" ); require( - uint32(block.number) <= - taskCreatedBlock + TASK_RESPONSE_WINDOW_BLOCK, + uint32(block.number) <= taskCreatedBlock + TASK_RESPONSE_WINDOW_BLOCK, "Aggregator has responded to the task too late" ); @@ -138,37 +131,23 @@ contract IncredibleSquaringTaskManager is bytes32 message = keccak256(abi.encode(taskResponse)); // check the BLS signature - ( - QuorumStakeTotals memory quorumStakeTotals, - bytes32 hashOfNonSigners - ) = checkSignatures( - message, - quorumNumbers, - taskCreatedBlock, - nonSignerStakesAndSignature - ); + (QuorumStakeTotals memory quorumStakeTotals, bytes32 hashOfNonSigners) = + checkSignatures(message, quorumNumbers, taskCreatedBlock, nonSignerStakesAndSignature); // check that signatories own at least a threshold percentage of each quourm - for (uint i = 0; i < quorumNumbers.length; i++) { + for (uint256 i = 0; i < quorumNumbers.length; i++) { // we don't check that the quorumThresholdPercentages are not >100 because a greater value would trivially fail the check, implying // signed stake > total stake require( - quorumStakeTotals.signedStakeForQuorum[i] * - _THRESHOLD_DENOMINATOR >= - quorumStakeTotals.totalStakeForQuorum[i] * - uint8(quorumThresholdPercentage), + quorumStakeTotals.signedStakeForQuorum[i] * _THRESHOLD_DENOMINATOR + >= quorumStakeTotals.totalStakeForQuorum[i] * uint8(quorumThresholdPercentage), "Signatories do not own at least threshold percentage of a quorum" ); } - TaskResponseMetadata memory taskResponseMetadata = TaskResponseMetadata( - uint32(block.number), - hashOfNonSigners - ); + TaskResponseMetadata memory taskResponseMetadata = TaskResponseMetadata(uint32(block.number), hashOfNonSigners); // updating the storage with task responsea - allTaskResponses[taskResponse.referenceTaskIndex] = keccak256( - abi.encode(taskResponse, taskResponseMetadata) - ); + allTaskResponses[taskResponse.referenceTaskIndex] = keccak256(abi.encode(taskResponse, taskResponseMetadata)); // emitting event emit TaskResponded(taskResponse, taskResponseMetadata); @@ -190,13 +169,9 @@ 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] != bytes32(0), - "Task hasn't been responded to yet" - ); - require( - allTaskResponses[referenceTaskIndex] == - keccak256(abi.encode(taskResponse, taskResponseMetadata)), + allTaskResponses[referenceTaskIndex] == keccak256(abi.encode(taskResponse, taskResponseMetadata)), "Task response does not match the one recorded in the contract" ); require( @@ -205,16 +180,13 @@ contract IncredibleSquaringTaskManager is ); require( - uint32(block.number) <= - taskResponseMetadata.taskResponsedBlock + - TASK_CHALLENGE_WINDOW_BLOCK, + uint32(block.number) <= taskResponseMetadata.taskResponsedBlock + TASK_CHALLENGE_WINDOW_BLOCK, "The challenge period for this task has already expired." ); // logic for checking whether challenge is valid or not uint256 actualSquaredOutput = numberToBeSquared * numberToBeSquared; - bool isResponseCorrect = (actualSquaredOutput == - taskResponse.numberSquared); + bool isResponseCorrect = (actualSquaredOutput == taskResponse.numberSquared); // if response was correct, no slashing happens so we return if (isResponseCorrect == true) { @@ -223,13 +195,9 @@ 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 - ); - for (uint i = 0; i < pubkeysOfNonSigningOperators.length; i++) { - hashesOfPubkeysOfNonSigningOperators[ - i - ] = pubkeysOfNonSigningOperators[i].hashG1Point(); + bytes32[] memory hashesOfPubkeysOfNonSigningOperators = new bytes32[](pubkeysOfNonSigningOperators.length); + for (uint256 i = 0; i < pubkeysOfNonSigningOperators.length; i++) { + hashesOfPubkeysOfNonSigningOperators[i] = pubkeysOfNonSigningOperators[i].hashG1Point(); } // verify whether the pubkeys of "claimed" non-signers supplied by challenger are actually non-signers as recorded before @@ -237,25 +205,18 @@ contract IncredibleSquaringTaskManager is // currently inlined, as the MiddlewareUtils.computeSignatoryRecordHash function was removed from BLSSignatureChecker // in this PR: https://github.com/Layr-Labs/eigenlayer-contracts/commit/c836178bf57adaedff37262dff1def18310f3dce#diff-8ab29af002b60fc80e3d6564e37419017c804ae4e788f4c5ff468ce2249b4386L155-L158 // TODO(samlaf): contracts team will add this function back in the BLSSignatureChecker, which we should use to prevent potential bugs from code duplication - bytes32 signatoryRecordHash = keccak256( - abi.encodePacked( - task.taskCreatedBlock, - hashesOfPubkeysOfNonSigningOperators - ) - ); + bytes32 signatoryRecordHash = + keccak256(abi.encodePacked(task.taskCreatedBlock, hashesOfPubkeysOfNonSigningOperators)); require( signatoryRecordHash == taskResponseMetadata.hashOfNonSigners, "The pubkeys of non-signing operators supplied by the challenger are not correct." ); // get the address of operators who didn't sign - address[] memory addresssOfNonSigningOperators = new address[]( - pubkeysOfNonSigningOperators.length - ); - for (uint i = 0; i < pubkeysOfNonSigningOperators.length; i++) { - addresssOfNonSigningOperators[i] = BLSApkRegistry( - address(blsApkRegistry) - ).pubkeyHashToOperator(hashesOfPubkeysOfNonSigningOperators[i]); + address[] memory addresssOfNonSigningOperators = new address[](pubkeysOfNonSigningOperators.length); + for (uint256 i = 0; i < pubkeysOfNonSigningOperators.length; i++) { + addresssOfNonSigningOperators[i] = + BLSApkRegistry(address(blsApkRegistry)).pubkeyHashToOperator(hashesOfPubkeysOfNonSigningOperators[i]); } // @dev the below code is commented out for the upcoming M2 release @@ -337,6 +298,4 @@ contract IncredibleSquaringTaskManager is aggregator = newAggregator; emit AggregatorUpdated(oldAggregator, newAggregator); } - - } diff --git a/contracts/test/CredibleSquaringTaskManager.t.sol b/contracts/test/CredibleSquaringTaskManager.t.sol index 2022adf3..1c7be0e5 100644 --- a/contracts/test/CredibleSquaringTaskManager.t.sol +++ b/contracts/test/CredibleSquaringTaskManager.t.sol @@ -13,17 +13,14 @@ contract IncredibleSquaringTaskManagerTest is BLSMockAVSDeployer { IncredibleSquaringTaskManager tmImplementation; uint32 public constant TASK_RESPONSE_WINDOW_BLOCK = 30; - address aggregator = - address(uint160(uint256(keccak256(abi.encodePacked("aggregator"))))); - address generator = - address(uint160(uint256(keccak256(abi.encodePacked("generator"))))); + address aggregator = address(uint160(uint256(keccak256(abi.encodePacked("aggregator"))))); + address generator = address(uint160(uint256(keccak256(abi.encodePacked("generator"))))); function setUp() public { _setUpBLSMockAVSDeployer(); tmImplementation = new IncredibleSquaringTaskManager( - incsqsm.IRegistryCoordinator(address(registryCoordinator)), - TASK_RESPONSE_WINDOW_BLOCK + incsqsm.IRegistryCoordinator(address(registryCoordinator)), TASK_RESPONSE_WINDOW_BLOCK ); // Third, upgrade the proxy contracts to use the correct implementation contracts and initialize them. @@ -33,11 +30,7 @@ contract IncredibleSquaringTaskManagerTest is BLSMockAVSDeployer { address(tmImplementation), address(proxyAdmin), abi.encodeWithSelector( - tm.initialize.selector, - pauserRegistry, - registryCoordinatorOwner, - aggregator, - generator + tm.initialize.selector, pauserRegistry, registryCoordinatorOwner, aggregator, generator ) ) )