|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import {ILayerServiceManager} from "./interfaces/ILayerServiceManager.sol"; |
| 5 | +import {ECDSAServiceManagerBase} from "@eigenlayer/middleware/src/unaudited/ECDSAServiceManagerBase.sol"; |
| 6 | +import {ECDSAStakeRegistry} from "@eigenlayer/middleware/src/unaudited/ECDSAStakeRegistry.sol"; |
| 7 | +import {IERC1271Upgradeable} from "@openzeppelin-upgrades/contracts/interfaces/IERC1271Upgradeable.sol"; |
| 8 | +import {ECDSAUpgradeable} from "@openzeppelin-upgrades/contracts/utils/cryptography/ECDSAUpgradeable.sol"; |
| 9 | + |
| 10 | +/** |
| 11 | + * @title LayerServiceManager |
| 12 | + * @notice contract that validates signatures using the ECDSAStakeRegistry. |
| 13 | + * typically this contract is called from some "ILayerServiceHandler" (a vanilla implementation of ILayerService/ILayerServiceMulti) |
| 14 | + */ |
| 15 | +contract LayerServiceManager is ECDSAServiceManagerBase,ILayerServiceManager { |
| 16 | + |
| 17 | + // ------------------------------------------------------------------------ |
| 18 | + // Constructor |
| 19 | + // ------------------------------------------------------------------------ |
| 20 | + constructor( |
| 21 | + address _avsDirectory, |
| 22 | + address _stakeRegistry, |
| 23 | + address _rewardsCoordinator, |
| 24 | + address _delegationManager |
| 25 | + ) |
| 26 | + ECDSAServiceManagerBase( |
| 27 | + _avsDirectory, |
| 28 | + _stakeRegistry, |
| 29 | + _rewardsCoordinator, |
| 30 | + _delegationManager |
| 31 | + ) |
| 32 | + { |
| 33 | + } |
| 34 | + |
| 35 | + // ------------------------------------------------------------------------ |
| 36 | + // Functions |
| 37 | + // ------------------------------------------------------------------------ |
| 38 | + |
| 39 | + /** |
| 40 | + * @notice Validate signed data via ECDSAStakeRegistry. |
| 41 | + */ |
| 42 | + function validate(bytes calldata data, bytes calldata signature) external view |
| 43 | + { |
| 44 | + bytes32 message = keccak256(data); |
| 45 | + bytes32 ethSignedMessageHash = ECDSAUpgradeable.toEthSignedMessageHash(message); |
| 46 | + bytes4 magicValue = IERC1271Upgradeable.isValidSignature.selector; |
| 47 | + |
| 48 | + // If the registry returns the magicValue, signature is considered valid |
| 49 | + if( magicValue != |
| 50 | + ECDSAStakeRegistry(stakeRegistry).isValidSignature( |
| 51 | + ethSignedMessageHash, |
| 52 | + signature |
| 53 | + ) |
| 54 | + ) { |
| 55 | + revert ILayerServiceManager.InvalidSignature(); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments