DittoOthenticHook

Description:

Multi-signature wallet contract requiring multiple confirmations for transaction execution.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "src/othentic/DittoOthenticHook.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import {IAvsLogic} from "@othentic/NetworkManagement/L2/interfaces/IAvsLogic.sol";
import {IAttestationCenter} from "@othentic/NetworkManagement/L2/interfaces/IAttestationCenter.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {IEntryPoint_v07 as IEntryPoint} from "../interfaces/IEntryPoint_v07.sol";

/**
 * @title DittoOthenticHook
 * @author Ditto
 * @notice This contract serves as a hook for the Othentic AVS. It validates task submissions based on a
 * required set of Ditto attesters and executes the task data as an ERC-4337 UserOperation.
 * It is designed to be UUPS upgradeable.
 */
contract DittoOthenticHook is IAvsLogic, UUPSUpgradeable, OwnableUpgradeable, ReentrancyGuardUpgradeable {
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    // =============================================================
    //                           CUSTOM ERRORS
    // =============================================================
    error MissingDittoAttesters();
    error InvalidUserOperationData();
    error EntryPointCallFailed();
    error AlreadyApproved();
    error NotAttestationCenter();

    // =============================================================
    //                               EVENTS
    // =============================================================
    event DittoAttestersMaskUpdated(uint256 newMask);
    event UserOperationApproved(bytes32 indexed userOpHash);
    event UserOperationExecuted(bytes32 indexed userOpHash, bool success);
    event AttestationCenterUpdated(address indexed newAttestationCenter);
    event BeneficiaryUpdated(address indexed newBeneficiary);

    // =============================================================
    //                           STATE VARIABLES
    // =============================================================
    /// @notice The ERC-4337 EntryPoint contract.
    IEntryPoint public entryPoint;

    /// @notice The Othentic AttestationCenter contract, the only address allowed to call the submission hooks.
    address public attestationCenter;

    /// @notice A bitmask representing the set of required Ditto attester IDs.
    uint256 public dittoAttestersMask;

    /// @notice A mapping to temporarily store and approve UserOperation hashes before execution.
    mapping(bytes32 => bool) public isApprovedUserOpHash;

    /// @notice The beneficiary address that receives ETH collected from UserOperations.
    address public beneficiary;

    // =============================================================
    //                             MODIFIERS
    // =============================================================
    modifier onlyAttestationCenter() {
        require(msg.sender == attestationCenter, NotAttestationCenter());
        _;
    }

    // =============================================================
    //                           INITIALIZER
    // =============================================================
    function initialize(address _initialOwner, address _entryPoint, address _attestationCenter) public initializer {
        __Ownable_init(_initialOwner);
        __UUPSUpgradeable_init();
        __ReentrancyGuard_init();
        entryPoint = IEntryPoint(_entryPoint);
        attestationCenter = _attestationCenter;
    }

    // =============================================================
    //                       OWNER-ONLY FUNCTIONS
    // =============================================================

    /**
     * @notice Sets the required Ditto attesters by creating a bitmask.
     * @dev Attester IDs must be less than 256. IDs >= 256 will be ignored.
     * @param _attesterIds An array of Ditto attester IDs.
     */
    function setDittoAttesters(uint256[] calldata _attesterIds) external onlyOwner {
        uint256 newMask;
        for (uint256 i = 0; i < _attesterIds.length; ++i) {
            uint256 attesterId = _attesterIds[i];
            if (attesterId < 256) {
                newMask |= (1 << attesterId);
            }
        }
        dittoAttestersMask = newMask;
        emit DittoAttestersMaskUpdated(newMask);
    }

    /**
     * @notice Updates the address of the AttestationCenter.
     * @param _newAttestationCenter The address of the new AttestationCenter contract.
     */
    function setAttestationCenter(address _newAttestationCenter) external onlyOwner {
        attestationCenter = _newAttestationCenter;
        emit AttestationCenterUpdated(_newAttestationCenter);
    }

    /**
     * @notice Sets the beneficiary address that receives ETH from UserOperations.
     * @param _beneficiary The address of the new beneficiary.
     */
    function setBeneficiary(address _beneficiary) external onlyOwner {
        beneficiary = _beneficiary;
        emit BeneficiaryUpdated(_beneficiary);
    }

    /**
     * @dev Required by UUPS upgradeability.
     */
    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

    // =============================================================
    //                           AVS HOOK LOGIC
    // =============================================================

    /**
     * @inheritdoc IAvsLogic
     * @dev This hook version handles an ECDSA signature from the task performer.
     */
    function beforeTaskSubmission(
        IAttestationCenter.TaskInfo calldata _taskInfo,
        bool _isApproved,
        bytes calldata, // _tpSignature
        uint256[2] calldata, // _taSignature
        uint256[] calldata _attestersIds
    ) external nonReentrant onlyAttestationCenter {
        if (_isApproved) {
            _beforeTaskSubmissionLogic(_taskInfo, _attestersIds);
        }
    }

    /**
     * @inheritdoc IAvsLogic
     * @dev This hook version handles a BLS signature from the task performer.
     */
    function beforeTaskSubmission(
        IAttestationCenter.TaskInfo calldata _taskInfo,
        bool _isApproved,
        uint256[2] calldata, // _tpSignature
        uint256[2] calldata, // _taSignature
        uint256[] calldata _attestersIds
    ) external nonReentrant onlyAttestationCenter {
        if (_isApproved) {
            _beforeTaskSubmissionLogic(_taskInfo, _attestersIds);
        }
    }

    // =============================================================
    //                       INTERNAL LOGIC
    // =============================================================

    /**
     * @dev Core logic for validating and executing a task as a UserOperation.
     */
    function _beforeTaskSubmissionLogic(
        IAttestationCenter.TaskInfo calldata _taskInfo,
        uint256[] calldata _attestersIds
    ) internal {
        // 1. Verify that all required Ditto attesters are present.
        uint256 attestersMask;
        for (uint256 i = 0; i < _attestersIds.length; ++i) {
            uint256 attesterId = _attestersIds[i];
            if (attesterId < 256) {
                attestersMask |= (1 << attesterId);
            }
        }

        require((attestersMask & dittoAttestersMask) == dittoAttestersMask, MissingDittoAttesters());

        // 2. Decode UserOperation and calculate its hash.
        IEntryPoint.PackedUserOperation[] memory userOps = new IEntryPoint.PackedUserOperation[](1);
        userOps[0] = _decodeUserOp(_taskInfo.data);
        bytes32 userOpHash = entryPoint.getUserOpHash(userOps[0]);
        require(!isApprovedUserOpHash[userOpHash], AlreadyApproved());

        // 3. Approve the UserOperation hash.
        isApprovedUserOpHash[userOpHash] = true;
        emit UserOperationApproved(userOpHash);

        // 4. Execute the UserOperation via the EntryPoint.
        // We use a try/catch block to ensure cleanup happens even if execution fails.
        bool success;
        try entryPoint.handleOps(userOps, payable(beneficiary)) {
            success = true;
        } catch {
            success = false;
        }

        emit UserOperationExecuted(userOpHash, success);

        // 5. Clean up the approval.
        delete isApprovedUserOpHash[userOpHash];

        // Revert if the handleOps call failed.
        require(success, EntryPointCallFailed());
    }

    /**
     * @dev Decodes a UserOperation from a bytes array.
     */
    function _decodeUserOp(bytes calldata _data) internal pure returns (IEntryPoint.PackedUserOperation memory) {
        require(_data.length > 0, InvalidUserOperationData());
        return abi.decode(_data, (IEntryPoint.PackedUserOperation));
    }

    // =============================================================
    //                  UNUSED IAVSLOGIC FUNCTIONS
    // =============================================================

    function afterTaskSubmission(
        IAttestationCenter.TaskInfo calldata,
        bool,
        bytes calldata,
        uint256[2] calldata,
        uint256[] calldata
    ) external pure {}

    function afterTaskSubmission(
        IAttestationCenter.TaskInfo calldata,
        bool,
        uint256[2] calldata,
        uint256[2] calldata,
        uint256[] calldata
    ) external pure {}
}
"
    },
    "lib/@othentic/src/NetworkManagement/L2/interfaces/IAvsLogic.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.25;

