P
P
PQ Reviews
Search…
0.7
Trader Joe Process Quality Review

Overview

This is a TraderJoe Process Quality Review completed on the 14th of January, 2022. It was performed using the Process Review process (version 0.7.3) and is documented here. The review was performed by of DeFiSafety. Check out our Telegram.
The final score of the review is 50%, a FAIL.The breakdown of the scoring is in Scoring Appendix. For our purposes, a pass is 70%.

Summary of the Process

Very simply, the review looks for the following declarations from the developer's site. With these declarations, it is reasonable to trust the smart contracts.
  • Here are my smart contracts on the blockchain
  • Here is the documentation that explains what my smart contracts do
  • Here are the tests I ran to verify my smart contract
  • Here are the audit(s) performed on my code by third party experts
  • Here are the admin controls and strategies

Disclaimer

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 2021. Permission is given to copy in whole, retaining this copyright label.

Chain

This section indicates the blockchains used by this protocol. This report covers all of the blockchains upon which the protocol is deployed.
Chain: Avalanche
Guidance: Ethereum Binance Smart Chain Polygon Avalanche Terra Celo Arbitrum Solana

Code and Team

This section looks at the code deployed on the Mainnet that gets reviewed and its corresponding software repository. The document explaining these questions is here. This review will answer the following questions:
1) Are the executing code addresses readily available? (%) 2) Is the code actively being used? (%) 3) Is there a public software repository? (Y/N) 4) Is there a development history visible? (%) 5) Is the team public (not anonymous)? (Y/N)

1) Are the executing code addresses readily available? (%)

Answer: 100%
Contracts are easily located.
Guidance: 100% Clearly labelled and on website, docs or repo, quick to find 70% Clearly labelled and on website, docs or repo but takes a bit of looking 40% Addresses in mainnet.json, in discord or sub graph, etc 20% Address found but labeling not clear or easy to find 0% Executing addresses could not be found

2) Is the code actively being used? (%)

Answer: 100%
Joe's MasterChef V3 contract is used well over 100 times a day, as indicated in the Appendix.

Guidance:

100% More than 10 transactions a day 70% More than 10 transactions a week 40% More than 10 transactions a month 10% Less than 10 transactions a month 0% No activity

3) Is there a public software repository? (Y/N)

Answer: Yes
GitHub: Joe's software repository is on GitHub
Is there a public software repository with the code at a minimum, but also normally test and scripts. Even if the repository was created just to hold the files and has just 1 transaction, it gets a "Yes". For teams with private repositories, this answer is "No".

4) Is there a development history visible? (%)

Answer: 100%
At 382 commits and 11 branches, it's clear that Joe's trading logbook goes back some way.
This metric checks if the software repository demonstrates a strong steady history. This is normally demonstrated by commits, branches and releases in a software repository. A healthy history demonstrates a history of more than a month (at a minimum).
Guidance: 100% Any one of 100+ commits, 10+branches 70% Any one of 70+ commits, 7+branches 50% Any one of 50+ commits, 5+branches 30% Any one of 30+ commits, 3+branches 0% Less than 2 branches or less than 30 commits

5) Is the team public (not anonymous)? (Y/N)

Answer: No
For a "Yes" in this question, the real names of some team members must be public on the website or other documentation (LinkedIn, etc). If the team is anonymous, then this question is a "No".

Documentation

This section looks at the software documentation. The document explaining these questions is here.
Required questions are;
6) Is there a whitepaper? (Y/N) 7) Are the basic software functions documented? (Y/N) 8) Does the software function documentation fully (100%) cover the deployed contracts? (%) 9) Are there sufficiently detailed comments for all functions within the deployed contract code (%) 10) Is it possible to trace from software documentation to the implementation in code (%)

6) Is there a whitepaper? (Y/N)

Answer: Yes
Location: TJ has a whitepaper.

7) Are the basic software functions documented? (Y/N)

Answer: No
No software function documentation was found.

How to improve this score:

Write the document based on the deployed code. For guidance, refer to the SecurEth System Description Document.

8) Does the software function documentation fully (100%) cover the deployed contracts? (%)

Answer: 0%
No software function documentation was found.
Guidance:
100% All contracts and functions documented 80% Only the major functions documented 79-1% Estimate of the level of software documentation 0% No software documentation

How to improve this score:

This score can be improved by adding content to the software functions document such that it comprehensively covers the requirements. For guidance, refer to the SecurEth System Description Document. Using tools that aid traceability detection will help.

9) Are there sufficiently detailed comments for all functions within the deployed contract code (%)

