Skip to content

Commit da95d8b

Browse files
authored
Merge pull request #1123 from graphprotocol/tmigone/horizon-pre-audit-assesment
fix: pre-audit assessment fixes
2 parents 7bac074 + 36efdac commit da95d8b

File tree

70 files changed

+1591
-858
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1591
-858
lines changed

packages/contracts/contracts/rewards/RewardsManager.sol

-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
pragma solidity ^0.7.6;
44
pragma abicoder v2;
55

6-
import "@openzeppelin/contracts/math/SafeMath.sol";
7-
86
import "../upgrades/GraphUpgradeable.sol";
97
import "../staking/libs/MathUtils.sol";
108

119
import "./RewardsManagerStorage.sol";
12-
import "./IRewardsManager.sol";
13-
import { IRewardsIssuer } from "./IRewardsIssuer.sol";
1410

1511
/**
1612
* @title Rewards Manager Contract

packages/horizon/contracts/data-service/DataService.sol

+6-14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import { ProvisionManager } from "./utilities/ProvisionManager.sol";
2727
* will be required in the constructor.
2828
* - Note that in both cases if using {__DataService_init_unchained} variant the corresponding parent
2929
* initializers must be called in the implementation.
30+
* @custom:security-contact Please email [email protected] if you find any
31+
* bugs. We may have an active bug bounty program.
3032
*/
3133
abstract contract DataService is GraphDirectory, ProvisionManager, DataServiceV1Storage, IDataService {
3234
/**
@@ -35,38 +37,29 @@ abstract contract DataService is GraphDirectory, ProvisionManager, DataServiceV1
3537
*/
3638
constructor(address controller) GraphDirectory(controller) {}
3739

38-
/**
39-
* @notice See {IDataService-getThawingPeriodRange}.
40-
*/
40+
/// @inheritdoc IDataService
4141
function getThawingPeriodRange() external view returns (uint64, uint64) {
4242
return _getThawingPeriodRange();
4343
}
4444

45-
/**
46-
* @notice See {IDataService-getVerifierCutRange}.
47-
*/
45+
/// @inheritdoc IDataService
4846
function getVerifierCutRange() external view returns (uint32, uint32) {
4947
return _getVerifierCutRange();
5048
}
5149

52-
/**
53-
* @notice See {IDataService-getProvisionTokensRange}.
54-
*/
50+
/// @inheritdoc IDataService
5551
function getProvisionTokensRange() external view returns (uint256, uint256) {
5652
return _getProvisionTokensRange();
5753
}
5854

59-
/**
60-
* @notice See {IDataService-getDelegationRatio}.
61-
*/
55+
/// @inheritdoc IDataService
6256
function getDelegationRatio() external view returns (uint32) {
6357
return _getDelegationRatio();
6458
}
6559

6660
/**
6761
* @notice Initializes the contract and any parent contracts.
6862
*/
69-
// solhint-disable-next-line func-name-mixedcase
7063
function __DataService_init() internal onlyInitializing {
7164
__ProvisionManager_init_unchained();
7265
__DataService_init_unchained();
@@ -75,6 +68,5 @@ abstract contract DataService is GraphDirectory, ProvisionManager, DataServiceV1
7568
/**
7669
* @notice Initializes the contract.
7770
*/
78-
// solhint-disable-next-line func-name-mixedcase
7971
function __DataService_init_unchained() internal onlyInitializing {}
8072
}

packages/horizon/contracts/data-service/DataServiceStorage.sol

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22
pragma solidity 0.8.27;
33

4+
/**
5+
* @title DataServiceStorage
6+
* @dev This contract holds the storage variables for the DataService contract.
7+
* @custom:security-contact Please email [email protected] if you find any
8+
* bugs. We may have an active bug bounty program.
9+
*/
410
abstract contract DataServiceV1Storage {
511
/// @dev Gap to allow adding variables in future upgrades
612
/// Note that this contract is not upgradeable but might be inherited by an upgradeable contract

packages/horizon/contracts/data-service/extensions/DataServiceFees.sol

+12-5
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import { DataServiceFeesV1Storage } from "./DataServiceFeesStorage.sol";
1616
* using a Horizon provision. See {IDataServiceFees} for more details.
1717
* @dev This contract inherits from {DataService} which needs to be initialized, please see
1818
* {DataService} for detailed instructions.
19+
* @custom:security-contact Please email [email protected] if you find any
20+
* bugs. We may have an active bug bounty program.
1921
*/
2022
abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDataServiceFees {
2123
using ProvisionTracker for mapping(address => uint256);
2224
using LinkedList for LinkedList.List;
2325

24-
/**
25-
* @notice See {IDataServiceFees-releaseStake}
26-
*/
26+
/// @inheritdoc IDataServiceFees
2727
function releaseStake(uint256 numClaimsToRelease) external virtual override {
2828
_releaseStake(msg.sender, numClaimsToRelease);
2929
}
@@ -42,7 +42,7 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
4242
*/
4343
function _lockStake(address _serviceProvider, uint256 _tokens, uint256 _unlockTimestamp) internal {
4444
require(_tokens != 0, DataServiceFeesZeroTokens());
45-
feesProvisionTracker.lock(_graphStaking(), _serviceProvider, _tokens, delegationRatio);
45+
feesProvisionTracker.lock(_graphStaking(), _serviceProvider, _tokens, _delegationRatio);
4646

4747
LinkedList.List storage claimsList = claimsLists[_serviceProvider];
4848

@@ -61,7 +61,11 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
6161
}
6262

6363
/**
64-
* @notice See {IDataServiceFees-releaseStake}
64+
* @notice Releases expired stake claims for a service provider.
65+
* @dev This function can be overriden and/or disabled.
66+
* @dev Emits a {StakeClaimsReleased} event, and a {StakeClaimReleased} event for each claim released.
67+
* @param _serviceProvider The address of the service provider
68+
* @param _numClaimsToRelease Amount of stake claims to process. If 0, all stake claims are processed.
6569
*/
6670
function _releaseStake(address _serviceProvider, uint256 _numClaimsToRelease) internal {
6771
LinkedList.List storage claimsList = claimsLists[_serviceProvider];
@@ -116,6 +120,7 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
116120
/**
117121
* @notice Gets the details of a stake claim
118122
* @param _claimId The ID of the stake claim
123+
* @return The stake claim details
119124
*/
120125
function _getStakeClaim(bytes32 _claimId) private view returns (StakeClaim memory) {
121126
StakeClaim memory claim = claims[_claimId];
@@ -127,6 +132,7 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
127132
* @notice Gets the next stake claim in the linked list
128133
* @dev This function is used as a callback in the stake claims linked list traversal.
129134
* @param _claimId The ID of the stake claim
135+
* @return The next stake claim ID
130136
*/
131137
function _getNextStakeClaim(bytes32 _claimId) private view returns (bytes32) {
132138
return claims[_claimId].nextClaim;
@@ -136,6 +142,7 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
136142
* @notice Builds a stake claim ID
137143
* @param _serviceProvider The address of the service provider
138144
* @param _nonce A nonce of the stake claim
145+
* @return The stake claim ID
139146
*/
140147
function _buildStakeClaimId(address _serviceProvider, uint256 _nonce) private view returns (bytes32) {
141148
return keccak256(abi.encodePacked(address(this), _serviceProvider, _nonce));

packages/horizon/contracts/data-service/extensions/DataServiceFeesStorage.sol

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { LinkedList } from "../../libraries/LinkedList.sol";
77

88
/**
99
* @title Storage layout for the {DataServiceFees} extension contract.
10+
* @custom:security-contact Please email [email protected] if you find any
11+
* bugs. We may have an active bug bounty program.
1012
*/
1113
abstract contract DataServiceFeesV1Storage {
1214
mapping(address serviceProvider => uint256 tokens) public feesProvisionTracker;

packages/horizon/contracts/data-service/extensions/DataServicePausable.sol

+4-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { DataService } from "../DataService.sol";
1616
* guardians. This should be implemented in the derived contract.
1717
* @dev This contract inherits from {DataService} which needs to be initialized, please see
1818
* {DataService} for detailed instructions.
19+
* @custom:security-contact Please email [email protected] if you find any
20+
* bugs. We may have an active bug bounty program.
1921
*/
2022
abstract contract DataServicePausable is Pausable, DataService, IDataServicePausable {
2123
/// @notice List of pause guardians and their allowed status
@@ -29,26 +31,19 @@ abstract contract DataServicePausable is Pausable, DataService, IDataServicePaus
2931
_;
3032
}
3133

32-
/**
33-
* @notice See {IDataServicePausable-pause}
34-
*/
34+
/// @inheritdoc IDataServicePausable
3535
function pause() external override onlyPauseGuardian whenNotPaused {
3636
_pause();
3737
}
3838

39-
/**
40-
* @notice See {IDataServicePausable-pause}
41-
*/
39+
/// @inheritdoc IDataServicePausable
4240
function unpause() external override onlyPauseGuardian whenPaused {
4341
_unpause();
4442
}
4543

4644
/**
4745
* @notice Sets a pause guardian.
4846
* @dev Internal function to be used by the derived contract to set pause guardians.
49-
*
50-
* Emits a {PauseGuardianSet} event.
51-
*
5247
* @param _pauseGuardian The address of the pause guardian
5348
* @param _allowed The allowed status of the pause guardian
5449
*/

packages/horizon/contracts/data-service/extensions/DataServicePausableUpgradeable.sol

+4-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { DataService } from "../DataService.sol";
1212
* @dev Upgradeable version of the {DataServicePausable} contract.
1313
* @dev This contract inherits from {DataService} which needs to be initialized, please see
1414
* {DataService} for detailed instructions.
15+
* @custom:security-contact Please email [email protected] if you find any
16+
* bugs. We may have an active bug bounty program.
1517
*/
1618
abstract contract DataServicePausableUpgradeable is PausableUpgradeable, DataService, IDataServicePausable {
1719
/// @notice List of pause guardians and their allowed status
@@ -28,24 +30,19 @@ abstract contract DataServicePausableUpgradeable is PausableUpgradeable, DataSer
2830
_;
2931
}
3032

31-
/**
32-
* @notice See {IDataServicePausable-pause}
33-
*/
33+
/// @inheritdoc IDataServicePausable
3434
function pause() external override onlyPauseGuardian whenNotPaused {
3535
_pause();
3636
}
3737

38-
/**
39-
* @notice See {IDataServicePausable-pause}
40-
*/
38+
/// @inheritdoc IDataServicePausable
4139
function unpause() external override onlyPauseGuardian whenPaused {
4240
_unpause();
4341
}
4442

4543
/**
4644
* @notice Initializes the contract and parent contracts
4745
*/
48-
// solhint-disable-next-line func-name-mixedcase
4946
function __DataServicePausable_init() internal onlyInitializing {
5047
__Pausable_init_unchained();
5148
__DataServicePausable_init_unchained();
@@ -54,7 +51,6 @@ abstract contract DataServicePausableUpgradeable is PausableUpgradeable, DataSer
5451
/**
5552
* @notice Initializes the contract
5653
*/
57-
// solhint-disable-next-line func-name-mixedcase
5854
function __DataServicePausable_init_unchained() internal onlyInitializing {}
5955

6056
/**

packages/horizon/contracts/data-service/extensions/DataServiceRescuable.sol

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
1919
* rescuers. This should be implemented in the derived contract.
2020
* @dev This contract inherits from {DataService} which needs to be initialized, please see
2121
* {DataService} for detailed instructions.
22+
* @custom:security-contact Please email [email protected] if you find any
23+
* bugs. We may have an active bug bounty program.
2224
*/
2325
abstract contract DataServiceRescuable is DataService, IDataServiceRescuable {
2426
/// @notice List of rescuers and their allowed status
@@ -36,16 +38,12 @@ abstract contract DataServiceRescuable is DataService, IDataServiceRescuable {
3638
_;
3739
}
3840

39-
/**
40-
* @notice See {IDataServiceRescuable-rescueGRT}
41-
*/
41+
/// @inheritdoc IDataServiceRescuable
4242
function rescueGRT(address to, uint256 tokens) external virtual onlyRescuer {
4343
_rescueTokens(to, address(_graphToken()), tokens);
4444
}
4545

46-
/**
47-
* @notice See {IDataServiceRescuable-rescueETH}
48-
*/
46+
/// @inheritdoc IDataServiceRescuable
4947
function rescueETH(address payable to, uint256 tokens) external virtual onlyRescuer {
5048
_rescueTokens(to, Denominations.NATIVE_TOKEN, tokens);
5149
}

packages/horizon/contracts/data-service/interfaces/IDataService.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { IGraphPayments } from "../../interfaces/IGraphPayments.sol";
1212
* the implementation code and the documentation.
1313
* @dev This interface is expected to be inherited and extended by a data service interface. It can be
1414
* used to interact with it however it's advised to use the more specific parent interface.
15+
* @custom:security-contact Please email [email protected] if you find any
16+
* bugs. We may have an active bug bounty program.
1517
*/
1618
interface IDataService {
1719
/**
@@ -110,7 +112,6 @@ interface IDataService {
110112
* @notice Collects payment earnt by the service provider.
111113
* @dev The implementation of this function is expected to interact with {GraphPayments}
112114
* to collect payment from the service payer, which is done via {IGraphPayments-collect}.
113-
* @param serviceProvider The address of the service provider.
114115
*
115116
* Emits a {ServicePaymentCollected} event.
116117
*

packages/horizon/contracts/data-service/interfaces/IDataServiceFees.sol

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,24 @@ import { IDataService } from "./IDataService.sol";
1818
* @dev Note that this implementation uses the entire provisioned stake as collateral for the payment.
1919
* It can be used to provide economic security for the payments collected as long as the provisioned
2020
* stake is not being used for other purposes.
21+
* @custom:security-contact Please email [email protected] if you find any
22+
* bugs. We may have an active bug bounty program.
2123
*/
2224
interface IDataServiceFees is IDataService {
2325
/**
2426
* @notice A stake claim, representing provisioned stake that gets locked
2527
* to be released to a service provider.
2628
* @dev StakeClaims are stored in linked lists by service provider, ordered by
2729
* creation timestamp.
30+
* @param tokens The amount of tokens to be locked in the claim
31+
* @param createdAt The timestamp when the claim was created
32+
* @param releasableAt The timestamp when the tokens can be released
33+
* @param nextClaim The next claim in the linked list
2834
*/
2935
struct StakeClaim {
30-
// The amount of tokens to be locked in the claim
3136
uint256 tokens;
32-
// Timestamp when the claim was created
3337
uint256 createdAt;
34-
// Timestamp when the claim will expire and tokens can be released
3538
uint256 releasableAt;
36-
// Next claim in the linked list
3739
bytes32 nextClaim;
3840
}
3941

@@ -75,6 +77,7 @@ interface IDataServiceFees is IDataService {
7577

7678
/**
7779
* @notice Thrown when attempting to get a stake claim that does not exist.
80+
* @param claimId The id of the stake claim
7881
*/
7982
error DataServiceFeesClaimNotFound(bytes32 claimId);
8083

packages/horizon/contracts/data-service/interfaces/IDataServicePausable.sol

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { IDataService } from "./IDataService.sol";
88
* @notice Extension for the {IDataService} contract, adds pausing functionality
99
* to the data service. Pausing is controlled by privileged accounts called
1010
* pause guardians.
11+
* @custom:security-contact Please email [email protected] if you find any
12+
* bugs. We may have an active bug bounty program.
1113
*/
1214
interface IDataServicePausable is IDataService {
1315
/**

packages/horizon/contracts/data-service/interfaces/IDataServiceRescuable.sol

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { IDataService } from "./IDataService.sol";
77
* @title Interface for the {IDataServicePausable} contract.
88
* @notice Extension for the {IDataService} contract, adds the ability to rescue
99
* any ERC20 token or ETH from the contract, controlled by a rescuer privileged role.
10+
* @custom:security-contact Please email [email protected] if you find any
11+
* bugs. We may have an active bug bounty program.
1012
*/
1113
interface IDataServiceRescuable is IDataService {
1214
/**
@@ -20,6 +22,8 @@ interface IDataServiceRescuable is IDataService {
2022

2123
/**
2224
* @notice Emitted when a rescuer is set.
25+
* @param account The address of the rescuer
26+
* @param allowed Whether the rescuer is allowed to rescue tokens
2327
*/
2428
event RescuerSet(address indexed account, bool allowed);
2529

@@ -30,6 +34,7 @@ interface IDataServiceRescuable is IDataService {
3034

3135
/**
3236
* @notice Thrown when the caller is not a rescuer.
37+
* @param account The address of the account that attempted the rescue
3338
*/
3439
error DataServiceRescuableNotRescuer(address account);
3540

packages/horizon/contracts/data-service/libraries/ProvisionTracker.sol

+5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ import { IHorizonStaking } from "../../interfaces/IHorizonStaking.sol";
1010
* their services.
1111
* The library provides two primitives, lock and release to signal token usage and free up tokens respectively. It
1212
* does not make any assumptions about the conditions under which tokens are locked or released.
13+
* @custom:security-contact Please email [email protected] if you find any
14+
* bugs. We may have an active bug bounty program.
1315
*/
1416
library ProvisionTracker {
1517
/**
1618
* @notice Thrown when trying to lock more tokens than available
19+
* @param tokensAvailable The amount of tokens available
20+
* @param tokensRequired The amount of tokens required
1721
*/
1822
error ProvisionTrackerInsufficientTokens(uint256 tokensAvailable, uint256 tokensRequired);
1923

@@ -62,6 +66,7 @@ library ProvisionTracker {
6266
* @param graphStaking The HorizonStaking contract
6367
* @param serviceProvider The service provider address
6468
* @param delegationRatio A delegation ratio to limit the amount of delegation that's usable
69+
* @return true if the service provider has enough tokens available to lock, false otherwise
6570
*/
6671
function check(
6772
mapping(address => uint256) storage self,

0 commit comments

Comments
 (0)