/*______     __      __                              __      __ 
 /      \   /  |    /  |                            /  |    /  |
/$$$$$$  | _$$ |_   $$ |____    ______   _______   _$$ |_   $$/   _______ 
$$ |  $$ |/ $$   |  $$      \  /      \ /       \ / $$   |  /  | /       |
$$ |  $$ |$$$$$$/   $$$$$$$  |/$$$$$$  |$$$$$$$  |$$$$$$/   $$ |/$$$$$$$/ 
$$ |  $$ |  $$ | __ $$ |  $$ |$$    $$ |$$ |  $$ |  $$ | __ $$ |$$ |
$$ \__$$ |  $$ |/  |$$ |  $$ |$$$$$$$$/ $$ |  $$ |  $$ |/  |$$ |$$ \_____ 
$$    $$/   $$  $$/ $$ |  $$ |$$       |$$ |  $$ |  $$  $$/ $$ |$$       |
 $$$$$$/     $$$$/  $$/   $$/  $$$$$$$/ $$/   $$/    $$$$/  $$/  $$$$$$$/
*/
import {IAttestationCenter} from "@othentic/NetworkManagement/L2/interfaces/IAttestationCenter.sol";
/**
 * @author Othentic Labs LTD.
 * @notice Terms of Service: https://www.othentic.xyz/terms-of-service
 * @notice Depending on the application, it may be necessary to add reentrancy gaurds to hooks
 */

interface IAvsLogic {
    function afterTaskSubmission(
        IAttestationCenter.TaskInfo calldata _taskInfo,
        bool _isApproved,
        bytes calldata _tpSignature,
        uint256[2] calldata _taSignature,
        uint256[] calldata _attestersIds
    ) external;

    function beforeTaskSubmission(
        IAttestationCenter.TaskInfo calldata _taskInfo,
        bool _isApproved,
        bytes calldata _tpSignature,
        uint256[2] calldata _taSignature,
        uint256[] calldata _attestersIds
    ) external;

