generated from BreadchainCoop/solidity-foundry-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {ECDSAStakeRegistry} from '@eigenlayer-middleware/unaudited/ECDSAStakeRegistry.sol'; | ||
import {LayerSDK} from 'contracts/LayerSDK.sol'; | ||
import {ILayerConsumer} from 'interfaces/ILayerConsumer.sol'; | ||
|
||
contract LayerConsumer is ILayerConsumer { | ||
/// @notice bytes4(keccak256("isValidSignature(bytes32,bytes)") | ||
bytes4 internal constant _ERC1271_SIGNATURE = 0x1626ba7e; | ||
contract LayerConsumer is LayerSDK, ILayerConsumer { | ||
/// @notice Initializer | ||
constructor(address _stakeRegistry) LayerSDK(_stakeRegistry) {} | ||
|
||
/// @inheritdoc ILayerConsumer | ||
ECDSAStakeRegistry public immutable STAKE_REGISTRY; | ||
|
||
/** | ||
* @notice Initializer | ||
* @param _stakeRegistry The address of the stake registry contract | ||
*/ | ||
constructor(address _stakeRegistry) { | ||
STAKE_REGISTRY = ECDSAStakeRegistry(_stakeRegistry); | ||
} | ||
|
||
/** | ||
* @notice Validates a layer task from off-chain AVS operator | ||
* @param _task The message and signatures to verify | ||
* @return _isValid Whether the task is valid | ||
*/ | ||
function _validateLayerTask(Task memory _task) internal view returns (bool _isValid) { | ||
_isValid = (_ERC1271_SIGNATURE == STAKE_REGISTRY.isValidSignature(_task.dataHash, _task.signatureData)); | ||
function validateLayerTask(string calldata _offchainData) external view returns (bool _isValid) { | ||
Task memory _task = Task({dataHash: bytes32(bytes(_offchainData[0:32])), signatureData: bytes(_offchainData[32:])}); | ||
_isValid = _validateLayerTask(_task); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {LayerConsumer} from 'contracts/LayerConsumer.sol'; | ||
import {ECDSAStakeRegistry} from '@eigenlayer-middleware/unaudited/ECDSAStakeRegistry.sol'; | ||
import {ILayerSDK} from 'interfaces/ILayerSDK.sol'; | ||
|
||
contract LayerSDK is LayerConsumer, ILayerSDK { | ||
/// @notice Initializer | ||
constructor(address _stakeRegistry) LayerConsumer(_stakeRegistry) {} | ||
contract LayerSDK is ILayerSDK { | ||
/// @notice bytes4(keccak256("isValidSignature(bytes32,bytes)") | ||
bytes4 internal constant _ERC1271_SIGNATURE = 0x1626ba7e; | ||
|
||
/// @inheritdoc ILayerSDK | ||
function validateLayerTask(string calldata _offchainData) external view returns (bool _isValid) { | ||
Task memory _task = Task({dataHash: bytes32(bytes(_offchainData[0:32])), signatureData: bytes(_offchainData[32:])}); | ||
_isValid = _validateLayerTask(_task); | ||
ECDSAStakeRegistry public immutable STAKE_REGISTRY; | ||
|
||
/** | ||
* @notice Initializer | ||
* @param _stakeRegistry The address of the stake registry contract | ||
*/ | ||
constructor(address _stakeRegistry) { | ||
STAKE_REGISTRY = ECDSAStakeRegistry(_stakeRegistry); | ||
} | ||
|
||
/** | ||
* @notice Validates a layer task from off-chain AVS operator | ||
* @param _task The message and signatures to verify | ||
* @return _isValid Whether the task is valid | ||
*/ | ||
function _validateLayerTask(Task memory _task) internal view returns (bool _isValid) { | ||
_isValid = (_ERC1271_SIGNATURE == STAKE_REGISTRY.isValidSignature(_task.dataHash, _task.signatureData)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,17 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {ECDSAStakeRegistry} from '@eigenlayer-middleware/unaudited/ECDSAStakeRegistry.sol'; | ||
import {ILayerSDK} from 'interfaces/ILayerSDK.sol'; | ||
|
||
/** | ||
* @title AVSConsumer Contract | ||
* @author Breadchain | ||
* @notice LayerConsumer contract to validate layer tasks from off-chain AVS operators | ||
*/ | ||
interface ILayerConsumer { | ||
interface ILayerConsumer is ILayerSDK { | ||
/*/////////////////////////////////////////////////////////////// | ||
DATA STRUCTURES | ||
LOGIC | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @notice The task structure | ||
* @param dataHash The hash of the data to verify | ||
* @param signatureData The signature(s) to verify | ||
* @notice Validates a layer task from off-chain AVS operator | ||
* @param _offchainData The off-chain data to verify | ||
* @return _isValid Whether the task is valid | ||
*/ | ||
struct Task { | ||
bytes32 dataHash; | ||
bytes signatureData; | ||
} | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
ERRORS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/// @notice Error thrown when the caller is not an operator | ||
error NotOperator(); | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
VARIABLES | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @notice The stake registry contract | ||
* @return _stakeRegistry The stake registry address | ||
*/ | ||
function STAKE_REGISTRY() external view returns (ECDSAStakeRegistry _stakeRegistry); // solhint-disable-line func-name-mixedcase | ||
function validateLayerTask(string calldata _offchainData) external view returns (bool _isValid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {ILayerConsumer} from 'interfaces/ILayerConsumer.sol'; | ||
import {ECDSAStakeRegistry} from '@eigenlayer-middleware/unaudited/ECDSAStakeRegistry.sol'; | ||
|
||
interface ILayerSDK is ILayerConsumer { | ||
/** | ||
* @title LayerSDK Contract | ||
* @author Breadchain | ||
* @notice LayerSDK contract to validate layer tasks from off-chain AVS operators | ||
*/ | ||
interface ILayerSDK { | ||
/*/////////////////////////////////////////////////////////////// | ||
LOGIC | ||
DATA STRUCTURES | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @notice Validates a layer task from off-chain AVS operator | ||
* @param _offchainData The off-chain data to verify | ||
* @return _isValid Whether the task is valid | ||
* @notice The task structure | ||
* @param dataHash The hash of the data to verify | ||
* @param signatureData The signature(s) to verify | ||
*/ | ||
function validateLayerTask(string calldata _offchainData) external view returns (bool _isValid); | ||
struct Task { | ||
bytes32 dataHash; | ||
bytes signatureData; | ||
} | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
ERRORS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/// @notice Error thrown when the caller is not an operator | ||
error NotOperator(); | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
VARIABLES | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @notice The stake registry contract | ||
* @return _stakeRegistry The stake registry address | ||
*/ | ||
function STAKE_REGISTRY() external view returns (ECDSAStakeRegistry _stakeRegistry); // solhint-disable-line func-name-mixedcase | ||
} |