Bartrr

Smart Contract Audit Report

Audit Summary

Bartrr Audit Report Bartrr is building a platform that allows participants to wager on the prices of various tokens.

For this audit, we reviewed the following contracts at commit cc7d70a8c0634e7f788a7d9778051fbaeda7e864 on the team's Github repository and we validated the team's deployed contracts at the following addresses:

Arbitrum Mainnet: Avalanche Mainnet: Binance Smart Chain Mainnet: Ethereum Mainnet: Polygon Mainnet: Optimism Mainnet:

Audit Findings

All findings have been resolved, though some centralized aspects are present.
Date: June 21st, 2022.
Updated: July 1st, 2022 to resolve findings and to reflect changes from Gist revision 11 to 17.
Updated: July 26th, 2022 to reflect changes from Gist revision 17 to 21 and include mainnet addresses.
Updated: September 21st, 2022 to reflect changes made to support fee-on-transfer tokens, include various gas optimizations, resolve an issue related to canceling a wager, tidy up the codebase, and include new mainnet addresses.

Finding #1 - FixedWager, ConditionalWager - High (Resolved)

Description: Takers on Wagers with ETH as a payment token are not required to pay their wager amount.
Risk/Impact: Since the Taker never has to pay their wager amount, when the winning sum is paid out, contract funds from other sources besides this wager will be lost. Additionally, this effectively means the Taker is wagering nothing, and only responsible for paying the fee.
Recommendation: We recommend that this contract require the Taker's ETH wager amount is sent to this contract as they are filling a Wager.
Resolution: The team has implemented the above recommendation.

Finding #2 - FixedWager, ConditionalWager - High (Resolved)

Description: Users can redeem a Wager on a wager token that has been marked as refundable by the team. This could lead to Bettors or Takers getting paid out winnings after they have already been refunded their wager amount.
Exploit Scenario:
  1. A Wager is created and filled.
  2. The team deactivates the wager token, marking it as refundable.
  3. The Taker or Bettor initiates a refund, and gets their wager amount returned.
  4. When redeeming the Wager, funds paid out to the winner include the wager amount that was already refunded.
Risk/Impact: In this scenario, the contract can lose funds meant to pay out winnings for Wagers.
Recommendation: We recommend the team not allow Wagers to be redeemend if they have partially been refunded.
Resolution: The team has implemented the above recommendation.

Finding #3 - FixedWager, ConditionalWager - High (Resolved)

Description: A Bettor who cancels a Wager with a Taker specified will get refunded a fee that they did not pay.
Risk/Impact: A User with knowledge of this could steal funds from the contract by repeatedly creating and cancelling Wagers to receive the fee that they never paid.
Recommendation: We recommend ensuring that only fees that have actually been paid get refunded for Users cancelling Wagers.
Resolution: The team has implemented the above recommendation.

Finding #4 - TokenLockup - High (Resolved)

Description: Anyone can receive locked tokens that are eligible for unlock by specifying a lockup id.
Risk/Impact: A user with knowledge of this can receive locked tokens that are not theirs.
Recommendation: We recommend the team include an address associated with Users' locked tokens to ensure that upon unlock, the tokens are transferred back to the depositor.
Resolution: The team has implemented the above recommendation.

Finding #5 - FixedWager, ConditionalWager - High (Resolved)

Description: A Wager with a specified Taker and an ERC20 payment token, can be filled by users other than the assigned Taker.
Risk/Impact: If a user who is not the assigned Taker fills this Wager, their funds will be taken by the contract, despite them ever being assigned as the Taker for a Wager. Additionally, this allows them to pay on behalf of the assigned Taker.
Recommendation: We recommend the team require that the users filling Wagers with assigned Takers are actually the assigned Takers.
Resolution: The team has implemented the above recommendation.

Finding #6 - FixedWager, ConditionalWager - Low (Resolved)

Description: A Wager with a specified Taker, with ETH as the payment token, never collects a fee from the Bettor when filling a Wager.
Risk/Impact: This could lead to the team receiving less fees than intended from use of the platform.
Recommendation: We recommend the team to collect this fee in the fillWager() function if they wish to include this functionality.
Resolution: The team has implemented the above recommendation.

