diff --git a/contracts/script/MockRollupDeployer.s.sol b/contracts/script/MockRollupDeployer.s.sol index 011f7bbe6f..63c21482e9 100644 --- a/contracts/script/MockRollupDeployer.s.sol +++ b/contracts/script/MockRollupDeployer.s.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.9; import "forge-std/Script.sol"; -import "../test/rollup/MockRollup.sol"; +import "../test/rollupV1/MockRollup.sol"; import {IEigenDAServiceManager} from "../src/interfaces/IEigenDAServiceManager.sol"; contract MockRollupDeployer is Script { diff --git a/contracts/src/core/EigenDABlobVerifier.sol b/contracts/src/core/EigenDABlobVerifier.sol index d89198e391..1d3f623611 100644 --- a/contracts/src/core/EigenDABlobVerifier.sol +++ b/contracts/src/core/EigenDABlobVerifier.sol @@ -96,7 +96,7 @@ contract EigenDABlobVerifier is IEigenDABlobVerifier { blobVerificationProof, nonSignerStakesAndSignature, getDefaultSecurityThresholdsV2(), - quorumNumbersRequired() + blobVerificationProof.blobCertificate.blobHeader.quorumNumbers ); } @@ -118,7 +118,7 @@ contract EigenDABlobVerifier is IEigenDABlobVerifier { signedBatch, blobVerificationProof, getDefaultSecurityThresholdsV2(), - quorumNumbersRequired() + blobVerificationProof.blobCertificate.blobHeader.quorumNumbers ); } diff --git a/contracts/src/core/EigenDAThresholdRegistryStorage.sol b/contracts/src/core/EigenDAThresholdRegistryStorage.sol index 377fb8a037..076b0f3b7a 100644 --- a/contracts/src/core/EigenDAThresholdRegistryStorage.sol +++ b/contracts/src/core/EigenDAThresholdRegistryStorage.sol @@ -11,17 +11,25 @@ import "../interfaces/IEigenDAStructs.sol"; */ abstract contract EigenDAThresholdRegistryStorage is IEigenDAThresholdRegistry { + /// @notice The adversary threshold percentage for the quorum at position `quorumNumber` bytes public quorumAdversaryThresholdPercentages; + /// @notice The confirmation threshold percentage for the quorum at position `quorumNumber` bytes public quorumConfirmationThresholdPercentages; + /// @notice The set of quorum numbers that are required bytes public quorumNumbersRequired; + /// @notice The next blob version id to be added uint16 public nextBlobVersion; + /// @notice mapping of blob version id to the params of the blob version mapping(uint16 => VersionedBlobParams) public versionedBlobParams; + /// @notice Default security thresholds for quorums SecurityThresholds public defaultSecurityThresholdsV2; + // storage gap for upgradeability + // slither-disable-next-line shadowing-state uint256[44] private __GAP; } \ No newline at end of file diff --git a/contracts/src/payments/PaymentVault.sol b/contracts/src/payments/PaymentVault.sol index 9dae3cd17c..1615bdc7de 100644 --- a/contracts/src/payments/PaymentVault.sol +++ b/contracts/src/payments/PaymentVault.sol @@ -106,8 +106,8 @@ contract PaymentVault is OwnableUpgradeable, PaymentVaultStorage { require(success); } - function withdrawERC20(address _token, uint256 _amount) external onlyOwner { - IERC20(_token).transfer(owner(), _amount); + function withdrawERC20(IERC20 _token, uint256 _amount) external onlyOwner { + _token.transfer(owner(), _amount); } function _checkQuorumSplit(bytes memory _quorumNumbers, bytes memory _quorumSplits) internal pure { diff --git a/contracts/test/MockEigenDADeployer.sol b/contracts/test/MockEigenDADeployer.sol new file mode 100644 index 0000000000..403a24483a --- /dev/null +++ b/contracts/test/MockEigenDADeployer.sol @@ -0,0 +1,279 @@ +// SPDX-License-Identifier: MIT +pragma solidity =0.8.12; + +import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import "../lib/eigenlayer-middleware/test/utils/BLSMockAVSDeployer.sol"; +import {EigenDAHasher} from "../src/libraries/EigenDAHasher.sol"; +import {EigenDAServiceManager, IRewardsCoordinator} from "../src/core/EigenDAServiceManager.sol"; +import {EigenDABlobVerificationUtils} from "../src/libraries/EigenDABlobVerificationUtils.sol"; +import {EigenDAHasher} from "../src/libraries/EigenDAHasher.sol"; +import {EigenDAServiceManager} from "../src/core/EigenDAServiceManager.sol"; +import {IEigenDAServiceManager} from "../src/interfaces/IEigenDAServiceManager.sol"; +import {EigenDABlobVerifier} from "../src/core/EigenDABlobVerifier.sol"; +import {EigenDAThresholdRegistry, IEigenDAThresholdRegistry} from "../src/core/EigenDAThresholdRegistry.sol"; +import {IEigenDABatchMetadataStorage} from "../src/interfaces/IEigenDABatchMetadataStorage.sol"; +import {IEigenDASignatureVerifier} from "../src/interfaces/IEigenDASignatureVerifier.sol"; +import {IRegistryCoordinator} from "../lib/eigenlayer-middleware/src/interfaces/IRegistryCoordinator.sol"; +import {IEigenDARelayRegistry} from "../src/interfaces/IEigenDARelayRegistry.sol"; +import {EigenDARelayRegistry} from "../src/core/EigenDARelayRegistry.sol"; +import {IPaymentVault} from "../src/interfaces/IPaymentVault.sol"; +import {PaymentVault} from "../src/payments/PaymentVault.sol"; +import {IEigenDADisperserRegistry} from "../src/interfaces/IEigenDADisperserRegistry.sol"; +import {EigenDADisperserRegistry} from "../src/core/EigenDADisperserRegistry.sol"; +import "../src/interfaces/IEigenDAStructs.sol"; +import "forge-std/StdStorage.sol"; + +contract MockEigenDADeployer is BLSMockAVSDeployer { + using stdStorage for StdStorage; + using BN254 for BN254.G1Point; + using EigenDAHasher for BatchHeader; + using EigenDAHasher for ReducedBatchHeader; + using EigenDAHasher for BlobHeader; + using EigenDAHasher for BatchMetadata; + + address confirmer = address(uint160(uint256(keccak256(abi.encodePacked("confirmer"))))); + address notConfirmer = address(uint160(uint256(keccak256(abi.encodePacked("notConfirmer"))))); + address rewardsInitiator = address(uint160(uint256(keccak256(abi.encodePacked("rewardsInitiator"))))); + + EigenDAServiceManager eigenDAServiceManager; + EigenDAServiceManager eigenDAServiceManagerImplementation; + EigenDARelayRegistry eigenDARelayRegistry; + EigenDARelayRegistry eigenDARelayRegistryImplementation; + EigenDAThresholdRegistry eigenDAThresholdRegistry; + EigenDAThresholdRegistry eigenDAThresholdRegistryImplementation; + EigenDADisperserRegistry eigenDADisperserRegistry; + EigenDADisperserRegistry eigenDADisperserRegistryImplementation; + PaymentVault paymentVault; + PaymentVault paymentVaultImplementation; + EigenDABlobVerifier eigenDABlobVerifier; + + ERC20 mockToken; + + bytes quorumAdversaryThresholdPercentages = hex"212121"; + bytes quorumConfirmationThresholdPercentages = hex"373737"; + bytes quorumNumbersRequired = hex"0001"; + SecurityThresholds defaultSecurityThresholds = SecurityThresholds(55, 33); + + uint32 defaultReferenceBlockNumber = 100; + uint32 defaultConfirmationBlockNumber = 1000; + uint32 defaultBatchId = 0; + + uint64 minNumSymbols = 1; + uint64 pricePerSymbol = 3; + uint64 priceUpdateCooldown = 6 days; + uint64 globalSymbolsPerPeriod = 2; + uint64 reservationPeriodInterval = 4; + uint64 globalRatePeriodInterval = 5; + + mapping(uint8 => bool) public quorumNumbersUsed; + + function _deployDA() public { + _setUpBLSMockAVSDeployer(); + + eigenDAServiceManager = EigenDAServiceManager( + address( + new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") + ) + ); + + eigenDAThresholdRegistry = EigenDAThresholdRegistry( + address( + new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") + ) + ); + + eigenDARelayRegistry = EigenDARelayRegistry( + address( + new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") + ) + ); + + paymentVault = PaymentVault( + payable( + address( + new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") + ) + ) + ); + + eigenDADisperserRegistry = EigenDADisperserRegistry( + address( + new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") + ) + ); + + eigenDAServiceManagerImplementation = new EigenDAServiceManager( + avsDirectory, + rewardsCoordinator, + registryCoordinator, + stakeRegistry, + eigenDAThresholdRegistry, + eigenDARelayRegistry, + paymentVault, + eigenDADisperserRegistry + ); + + address[] memory confirmers = new address[](1); + confirmers[0] = confirmer; + + cheats.prank(proxyAdminOwner); + proxyAdmin.upgradeAndCall( + TransparentUpgradeableProxy(payable(address(eigenDAServiceManager))), + address(eigenDAServiceManagerImplementation), + abi.encodeWithSelector( + EigenDAServiceManager.initialize.selector, + pauserRegistry, + 0, + registryCoordinatorOwner, + confirmers, + registryCoordinatorOwner + ) + ); + + eigenDAThresholdRegistryImplementation = new EigenDAThresholdRegistry(); + + VersionedBlobParams[] memory versionedBlobParams = new VersionedBlobParams[](1); + versionedBlobParams[0] = VersionedBlobParams({ + maxNumOperators: 3537, + numChunks: 8192, + codingRate: 8 + }); + + cheats.prank(proxyAdminOwner); + proxyAdmin.upgradeAndCall( + TransparentUpgradeableProxy(payable(address(eigenDAThresholdRegistry))), + address(eigenDAThresholdRegistryImplementation), + abi.encodeWithSelector( + EigenDAThresholdRegistry.initialize.selector, + registryCoordinatorOwner, + quorumAdversaryThresholdPercentages, + quorumConfirmationThresholdPercentages, + quorumNumbersRequired, + versionedBlobParams, + defaultSecurityThresholds + ) + ); + + eigenDARelayRegistryImplementation = new EigenDARelayRegistry(); + + cheats.prank(proxyAdminOwner); + proxyAdmin.upgradeAndCall( + TransparentUpgradeableProxy(payable(address(eigenDARelayRegistry))), + address(eigenDARelayRegistryImplementation), + abi.encodeWithSelector(EigenDARelayRegistry.initialize.selector, registryCoordinatorOwner) + ); + + eigenDADisperserRegistryImplementation = new EigenDADisperserRegistry(); + + cheats.prank(proxyAdminOwner); + proxyAdmin.upgradeAndCall( + TransparentUpgradeableProxy(payable(address(eigenDADisperserRegistry))), + address(eigenDADisperserRegistryImplementation), + abi.encodeWithSelector(EigenDADisperserRegistry.initialize.selector, registryCoordinatorOwner) + ); + + paymentVaultImplementation = PaymentVault(payable(address(new PaymentVault()))); + + paymentVault = PaymentVault( + payable( + address( + new TransparentUpgradeableProxy( + address(paymentVaultImplementation), + address(proxyAdmin), + abi.encodeWithSelector( + PaymentVault.initialize.selector, + registryCoordinatorOwner, + minNumSymbols, + pricePerSymbol, + priceUpdateCooldown, + globalSymbolsPerPeriod, + reservationPeriodInterval, + globalRatePeriodInterval + ) + ) + ) + ) + ); + + mockToken = new ERC20("Mock Token", "MOCK"); + + eigenDABlobVerifier = new EigenDABlobVerifier( + IEigenDAThresholdRegistry(address(eigenDAThresholdRegistry)), + IEigenDABatchMetadataStorage(address(eigenDAServiceManager)), + IEigenDASignatureVerifier(address(eigenDAServiceManager)), + IEigenDARelayRegistry(address(eigenDARelayRegistry)), + OperatorStateRetriever(address(operatorStateRetriever)), + IRegistryCoordinator(address(registryCoordinator)) + ); + } + + function _getHeaderandNonSigners(uint256 _nonSigners, uint256 _pseudoRandomNumber, uint8 _threshold) internal returns (BatchHeader memory, BLSSignatureChecker.NonSignerStakesAndSignature memory) { + // register a bunch of operators + uint256 quorumBitmap = 1; + bytes memory quorumNumbers = BitmapUtils.bitmapToBytesArray(quorumBitmap); + + // 0 nonSigners + (uint32 referenceBlockNumber, BLSSignatureChecker.NonSignerStakesAndSignature memory nonSignerStakesAndSignature) = + _registerSignatoriesAndGetNonSignerStakeAndSignatureRandom(_pseudoRandomNumber, _nonSigners, quorumBitmap); + + // get a random batch header + BatchHeader memory batchHeader = _getRandomBatchHeader(_pseudoRandomNumber, quorumNumbers, referenceBlockNumber, _threshold); + + // set batch specific signature + bytes32 reducedBatchHeaderHash = batchHeader.hashBatchHeaderToReducedBatchHeader(); + nonSignerStakesAndSignature.sigma = BN254.hashToG1(reducedBatchHeaderHash).scalar_mul(aggSignerPrivKey); + + return (batchHeader, nonSignerStakesAndSignature); + } + + function _getRandomBatchHeader(uint256 pseudoRandomNumber, bytes memory quorumNumbers, uint32 referenceBlockNumber, uint8 threshold) internal pure returns(BatchHeader memory) { + BatchHeader memory batchHeader; + batchHeader.blobHeadersRoot = keccak256(abi.encodePacked("blobHeadersRoot", pseudoRandomNumber)); + batchHeader.quorumNumbers = quorumNumbers; + batchHeader.signedStakeForQuorums = new bytes(quorumNumbers.length); + for (uint256 i = 0; i < quorumNumbers.length; i++) { + batchHeader.signedStakeForQuorums[i] = bytes1(threshold); + } + batchHeader.referenceBlockNumber = referenceBlockNumber; + return batchHeader; + } + + function _generateRandomBlobHeader(uint256 pseudoRandomNumber, uint256 numQuorumsBlobParams) internal returns (BlobHeader memory) { + if(pseudoRandomNumber == 0) { + pseudoRandomNumber = 1; + } + + BlobHeader memory blobHeader; + blobHeader.commitment.X = uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.commitment.X"))) % BN254.FP_MODULUS; + blobHeader.commitment.Y = uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.commitment.Y"))) % BN254.FP_MODULUS; + + blobHeader.dataLength = uint32(uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.dataLength")))); + + blobHeader.quorumBlobParams = new QuorumBlobParam[](numQuorumsBlobParams); + blobHeader.dataLength = uint32(uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.dataLength")))); + for (uint i = 0; i < numQuorumsBlobParams; i++) { + if(i < 2){ + blobHeader.quorumBlobParams[i].quorumNumber = uint8(i); + } else { + blobHeader.quorumBlobParams[i].quorumNumber = uint8(uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.quorumBlobParams[i].quorumNumber", i)))) % 192; + + // make sure it isn't already used + while(quorumNumbersUsed[blobHeader.quorumBlobParams[i].quorumNumber]) { + blobHeader.quorumBlobParams[i].quorumNumber = uint8(uint256(blobHeader.quorumBlobParams[i].quorumNumber) + 1) % 192; + } + quorumNumbersUsed[blobHeader.quorumBlobParams[i].quorumNumber] = true; + } + + blobHeader.quorumBlobParams[i].adversaryThresholdPercentage = eigenDABlobVerifier.getQuorumAdversaryThresholdPercentage(blobHeader.quorumBlobParams[i].quorumNumber); + blobHeader.quorumBlobParams[i].chunkLength = uint32(uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.quorumBlobParams[i].chunkLength", i)))); + blobHeader.quorumBlobParams[i].confirmationThresholdPercentage = eigenDABlobVerifier.getQuorumConfirmationThresholdPercentage(blobHeader.quorumBlobParams[i].quorumNumber); + } + // mark all quorum numbers as unused + for (uint i = 0; i < numQuorumsBlobParams; i++) { + quorumNumbersUsed[blobHeader.quorumBlobParams[i].quorumNumber] = false; + } + + return blobHeader; + } +} diff --git a/contracts/test/rollup/EigenDARollupUtils.sol b/contracts/test/rollupV1/EigenDARollupUtils.sol similarity index 100% rename from contracts/test/rollup/EigenDARollupUtils.sol rename to contracts/test/rollupV1/EigenDARollupUtils.sol diff --git a/contracts/test/rollup/MockRollup.sol b/contracts/test/rollupV1/MockRollup.sol similarity index 100% rename from contracts/test/rollup/MockRollup.sol rename to contracts/test/rollupV1/MockRollup.sol diff --git a/contracts/test/rollup/MockRollup.t.sol b/contracts/test/rollupV1/MockRollup.t.sol similarity index 54% rename from contracts/test/rollup/MockRollup.t.sol rename to contracts/test/rollupV1/MockRollup.t.sol index 8f9a24d7f9..2cf29b1d4e 100644 --- a/contracts/test/rollup/MockRollup.t.sol +++ b/contracts/test/rollupV1/MockRollup.t.sol @@ -2,56 +2,16 @@ pragma solidity ^0.8.9; -import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; - -import {BLSMockAVSDeployer} from "../../lib/eigenlayer-middleware/test/utils/BLSMockAVSDeployer.sol"; import {MockRollup} from "./MockRollup.sol"; -import {EigenDAHasher} from "../../src/libraries/EigenDAHasher.sol"; -import {EigenDAServiceManager, IRewardsCoordinator} from "../../src/core/EigenDAServiceManager.sol"; -import {IEigenDAServiceManager} from "../../src/interfaces/IEigenDAServiceManager.sol"; -import {EigenDABlobVerificationUtils} from "../../src/libraries/EigenDABlobVerificationUtils.sol"; -import {BN254} from "eigenlayer-middleware/libraries/BN254.sol"; -import {EigenDABlobVerifier} from "../../src/core/EigenDABlobVerifier.sol"; -import {EigenDAThresholdRegistry, IEigenDAThresholdRegistry} from "../../src/core/EigenDAThresholdRegistry.sol"; -import {IEigenDABatchMetadataStorage} from "../../src/interfaces/IEigenDABatchMetadataStorage.sol"; -import {IEigenDASignatureVerifier} from "../../src/interfaces/IEigenDASignatureVerifier.sol"; -import {OperatorStateRetriever} from "../../lib/eigenlayer-middleware/src/OperatorStateRetriever.sol"; -import {IEigenDARelayRegistry} from "../../src/interfaces/IEigenDARelayRegistry.sol"; -import {IPaymentVault} from "../../src/interfaces/IPaymentVault.sol"; -import {EigenDARelayRegistry} from "../../src/core/EigenDARelayRegistry.sol"; -import {IRegistryCoordinator} from "../../lib/eigenlayer-middleware/src/interfaces/IRegistryCoordinator.sol"; -import {IEigenDADisperserRegistry} from "../../src/interfaces/IEigenDADisperserRegistry.sol"; -import "../../src/interfaces/IEigenDAStructs.sol"; -import "forge-std/StdStorage.sol"; +import "../MockEigenDADeployer.sol"; -contract MockRollupTest is BLSMockAVSDeployer { - using stdStorage for StdStorage; +contract MockRollupTest is MockEigenDADeployer { using BN254 for BN254.G1Point; using EigenDAHasher for BatchHeader; using EigenDAHasher for ReducedBatchHeader; using EigenDAHasher for BlobHeader; using EigenDAHasher for BatchMetadata; - - EigenDAServiceManager eigenDAServiceManager; - EigenDAServiceManager eigenDAServiceManagerImplementation; - EigenDABlobVerifier eigenDABlobVerifier; - EigenDARelayRegistry eigenDARelayRegistry; - EigenDARelayRegistry eigenDARelayRegistryImplementation; - - EigenDAThresholdRegistry eigenDAThresholdRegistry; - EigenDAThresholdRegistry eigenDAThresholdRegistryImplementation; - bytes quorumAdversaryThresholdPercentages = hex"212121"; - bytes quorumConfirmationThresholdPercentages = hex"373737"; - bytes quorumNumbersRequired = hex"0001"; - SecurityThresholds defaultSecurityThresholds = SecurityThresholds(33, 55); - - uint8 defaultCodingRatioPercentage = 10; - uint32 defaultReferenceBlockNumber = 100; - uint32 defaultConfirmationBlockNumber = 1000; - uint32 defaultBatchId = 0; - uint256 defaultStakeRequired = 1 ether; - - mapping(uint8 => bool) public quorumNumbersUsed; + using stdStorage for StdStorage; address alice = address(0x101); address bob = address(0x202); @@ -70,91 +30,8 @@ contract MockRollupTest is BLSMockAVSDeployer { BN254.G2Point illegalProof; function setUp() public { - _setUpBLSMockAVSDeployer(); - - eigenDAServiceManager = EigenDAServiceManager( - address( - new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") - ) - ); - - eigenDARelayRegistry = EigenDARelayRegistry( - address( - new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") - ) - ); - - eigenDAThresholdRegistry = EigenDAThresholdRegistry( - address( - new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") - ) - ); - - eigenDAServiceManagerImplementation = new EigenDAServiceManager( - avsDirectory, - rewardsCoordinator, - registryCoordinator, - stakeRegistry, - eigenDAThresholdRegistry, - eigenDARelayRegistry, - IPaymentVault(address(0)), - IEigenDADisperserRegistry(address(0)) - ); - - eigenDAThresholdRegistryImplementation = new EigenDAThresholdRegistry(); - - VersionedBlobParams[] memory versionedBlobParams = new VersionedBlobParams[](0); - - cheats.prank(proxyAdminOwner); - proxyAdmin.upgradeAndCall( - TransparentUpgradeableProxy(payable(address(eigenDAThresholdRegistry))), - address(eigenDAThresholdRegistryImplementation), - abi.encodeWithSelector( - EigenDAThresholdRegistry.initialize.selector, - registryCoordinatorOwner, - quorumAdversaryThresholdPercentages, - quorumConfirmationThresholdPercentages, - quorumNumbersRequired, - versionedBlobParams, - defaultSecurityThresholds - ) - ); - - address[] memory confirmers = new address[](1); - confirmers[0] = registryCoordinatorOwner; - - cheats.prank(proxyAdminOwner); - proxyAdmin.upgradeAndCall( - TransparentUpgradeableProxy(payable(address(eigenDAServiceManager))), - address(eigenDAServiceManagerImplementation), - abi.encodeWithSelector( - EigenDAServiceManager.initialize.selector, - pauserRegistry, - 0, - registryCoordinatorOwner, - confirmers, - registryCoordinatorOwner - ) - ); - - eigenDABlobVerifier = new EigenDABlobVerifier( - IEigenDAThresholdRegistry(address(eigenDAThresholdRegistry)), - IEigenDABatchMetadataStorage(address(eigenDAServiceManager)), - IEigenDASignatureVerifier(address(eigenDAServiceManager)), - IEigenDARelayRegistry(address(eigenDARelayRegistry)), - OperatorStateRetriever(address(operatorStateRetriever)), - IRegistryCoordinator(address(registryCoordinator)) - ); - - eigenDARelayRegistryImplementation = new EigenDARelayRegistry(); - - cheats.prank(proxyAdminOwner); - proxyAdmin.upgradeAndCall( - TransparentUpgradeableProxy(payable(address(eigenDARelayRegistry))), - address(eigenDARelayRegistryImplementation), - abi.encodeWithSelector(EigenDARelayRegistry.initialize.selector, registryCoordinatorOwner) - ); - + _deployDA(); + mockRollup = new MockRollup(IEigenDAServiceManager(address(eigenDAServiceManager)), s1); //hardcode g2 proof diff --git a/contracts/test/go/rollup.go b/contracts/test/rollupV1/rollup_proof.go similarity index 100% rename from contracts/test/go/rollup.go rename to contracts/test/rollupV1/rollup_proof.go diff --git a/contracts/test/unit/EigenDABlobUtils.t.sol b/contracts/test/unit/EigenDABlobUtilsV1Unit.t.sol similarity index 66% rename from contracts/test/unit/EigenDABlobUtils.t.sol rename to contracts/test/unit/EigenDABlobUtilsV1Unit.t.sol index 25f5c032b3..8f740b5ee8 100644 --- a/contracts/test/unit/EigenDABlobUtils.t.sol +++ b/contracts/test/unit/EigenDABlobUtilsV1Unit.t.sol @@ -1,145 +1,18 @@ // SPDX-License-Identifier: MIT pragma solidity =0.8.12; -import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; - -import "../../lib/eigenlayer-middleware/test/utils/BLSMockAVSDeployer.sol"; -import {EigenDAHasher} from "../../src/libraries/EigenDAHasher.sol"; -import {EigenDAServiceManager, IRewardsCoordinator} from "../../src/core/EigenDAServiceManager.sol"; -import {EigenDABlobVerificationUtils} from "../../src/libraries/EigenDABlobVerificationUtils.sol"; -import {EigenDAHasher} from "../../src/libraries/EigenDAHasher.sol"; -import {EigenDAServiceManager} from "../../src/core/EigenDAServiceManager.sol"; -import {IEigenDAServiceManager} from "../../src/interfaces/IEigenDAServiceManager.sol"; -import {EigenDABlobVerifier} from "../../src/core/EigenDABlobVerifier.sol"; -import {EigenDAThresholdRegistry, IEigenDAThresholdRegistry} from "../../src/core/EigenDAThresholdRegistry.sol"; -import {IEigenDABatchMetadataStorage} from "../../src/interfaces/IEigenDABatchMetadataStorage.sol"; -import {IEigenDASignatureVerifier} from "../../src/interfaces/IEigenDASignatureVerifier.sol"; -import {IRegistryCoordinator} from "../../lib/eigenlayer-middleware/src/interfaces/IRegistryCoordinator.sol"; -import {IEigenDARelayRegistry} from "../../src/interfaces/IEigenDARelayRegistry.sol"; -import {EigenDARelayRegistry} from "../../src/core/EigenDARelayRegistry.sol"; -import {IPaymentVault} from "../../src/interfaces/IPaymentVault.sol"; -import {PaymentVault} from "../../src/payments/PaymentVault.sol"; -import {IEigenDADisperserRegistry} from "../../src/interfaces/IEigenDADisperserRegistry.sol"; - -import "../../src/interfaces/IEigenDAStructs.sol"; -import "forge-std/StdStorage.sol"; - -contract EigenDABlobUtilsUnit is BLSMockAVSDeployer { - using stdStorage for StdStorage; +import "../MockEigenDADeployer.sol"; +contract EigenDABlobUtilsV1Unit is MockEigenDADeployer { + using stdStorage for StdStorage; using BN254 for BN254.G1Point; using EigenDAHasher for BatchHeader; using EigenDAHasher for ReducedBatchHeader; using EigenDAHasher for BlobHeader; using EigenDAHasher for BatchMetadata; - address confirmer = address(uint160(uint256(keccak256(abi.encodePacked("confirmer"))))); - address notConfirmer = address(uint160(uint256(keccak256(abi.encodePacked("notConfirmer"))))); - address rewardsInitiator = address(uint160(uint256(keccak256(abi.encodePacked("rewardsInitiator"))))); - - EigenDAServiceManager eigenDAServiceManager; - EigenDAServiceManager eigenDAServiceManagerImplementation; - EigenDABlobVerifier eigenDABlobVerifier; - EigenDARelayRegistry eigenDARelayRegistry; - EigenDARelayRegistry eigenDARelayRegistryImplementation; - EigenDAThresholdRegistry eigenDAThresholdRegistry; - EigenDAThresholdRegistry eigenDAThresholdRegistryImplementation; - bytes quorumAdversaryThresholdPercentages = hex"212121"; - bytes quorumConfirmationThresholdPercentages = hex"373737"; - bytes quorumNumbersRequired = hex"0001"; - SecurityThresholds defaultSecurityThresholds = SecurityThresholds(33, 55); - - uint32 defaultReferenceBlockNumber = 100; - uint32 defaultConfirmationBlockNumber = 1000; - uint32 defaultBatchId = 0; - - mapping(uint8 => bool) public quorumNumbersUsed; - function setUp() virtual public { - _setUpBLSMockAVSDeployer(); - - eigenDAServiceManager = EigenDAServiceManager( - address( - new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") - ) - ); - - eigenDAThresholdRegistry = EigenDAThresholdRegistry( - address( - new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") - ) - ); - - eigenDARelayRegistry = EigenDARelayRegistry( - address( - new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") - ) - ); - - eigenDAServiceManagerImplementation = new EigenDAServiceManager( - avsDirectory, - rewardsCoordinator, - registryCoordinator, - stakeRegistry, - eigenDAThresholdRegistry, - eigenDARelayRegistry, - IPaymentVault(address(0)), - IEigenDADisperserRegistry(address(0)) - ); - - eigenDAThresholdRegistryImplementation = new EigenDAThresholdRegistry(); - - address[] memory confirmers = new address[](1); - confirmers[0] = registryCoordinatorOwner; - - cheats.prank(proxyAdminOwner); - proxyAdmin.upgradeAndCall( - TransparentUpgradeableProxy(payable(address(eigenDAServiceManager))), - address(eigenDAServiceManagerImplementation), - abi.encodeWithSelector( - EigenDAServiceManager.initialize.selector, - pauserRegistry, - 0, - registryCoordinatorOwner, - confirmers, - registryCoordinatorOwner - ) - ); - - VersionedBlobParams[] memory versionedBlobParams = new VersionedBlobParams[](0); - - cheats.prank(proxyAdminOwner); - proxyAdmin.upgradeAndCall( - TransparentUpgradeableProxy(payable(address(eigenDAThresholdRegistry))), - address(eigenDAThresholdRegistryImplementation), - abi.encodeWithSelector( - EigenDAThresholdRegistry.initialize.selector, - registryCoordinatorOwner, - quorumAdversaryThresholdPercentages, - quorumConfirmationThresholdPercentages, - quorumNumbersRequired, - versionedBlobParams, - defaultSecurityThresholds - ) - ); - - eigenDABlobVerifier = new EigenDABlobVerifier( - IEigenDAThresholdRegistry(address(eigenDAThresholdRegistry)), - IEigenDABatchMetadataStorage(address(eigenDAServiceManager)), - IEigenDASignatureVerifier(address(eigenDAServiceManager)), - IEigenDARelayRegistry(address(eigenDARelayRegistry)), - OperatorStateRetriever(address(operatorStateRetriever)), - IRegistryCoordinator(address(registryCoordinator)) - ); - - eigenDARelayRegistryImplementation = new EigenDARelayRegistry(); - - cheats.prank(proxyAdminOwner); - proxyAdmin.upgradeAndCall( - TransparentUpgradeableProxy(payable(address(eigenDARelayRegistry))), - address(eigenDARelayRegistryImplementation), - abi.encodeWithSelector(EigenDARelayRegistry.initialize.selector, registryCoordinatorOwner) - ); + _deployDA(); } function testVerifyBlob_TwoQuorums(uint256 pseudoRandomNumber) public { @@ -415,45 +288,5 @@ contract EigenDABlobUtilsUnit is BLSMockAVSDeployer { require(eigenDABlobVerifier.getIsQuorumRequired(0) == true, "getIsQuorumRequired failed"); require(eigenDABlobVerifier.getIsQuorumRequired(1) == true, "getIsQuorumRequired failed"); require(eigenDABlobVerifier.getIsQuorumRequired(2) == false, "getIsQuorumRequired failed"); - } - - // generates a random blob header with the given coding ratio percentage as the ratio of original data to encoded data - function _generateRandomBlobHeader(uint256 pseudoRandomNumber, uint256 numQuorumsBlobParams) internal returns (BlobHeader memory) { - if(pseudoRandomNumber == 0) { - pseudoRandomNumber = 1; - } - - BlobHeader memory blobHeader; - blobHeader.commitment.X = uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.commitment.X"))) % BN254.FP_MODULUS; - blobHeader.commitment.Y = uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.commitment.Y"))) % BN254.FP_MODULUS; - - blobHeader.dataLength = uint32(uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.dataLength")))); - - blobHeader.quorumBlobParams = new QuorumBlobParam[](numQuorumsBlobParams); - blobHeader.dataLength = uint32(uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.dataLength")))); - for (uint i = 0; i < numQuorumsBlobParams; i++) { - if(i < 2){ - blobHeader.quorumBlobParams[i].quorumNumber = uint8(i); - } else { - blobHeader.quorumBlobParams[i].quorumNumber = uint8(uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.quorumBlobParams[i].quorumNumber", i)))) % 192; - - // make sure it isn't already used - while(quorumNumbersUsed[blobHeader.quorumBlobParams[i].quorumNumber]) { - blobHeader.quorumBlobParams[i].quorumNumber = uint8(uint256(blobHeader.quorumBlobParams[i].quorumNumber) + 1) % 192; - } - quorumNumbersUsed[blobHeader.quorumBlobParams[i].quorumNumber] = true; - } - - blobHeader.quorumBlobParams[i].adversaryThresholdPercentage = eigenDABlobVerifier.getQuorumAdversaryThresholdPercentage(blobHeader.quorumBlobParams[i].quorumNumber); - blobHeader.quorumBlobParams[i].chunkLength = uint32(uint256(keccak256(abi.encodePacked(pseudoRandomNumber, "blobHeader.quorumBlobParams[i].chunkLength", i)))); - blobHeader.quorumBlobParams[i].confirmationThresholdPercentage = eigenDABlobVerifier.getQuorumConfirmationThresholdPercentage(blobHeader.quorumBlobParams[i].quorumNumber); - } - // mark all quorum numbers as unused - for (uint i = 0; i < numQuorumsBlobParams; i++) { - quorumNumbersUsed[blobHeader.quorumBlobParams[i].quorumNumber] = false; - } - - return blobHeader; - } - + } } \ No newline at end of file diff --git a/contracts/test/unit/EigenDABlobVerifierV2Unit.t.sol b/contracts/test/unit/EigenDABlobVerifierV2Unit.t.sol new file mode 100644 index 0000000000..510ddbe2e5 --- /dev/null +++ b/contracts/test/unit/EigenDABlobVerifierV2Unit.t.sol @@ -0,0 +1,198 @@ +// SPDX-License-Identifier: MIT +pragma solidity =0.8.12; + +import "../MockEigenDADeployer.sol"; + +contract EigenDABlobVerifierV2Unit is MockEigenDADeployer { + using stdStorage for StdStorage; + using BN254 for BN254.G1Point; + + address relay0 = address(uint160(uint256(keccak256(abi.encodePacked("relay0"))))); + address relay1 = address(uint160(uint256(keccak256(abi.encodePacked("relay1"))))); + + function setUp() virtual public { + _deployDA(); + } + + function test_verifyBlobV2(uint256 pseudoRandomNumber) public { + ( + SignedBatch memory signedBatch, + BlobVerificationProofV2 memory blobVerificationProof, + BLSSignatureChecker.NonSignerStakesAndSignature memory nssas + ) = _getSignedBatchAndBlobVerificationProof(pseudoRandomNumber, 0); + + NonSignerStakesAndSignature memory nonSignerStakesAndSignature; + nonSignerStakesAndSignature.nonSignerQuorumBitmapIndices = nssas.nonSignerQuorumBitmapIndices; + nonSignerStakesAndSignature.nonSignerPubkeys = nssas.nonSignerPubkeys; + nonSignerStakesAndSignature.quorumApks = nssas.quorumApks; + nonSignerStakesAndSignature.apkG2 = nssas.apkG2; + nonSignerStakesAndSignature.sigma = nssas.sigma; + nonSignerStakesAndSignature.quorumApkIndices = nssas.quorumApkIndices; + nonSignerStakesAndSignature.totalStakeIndices = nssas.totalStakeIndices; + nonSignerStakesAndSignature.nonSignerStakeIndices = nssas.nonSignerStakeIndices; + + _registerRelayKeys(); + + eigenDABlobVerifier.verifyBlobV2FromSignedBatch(signedBatch, blobVerificationProof); + + eigenDABlobVerifier.verifyBlobV2(signedBatch.batchHeader, blobVerificationProof, nonSignerStakesAndSignature); + + NonSignerStakesAndSignature memory _nonSignerStakesAndSignature = eigenDABlobVerifier.getNonSignerStakesAndSignature(signedBatch); + eigenDABlobVerifier.verifyBlobV2(signedBatch.batchHeader, blobVerificationProof, _nonSignerStakesAndSignature); + } + + function test_verifyBlobV2_revert_RelayKeysNotSet(uint256 pseudoRandomNumber) public { + ( + SignedBatch memory signedBatch, + BlobVerificationProofV2 memory blobVerificationProof, + BLSSignatureChecker.NonSignerStakesAndSignature memory nssas + ) = _getSignedBatchAndBlobVerificationProof(pseudoRandomNumber, 0); + + vm.expectRevert("EigenDABlobVerificationUtils._verifyRelayKeysSet: relay key is not set"); + eigenDABlobVerifier.verifyBlobV2FromSignedBatch(signedBatch, blobVerificationProof); + } + + function test_verifyBlobV2_revert_InclusionProofInvalid(uint256 pseudoRandomNumber) public { + ( + SignedBatch memory signedBatch, + BlobVerificationProofV2 memory blobVerificationProof, + BLSSignatureChecker.NonSignerStakesAndSignature memory nssas + ) = _getSignedBatchAndBlobVerificationProof(pseudoRandomNumber, 0); + + blobVerificationProof.inclusionProof = abi.encodePacked(keccak256(abi.encode(pseudoRandomNumber, "inclusion proof"))); + + vm.expectRevert("EigenDABlobVerificationUtils._verifyBlobV2ForQuorums: inclusion proof is invalid"); + eigenDABlobVerifier.verifyBlobV2FromSignedBatch(signedBatch, blobVerificationProof); + } + + function test_verifyBlobV2_revert_BadVersion(uint256 pseudoRandomNumber) public { + ( + SignedBatch memory signedBatch, + BlobVerificationProofV2 memory blobVerificationProof, + BLSSignatureChecker.NonSignerStakesAndSignature memory nssas + ) = _getSignedBatchAndBlobVerificationProof(pseudoRandomNumber, 1); + + _registerRelayKeys(); + + vm.expectRevert(); + eigenDABlobVerifier.verifyBlobV2FromSignedBatch(signedBatch, blobVerificationProof); + } + + function test_verifyBlobV2_revert_BadSecurityParams(uint256 pseudoRandomNumber) public { + ( + SignedBatch memory signedBatch, + BlobVerificationProofV2 memory blobVerificationProof, + BLSSignatureChecker.NonSignerStakesAndSignature memory nssas + ) = _getSignedBatchAndBlobVerificationProof(pseudoRandomNumber, 0); + + vm.prank(registryCoordinatorOwner); + eigenDAThresholdRegistry.updateDefaultSecurityThresholdsV2(SecurityThresholds({ + confirmationThreshold: 33, + adversaryThreshold: 55 + })); + + _registerRelayKeys(); + + vm.expectRevert("EigenDABlobVerificationUtils._verifyBlobSecurityParams: confirmationThreshold must be greater than adversaryThreshold"); + eigenDABlobVerifier.verifyBlobV2FromSignedBatch(signedBatch, blobVerificationProof); + } + + function test_verifyBlobSecurityParams() public { + VersionedBlobParams memory blobParams = eigenDAThresholdRegistry.getBlobParams(0); + SecurityThresholds memory securityThresholds = eigenDAThresholdRegistry.getDefaultSecurityThresholdsV2(); + eigenDABlobVerifier.verifyBlobSecurityParams(blobParams, securityThresholds); + eigenDABlobVerifier.verifyBlobSecurityParams(0, securityThresholds); + } + + function _getSignedBatchAndBlobVerificationProof(uint256 pseudoRandomNumber, uint8 version) internal returns (SignedBatch memory, BlobVerificationProofV2 memory, BLSSignatureChecker.NonSignerStakesAndSignature memory) { + BlobHeaderV2 memory blobHeader1 = _getRandomBlobHeaderV2(pseudoRandomNumber, version); + BlobHeaderV2 memory blobHeader2 = _getRandomBlobHeaderV2(pseudoRandomNumber, version); + + uint32[] memory relayKeys = new uint32[](2); + relayKeys[0] = 0; + relayKeys[1] = 1; + + BlobCertificate memory blobCertificate1 = BlobCertificate({ + blobHeader: blobHeader1, + relayKeys: relayKeys + }); + + BlobCertificate memory blobCertificate2 = BlobCertificate({ + blobHeader: blobHeader2, + relayKeys: relayKeys + }); + + bytes32 batchRoot = keccak256(abi.encode( + keccak256(abi.encode(EigenDAHasher.hashBlobCertificate(blobCertificate1))), + keccak256(abi.encode(EigenDAHasher.hashBlobCertificate(blobCertificate2))) + )); + + BlobVerificationProofV2 memory blobVerificationProof = BlobVerificationProofV2({ + blobCertificate: blobCertificate1, + blobIndex: 0, + inclusionProof: abi.encodePacked(keccak256(abi.encode(EigenDAHasher.hashBlobCertificate(blobCertificate2)))) + }); + + (uint32 referenceBlockNumber, BLSSignatureChecker.NonSignerStakesAndSignature memory nonSignerStakesAndSignature) = + _registerSignatoriesAndGetNonSignerStakeAndSignatureRandom(pseudoRandomNumber, 0, 1); + + BatchHeaderV2 memory batchHeader = BatchHeaderV2({ + batchRoot: batchRoot, + referenceBlockNumber: referenceBlockNumber + }); + + nonSignerStakesAndSignature.sigma = BN254.hashToG1(keccak256(abi.encode(batchHeader))).scalar_mul(aggSignerPrivKey); + + uint32[] memory quorumNumbers = new uint32[](1); + quorumNumbers[0] = 0; + + Attestation memory attestation = Attestation({ + nonSignerPubkeys: nonSignerStakesAndSignature.nonSignerPubkeys, + quorumApks: nonSignerStakesAndSignature.quorumApks, + sigma: nonSignerStakesAndSignature.sigma, + apkG2: nonSignerStakesAndSignature.apkG2, + quorumNumbers: quorumNumbers + }); + + SignedBatch memory signedBatch = SignedBatch({ + batchHeader: batchHeader, + attestation: attestation + }); + + return (signedBatch, blobVerificationProof, nonSignerStakesAndSignature); + } + + function _getRandomBlobHeaderV2(uint256 psuedoRandomNumber, uint8 version) internal view returns (BlobHeaderV2 memory) { + uint256[2] memory lengthCommitmentX = [uint256(keccak256(abi.encode(psuedoRandomNumber, "blobHeader.commitment.lengthCommitment.X"))), uint256(keccak256(abi.encode(psuedoRandomNumber, "blobHeader.commitment.lengthCommitment.X")))]; + uint256[2] memory lengthCommitmentY = [uint256(keccak256(abi.encode(psuedoRandomNumber, "blobHeader.commitment.lengthCommitment.Y"))), uint256(keccak256(abi.encode(psuedoRandomNumber, "blobHeader.commitment.lengthCommitment.Y")))]; + uint256[2] memory lengthProofX = [uint256(keccak256(abi.encode(psuedoRandomNumber, "blobHeader.commitment.lengthProof.X"))), uint256(keccak256(abi.encode(psuedoRandomNumber, "blobHeader.commitment.lengthProof.X")))]; + uint256[2] memory lengthProofY = [uint256(keccak256(abi.encode(psuedoRandomNumber, "blobHeader.commitment.lengthProof.Y"))), uint256(keccak256(abi.encode(psuedoRandomNumber, "blobHeader.commitment.lengthProof.Y")))]; + + BlobHeaderV2 memory blobHeader = BlobHeaderV2({ + version: version, + quorumNumbers: hex"00", + commitment: BlobCommitment({ + commitment: BN254.G1Point(uint256(keccak256(abi.encode(psuedoRandomNumber, "blobHeader.commitment.X"))), uint256(keccak256(abi.encode(psuedoRandomNumber, "blobHeader.commitment.Y")))), + lengthCommitment: BN254.G2Point(lengthCommitmentX, lengthCommitmentY), + lengthProof: BN254.G2Point(lengthProofX, lengthProofY), + dataLength: uint32(uint256(keccak256(abi.encode(psuedoRandomNumber, "blobHeader.dataLength")))) + }), + paymentHeaderHash: keccak256(abi.encode(psuedoRandomNumber, "blobHeader.paymentHeaderHash")) + }); + + return blobHeader; + } + + function _registerRelayKeys() internal { + vm.startPrank(registryCoordinatorOwner); + eigenDARelayRegistry.addRelayInfo(RelayInfo({ + relayAddress: relay0, + relayURL: "https://relay0.com" + })); + eigenDARelayRegistry.addRelayInfo(RelayInfo({ + relayAddress: relay1, + relayURL: "https://relay1.com" + })); + vm.stopPrank(); + } +} diff --git a/contracts/test/unit/EigenDADisperserRegistryUnit.t.sol b/contracts/test/unit/EigenDADisperserRegistryUnit.t.sol new file mode 100644 index 0000000000..00e2759044 --- /dev/null +++ b/contracts/test/unit/EigenDADisperserRegistryUnit.t.sol @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: MIT +pragma solidity =0.8.12; + +import "../MockEigenDADeployer.sol"; + +contract EigenDADisperserRegistryUnit is MockEigenDADeployer { + + event DisperserAdded(uint32 indexed key, address indexed disperser); + + function setUp() virtual public { + _deployDA(); + } + + function test_initalize() public { + assertEq(eigenDADisperserRegistry.owner(), registryCoordinatorOwner); + vm.expectRevert("Initializable: contract is already initialized"); + eigenDADisperserRegistry.initialize(address(this)); + } + + function test_setDisperserInfo() public { + uint32 disperserKey = 1; + address disperserAddress = address(uint160(uint256(keccak256(abi.encodePacked("disperser"))))); + DisperserInfo memory disperserInfo = DisperserInfo({ + disperserAddress: disperserAddress + }); + + vm.expectEmit(address(eigenDADisperserRegistry)); + emit DisperserAdded(disperserKey, disperserAddress); + vm.prank(registryCoordinatorOwner); + eigenDADisperserRegistry.setDisperserInfo(disperserKey, disperserInfo); + + assertEq(eigenDADisperserRegistry.disperserKeyToAddress(disperserKey), disperserAddress); + } + + function test_setDisperserInfo_revert_notOwner() public { + uint32 disperserKey = 1; + address disperserAddress = address(uint160(uint256(keccak256(abi.encodePacked("disperser"))))); + DisperserInfo memory disperserInfo = DisperserInfo({ + disperserAddress: disperserAddress + }); + + vm.expectRevert("Ownable: caller is not the owner"); + eigenDADisperserRegistry.setDisperserInfo(disperserKey, disperserInfo); + } +} diff --git a/contracts/test/unit/EigenDARelayRegistryUnit.t.sol b/contracts/test/unit/EigenDARelayRegistryUnit.t.sol new file mode 100644 index 0000000000..3ea0b2ee78 --- /dev/null +++ b/contracts/test/unit/EigenDARelayRegistryUnit.t.sol @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: MIT +pragma solidity =0.8.12; + +import "../MockEigenDADeployer.sol"; + +contract EigenDARelayRegistryUnit is MockEigenDADeployer { + + event RelayAdded(address indexed relay, uint32 indexed key, string relayURL); + + function setUp() virtual public { + _deployDA(); + } + + function test_initalize() public { + assertEq(eigenDARelayRegistry.owner(), registryCoordinatorOwner); + vm.expectRevert("Initializable: contract is already initialized"); + eigenDARelayRegistry.initialize(address(this)); + } + + function test_addRelayInfo() public { + RelayInfo memory relayInfo = RelayInfo({ + relayAddress: address(uint160(uint256(keccak256(abi.encodePacked("relay"))))), + relayURL: "https://relay.com" + }); + + vm.expectEmit(address(eigenDARelayRegistry)); + emit RelayAdded(relayInfo.relayAddress, eigenDARelayRegistry.nextRelayKey(), relayInfo.relayURL); + vm.prank(registryCoordinatorOwner); + eigenDARelayRegistry.addRelayInfo(relayInfo); + + assertEq(eigenDARelayRegistry.relayKeyToAddress(eigenDARelayRegistry.nextRelayKey() - 1), relayInfo.relayAddress); + assertEq(eigenDARelayRegistry.relayKeyToUrl(eigenDARelayRegistry.nextRelayKey() - 1), relayInfo.relayURL); + } + + function test_addRelayInfo_revert_notOwner() public { + RelayInfo memory relayInfo = RelayInfo({ + relayAddress: address(uint160(uint256(keccak256(abi.encodePacked("relay"))))), + relayURL: "https://relay.com" + }); + + vm.expectRevert("Ownable: caller is not the owner"); + eigenDARelayRegistry.addRelayInfo(relayInfo); + } +} diff --git a/contracts/test/unit/EigenDAServiceManagerUnit.t.sol b/contracts/test/unit/EigenDAServiceManagerUnit.t.sol index 8c14a98c0c..443e30f21e 100644 --- a/contracts/test/unit/EigenDAServiceManagerUnit.t.sol +++ b/contracts/test/unit/EigenDAServiceManagerUnit.t.sol @@ -1,138 +1,17 @@ // SPDX-License-Identifier: MIT pragma solidity =0.8.12; -import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "../MockEigenDADeployer.sol"; -import "../../lib/eigenlayer-middleware/test/utils/BLSMockAVSDeployer.sol"; -import {EigenDAServiceManager, IRewardsCoordinator} from "../../src/core/EigenDAServiceManager.sol"; -import {EigenDAHasher} from "../../src/libraries/EigenDAHasher.sol"; -import {EigenDAServiceManager} from "../../src/core/EigenDAServiceManager.sol"; -import {IEigenDAServiceManager} from "../../src/interfaces/IEigenDAServiceManager.sol"; -import {EigenDABlobVerifier} from "../../src/core/EigenDABlobVerifier.sol"; -import {EigenDAThresholdRegistry, IEigenDAThresholdRegistry} from "../../src/core/EigenDAThresholdRegistry.sol"; -import {IEigenDABatchMetadataStorage} from "../../src/interfaces/IEigenDABatchMetadataStorage.sol"; -import {IEigenDASignatureVerifier} from "../../src/interfaces/IEigenDASignatureVerifier.sol"; -import {IRegistryCoordinator} from "../../lib/eigenlayer-middleware/src/interfaces/IRegistryCoordinator.sol"; -import {IEigenDARelayRegistry} from "../../src/interfaces/IEigenDARelayRegistry.sol"; -import {IPaymentVault} from "../../src/interfaces/IPaymentVault.sol"; -import {EigenDARelayRegistry} from "../../src/core/EigenDARelayRegistry.sol"; -import {IEigenDADisperserRegistry} from "../../src/interfaces/IEigenDADisperserRegistry.sol"; -import "../../src/interfaces/IEigenDAStructs.sol"; - -contract EigenDAServiceManagerUnit is BLSMockAVSDeployer { +contract EigenDAServiceManagerUnit is MockEigenDADeployer { using BN254 for BN254.G1Point; using EigenDAHasher for BatchHeader; using EigenDAHasher for ReducedBatchHeader; - address confirmer = address(uint160(uint256(keccak256(abi.encodePacked("confirmer"))))); - address notConfirmer = address(uint160(uint256(keccak256(abi.encodePacked("notConfirmer"))))); - address newFeeSetter = address(uint160(uint256(keccak256(abi.encodePacked("newFeeSetter"))))); - address rewardsInitiator = address(uint160(uint256(keccak256(abi.encodePacked("rewardsInitiator"))))); - - EigenDAServiceManager eigenDAServiceManager; - EigenDAServiceManager eigenDAServiceManagerImplementation; - EigenDABlobVerifier eigenDABlobVerifier; - EigenDARelayRegistry eigenDARelayRegistry; - EigenDARelayRegistry eigenDARelayRegistryImplementation; - - EigenDAThresholdRegistry eigenDAThresholdRegistry; - EigenDAThresholdRegistry eigenDAThresholdRegistryImplementation; - bytes quorumAdversaryThresholdPercentages = hex"212121"; - bytes quorumConfirmationThresholdPercentages = hex"373737"; - bytes quorumNumbersRequired = hex"0001"; - SecurityThresholds defaultSecurityThresholds = SecurityThresholds(33, 55); - - uint256 feePerBytePerTime = 0; - event BatchConfirmed(bytes32 indexed batchHeaderHash, uint32 batchId); - event FeePerBytePerTimeSet(uint256 previousValue, uint256 newValue); - event FeeSetterChanged(address previousAddress, address newAddress); function setUp() virtual public { - _setUpBLSMockAVSDeployer(); - - eigenDAServiceManager = EigenDAServiceManager( - address( - new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") - ) - ); - - eigenDAThresholdRegistry = EigenDAThresholdRegistry( - address( - new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") - ) - ); - - eigenDARelayRegistry = EigenDARelayRegistry( - address( - new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "") - ) - ); - - eigenDAThresholdRegistryImplementation = new EigenDAThresholdRegistry(); - - eigenDAServiceManagerImplementation = new EigenDAServiceManager( - avsDirectory, - rewardsCoordinator, - registryCoordinator, - stakeRegistry, - eigenDAThresholdRegistry, - eigenDARelayRegistry, - IPaymentVault(address(0)), - IEigenDADisperserRegistry(address(0)) - ); - - address[] memory confirmers = new address[](1); - confirmers[0] = confirmer; - - cheats.prank(proxyAdminOwner); - proxyAdmin.upgradeAndCall( - TransparentUpgradeableProxy(payable(address(eigenDAServiceManager))), - address(eigenDAServiceManagerImplementation), - abi.encodeWithSelector( - EigenDAServiceManager.initialize.selector, - pauserRegistry, - 0, - registryCoordinatorOwner, - confirmers, - registryCoordinatorOwner - ) - ); - - VersionedBlobParams[] memory versionedBlobParams = new VersionedBlobParams[](0); - - cheats.prank(proxyAdminOwner); - proxyAdmin.upgradeAndCall( - TransparentUpgradeableProxy(payable(address(eigenDAThresholdRegistry))), - address(eigenDAThresholdRegistryImplementation), - abi.encodeWithSelector( - EigenDAThresholdRegistry.initialize.selector, - registryCoordinatorOwner, - quorumAdversaryThresholdPercentages, - quorumConfirmationThresholdPercentages, - quorumNumbersRequired, - versionedBlobParams, - defaultSecurityThresholds - ) - ); - - eigenDABlobVerifier = new EigenDABlobVerifier( - IEigenDAThresholdRegistry(address(eigenDAThresholdRegistry)), - IEigenDABatchMetadataStorage(address(eigenDAServiceManager)), - IEigenDASignatureVerifier(address(eigenDAServiceManager)), - IEigenDARelayRegistry(address(eigenDARelayRegistry)), - OperatorStateRetriever(address(operatorStateRetriever)), - IRegistryCoordinator(address(registryCoordinator)) - ); - - eigenDARelayRegistryImplementation = new EigenDARelayRegistry(); - - cheats.prank(proxyAdminOwner); - proxyAdmin.upgradeAndCall( - TransparentUpgradeableProxy(payable(address(eigenDARelayRegistry))), - address(eigenDARelayRegistryImplementation), - abi.encodeWithSelector(EigenDARelayRegistry.initialize.selector, registryCoordinatorOwner) - ); + _deployDA(); } function testConfirmBatch_AllSigning_Valid(uint256 pseudoRandomNumber) public { @@ -181,7 +60,6 @@ contract EigenDAServiceManagerUnit is BLSMockAVSDeployer { } function testConfirmBatch_Revert_FutureBlocknumber(uint256 pseudoRandomNumber) public { - uint256 quorumBitmap = 1; bytes memory quorumNumbers = BitmapUtils.bitmapToBytesArray(quorumBitmap); @@ -260,35 +138,4 @@ contract EigenDAServiceManagerUnit is BLSMockAVSDeployer { nonSignerStakesAndSignature ); } - - function _getHeaderandNonSigners(uint256 _nonSigners, uint256 _pseudoRandomNumber, uint8 _threshold) internal returns (BatchHeader memory, BLSSignatureChecker.NonSignerStakesAndSignature memory) { - // register a bunch of operators - uint256 quorumBitmap = 1; - bytes memory quorumNumbers = BitmapUtils.bitmapToBytesArray(quorumBitmap); - - // 0 nonSigners - (uint32 referenceBlockNumber, BLSSignatureChecker.NonSignerStakesAndSignature memory nonSignerStakesAndSignature) = - _registerSignatoriesAndGetNonSignerStakeAndSignatureRandom(_pseudoRandomNumber, _nonSigners, quorumBitmap); - - // get a random batch header - BatchHeader memory batchHeader = _getRandomBatchHeader(_pseudoRandomNumber, quorumNumbers, referenceBlockNumber, _threshold); - - // set batch specific signature - bytes32 reducedBatchHeaderHash = batchHeader.hashBatchHeaderToReducedBatchHeader(); - nonSignerStakesAndSignature.sigma = BN254.hashToG1(reducedBatchHeaderHash).scalar_mul(aggSignerPrivKey); - - return (batchHeader, nonSignerStakesAndSignature); - } - - function _getRandomBatchHeader(uint256 pseudoRandomNumber, bytes memory quorumNumbers, uint32 referenceBlockNumber, uint8 threshold) internal pure returns(BatchHeader memory) { - BatchHeader memory batchHeader; - batchHeader.blobHeadersRoot = keccak256(abi.encodePacked("blobHeadersRoot", pseudoRandomNumber)); - batchHeader.quorumNumbers = quorumNumbers; - batchHeader.signedStakeForQuorums = new bytes(quorumNumbers.length); - for (uint256 i = 0; i < quorumNumbers.length; i++) { - batchHeader.signedStakeForQuorums[i] = bytes1(threshold); - } - batchHeader.referenceBlockNumber = referenceBlockNumber; - return batchHeader; - } } \ No newline at end of file diff --git a/contracts/test/unit/EigenDAThresholdRegistryUnit.t.sol b/contracts/test/unit/EigenDAThresholdRegistryUnit.t.sol new file mode 100644 index 0000000000..c372f7531e --- /dev/null +++ b/contracts/test/unit/EigenDAThresholdRegistryUnit.t.sol @@ -0,0 +1,171 @@ +// SPDX-License-Identifier: MIT +pragma solidity =0.8.12; + +import "../MockEigenDADeployer.sol"; + +contract EigenDAThresholdRegistryUnit is MockEigenDADeployer { + + event VersionedBlobParamsAdded(uint16 indexed version, VersionedBlobParams versionedBlobParams); + event QuorumAdversaryThresholdPercentagesUpdated(bytes previousQuorumAdversaryThresholdPercentages, bytes newQuorumAdversaryThresholdPercentages); + event QuorumConfirmationThresholdPercentagesUpdated(bytes previousQuorumConfirmationThresholdPercentages, bytes newQuorumConfirmationThresholdPercentages); + event QuorumNumbersRequiredUpdated(bytes previousQuorumNumbersRequired, bytes newQuorumNumbersRequired); + event DefaultSecurityThresholdsV2Updated(SecurityThresholds previousDefaultSecurityThresholdsV2, SecurityThresholds newDefaultSecurityThresholdsV2); + + function setUp() virtual public { + _deployDA(); + } + + function test_initalize() public { + VersionedBlobParams memory _versionedBlobParams = VersionedBlobParams({ + maxNumOperators: 3537, + numChunks: 8192, + codingRate: 8 + }); + + assertEq(eigenDAThresholdRegistry.owner(), registryCoordinatorOwner); + assertEq(keccak256(abi.encode(eigenDAThresholdRegistry.quorumAdversaryThresholdPercentages())), keccak256(abi.encode(quorumAdversaryThresholdPercentages))); + assertEq(keccak256(abi.encode(eigenDAThresholdRegistry.quorumConfirmationThresholdPercentages())), keccak256(abi.encode(quorumConfirmationThresholdPercentages))); + assertEq(keccak256(abi.encode(eigenDAThresholdRegistry.quorumNumbersRequired())), keccak256(abi.encode(quorumNumbersRequired))); + (uint8 confirmationThreshold, uint8 adversaryThreshold) = eigenDAThresholdRegistry.defaultSecurityThresholdsV2(); + assertEq(adversaryThreshold, defaultSecurityThresholds.adversaryThreshold); + assertEq(confirmationThreshold, defaultSecurityThresholds.confirmationThreshold); + (uint32 maxNumOperators, uint32 numChunks, uint8 codingRate) = eigenDAThresholdRegistry.versionedBlobParams(0); + assertEq(maxNumOperators, _versionedBlobParams.maxNumOperators); + assertEq(numChunks, _versionedBlobParams.numChunks); + assertEq(codingRate, _versionedBlobParams.codingRate); + + VersionedBlobParams[] memory versionedBlobParams = new VersionedBlobParams[](1); + versionedBlobParams[0] = _versionedBlobParams; + vm.expectRevert("Initializable: contract is already initialized"); + eigenDAThresholdRegistry.initialize( + registryCoordinatorOwner, + quorumAdversaryThresholdPercentages, + quorumConfirmationThresholdPercentages, + quorumNumbersRequired, + versionedBlobParams, + defaultSecurityThresholds + ); + } + + function test_updateQuorumAdversaryThresholdPercentages() public { + bytes memory _quorumAdversaryThresholdPercentages = hex"AABBCC"; + vm.expectEmit(address(eigenDAThresholdRegistry)); + emit QuorumAdversaryThresholdPercentagesUpdated(quorumAdversaryThresholdPercentages, _quorumAdversaryThresholdPercentages); + vm.prank(registryCoordinatorOwner); + eigenDAThresholdRegistry.updateQuorumAdversaryThresholdPercentages(_quorumAdversaryThresholdPercentages); + assertEq(keccak256(abi.encode(eigenDAThresholdRegistry.quorumAdversaryThresholdPercentages())), keccak256(abi.encode(_quorumAdversaryThresholdPercentages))); + } + + function test_updateQuorumConfirmationThresholdPercentages() public { + bytes memory _quorumConfirmationThresholdPercentages = hex"AABBCC"; + vm.expectEmit(address(eigenDAThresholdRegistry)); + emit QuorumConfirmationThresholdPercentagesUpdated(quorumConfirmationThresholdPercentages, _quorumConfirmationThresholdPercentages); + vm.prank(registryCoordinatorOwner); + eigenDAThresholdRegistry.updateQuorumConfirmationThresholdPercentages(_quorumConfirmationThresholdPercentages); + assertEq(keccak256(abi.encode(eigenDAThresholdRegistry.quorumConfirmationThresholdPercentages())), keccak256(abi.encode(_quorumConfirmationThresholdPercentages))); + } + + function test_updateQuorumNumbersRequired() public { + bytes memory _quorumNumbersRequired = hex"AABBCC"; + vm.expectEmit(address(eigenDAThresholdRegistry)); + emit QuorumNumbersRequiredUpdated(quorumNumbersRequired, _quorumNumbersRequired); + vm.prank(registryCoordinatorOwner); + eigenDAThresholdRegistry.updateQuorumNumbersRequired(_quorumNumbersRequired); + assertEq(keccak256(abi.encode(eigenDAThresholdRegistry.quorumNumbersRequired())), keccak256(abi.encode(_quorumNumbersRequired))); + } + + function test_updateDefaultSecurityThresholdsV2() public { + SecurityThresholds memory _defaultSecurityThresholds = SecurityThresholds({ + adversaryThreshold: 10, + confirmationThreshold: 20 + }); + vm.expectEmit(address(eigenDAThresholdRegistry)); + emit DefaultSecurityThresholdsV2Updated(defaultSecurityThresholds, _defaultSecurityThresholds); + vm.prank(registryCoordinatorOwner); + eigenDAThresholdRegistry.updateDefaultSecurityThresholdsV2(_defaultSecurityThresholds); + (uint8 confirmationThreshold, uint8 adversaryThreshold) = eigenDAThresholdRegistry.defaultSecurityThresholdsV2(); + assertEq(adversaryThreshold, _defaultSecurityThresholds.adversaryThreshold); + assertEq(confirmationThreshold, _defaultSecurityThresholds.confirmationThreshold); + } + + function test_addVersionedBlobParams() public { + VersionedBlobParams memory _versionedBlobParams = VersionedBlobParams({ + maxNumOperators: 999, + numChunks: 999, + codingRate: 9 + }); + vm.expectEmit(address(eigenDAThresholdRegistry)); + emit VersionedBlobParamsAdded(1, _versionedBlobParams); + vm.prank(registryCoordinatorOwner); + uint16 version = eigenDAThresholdRegistry.addVersionedBlobParams(_versionedBlobParams); + assertEq(version, 1); + (uint32 maxNumOperators, uint32 numChunks, uint8 codingRate) = eigenDAThresholdRegistry.versionedBlobParams(version); + assertEq(maxNumOperators, _versionedBlobParams.maxNumOperators); + assertEq(numChunks, _versionedBlobParams.numChunks); + assertEq(codingRate, _versionedBlobParams.codingRate); + } + + function test_revert_onlyOwner() public { + vm.expectRevert("Ownable: caller is not the owner"); + eigenDAThresholdRegistry.updateQuorumAdversaryThresholdPercentages(hex"AABBCC"); + vm.expectRevert("Ownable: caller is not the owner"); + eigenDAThresholdRegistry.updateQuorumConfirmationThresholdPercentages(hex"AABBCC"); + vm.expectRevert("Ownable: caller is not the owner"); + eigenDAThresholdRegistry.updateQuorumNumbersRequired(hex"AABBCC"); + vm.expectRevert("Ownable: caller is not the owner"); + eigenDAThresholdRegistry.updateDefaultSecurityThresholdsV2(SecurityThresholds({ + adversaryThreshold: 10, + confirmationThreshold: 20 + })); + vm.expectRevert("Ownable: caller is not the owner"); + eigenDAThresholdRegistry.addVersionedBlobParams(VersionedBlobParams({ + maxNumOperators: 999, + numChunks: 999, + codingRate: 9 + })); + } + + function test_getQuorumAdversaryThresholdPercentage() public { + uint8 quorumNumber = 1; + uint8 adversaryThresholdPercentage = eigenDAThresholdRegistry.getQuorumAdversaryThresholdPercentage(quorumNumber); + assertEq(adversaryThresholdPercentage, uint8(quorumAdversaryThresholdPercentages[quorumNumber])); + } + + function test_getQuorumConfirmationThresholdPercentage() public { + uint8 quorumNumber = 1; + uint8 confirmationThresholdPercentage = eigenDAThresholdRegistry.getQuorumConfirmationThresholdPercentage(quorumNumber); + assertEq(confirmationThresholdPercentage, uint8(quorumConfirmationThresholdPercentages[quorumNumber])); + } + + function test_getIsQuorumRequired() public { + uint8 quorumNumber = 0; + bool isQuorumRequired = eigenDAThresholdRegistry.getIsQuorumRequired(quorumNumber); + assertEq(isQuorumRequired, true); + quorumNumber = 1; + isQuorumRequired = eigenDAThresholdRegistry.getIsQuorumRequired(quorumNumber); + assertEq(isQuorumRequired, true); + quorumNumber = 2; + isQuorumRequired = eigenDAThresholdRegistry.getIsQuorumRequired(quorumNumber); + assertEq(isQuorumRequired, false); + } + + function test_getDefaultSecurityThresholdsV2() public { + SecurityThresholds memory defaultSecurityThresholds = eigenDAThresholdRegistry.getDefaultSecurityThresholdsV2(); + assertEq(defaultSecurityThresholds.adversaryThreshold, defaultSecurityThresholds.adversaryThreshold); + assertEq(defaultSecurityThresholds.confirmationThreshold, defaultSecurityThresholds.confirmationThreshold); + } + + function test_getBlobParams() public { + VersionedBlobParams memory _versionedBlobParams = VersionedBlobParams({ + maxNumOperators: 999, + numChunks: 999, + codingRate: 9 + }); + vm.prank(registryCoordinatorOwner); + uint16 version = eigenDAThresholdRegistry.addVersionedBlobParams(_versionedBlobParams); + VersionedBlobParams memory blobParams = eigenDAThresholdRegistry.getBlobParams(version); + assertEq(blobParams.maxNumOperators, _versionedBlobParams.maxNumOperators); + assertEq(blobParams.numChunks, _versionedBlobParams.numChunks); + assertEq(blobParams.codingRate, _versionedBlobParams.codingRate); + } +} \ No newline at end of file diff --git a/contracts/test/unit/PaymentVaultUnit.t.sol b/contracts/test/unit/PaymentVaultUnit.t.sol index 740c2e7a55..d2163c623d 100644 --- a/contracts/test/unit/PaymentVaultUnit.t.sol +++ b/contracts/test/unit/PaymentVaultUnit.t.sol @@ -1,14 +1,9 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.12; -import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import "src/payments/PaymentVault.sol"; -import "src/interfaces/IPaymentVault.sol"; -import "forge-std/Test.sol"; -import "forge-std/StdStorage.sol"; - -contract PaymentVaultUnit is Test { +import "../MockEigenDADeployer.sol"; + +contract PaymentVaultUnit is MockEigenDADeployer { using stdStorage for StdStorage; event ReservationUpdated(address indexed account, IPaymentVault.Reservation reservation); @@ -25,54 +20,18 @@ contract PaymentVaultUnit is Test { uint64 newPriceUpdateCooldown ); - PaymentVault paymentVault; - PaymentVault paymentVaultImplementation; - ERC20 mockToken; - - address proxyAdmin = address(uint160(uint256(keccak256(abi.encodePacked("proxyAdmin"))))); - address initialOwner = address(uint160(uint256(keccak256(abi.encodePacked("initialOwner"))))); address user = address(uint160(uint256(keccak256(abi.encodePacked("user"))))); address user2 = address(uint160(uint256(keccak256(abi.encodePacked("user2"))))); - uint64 minNumSymbols = 1; - uint64 globalSymbolsPerPeriod = 2; - uint64 pricePerSymbol = 3; - uint64 reservationPeriodInterval = 4; - uint64 globalRatePeriodInterval = 5; - uint64 priceUpdateCooldown = 6 days; - bytes quorumNumbers = hex"0001"; bytes quorumSplits = hex"3232"; function setUp() virtual public { - paymentVaultImplementation = new PaymentVault(); - - paymentVault = PaymentVault( - payable( - address( - new TransparentUpgradeableProxy( - address(paymentVaultImplementation), - address(proxyAdmin), - abi.encodeWithSelector( - PaymentVault.initialize.selector, - initialOwner, - minNumSymbols, - pricePerSymbol, - priceUpdateCooldown, - globalSymbolsPerPeriod, - reservationPeriodInterval, - globalRatePeriodInterval - ) - ) - ) - ) - ); - - mockToken = new ERC20("Mock Token", "MOCK"); + _deployDA(); } function test_initialize() public { - require(paymentVault.owner() == initialOwner, "Owner is not set"); + assertEq(paymentVault.owner(), registryCoordinatorOwner); assertEq(paymentVault.minNumSymbols(), minNumSymbols); assertEq(paymentVault.globalSymbolsPerPeriod(), globalSymbolsPerPeriod); assertEq(paymentVault.pricePerSymbol(), pricePerSymbol); @@ -101,7 +60,7 @@ contract PaymentVaultUnit is Test { vm.expectEmit(address(paymentVault)); emit ReservationUpdated(_account, reservation); - vm.prank(initialOwner); + vm.prank(registryCoordinatorOwner); paymentVault.setReservation(_account, reservation); assertEq(keccak256(abi.encode(paymentVault.getReservation(_account))), keccak256(abi.encode(reservation))); @@ -117,7 +76,7 @@ contract PaymentVaultUnit is Test { }); vm.expectRevert("sum of quorumSplits must be 100"); - vm.prank(initialOwner); + vm.prank(registryCoordinatorOwner); paymentVault.setReservation(user, reservation); reservation = IPaymentVault.Reservation({ @@ -129,7 +88,7 @@ contract PaymentVaultUnit is Test { }); vm.expectRevert("sum of quorumSplits must be 100"); - vm.prank(initialOwner); + vm.prank(registryCoordinatorOwner); paymentVault.setReservation(user, reservation); reservation = IPaymentVault.Reservation({ @@ -141,7 +100,7 @@ contract PaymentVaultUnit is Test { }); vm.expectRevert("arrays must have the same length"); - vm.prank(initialOwner); + vm.prank(registryCoordinatorOwner); paymentVault.setReservation(user, reservation); } @@ -155,7 +114,7 @@ contract PaymentVaultUnit is Test { }); vm.expectRevert("end timestamp must be greater than start timestamp"); - vm.prank(initialOwner); + vm.prank(registryCoordinatorOwner); paymentVault.setReservation(user, reservation); } @@ -219,7 +178,7 @@ contract PaymentVaultUnit is Test { vm.expectEmit(address(paymentVault)); emit PriceParamsUpdated(minNumSymbols, minNumSymbols + 1, pricePerSymbol, pricePerSymbol + 1, priceUpdateCooldown, priceUpdateCooldown + 1); - vm.prank(initialOwner); + vm.prank(registryCoordinatorOwner); paymentVault.setPriceParams(minNumSymbols + 1, pricePerSymbol + 1, priceUpdateCooldown + 1); assertEq(paymentVault.minNumSymbols(), minNumSymbols + 1); @@ -232,14 +191,14 @@ contract PaymentVaultUnit is Test { vm.warp(block.timestamp + priceUpdateCooldown - 1); vm.expectRevert("price update cooldown not surpassed"); - vm.prank(initialOwner); + vm.prank(registryCoordinatorOwner); paymentVault.setPriceParams(minNumSymbols + 1, pricePerSymbol + 1, priceUpdateCooldown + 1); } function test_setGlobalRatePeriodInterval() public { vm.expectEmit(address(paymentVault)); emit GlobalRatePeriodIntervalUpdated(globalRatePeriodInterval, globalRatePeriodInterval + 1); - vm.prank(initialOwner); + vm.prank(registryCoordinatorOwner); paymentVault.setGlobalRatePeriodInterval(globalRatePeriodInterval + 1); assertEq(paymentVault.globalRatePeriodInterval(), globalRatePeriodInterval + 1); } @@ -247,7 +206,7 @@ contract PaymentVaultUnit is Test { function test_setGlobalSymbolsPerPeriod() public { vm.expectEmit(address(paymentVault)); emit GlobalSymbolsPerPeriodUpdated(globalSymbolsPerPeriod, globalSymbolsPerPeriod + 1); - vm.prank(initialOwner); + vm.prank(registryCoordinatorOwner); paymentVault.setGlobalSymbolsPerPeriod(globalSymbolsPerPeriod + 1); assertEq(paymentVault.globalSymbolsPerPeriod(), globalSymbolsPerPeriod + 1); } @@ -255,23 +214,23 @@ contract PaymentVaultUnit is Test { function test_setReservationPeriodInterval() public { vm.expectEmit(address(paymentVault)); emit ReservationPeriodIntervalUpdated(reservationPeriodInterval, reservationPeriodInterval + 1); - vm.prank(initialOwner); + vm.prank(registryCoordinatorOwner); paymentVault.setReservationPeriodInterval(reservationPeriodInterval + 1); assertEq(paymentVault.reservationPeriodInterval(), reservationPeriodInterval + 1); } function test_withdraw() public { test_depositOnDemand(); - vm.prank(initialOwner); + vm.prank(registryCoordinatorOwner); paymentVault.withdraw(100 ether); assertEq(address(paymentVault).balance, 100 ether); } function test_withdrawERC20() public { deal(address(mockToken), address(paymentVault), 100 ether); - vm.prank(initialOwner); - paymentVault.withdrawERC20(address(mockToken), 100 ether); - assertEq(mockToken.balanceOf(address(initialOwner)), 100 ether); + vm.prank(registryCoordinatorOwner); + paymentVault.withdrawERC20(mockToken, 100 ether); + assertEq(mockToken.balanceOf(address(registryCoordinatorOwner)), 100 ether); } function test_ownedFunctions() public { @@ -288,7 +247,7 @@ contract PaymentVaultUnit is Test { vm.expectRevert("Ownable: caller is not the owner"); paymentVault.withdraw(100 ether); vm.expectRevert("Ownable: caller is not the owner"); - paymentVault.withdrawERC20(address(mockToken), 100 ether); + paymentVault.withdrawERC20(mockToken, 100 ether); vm.expectRevert("Ownable: caller is not the owner"); paymentVault.setPriceParams(minNumSymbols + 1, pricePerSymbol + 1, priceUpdateCooldown + 1); vm.expectRevert("Ownable: caller is not the owner"); @@ -316,7 +275,7 @@ contract PaymentVaultUnit is Test { quorumSplits: hex"0163" }); - vm.startPrank(initialOwner); + vm.startPrank(registryCoordinatorOwner); paymentVault.setReservation(user, reservation); paymentVault.setReservation(user2, reservation2); vm.stopPrank();