Platform: Code4rena
Start Date: 09/09/2022
Pot Size: $42,000 USDC
Total HM: 2
Participants: 101
Period: 3 days
Judge: hickuphh3
Total Solo HM: 2
Id: 161
League: ETH
Rank: 99/101
Findings: 1
Award: $33.58
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: GalloDaSballo
Also found by: 0x040, 0x1f8b, 0x4non, 0x52, 0x85102, 0xNazgul, 0xSky, 0xSmartContract, Aymen0909, Bnke0x0, CertoraInc, Chandr, Chom, CodingNameKiki, Deivitto, Diana, Funen, JC, Jeiwan, Junnon, KIntern_NA, Lambda, Mohandes, Noah3o6, Ocean_Sky, Picodes, R2, Randyyy, RaymondFam, ReyAdmirado, Rohan16, Rolezn, Samatak, Sm4rty, SnowMan, SooYa, StevenL, Tagir2003, Tointer, TomJ, Tomo, V_B, Waze, _Adam, __141345__, a12jmx, ajtra, ak1, asutorufos, bharg4v, bobirichman, brgltd, c3phas, cccz, cryptonue, cryptostellar5, cryptphi, csanuragjain, d3e4, datapunk, delfin454000, dipp, djxploit, durianSausage, erictee, fatherOfBlocks, gogo, got_targ, hansfriese, horsefacts, hyh, ignacio, innertia, izhuer, karanctf, ladboy233, leosathya, lucacez, lukris02, mics, oyc_109, pashov, pauliax, prasantgupta52, rbserver, ret2basic, rfa, robee, rokinot, rotcivegaf, rvierdiiev, sach1r0, scaraven, sikorico, simon135, smiling_heretic, sorrynotsorry, unforgiven, wagmi, yixxas
33.5762 USDC - $33.58
Some tokens don't correctly implement the EIP20 standard and their approve function returns void instead of a success boolean. Calling these functions with the correct EIP20 function signatures will always revert. Tokens that don't correctly implement the latest EIP20 spec, like USDT, will be unusable in the mentioned contracts as they revert the transaction because of the missing return value. We recommend using OpenZeppelin’s SafeERC20 versions with the safeApprove function that handle the return value check as well as non-standard-compliant tokens. The list of occurrences in format (solidity file, line number, actual line)
ERC20TokemakPCVDeposit.sol, 29, token.approve(pool, amount); VoteEscrowTokenManager.sol, 84, liquidToken.approve(address(veToken), tokenBalance); BalancerLBPSwapper.sol, 176, IERC20(tokenReceived).approve(address(_vault), type(uint256).max); VotiumBriber.sol, 55, token.approve(address(votiumBribe), tokenAmount); AavePCVDeposit.sol, 86, token.approve(address(lendingPool), pendingBalance); PSMRouter.sol, 25, _fei.approve(address(_psm), type(uint256).max); ERC20CompoundPCVDeposit.sol, 28, token.approve(address(cToken), amount); ConvexPCVDeposit.sol, 73, curvePool.approve(address(convexBooster), lpTokenBalance); BalancerLBPSwapper.sol, 175, IERC20(tokenSpent).approve(address(_vault), type(uint256).max); UniswapPCVDeposit.sol, 218, IERC20(_token).approve(address(router), maxTokens); LiquidityGaugeManager.sol, 116, IERC20(token).approve(gaugeAddress, amount); LiquidityGaugeManager.sol, 128, IERC20(token).approve(gaugeAddress, amount); VoteEscrowTokenManager.sol, 79, liquidToken.approve(address(veToken), tokenBalance); IVault.sol, 607, * must have allowed the Vault to use their tokens via `IERC20.approve()`. This matches the behavior of BalancerPCVDepositWeightedPool.sol, 202, IERC20(address(poolAssets[i])).approve(address(vault), balances[i]);
From solidity docs: Properly functioning code should never reach a failing assert statement; if this happens there is a bug in your contract which you should fix. With assert the user pays the gas and with require it doesn't. The ETH network gas isn't cheap and users can see it as a scam.
FuseFixer.sol : reachable assert in line 75 FuseFixer.sol : reachable assert in line 77 TribalChief.sol : reachable assert in line 570 FuseFixer.sol : reachable assert in line 79 FuseFixer.sol : reachable assert in line 81 ExchangerTimelock.sol : reachable assert in line 43 ABDKMath64x64.sol : reachable assert in line 598 FuseFixer.sol : reachable assert in line 73 TribalChief.sol : reachable assert in line 565 FuseFixer.sol : reachable assert in line 74 FuseFixer.sol : reachable assert in line 72 CollateralizationOracleGuardian.sol : reachable assert in line 77 FuseFixer.sol : reachable assert in line 76 FuseFixer.sol : reachable assert in line 80 FuseFixer.sol : reachable assert in line 78 ExchangerTimelock.sol : reachable assert in line 39 TribeMinter.sol : reachable assert in line 185
Need to use safeTransfer instead of transfer. As there are popular tokens, such as USDT that transfer/trasnferFrom method doesn’t return anything. The transfer return value has to be checked (as there are some other tokens that returns false instead revert), that means you must
MockCurveMetapool.sol, 23 (add_liquidity), IERC20(coins[0]).transferFrom(msg.sender, address(this), amounts[0]); MockCurveMetapool.sol, 52 (remove_liquidity_one_coin), IERC20(coins[uint256(uint128(i))]).transfer(msg.sender, _amountOut); MockPCVDepositV2.sol, 42 (withdraw), IERC20(balanceReportedIn).transfer(to, amount); MockUniswapV2PairLiquidity.sol, 99 (burnToken), IERC20(token0).transfer(to, amount0); MockLendingPool.sol, 21 (deposit), IERC20(asset).transferFrom(msg.sender, address(this), amount);
The attacker can push unlimitedly to an array, that some function loop over this array. If increasing the array size enough, calling the function that does a loop over the array will always revert since there is a gas limit. This is an High Risk issue since those arrays are publicly allows to push items into them.
TribalChief.sol (L254): Unbounded loop on the array poolInfo that can be publicly pushed by ['add']
You allow in some arrays to have duplicates. Sometimes you assumes there are no duplicates in the array.
PodFactory._createOptimisticPod pushed (safeAddress) TribalChief.deposit pushed (poolDeposit) TribalChief.add pushed (_rewarder) TribalChief.add pushed (_stakedToken)
This issue is about arithmetic computation that could have been done more percise. The following are places in the codebase in which you multiplied after the divisions. Doing the multiplications at start lead to more accurate calculations. This is a list of places in the code that this appears (Solidity file, line number, actual line):
UniswapPCVDeposit.sol, 153, uint256 resistantOtherInPool = Decimal.one().div(priceOfToken).mul(k).asUint256().sqrt(); UniswapLens.sol, 62, uint256 resistantOtherInPool = Decimal.one().div(priceOfToken).mul(k).asUint256().sqrt(); AngleUniswapPCVDeposit.sol, 61, uint256 minAgTokenOut = Decimal .from(amountFei) .div(readOracle()) .mul(Constants.BASIS_POINTS_GRANULARITY - maxBasisPointsFromPegLP) .div(Constants.BASIS_POINTS_GRANULARITY) .asUint256();
Some fee parameters of functions are not checked for invalid values. Validate the parameters:
FixedPricePSM.constructor (_redeemFeeBasisPoints) PegStabilityModule._setRedeemFee (newRedeemFeeBasisPoints) PegStabilityModule.constructor (_redeemFeeBasisPoints) PegStabilityModule.setMintFee (newMintFeeBasisPoints) PegStabilityModule.constructor (_mintFeeBasisPoints) NonCustodialPSM._setRedeemFee (newRedeemFeeBasisPoints) PegStabilityModule.setRedeemFee (newRedeemFeeBasisPoints) FixedPricePSM.constructor (_mintFeeBasisPoints) PriceBoundPSM.constructor (_redeemFeeBasisPoints) BaseBalancerPoolManager.setSwapFee (swapFee)
You use safeApprove of openZeppelin although it's deprecated. (see https://github.com/OpenZeppelin/openzeppelin-contracts/blob/566a774222707e424896c0c390a84dc3c13bdcb2/contracts/token/ERC20/utils/SafeERC20.sol#L38) You should change it to increase/decrease Allowance as OpenZeppilin says.
Deprecated safeApprove in RariMerkleRedeemer_flattened.sol line 1743: _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); Deprecated safeApprove in FuseFixer.sol line 150: SafeERC20.safeApprove(IERC20(underlying), ctoken, type(uint256).max); Deprecated safeApprove in BAMMDeposit.sol line 31: lusd.safeApprove(address(BAMM), amount); Deprecated safeApprove in PSMRouter.sol line 24: IERC20(address(Constants.WETH)).approve(address(_psm), type(uint256).max);
The following requires are with empty messages. This is very important to add a message for any require. So the user has enough information to know the reason of failure.
Solidity file: ABDKMath64x64.sol, In line 277 with Empty Require message. Solidity file: WETH9.sol, In line 51 with Empty Require message. Solidity file: MaxFeiWithdrawalGuard.sol, In line 38 with Empty Require message. Solidity file: ABDKMath64x64.sol, In line 442 with Empty Require message.
The following requires has a non comprehensive messages. This is very important to add a comprehensive message for any require. Such that the user has enough information to know the reason of failure:
Solidity file: PCVGuardian.sol, In line 81 with Require message: empty Solidity file: PCVGuardian.sol, In line 56 with Require message: empty Solidity file: PCVGuardian.sol, In line 181 with Require message: set Solidity file: AutoRewardsDistributorV2.sol, In line 108 with Require message: init Solidity file: AutoRewardsDistributorV2.sol, In line 67 with Require message: pid Solidity file: TribalChiefSyncV2.sol, In line 69 with Require message: rewards Solidity file: TribalChiefSyncV2.sol, In line 70 with Require message: timestamp Solidity file: AutoRewardsDistributorV2.sol, In line 70 with Require message: ctoken Solidity file: MergerGate.sol, In line 23 with Require message: rip Solidity file: PCVGuardian.sol, In line 186 with Require message: unset
external / public functions parameters should be validated to make sure the address is not 0. Otherwise if not given the right input it can mistakenly lead to loss of user funds.
PegStabilityModule.sol.withdraw to RatioPCVControllerV2.sol.transferFromRatio to GlobalRateLimitedMinter.sol.mint to
Make sure the treasury is not address(0).
TribeMinter.sol.setTribeTreasury newTribeTreasury
The project is compiled with different versions of solidity, which is not recommended because it can lead to undefined behaviors.
WETH address is hardcoded but it may differ on other chains, e.g. Polygon, so make sure to check this before deploying and update if necessary You should consider injecting WETH address via the constructor. (previous issue: https://github.com/code-423n4/2021-10-ambire-findings/issues/54)
Hardcoded weth address in Constants.sol Hardcoded weth address in VeBalDelegatorPCVDeposit.sol
You should use safe math for solidity version <8 since there is no default over/under flow check it suchversions of solidity.
The contract WETH9.sol doesn't use safe math and is of solidity version < 8
You can't use SafeERC20 for non ERC20 protocols (as for example ERC721) due to undefined behavior of it. The following files does that:
SimpleFeiDaiPSM.sol, 15 : using SafeERC20 for Fei;
owner param should be validated to make sure the owner address is not address(0). Otherwise if not given the right input all only owner accessible functions will be unaccessible.
Tribe.sol.permit owner Fei.sol.permit owner
Most contracts use an init pattern (instead of a constructor) to initialize contract parameters. Unless these are enforced to be atomic with contact deployment via deployment script or factory contracts, they are susceptible to front-running race conditions where an attacker/griefer can front-run (cannot access control because admin roles are not initialized) to initially with their own (malicious) parameters upon detecting (if an event is emitted) which the contract deployer has to redeploy wasting gas and risking other transactions from interacting with the attacker-initialized contract.
Many init functions do not have an explicit event emission which makes monitoring such scenarios harder. All of them have re-init checks; while many are explicit some (those in auction contracts) have implicit reinit checks in initAccessControls() which is better if converted to an explicit check in the main init function itself. (details credit to: https://github.com/code-423n4/2021-09-sushimiso-findings/issues/64) The vulnerable initialization functions in the codebase are:
TribalChief.sol, initialize, 140 StakingTokenWrapper.sol, init, 30 Core.sol, init, 20
Users can mistakenly think that the return value is the named return, but it is actually the actualreturn statement that comes after. To know that the user needs to read the code and is confusing. Furthermore, removing either the actual return or the named return will save gas.
UintArrayOps.sol, positiveDifference ConvexPCVDeposit.sol, resistantBalanceAndFei MaxFeiWithdrawalGuard.sol, getProtecActions CurvePCVDepositPlainPool.sol, resistantBalanceAndFei BalancerLBPSwapper.sol, getTokensIn
The following contracts have a function that allows them an admin to change it to a different address. If the admin accidentally uses an invalid address for which they do not have the private key, then the system gets locked. It is important to have two steps admin change where the first is announcing a pending new admin and the new address should then claim its ownership. A similar issue was reported in a previous contest and was assigned a severity of medium: code-423n4/2021-06-realitycards-findings#105
IBaseBalancerPoolManager.sol PodAdminGateway.sol CoreRef.sol CollateralizationOracleWrapper.sol AutoRewardsDistributorV2.sol ICollateralizationOracleWrapper.sol AngleUniswapPCVDeposit.sol IBasePool.sol IAaveGovernanceV2.sol Permissions.sol ICoreRef.sol BaseBalancerPoolManager.sol AutoRewardsDistributor.sol ICurvePool.sol
The following functions are missing reentrancy modifier although some other pulbic/external functions does use reentrancy modifer. Even though I did not find a way to exploit it, it seems like those functions should have the nonReentrant modifier as the other functions have it as well..
NonCustodialPSM.sol, setGlobalRateLimitedMinter is missing a reentrancy modifier TribalChief.sol, governorWithdrawTribe is missing a reentrancy modifier TribalChief.sol, resetRewards is missing a reentrancy modifier NonCustodialPSM.sol, setPCVDeposit is missing a reentrancy modifier NonCustodialPSM.sol, withdrawERC20 is missing a reentrancy modifier
In the following functions no value is returned, due to which by default value of return will be 0. We assumed that after the update you return the latest new value. (similar issue here: https://github.com/code-423n4/2021-10-badgerdao-findings/issues/85).
TribalChief.sol, updatePool CollateralizationOracleWrapper.sol, update WeightedBalancerPoolManager.sol, updateWeightsGradually MultiRateLimited.sol, updateMaxBufferCap MultiRateLimited.sol, updateMaxRateLimitPerSecond OracleRef.sol, updateOracle ChainlinkOracleWrapper.sol, update PodFactory.sol, updateDefaultPodController CollateralizationOracle.sol, update CompositeOracle.sol, update MultiRateLimited.sol, updateAddress TribalChief.sol, updateBlockReward CollateralizationOracleWrapper.sol, updateIfOutdated ConstantOracle.sol, update TribalChief.sol, massUpdatePools GOhmEthOracle.sol, update
Open TODOs can hint at programming or architectural errors that still need to be fixed. These files has open TODOs:
Open TODO in MockRariMerkleRedeemerNoSigs.sol line 24 : // @todo - do we want to use this, which supports ERC1271, or *just* EOA signatures?
The following functions are missing commenting as describe below:
TribeRagequit.sol, getCirculatingTribe (public), @return is missing RatioPCVControllerV2.sol, _withdrawRatio (internal), parameters pcvDeposit, to, basisPoints not commented FuseFixer.sol, _repayERC20 (internal), parameter underlying not commented RatioPCVControllerV2.sol, _withdrawRatio (internal), @return is missing FuseFixer.sol, withdraw (external), parameters to, amount not commented TribeTimelockedDelegatorBurner.sol, undelegate (external), parameter _delegate not commented RatioPCVControllerV2.sol, _transferETHAsWETH (internal), parameters to, amount not commented ConstantOracle.sol, isOutdated (external), @return is missing RatioPCVControllerV2.sol, _transferWETHAsETH (internal), parameters to, amount not commented Permissions.sol, _setupGovernor (internal), parameter governor not commented NonCustodialPSM.sol, _validatePriceRange (internal), parameter price not commented BalancerPCVDepositBase.sol, claimRewards (external), parameters distributionId, amount, merkleProof not commented FuseFixer.sol, balanceReportedIn (public), @return is missing FuseFixer.sol, balance (public), @return is missing RestrictedPermissions.sol, isGovernor (external), @return is missing
To give more trust to users: functions that set key/critical variables should be put behind a timelock.
https://github.com/code-423n4/2022-09-tribe/tree/main/contracts/core/Core.sol#L32 https://github.com/code-423n4/2022-09-tribe/tree/main/contracts/peg/PriceBoundPSM.sol#L59 https://github.com/code-423n4/2022-09-tribe/tree/main/contracts/refs/OracleRef.sol#L68 https://github.com/code-423n4/2022-09-tribe/tree/main/contracts/tribe/TribeMinter.sol#L86
Some tokens (like USDT) do not work when changing the allowance from an existing non-zero allowance value. They must first be approved by zero and then the actual allowance must be approved.
approve without approving 0 first BalancerLBPSwapper.sol, 176, IERC20(tokenReceived).approve(address(_vault), type(uint256).max); approve without approving 0 first BalancerPCVDepositWeightedPool.sol, 202, IERC20(address(poolAssets[i])).approve(address(vault), balances[i]); approve without approving 0 first LiquidityGaugeManager.sol, 128, IERC20(token).approve(gaugeAddress, amount); approve without approving 0 first PSMRouter.sol, 25, _fei.approve(address(_psm), type(uint256).max); approve without approving 0 first ERC20CompoundPCVDeposit.sol, 28, token.approve(address(cToken), amount); approve without approving 0 first PSMRouter.sol, 24, IERC20(address(Constants.WETH)).approve(address(_psm), type(uint256).max); approve without approving 0 first LiquidityGaugeManager.sol, 116, IERC20(token).approve(gaugeAddress, amount); approve without approving 0 first VotiumBriber.sol, 55, token.approve(address(votiumBribe), tokenAmount); approve without approving 0 first CurvePCVDepositPlainPool.sol, 87, tokens[i].approve(address(curvePool), balances[i]); approve without approving 0 first UniswapPCVDeposit.sol, 218, IERC20(_token).approve(address(router), maxTokens); approve without approving 0 first ConvexPCVDeposit.sol, 73, curvePool.approve(address(convexBooster), lpTokenBalance); approve without approving 0 first ExchangerTimelock.sol, 36, rgt.approve(address(exchanger), rgtBalance); approve without approving 0 first BalancerLBPSwapper.sol, 175, IERC20(tokenSpent).approve(address(_vault), type(uint256).max); approve without approving 0 first ERC20TokemakPCVDeposit.sol, 29, token.approve(pool, amount); approve without approving 0 first BalancerLBPSwapper.sol, 174, _pool.approve(address(_vault), type(uint256).max); approve without approving 0 first BAMMDeposit.sol, 31, lusd.safeApprove(address(BAMM), amount); approve without approving 0 first UniswapLiquidityRemover.sol, 48, FEI_TRIBE_PAIR.approve(address(UNISWAP_ROUTER), amountLP); approve without approving 0 first VlAuraDelegatorPCVDeposit.sol, 116, IERC20(aura).safeApprove(auraLocker, amount); approve without approving 0 first AavePCVDeposit.sol, 86, token.approve(address(lendingPool), pendingBalance); approve without approving 0 first VoteEscrowTokenManager.sol, 84, liquidToken.approve(address(veToken), tokenBalance); approve without approving 0 first VoteEscrowTokenManager.sol, 79, liquidToken.approve(address(veToken), tokenBalance); approve without approving 0 first AngleEuroRedeemer.sol, 86, USDC.approve(MAKER_DAI_USDC_PSM_AUTH, usdcBalance);
use openzeppilin's safeCast in (although its a mock I think it might be good to address):
https://github.com/code-423n4/2022-09-tribe/tree/main/contracts/mock/MockRouter.sol#L62 : unsafe cast uint112(amountToken0Desired) https://github.com/code-423n4/2022-09-tribe/tree/main/contracts/mock/MockRouter.sol#L62 : unsafe cast uint112(amountToken1Desired)
The functions below fail to perform input validation on arrays to verify the lengths match. A mismatch could lead to an exception or undefined behavior. Consider making this a medium risk please.
https://github.com/code-423n4/2022-09-tribe/tree/main/contracts/sentinel/guards/MaxFeiWithdrawalGuard.sol#L31 constructor ['deposits', 'destinations', 'liquiditySources']
A malicious attacker that is also a protocol owner can push unlimitedly to an array, that some function loop over this array. If increasing the array size enough, calling the function that does a loop over the array will always revert since there is a gas limit. This is a Med Risk issue since it can lead to DoS with a reasonable chance of having untrusted owner or even an owner that did a mistake in good faith.
TribalChief.sol (L254): Unbounded loop on the array poolInfo that can be publicly pushed by ['add'] and can't be pulled
the balance of outputToken is checked to be exactly a specified value that is not declared in this specific function. Therefore, a malicious user can transfer to the contract address tiny amount of tokens and the user transactions will always revert.
Potential DoS in ERC20CompoundPCVDeposit.sol, 32
Division by 0 can lead to accidentally revert, (An example of a similar issue - https://github.com/code-423n4/2021-10-defiprotocol-findings/issues/84)
https://github.com/code-423n4/2022-09-tribe/tree/main/contracts/staking/TribalChief.sol#L543 to might be 0 https://github.com/code-423n4/2022-09-tribe/tree/main/contracts/timelocks/LinearTokenTimelock.sol#L25 duration might be 0
There are ERC20 tokens that charge fee for every transfer() / transferFrom().
Vault.sol#addValue() assumes that the received amount is the same as the transfer amount, and uses it to calculate attributions, balance amounts, etc. But, the actual transferred amount can be lower for those tokens. Therefore it's recommended to use the balance change before and after the transfer instead of the amount. This way you also support the tokens with transfer fee - that are popular.
https://github.com/code-423n4/2022-09-tribe/tree/main/scripts/shutdown/data/prod/RariMerkleRedeemer_flattened.sol#L2342 https://github.com/code-423n4/2022-09-tribe/tree/main/contracts/shutdown/fuse/RariMerkleRedeemer.sol#L246 https://github.com/code-423n4/2022-09-tribe/tree/main/contracts/tribe/TribeMinter.sol#L179
#0 - HickupHH3
2022-10-08T08:04:30Z
most of the issues mentioned had files that were OOS. The data dump / spray + pray something sticks reporting style is frankly a waste of the sponsor and judge's time.