Dovish Weth Index Module
Smart Contract Audit Report
Audit Summary
Dovish Finance is creating a new smart contract to manage WETH and USDC fund allocations for associated "Set Tokens".
For this audit, we reviewed Dovish Finance's WethIndexModule contract at commit c4898e6fe27a60ea444e4f8b99b0c343e133d3a9 on the team's private GitHub repository.
Audit Findings
A Low finding remains present, but has been acknowledged by the team. In addition, centralized aspects are present.
Date: March 10th, 2023.
Updated: March 14th, 2023 to reflect changes from commit 445982e62a8921f457105934b4c7774cad94e0a7 to commit c4898e6fe27a60ea444e4f8b99b0c343e133d3a9.Finding #1 - WethIndexModule - Low
Description: As the contract allows users to trigger the associated SetToken contract to swap its funds between USDC and WETH, trades can be frontrun by malicious users in certain scenarios. When buy data is prepared with either the UniswapV2 or V3 Router, the contract specifies a minimum token amount to receive of 1. Additionally, 20% slippage is permitted when selling through either exchange.
Risk/Impact: Any buy or sell can be frontrun with a separate buy or sell in order to unfavorably decrease or increase the price of USDC or ETH. As a result, the contract may be required to supply more funds for a swap than intended, or receive less funds than intended. As contracts are not permitted to initiate trades and therefore cannot execute a flashloan attack, and WETH and USDC liquidity pools are large, a user would have to hold a massive amount of funds in order to make a significant impact.
Recommendation: The project team should either use the associated Price Oracle contract to calculate appropriate slippage, or ensure that the maximum swap amounts are set to a small value. The team should also consider decreasing the permitted slippage rate.
Update: The team plans to menually update the trade maximums to 20% of a vault size below $1M, 10% below $5M and 5% between $5M and $10M.
Finding #2 - WethIndexModule - Informational (Resolved)
Description: The "exchange" field of AssetInfo structs is fetched and updated throughout the contract, but is never substantially used.
Recommendation: The setExchanges() function can be removed along with all mentions of the exchange field for gas savings on deployment and function calls.
Resolution: The team has implemented the above recommendation.
Finding #3 - WethIndexModule - Informational (Resolved)
Description: The following internal function is declared, but is never used:
Recommendation: This function can be removed for gas savings on deployment and function calls._noTokensToSell()
Resolution: The team has implemented the above recommendation.
Finding #4 - WethIndexModule - Informational (Resolved)
Description: The following variables are initialized in the _executeTrade() function, but are never used:
Recommendation: These variables can be removed for additional gas savings on each function call.wethBalance, usdcBalance
Resolution: The team has implemented the above recommendation.
Contract Overview
- As the SetToken, Controller, and Price Oracle contracts were not included in the scope of this audit, we are unable to provide an assessment with regards to their security or functionality.
- ReentrancyGuard is utilized to prevent reentrancy attacks in applicable functions.
- As the contract is implemented with Solidity v0.8.0, it is safe from any possible overflows/underflows.
- This contract is used to maintain desired WETH:USDC ratios and balances held by an associated Set Token contract.
- While the open trading flag is enabled, any EOA can initiate a trade with a specified Component, intended to be either WETH or USDC. While the flag is disabled, only addresses included in the Trader Whitelist are permitted to initiate a trade.
- Contracts are not permitted to initiate trades at any time.
- When a trade is initiated, the contract determines whether to use the funds in the Set Token contract to buy or sell the specified Component. All swaps are made between USDC and ETH.
- If the Set Token's current Position for the Component is greater than the Component's target position, a buy is calculated. If the current Position is less than the target, a sell is calculated.
- The SetToken's position is calculated using logic from the Set Token contract; the Component's target position is initially set using the SetToken contract, but is updated by Manager of the Set Token contract upon any "rebalance".
- The Component amount to buy with or the amount to receive from a sell is calculated as the difference between the current position and the target position.
- The amount to be swapped is limited to the Component's trade maximum.
- This contract is only used to determine swap data including swap amounts, slippage, and which exchange to use; this data is then sent to the Set Token contract in which the swap is intended to be executed.
- Once a Component is traded, it cannot be traded again until its specified cooldown period has passed. A Component on cooldown can still be included in a swap if a trade is initiated with the other Component.
- The Manager of the Set Token contract can execute a "rebalance" at any time to update target values and contract properties.
- When rebalancing, the Manager specifies a list of new target units for Components, a list of previous target units, a "position multiplier", and a "signal".
- The position multiplier and a Component's target units are used to calculate a Component's target position.
- The current signal is used to indicate market direction. If the signal from a rebalance is equal to the previous rebalance's signal, trading functionality is disabled.
- If the target allocations of both WETH and USDC are currently met, a user can increase the targets for both WETH and USDC by a small percentage.
- While the open trading flag is disabled, only users included in the Trader whitelist can increase targets.
- The Manager of the associated Set Token can update the trade maximum and cooldown period for any Component at any time.
- The project team should ensure that trade maximums are limited to a small value to prevent any potential frontrunning.
- The Manager of the associated Set Token can update the Uniswap V2 and Uniswap V3 Router addresses at any time.
- The Manager of the associated Set Token can toggle the contract to use either the Uniswap V2 Router or V3 Router for trades at any time.
- The Manager of the associated Set Token can add or remove a user from the Trader Whitelist at any time.
- The Manager can toggle the open trading flag at any time.
- Manager-only functions can be called only if the Set token is initialized and registered in the associated Controller contract.
Audit Results
| Vulnerability Category | Notes | Result |
|---|---|---|
| Arbitrary Jump/Storage Write | N/A | PASS |
| Centralization of Control |
|
WARNING |
| 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 | Trades are susceptible to frontrunning, although the likelihood of any significant impact is low. | 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 |
| Sybil Attack | N/A | PASS |
| Unbounded Loops | N/A | PASS |
| Unused Code | N/A | PASS |
| Overall Contract Safety | PASS |
Inheritance Chart