Contracts Overview

  • The contracts utilize ReentrancyGuard to prevent against reentrancy attacks in applicable functions.
  • As the contracts are implemented with Solidity v0.8.0, they are safe from any possible overflows/underflows.
ConditionalWager, FixedWager Contracts:
  • These contracts implement the wager system of Bartrr, allowing for users to create, cancel, fill, redeem, and refund wagers; these contracts differ only in how a winner is determined for a given wager.
  • There are two participants in a Bartrr Wager. The Bettor is the user creating the wager and terms and the Taker is the user taking the bet.
  • The owner must initialize the contract prior to any wagers being created.
  • Bettors can create a Wager by specifying a wager token, whose price is being bet on, a payment token, that will be used to pay fees and winnings, the amount of tokens wagered by the Bettor and the Taker, in addition to how long the Wager will be active for. Wagers can only be created if the owner has approved both the wager token and the payment token for use, and the duration specified is at least the minimum wager duration of one day.
    • During creation of a Fixed Wager, the Bettor specifies whether they are betting the price will be above or below the wager price at the end of the wager duration.
    • Upon creation of a Conditional Wager, the Bettor specifies a wager price for both themselves and the Taker to be used in comparisons at the end of the wager duration; it is ensured that the prices are different.
    • Upon the creation of any Wager, the Bettor pays their wager amount in either ETH or the selected ERC20 payment token.
  • Bettors can choose whether to specify a Taker when creating a Wager. If no Taker is specified during creation, anyone can fill their Wager given that the expiration period of 30 days has not passed.
  • If there is no Taker specified during creation, the Bettor will pay a fee during the creation of the Wager to a team determined fee address in the form of the specified payment token; the payment token can be either ETH or a team-approved ERC-20 token. If there is a Taker specified, fees are collected when the Wager is filled.
  • When calculating a fee, the latest USD Price of the payment token is determined by a Chainlink Oracle specified by the team to be used for the given payment token. If the amount being wagered is not greater than $10, the transaction will revert, ensuring that this minimum wager USD value is met.
  • The fee for participating in a wager is calculated as 0.5% of the wager amount; if the calculated fee has a price below $5, it is ensured that the minimum fee paid is $5. The initial wager amount for the user is reduced by the amount of this fee.
  • Wagers can be filled only once, as long as the owner has not deactivated the wager token, making it unfillable; this contract ensures Bettors cannot fill their own wagers.
  • If a Taker was specified during creation of the Wager, it is ensured that the Taker is filling the Wager. It is intended that both the Bettor and the Taker pay their fee to the team determined fee address in the specified payment token at this time.
  • If there was not a Taker specified during the creation of the Wager, anyone can fill the Wager effectively becoming the Taker. It is intended that the Taker pay both the fee and their wager in the specified payment token at this time.
  • Anyone can initiate the redemption of a Wager as long as the Wager hasn't been cancelled, the wager token has not been marked as refundable during the applicable time period, or the duration of the wager has not passed.
  • During a redemption, historical price data from the end time of the Wager is received from the Chainlink Oracle assigned to the wager token by the team.
    • For both types of Wagers, if there is an issue receiving the historical price from the Chainlink Oracle for the end time of the Wager, it is considered a draw.
    • For a Fixed Wager, the Bettor will win based on if the price of the wager token is at least the wager price if they bet above, or at or below the wager price if they bet below. The Taker wins otherwise.
    • For a Conditional Wager, if the Bettor bet on a price above the price bet on by the Taker, they will win if the price is at least their wager price. The Taker will win only if the price of the wager token is at or below the price they wagered. If the Bettor bet below the price of the Taker, then they will win if the price is at or below their wager price. The Taker will win only if the price is at least their wager price. If neither the Bettor nor the Taker are in a winning situation, the wager is considered a draw.
    • Once the winner has been determined, they are paid out the winning sum of both the Bettor and Taker's wager amount, in the specified wager payment token. In the event of a draw, both users are paid out their wager amount.
  • Either the Bettor or an assigned Taker for a Wager can cancel an existing Wager as long as it has not been filled. Upon cancellation of a Wager, the Bettor will get refunded the wager amount they paid in either ETH or an ERC20 payment token; if there was a Taker specified during the creation of the Wager being cancelled, the Bettor will get the fee they paid back.
  • Refunds of the wager amount of both the Bettor and the Taker can be refunded after the team has deactivated the wager token. If a refund is issued on a filled wager, it is ensured that the duration of the wager has not passed. The Wager is only considered closed after both the Bettor and the Taker have received their refunds.
  • The owner can initialize the contract once by specifying an address to collect fees and an owner address.
  • The owner can toggle wager and payment tokens as active or not, as well as assign the addresses of Chainlink Oracles to be used for the tokens respectively.
  • The owner can assign a token as refundable or not.
