P
P
PQ Reviews
Search…
0.6
Retired
Flexa/AMP PQ Audit
Score: 82%
This is a Flexa / AMP Process Quality Review completed on 22 December 2020. The review covers the AMP and Flexa contracts and documentation. It was performed using the Process Review process (version 0.6.1) and is documented here. The review was performed by ShinkaRex of DeFiSafety. Check out our Telegram.
The final score of the review is 82%, a solid pass. The breakdown of the scoring is in Scoring Appendix.

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

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.

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 questions;
  1. 1.
    Are the executing code addresses readily available? (Y/N)
  2. 2.
    Is the code actively being used? (%)
  3. 3.
    Is there a public software repository? (Y/N)
  4. 4.
    Is there a development history visible? (%)
  5. 5.
    Is the team public (not anonymous)? (Y/N)

Are the executing code addresses readily available? (Y/N)

Answer: Yes
They are available at website https://github.com/flexahq/flexa-collateral-manager and https://amptoken.org/faq as indicated in the Appendix.

Is the code actively being used? (%)

Answer: 100%
Activity is 4 transactions a day on contract FlexacollateralManager.sol, as indicated in the Appendix.

Percentage Score 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

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

Answer: Yes
Is there a public software repository with the code at a minimum, but normally test and scripts also (Y/N). Even if the repo was created just to hold the files and has just 1 transaction, it gets a Yes. For teams with private repos, this answer is No.

Is there a development history visible? (%)

Answer: 0%
With 4 commits and 1 branch, this is not a healthy repository. AMP is about the same, probably a private repo dev.
This 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 10 commits

How to improve this score

Continue to test and perform other verification activities after deployment, including routine maintenance updating to new releases of testing and deployment tools. A public development history indicates clearly to the public the level of continued investment and activity by the developers on the application. This gives a level of security and faith in the application.

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

Answer: Yes
The Flexa Team is found in the Flexa whitepaper.
For a yes in this question the real names of some team members must be public on the website or other documentation. If the team is anonymous and then this question is a No.

Documentation

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

Is there a whitepaper? (Y/N)

Answer: Yes
The whitepaper is for the Flexa payment system but not on the AMP token.

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

Answer: Yes
This is an API reference only for the AMP token only. There are no docs for Flexa.

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

Answer: 40%
There is an API doc for the AMP token contracts, so 80% for that but nothing for Flexa, 0%, average 40%.
Flexa's documentation is invite-only, and therefore there is no evidence of any public software function documentaton.
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 improve by adding content to the requirements 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.

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

Answer: 90%
There is good detail in the code as to the purpose of the functions. Their CtC is 90% and comments follow NatSpec.
Code examples are in the Appendix. As per the SLOC, there is 90% 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.

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

Answer: 0%
The AMP documentation is just API, a list of external functions.
As flexa's documentation is invite-only, there is no formal public documentation of flexa's smart contract functions.
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 requirements to code such that it is clear where each requirement is coded. 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;
  1. 1.
    Full test suite (Covers all the deployed code) (%)
  2. 2.
    Code coverage (Covers all the deployed lines of code, or explains misses) (%)
  3. 3.
    Scripts and instructions to run the tests (Y/N)
  4. 4.
    Packaged with the deployed code (Y/N)
  5. 5.
    Report of the results (%)
  6. 6.
    Formal Verification test done (%)
  7. 7.
    Stress Testing environment (%)

Is there a Full test suite? (%)

Answer: 100%
With a TtC of 785%, there is clearly a robust series of tests.
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 improve by adding tests to fully cover the code. Document what is covered by traceability or test results in the software repository.

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

Answer: 50%
There is no code coverage reports evident, although there is clearly a reasonable set of tests.
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 improve by adding tests achieving full code coverage. A clear report and scripts in the software repository will guarantee a high score.

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

Answer: No
Scripts and instructions to run flexa's and AMPS smart contracts cannot be found in their GitHub.

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.

Packaged with the deployed code (Y/N)

Answer: Yes
The Flexa tests are packaged with the deployed code.

How to improve this score

Improving this score requires redeployment of the code, with the tests. This score gives credit to those who test their code before deployment and release them together. If a developer adds tests after deployment they can gain full points for all test elements except this one.

Report of the results (%)

Answer: 0%
There is no evident report of flexa test results.
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.

Formal Verification test done (%)

Answer: 0%
There is no evidence of formal verification testing.

Stress Testing environment (%)

Answer: 100%
There is evidence of robust stress-testing on the Rinkeby network.