Function Graph

Functions Overview
($) = 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] Math
- [Int] max
- [Int] min
- [Int] average
- [Int] ceilDiv
- [Int] mulDiv
- [Int] mulDiv
- [Int] sqrt
- [Int] sqrt
- [Int] log2
- [Int] log2
- [Int] log10
- [Int] log10
- [Int] log256
- [Int] log256
+ ReentrancyGuard
- [Pub] #
- [Prv] _nonReentrantBefore #
- [Prv] _nonReentrantAfter #
+ [Lib] SafeCast
- [Int] toUint248
- [Int] toUint240
- [Int] toUint232
- [Int] toUint224
- [Int] toUint216
- [Int] toUint208
- [Int] toUint200
- [Int] toUint192
- [Int] toUint184
- [Int] toUint176
- [Int] toUint168
- [Int] toUint160
- [Int] toUint152
- [Int] toUint144
- [Int] toUint136
- [Int] toUint128
- [Int] toUint120
- [Int] toUint112
- [Int] toUint104
- [Int] toUint96
- [Int] toUint88
- [Int] toUint80
- [Int] toUint72
- [Int] toUint64
- [Int] toUint56
- [Int] toUint48
- [Int] toUint40
- [Int] toUint32
- [Int] toUint24
- [Int] toUint16
- [Int] toUint8
- [Int] toUint256
- [Int] toInt248
- [Int] toInt240
- [Int] toInt232
- [Int] toInt224
- [Int] toInt216
- [Int] toInt208
- [Int] toInt200
- [Int] toInt192
- [Int] toInt184
- [Int] toInt176
- [Int] toInt168
- [Int] toInt160
- [Int] toInt152
- [Int] toInt144
- [Int] toInt136
- [Int] toInt128
- [Int] toInt120
- [Int] toInt112
- [Int] toInt104
- [Int] toInt96
- [Int] toInt88
- [Int] toInt80
- [Int] toInt72
- [Int] toInt64
- [Int] toInt56
- [Int] toInt48
- [Int] toInt40
- [Int] toInt32
- [Int] toInt24
- [Int] toInt16
- [Int] toInt8
- [Int] toInt256
+ [Lib] SafeMath
- [Int] tryAdd
- [Int] trySub
- [Int] tryMul
- [Int] tryDiv
- [Int] tryMod
- [Int] add
- [Int] sub
- [Int] mul
- [Int] div
- [Int] mod
- [Int] sub
- [Int] div
- [Int] mod
+ [Int] IUniswapV3SwapCallback
- [Ext] uniswapV3SwapCallback #
+ [Int] IV3SwapRouter (IUniswapV3SwapCallback)
- [Ext] exactInputSingle ($)
- [Ext] exactInput ($)
- [Ext] exactOutputSingle ($)
- [Ext] exactOutput ($)
+ [Lib] AddressArrayUtils
- [Int] indexOf
- [Int] contains
- [Int] hasDuplicate
- [Int] remove
- [Int] removeStorage #
- [Int] pop
- [Int] extend
- [Int] validatePairsWithArray
- [Int] validatePairsWithArray
- [Int] validatePairsWithArray
- [Int] validatePairsWithArray
- [Int] validatePairsWithArray
- [Int] _validateLengthAndUniqueness
+ [Int] IController
- [Ext] addSet #
- [Ext] feeRecipient
- [Ext] getModuleFee
- [Ext] isModule
- [Ext] isSet
- [Ext] isSystemContract
- [Ext] resourceId
+ [Int] IPriceOracle
- [Ext] getPrice
- [Ext] masterQuoteAsset
+ [Lib] Invoke
- [Int] invokeApprove #
- [Int] invokeTransfer #
- [Int] strictInvokeTransfer #
- [Int] invokeUnwrapWETH #
- [Int] invokeWrapWETH #
+ [Int] ISetToken (IERC20)
- [Ext] addComponent #
- [Ext] removeComponent #
- [Ext] editDefaultPositionUnit #
- [Ext] addExternalPositionModule #
- [Ext] removeExternalPositionModule #
- [Ext] editExternalPositionUnit #
- [Ext] editExternalPositionData #
- [Ext] invoke #
- [Ext] editPositionMultiplier #
- [Ext] mint #
- [Ext] burn #
- [Ext] lock #
- [Ext] unlock #
- [Ext] addModule #
- [Ext] removeModule #
- [Ext] initializeModule #
- [Ext] setManager #
- [Ext] manager
- [Ext] moduleStates
- [Ext] getModules
- [Ext] getDefaultPositionRealUnit
- [Ext] getExternalPositionRealUnit
- [Ext] getComponents
- [Ext] getExternalPositionModules
- [Ext] getExternalPositionData
- [Ext] isExternalPositionModule
- [Ext] isComponent
- [Ext] positionMultiplier
- [Ext] getPositions
- [Ext] getTotalComponentRealUnits
- [Ext] isInitializedModule
- [Ext] isPendingModule
- [Ext] isLocked
+ [Int] IWETH (IERC20)
- [Ext] deposit ($)
- [Ext] withdraw #
+ [Int] IERC20Permit
- [Ext] permit #
- [Ext] nonces
- [Ext] DOMAIN_SEPARATOR
+ [Lib] Address
- [Int] isContract
- [Int] sendValue #
- [Int] functionCall #
- [Int] functionCall #
- [Int] functionCallWithValue #
- [Int] functionCallWithValue #
- [Int] functionStaticCall
- [Int] functionStaticCall
- [Int] functionDelegateCall #
- [Int] functionDelegateCall #
- [Int] verifyCallResultFromTarget
- [Int] verifyCallResult
- [Prv] _revert
+ [Lib] SafeERC20
- [Int] safeTransfer #
- [Int] safeTransferFrom #
- [Int] safeApprove #
- [Int] safeIncreaseAllowance #
- [Int] safeDecreaseAllowance #
- [Int] safePermit #
- [Prv] _callOptionalReturn #
+ [Lib] ExplicitERC20
- [Int] transferFrom #
+ [Int] IModule
- [Ext] removeModule #
+ [Lib] SignedSafeMath
- [Int] mul
- [Int] div
- [Int] sub
- [Int] add
+ [Lib] PreciseUnitMath
- [Int] preciseUnit
- [Int] preciseUnitInt
- [Int] maxUint256
- [Int] maxInt256
- [Int] minInt256
- [Int] preciseMul
- [Int] preciseMul
- [Int] preciseMulCeil
- [Int] preciseDiv
- [Int] preciseDiv
- [Int] preciseDivCeil
- [Int] preciseDivCeil
- [Int] divDown
- [Int] conservativePreciseMul
- [Int] conservativePreciseDiv
- [Int] safePower
- [Int] approximatelyEquals
- [Int] abs
- [Int] neg
+ [Lib] Position
- [Int] hasDefaultPosition
- [Int] hasExternalPosition
- [Int] hasSufficientDefaultUnits
- [Int] hasSufficientExternalUnits
- [Int] editDefaultPosition #
- [Int] editExternalPosition #
- [Int] getDefaultTotalNotional
- [Int] getDefaultPositionUnit
- [Int] getDefaultTrackedBalance
- [Int] calculateAndEditDefaultPosition #
- [Int] calculateDefaultEditPositionUnit
+ [Int] IIntegrationRegistry
- [Ext] addIntegration #
- [Ext] getIntegrationAdapter
- [Ext] getIntegrationAdapterWithHash
- [Ext] isValidIntegration
+ [Int] ISetValuer
- [Ext] calculateSetTokenValuation
+ [Lib] ResourceIdentifier
- [Int] getIntegrationRegistry
- [Int] getPriceOracle
- [Int] getSetValuer
+ ModuleBase (IModule)
- [Pub] #
- [Int] transferFrom #
- [Int] getAndValidateAdapter
- [Int] getAndValidateAdapterWithHash
- [Int] getModuleFee
- [Int] payProtocolFeeFromSetToken #
- [Int] isSetPendingInitialization
- [Int] isSetManager
- [Int] isSetValidAndInitialized
- [Int] getNameHash
- [Int] _validateOnlyManagerAndValidSet
- [Int] _validateOnlySetManager
- [Int] _validateOnlyValidAndInitializedSet
- [Int] _validateOnlyModule
- [Int] _validateOnlyValidAndPendingSet
+ [Lib] Uint256ArrayUtils
- [Int] extend
+ WethIndexModule (ModuleBase, ReentrancyGuard)
- [Pub] #
- modifiers: ModuleBase
- [Pub] startRebalance #
- modifiers: onlyManagerAndValidSet
- [Pub] trade #
- modifiers: nonReentrant,onlyAllowedTrader,onlyEOA
- [Ext] raiseAssetTargets #
- modifiers: nonReentrant,onlyAllowedTrader
- [Ext] setTradeMaximums #
- modifiers: onlyManagerAndValidSet
- [Ext] setRouterAddresses #
- modifiers: onlyManagerAndValidSet
- [Ext] setUsingV3 #
- modifiers: onlyManagerAndValidSet
- [Ext] setCoolOffPeriods #
- modifiers: onlyManagerAndValidSet
- [Ext] updateTraderStatus #
- modifiers: onlyManagerAndValidSet
- [Ext] updateAnyoneTrade #
- modifiers: onlyManagerAndValidSet
- [Ext] initialize #
- modifiers: onlySetManager,onlyValidAndPendingSet
- [Ext] removeModule #
- [Ext] getTargetUnits
- [Ext] getRebalanceComponents
- [Int] _validateTradeParameters
- [Pub] _calculateTradeSizeAndDirection
- [Int] _buyUnderweight #
- [Int] _sellOverweight #
- [Int] _executeTrade #
- [Int] _updatePositionState #
- [Int] _getUniswapLikeTradeData
- [Int] _allTargetsMet
- [Int] _normalizeTargetUnit
- [Int] _isAllowedTrader
- [Int] _validateArrays
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.