TokenLockup Contract:
  • This contract allows for users to lockup ETH or any ERC20 token for a specified amount of time up to 50 years.
  • During unlock, it is ensured that the duration of the lockup has passed. If it has, the locked amount for the specified id is sent to the caller of the function.

Audit Results

Vulnerability Category Notes Result
Arbitrary Jump/Storage Write N/A PASS
Centralization of Control
  • Owner can toggle whether payment and wager tokens are active or not.
  • Owner can assign a token as refundable or not, causing a wager to not be filled.
PASS
Compiler Issues N/A PASS
Delegate Call to Untrusted Contract N/A PASS
Dependence on Predictable Variables N/A PASS
Ether/Token Theft N/A PASS
Flash Loans N/A PASS
Front Running N/A PASS
Improper Events N/A PASS
Improper Authorization Scheme N/A PASS
Integer Over/Underflow N/A PASS
Logical Issues N/A PASS
Oracle Issues N/A PASS
Outdated Compiler Version N/A PASS
Race Conditions N/A PASS
Reentrancy N/A PASS
Signature Issues N/A PASS
Unbounded Loops N/A PASS
Unused Code N/A PASS
Overall Contract Safety   PASS

FixedWager Contract

Smart Contract Audit - Inheritance

Smart Contract Audit - Graph


 ($) = payable function
 # = non-constant function

 Int = Internal
 Ext = External
 Pub = Public

 +  Context 
    - [Int] _msgSender
    - [Int] _msgData

 +  Ownable (Context)
    - [Pub]  #
    - [Pub] owner
    - [Pub] renounceOwnership #
       - modifiers: onlyOwner
    - [Pub] transferOwnership #
       - modifiers: onlyOwner
    - [Int] _transferOwnership #

 + [Int] IERC20 
    - [Ext] totalSupply
    - [Ext] balanceOf
    - [Ext] transfer #
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] transferFrom #

 + [Lib] Address 
    - [Int] isContract
    - [Int] sendValue #
    - [Int] functionCall #
    - [Int] functionCall #
    - [Int] functionCallWithValue #
    - [Int] functionCallWithValue #
    - [Int] functionStaticCall
    - [Int] functionStaticCall
    - [Int] functionDelegateCall #
    - [Int] functionDelegateCall #
    - [Int] verifyCallResult

 + [Lib] SafeERC20 
    - [Int] safeTransfer #
    - [Int] safeTransferFrom #
    - [Int] safeApprove #
    - [Int] safeIncreaseAllowance #
    - [Int] safeDecreaseAllowance #
    - [Prv] _callOptionalReturn #

 + [Int] IERC20Metadata (IERC20)
    - [Ext] name
    - [Ext] symbol
    - [Ext] decimals

 +  ReentrancyGuard 
    - [Pub]  #

 + [Int] AggregatorInterface 
    - [Ext] latestAnswer
    - [Ext] latestTimestamp
    - [Ext] latestRound
    - [Ext] getAnswer
    - [Ext] getTimestamp

 + [Int] AggregatorV3Interface 
    - [Ext] decimals
    - [Ext] description
    - [Ext] version
    - [Ext] getRoundData
    - [Ext] latestRoundData

 + [Int] AggregatorV2V3Interface (AggregatorInterface, AggregatorV3Interface)

 +  RoundIdFetcher 
    - [Pub]  #
    - [Pub] getPhaseForTimestamp
    - [Pub] _binarySearchForTimestamp
    - [Pub] getRoundId
    - [Int] getRoundIdForTimestamp

 +  BartrrBase (Ownable, RoundIdFetcher, ReentrancyGuard)
    - [Ext] oracleMalfunction #
       - modifiers: onlyOwner
    - [Ext] oracleRecovery #
       - modifiers: onlyOwner
    - [Ext] init #
       - modifiers: onlyOwner
    - [Ext] updateWagerToken #
       - modifiers: onlyOwner
    - [Ext] updatePaymentToken #
       - modifiers: onlyOwner
    - [Ext] updateWagerTokens #
       - modifiers: onlyOwner
    - [Ext] updatePaymentTokens #
       - modifiers: onlyOwner
    - [Int] _transfer #
    - [Int] _getHistoricalPrice
    - [Int] _getLatestPrice
    - [Int] _calculateFee

 +  FixedWager (BartrrBase)
    - [Pub]  #
    - [Pub] getAllWagers
    - [Ext] createWager ($)
       - modifiers: nonReentrant
    - [Int] _createWager #
    - [Ext] fillWager ($)
       - modifiers: nonReentrant
    - [Ext] cancelWager #
       - modifiers: nonReentrant
    - [Int] _refundWager #
       - modifiers: nonReentrant
    - [Int] _redeemWager #
       - modifiers: nonReentrant
    - [Ext] redeem #
       - modifiers: nonReentrant
    - [Pub] checkWinner

