Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidu28 committed Nov 6, 2024
1 parent 934e8ad commit f7a1beb
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 61 deletions.
128 changes: 94 additions & 34 deletions contracts/script/IncredibleSquaringDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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)
);
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -314,28 +364,38 @@ 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",
address(incredibleSquaringTaskManagerImplementation)
);
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");
}
Expand Down
9 changes: 7 additions & 2 deletions contracts/script/utils/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
7 changes: 5 additions & 2 deletions contracts/src/IIncredibleSquaringTaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion contracts/src/IncredibleSquaringServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
58 changes: 38 additions & 20 deletions contracts/src/IncredibleSquaringTaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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(
Expand All @@ -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) {
Expand All @@ -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();
}
Expand Down
Loading

0 comments on commit f7a1beb

Please sign in to comment.