Prepared by:
HALBORN
Last Updated 04/26/2024
Date of Engagement by: March 25th, 2022 - April 20th, 2022
80% of all REPORTED Findings have been addressed
All findings
5
Critical
0
High
0
Medium
0
Low
0
Informational
5
deBridge
engaged Halborn to conduct a security assessment on their smart contracts beginning on March 25th, 2022 and ending April 20th, 2022. deBridge
a cross-chain interoperability and liquidity transfer protocol that allows truly decentralized transfer of assets between various blockchains. deBridge is a cross-chain interoperability and liquidity transfer protocol that allows decentralized transfer of assets between blockchains.
The team at Halborn was provided four weeks for the engagement and assigned one full-time security engineer to audit the security of the assets in scope. The engineer is a blockchain and smart contract security expert with advanced penetration testing, smart-contract hacking, and deep knowledge of multiple blockchain protocols.
The purpose of this audit is to achieve the following:
Identify potential security issues with the smart contracts.
Halborn performed a combination of manual and automated security testing to balance efficiency, timeliness, practicality, and accuracy with the scope of the smart contract audit. While manual testing is recommended to uncover flaws in logic, process, and implementation, automated testing techniques help enhance the smart contract code coverage and quickly identify items that do not follow security best practices. The following phases and associated tools were used throughout the term of the audit:
Research into architecture and purpose.
Smart contract manual code review and walkthrough
Graphing out functionality and contract logic/connectivity/functions(solgraph
)
Manual testing of core functions through Hardhat
and Ganache
Manual testing with custom scripts.
Static Analysis of security for scoped contract, and imported functions.(Slither
)
Scanning of solidity files for vulnerabilities, security hotspots or bugs. (MythX
)
Testnet deployment (Remix IDE
)
The review was scoped to contracts and scripts in the following: master
branch 9e3262cd63cd9d916c9de00f021543888f3568ad
commit (cross-chain-swaps) master
branch 340b77c551a8cde4800ebdc4665a580938816737
commit (cross-chain-sdk)
Smart contracts:
CrossChainForwarder.sol
ForwarderBase.sol
LPConnector.sol
ReceivingForwarder.sol
CalldataUtils.sol
Flags.sol
SignatureUtil.sol
SwapCalldataUtils.sol
SDK:
Chain.ts
CrossChainForwardingService.ts
CrossChainPathFindingService.ts
CrossChainResolver.ts
DePair.ts
DePairsCollection.ts
Icons.ts
RecommendExecutionFeeService.ts
SDK.ts
SDKError.ts
SwapBuildingService.ts
Critical
0
High
0
Medium
0
Low
0
Informational
5
Impact x Likelihood
HAL-01
HAL-02
HAL-03
HAL-04
HAL-05
Security analysis | Risk level | Remediation Date |
---|---|---|
SAME PAIR OF TOKENS CAN BE USED | Informational | Not Applicable |
MISSING PAUSEABLE FUNCTIONALITY | Informational | Not Applicable |
UNUSED RETURN VALUES | Informational | - |
COGNITIVE COMPLEXITY OF FUNCTION IS TOO HIGH | Informational | Acknowledged |
POSSIBLE MISUSE OF PUBLIC FUNCTIONS | Informational | Solved - 12/05/2022 |
// Informational
It is observed that in forward()
and swapAndSend()
functions inside ReceivingForwarder.sol
and in CrosschainForwarder.sol
does not check if source token type equals to destination token type and accepts same pair of tokens as input.
This type of bugs may lead to critical attack vectors or griefing attacks.
ReceivingForwarder.sol
forward
function forward(
address _dstTokenIn,
address _router,
bytes memory _routerCalldata,
address _dstTokenOut,
address _fallbackAddress
) external payable override{
if (_dstTokenIn == NATIVE_TOKEN) {
return _forwardFromETH(
_router,
_routerCalldata,
_dstTokenOut,
_fallbackAddress
);
}
else {
return _forwardFromERC20(
IERC20Upgradeable(_dstTokenIn),
_router,
_routerCalldata,
_dstTokenOut,
_fallbackAddress
);
CrosschainForwarder.sol
swapAndSend
function swapAndSend(
address _srcTokenIn,
uint _srcAmountIn,
bytes memory _srcTokenInPermit,
address _srcSwapRouter,
bytes calldata _srcSwapCalldata,
address _srcTokenOut,
bytes calldata _dstDetails
) external payable override {
if (!supportedRouters[_srcSwapRouter]) revert NotSupportedRouter();
uint ethBalanceBefore = address(this).balance - msg.value;
uint srcAmountOut;
if (_srcTokenIn == NATIVE_TOKEN) {
_validateSrcETHIn(_srcAmountIn);
srcAmountOut = _swapToERC20Via(
_srcSwapRouter,
_srcSwapCalldata,
_srcAmountIn,
IERC20Upgradeable(_srcTokenOut)
);
}
else {
...
In the Proof of Concept below, we created a test script which gives same input token type for source and destination.
it('Same pair of tokens', async () => {
await state.usdToken.instance.mint(state.user.address,usd2v(10));
console.log(await state.usdToken.instance.balanceOf(state.user.address));
await state.receivingForwarder.instance.connect(state.user)
.forward(
state.usdToken.instance.address, // _wrappedToken
state.dex.instance.address, // _router
SAMPLE_CALLDATA.swap.sample, // _routerCalldata
state.usdToken.instance.address, // _targetToken
state.user.address, // _fallbackAddress
);
console.log(await state.usdToken.instance.balanceOf(state.user.address));
});
NOT APPLICABLE: The issue is marked as not applicable by the DeBridge team
with an explanation: Both CrosschainForwarder and ReceivingForwarder work as relayers: they take tokenIn from msg.sender, swap it to tokenOut via the swapRouter, then pass the resulting tokenOut along with deBridgeGate or the destination address. It seems that there is nothing wrong with the situation when both tokens are the same. Moreover, this opens broad possibilities for arbitrage.
// Informational
Even code that has been thoroughly audited and tested may contain bugs or defective code parts. These flaws are frequently undetected until they are employed in an attack by an opponent. Because immutability is one of the basic characteristics of the blockchain, it is difficult to correct if a critical fault is discovered. While some patterns (such as the Proxy Delegate pattern) allow for upgradeable code to some extent, these solutions normally take a long time to implement and come into action. Before the update is transmitted to the network, the attackers could continue with their malicious actions and cause harm.
NOT APPLICABLE: The issue is marked as not applicable by the DeBridge team
with an explanation: ReceivingForwarder and CrosschainForwarder communicate with the deBridgeGate contract. If we ever need to stop the contracts, we can either stop deBridgeGate or quickly upgrade the proxy to a fixed or paused implementation.
// Informational
// Informational
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
CrossChainPathFindingService.ts
refreshDst
ACKNOWLEDGED: The DeBridge team
acknowledged this finding.
// Informational
In public functions, array arguments are immediately copied to memory, while external functions can read directly from calldata
. Reading calldata
is cheaper than memory allocation. Public functions need to write the arguments to memory because public functions may be called internally. Internal calls are passed internally by pointers to memory. Thus, the function expects its arguments being located in memory when the compiler generates the code for an internal function.
Furthermore, methods do not necessarily have to be public if they are only called within the contract-in such case they should be marked internal
.
LPConnector.sol
getUnwrapToken
function getUnwrapToken(address _wrappedToken) public view returns (address) {
return pools[_wrappedToken].jToken;
}
SOLVED: The issue was solved by the DeBridge team
.
Halborn strongly recommends conducting a follow-up assessment of the project either within six months or immediately following any material changes to the codebase, whichever comes first. This approach is crucial for maintaining the project’s integrity and addressing potential vulnerabilities introduced by code modifications.
// Download the full report
* Use Google Chrome for best results
** Check "Background Graphics" in the print settings if needed