ConditionalWager Contract

Smart Contract Audit - Inheritance

Smart Contract Audit - Graph


 ($) = payable function
 # = non-constant function

 Int = Internal
 Ext = External
 Pub = Public

  +  Context 
    - [Int] _msgSender
    - [Int] _msgData

 +  Ownable (Context)
    - [Pub]  #
    - [Pub] owner
    - [Pub] renounceOwnership #
       - modifiers: onlyOwner
    - [Pub] transferOwnership #
       - modifiers: onlyOwner
    - [Int] _transferOwnership #

 + [Int] IERC20 
    - [Ext] totalSupply
    - [Ext] balanceOf
    - [Ext] transfer #
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] transferFrom #

 + [Lib] Address 
    - [Int] isContract
    - [Int] sendValue #
    - [Int] functionCall #
    - [Int] functionCall #
    - [Int] functionCallWithValue #
    - [Int] functionCallWithValue #
    - [Int] functionStaticCall
    - [Int] functionStaticCall
    - [Int] functionDelegateCall #
    - [Int] functionDelegateCall #
    - [Int] verifyCallResult

 + [Lib] SafeERC20 
    - [Int] safeTransfer #
    - [Int] safeTransferFrom #
    - [Int] safeApprove #
    - [Int] safeIncreaseAllowance #
    - [Int] safeDecreaseAllowance #
    - [Prv] _callOptionalReturn #

 + [Int] IERC20Metadata (IERC20)
    - [Ext] name
    - [Ext] symbol
    - [Ext] decimals

 +  ReentrancyGuard 
    - [Pub]  #

 + [Int] AggregatorInterface 
    - [Ext] latestAnswer
    - [Ext] latestTimestamp
    - [Ext] latestRound
    - [Ext] getAnswer
    - [Ext] getTimestamp

 + [Int] AggregatorV3Interface 
    - [Ext] decimals
    - [Ext] description
    - [Ext] version
    - [Ext] getRoundData
    - [Ext] latestRoundData

 + [Int] AggregatorV2V3Interface (AggregatorInterface, AggregatorV3Interface)

 +  RoundIdFetcher 
    - [Pub]  #
    - [Pub] getPhaseForTimestamp
    - [Pub] _binarySearchForTimestamp
    - [Pub] getRoundId
    - [Int] getRoundIdForTimestamp

 +  BartrrBase (Ownable, RoundIdFetcher, ReentrancyGuard)
    - [Ext] oracleMalfunction #
       - modifiers: onlyOwner
    - [Ext] oracleRecovery #
       - modifiers: onlyOwner
    - [Ext] init #
       - modifiers: onlyOwner
    - [Ext] updateWagerToken #
       - modifiers: onlyOwner
    - [Ext] updatePaymentToken #
       - modifiers: onlyOwner
    - [Ext] updateWagerTokens #
       - modifiers: onlyOwner
    - [Ext] updatePaymentTokens #
       - modifiers: onlyOwner
    - [Int] _transfer #
    - [Int] _getHistoricalPrice
    - [Int] _getLatestPrice
    - [Int] _calculateFee

 +  ConditionalWager (BartrrBase)
    - [Pub]  #
    - [Pub] getAllWagers
    - [Ext] createWager ($)
    - [Int] _createWager #
    - [Ext] fillWager ($)
       - modifiers: nonReentrant
    - [Ext] cancelWager #
       - modifiers: nonReentrant
    - [Int] _refundWager #
       - modifiers: nonReentrant
    - [Int] _redeemWager #
       - modifiers: nonReentrant
    - [Ext] redeem #
       - modifiers: nonReentrant
    - [Pub] checkWinner