Answer: 20%
Code examples are in the Appendix. As per the SLOC, there is 20% commenting to code (CtC).
The Comments to Code (CtC) ratio is the primary metric for this score.
Guidance: 100% CtC > 100 Useful comments consistently on all code 90-70% CtC > 70 Useful comment on most code 60-20% CtC > 20 Some useful commenting 0% CtC < 20 No useful commenting

How to improve this score

This score can improve by adding comments to the deployed code such that it comprehensively covers the code. For guidance, refer to the SecurEth Software Requirements.

10) Is it possible to trace from software documentation to the implementation in code (%)

Answer: 0%
Software functions are not listed in the documentation.
Guidance: 100% Clear explicit traceability between code and documentation at a requirement level for all code 60% Clear association between code and documents via non explicit traceability 40% Documentation lists all the functions and describes their functions 0% No connection between documentation and code

How to improve this score:

This score can improve by adding traceability from documentation to code such that it is clear where each outlined function is coded in the source code. For reference, check the SecurEth guidelines on traceability.

Testing

This section looks at the software testing available. It is explained in this document. This section answers the following questions;
11) Full test suite (Covers all the deployed code) (%) 12) Code coverage (Covers all the deployed lines of code, or explains misses) (%) 13) Scripts and instructions to run the tests (Y/N) 14) Report of the results (%) 15) Formal Verification test done (%) 16) Stress Testing environment (%)

11) Is there a Full test suite? (%)

Answer: 80%
Code examples are in the Appendix. As per the SLOC, there is 101% 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 reviewers best judgement is the final deciding factor.
Guidance: 100% TtC > 120% Both unit and system test visible 80% TtC > 80% Both unit and system test visible 40% TtC < 80% Some tests visible 0% No tests obvious

How to improve this score:

This score can improved by adding tests to fully cover the code. Document what is covered by traceability or test results in the software repository.

12) Code coverage (Covers all the deployed lines of code, or explains misses) (%)

Answer: 50%
No code coverage report was found, but there's clearly some good testing on this protocol.
Guidance: 100% Documented full coverage 99-51% Value of test coverage from documented results 50% No indication of code coverage but clearly there is a reasonably complete set of tests 30% Some tests evident but not complete 0% No test for coverage seen

How to improve this score:

This score can improved by adding tests that achieve full code coverage. A clear report and scripts in the software repository will guarantee a high score.

13) Scripts and instructions to run the tests (Y/N)

Answer: No
No test scripts were clearly labelled in the GitHub repo or the docs.

How to improve this score:

Add the scripts to the repository and ensure they work. Ask an outsider to create the environment and run the tests. Improve the scripts and docs based on their feedback.

14) Report of the results (%)

Answer: 0%
No report is evident.
Guidance: 100% Detailed test report as described below 70% GitHub code coverage report visible 0% No test report evident

How to improve this score

Add a report with the results. The test scripts should generate the report or elements of it.

15) Formal Verification test done (%)

Answer: 0%
Trader Joe has not undergone formal verification.

16) Stress Testing environment (%)

Answer: 100%
Evidence of testing on a testnet is documented. This should be elaborated upon nonetheless.

Security

This section looks at the 3rd party software audits done. It is explained in this document. This section answers the following questions;
17) Did 3rd Party audits take place? (%) 18) Is the bounty value acceptably high?

17) Did 3rd Party audits take place? (%)

Answer: 80%
TraderJoe V1 was deployed before it's single audit.
Guidance: 100% Multiple Audits performed before deployment and results public and implemented or not required 90% Single audit performed before deployment and results public and implemented or not required 70% Audit(s) performed after deployment and no changes required. Audit report is public
50% Audit(s) performed after deployment and changes needed but not implemented 20% No audit performed 0% Audit Performed after deployment, existence is public, report is not public and no improvements deployed OR smart contract address' not found, (where question 1 is 0%)
Deduct 25% if code is in a private repo and no note from auditors that audit is applicable to deployed code

18) Is the bounty value acceptably high (%)

Answer: 90%
Joe offers 500K through Immunefi.
Guidance:
100% Bounty is 10% TVL or at least $1M AND active program (see below) 90% Bounty is 5% TVL or at least 500k AND active program 80% Bounty is 5% TVL or at least 500k 70% Bounty is 100k or over AND active program 60% Bounty is 100k or over 50% Bounty is 50k or over AND active program 40% Bounty is 50k or over 20% Bug bounty program bounty is less than 50k 0% No bug bounty program offered
An active program means that a third party (such as Immunefi) is actively driving hackers to the site. An inactive program would be static mentions on the docs.

