Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QA Report #63

Open
code423n4 opened this issue Aug 15, 2022 · 0 comments
Open

QA Report #63

code423n4 opened this issue Aug 15, 2022 · 0 comments
Labels
bug Something isn't working edited-by-warden QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax

Comments

@code423n4
Copy link
Contributor

code423n4 commented Aug 15, 2022

approve return value is ignored

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)

Code instances:

FraxlendPairCore.sol, 1102, _assetContract.approve(_swapperAddress, _borrowAmount);

FraxlendPairCore.sol, 1183, _collateralContract.approve(_swapperAddress, _collateralToSwap);

Unbounded loop on array can lead to DoS

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.

Code instance:

    FraxlendPairDeployer.sol (L123): Unbounded loop on the array deployedPairsArray that can be publicly pushed by ['deploy', 'deployCustom']

Mult instead div in compares

To improve algorithm precision instead using division in comparison use multiplication in the following scenario:

    Instead a < b / c use a * c < b. 

In all of the big and trusted contracts this rule is maintained.

Code instances:

    VaultAccount.sol, 42, if (roundUp && (amount * total.shares) / total.amount < shares) {
    VaultAccount.sol, 25, if (roundUp && (shares * total.amount) / total.shares < amount) {

Missing fee parameter validation

Some fee parameters of functions are not checked for invalid values. Validate the parameters:

Code instances:

    FraxlendPairDeployer.deployCustom (_liquidationFee)
    FraxlendPairDeployer._deployFirst (_liquidationFee)
    FraxlendPair.constructor (_liquidationFee)
    FraxlendPair.changeFee (_newFee)
    FraxlendPairDeployer._logDeploy (_liquidationFee)
    FraxlendPairCore.constructor (_liquidationFee)

safeApprove of openZeppelin is deprecated

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.

Code instances:

    Deprecated safeApprove in FraxlendPairCore.sol line 1102: _assetContract.approve(_swapperAddress, _borrowAmount);
    Deprecated safeApprove in FraxlendPairCore.sol line 1183: _collateralContract.approve(_swapperAddress, _collateralToSwap);

Not verified input

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.

Code instances:

    FraxlendPairCore.sol.repayAsset _borrower
    FraxlendPairCore.sol.repayAssetWithCollateral _swapperAddress
    FraxlendPair.sol.withdrawFees _recipient
    FraxlendPairCore.sol.mint _receiver
    FraxlendPairCore.sol.redeem _receiver

Not verified owner

    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.

Code instances:

    FraxlendPairCore.sol.withdraw _owner
    FraxlendPairCore.sol.redeem _owner

Named return issue

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.

Code instances:

    FraxlendPairCore.sol, _updateExchangeRate
    FraxlendPairDeployer.sol, _deployFirst
    FraxlendPairCore.sol, _addInterest
    VariableInterestRate.sol, getConstants
    FraxlendPairCore.sol, addInterest
    LinearInterestRate.sol, getConstants

Two Steps Verification before Transferring Ownership

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

Code instances:

    IFraxlendWhitelist.sol
    IFraxlendPair.sol

Missing non reentrancy modifier

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..

Code instance:

    FraxlendPairCore.sol, initialize is missing a reentrancy modifier

Never used parameters

Those are functions and parameters pairs that the function doesn't use the parameter. In case those functions are external/public this is even worst since the user is required to put value that never used and can misslead him and waste its time.

Code instances:

    VariableInterestRate.sol: function requireValidInitData parameter _initData isn't used. (requireValidInitData is external)
    VariableInterestRate.sol: function getNewRate parameter _initData isn't used. (getNewRate is external)

Check transfer receiver is not 0 to avoid burned money

Transferring tokens to the zero address is usually prohibited to accidentally avoid "burning" tokens by sending them to an unrecoverable zero address.

Code instances:

    https://github.com/code-423n4/2022-08-frax/tree/main/src/contracts/FraxlendPairCore.sol#L574
    https://github.com/code-423n4/2022-08-frax/tree/main/src/contracts/FraxlendPairCore.sol#L728
    https://github.com/code-423n4/2022-08-frax/tree/main/src/contracts/FraxlendPairCore.sol#L819
    https://github.com/code-423n4/2022-08-frax/tree/main/src/contracts/FraxlendPairCore.sol#L777
    https://github.com/code-423n4/2022-08-frax/tree/main/src/contracts/FraxlendPairCore.sol#L651

Missing commenting

    The following functions are missing commenting as describe below:

Code instances:

    FraxlendPairDeployer.sol, _deployFirst (private), parameters _saltSeed, _immutables, _penaltyRate not commented
    FraxlendPairDeployer.sol, deployCustom (external), parameter _penaltyRate not commented
    VariableInterestRate.sol, requireValidInitData (external), parameter _initData not commented

Add a timelock

To give more trust to users: functions that set key/critical variables should be put behind a timelock.

Code instances:

    https://github.com/code-423n4/2022-08-frax/tree/main/src/contracts/FraxlendPair.sol#L204
    https://github.com/code-423n4/2022-08-frax/tree/main/src/contracts/FraxlendPairDeployer.sol#L170
    https://github.com/code-423n4/2022-08-frax/tree/main/src/contracts/FraxlendWhitelist.sol#L65
    https://github.com/code-423n4/2022-08-frax/tree/main/src/contracts/FraxlendPair.sol#L288
@code423n4 code423n4 added bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels Aug 15, 2022
code423n4 added a commit that referenced this issue Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working edited-by-warden QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Projects
None yet
Development

No branches or pull requests

1 participant