TokenLockup Contract

Smart Contract Audit - Inheritance

Smart Contract Audit - Graph


 ($) = payable function
 # = non-constant function

 Int = Internal
 Ext = External
 Pub = Public

 + [Int] IERC20 
    - [Ext] totalSupply
    - [Ext] balanceOf
    - [Ext] transfer #
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] transferFrom #

 + [Lib] Address 
    - [Int] isContract
    - [Int] sendValue #
    - [Int] functionCall #
    - [Int] functionCall #
    - [Int] functionCallWithValue #
    - [Int] functionCallWithValue #
    - [Int] functionStaticCall
    - [Int] functionStaticCall
    - [Int] functionDelegateCall #
    - [Int] functionDelegateCall #
    - [Int] verifyCallResult

 + [Lib] SafeERC20 
    - [Int] safeTransfer #
    - [Int] safeTransferFrom #
    - [Int] safeApprove #
    - [Int] safeIncreaseAllowance #
    - [Int] safeDecreaseAllowance #
    - [Prv] _callOptionalReturn #

 +  ReentrancyGuard 
    - [Pub]  #

 +  TokenLockup (ReentrancyGuard)
    - [Pub]  #
    - [Ext] lockTokens ($)
    - [Ext] unlockTokens #
       - modifiers: nonReentrant
    - [Int] _transfer #

About SourceHat

SourceHat has quickly grown to have one of the most experienced and well-equipped smart contract auditing teams in the industry. Our team has conducted 1800+ solidity smart contract audits covering all major project types and protocols, securing a total of over $50 billion U.S. dollars in on-chain value!
Our firm is well-reputed in the community and is trusted as a top smart contract auditing company for the review of solidity code, no matter how complex. Our team of experienced solidity smart contract auditors performs audits for tokens, NFTs, crowdsales, marketplaces, gambling games, financial protocols, and more!

Contact us today to get a free quote for a smart contract audit of your project!

What is a SourceHat Audit?

Typically, a smart contract audit is a comprehensive review process designed to discover logical errors, security vulnerabilities, and optimization opportunities within code. A SourceHat Audit takes this a step further by verifying economic logic to ensure the stability of smart contracts and highlighting privileged functionality to create a report that is easy to understand for developers and community members alike.

How Do I Interpret the Findings?

Each of our Findings will be labeled with a Severity level. We always recommend the team resolve High, Medium, and Low severity findings prior to deploying the code to the mainnet. Here is a breakdown on what each Severity level means for the project:

  • High severity indicates that the issue puts a large number of users' funds at risk and has a high probability of exploitation, or the smart contract contains serious logical issues which can prevent the code from operating as intended.
  • Medium severity issues are those which place at least some users' funds at risk and has a medium to high probability of exploitation.
  • Low severity issues have a relatively minor risk association; these issues have a low probability of occurring or may have a minimal impact.
  • Informational issues pose no immediate risk, but inform the project team of opportunities for gas optimizations and following smart contract security best practices.