    function afterTaskSubmission(
        IAttestationCenter.TaskInfo calldata _taskInfo,
        bool _isApproved,
        uint256[2] calldata _tpSignature,
        uint256[2] calldata _taSignature,
        uint256[] calldata _attestersIds
    ) external;

    function beforeTaskSubmission(
        IAttestationCenter.TaskInfo calldata _taskInfo,
        bool _isApproved,
        uint256[2] calldata _tpSignature,
        uint256[2] calldata _taSignature,
        uint256[] calldata _attestersIds
    ) external;
}
"
    },
    "lib/@othentic/src/NetworkManagement/L2/interfaces/IAttestationCenter.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.19;
/**
 * @author Othentic Labs LTD.
 * @notice Terms of Service: https://www.othentic.xyz/terms-of-service
 */

import {IAvsLogic} from "@othentic/NetworkManagement/L2/interfaces/IAvsLogic.sol";
import "@othentic/NetworkManagement/Common/interfaces/IOBLS.sol";
import "@othentic/NetworkManagement/Common/interfaces/ISlashingConfig.sol";
import "@othentic/NetworkManagement/L2/TaskDefinitionLibrary.sol";
import {IAccessControl} from "openzeppelin-contracts/contracts/access/IAccessControl.sol";
import "@othentic/NetworkManagement/L2/interfaces/IBeforePaymentsLogic.sol";
import {IInternalTaskHandler} from "@othentic/NetworkManagement/L2/interfaces/IInternalTaskHandler.sol";

interface IAttestationCenter is IAccessControl {
    enum OperatorStatus {
        INACTIVE,
        ACTIVE
    }

    enum PaymentStatus {
        REDEEMED,
        COMMITTED,
        CHALLENGED
    }

    struct RegistrationDetails {
        address operator;
        uint256 votingPower;
        uint256[4] blsKey;
        address rewardsReceiver;
    }

    struct OperatorDetails {
        address operator;
        uint256 operatorId;
        uint256 votingPower;
        uint256 feeToClaim;
        uint256[4] blsKey;
    }

    struct PaymentDetails {
        address operator;
        uint256 lastPaidTaskNumber;
        uint256 feeToClaim;
        PaymentStatus paymentStatus;
    }

    struct PaymentRequestMessage {
        address operator;
        uint256 feeToClaim;
    }

    struct TaskInfo {
        string proofOfTask;
        bytes data;
        address taskPerformer;
        uint16 taskDefinitionId;
    }

    struct TaskSubmissionDetails {
        bool isApproved;
        bytes ecdsaTpSignature;
        uint256[2] blsTpSignature;
        uint256[2] taSignature;
        uint256[] attestersIds;
    }

    struct EcdsaTaskSubmissionDetails {
        bool isApproved;
        bytes tpSignature;
        uint256[2] taSignature;
        uint256[] attestersIds;
    }

    struct BlsTaskSubmissionDetails {
        bool isApproved;
        uint256[2] tpSignature;
        uint256[2] taSignature;
        uint256[] attestersIds;
    }

    struct InitializationParams {
        address avsGovernanceMultisigOwner;
        address operationsMultisig;
        address communityMultisig;
        address messageHandler;
        address obls;
        address avsTreasury;
        bool isRewardsOnL2;
        address internalTaskHandler;
    }

    event PaymentsRequested(PaymentRequestMessage[] operators, uint256 lastPaidTaskNumber);
    event EigenPaymentsRequested(
        uint32 startTimestamp, uint32 duration, PaymentRequestMessage[] operators, uint256 lastPaidTaskNumber
    );
    event ClearPaymentRejected(address indexed operator, uint256 requestedTaskNumber, uint256 requestedAmountClaimed);
    event TaskSubmitted(
        address indexed operator,
        uint32 taskNumber,
        string proofOfTask,
        bytes data,
        uint16 indexed taskDefinitionId,
        uint256[] attestersIds
    );
    event TaskRejected(
        address indexed operator,
        uint32 taskNumber,
        string proofOfTask,
        bytes data,
        uint16 indexed taskDefinitionId,
        uint256[] attestersIds
    );
    event SetMessageHandler(address newMessageHandler);
    event RewardAccumulated(uint256 indexed _operatorId, uint256 _baseRewardFeeForOperator, uint32 indexed _taskNumber);
    event SlashPerformerForRejectedTaskRequested(TaskInfo taskInfo);

    error InvalidOperatorsForPayment();
    error MessageAlreadySigned();
    error InactiveTaskPerformer();
    error InactiveAggregator();
    error InvalidTaskDefinition();
    error TaskDefinitionNotFound(uint16 taskDefinitionId);
    error OperatorNotRegistered(address _operatorAddress);
    error InvalidPerformerSignature();
    error InvalidRangeForBatchPaymentRequest();
    error InvalidRestrictedAttester(uint256 taskDefinitionId, uint256 operatorIndex);
    error InsufficientVotingPowerForTaskDefinition(uint16 taskDefinitionId, uint256 minVotingPower);
    error InvalidAttesterSet();
    error InvalidMaximumNumberOfAttesters();
    error ZeroAddress();
    error EigenRewardsNotSupportedOnL2();
    error EigenRewardsMustBeRetroactive();
    error EigenRewardsDurationExceedsMaximum();
    error EigenRewardsDurationNotMultipleOfInterval();
    error EigenRewardsStartTimestampNotMultipleOfInterval();
    error EigenRewardsStartTimestampTooFarInPast();
    error EigenRewardsMaxRewardsAmountExceeded(uint256 totalRewards);

