kintsugi-tech / slash-refund

0 stars 0 forks source link

Slash Refund Module

Abstract

This paper describes the slash-refund module, how it works and its components.

The SDK module is a component strictly related to the staking module and has the purpose of refunding stakers from slashing events.

How it works

Any user has the possibility to deposit a certain amount of allowed tokens into the module for a particular validator. This funds will be used to repay possible loss deriving from slashing events of the particular validator.

The funds will be maintained in the module and can be withdrawn at any moment. Following the delegated proof of stake philosophy and design pattern, before the tokens claim any withdrawn amount requires an unbonding period. This unbonding time will be equal to the staking unbonding time and is necessary to be able to account for slashing events evidenced in all the allowed time.

types

Protobuf defines the following types:

Deposit

type Deposit struct {
    DepositorAddress string                                 `protobuf:"bytes,1,opt,name=depositor_address,json=depositorAddress,proto3" json:"depositor_address,omitempty"`
    ValidatorAddress string                                 `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"`
    Shares           github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=shares,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"shares"`
}

where DepositorAddress is address of a user who deposited tokens, ValidatorAddress is the validator for which tokens are provided, and Shares are the pool's partial shares associated to the depositor.

DepositPool

type DepositPool struct {
    OperatorAddress string                                 `protobuf:"bytes,1,opt,name=operator_address,json=operatorAddress,proto3" json:"operator_address,omitempty"`
    Tokens          types.Coin                             `protobuf:"bytes,2,opt,name=tokens,proto3" json:"tokens"`
    Shares          github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=shares,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"shares" yaml:"depositor_shares"`
}

where OperatorAddress is the operator address of an active, or previously active, validator, Tokens are the token available to refund the associated validator slashes, and Shares are the actual circulating shares associated to this pool.

Refund

type Refund struct {
    DelegatorAddress string                                 `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"`
    ValidatorAddress string                                 `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"`
    Shares           github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=shares,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"shares"`
}

This type is the analogous of Deposit but in this case Shares represents the portion of associated pool tokens the user can withdraw as result of a refund.

RefundPool

type RefundPool struct {
    OperatorAddress string                                 `protobuf:"bytes,1,opt,name=operator_address,json=operatorAddress,proto3" json:"operator_address,omitempty"`
    Tokens          types.Coin                             `protobuf:"bytes,2,opt,name=tokens,proto3" json:"tokens"`
    Shares          github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=shares,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"shares" yaml:"refund_shares"`
}

This type is the anologous of DepositPool but is used to manage refunded tokens.

Params

type Params struct {
    AllowedTokens []string `protobuf:"bytes,1,rep,name=allowedTokens,proto3" json:"allowedTokens,omitempty" yaml:"allowed_tokens"`
}

where allowedTokens are the native tokens that a user can deposit to help refunding validators slahes.

msgServer

The module's msgServer is composed of the following methods:

Keeper

The slash refund module's staking keeper expects the following Cosmos SDK keeper:

Here are described the provided methods:

$$ emittedShares = \frac{poolShares}{inputTokens} \cdot poolTokens $$

Important note

The module is based on a slightly modified version of the Cosmos SDK v0.46.8 in which we added the infraction height to slash events. This is imposed in the go.mod as a replacement:

replace github.com/cosmos/cosmos-sdk v0.46.1 => github.com/made-in-block/cosmos-sdk v0.46.8-infraction-height