Access Controls

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. The questions this section asks are as follow;
19) Can a user clearly and quickly find the status of the admin controls? 20) Is the information clear and complete? 21) Is the information in non-technical terms that pertain to the investments? 22) Is there Pause Control documentation including records of tests?

19) Can a user clearly and quickly find the status of the access controls (%)

Answer: 0%
There is no admin control information.
Guidance: 100% Clearly labelled and on website, docs or repo, quick to find 70% Clearly labelled and on website, docs or repo but takes a bit of looking 40% Access control docs in multiple places and not well labelled 20% Access control docs in multiple places and not labelled 0% Admin Control information could not be found

20) Is the information clear and complete (%)

Answer: 0%
There is no admin control information.
Guidance: All the contracts are immutable -- 100% OR
a) All contracts are clearly labelled as upgradeable (or not) -- 30% AND b) The type of ownership is clearly indicated (OnlyOwner / MultiSig / Defined Roles) -- 30% AND c) The capabilities for change in the contracts are described -- 30%

How to improve this score:

Create a document that covers the items described above. An example is enclosed.

21) Is the information in non-technical terms that pertain to the investments (%)

Answer: 0%
There is no admin control information.
Guidance: 100% All the contracts are immutable 90% Description relates to investments safety and updates in clear, complete non-software l language 30% Description all in software specific language 0% No admin control information could not be found

How to improve this score:

Create a document that covers the items described above in plain language that investors can understand. An example is enclosed.

22) Is there Pause Control documentation including records of tests (%)

Answer: 0%
No pause control information was found.
Guidance: 100% All the contracts are immutable or no pause control needed and this is explained OR 100% Pause control(s) are clearly documented and there is records of at least one test within 3 months 80% Pause control(s) explained clearly but no evidence of regular tests 40% Pause controls mentioned with no detail on capability or tests 0% Pause control not documented or explained

How to improve this score:

Create a document that covers the items described above in plain language that investors can understand. An example is enclosed.

Appendices

Author Details

The author of this review is Rex of DeFi Safety.
Email : [email protected] Twitter : @defisafety
I started with Ethereum just before the DAO and that was a wonderful education. It showed the importance of code quality. The second Parity hack also showed the importance of good process. Here my aviation background offers some value. Aerospace knows how to make reliable code using quality processes.
I was coaxed to go to EthDenver 2018 and there I started SecuEth.org with Bryant and Roman. We created guidelines on good processes for blockchain code development. We got EthFoundation funding to assist in their development.
Process Quality Reviews are an extension of the SecurEth guidelines that will further increase the quality processes in Solidity and Vyper development.
DeFiSafety is my full time gig and we are working on funding vehicles for a permanent staff.

Scoring Appendix

Executing Code Appendix

Code Used Appendix

Example Code Appendix