    function taskNumber() external view returns (uint32);

    function numOfActiveOperators() external view returns (uint256);

    function votingPower(address _operator) external view returns (uint256);

    function getOperatorPaymentDetail(uint256 _operatorId) external view returns (PaymentDetails memory);

    function getTaskDefinitionMinimumVotingPower(uint16 _taskDefinitionId) external view returns (uint256);

    function getTaskDefinitionRestrictedAttesters(uint16 _taskDefinitionId) external view returns (uint256[] memory);

    function getTaskDefinitionMaximumNumberOfAttesters(uint16 _taskDefinitionId) external view returns (uint256);

    function numOfTaskDefinitions() external view returns (uint16);

    function operatorsIdsByAddress(address _operator) external view returns (uint256);

    function avsLogic() external view returns (IAvsLogic);

    function beforePaymentsLogic() external view returns (IBeforePaymentsLogic);

    function obls() external view returns (IOBLS);

    function internalTaskHandler() external view returns (IInternalTaskHandler);

    function submitTask(TaskInfo calldata _taskInfo, EcdsaTaskSubmissionDetails calldata _taskSubmissionDetails)
        external;

    function submitTask(TaskInfo calldata _taskInfo, BlsTaskSubmissionDetails calldata _taskSubmissionDetails)
        external;

    function requestBatchPayment() external;

    function requestBatchPayment(uint256 _from, uint256 _to) external;

    function setPaymentRequestsRole(address _paymentRequestsAddress) external;

    function requestEigenBatchPayment(uint32 _startTimestamp, uint32 _duration, uint256 _from, uint256 _to) external;

    function nextEigenRewardsBatchStartTimestamp() external view returns (uint256);

    function clearBatchPayment(PaymentRequestMessage[] memory _operators, uint256 _lastPaidTaskNumber) external;

    function avsTreasury() external view returns (address);

    function PaymentRequestsRole() external view returns (address);

    function getActiveOperatorsDetails() external view returns (OperatorDetails[] memory _operators);
}
"
    },
    "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.22;

import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address private immutable __self = address(this);

    /**
     * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
     * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
     * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
     * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
     * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
     * during an upgrade.
     */
    string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";

    /**
     * @dev The call is from an unauthorized context.
     */
    error UUPSUnauthorizedCallContext();

    /**
     * @dev The storage `slot` is unsupported as a UUID.
     */
    error UUPSUnsupportedProxiableUUID(bytes32 slot);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        _checkProxy();
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        _checkNotDelegated();
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual notDelegated returns (bytes32) {
        return ERC1967Utils.IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data);
    }

    /**
     * @dev Reverts if the execution is not performed via delegatecall or the execution
     * context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
     */
    function _checkProxy() internal view virtual {
        if (
            address(this) == __self || // Must be called through delegatecall
            ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
        ) {
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Reverts if the execution is performed via delegatecall.
     * See {notDelegated}.
     */
    function _checkNotDelegated() internal view virtual {
        if (address(this) != __self) {
            // Must not be called through delegatecall
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
     *
     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
     * is expected to be the implementation slot in ERC-1967.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
                revert UUPSUnsupportedProxiableUUID(slot);
            }
            ERC1967Utils.upgradeToAndCall(newImplementation, data);
        } catch {
            // The implementation is not UUPS
            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
        }
    }
}
"
    },
    "lib/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Ownable
    struct OwnableStorage {
        address _owner;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;

    function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
        assembly {
            $.slot := OwnableStorageLocation
        }
    }

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    function __Ownable_init(address initialOwner) internal onlyInitializing {
        __Ownable_init_unchained(initialOwner);
    }

    function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        OwnableStorage storage $ = _getOwnableStorage();
        return $._owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        OwnableStorage storage $ = _getOwnableStorage();
        address oldOwner = $._owner;
        $._owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
"
    },
    "lib/openzeppelin-contracts-upgradeable/contracts/utils/ReentrancyGuardUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
    struct ReentrancyGuardStorage {
        uint256 _status;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
        assembly {
            $.slot := ReentrancyGuardStorageLocation
        }
    }

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        $._status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if ($._status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        $._status = ENTERED;
    }

    function _nonReentrantAfter() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        $._status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        return $._status == ENTERED;
    }
}
"
    },
    "src/interfaces/IEntryPoint_v07.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity >=0.8.25;

/**
 * @title IEntryPoint_v07
 * @author argentlabs
 * @notice Interface for the ERC-4337 EntryPoint contract, version 0.7.
 * This interface provides the necessary function signatures and structs to interact with the EntryPoint,
 * specifically for handling UserOperations.
 */
