Connext Amarok contest - 0xNazgul's results

The interoperability protocol of L2 Ethereum.

General Information

Platform: Code4rena

Start Date: 08/06/2022

Pot Size: $115,000 USDC

Total HM: 26

Participants: 72

Period: 11 days

Judge: leastwood

Total Solo HM: 14

Id: 132

League: ETH

Connext

Findings Distribution

Researcher Performance

Rank: 43/72

Findings: 2

Award: $226.92

🌟 Selected for report: 0

🚀 Solo Findings: 0

Missing Equivalence Checks in Setters

Severity: Low Context: PortalFacet.sol#L57-L69, ConnextPriceOracle.sol#L142-L180

Description: Setter functions are missing checks to validate if the new value being set is the same as the current value already set in the contract. Such checks will showcase mismatches between on-chain and off-chain states.

Recommendation: Add in the additional checks to validate if the new value being set is the same as the current value already set in the contract.

Missing Time locks

Severity: Low Context: PortalFacet.sol#L57-L69

Description: None of the onlyOwner functions that change critical protocol addresses/parameters appear to have a timelock for a time-delayed change to alert: (1) users and give them a chance to engage/exit protocol if they are not agreeable to the changes (2) team in case of compromised owner(s) and given them a chance to perform incident response.

Recommendation: Add a timelock to these functions for a time-delayed change to alert users and protect against possible malicious changes by compromised owners(s).

Lack of Event Emission For Critical Functions

Severity: Low Context: PortalFacet.sol#L57-L69

Description: Several functions update critical parameters that are missing event emission. These should be performed to ensure tracking of changes of such critical parameters.

Recommendation: Add events to functions that change critical parameters.

Unneeded Use of SafeMath.sol

Severity Informational Context: ConnextPriceoracle.sol, AmplificationUtils.sol, SwapUtils.sol

Description: Since Solidity 0.8, the overflow/underflow check is implemented on the language level - it adds the validation to the bytecode during compilation.

You don't need the SafeMath library for Solidity 0.8+. It will just perform the same validation twice (one on the language level and one in the library).

Recommendation: Remove the use of SafeMath library.

Unindexed Event Parameters

Severity Informational Context: AssetFacet.sol#L22-L62, BridgeFacet.sol#L179-L195, RoutersFacet.sol#L98-L124, ConnextPriceOracle.sol#L65-L69, SponsorVault.sol#L70-L113

Description: Parameters of certain events are expected to be indexed so that they’re included in the block’s bloom filter for faster access. Failure to do so might confuse off-chain tooling looking for such indexed events.

Recommendation: Add the indexed keyword to event parameters that should include it.

TODOs && FIXMEs Left In The Code

Severity: Informational Context: BridgeFacet.sol#L492, BridgeFacet.sol#L579, BridgeFacet.sol#L594, BridgeFacet.sol#L1027, Executor.sol#L7, LibConnextStorage.sol#L303

Description: There should never be any TODOs in the code when deploying.

Recommendation: Finish the TODOs before deploying.

Spelling Errors

Severity: Informational Context: BridgeFacet.sol#L86 (crosschain => cross chain), BridgeFacet.sol#L105 (crosschain => cross chain), BridgeFacet.sol#L125 (crosschain => cross chain), BridgeFacet.sol#L134 (crosschain => cross chain), BridgeFacet.sol#L148 (crosschain => cross chain), BridgeFacet.sol#L265 (bridgable => bridgeable), BridgeFacet.sol#L450-L451 (asseted => asset?), BridgeFacet.sol#L774 (addressess => addresses), BridgeFacet.sol#L1059 (a sthe => as the), ProposedOwnableFacet.sol#L143 (sournce => source), ProposedOwnableFacet.sol#L163 (sournce => source), ProposedOwnableFacet.sol#L176 (sournce => source), RelayerFacet.sol#L35 (rlayer => relayer), RoutersFacet.sol#L290 (crosschain => cross chain), RoutersFacet.sol#L575 (specicfied => specified), Executor.sol#L17 (callabale => callable), LPToken.sol#L41 (everytime => every time), ProposedOwnableUpgradeable.sol#L170 (sournce => source), ProposedOwnableUpgradeable.sol#L198 (sournce => source), ProposedOwnableUpgradeable.sol#L212 (sournce => source), PromiseRouter.sol#L50 (incomming => incoming), PromiseRouter.sol#L266 (crosschain=> cross chain), PromiseRouter.sol#L278 (crosschain=> cross chain), LibConnextStorage.sol#L23 (crosschain=> cross chain), LibConnextStorage.sol#L26 (crosschain=> cross chain), LibConnextStorage.sol#L278 (briding => bribing), LibCrossDomainProperty.sol#L35 (identifer => identifier)

Description: Spelling errors in comments can cause confusion to both users and developers.

Recommendation: Check all misspellings to ensure they are corrected.

Too Recent of a Pragma

Severity Informational Context: All Contracts

Description: Using too recent of a pragma is risky since they are not battle tested. A rise of a bug that wasn't known on release would cause either a hack or a need to secure funds and redeploy.

Recommendation: Use a Pragma version that has been used for sometime. I would suggest 0.8.4 for the decrease of risk and still has the gas optimizations implemented.

Awards

84.6501 USDC - $84.65

Labels

bug
duplicate
G (Gas Optimization)

External Links

Use ++index instead of index++ to increment a loop counter

