Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRST audit fixes for HorizonStaking contract #1073

Open
wants to merge 21 commits into
base: horizon
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ce749be
fix: separate delegation and provision thaw request lists (TRST-H02)
Maikol Nov 28, 2024
d02f410
fix: separate delegation and delegationWithBeneficiary thaw requests …
Maikol Nov 29, 2024
167055a
fix: round down tokens thawing when slashing (TRST-H04)
Maikol Dec 2, 2024
abe3321
fix: add legacy slasher for transition period (TRST-H06)
Maikol Dec 3, 2024
f254897
fix: add missing legacy withdraw delegated (TRST-H07)
Maikol Dec 4, 2024
91cda56
fix: added minimum delegation for provisions (TRST-M03)
Maikol Dec 4, 2024
07ef418
fix: operator check in closeAllocation (TRST-M12)
Maikol Dec 4, 2024
26e4dc7
fix: getThawedTokens calculation (TRST-L03)
Maikol Dec 4, 2024
c9f8a2f
fix: documentation on unstake (TRST-M11)
Maikol Dec 4, 2024
9271b99
fix: remove unused value from event (TRST-R01)
Maikol Dec 4, 2024
151e63a
fix: round thawing shares up (TRST-R07)
Maikol Dec 5, 2024
6e5a295
fix: check shares are not zero when creating a thaw request (TRST-R14)
Maikol Dec 5, 2024
d9c6190
fix: move legacyWithdrawDelegated to withdrawDelegated (TRST-H07)
Maikol Dec 6, 2024
161f8a2
fix: added comment for stack too deep solution
Maikol Dec 6, 2024
43bc72b
fix: added comment to explain minimum delegation (TRST-M03)
Maikol Dec 6, 2024
c59c186
fix: new event for minimum delegation not met (TRST-M03)
Maikol Dec 6, 2024
d1c5cc7
fix: add a new mapping instead of splitting thaw requests (TRST-H02)
Maikol Dec 6, 2024
6e00d17
docs: fix documentation errors (TRST-R09)
tmigone Dec 9, 2024
c94be63
fix: legacy slashing underflow (TRST-H09)
Maikol Dec 12, 2024
04fcd0a
fix: underflow in getIdleStake (TRST-L14)
Maikol Dec 12, 2024
f6ce016
fix: added thaw request type to thaw request fulfilled event (TRST-R15)
Maikol Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ interface IHorizonStakingBase {
*/
event StakeDeposited(address indexed serviceProvider, uint256 tokens);

/**
* @notice Thrown when using an invalid thaw request type.
*/
error HorizonStakingInvalidThawRequestType();

/**
* @notice Gets the details of a service provider.
* @param serviceProvider The address of the service provider.
Expand Down Expand Up @@ -134,34 +139,46 @@ interface IHorizonStakingBase {

/**
* @notice Gets a thaw request.
* @param thawRequestType The type of thaw request.
* @param thawRequestId The id of the thaw request.
* @return The thaw request details.
*/
function getThawRequest(bytes32 thawRequestId) external view returns (IHorizonStakingTypes.ThawRequest memory);
function getThawRequest(
IHorizonStakingTypes.ThawRequestType thawRequestType,
bytes32 thawRequestId
) external view returns (IHorizonStakingTypes.ThawRequest memory);

/**
* @notice Gets the metadata of a thaw request list.
* Service provider and delegators each have their own thaw request list per provision.
* Metadata includes the head and tail of the list, plus the total number of thaw requests.
* @param thawRequestType The type of thaw request.
* @param serviceProvider The address of the service provider.
* @param verifier The address of the verifier.
* @param owner The owner of the thaw requests. Use either the service provider or delegator address.
* @return The thaw requests list metadata.
*/
function getThawRequestList(
IHorizonStakingTypes.ThawRequestType thawRequestType,
address serviceProvider,
address verifier,
address owner
) external view returns (LinkedList.List memory);

/**
* @notice Gets the amount of thawed tokens for a given provision.
* @param thawRequestType The type of thaw request.
* @param serviceProvider The address of the service provider.
* @param verifier The address of the verifier.
* @param owner The owner of the thaw requests. Use either the service provider or delegator address.
* @return The amount of thawed tokens.
*/
function getThawedTokens(address serviceProvider, address verifier, address owner) external view returns (uint256);
function getThawedTokens(
IHorizonStakingTypes.ThawRequestType thawRequestType,
address serviceProvider,
address verifier,
address owner
) external view returns (uint256);

/**
* @notice Gets the maximum allowed thawing period for a provision.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ interface IHorizonStakingExtension is IRewardsIssuer {
uint256 delegationRewards
);

/**
* @dev Emitted when `indexer` was slashed for a total of `tokens` amount.
* Tracks `reward` amount of tokens given to `beneficiary`.
*/
event StakeSlashed(address indexed indexer, uint256 tokens, uint256 reward, address beneficiary);

/**
* @dev Emitted when `delegator` withdrew delegated `tokens` from `indexer` using `legacyWithdrawDelegated`.
*/
event StakeDelegatedWithdrawn(address indexed indexer, address indexed delegator, uint256 tokens);

/**
* @notice Close an allocation and free the staked tokens.
* To be eligible for rewards a proof of indexing must be presented.
Expand Down Expand Up @@ -148,4 +159,23 @@ interface IHorizonStakingExtension is IRewardsIssuer {
*/
// solhint-disable-next-line func-name-mixedcase
function __DEPRECATED_getThawingPeriod() external view returns (uint64);

/**
* @notice Slash the indexer stake. Delegated tokens are not subject to slashing.
* @dev Can only be called by the slasher role.
* @param indexer Address of indexer to slash
* @param tokens Amount of tokens to slash from the indexer stake
* @param reward Amount of reward tokens to send to a beneficiary
* @param beneficiary Address of a beneficiary to receive a reward for the slashing
*/
function legacySlash(address indexer, uint256 tokens, uint256 reward, address beneficiary) external;

/**
* @notice Withdraw undelegated tokens once the unbonding period has passed.
* @param _indexer Withdraw available tokens delegated to indexer
*/
function legacyWithdrawDelegated(
address _indexer,
address /* _newIndexer, deprecated */
) external returns (uint256);
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,8 @@ interface IHorizonStakingMain {

/**
* @notice Emitted when the delegation slashing global flag is set.
* @param enabled Whether delegation slashing is enabled or disabled.
*/
event DelegationSlashingEnabled(bool enabled);
event DelegationSlashingEnabled();

// -- Errors: tokens

Expand Down Expand Up @@ -515,6 +514,8 @@ interface IHorizonStakingMain {
* - During the transition period it's locked for a period of time before it can be withdrawn
* by calling {withdraw}.
* - After the transition period it's immediately withdrawn.
* Note that after the transition period if there are tokens still locked they will have to be
* withdrawn by calling {withdraw}.
* @dev Requirements:
* - `_tokens` cannot be zero.
* - `_serviceProvider` must have enough idle stake to cover the staking amount and any
Expand Down Expand Up @@ -747,7 +748,7 @@ interface IHorizonStakingMain {
* @param beneficiary The address where the tokens will be withdrawn after thawing
* @return The ID of the thaw request
*/
function undelegate(
function undelegateWithBeneficiary(
address serviceProvider,
address verifier,
uint256 shares,
Expand All @@ -772,6 +773,28 @@ interface IHorizonStakingMain {
*/
function withdrawDelegated(address serviceProvider, address verifier, uint256 nThawRequests) external;

/**
* @notice Withdraw undelegated with beneficiary tokens from a provision after thawing.
* @dev The parameter `nThawRequests` can be set to a non zero value to fulfill a specific number of thaw
* requests in the event that fulfilling all of them results in a gas limit error.
* @dev If the delegation pool was completely slashed before withdrawing, calling this function will fulfill
* the thaw requests with an amount equal to zero.
*
* Requirements:
* - Must have previously initiated a thaw request using {undelegateWithBeneficiary}.
*
* Emits {ThawRequestFulfilled}, {ThawRequestsFulfilled} and {DelegatedTokensWithdrawn} events.
*
* @param serviceProvider The service provider address
* @param verifier The verifier address
* @param nThawRequests The number of thaw requests to fulfill. Set to 0 to fulfill all thaw requests.
*/
function withdrawDelegatedWithBeneficiary(
address serviceProvider,
address verifier,
uint256 nThawRequests
) external;

/**
* @notice Re-delegate undelegated tokens from a provision after thawing to a `newServiceProvider` and `newVerifier`.
* @dev The parameter `nThawRequests` can be set to a non zero value to fulfill a specific number of thaw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ interface IHorizonStakingTypes {
uint256 __DEPRECATED_tokensLockedUntil;
}

/**
* @dev Enum to specify the type of thaw request.
* @param Provision Represents a thaw request for a provision.
* @param Delegation Represents a thaw request for a delegation.
*/
enum ThawRequestType {
Provision,
Delegation,
DelegationWithBeneficiary
}

/**
* @notice Details of a stake thawing operation.
* @dev ThawRequests are stored in linked lists by service provider/delegator,
Expand All @@ -146,4 +157,26 @@ interface IHorizonStakingTypes {
// Used to invalidate unfulfilled thaw requests
uint256 thawingNonce;
}

/**
* @notice Parameters to fulfill thaw requests.
* @param requestType The type of thaw request (Provision or Delegation)
* @param serviceProvider The address of the service provider
* @param verifier The address of the verifier
* @param owner The address of the owner of the thaw request
* @param tokensThawing The current amount of tokens already thawing
* @param sharesThawing The current amount of shares already thawing
* @param nThawRequests The number of thaw requests to fulfill. If set to 0, all thaw requests are fulfilled.
* @param thawingNonce The current valid thawing nonce. Any thaw request with a different nonce is invalid and should be ignored.
*/
struct FulfillThawRequestsParams {
Maikol marked this conversation as resolved.
Show resolved Hide resolved
ThawRequestType requestType;
address serviceProvider;
address verifier;
address owner;
uint256 tokensThawing;
uint256 sharesThawing;
uint256 nThawRequests;
uint256 thawingNonce;
}
}
Loading
Loading