Introduction
We express our gratitude to the Dinari team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.
Dinari Securities Backed Tokens (dShares) provide direct exposure to the world's most trusted assets such as Google and Apple shares.
Document | |
|---|---|
| Name | Smart Contract Code Review and Security Analysis Report for Dinari |
| Audited By | Stepan Chekhovskoi |
| Approved By | Przemyslaw Swiatowiec |
| Website | https://dinari.com→ |
| Changelog | 12/12/2024 - Preliminary Report |
| 30/12/2024 - Second Report | |
| Platform | Plume |
| Language | Solidity |
| Tags | Vault, DeFi |
| Methodology | https://hackenio.cc/sc_methodology→ |
Document
- Name
- Smart Contract Code Review and Security Analysis Report for Dinari
- Audited By
- Stepan Chekhovskoi
- Approved By
- Przemyslaw Swiatowiec
- Website
- https://dinari.com→
- Changelog
- 12/12/2024 - Preliminary Report
- 30/12/2024 - Second Report
- Platform
- Plume
- Language
- Solidity
- Tags
- Vault, DeFi
- Methodology
- https://hackenio.cc/sc_methodology→
Review Scope | |
|---|---|
| Repository | https://github.com/dinaricrypto/sbt-contracts→ |
| Initial Commit | 1fa1a298373cefc252694984640db62d8f3a6b33 |
| Second Commit | d327ea9a6fc5f86caf73769dd1983b5333e774b8 |
Review Scope
- Initial Commit
- 1fa1a298373cefc252694984640db62d8f3a6b33
- Second Commit
- d327ea9a6fc5f86caf73769dd1983b5333e774b8
Audit Summary
The system users should acknowledge all the risks summed up in the risks section of the report
Documentation quality
Functional Requirements are partially missed.
Technical Description is provided.
Code quality
The code architecture is clean and easy to read.
The development environment is configured.
While the NatSpec comments mention
OrderProcessorprovides price with 18 decimals, the calculations imply36 - dShare.decimals().The
OracleLibfunctionality does not revert transaction in case of overflow and returns zero.
Test coverage
Code coverage of the project is 74% (branch coverage).
Deployment and basic user interactions are covered with tests.
Negative cases coverage is partially missed.
System Overview
DinariAdapterToken is a vault contract developed to use ETF dShare as one of liquid assets in Plume Nest money market.
The vault is built on top of out-of-scope ComponentToken contract - ERC-4626 Vault with ERC-7540 and ERC-7575 extensions.
The contract integrates external OrderProcessor used to exchange vault asset token to dShare and back.
Implemented functionality:
convertToShares,convertToAssets-ComponentTokenoverrides provide info on the vault rate based on conversion rate fromOrderProcessor,requestDeposit,requestRedeem- asynchronous vault deposit and redeem processing funds through theOrderProcessor,processSubmittedOrders,processNextSubmittedOrder- functions to validate if theOrderProcessorhave executed the submitted requests.
Privileged roles
The system is designed to work exclusively with Nest Staking.
The system owner can upgrade the contract.
Potential Risks
System Reliance on External Contracts: The functioning of the system significantly relies on Order Processor and Nest Staking external contracts. Any flaws or vulnerabilities in these contracts adversely affect the audited project, potentially leading to security breaches or loss of funds.
Dependency on External Logic for Implemented Logic: The DinariAdapterToken logic highly depends on ComponentToken external contract not covered by the audit. This reliance introduces risks if these external contracts are compromised or contain vulnerabilities, affecting the audited project's integrity.
Dynamic Array Iteration Gas Limit Risks: The processSubmittedOrders iterates over large dynamic arrays, which leads to excessive Gas costs, risking denial of service due to out-of-gas errors, alternative processNextSubmittedOrder function can be used to process requests one-by-one.
Single Points of Failure and Control: The project is mostly centralized, introducing single points of failure and control. This centralization can lead to vulnerabilities in decision-making and operational processes, making the system more susceptible to targeted attacks or manipulation.
Flexibility and Risk in Contract Upgrades: The project's contracts are upgradeable, allowing the administrator to update the contract logic at any time. While this provides flexibility in addressing issues and evolving the project, it also introduces risks if upgrade processes are not properly managed or secured, potentially allowing for unauthorized changes that could compromise the project's integrity and security.
Token Decimals Reliance: The system relies on the dShare token has 18 decimals. Missing the invariant may cause inconsistencies in price decimals calculation leading to the price interpreted incorrectly breaking the conversion rate.
Zero Output in Case of Overflow: The system returns zero shares in exchange for assets or zero assets in exchange for shares in case overflow happens in internal price calculations. Consider simulate transaction before executing to avoid the edge cases.
Findings
Code ― | Title | Status | Severity | |
|---|---|---|---|---|
| F-2024-7639 | Possibly Invalid Swap Rate due to Using Unreliable Market Price | accepted | Medium | |
| F-2024-7626 | Floating Pragma | fixed | Observation | |
| F-2024-7625 | Public Functions that Can be External | fixed | Observation |
Appendix 1. Definitions
Severities
When auditing smart contracts, Hacken is using a risk-based approach that considers Likelihood, Impact, Exploitability and Complexity metrics to evaluate findings and score severities.
Reference on how risk scoring is done is available through the repository in our Github organization:
Severity | Description |
|---|---|
Critical | Critical vulnerabilities are usually straightforward to exploit and can lead to the loss of user funds or contract state manipulation. |
High | High vulnerabilities are usually harder to exploit, requiring specific conditions, or have a more limited scope, but can still lead to the loss of user funds or contract state manipulation. |
Medium | Medium vulnerabilities are usually limited to state manipulations and, in most cases, cannot lead to asset loss. Contradictions and requirements violations. Major deviations from best practices are also in this category. |
Low | Major deviations from best practices or major Gas inefficiency. These issues will not have a significant impact on code execution. |
Severity
- Critical
Description
- Critical vulnerabilities are usually straightforward to exploit and can lead to the loss of user funds or contract state manipulation.
Severity
- High
Description
- High vulnerabilities are usually harder to exploit, requiring specific conditions, or have a more limited scope, but can still lead to the loss of user funds or contract state manipulation.
Severity
- Medium
Description
- Medium vulnerabilities are usually limited to state manipulations and, in most cases, cannot lead to asset loss. Contradictions and requirements violations. Major deviations from best practices are also in this category.
Severity
- Low
Description
- Major deviations from best practices or major Gas inefficiency. These issues will not have a significant impact on code execution.
Potential Risks
The "Potential Risks" section identifies issues that are not direct security vulnerabilities but could still affect the project’s performance, reliability, or user trust. These risks arise from design choices, architectural decisions, or operational practices that, while not immediately exploitable, may lead to problems under certain conditions. Additionally, potential risks can impact the quality of the audit itself, as they may involve external factors or components beyond the scope of the audit, leading to incomplete assessments or oversight of key areas. This section aims to provide a broader perspective on factors that could affect the project's long-term security, functionality, and the comprehensiveness of the audit findings.
Appendix 2. Scope
The scope of the project includes the following smart contracts from the provided repository:
Scope Details | |
|---|---|
| Repository | https://github.com/dinaricrypto/sbt-contracts→ |
| Initial Commit | 1fa1a298373cefc252694984640db62d8f3a6b33 |
| Second Commit | d327ea9a6fc5f86caf73769dd1983b5333e774b8 |
| Whitepaper | https://assets.dinari.com/forms/dinari-whitepaper.pdf→ |
| Requirements | Notes shared internally |
| Technical Requirements | README.md |
Scope Details
- Initial Commit
- 1fa1a298373cefc252694984640db62d8f3a6b33
- Second Commit
- d327ea9a6fc5f86caf73769dd1983b5333e774b8
- Requirements
- Notes shared internally
- Technical Requirements
- README.md
Assets in Scope
Appendix 3. Additional Valuables
Additional Recommendations
The smart contracts in the scope of this audit could benefit from the introduction of automatic emergency actions for critical activities, such as unauthorized operations like ownership changes or proxy upgrades, as well as unexpected fund manipulations, including large withdrawals or minting events. Adding such mechanisms would enable the protocol to react automatically to unusual activity, ensuring that the contract remains secure and functions as intended.
To improve functionality, these emergency actions could be designed to trigger under specific conditions, such as:
Detecting changes to ownership or critical permissions.
Monitoring large or unexpected transactions and minting events.
Pausing operations when irregularities are identified.
These enhancements would provide an added layer of security, making the contract more robust and better equipped to handle unexpected situations while maintaining smooth operations.