1
// SPDX-License-Identifier: MIT
2
3
// P1 - P3: OK
4
pragma solidity 0.6.12;
5
6
import "./libraries/SafeMath.sol";
7
import "./libraries/SafeERC20.sol";
8
9
import "./traderjoe/interfaces/IERC20.sol";
10
import "./traderjoe/interfaces/IJoePair.sol";
11
import "./traderjoe/interfaces/IJoeFactory.sol";
12
13
import "@openzeppelin/contracts/access/Ownable.sol";
14
15
// JoeMakerV3 is MasterJoe's left hand and kinda a wizard. He can cook up Joe from pretty much anything!
16
// This contract handles "serving up" rewards for xJoe holders by trading tokens collected from fees for Joe.
17
18
// T1 - T4: OK
19
contract JoeMakerV3 is Ownable {
20
using SafeMath for uint256;
21
using SafeERC20 for IERC20;
22
23
IJoeFactory public immutable factory;
24
25
address public immutable bar;
26
address private immutable joe;
27
address private immutable wavax;
28
uint256 public devCut = 0; // in basis points aka parts per 10,000 so 5000 is 50%, cap of 50%, default is 0
29
address public devAddr;
30
31
// set of addresses that can perform certain functions
32
mapping(address => bool) public isAuth;
33
address[] public authorized;
34
bool public anyAuth = false;
35
36
modifier onlyAuth() {
37
require(isAuth[msg.sender] || anyAuth, "JoeMakerV3: FORBIDDEN");
38
_;
39
}
40
41
// V1 - V5: OK
42
mapping(address => address) internal _bridges;
43
44
event SetDevAddr(address _addr);
45
event SetDevCut(uint256 _amount);
46
event LogBridgeSet(address indexed token, address indexed bridge);
47
event LogConvert(
48
address indexed server,
49
address indexed token0,
50
address indexed token1,
51
uint256 amount0,
52
uint256 amount1,
53
uint256 amountJOE
54
);
55
56
constructor(
57
address _factory,
58
address _bar,
59
address _joe,
60
address _wavax
61
) public {
62
factory = IJoeFactory(_factory);
63
bar = _bar;
64
joe = _joe;
65
wavax = _wavax;
66
devAddr = msg.sender;
67
isAuth[msg.sender] = true;
68
authorized.push(msg.sender);
69
}
70
71
// Begin Owner functions
72
function addAuth(address _auth) external onlyOwner {
73
isAuth[_auth] = true;
74
authorized.push(_auth);
75
}
76
77
function revokeAuth(address _auth) external onlyOwner {
78
isAuth[_auth] = false;
79
}
80
81
// setting anyAuth to true allows anyone to call functions protected by onlyAuth
82
function setAnyAuth(bool access) external onlyOwner {
83
anyAuth = access;
84
}
85
86
function setBridge(address token, address bridge) external onlyOwner {
87
// Checks
88
require(token != joe && token != wavax && token != bridge, "JoeMakerV3: Invalid bridge");
89
90
// Effects
91
_bridges[token] = bridge;
92
emit LogBridgeSet(token, bridge);
93
}
94
95
function setDevCut(uint256 _amount) external onlyOwner {
96
require(_amount <= 5000, "setDevCut: cut too high");
97
devCut = _amount;
98
99
emit SetDevCut(_amount);
100
}
101
102
function setDevAddr(address _addr) external onlyOwner {
103
require(_addr != address(0), "setDevAddr, address cannot be zero address");
104
devAddr = _addr;
105
106
emit SetDevAddr(_addr);
107
}
108
109
// End owner functions
110
111
function bridgeFor(address token) public view returns (address bridge) {
112
bridge = _bridges[token];
113
if (bridge == address(0)) {
114
bridge = wavax;
115
}
116
}
117
118
// C6: It's not a fool proof solution, but it prevents flash loans, so here it's ok to use tx.origin
119
modifier onlyEOA() {
120
// Try to make flash-loan exploit harder to do by only allowing externally owned addresses.
121
require(msg.sender == tx.origin, "JoeMakerV3: must use EOA");
122
_;
123
}
124
125
// F1 - F10: OK
126
// F3: _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple
127
// F6: There is an exploit to add lots of JOE to the bar, run convert, then remove the JOE again.
128
// As the size of the JoeBar has grown, this requires large amounts of funds and isn't super profitable anymore
129
// The onlyEOA modifier prevents this being done with a flash loan.
130
// C1 - C24: OK
131
function convert(address token0, address token1) external onlyEOA onlyAuth {
132
_convert(token0, token1);
133
}
134
135
// F1 - F10: OK, see convert
136
// C1 - C24: OK
137
// C3: Loop is under control of the caller
138
function convertMultiple(address[] calldata token0, address[] calldata token1) external onlyEOA onlyAuth {
139
// TODO: This can be optimized a fair bit, but this is safer and simpler for now
140
uint256 len = token0.length;
141
for (uint256 i = 0; i < len; i++) {
142
_convert(token0[i], token1[i]);
143
}
144
}
145
146
// F1 - F10: OK
147
// C1- C24: OK
148
function _convert(address token0, address token1) internal {
149
uint256 amount0;
150
uint256 amount1;
151
152
// handle case where non-LP tokens need to be converted
153
if (token0 == token1) {
154
amount0 = IERC20(token0).balanceOf(address(this));
155
amount1 = 0;
156
} else {
157
IJoePair pair = IJoePair(factory.getPair(token0, token1));
158
require(address(pair) != address(0), "JoeMakerV3: Invalid pair");
159
160
IERC20(address(pair)).safeTransfer(address(pair), pair.balanceOf(address(this)));
161
162
// take balance of tokens in this contract before burning the pair, incase there are already some here
163
uint256 tok0bal = IERC20(token0).balanceOf(address(this));
164
uint256 tok1bal = IERC20(token1).balanceOf(address(this));
165
166
pair.burn(address(this));
167
168
// subtract old balance of tokens from new balance
169
// the return values of pair.burn cant be trusted due to transfer tax tokens
170
amount0 = IERC20(token0).balanceOf(address(this)).sub(tok0bal);
171
amount1 = IERC20(token1).balanceOf(address(this)).sub(tok1bal);
172
}
173
emit LogConvert(msg.sender, token0, token1, amount0, amount1, _convertStep(token0, token1, amount0, amount1));
174
}
175
176
// F1 - F10: OK
177
// C1 - C24: OK
178
// All safeTransfer, _swap, _toJOE, _convertStep: X1 - X5: OK
179
function _convertStep(
180
address token0,
181
address token1,
182
uint256 amount0,
183
uint256 amount1
184
) internal returns (uint256 joeOut) {
185
// Interactions
186
if (token0 == token1) {
187
uint256 amount = amount0.add(amount1);
188
if (token0 == joe) {
189
IERC20(joe).safeTransfer(bar, amount);
190
joeOut = amount;
191
} else if (token0 == wavax) {
192
joeOut = _toJOE(wavax, amount);
193
} else {
194
address bridge = bridgeFor(token0);
195
amount = _swap(token0, bridge, amount, address(this));
196
joeOut = _convertStep(bridge, bridge, amount, 0);
197
}
198
} else if (token0 == joe) {
199
// eg. JOE - AVAX
200
IERC20(joe).safeTransfer(bar, amount0);
201
joeOut = _toJOE(token1, amount1).add(amount0);
202
} else if (token1 == joe) {
203
// eg. USDT - JOE
204
IERC20(joe).safeTransfer(bar, amount1);
205
joeOut = _toJOE(token0, amount0).add(amount1);
206
} else if (token0 == wavax) {
207
// eg. AVAX - USDC
208
joeOut = _toJOE(wavax, _swap(token1, wavax, amount1, address(this)).add(amount0));
209
} else if (token1 == wavax) {
210
// eg. USDT - AVAX
211
joeOut = _toJOE(wavax, _swap(token0, wavax, amount0, address(this)).add(amount1));
212
} else {
213
// eg. MIC - USDT
214
address bridge0 = bridgeFor(token0);
215
address bridge1 = bridgeFor(token1);
216
if (bridge0 == token1) {
217
// eg. MIC - USDT - and bridgeFor(MIC) = USDT
218
joeOut = _convertStep(bridge0, token1, _swap(token0, bridge0, amount0, address(this)), amount1);
219
} else if (bridge1 == token0) {
220
// eg. WBTC - DSD - and bridgeFor(DSD) = WBTC
221
joeOut = _convertStep(token0, bridge1, amount0, _swap(token1, bridge1, amount1, address(this)));
222
} else {
223
joeOut = _convertStep(
224
bridge0,
225
bridge1, // eg. USDT - DSD - and bridgeFor(DSD) = WBTC
226
_swap(token0, bridge0, amount0, address(this)),
227
_swap(token1, bridge1, amount1, address(this))
228
);
229
}
230
}
231
}
232
233
// F1 - F10: OK
234
// C1 - C24: OK
235
// All safeTransfer, swap: X1 - X5: OK
236
function _swap(
237
address fromToken,
238
address toToken,
239
uint256 amountIn,
240
address to
241
) internal returns (uint256 amountOut) {
242
// Checks
243
// X1 - X5: OK
244
IJoePair pair = IJoePair(factory.getPair(fromToken, toToken));
245
require(address(pair) != address(0), "JoeMakerV3: Cannot convert");
246
247
(uint256 reserve0, uint256 reserve1, ) = pair.getReserves();
248
(uint256 reserveInput, uint256 reserveOutput) = fromToken == pair.token0()
249
? (reserve0, reserve1)
250
: (reserve1, reserve0);
251
IERC20(fromToken).safeTransfer(address(pair), amountIn);
252
uint256 amountInput = IERC20(fromToken).balanceOf(address(pair)).sub(reserveInput); // calculate amount that was transferred, this accounts for transfer taxes
253
254
amountOut = getAmountOut(amountInput, reserveInput, reserveOutput);
255
(uint256 amount0Out, uint256 amount1Out) = fromToken == pair.token0()
256
? (uint256(0), amountOut)
257
: (amountOut, uint256(0));
258
pair.swap(amount0Out, amount1Out, to, new bytes(0));
259
}
260
261
// F1 - F10: OK
262
// C1 - C24: OK
263
function _toJOE(address token, uint256 amountIn) internal returns (uint256 amountOut) {
264
uint256 amount = amountIn;
265
if (devCut > 0) {
266
amount = amount.mul(devCut).div(10000);
267
IERC20(token).safeTransfer(devAddr, amount);
268
amount = amountIn.sub(amount);
269
}
270
amountOut = _swap(token, joe, amount, bar);
271
}
Copied!

SLOC Appendix

Solidity Contracts

Language
Files
Lines
Blanks
Comments
Code
Complexity
Solidity
26
5965
780
822
4093
622
Comments to Code 822/4093 = 20%

Javascript Tests

Language
Files
Lines
Blanks
Comments
Code
Complexity
JavaScript
12
5555
729
668
4158
3
Tests to Code 4158/4093 = 101%
Last modified 10d ago