Omniscia Alliance Block Audit
RouterFacet Code Style Findings
RouterFacet Code Style Findings
RFT-01C: Inefficient Duplicate Read
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | RouterFacet.sol:L79, L81 |
Description:
The linked code utilizes the rs.bridgeAddressByChainId[targetChainId_]
value from storage twice redundantly.
Example:
contracts/facets/RouterFacet.sol
79require(rs.bridgeAddressByChainId[targetChainId_].length > 0, "Router: unknown destination");80ITeleport(rs.teleportAddress).transmit{value: msg.value}(81 targetChainId_, rs.bridgeAddressByChainId[targetChainId_], rs.dAppId,82 payload83 );
Recommendation:
We advise the mapping lookup to be performed once, cached to a local variable and consequently utilized in both instances.
Alleviation:
The code was updated according to our recommendation performing a single mapping lookup and making use of optimal local variables.
RFT-02C: Redundant Nested Structure
Type | Severity | Location |
---|---|---|
Code Style | ![]() | RouterFacet.sol:L52-L69 |
Description:
The linked nested if
structure is redundant and can be chained with the upper one.
Example:
contracts/facets/RouterFacet.sol
44if (nativeCollection.chainId == 0) {45 emit LockMint(targetChainId_, assets_[i].collection, assets_[i].tokenIds, receiver_);46
47 actions[i] = abi.encode(48 IRouter.TargetAction.Mint, _addressToBytes(assets_[i].collection),49 _lockMint(assets_[i].collection, assets_[i].tokenIds)50 );51}52else {53 if (nativeCollection.chainId == targetChainId_) {54 emit BurnUnlock(targetChainId_, assets_[i].collection, assets_[i].tokenIds, receiver_);55
56 actions[i] = abi.encode(57 IRouter.TargetAction.Unlock, nativeCollection.contractAddress,58 _burnUnlock(assets_[i].collection, assets_[i].tokenIds)59 );60 }61 else {62 emit BurnMint(targetChainId_, assets_[i].collection, assets_[i].tokenIds, receiver_);63
64 actions[i] = abi.encode(65 IRouter.TargetAction.Mint, nativeCollection.contractAddress,66 _burnMint(nativeCollection.chainId, assets_[i].collection, assets_[i].tokenIds)67 );68 }69}
Recommendation:
We advise this to be done so to increase the legibility of the codebase.
Alleviation:
The nested if
structure was properly expanded to the top level as an if-else
chain optimizing the function's gas cost.