interface IEntryPoint_v07 {
    /**
     * @dev UserOperation struct based on ERC-4337 v0.7.
     * Note the packed fields for gas limits and fees.
     */
    struct PackedUserOperation {
        address sender;
        uint256 nonce;
        bytes initCode;
        bytes callData;
        bytes32 accountGasLimits; // packed(verificationGasLimit, callGasLimit)
        uint256 preVerificationGas;
        bytes32 gasFees; // packed(maxPriorityFeePerGas, maxFeePerGas)
        bytes paymasterAndData;
        bytes signature;
    }

    /**
     * @notice Execute a batch of UserOperations.
     * @param ops The UserOperations to execute.
     * @param beneficiary The address to receive the gas refund.
     */
    function handleOps(PackedUserOperation[] calldata ops, address payable beneficiary) external;

    /**
     * @notice Calculate the hash of a UserOperation.
     * This hash is what gets signed by the user and validated by the account.
     * @param userOp The UserOperation to hash.
     * @return The hash of the UserOperation.
     */
    function getUserOpHash(PackedUserOperation calldata userOp) external view returns (bytes32);
}
"
    },
    "lib/@othentic/src/NetworkManagement/Common/interfaces/IOBLS.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity >=0.8.25;

import {BLSAuthLibrary} from "@othentic/NetworkManagement/Common/BLSAuthLibrary.sol";

/**
 * @author Othentic Labs LTD.
 */
interface IOBLS {
    struct BLSOperator {
        uint256[4] blsKey;
        uint256 votingPower;
        bool isRegistered;
    }

    struct OperatorVotingPower {
        uint256 operatorId;
        uint256 votingPower;
    }

    error NotOBLSManager();
    error NotOBLSManagerOrShareSyncer();
    error InsufficientVotingPower();
    error InvalidOBLSSignature();
    error InvalidOperatorIndexes();
    error InactiveOperator(uint256 operator);
    error InvalidAuthSignature();
    error OperatorDoesNotHaveMinimumVotingPower(uint256 _operatorIndex);
    error InvalidRequiredVotingPower();
    error InvalidOperatorIndex();

    event SetOBLSManager(address newOBLSManager);
    event SharesSyncerModified(address syncer);
    event IncreaseBatchOperatorVotingPower(OperatorVotingPower[] operatorsVotingPower);
    event DecreaseBatchOperatorVotingPower(OperatorVotingPower[] operatorsVotingPower);
    event SetTotalVotingPowerPerTaskDefinition(
        uint16 taskdefinitionId, uint256 numOfTotalOperators, uint256 minimumVotingPower
    );
    event SetTotalVotingPowerPerRestrictedTaskDefinition(
        uint16 taskDefinitionId, uint256 minimumVotingPower, uint256[] restrictedAttesterIds
    );

    function totalVotingPower() external view returns (uint256);

    function votingPower(uint256 _index) external view returns (uint256);

    function totalVotingPowerPerTaskDefinition(uint256 _id) external view returns (uint256);

    // @obsolete - use isRegistered
    function isActive(uint256 _index) external view returns (bool);

    function isRegistered(uint256 _index) external view returns (bool);

    function getOperatorBLSPubKey(uint256 _index) external view returns (uint256[4] memory);

    function verifySignature(
        uint256[2] calldata _message,
        uint256[2] calldata _signature,
        uint256[] calldata _indexes,
        uint256 _requiredVotingPower,
        uint256 _minimumVotingPowerPerTaskDefinition
    ) external view;

    function verifyAuthSignature(
        BLSAuthLibrary.Signature calldata _signature,
        address _operator,
        address _contract,
        uint256[4] calldata _blsKey
    ) external view;

    function validateOperatorSignature(
        uint256 _operatorId,
        uint256[2] calldata _message,
        uint256[2] calldata _signature
    ) external view;

    function hashToPoint(bytes32 domain, bytes calldata message) external view returns (uint256[2] memory);

    function unRegisterOperator(uint256 _index) external;

    function registerOperator(uint256 _index, uint256 _votingPower, uint256[4] memory _blsKey) external;

    function syncOperatorDetails(uint256[] calldata _votingPowers, uint256[4][] calldata _blsKeys) external;

    function setTotalVotingPowerPerTaskDefinition(
        uint16 _taskdefinitionId,
        uint256 _numOfTotalOperators,
        uint256 _minimumVotingPower
    ) external;

    function setTotalVotingPowerPerRestrictedTaskDefinition(
        uint16 _taskDefinitionId,
        uint256 _minimumVotingPower,
        uint256[] calldata _restrictedAttesterIds
    ) external;

    function modifyOperatorBlsKey(uint256 _index, uint256[4] memory _blsKey) external;

    function increaseOperatorVotingPower(uint256 _index, uint256 _votingPower) external;

    function increaseBatchOperatorVotingPower(OperatorVotingPower[] memory _operatorsVotingPower) external;

    function increaseOperatorVotingPowerPerTaskDefinition(uint16 _taskDefinitionId, uint256 _votingPower) external;

    function decreaseOperatorVotingPower(uint256 _index, uint256 _votingPower) external;

    function decreaseBatchOperatorVotingPower(OperatorVotingPower[] memory _operatorsVotingPower) external;

    function decreaseOperatorVotingPowerPerTaskDefinition(uint16 _taskDefinitionId, uint256 _votingPower) external;

    function setOblsSharesSyncer(address _oblsSharesSyncer) external;

