Cudos contest - peritoflores's results

Decentralised cloud computing for Web3.

General Information

Platform: Code4rena

Start Date: 03/05/2022

Pot Size: $75,000 USDC

Total HM: 6

Participants: 55

Period: 7 days

Judge: Albert Chon

Total Solo HM: 2

Id: 116

League: COSMOS

Cudos

Findings Distribution

Researcher Performance

Rank: 51/55

Findings: 1

Award: $69.51

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

69.5108 USDC - $69.51

Labels

bug
G (Gas Optimization)

External Links

Gas Optimization for Cudos (May-05) by PeritoFlores

[G-01] Avoid initializing integers to 0

Initializing integers to zero consumes gas an is unnecessary. This is important as many of those function are called inside a loop .

https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L54

https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L54

https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L231

https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L233

https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L263

https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L453

https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L568

https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L579

[G-02] Optimize code at checkValidatorSignatures

In the function checkValidatorSignatures at some part of your code you can revert just inside the loop to avoid calculating twice cumulativePower > _powerThreshold

// Break early to avoid wasting gas if (cumulativePower > _powerThreshold) { break; } } } // Check that there was enough power require( cumulativePower > _powerThreshold, "Submitted validator set signatures do not have enough power." ); // Success }

Modify break for

revert("Submitted validator set signatures do not have enough power.")

[G-03] Remove Safe Math library and some usages

​

​ As you are using solidity >= 0.8 it is not necessary to use SafeMath so you can remove

Remove

import "@openzeppelin/contracts/math/SafeMath.sol";

using SafeMath for uint256;

Replace

[-] totalFee = totalFee.add(_fees[i]); #L455 [+] totalFee = totalFee + _fees[i];

The following line is repeated at #L349, 465, 585, 601, 621

[-] state_lastEventNonce = state_lastEventNonce.add(1); [+] state_lastEventNonce++;

#0 - V-Staykov

2022-05-10T12:30:18Z

[G-02] Is a good catch, but the solution is not right. When cumulativePower > _powerThreshold we expect the function to pass and not revert. The revert should only happen when the loop finishes and still the cumulitivePower has not reached the threshold.

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