This is a Compound Finance Process Quality Audit started on 19 May 2020 and completed on 18 June 2020. This was one of the three written while developing the process. That is why it took a montIt was performed using the Process Audit process (version 0.2) and is documented here. The audit was performed by ShinkaRex of Caliburn Consulting. Check out our Telegram.
The final score of the audit is 88%, an excellent pass. The breakdown of the scoring is in Scoring Appendix.
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, 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. 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 section looks at the executing code on the Mainnet that gets audited and its corresponding software repository. The document explaining these questions is here. This audit will answer the questions;
Is the deployed code address(s) readily available? (Y/N)
Is the code actively being used? (%)
Are the Contract(s) Verified/Verifiable? (Y/N)
Does the code match a tagged version in the code hosting platform? (%)
Is the software repository healthy? (%)
Answer: Yes
They are available at Address https://compound.finance/doc as indicated in the Appendix for Deployed Code. This Audit only covers the Comptroller contract (address 0x3d9819210a31b4961b30ef54be2aed79b9c9cd3b which proxyβs to 0x97BD4Cc841FC999194174cd1803C543247a014fe)
Answer: 100%
Activity is 10 transactions a day, as indicated in the Appendix.
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
Answer: Yes
Through Etherscan for the contract address 0x97BD4Cc841FC999194174cd1803C543247a014fe, which is a revised (or proxied) address for 0x3d9819210a31b4961b30ef54be2aed79b9c9cd3b.
Answer: 80%
GitHub address : https://github.com/compound-finance/compound-protocolβ
Deployed contracts in the following file;
Matching Repository: https://github.com/compound-finance/compound-protocol/releases/tag/v2.6-rc1β
It is difficult and not clear which release corresponded to the actual code that was deployed for both the initial release and 2.6. The documentation for this is an area of improvement. Also the contract was created on Mar 11 (0x0d4e67d68f01baa212b3ccf9b0a10ce5949a718a8ca3501afc912681208d2879) but the release zip was created on Mar 31. The differences in dates makes it slightly suspect. For clarity, the GitHub release zip should be made before the deployment, not after. However the source code matches fully. Given the date mismatch and the bad labeling, only 80% score given
Ensure there is a clearly labelled repository holding all the contracts, documentation and tests for the deployed code. Ensure an appropriately labeled tag exists corresponding to deployment dates. Release tags are clearly communicated.
Answer: Yes
This section looks at the software documentation. The document explaining these questions is here.
Required questions are;
Is there a whitepaper? (Y/N)
Are the basic application requirements documented? (Y/N)
Do the requirements fully (100%) cover the deployed contracts? (%)
Are there sufficiently detailed comments for all functions within the deployed contract code (%)
Is it possible to trace software requirements to the implementation in code (%)
Answer: Yes
Location: https://compound.finance/documents/Compound.Whitepaper.pdfβ
Answer: Yes
Location: https://github.com/compound-finance/compound-protocol/tree/master/docsβ
Answer: 70%
The Compound Protocol Specification document is comprehensive and clear. It has a revision version and a date and appears to be up to date. While it does not methodically go through each function, it does explain the high level requirements of all system capabilities in clear language. Most of the variables are clearly defined. There is no traceability. Since there is no traceability, it is difficult to see how complete the requirements cover the code without detailed analysis. Given these points we give an approximate answer of 70%.
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.
Answer: 70%
The main functions are well documented, as indicated in the following example. However some of the ancillary functions have no documentation, as seen Appendix for Example Code. Overall for 2020 Blockchain development norms, the code is well documented. As per the software line of code appendix there is an 80% comment to code ratio. For this reason the 70% score was given.
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.
Answer: 0%
No traceability artifacts are evident in the requirements document or the code. It does not appear to be any intention of the developers. For this reason a score of 0% is unavoidable. In their defense, very few blockchain development programs use traceability yet.
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.
This section looks at the software testing available. It is explained in this document. This section answers the following questions;
Full test suite (Covers all the deployed code) (%)
Code coverage (Covers all the deployed lines of code, or explains misses) (%)
Scripts and instructions to run the tests (Y/N)
Packaged with the deployed code (Y/N)
Report of the results (%)
Formal Verification test done (%)
Stress Testing environment (%)
Matching Repository: https://github.com/compound-finance/compound-protocol/releases/tag/v2.6-rc1β
Answer: 100%
There are a significant number and lines of tests. There are contract tests (over 52 source files), scenario tests and others. Without actually running the tests it is difficult to confirm it is a complete test suite, but it certainly appears so.
Answer: 70%
There are clear artifacts of unit tests (in tests/contract) and scripts for coverage testing. We did not find the output of the coverage tests (though the file name and directory is specified in script/coverage bash file). At this point it seems to indicate full coverage. However without evidence, we cannot give a score higher than 70%.
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.
Answer: Yes
In the script subdirectory there are scripts to test, coverage, lint and verify.
Answer: Yes
The deployed code was saved as a GitHub release. The tests and scripts were packaged with the release in the repository zip file.
Answer: 0%
No test results or reports were saved in the repository.
Add a report with the results. The test scripts should generate the report or elements of it.
Answer: 100%
A formal verification was performed by the Cetora group. Their report clearly states what they did. Some errors were found and listed. We cannot comment on the impact of the errors listed. The Certora report stats that Compound met their specification.
Answer: 100%
Compound operates a simulation-based market stress-testing platform to evaluate the economic security of the Compound protocol, as it scales supported assets and volume. This is operated by Gauntlet and a report is on the Compound website security section.
Answer: 100%
Compound has had consistent audits through their development as documented on their site. They have audits from two top level audit organizations. The audits are public and they have implemented findings in order to improve their code.
Multiple Audits performed before deployment and results public and implemented or not required (100%)
Single audit performed before deployment and results public and implemented or not required (90%)
Audit(s) performed after deployment and no changes required. Audit report is public. (70%)
No audit performed (20%)
Audit Performed after deployment, existence is public, report is not public and no improvements deployed (0%)
The author of this audit is Rex of Caliburn Consulting.
Email : [email protected] Twitter : @ShinkaRex
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 2017 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 Audits 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 for an avionics supplier.
/*** @title Compound's CToken Contract* @notice Abstract base for CTokens* @author Compound*/contract CToken is CTokenInterface, Exponential, TokenErrorReporter {/*** @notice Initialize the money market* @param comptroller_ The address of the Comptroller* @param interestRateModel_ The address of the interest rate model* @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18* @param name_ EIP-20 name of this token* @param symbol_ EIP-20 symbol of this token* @param decimals_ EIP-20 decimal precision of this token*/function initialize(ComptrollerInterface comptroller_,InterestRateModel interestRateModel_,uint initialExchangeRateMantissa_,string memory name_,string memory symbol_,uint8 decimals_) public {require(msg.sender == admin, "only admin may initialize the market");require(accrualBlockNumber == 0 && borrowIndex == 0, "market may only be initialized once");β// Set initial exchange rateinitialExchangeRateMantissa = initialExchangeRateMantissa_;require(initialExchangeRateMantissa > 0, "initial exchange rate must be greater than zero.");β// Set the comptrolleruint err = _setComptroller(comptroller_);require(err == uint(Error.NO_ERROR), "setting comptroller failed");β// Initialize block number and borrow index (block number mocks depend on comptroller being set)accrualBlockNumber = getBlockNumber();borrowIndex = mantissaOne;β// Set the interest rate model (depends on block number / borrow index)err = _setInterestRateModelFresh(interestRateModel_);require(err == uint(Error.NO_ERROR), "setting interest rate model failed");βname = name_;symbol = symbol_;decimals = decimals_;β// The counter starts true to prevent changing it from zero to non-zero (i.e. smaller cost/refund)_notEntered = true;}
function requireNoError(uint errCode, string memory message) internal pure {if (errCode == uint(Error.NO_ERROR)) {return;}bytes memory fullMessage = new bytes(bytes(message).length + 5);uint i;for (i = 0; i < bytes(message).length; i++) {fullMessage[i] = bytes(message)[i];}fullMessage[i+0] = byte(uint8(32));fullMessage[i+1] = byte(uint8(40));fullMessage[i+2] = byte(uint8(48 + ( errCode / 10 )));fullMessage[i+3] = byte(uint8(48 + ( errCode % 10 )));fullMessage[i+4] = byte(uint8(41));βrequire(errCode == uint(Error.NO_ERROR), string(fullMessage));}
Language | Files | Lines | Blanks | Comments | Code | Complexity |
Solidity | 14 | 7551 | 1227 | 2810 | 3514 | 750 |
Comments to Code 2810 / 3514 = 80%
Language | Files | Lines | Blanks | Comments | Code | Complexity |
JavaScript | 43 | 6952 | 1102 | 154 | 5696 | 202 |
Tests to Code 6952 / 3514 = 197%