    function getOblsManager() external view returns (address);
}
"
    },
    "lib/@othentic/src/NetworkManagement/Common/interfaces/ISlashingConfig.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.25;
/*______     __      __                              __      __
 /      \   /  |    /  |                            /  |    /  |
/$$$$$$  | _$$ |_   $$ |____    ______   _______   _$$ |_   $$/   _______
$$ |  $$ |/ $$   |  $$      \  /      \ /       \ / $$   |  /  | /       |
$$ |  $$ |$$$$$$/   $$$$$$$  |/$$$$$$  |$$$$$$$  |$$$$$$/   $$ |/$$$$$$$/
$$ |  $$ |  $$ | __ $$ |  $$ |$$    $$ |$$ |  $$ |  $$ | __ $$ |$$ |
$$ \__$$ |  $$ |/  |$$ |  $$ |$$$$$$$$/ $$ |  $$ |  $$ |/  |$$ |$$ \_____
$$    $$/   $$  $$/ $$ |  $$ |$$       |$$ |  $$ |  $$  $$/ $$ |$$       |
 $$$$$$/     $$$$/  $$/   $$/  $$$$$$$/ $$/   $$/    $$$$/  $$/  $$$$$$$/
*/

/**
 * @author Othentic Labs LTD.
 */
interface ISlashingConfig {
    enum SlashingCondition {
        None,
        DoubleAttestations,
        RejectedTask,
        IncorrectAttestations
    }
}
"
    },
    "lib/@othentic/src/NetworkManagement/L2/TaskDefinitionLibrary.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.25;

/*______     __      __                              __      __ 
 /      \   /  |    /  |                            /  |    /  |
/$$$$$$  | _$$ |_   $$ |____    ______   _______   _$$ |_   $$/   _______ 
$$ |  $$ |/ $$   |  $$      \  /      \ /       \ / $$   |  /  | /       |
$$ |  $$ |$$$$$$/   $$$$$$$  |/$$$$$$  |$$$$$$$  |$$$$$$/   $$ |/$$$$$$$/ 
$$ |  $$ |  $$ | __ $$ |  $$ |$$    $$ |$$ |  $$ |  $$ | __ $$ |$$ |
$$ \__$$ |  $$ |/  |$$ |  $$ |$$$$$$$$/ $$ |  $$ |  $$ |/  |$$ |$$ \_____ 
$$    $$/   $$  $$/ $$ |  $$ |$$       |$$ |  $$ |  $$  $$/ $$ |$$       |
 $$$$$$/     $$$$/  $$/   $$/  $$$$$$$/ $$/   $$/    $$$$/  $$/  $$$$$$$/
*/

struct TaskDefinition {
    uint16 taskDefinitionId;
    bool isRejectedTaskSlashingEnabled;
    bool isIncorrectAttestationSlashingEnabled;
    string name;
    uint256 blockExpiry;
    uint256 baseRewardFeeForAttesters;
    uint256 baseRewardFeeForPerformer;
    uint256 baseRewardFeeForAggregator;
    uint256 disputePeriodBlocks;
    uint256 minimumVotingPower;
    uint256[] restrictedAttesterIds;
    uint256 maximumNumberOfAttesters;
}

// @obsolete - use TaskDefinitionParamsV2
struct TaskDefinitionParams {
    uint256 blockExpiry;
    uint256 baseRewardFeeForAttesters;
    uint256 baseRewardFeeForPerformer;
    uint256 baseRewardFeeForAggregator;
    uint256 disputePeriodBlocks;
    uint256 minimumVotingPower;
    uint256[] restrictedAttesterIds;
}

struct TaskDefinitionParamsV2 {
    uint256 blockExpiry;
    uint256 baseRewardFeeForAttesters;
    uint256 baseRewardFeeForPerformer;
    uint256 baseRewardFeeForAggregator;
    uint256 disputePeriodBlocks;
    uint256 minimumVotingPower;
    uint256[] restrictedAttesterIds;
    uint256 maximumNumberOfAttesters;
}

struct TaskDefinitions {
    uint16 counter;
    mapping(uint16 => TaskDefinition) taskDefinitions;
}

error InvalidBlockExpiry();

/**
 * @author Othentic Labs LTD.
 * @notice Terms of Service: https://www.othentic.xyz/terms-of-service
 */
