If you notice some outdated information please let us know!
PASS
The final review score is indicated as a percentage. The percentage is calculated as Achieved Points due to MAX Possible Points. For each element the answer can be either Yes/No or a percentage. For a detailed breakdown of the individual weights of each question, please consult this document.
Very simply, the audit looks for the following declarations from the developer's site. With these declarations, it is reasonable to trust the smart contracts.
This report is for informational purposes only and does not constitute investment advice of any kind, nor does it constitute an offer to provide investment advisory or other services. Nothing in this report shall be considered a solicitation or offer to buy or sell any security, token, future, option or other financial instrument or to offer or provide any investment advice or service to any person in any jurisdiction. Nothing contained in this report constitutes investment advice or offers any opinion with respect to the suitability of any security, and the views expressed in this report should not be taken as advice to buy, sell or hold any security. The information in this report should not be relied upon for the purpose of investing. In preparing the information contained in this report, we have not taken into account the investment needs, objectives and financial circumstances of any particular investor. This information has no regard to the specific investment objectives, financial situation and particular needs of any specific recipient of this information and investments discussed may not be suitable for all investors.
Any views expressed in this report by us were prepared based upon the information available to us at the time such views were written. The views expressed within this report are limited to DeFiSafety and the author and do not reflect those of any additional or third party and are strictly based upon DeFiSafety, its authors, interpretations and evaluation of relevant data. Changed or additional information could cause such views to change. All information is subject to possible correction. Information may quickly become unreliable for various reasons, including changes in market conditions or economic circumstances.
This completed report is copyright (c) DeFiSafety 2023. Permission is given to copy in whole, retaining this copyright label.
This section looks at the code deployed on the relevant chain that gets reviewed and its corresponding software repository. The document explaining these questions is here.
1. Are the smart contract addresses easy to find? (%)
Contract addresses were found in the front end. In addition, they can be located in the GitBook too.
2. How active is the primary contract? (%)
Contract use is frequently over 10 times a day. Given that this is a bug bounty program, this is extremely impressive.
3. Does the protocol have a public software repository? (Y/N)
This protocol uses GitHub.
4. Is there a development history visible? (%)
At 166 commits and 46 branches, these developers document their history as frequently as they tip (and even change) their fedoras.
5. Is the team public (not anonymous)?
No team members that cross-confirm they are contributing to Hats were found. Some contributors are public, but they do not confirm affiliation.
The difference between this and the old link is solely the link. This section looks at the software documentation. The document explaining these questions is here.
6. Is there a whitepaper? (Y/N)
Location: https://docs.hats.finance/
7. Is the protocol's software architecture documented? (Y/N)
Hat's software architecture is documented.
8. Does the software documentation fully cover the deployed contracts' source code? (%)
There is coverage of deployed contracts by software function documentation.
9. Is it possible to trace the documented software to its implementation in the protocol's source code? (%)
There is implied and non-explicit traceability between software documentation and implemented code.
10. Has the protocol tested their deployed code? (%)
Code examples are in the Appendix at the end of this report.. As per the SLOC, there is 303% testing to code (TtC). This score is guided by the Test to Code ratio (TtC). Generally a good test to code ratio is over 100%. However, the reviewer's best judgement is the final deciding factor.
11. How covered is the protocol's code? (%)
Hats has 97% coverage.
12. Does the protocol provide scripts and instructions to run their tests? (Y/N)
Scripts/Instructions location: https://github.com/hats-finance/hats-contracts#check-deployment
13. Is there a detailed report of the protocol's test results?(%)
A code coverage report is evident.
14. Has the protocol undergone Formal Verification? (Y/N)
This protocol has not undergone formal verification.
15. Were the smart contracts deployed to a testnet? (Y/N)
Hats has been deployed to a testnet. This could be more clearly documented nevertheless and users could benefit from the testnet addresses for verification.
This section looks at the 3rd party software audits done. It is explained in this document.
16. Is the protocol sufficiently audited? (%)
Hats' is audited. It underwent multiple audits, all of which were before launch.
17. Is the bounty value acceptably high (%)
Hats offers a $250K active bug bounty program. This is more than 10% of the total TVL at time of writing.
This section covers the documentation of special access controls for a DeFi protocol. The admin access controls are the contracts that allow updating contracts or coefficients in the protocol. Since these contracts can allow the protocol admins to "change the rules", complete disclosure of capabilities is vital for user's transparency. It is explained in this document.
18. Is the protocol's admin control information easy to find?
Admin control information was easy to find.
19. Are relevant contracts clearly labelled as upgradeable or immutable? (%)
The relevant contracts are clearly identified as immutable or upgradeable.
20. Is the type of smart contract ownership clearly indicated? (%)
$HAT holders will be the owners of the protocol. It is currently controlled by a Multisig.
21. Are the protocol's smart contract change capabilities described? (%)
Smart contract change capabilities are identified in this document
22. Is the protocol's admin control information easy to understand? (%)
This information is not in software specific language, aiding user comprehension.
23. Is there sufficient Pause Control documentation? (%)
Hats Finance does not use a pause control. This is explained.
24. Is there sufficient Timelock documentation? (%)
This protocol has timelock documentation. A timelock.sol is in the github repo.
25. Is the Timelock of an adequate length? (Y/N)
The timelock is 3 weeks long. This length is the default as set by OpenZeppelin.
This section goes over the documentation that a protocol may or may not supply about their Oracle usage. Oracles are a fundamental part of DeFi as they are responsible for relaying tons of price data information to thousands of protocols using blockchain technology. Not only are they important for price feeds, but they are also an essential component of transaction verification and security. This is explained in this document.
26. Is the protocol's Oracle sufficiently documented? (%)
Hats does not use an oracle, as explained here.
27. Is front running mitigated by this protocol? (Y/N)
This protocol documents good front running mitigation techniques. Bounty payouts are impossible to front run thanks to a safety period.
28. Can flashloan attacks be applied to the protocol, and if so, are those flashloan attack risks mitigated? (Y/N)
This protocol cannot undergo flashloan attacks, and this is explained in this location.
1// SPDX-License-Identifier: MIT
2// Disclaimer https://github.com/hats-finance/hats-contracts/blob/main/DISCLAIMER.md
3
4pragma solidity 0.8.6;
5
6
7import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
8import "openzeppelin-solidity/contracts/token/ERC20/utils/SafeERC20.sol";
9import "openzeppelin-solidity/contracts/utils/math/SafeMath.sol";
10import "./HATToken.sol";
11import "openzeppelin-solidity/contracts/security/ReentrancyGuard.sol";
12
13// Errors:
14// HME01: Pool range is too big
15// HME02: Invalid pool range
16// HME03: Committee not checked in yet
17// HME04: Withdraw: not enough user balance
18// HME05: User amount must be greater than 0
19// HME06: lpToken is already in pool
20contract HATMaster is ReentrancyGuard {
21 using SafeMath for uint256;
22 using SafeERC20 for IERC20;
23
24 struct UserInfo {
25 uint256 amount; // The user share of the pool based on the amount of lpToken the user has provided.
26 uint256 rewardDebt; // Reward debt. See explanation below.
27 //
28 // We do some fancy math here. Basically, any point in time, the amount of HATs
29 // entitled to a user but is pending to be distributed is:
30 //
31 // pending reward = (user.amount * pool.rewardPerShare) - user.rewardDebt
32 //
33 // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
34 // 1. The pool's `rewardPerShare` (and `lastRewardBlock`) gets updated.
35 // 2. User receives the pending reward sent to his/her address.
36 // 3. User's `amount` gets updated.
37 // 4. User's `rewardDebt` gets updated.
38 }
39
40 struct PoolUpdate {
41 uint256 blockNumber;// update blocknumber
42 uint256 totalAllocPoint; //totalAllocPoint
43 }
44
45 struct RewardsSplit {
46 //the percentage of the total reward to reward the hacker via vesting contract(claim reported)
47 uint256 hackerVestedReward;
48 //the percentage of the total reward to reward the hacker(claim reported)
49 uint256 hackerReward;
50 // the percentage of the total reward to be sent to the committee
51 uint256 committeeReward;
52 // the percentage of the total reward to be swap to HAT and to be burned
53 uint256 swapAndBurn;
54 // the percentage of the total reward to be swap to HAT and sent to governance
55 uint256 governanceHatReward;
56 // the percentage of the total reward to be swap to HAT and sent to the hacker
57 uint256 hackerHatReward;
58 }
59
60 // Info of each pool.
61 struct PoolInfo {
62 IERC20 lpToken;
63 uint256 allocPoint;
64 uint256 lastRewardBlock;
65 uint256 rewardPerShare;
66 uint256 totalUsersAmount;
67 uint256 lastProcessedTotalAllocPoint;
68 uint256 balance;
69 }
70
71 // Info of each pool.
72 struct PoolReward {
73 RewardsSplit rewardsSplit;
74 uint256[] rewardsLevels;
75 bool committeeCheckIn;
76 uint256 vestingDuration;
77 uint256 vestingPeriods;
78 }
79
80 HATToken public immutable HAT;
81 uint256 public immutable REWARD_PER_BLOCK;
82 uint256 public immutable START_BLOCK;
83 uint256 public immutable MULTIPLIER_PERIOD;
84 uint256 public constant MULTIPLIERS_LENGTH = 24;
85
86 // Info of each pool.
87 PoolInfo[] public poolInfo;
88 PoolUpdate[] public globalPoolUpdates;
89
90 // Reward Multipliers
91 uint256[24] public rewardMultipliers = [4413, 4413, 8825, 7788, 6873, 6065,
92 5353, 4724, 4169, 3679, 3247, 2865,
93 2528, 2231, 1969, 1738, 1534, 1353,
94 1194, 1054, 930, 821, 724, 639];
95 mapping(address => uint256) public poolId1; // poolId1 count from 1, subtraction 1 before using with poolInfo
96 // Info of each user that stakes LP tokens. pid => user address => info
97 mapping (uint256 => mapping (address => UserInfo)) public userInfo;
98 //pid -> PoolReward
99 mapping (uint256=>PoolReward) internal poolsRewards;
100
101 event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
102 event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
103 event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);
104 event SendReward(address indexed user, uint256 indexed pid, uint256 amount, uint256 requestedAmount);
105 event MassUpdatePools(uint256 _fromPid, uint256 _toPid);
106
107 constructor(
108 HATToken _hat,
109 uint256 _rewardPerBlock,
110 uint256 _startBlock,
111 uint256 _multiplierPeriod
112 // solhint-disable-next-line func-visibility
113 ) {
114 HAT = _hat;
115 REWARD_PER_BLOCK = _rewardPerBlock;
116 START_BLOCK = _startBlock;
117 MULTIPLIER_PERIOD = _multiplierPeriod;
118 }
119
120 /**
121 * @dev massUpdatePools - Update reward variables for all pools
122 * Be careful of gas spending!
123 * @param _fromPid update pools range from this pool id
124 * @param _toPid update pools range to this pool id
125 */
126 function massUpdatePools(uint256 _fromPid, uint256 _toPid) external {
127 require(_toPid <= poolInfo.length, "HME01");
128 require(_fromPid <= _toPid, "HME02");
129 for (uint256 pid = _fromPid; pid < _toPid; ++pid) {
130 updatePool(pid);
131 }
132 emit MassUpdatePools(_fromPid, _toPid);
133 }
134
135 function claimReward(uint256 _pid) external {
136 _deposit(_pid, 0);
137 }
138
139 function updatePool(uint256 _pid) public {
140 PoolInfo storage pool = poolInfo[_pid];
141 uint256 lastRewardBlock = pool.lastRewardBlock;
142 if (block.number <= lastRewardBlock) {
143 return;
144 }
145 uint256 totalUsersAmount = pool.totalUsersAmount;
146 uint256 lastPoolUpdate = globalPoolUpdates.length-1;
147 if (totalUsersAmount == 0) {
148 pool.lastRewardBlock = block.number;
149 pool.lastProcessedTotalAllocPoint = lastPoolUpdate;
150 return;
151 }
152 uint256 reward = calcPoolReward(_pid, lastRewardBlock, lastPoolUpdate);
153 uint256 amountCanMint = HAT.minters(address(this));
154 reward = amountCanMint < reward ? amountCanMint : reward;
155 if (reward > 0) {
156 HAT.mint(address(this), reward);
157 }
158 pool.rewardPerShare = pool.rewardPerShare.add(reward.mul(1e12).div(totalUsersAmount));
159 pool.lastRewardBlock = block.number;
160 pool.lastProcessedTotalAllocPoint = lastPoolUpdate;
161 }
162
163 /**
164 * @dev getMultiplier - multiply blocks with relevant multiplier for specific range
165 * @param _from range's from block
166 * @param _to range's to block
167 * will revert if from < START_BLOCK or _to < _from
168 */
169 function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 result) {
170 uint256 i = (_from - START_BLOCK) / MULTIPLIER_PERIOD + 1;
171 for (; i <= MULTIPLIERS_LENGTH; i++) {
172 uint256 endBlock = MULTIPLIER_PERIOD * i + START_BLOCK;
173 if (_to <= endBlock) {
174 break;
175 }
176 result += (endBlock - _from) * rewardMultipliers[i-1];
177 _from = endBlock;
178 }
179 result += (_to - _from) * (i > MULTIPLIERS_LENGTH ? 0 : rewardMultipliers[i-1]);
180 }
181
182 function getRewardForBlocksRange(uint256 _from, uint256 _to, uint256 _allocPoint, uint256 _totalAllocPoint)
183 public
184 view
185 returns (uint256 reward) {
186 if (_totalAllocPoint > 0) {
187 reward = getMultiplier(_from, _to).mul(REWARD_PER_BLOCK).mul(_allocPoint).div(_totalAllocPoint).div(100);
188 }
189 }
190
191 /**
192 * @dev calcPoolReward -
193 * calculate rewards for a pool by iterating over the history of totalAllocPoints updates.
194 * and sum up all rewards periods from pool.lastRewardBlock till current block number.
195 * @param _pid pool id
196 * @param _from block starting calculation
197 * @param _lastPoolUpdate lastPoolUpdate
198 * @return reward
199 */
200 function calcPoolReward(uint256 _pid, uint256 _from, uint256 _lastPoolUpdate) public view returns(uint256 reward) {
201 uint256 poolAllocPoint = poolInfo[_pid].allocPoint;
202 uint256 i = poolInfo[_pid].lastProcessedTotalAllocPoint;
203 for (; i < _lastPoolUpdate; i++) {
204 uint256 nextUpdateBlock = globalPoolUpdates[i+1].blockNumber;
205 reward =
206 reward.add(getRewardForBlocksRange(_from,
207 nextUpdateBlock,
208 poolAllocPoint,
209 globalPoolUpdates[i].totalAllocPoint));
210 _from = nextUpdateBlock;
211 }
212 return reward.add(getRewardForBlocksRange(_from,
213 block.number,
214 poolAllocPoint,
215 globalPoolUpdates[i].totalAllocPoint));
216 }