Introduction
We express our gratitude to the Onchain Labs team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.
The OnChain contracts are core of the OnChain Payment Network (swapsy) that allows end user perform multiple swaps within single transaction.
Document | |
---|---|
Name | Smart Contract Code Review and Security Analysis Report for Onchain Labs |
Audited By | Grzegorz Trawinski |
Approved By | Ataberk Yavuzer |
Website | https://www.onchainlabs.org/→ |
Changelog | 27/12/2024 - Preliminary Report |
07/01/2025 - Final Report | |
Platform | Polygon, Base, BNB, Ethereum |
Language | Solidity |
Tags | Uniswapv2, Uniswapv3 |
Methodology | https://hackenio.cc/sc_methodology→ |
Document
- Name
- Smart Contract Code Review and Security Analysis Report for Onchain Labs
- Audited By
- Grzegorz Trawinski
- Approved By
- Ataberk Yavuzer
- Changelog
- 27/12/2024 - Preliminary Report
- 07/01/2025 - Final Report
- Platform
- Polygon, Base, BNB, Ethereum
- Language
- Solidity
- Tags
- Uniswapv2, Uniswapv3
- Methodology
- https://hackenio.cc/sc_methodology→
Review Scope | |
---|---|
Repository | https://github.com/onchain-team/ramp-contracts/→ |
Commit | 0f7bdb99722e7f6b73fa7c99a645f818e2edc680 |
Retest commit | 02266e4ab43ec0a393925d679865e194ad77b729 |
Review Scope
- Commit
- 0f7bdb99722e7f6b73fa7c99a645f818e2edc680
- Retest commit
- 02266e4ab43ec0a393925d679865e194ad77b729
Audit Summary
The system users should acknowledge all the risks summed up in the risks section of the report
Documentation quality
Functional requirements were not provided.
Partial technical requirements, deployment and testing scripts provided.
Code quality
The code base represents mature protocol.
Test coverage
Tests coverage could not be provided to too coverage tool calculation failure.
Only 4 basic unit tests provided within the
onchain-price.test.ts
file.Multiple tests and use cases provided as scripts.
System Overview
The OnChain contracts allow the end user to perform multiple swaps within a single transaction.
Router.sol - a contract that allows to perform a swap via Uniswapv2 pairs and Uniswapv3 pools. Additionally, privileged users can configure contract fees and rescue native and ERC20 tokens. RouterFactory.sol - a contract that allows Router instance deployment. The contract is permission-less.
Privileged roles
The owner of the Router contract can update the new owner, set order ID, set protocol fees, set fee address, and rescue native and ERC20 tokens.
Potential Risks
System Reliance on External Contracts: The functioning of the system significantly relies on Uniswapv2 and Uniswapv3 external contracts. Any flaws or vulnerabilities in these contracts adversely affect the audited project, potentially leading to security breaches or loss of funds.
Owner's Unrestricted State Modification: The absence of restrictions on state variable modifications by the owner leads to arbitrary changes, affecting contract integrity and user trust, especially during critical operations like updating fees.
Findings
Code ― | Title | Status | Severity | |
---|---|---|---|---|
F-2024-7984 | The setGasAmount can lead to revert or funds theft | fixed | High | |
F-2024-7986 | Swap can revert due to division by 0 | mitigated | Low | |
F-2024-7983 | Fee setting lacks upper band input validation | fixed | Low | |
F-2024-7985 | The feeAddress can be set to 0 address | fixed | Observation | |
F-2024-7982 | Lack of ownership two-step transfer process | accepted | Observation |
Identify vulnerabilities in your smart contracts.
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/onchain-team/ramp-contracts/→ |
Commit | 0f7bdb99722e7f6b73fa7c99a645f818e2edc680 |
Retest Commit | 02266e4ab43ec0a393925d679865e194ad77b729 |
Whitepaper | N/A |
Requirements | N/A |
Technical Requirements | README.md |
Scope Details
- Commit
- 0f7bdb99722e7f6b73fa7c99a645f818e2edc680
- Retest Commit
- 02266e4ab43ec0a393925d679865e194ad77b729
- Whitepaper
- N/A
- Requirements
- N/A
- Technical Requirements
- README.md
Assets in Scope
Appendix 3. Additional Valuables
Verification of System Invariants
During the audit of OnChain contracts Hacken followed its methodology by performing fuzz-testing on the project's main functions. Foundry, a tool used for fuzz-testing, was employed to check how the protocol behaves under various inputs. Due to the complex and dynamic interactions within the protocol, unexpected edge cases might arise. Therefore, it was important to use fuzz-testing to ensure that several system invariants hold true in all situations.
Fuzz-testing allows the input of many random data points into the system, helping to identify issues that regular testing might miss. A specific Echidna fuzzing suite was prepared for this task, and throughout the assessment, 4invariants were tested over 100,000 runs. This thorough testing ensured that the system works correctly even with unexpected or unusual inputs.
Invariant | Test Result | Run Count |
---|---|---|
Perform Uniswapv2 swap with path USDC - WETH - SHIB with reasonable input and without unexpected revert. | Passed | 100k |
Perform Uniswapv2 swap with path SHIB - WETH - USDC with reasonable input and without unexpected revert. | Passed | 100k |
Perform Uniswapv3 swap with path USDC - WETH - DAI with reasonable input and without unexpected revert. | Passed | 100k |
Perform Uniswapv3 swap with path DAI - WETH - USDC with reasonable input and without unexpected revert. | Passed | 100k |
Invariant
- Perform Uniswapv2 swap with path USDC - WETH - SHIB with reasonable input and without unexpected revert.
Test Result
- Passed
Run Count
- 100k
Invariant
- Perform Uniswapv2 swap with path SHIB - WETH - USDC with reasonable input and without unexpected revert.
Test Result
- Passed
Run Count
- 100k
Invariant
- Perform Uniswapv3 swap with path USDC - WETH - DAI with reasonable input and without unexpected revert.
Test Result
- Passed
Run Count
- 100k
Invariant
- Perform Uniswapv3 swap with path DAI - WETH - USDC with reasonable input and without unexpected revert.
Test Result
- Passed
Run Count
- 100k
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.