library TaskDefinitionLibrary {
    event TaskDefinitionCreated(
        uint16 taskDefinitionId,
        string name,
        uint256 blockExpiry,
        uint256 baseRewardFeeForAttesters,
        uint256 baseRewardFeeForPerformer,
        uint256 baseRewardFeeForAggregator,
        uint256 disputePeriodBlocks,
        uint256 minimumVotingPower,
        uint256[] restrictedAttesterIds,
        uint256 maximumNumberOfAttesters
    );

    uint16 constant MIN_INTERNAL_TASK_ID = 10_001; // 10001 or greater ids are reserved for internal tasks
    uint16 constant VOTING_POWER_SYNC_TASK_DEFINITION_ID = 10_001;
    uint16 constant TOTAL_VOTING_POWER_CALC_TASK_DEFINITION_ID = 10_002;
    uint16 constant WEIGHTS_UPDATE_TASK_DEFINITION_ID = 10_003;

    function createNewTaskDefinition(
        TaskDefinitions storage self,
        string memory _name,
        TaskDefinitionParamsV2 memory _params
    ) internal returns (uint16 _id) {
        if (_params.blockExpiry <= block.number) revert InvalidBlockExpiry();
        _id = ++self.counter;
        self.taskDefinitions[_id] = TaskDefinition(
            _id,
            false,
            false,
            _name,
            _params.blockExpiry,
            _params.baseRewardFeeForAttesters,
            _params.baseRewardFeeForPerformer,
            _params.baseRewardFeeForAggregator,
            _params.disputePeriodBlocks,
            _params.minimumVotingPower,
            _params.restrictedAttesterIds,
            _params.maximumNumberOfAttesters
        );
        emit TaskDefinitionCreated(
            _id,
            _name,
            _params.blockExpiry,
            _params.baseRewardFeeForAttesters,
            _params.baseRewardFeeForPerformer,
            _params.baseRewardFeeForAggregator,
            _params.disputePeriodBlocks,
            _params.minimumVotingPower,
            _params.restrictedAttesterIds,
            _params.maximumNumberOfAttesters
        );
    }

    function getTaskDefinition(TaskDefinitions storage self, uint16 _taskDefinitionId)
        internal
        view
        returns (TaskDefinition storage)
    {
        return self.taskDefinitions[_taskDefinitionId];
    }

    function getMinimumVotingPower(TaskDefinitions storage self, uint16 _taskDefinitionId)
        internal
        view
        returns (uint256)
    {
        return self.taskDefinitions[_taskDefinitionId].minimumVotingPower;
    }

    function getRestrictedAttesterIds(TaskDefinitions storage self, uint16 _taskDefinitionId)
        internal
        view
        returns (uint256[] storage)
    {
        return self.taskDefinitions[_taskDefinitionId].restrictedAttesterIds;
    }

    function getMaximumNumberOfAttesters(TaskDefinitions storage self, uint16 _taskDefinitionId)
        internal
        view
        returns (uint256)
    {
        return self.taskDefinitions[_taskDefinitionId].maximumNumberOfAttesters;
    }
}
"
    },
    "lib/openzeppelin-contracts/contracts/access/IAccessControl.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/IAccessControl.sol)

pragma solidity >=0.8.4;

/**
 * @dev External interface of AccessControl declared to support ERC-165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted to signal this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
     * Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}
"
    },
    "lib/@othentic/src/NetworkManagement/L2/interfaces/IBeforePaymentsLogic.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.25;

/*______     __      __                              __      __ 
 /      \   /  |    /  |                            /  |    /  |
/$$$$$$  | _$$ |_   $$ |____    ______   _______   _$$ |_   $$/   _______ 
$$ |  $$ |/ $$   |  $$      \  /      \ /       \ / $$   |  /  | /       |
$$ |  $$ |$$$$$$/   $$$$$$$  |/$$$$$$  |$$$$$$$  |$$$$$$/   $$ |/$$$$$$$/ 
$$ |  $$ |  $$ | __ $$ |  $$ |$$    $$ |$$ |  $$ |  $$ | __ $$ |$$ |
$$ \__$$ |  $$ |/  |$$ |  $$ |$$$$$$$$/ $$ |  $$ |  $$ |/  |$$ |$$ \_____ 
$$    $$/   $$  $$/ $$ |  $$ |$$       |$$ |  $$ |  $$  $$/ $$ |$$       |
 $$$$$$/     $$$$/  $$/   $$/  $$$$$$$/ $$/   $$/    $$$$/  $$/  $$$$$$$/
*/
import {IAttestationCenter} from "@othentic/NetworkManagement/L2/interfaces/IAttestationCenter.sol";
/**
 * @author Othentic Labs LTD.
 * @notice Terms of Service: https://www.othentic.xyz/terms-of-service
 * @notice Depending on the application, it may be necessary to add reentrancy gaurds to hooks
 */

interface IBeforePaymentsLogic {
    function beforePaymentRequest(
        uint256 _operatorId,
        IAttestationCenter.PaymentDetails calldata _paymentDetails,
        uint32 _taskNumber
    ) external;
}
"
    },
    "lib/@othentic/src/NetworkManagement/L2/interfaces/IInternalTaskHandler.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.25;

/*______     __      __                              __      __ 
 /      \   /  |    /  |                            /  |    /  |
/$$$$$$  | _$$ |_   $$ |____    ______   _______   _$$ |_   $$/   _______ 
$$ |  $$ |/ $$   |  $$      \  /      \ /       \ / $$   |  /  | /       |
$$ |  $$ |$$$$$$/   $$$$$$$  |/$$$$$$  |$$$$$$$  |$$$$$$/   $$ |/$$$$$$$/ 
$$ |  $$ |  $$ | __ $$ |  $$ |$$    $$ |$$ |  $$ |  $$ | __ $$ |$$ |
$$ \__$$ |  $$ |/  |$$ |  $$ |$$$$$$$$/ $$ |  $$ |  $$ |/  |$$ |$$ \_____ 
$$    $$/   $$  $$/ $$ |  $$ |$$       |$$ |  $$ |  $$  $$/ $$ |$$       |
 $$$$$$/     $$$$/  $$/   $$/  $$$$$$$/ $$/   $$/    $$$$/  $$/  $$$$$$$/
*/
import {IAttestationCenter} from "@othentic/NetworkManagement/L2/interfaces/IAttestationCenter.sol";
import {IAttestationCenterExtension} from "@othentic/NetworkManagement/L2/interfaces/IAttestationCenterExtension.sol";
import {IOBLS} from "@othentic/NetworkManagement/Common/interfaces/IOBLS.sol";

