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 #11

Closed
code423n4 opened this issue Oct 8, 2022 · 1 comment
Closed

QA Report #11

code423n4 opened this issue Oct 8, 2022 · 1 comment
Labels
bug Something isn't working invalid This doesn't seem right QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@code423n4
Copy link
Contributor

code423n4 commented Oct 8, 2022

Missing fee parameter validation

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

Code instances:

    Rebates.addToPool (_indexerFees)
    Staking._setDelegationParameters (_queryFeeCut)
    Cobbs.cobbDouglas (fees)
    Cobbs.cobbDouglas (totalFees)
    Staking.setDelegationParameters (_queryFeeCut)
    Rebates.redeem (_indexerFees)

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 BridgeEscrow.sol line 28: graphToken().approve(_spender, type(uint256).max);
    Deprecated safeApprove in GNS.sol line 173: graphToken().approve(address(curation()), MAX_UINT256);
    Deprecated safeApprove in AllocationExchange.sol line 77: graphToken.approve(address(staking), MAX_UINT256);

Require with empty message

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.

Code instances:

    Solidity file: GraphProxyAdmin.sol, In line 47 with Empty Require message.
    Solidity file: BancorFormula.sol, In line 416 with Empty Require message.
    Solidity file: BancorFormula.sol, In line 284 with Empty Require message.
    Solidity file: GraphProxyAdmin.sol, In line 59 with Empty Require message.
    Solidity file: BancorFormula.sol, In line 366 with Empty Require message.
    Solidity file: BancorFormula.sol, In line 327 with Empty Require message.
    Solidity file: GraphProxy.sol, In line 133 with Empty Require message.
    Solidity file: GraphProxyAdmin.sol, In line 34 with Empty Require message.
    Solidity file: BancorFormula.sol, In line 509 with Empty Require message.

Require with not comprehensive 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:

Code instances:

    Solidity file: Staking.sol, In line 1185 with Require message: <epochs
    Solidity file: Staking.sol, In line 428 with Require message: <cooldown
    Solidity file: GraphGovernance.sol, In line 72 with Require message: proposed

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:

    Controller.sol.updateController _controller
    DisputeManager.sol.createIndexingDispute _allocationID
    GraphToken.sol.mint _to
    Curation.sol.initialize _controller
    EthereumDIDRegistry.sol.revokeAttributeSigned identity
    GNS.sol.initialize _bondingCurve
    Staking.sol.setAssetHolder _assetHolder
    AllocationExchange.sol.withdraw _to

Solidity compiler versions mismatch

The project is compiled with different versions of solidity, which is not recommended because it can lead to undefined behaviors.

Use safe math for solidity version <8

You should use safe math for solidity version <8 since there is no default over/under flow check it suchversions of solidity.

Code instances:

    The contract WithdrawHelper.sol doesn't use safe math and is of solidity version < 8
    The contract GraphGovernanceStorage.sol doesn't use safe math and is of solidity version < 8
    The contract SubgraphNFT.sol doesn't use safe math and is of solidity version < 8
    The contract Managed.sol doesn't use safe math and is of solidity version < 8
    The contract AllocationExchange.sol doesn't use safe math and is of solidity version < 8

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:

    EthereumDIDRegistry.sol.changeOwner newOwner
    L2GraphToken.sol.initialize _owner
    EthereumDIDRegistry.sol.changeOwnerSigned newOwner
    GraphCurationToken.sol.initialize _owner

Init frontrun

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: code-423n4/2021-09-sushimiso-findings#64)
The vulnerable initialization functions in the codebase are:

Code instance:

    GraphCurationToken.sol, initialize, 26

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:

    LibFixedMath.sol, _mul
    LibFixedMath.sol, toInteger
    LibFixedMath.sol, exp
    Cobbs.sol, cobbDouglas
    LibFixedMath.sol, ln

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:

    GraphProxyStorage.sol
    GNS.sol
    GraphProxy.sol
    IGNS.sol
    IGraphProxy.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:

    L2GraphTokenGateway.sol, outboundTransfer is missing a reentrancy modifier

Assert instead require to validate user inputs

    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.

Code instances:

    GraphProxy.sol : reachable assert in line 46
    GraphProxy.sol : reachable assert in line 50
    GraphProxy.sol : reachable assert in line 47

In the following public update functions no value is returned

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: code-423n4/2021-10-badgerdao-findings#85).

Code instances:

    GNS.sol, updateSubgraphMetadata
    GraphGovernance.sol, updateProposal

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 instance:

    L2ArbitrumMessenger.sol: function sendTxToL1 parameter _l1CallValue isn't used. (sendTxToL1 is internal)

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-10-thegraph/tree/main/contracts/l2/gateway/L2GraphTokenGateway.sol#L244
    https://github.com/code-423n4/2022-10-thegraph/tree/main/contracts/gateway/L1GraphTokenGateway.sol#L276

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-10-thegraph/tree/main/contracts/governance/Controller.sol#L98
    https://github.com/code-423n4/2022-10-thegraph/tree/main/contracts/gateway/L1GraphTokenGateway.sol#L121
    https://github.com/code-423n4/2022-10-thegraph/tree/main/contracts/curation/Curation.sol#L124

Must approve 0 first

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.

Code instances:

approve without approving 0 first AllocationExchange.sol, 77,         graphToken.approve(address(staking), MAX_UINT256);
approve without approving 0 first GNS.sol, 173,         graphToken().approve(address(curation()), MAX_UINT256);
approve without approving 0 first BridgeEscrow.sol, 28,         graphToken().approve(_spender, type(uint256).max);

Div by 0

Division by 0 can lead to accidentally revert,
(An example of a similar issue - code-423n4/2021-10-defiprotocol-findings#84)

Code instances:

    https://github.com/code-423n4/2022-10-thegraph/tree/main/contracts/bancor/BancorFormula.sol#L295 _amount might be 0
    https://github.com/code-423n4/2022-10-thegraph/tree/main/contracts/bancor/BancorFormula.sol#L257 result might be 0

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:

AllocationExchange.sol, 77,         graphToken.approve(address(staking), MAX_UINT256);
BridgeEscrow.sol, 28,         graphToken().approve(_spender, type(uint256).max);
@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 Oct 8, 2022
code423n4 added a commit that referenced this issue Oct 8, 2022
code423n4 added a commit that referenced this issue Oct 8, 2022
@pcarranzav
Copy link

Some of the QA issues reported here may be valid as noted in other reports, but it's worth noting several of the reported issues are for files that are out of scope.

@JeeberC4 JeeberC4 added invalid This doesn't seem right unsatisfactory does not satisfy C4 submission criteria; not eligible for awards labels Oct 25, 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 invalid This doesn't seem right QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

3 participants