Skip to content

Core Function hooks

In the context of Distributed Secure Service (DSS) contracts, Core contracts initiate updates by calling specific hooks within the DSS. These hooks ensure that the DSS contract remains synchronized with changes made in the Core contracts. However, to optimize gas usage, DSS contracts can choose to implement only the hooks necessary for them.

Implementing Desired Hooks

DSS contracts can selectively implement hooks based on their operational needs. This selection is managed through the supportsInterface function, which determines whether the DSS supports specific interface functions. For instance, if a DSS only requires functionalities related to registration and unregistration, it can specify this in the supportsInterface function as follows:

function supportsInterface(bytes4 interfaceID) external view returns (bool){
    if (
        interfaceID == IDSS.registrationHook.selector ||
        interfaceID == IDSS.unregistrationHook.selector
    ) {
        return true;
    }
    return false;
}

Execution of Core Functions

When a relevant Core function is executed, the corresponding hook implemented in supportsInterface is automatically invoked by the system. This ensures that the DSS contract is updated accordingly, reflecting changes made in the Core contracts.

Handling extraData Parameter

Some hook functions, such as registrationHook, include an extraData parameter. This parameter is designed for DSS contracts to provide additional information that can be decoded into any required data structure during the hook invocation. For example:

struct RegistrationData {
    bytes32 signature,
    uint256 timestamp,
}
 
function registrationHook(address operator, bytes memory extraData) external {
    ...
    RegistrationData memory data = abi.decode(extraData, (RegistrationData));
}

All Hooks

Registration Hook : Called when a new operator registers, providing their address and optional data (extraData).

Unregistration Hook : Called when an operator unregisters, providing their address and optional data (extraData).

Request Update Stake Hook : Called when an operator requests to update staked amount in DSS, providing their address and StakeUpdateRequest struct.

struct StakeUpdateRequest {
    address vault;
    IDSS dss;
    bool toStake; // true for stake, false for unstake
}

Cancel Update Stake Hook : Called when an operator cancels its request to update staked amount in DSS, providing their address and vault address.

Finish Update Stake Hook : Called when an operator finalizes its request to update staked amount in DSS, providing their address.

Request Slashing Hook : Called when the DSS requests a slashing, providing their operator address and a list of slashingPercentageWad.

slashingPercentageWad : A percentage wad scales a percentage to 10^18 points, where passing 10^18 represents 100%.

Cancel Slashing Hook : Called when the Slashing Commitee cancels the slashing request, providing their operator address.

Finish Slashing Hook : Called when the DSS finalizes the slashing request, providing their operator address.

By setting up the DSS contract to interact seamlessly with the Core through these hooks and incorporating necessary custom logic, developers ensure robust integration and efficient operation within the broader system architecture.