Skip to content
$1,000,000 in security audit grants are live now, Apply here →

Security review · May 2022

Exchange, Part 2

for Bridges Exchange

After a line by line manual analysis and automated review, Guardian Audits has concluded that:

Published
Language
Solidity
Chains
BNB Chain
Sector
DEXs and AMMs
  • 0 Critical
  • 0 High
  • 4 Medium
  • 4 Low
  • 0 Informational

7 resolved · 1 partially resolved

Scope

Overview

After a line by line manual analysis and automated review, Guardian Audits has concluded that:

  • Bridges’ smart contracts have a LOW RISK SEVERITY
  • Bridges’ smart contracts have an ACTIVE OWNERSHIP
  • Bridges’ smart contract owner has multiple “write” privileges. Centralization risk correlated to the active ownership is MEDIUM

Findings 8

  1. GLOBAL-1 Medium Centralization Risk Centralization / Privilege Partially resolved
    Location
    Global

    Description

    Privileged addresses have authority over many functions that may be used to negatively disrupt the project. Some important privileges include:

    GoldenGate

    • owner can withdraw all funds.
    • owner can set admins which are able to dilute allocation of other pools.
    • owner can set the migrator contract which can lead to loss of LP if malicious.

    TokenVesting

    • owner can arbitrarily set the fee and fee address which can lead to loss of user funds.

    BridgesRef

    • feeToSetter can arbitrarily set the distribution rate.
    • feeToSetter can withdraw any ERC-20 token in the contract.

    BridgesRouter

    • feeSetter can set a arbitrary referral and dividend tracker contract.

    Recommendation

    Ensure that the privileged addresses are multi-sig and/or introduce timelock for improved community oversight. Optionally introduce require statements to limit the scope of the exploits that can be carried out by the privileged addresses.

    Resolution

    Bridges Team: - All centralized BNB and token withdrawal functions have been removed from the GoldenGate contract,

    • The possibility to change fees on the TokenVault has been removed as well.
    • The GoldenGate migrator has to be there for an eventual V2 in the future.
    • For the same reason all update functions on the tracker are necessary.
    • Every privileged address will be a multi-sig with trusted members in production.
  2. GG-1 Medium Unable to Emergency Withdraw Denial-of-Service Resolved
    Location
    GoldenGate.sol:284

    Description

    Due to require(block.timestamp >= user.stakeUntil, "Locked") in emergencyWithdraw, if a user has LP tokens that are not locked alongside LP tokens that are indeed locked, the user would have to wait until their locked LP tokens become unlocked before they can emergencyWithdraw.

    Recommendation

    If this is intended behavior, keep as is. Otherwise, refactor emergencyWithdraw such that users may withdraw their unlocked positions.

    Resolution

    Bridges Team: - This is indeed expected behavior, if you have a locked position you cannot emergencyWithdraw any part of your position.

  3. FACT-1 Low Immutability Modifiers Mutability Resolved
    Location
    BridgesFactory.sol:10

    Description

    The GoldenGate address is not set after the constructor and can therefore be declared immutable.

    Recommendation

    Either make a setter for GoldenGate or declare it immutable.

    Resolution

    Bridges Team: - Implemented a setter for GoldenGate.

  4. PAIR-1 Medium Diluted Dividends Logical Error Resolved
    Location
    BridgesPair.sol:229, 232

    Description

    The rewards for the BridgesPair contract are ignored on line 232 by adjusting the rewardDebt, but they are not excluded in the magnifiedDividendPerShare calculation, therefore decreasing the dividends received by every other holder.

    Recommendation

    Subtract the BridgesPair’s balance from the totalSupply on line 229.

    Resolution

    Bridges Team: - Removed the BridgesPair contract balance from the dividends calculation.

  5. PAIR-2 Low Mutability Modifiers Mutability Resolved
    Location
    BridgesPair.sol: 39

    Description

    nullAddress is not changed anywhere and can therefore be declared constant.

    Recommendation

    Declare nullAddress constant.

    Resolution

    Bridges Team: - Declared nullAddress constant.

  6. PAIR-3 Low Superfluous Code Optimization Resolved
    Location
    BridgesPair.sol: 74

    Description

    The UserInfo struct now only contains a rewardDebt, therefore the userInfo mapping can simply be a mapping of address => uint where the uint is the rewardDebt.

    Recommendation

    Delete the UserInfo struct and convert the userInfo mapping to a simple address => uint mapping storing the rewardDebt directly.

    Resolution

    Bridges Team: - The mapping is now simply rewardDebt.

  7. PAIR-4 Low Superfluous Code Optimization Resolved
    Location
    BridgesPair.sol

    Description

    The sendToGate, sendToGateFrom0, sendToDevFromGate, and sendToDevFrom0 functions all do the same thing just with different addresses.

    Recommendation

    Make one function that does this computation that accepts configurable addresses as arguments and add a require statement to limit the scope of which addresses can be used.

    Resolution

    Bridges Team: - Combined these functions into one withdrawSpecial function.

  8. BRT-1 Medium Unexpected AmountOut Logical Error Resolved
    Location
    BridgesRouter.sol: 154

    Description

    Because the tradingFee is taken after the calculation of getAmountsIn, the user will receive 1000-tradingFee/10% of amountOut, rather than getting the whole amountOut. If the tradingFee is 30, the user will receive only 97% of the specified amountOut.

    Recommendation

    If it is desired to receive the amountOut at minimum, take the fee in the same manner as in getAmountsIn, where the amountIn is simply increased in order to maintain the amountOut.

    Resolution

    Bridges Team: - Removed the fee calculation logic as 3% slippage is handled on the frontend.

More from Bridges Exchange

  1. Exchange, Part 1

    23 findings2 high 23 findings: 2 high, 9 medium, 12 low

Put your code through the same review.

This review started with a conversation about scope. Tell us what you are building and we will plan yours with you.

Get a quote