Audits

Answer: 100%
Flexa published their whitepaper in August 2018.
ConsenSys Diligence preformed an audit in June 2020.
Trail of Bits preformed an audit on July and August 2020, as well as September 2019.
Guidance:
  1. 1.
    Multiple Audits performed before deployment and results public and implemented or not required (100%)
  2. 2.
    Single audit performed before deployment and results public and implemented or not required (90%)
  3. 3.
    Audit(s) performed after deployment and no changes required. Audit report is public. (70%)
  4. 4.
    No audit performed (20%)
  5. 5.
    Audit Performed after deployment, existence is public, report is not public and no improvements deployed OR smart contract address' not found, question 1 (0%)

Appendices

Author Details

The author of this review is Rex of DeFi Safety.
Email : [email protected]defisafety.com 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.
Career wise I am a business development manager for an avionics supplier.

Scoring Appendix

Executing Code Appendix

Code Used Appendix

Example Code Appendix

1
}
2
3
/**********************************************************************************************
4
* Role Management
5
*********************************************************************************************/
6
7
/**
8
* @notice Updates the Withdrawal Publisher address, the only address other than the owner that
9
* can publish / remove withdrawal Merkle tree roots.
10
* @param _newWithdrawalPublisher The address of the new Withdrawal Publisher
11
* @dev Error invalid sender.
12
*/
13
function setWithdrawalPublisher(address _newWithdrawalPublisher) external {
14
require(msg.sender == owner(), "Invalid sender");
15
16
address oldValue = withdrawalPublisher;
17
withdrawalPublisher = _newWithdrawalPublisher;
18
19
emit WithdrawalPublisherUpdate(oldValue, withdrawalPublisher);
20
}
21
22
/**
23
* @notice Updates the Fallback Publisher address, the only address other than the owner that
24
* can publish / remove fallback withdrawal Merkle tree roots.
25
* @param _newFallbackPublisher The address of the new Fallback Publisher
26
* @dev Error invalid sender.
27
*/
28
function setFallbackPublisher(address _newFallbackPublisher) external {
29
require(msg.sender == owner(), "Invalid sender");
30
31
address oldValue = fallbackPublisher;
32
fallbackPublisher = _newFallbackPublisher;
33
34
emit FallbackPublisherUpdate(oldValue, fallbackPublisher);
35
}
36
37
/**
38
* @notice Updates the Withdrawal Limit Publisher address, the only address other than the
39
* owner that can set the withdrawal limit.
40
* @param _newWithdrawalLimitPublisher The address of the new Withdrawal Limit Publisher
41
* @dev Error invalid sender.
42
*/
43
function setWithdrawalLimitPublisher(address _newWithdrawalLimitPublisher) external {
44
require(msg.sender == owner(), "Invalid sender");
45
46
address oldValue = withdrawalLimitPublisher;
47
withdrawalLimitPublisher = _newWithdrawalLimitPublisher;
48
49
emit WithdrawalLimitPublisherUpdate(oldValue, withdrawalLimitPublisher);
50
}
51
52
/**
53
* @notice Updates the DirectTransferer address, the only address other than the owner that
54
* can execute direct transfers
55
* @param _newDirectTransferer The address of the new DirectTransferer
56
*/
57
function setDirectTransferer(address _newDirectTransferer) external {
58
require(msg.sender == owner(), "Invalid sender");
59
60
address oldValue = directTransferer;
61
directTransferer = _newDirectTransferer;
62
63
emit DirectTransfererUpdate(oldValue, directTransferer);
64
}
65
66
/**
67
* @notice Updates the Partition Manager address, the only address other than the owner that
68
* can add and remove permitted partitions
69
* @param _newPartitionManager The address of the new PartitionManager
70
*/
71
function setPartitionManager(address _newPartitionManager) external {
72
require(msg.sender == owner(), "Invalid sender");
73
74
address oldValue = partitionManager;
75
partitionManager = _newPartitionManager;
76
77
emit PartitionManagerUpdate(oldValue, partitionManager);
78
}
79
80
/**********************************************************************************************
81
* Operator Data Decoders
82
*********************************************************************************************/
83
84
/**
85
* @notice Extract flag from operatorData
86
* @param _operatorData The operator data to be decoded
87
* @return flag, the transfer operation type
88
*/
89
function _decodeOperatorDataFlag(bytes memory _operatorData) internal pure returns (bytes32) {
90
return abi.decode(_operatorData, (bytes32));
91
}
92
93
/**
94
* @notice Extracts the supplier, max authorized nonce, and Merkle proof from the operator data
95
* @param _operatorData The operator data to be decoded
96
* @return supplier, the address whose account is authorized
97
* @return For withdrawals: max authorized nonce, the last used withdrawal root nonce for the
98
* supplier and partition. For fallback withdrawals: max cumulative withdrawal amount, the
99
* maximum amount of tokens that can be withdrawn for the supplier's account, including both
100
* withdrawals and fallback withdrawals
101
* @return proof, the Merkle proof to be used for the authorization
102
*/
103
function _decodeWithdrawalOperatorData(bytes memory _operatorData)
104
internal
105
pure
106
returns (
107
address,
108
uint256,
109
bytes32[] memory
110
)
111
{
112
(, address supplier, uint256 nonce, bytes32[] memory proof) = abi.decode(
113
_operatorData,
114
(bytes32, address, uint256, bytes32[])
115
);
116
117
return (supplier, nonce, proof);
118
}
119
120
/**
121
* @notice Extracts the supply nonce from the operator data
122
* @param _operatorData The operator data to be decoded
123
* @return nonce, the nonce of the supply to be refunded
124
*/
125
function _decodeRefundOperatorData(bytes memory _operatorData) internal pure returns (uint256) {
126
(, uint256 nonce) = abi.decode(_operatorData, (bytes32, uint256));
127
128
return nonce;
129
}
130
131
/**********************************************************************************************
132
* Merkle Tree Verification
133
*********************************************************************************************/
134
135
/**
136
* @notice Hashes the supplied data and returns the hash to be used in conjunction with a proof
137
* to calculate the Merkle tree root
138
* @param _supplier The address whose account is authorized
139
* @param _partition Source partition of the tokens
140
* @param _value Number of tokens to be transferred
141
* @param _maxAuthorizedAccountNonce The maximum existing used withdrawal nonce for the
142
* supplier and partition
143
* @return leaf, the hash of the supplied data
144
*/
145
function _calculateWithdrawalLeaf(
146
address _supplier,
147
bytes32 _partition,
148
uint256 _value,
149
uint256 _maxAuthorizedAccountNonce
150
) internal pure returns (bytes32) {
151
return
152
keccak256(abi.encodePacked(_supplier, _partition, _value, _maxAuthorizedAccountNonce));
153
}
154
155
/**
156
* @notice Hashes the supplied data and returns the hash to be used in conjunction with a proof
157
* to calculate the Merkle tree root
158
* @param _supplier The address whose account is authorized
159
* @param _partition Source partition of the tokens
160
* @param _maxCumulativeWithdrawalAmount, the maximum amount of tokens that can be withdrawn
161
* for the supplier's account, including both withdrawals and fallback withdrawals
162
* @return leaf, the hash of the supplied data
163
*/
164
function _calculateFallbackLeaf(
165
address _supplier,
166
bytes32 _partition,
167
uint256 _maxCumulativeWithdrawalAmount
168
) internal pure returns (bytes32) {
169
return keccak256(abi.encodePacked(_supplier, _partition, _maxCumulativeWithdrawalAmount));
170
}
171
172
/**
173
* @notice Calculates the Merkle root for the unique Merkle tree described by the provided
174
Merkle proof and leaf hash.
175
* @param _merkleProof The sibling node hashes at each level of the tree.
176
* @param _leafHash The hash of the leaf data for which merkleProof is an inclusion proof.
177
* @return The calculated Merkle root.
178
*/
179
function _calculateMerkleRoot(bytes32[] memory _merkleProof, bytes32 _leafHash)
180
private
181
pure
182
returns (bytes32)
183
{
184
bytes32 computedHash = _leafHash;
185
186
for (uint256 i = 0; i < _merkleProof.length; i++) {
187
bytes32 proofElement = _merkleProof[i];
188
189
if (computedHash < proofElement) {
190
computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
191
} else {
192
computedHash = keccak256(abi.encodePacked(proofElement, computedHash));
193
}
194
}
195
196
return computedHash;
197
}
198
}
Copied!

SLOC Appendix

Solidity Contracts

Language
Files
Lines
Blanks
Comments
Code
Complexity
Solidity
3
1439
194
592
653
93
Comments to Code 592/ 653 = 90%

Javascript Tests

Language
Files
Lines
Blanks
Comments
Code
Complexity
JavaScript
32
5824
670
24
5130
13
Tests to Code 5130 / 653 = 785%
Last modified 11mo ago