Connext Amarok contest - Waze'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: 36/72

Findings: 2

Award: $241.00

🌟 Selected for report: 0

🚀 Solo Findings: 0

#1 Unused variable Impact efficiency code and reduce gas cost

Proof of Concept https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L859

Tool Used Remix

Recommended Mitigation Steps remove unnecessary code. i suggest to change

(bool success, bytes memory returnData) = s.executor.execute

to

(bool success, ) = s.executor.execute

#2 Missing param define _transferId impact repayAavePortal function have natspec comment which is missing the newOwner function parameter. Issues with comments are low risk based on Code4rena risk categories.

Proof of Concept https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/PortalFacet.sol#L74-L79

Tool Manual Review

Recommended Mitigation Steps Add natspec comments include transferId parameter in repayAavePortal function.

#3 Router must be indexed

Impact event is missing indexed fields.

Proof of Concept https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/RoutersFacet.sol#L117

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/RoutersFacet.sol#L124

Tool Manual review

Recommendation Mitigation Steps Add indexed at router.

#4 canonicalId must be indexed

Impact event is missing indexed fields.

Proof of Concept https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/RoutersFacet.sol#L136

Tool Manual review

Recommendation Mitigation Steps Add indexed at canonicalId.

#5 Missing amount check

Impact Being instantiated with wrong configuration the contract will be inoperable. amount can't be 0.

Proof of Concept https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/RoutersFacet.sol#L490

Tool Manual review

Recommendation Mitigation Steps add

if (_amount == 0) revert()

to the function

#6 Typo Impact Misleading the user

Proof of Concept https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/RoutersFacet.sol#L575

Tool Manual Review

Recommended Mitigation Steps Fix it from specicfied to specified.

#7 inclusive condition Impact this functions will fail when the end-user expects it to pass through

Proof of Concept https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/RoutersFacet.sol#L592

Tool Manual Review

RecommendationMitigation Steps Conditions routerBalance should be inclusive >= or <= :

#8 Param wrapped must be immutable

Impact the state wrapped can't be initialize by constructor.

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/helpers/ConnextPriceOracle.sol#L49

Tool Used Manual Review

Recommended Mitigation Steps the state must add immutable because in the constructor parameter mention wrapped to initialize. so i suggest to add immutable on it.

#9 transferId must be indexed

Impact event is missing indexed fields.

Proof of Concept https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/promise/PromiseRouter.sol#L102

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/relayer-fee/RelayerFeeRouter.sol#L50

Tool Manual review

Recommendation Mitigation Steps Add indexed at transferId.

#0 - jakekidd

2022-07-02T00:36:16Z

1 invalid: Unused variable is being used in event emit below? 7 invalid: should NOT be inclusive comparison 8 invalid?: needs more explanation, I think? there may or may not be a wrapper contract on a given chain, and that may change, so it can't be immutable

3+4+9 should be 1 issue

#1 Use storage instead memory

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/AssetFacet.sol#L71

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L591

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L591

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/helpers/StableSwap.sol#L79

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/ConnextMessage.sol#L117

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/SwapUtils.sol#L202

Use storage instead of memory to reduce the gas fee. I suggest change

ConnextMessage.TokenId memory canonical = ConnextMessage.TokenId(

to

ConnextMessage.TokenId storage canonical = ConnextMessage.TokenId(

apply to others.

#2 Caching s.adoptedToCanonical

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/AssetFacet.sol#L146-L147

cache the s.adoptedToCanonical to the memory for reduce the gas fee because it use multiple times.

s.adoptedToCanonical[supported].domain = _canonical.domain; s.adoptedToCanonical[supported].id = _canonical.id;

#3 Sort the struct XCalledEventArgs

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L34-L38

sort the struct can reduce the gas fee, i suggest to change from

struct XCalledEventArgs { address transactingAssetId; uint256 amount; uint256 bridgedAmt; address bridged;

to

struct XCalledEventArgs { uint256 amount; uint256 bridgedAmt; address transactingAssetId; address bridged;

#4 Visibility

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L68

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibCrossDomainProperty.sol#L37

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/helpers/PriceOracle.sol#L6

change visibility from public to private can save gas. so i recommend to change it.

#5 Short the error message

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L113

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L121

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L123

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L150

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L161

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L224

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L226

reduce size of error message to bytes 32 can reduce the gas fee. reduce that if possible.

#6 Pre increment

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L134

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L153

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L147

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L162

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L613

using pre increment more cheaper gas than post increment. so, i sugget to change from

selectorPosition++;

to

++selectorPosition;

apply it to others.

#7 Default uint is 0

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L68

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/VersionFacet.sol#L16

the default value of uint is 0, so remove unnecassary explicit code.

#8 inequality

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L293

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L1095

non strict inequality are cheaper than strict one. i suggest to use >= or <= instead of > and < if possible.

#9 Use calldata

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L393

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/helpers/StableSwap.sol#L62

In the external functions where the function argument is read-only, the function() has an inputed parameter that using memory, if this function didnt change the parameter, its cheaper to use calldata then memory. so we suggest to change it.

#10 Cache _transferIds

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/RelayerFacet.sol#L137-L140

cache the _targetIds.length can reduce gas it caused access to a local variable is more cheap than query storage / calldata / memory in solidity and it use twice.

#11 Cache tokenAddresses

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/helpers/ConnextPriceOracle.sol#L176

caching the tokenAddresses.length can reduce gas it caused access to a local variable is more cheap than query storage / calldata / memory in solidity and it use twice.

#12 Cache pooled and decimal

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/StableSwapFacet.sol#L393

caching the pooled.length and decimal.length can reduce gas it caused access to a local variable is more cheap than query storage / calldata / memory in solidity and it use twice.

#13 Use !=0 instead >=0

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/helpers/ConnextPriceOracle.sol#L150

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L247

for unsigned integer, >0 is less efficient then !=0, so use !=0 instead of >0. apply to others.

#14 cache _pooledTokens

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/helpers/StableSwap.sol#L75-L77

caching _pooledTokens.length to memory because use multiple times can reduce the gas.

#15 Cache _a * AmplificationUtils.A_PRECISION;

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/helpers/StableSwap.sol#L110-L111

swapStorage.initialA = _a * AmplificationUtils.A_PRECISION; swapStorage.futureA = _a * AmplificationUtils.A_PRECISION;

cache the_a * AmplificationUtils.A_PRECISION; to memory because use multiple times can reduce the gas.

#16 Sort callparam struct

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibConnextStorage.sol#L38

#17 Sort executearg struct

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibConnextStorage.sol#L77

#18 Cache calldata.length

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L224-L226

caching _calldata.length to memory because use multiple times can reduce the gas.

#19 Caching _facetAddress

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/LibDiamond.sol#L191-L193

caching _facetAddress to memory can reduce the gas. Because use multiple times.

#20 Caching xp.length

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/SwapUtils.sol#L191

caching xp.length to memory because use multiple times can reduce the 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