/**
 * @author Othentic Labs LTD.
 * @notice Terms of Service: https://www.othentic.xyz/terms-of-service
 */
interface IInternalTaskHandler {
    enum LeaderElectionMechanism {
        Static,
        RoundRobin,
        StakeWeightedRandom,
        ConsistentHashing
    }

    struct InternalTaskConfig {
        bool isInternalTaskActivated;
        uint48 interval;
        LeaderElectionMechanism leaderElectionMechanism;
        bytes data;
    }

    struct VotingPowerUpdate {
        IOBLS.OperatorVotingPower[] toIncrease;
        IOBLS.OperatorVotingPower[] toDecrease;
        uint256 toBlockL1;
        uint256 toBlockL2;
    }

    struct InternalTransaction {
        address to;
        bytes data;
    }

    struct WeightUpdate {
        address stakingContract;
        uint256 weight;
    }

    event InternalTaskConfigUpdated(uint16 taskDefinitionId, InternalTaskConfig config);
    event TaskProcessed(uint256 taskDefinitionId, string proofOfTask);
    event VotingPowerUpdated(uint256 toBlockL1, uint256 toBlockL2, string proofOfTask);
    event ExecuteInternalTransactionsTask(InternalTransaction[] transactions);
    event WeightsUpdated(WeightUpdate[] weights);

    error InternalTaskNotActivated(uint16 taskDefinitionId);
    error InvalidInternalTaskId(uint16 taskDefinitionId);
    error InvalidInterval(uint48 interval);
    error InvalidToBlockL1VsLastCommitBlockL1(uint256 requiredMinToBlockL1);
    error InvalidToBlockL2VsLastCommitBlockL2(uint256 requiredMinToBlockL2);
    error InvalidToBlockL2VsCurrentHeight(uint256 toBlockL2, uint256 currentHeight);
    error InvalidIntenalTransactionNonce(uint256 requiredNonce, uint256 currentNonce);
    error InternalTransactionRevert(bytes reason);
    error InternalTransactionNotAllowed(address to, bytes data);
    error InvalidAttestationCenterAddress();

    // ------------------ Internal Task Handler Interface ------------------
    function getInternalTaskConfig(uint16 _taskDefinitionId) external view returns (InternalTaskConfig memory);
    function updateInternalTaskConfig(uint16 _taskDefinitionId, InternalTaskConfig memory _config) external;
    function processTask(IAttestationCenter.TaskInfo calldata _task) external;
}
"
    },
    "lib/openzeppelin-contracts/contracts/interfaces/draft-IERC1822.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/draft-IERC1822.sol)

pragma solidity >=0.4.16;

/**
 * @dev ERC-1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822Proxiable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}
"
    },
    "lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (proxy/ERC1967/ERC1967Utils.sol)

pragma solidity ^0.8.21;

import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
 * @dev This library provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
 */
library ERC1967Utils {
    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the ERC-1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(newImplementation);
        }
        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Performs implementation upgrade with additional setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) internal {
        _setImplementation(newImplementation);
        emit IERC1967.Upgraded(newImplementation);

        if (data.length > 0) {
            Address.functionDelegateCall(newImplementation, data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the ERC-1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        if (newAdmin == address(0)) {
            revert ERC1967InvalidAdmin(address(0));
        }
        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {IERC1967-AdminChanged} event.
     */
    function changeAdmin(address newAdmin) internal {
        emit IERC1967.AdminChanged(getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the ERC-1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        if (newBeacon.code.length == 0) {
            revert ERC1967InvalidBeacon(newBeacon);
        }

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

        address beaconImplementation = IBeacon(newBeacon).implementation();
        if (beaconImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(beaconImplementation);
        }
    }

    /**
     * @dev Change the beacon and trigger a setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-BeaconUpgraded} event.
     *
     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
     * efficiency.
     */
    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
        _setBeacon(newBeacon);
        emit IERC1967.BeaconUpgraded(newBeacon);

        if (data.length > 0) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
     * if an upgrade doesn't perform an initialization call.
     */
    function _checkNonPayable() private {
        if (msg.value > 0) {
            revert ERC1967NonPayable();
        }
    }
}
"
    },
    "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableIniti

Tags:
Multisig, Voting, Upgradeable, Multi-Signature, Factory|addr:0x890750975d86f5aa24d6a69ac90865ac8d583b47|verified:true|block:23621638|tx:0xbf63b1eec41357cd138c0aba13d486e183d74aec67b019ca897504ed6ea65949|first_check:1761055404

Submitted on: 2025-10-21 16:03:26

Comments

Log in to comment.

No comments yet.