Context: DiamondLoupeFacet.sol#L27-L36, StableSwapFacet.sol#L393-L454, ConnextPriceOracle.sol#L175-L180, StableSwap.sol#L61-L93, LibDiamond.sol#L95-L118, LibDiamond.sol#L120-L136, LibDiamond.sol#L138-L155, LibDiamond.sol#L157-L167, SwapUtils.sol#L173-L221, SwapUtils.sol#L241-L276 (For both), SwapUtils.sol#L286-L321 (For all three), SwapUtils.sol#L336-L348, SwapUtils.sol#L388-L433 (For both), SwapUtils.sol#L549-L562, SwapUtils.sol#L581-L606, SwapUtils.sol#L817-L898 (For both), SwapUtils.sol#L909-L935, SwapUtils.sol#L986-L1046 (For all three), SwapUtils.sol#L1053-L1062,

Description: Due to reduced stack operations, using ++index saves 5 gas per iteration.

Recommendation: Use ++index to increment a loop counter.

Catching The Array Length Prior To Loop

Context: RelayerFacet.sol#L130-L152, StableSwapFacet.sol#L393-L454, ConnextPriceOracle.sol#L175-L180, StableSwap.sol#L61-L93, LibDiamond.sol#L95-L118, LibDiamond.sol#L120-L136, LibDiamond.sol#L138-L155, LibDiamond.sol#L157-L167, SwapUtils.sol#L173-L221, SwapUtils.sol#L549-L562, SwapUtils.sol#L581-L606, SwapUtils.sol#L817-L898 (For both), SwapUtils.sol#L909-L935, SwapUtils.sol#L986-L1046 (For all three), SwapUtils.sol#L1053-L1062

Description: One can save gas by caching the array length (in stack) and using that set variable in the loop. Replace state variable reads and writes within loops with local variable reads and writes. This is done by assigning state variable values to new local variables, reading and/or writing the local variables in a loop, then after the loop assigning any changed local variables to their equivalent state variables.

Recommendation: Simply do something like so before the for loop: uint length = variable.length. Then add length in place of variable.length in the for loop.

The Increment In For Loop Post Condition Can Be Made Unchecked

Context: DiamondLoupeFacet.sol#L27-L36, StableSwapFacet.sol#L393-L454, ConnextPriceOracle.sol#L175-L180, StableSwap.sol#L61-L93, LibDiamond.sol#L95-L118, LibDiamond.sol#L120-L136, LibDiamond.sol#L138-L155, LibDiamond.sol#L157-L167, SwapUtils.sol#L173-L221, SwapUtils.sol#L241-L276 (For both), SwapUtils.sol#L286-L321 (For all three), SwapUtils.sol#L336-L348, SwapUtils.sol#L388-L433 (For both), SwapUtils.sol#L549-L562, SwapUtils.sol#L581-L606, SwapUtils.sol#L817-L898 (For both), SwapUtils.sol#L909-L935, SwapUtils.sol#L986-L1046 (For all three), SwapUtils.sol#L1053-L1062

Description: (This is only relevant if you are using the default solidity checked arithmetic). i++ involves checked arithmetic, which is not required. This is because the value of i is always strictly less than length <= 2**256 - 1. Therefore, the theoretical maximum value of i to enter the for-loop body is 2**256 - 2. This means that the i++ in the for loop can never overflow. Regardless, the overflow checks are performed by the compiler.

Unfortunately, the Solidity optimizer is not smart enough to detect this and remove the checks. One can manually do this by:

for (uint i = 0; i < length; i = unchecked_inc(i)) {
    // do something that doesn't change the value of i
}

function unchecked_inc(uint i) returns (uint) {
    unchecked {
        return i + 1;
    }
}

Note that it’s important that the call to unchecked_inc is inlined. This is only possible for solidity versions starting from 0.8.2.

Recommendation: The increment in the for loop post condition can be made unchecked.

In require(), Use != 0 Instead of > 0 With Uint Values

Context: ConnextPriceOracle.sol#L142-L156, AmplificationUtils.sol#79-L103 (For L86), LibDiamond.sol#120-L136 (For L121), LibDiamond.sol#138-L155 (For L139), LibDiamond.sol#157-L167 (For L158), LibDiamond.sol#222-L240 (For L226), LibDiamond.sol#L242-L248 (For L247)

Description: In a require, when checking a uint, using != 0 instead of > 0 saves 6 gas. This will jump over or avoid an extra ISZERO opcode.

Recommendation: Use != 0 instead of > 0 with uint values but only in require() statements.

Setting The Constructor To Payable

Context: All Contracts

Description: You can cut out 10 opcodes in the creation-time EVM bytecode if you declare a constructor payable. Making the constructor payable eliminates the need for an initial check of msg.value == 0 and saves 21 gas on deployment with no security risks.

Recommendation: Set the constructor to payable.

Function Ordering via Method ID

Context: All Contracts

Description: Contracts most called functions could simply save gas by function ordering via Method ID. Calling a function at runtime will be cheaper if the function is positioned earlier in the order (has a relatively lower Method ID) because 22 gas are added to the cost of a function for every position that came before it. The caller can save on gas if you prioritize most called functions. One could use This tool to help find alternative function names with lower Method IDs while keeping the original name intact.

Recommendation: Find a lower method ID name for the most called functions for example mostCalled() vs. mostCalled_41q() is cheaper by 44 gas.

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter