SKALE contest - kenta's results

The only Ethereum native multichain scaling network.

General Information

Platform: Code4rena

Start Date: 18/02/2022

Pot Size: $125,000 USDC

Total HM: 13

Participants: 24

Period: 14 days

Judge: GalloDaSballo

Total Solo HM: 6

Id: 88

League: ETH

SKALE

Findings Distribution

Researcher Performance

Rank: 18/24

Findings: 2

Award: $530.38

🌟 Selected for report: 0

πŸš€ Solo Findings: 0

Findings Information

🌟 Selected for report: defsec

Also found by: 0x1f8b, 0xwags, cmichel, csanuragjain, gzeon, jayjonah8, kenta, kirk-baird, kyliek, leastwood, rfa, robee, ye0lde

Labels

bug
QA (Quality Assurance)

Awards

351.8878 USDC - $351.89

External Links

#0 - DimaStebaev

2022-03-14T15:29:01Z

Agreed.

#1 - GalloDaSballo

2022-05-05T14:44:57Z

Finding is valid and non-critical

Findings Information

🌟 Selected for report: IllIllI

Also found by: 0x1f8b, CertoraInc, TerrierLover, Tomio, WatchPug, d4rk, gzeon, kenta, kyliek, m_smirnova2020, rfa, robee, saian, ye0lde

Labels

bug
G (Gas Optimization)

Awards

178.4876 USDC - $178.49

External Links

skalenetwork/ima-c4-audit gas optimization

1 use cache for storage in registerExtraContractForAll and removeExtraContractForAll.

https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/MessageProxy.sol#L174-L175 https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/MessageProxy.sol#L188-L189

EnumerableSetUpgradeable.AddressSet storage registryContracts = _getRegistryContracts()[bytes32(0)]; require(!registryContracts.contains(extraContract), "Extra contract is already registered"); registryContracts.add(extraContract);

EnumerableSetUpgradeable.AddressSet storage registryContracts = _getRegistryContracts()[bytes32(0)]; require(registryContracts.contains(extraContract), "Extra contract is not registered"); registryContracts.remove(extraContract);

2 use unchecked. from < to is already checked so you can use unchecked for the following line to save gas.

https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/MessageProxy.sol#L220

Unchecked { contractsInRange = new address[](to -from); }

3 use cache for storage in postOutgoingMessage.

https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/MessageProxy.sol#L291-L302

ConnectedChainInfo storage _connectedChain = connectedChains[targetChainHash]; require(_connectedChain.inited, "Destination chain is not initialized"); _authorizeOutgoingMessageSender(targetChainHash);

emit OutgoingMessage( targetChainHash, _connectedChain.outgoingMessageCounter, msg.sender, targetContract, data ); _connectedChain.outgoingMessageCounter += 1;

4 use cache for storage in _registerExtraContract and _removeExtraContract

https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/MessageProxy.sol#L365-L371 https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/MessageProxy.sol#L389-L390

5 Input must be checked earlier to save gas. The following line can be checked at the beginning of the function to save gas.

https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/schain/TokenManager.sol#L192

6 Use initial value for uint256 and ++i in loop in TokenManagerLinker.sol

https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/schain/TokenManagerLinker.sol#L122 https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/schain/TokenManagerLinker.sol#L151 https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/schain/TokenManagerLinker.sol#L166 https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/schain/TokenManagerLinker.sol#L178 https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/schain/TokenManagerLinker.sol#L192

7 use unchecked. balance < MINIMUM_BALANCE is already checked in if sentence, so you can use unchecked.

https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/schain/MessageProxyForSchain.sol#L404

uint missingAmount; unchecked { missingAmount = MINIMUM_BALANCE - balance; }

8 No need to use cache. _outgoingMessageDataHash[message.dstChainHash][message.msgCounter] Is used only one time in function so you don’t use cache

https://github.com/skalenetwork/ima-c4-audit/blob/main/contracts/schain/MessageProxyForSchain.sol#L253

if (_outgoingMessageDataHash[message.dstChainHash][message.msgCounter] == _hashOfMessage(message)) isValidMessage = true;

#0 - yavrsky

2022-03-14T18:22:15Z

Only marginal gas improvements.

#1 - GalloDaSballo

2022-04-28T17:32:24Z

1 use cache for storage in registerExtraContractForAll and removeExtraContractForAll.

Not convinced this will save gas as you're still dealing with storage pointers

2 use unchecked.

Saves 20g

3 use cache for storage in postOutgoingMessage.

Same as 1, caching a storage pointer won't save gas

4 use cache for storage in _registerExtraContract and _removeExtraContract

Same as 1

5 Input must be checked earlier to save gas.

Don't think it makes much difference

6 Use initial value for uint256 and ++i in loop in TokenManagerLinker.sol

3 * 5 * 2 = 30

7 use unchecked. balance < MINIMUM_BALANCE is already checked in if sentence, so you can use unchecked.

This would save 20 gas

8 No need to use cache. _outgoingMessageDataHash[message.dstChainHash][message.msgCounter]

Would save 6 gas

Total Gas Saved 76

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