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? (%)
Contracts for specific vaults are listed on each strategy's webpage.
2. How active is the primary contract? (%)
Their most recent strategy has well over 10 interactions in the past day.
3. Does the protocol have a public software repository? (Y/N)
Location: https://github.com/beefyfinance
4. Is there a development history visible? (%)
At 810 commits at 74 branches, this development history has been around since before the cows came home.
5. Is the team public (not anonymous)?
Beefy has both public and anonymous team members. Given that two are public and confirm their contributions, we will award 100%.
This section looks at the software documentation. The document explaining these questions is here.
6. Is there a whitepaper? (Y/N)
Location: https://docs.beefy.finance/
7. Is the protocol's software architecture documented? (Y/N)
Beefy documents no software architecture. While some yield farming diagrams are documented, they relate to fee programs and not specific contracts and how they interact with each other. On a strategy level, there is no clear documentation relating to how they operate.
8. Does the software documentation fully cover the deployed contracts' source code? (%)
There is no 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 no traceability between software documentation and implemented code. While there is good traceability on many different aspects of this protocol, there is nothing relating to software function documentation on contracts.
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 4% 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. This TtC is incredibly low given the stated vault testing procedure in their documentation. In addition, given each vault is the exact same, there is questionable value in documenting each vault's testing with the same test scripts.
11. How covered is the protocol's code? (%)
Beefy has a high relative TtC, meaning we will award 50% here.
12. Does the protocol provide scripts and instructions to run their tests? (Y/N)
Scripts/Instructions location: https://github.com/beefyfinance/beefy-contracts#3-test-the-contracts
13. Is there a detailed report of the protocol's test results?(%)
No test report is documented in their GitHub repository.
14. Has the protocol undergone Formal Verification? (Y/N)
Beefy has not undergone formal verification.
15. Were the smart contracts deployed to a testnet? (Y/N)
Beefy has been deployed to a testnet. Here is a vault.
This section looks at the 3rd party software audits done. It is explained in this document.
16. Is the protocol sufficiently audited? (%)
Beefy has undergone multiple audits. These were post deployment. Their first "audit" was not an audit - it is a smart contract analysis. Their second and third audit was conducted by CertiK. Beefy uses V6 vaults - the most recent audit had V4 vaults in scope. Nevertheless, given the highly fluid nature of yield aggregator contract deployment, we will award points for this. Still, it is time to update these audits or even enter into a continual audit agreement with a firm.
17. Is the bounty value acceptably high (%)
This protocol offers an active bug bounty of $75K
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 is detailed in Beefy's documentation.
19. Are relevant contracts clearly labelled as upgradeable or immutable? (%)
The relevant contracts are identified as immutable. All vaults / strategies are immutable.
20. Is the type of smart contract ownership clearly indicated? (%)
The contracts are not owned by anyone.
21. Are the protocol's smart contract change capabilities described? (%)
Smart contracts cannot change, as identified here.
22. Is the protocol's admin control information easy to understand? (%)
This information is in simple language.
23. Is there sufficient Pause Control documentation? (%)
Beefy does not use a pause control because it is immutable.
24. Is there sufficient Timelock documentation? (%)
This protocol has some timelock documentation which can be found at this location. Each relevant contract is identified. There is a justification as to why 6 hours was chosen.
25. Is the Timelock of an adequate length? (Y/N)
The timelock is justified at 6 hours for reasons of agility.
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. These questions are explained in this document.
26. Is the protocol's Oracle sufficiently documented? (%)
Beefy does not use an oracle, and this is stated and explained in this location.
27. Is front running mitigated by this protocol? (Y/N)
This protocol documents no front running mitigation techniques in their strategies.
28. Can flashloan attacks be applied to the protocol, and if so, are those flashloan attack risks mitigated? (Y/N)
Beefy is not susceptible to flashloan attack, and this is explained in their documentation.
1// SPDX-License-Identifier: MIT
2
3pragma solidity ^0.6.0;
4
5import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
6import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
7import "@openzeppelin/contracts/math/SafeMath.sol";
8import "@openzeppelin/contracts/access/Ownable.sol";
9import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
10
11import "../interfaces/beefy/IStrategy.sol";
12
13/**
14 * @dev Implementation of a vault to deposit funds for yield optimizing.
15 * This is the contract that receives funds and that users interface with.
16 * The yield optimizing strategy itself is implemented in a separate 'Strategy.sol' contract.
17 */
18contract BeefyVaultV6 is ERC20, Ownable, ReentrancyGuard {
19 using SafeERC20 for IERC20;
20 using SafeMath for uint256;
21
22 struct StratCandidate {
23 address implementation;
24 uint proposedTime;
25 }
26
27 // The last proposed strategy to switch to.
28 StratCandidate public stratCandidate;
29 // The strategy currently in use by the vault.
30 IStrategy public strategy;
31 // The minimum time it has to pass before a strat candidate can be approved.
32 uint256 public immutable approvalDelay;
33
34 event NewStratCandidate(address implementation);
35 event UpgradeStrat(address implementation);
36
37 /**
38 * @dev Sets the value of {token} to the token that the vault will
39 * hold as underlying value. It initializes the vault's own 'moo' token.
40 * This token is minted when someone does a deposit. It is burned in order
41 * to withdraw the corresponding portion of the underlying assets.
42 * @param _strategy the address of the strategy.
43 * @param _name the name of the vault token.
44 * @param _symbol the symbol of the vault token.
45 * @param _approvalDelay the delay before a new strat can be approved.
46 */
47 constructor (
48 IStrategy _strategy,
49 string memory _name,
50 string memory _symbol,
51 uint256 _approvalDelay
52 ) public ERC20(
53 _name,
54 _symbol
55 ) {
56 strategy = _strategy;
57 approvalDelay = _approvalDelay;
58 }
59
60 function want() public view returns (IERC20) {
61 return IERC20(strategy.want());
62 }
63
64 /**
65 * @dev It calculates the total underlying value of {token} held by the system.
66 * It takes into account the vault contract balance, the strategy contract balance
67 * and the balance deployed in other contracts as part of the strategy.
68 */
69 function balance() public view returns (uint) {
70 return want().balanceOf(address(this)).add(IStrategy(strategy).balanceOf());
71 }
72
73 /**
74 * @dev Custom logic in here for how much the vault allows to be borrowed.
75 * We return 100% of tokens for now. Under certain conditions we might
76 * want to keep some of the system funds at hand in the vault, instead
77 * of putting them to work.
78 */
79 function available() public view returns (uint256) {
80 return want().balanceOf(address(this));
81 }
82
83 /**
84 * @dev Function for various UIs to display the current value of one of our yield tokens.
85 * Returns an uint256 with 18 decimals of how much underlying asset one vault share represents.
86 */
87 function getPricePerFullShare() public view returns (uint256) {
88 return totalSupply() == 0 ? 1e18 : balance().mul(1e18).div(totalSupply());
89 }
90
91 /**
92 * @dev A helper function to call deposit() with all the sender's funds.
93 */
94 function depositAll() external {
95 deposit(want().balanceOf(msg.sender));
96 }
97
98 /**
99 * @dev The entrypoint of funds into the system. People deposit with this function
100 * into the vault. The vault is then in charge of sending funds into the strategy.
101 */
102 function deposit(uint _amount) public nonReentrant {
103 strategy.beforeDeposit();
104
105 uint256 _pool = balance();
106 want().safeTransferFrom(msg.sender, address(this), _amount);
107 earn();
108 uint256 _after = balance();
109 _amount = _after.sub(_pool); // Additional check for deflationary tokens
110 uint256 shares = 0;
111 if (totalSupply() == 0) {
112 shares = _amount;
113 } else {
114 shares = (_amount.mul(totalSupply())).div(_pool);
115 }
116 _mint(msg.sender, shares);
117 }
118
119 /**
120 * @dev Function to send funds into the strategy and put them to work. It's primarily called
121 * by the vault's deposit() function.
122 */
123 function earn() public {
124 uint _bal = available();
125 want().safeTransfer(address(strategy), _bal);
126 strategy.deposit();
127 }
128
129 /**
130 * @dev A helper function to call withdraw() with all the sender's funds.
131 */
132 function withdrawAll() external {
133 withdraw(balanceOf(msg.sender));
134 }
135
136 /**
137 * @dev Function to exit the system. The vault will withdraw the required tokens
138 * from the strategy and pay up the token holder. A proportional number of IOU
139 * tokens are burned in the process.
140 */
141 function withdraw(uint256 _shares) public {
142 uint256 r = (balance().mul(_shares)).div(totalSupply());
143 _burn(msg.sender, _shares);
144
145 uint b = want().balanceOf(address(this));
146 if (b < r) {
147 uint _withdraw = r.sub(b);
148 strategy.withdraw(_withdraw);
149 uint _after = want().balanceOf(address(this));
150 uint _diff = _after.sub(b);
151 if (_diff < _withdraw) {
152 r = b.add(_diff);
153 }
154 }
155
156 want().safeTransfer(msg.sender, r);
157 }
158
159 /**
160 * @dev Sets the candidate for the new strat to use with this vault.
161 * @param _implementation The address of the candidate strategy.
162 */
163 function proposeStrat(address _implementation) public onlyOwner {
164 require(address(this) == IStrategy(_implementation).vault(), "Proposal not valid for this Vault");
165 stratCandidate = StratCandidate({
166 implementation: _implementation,
167 proposedTime: block.timestamp
168 });
169
170 emit NewStratCandidate(_implementation);
171 }
172
173 /**
174 * @dev It switches the active strat for the strat candidate. After upgrading, the
175 * candidate implementation is set to the 0x00 address, and proposedTime to a time
176 * happening in +100 years for safety.
177 */
178
179 function upgradeStrat() public onlyOwner {
180 require(stratCandidate.implementation != address(0), "There is no candidate");
181 require(stratCandidate.proposedTime.add(approvalDelay) < block.timestamp, "Delay has not passed");
182
183 emit UpgradeStrat(stratCandidate.implementation);
184
185 strategy.retireStrat();
186 strategy = IStrategy(stratCandidate.implementation);
187 stratCandidate.implementation = address(0);
188 stratCandidate.proposedTime = 5000000000;
189
190 earn();
191 }
192
193 /**
194 * @dev Rescues random funds stuck that the strat can't handle.
195 * @param _token address of the token to rescue.
196 */
197 function inCaseTokensGetStuck(address _token) external onlyOwner {
198 require(_token != address(want()), "!token");
199
200 uint256 amount = IERC20(_token).balanceOf(address(this));
201 IERC20(_token).safeTransfer(msg.sender, amount);
202 }
203}
Tests to Code: 1366 / 30483 = 4 %