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.
feat: add consumer and sdk contracts
- Loading branch information
Showing
9 changed files
with
118 additions
and
40 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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {ECDSAStakeRegistry} from '@eigenlayer-middleware/unaudited/ECDSAStakeRegistry.sol'; | ||
import {ILayerConsumer} from 'interfaces/ILayerConsumer.sol'; | ||
|
||
contract LayerConsumer is ILayerConsumer { | ||
/// @notice bytes4(keccak256("isValidSignature(bytes32,bytes)") | ||
bytes4 internal constant _ERC1271_SIGNATURE = 0x1626ba7e; | ||
|
||
/// @inheritdoc ILayerConsumer | ||
ECDSAStakeRegistry public immutable STAKE_REGISTRY; | ||
|
||
/// @notice Enforce that the caller is an operator | ||
modifier onlyOperator() { | ||
if (!STAKE_REGISTRY.operatorRegistered(msg.sender)) revert NotOperator(); | ||
_; | ||
} | ||
|
||
/** | ||
* @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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {LayerConsumer} from 'contracts/LayerConsumer.sol'; | ||
import {ILayerSDK} from 'interfaces/ILayerSDK.sol'; | ||
|
||
contract LayerSDK is LayerConsumer, ILayerSDK { | ||
/// @notice Initializer | ||
constructor(address _stakeRegistry) LayerConsumer(_stakeRegistry) {} | ||
|
||
/// @inheritdoc ILayerSDK | ||
function validateLayerTask(string calldata _offchainData) external view onlyOperator returns (bool _isValid) { | ||
Task memory _task = Task({dataHash: bytes32(bytes(_offchainData[0:32])), signatureData: bytes(_offchainData[32:])}); | ||
_isValid = _validateLayerTask(_task); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {ECDSAStakeRegistry} from '@eigenlayer-middleware/unaudited/ECDSAStakeRegistry.sol'; | ||
|
||
/** | ||
* @title AVSConsumer Contract | ||
* @author Breadchain | ||
* @notice LayerConsumer contract to validate layer tasks from off-chain AVS operators | ||
*/ | ||
interface ILayerConsumer { | ||
/*/////////////////////////////////////////////////////////////// | ||
DATA STRUCTURES | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @notice The task structure | ||
* @param dataHash The hash of the data to verify | ||
* @param signatureData The signature(s) to verify | ||
*/ | ||
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 | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {ILayerConsumer} from 'interfaces/ILayerConsumer.sol'; | ||
|
||
interface ILayerSDK is ILayerConsumer { | ||
/*/////////////////////////////////////////////////////////////// | ||
LOGIC | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
* @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 | ||
*/ | ||
function validateLayerTask(string calldata _offchainData) external view returns (bool _isValid); | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {Test} from 'forge-std/Test.sol'; | ||
|
||
contract UnitLayerConsumer is Test {} |