prePO contest - Kiep's results

Gain exposure to pre-IPO companies & pre-token projects.

General Information

Platform: Code4rena

Start Date: 17/03/2022

Pot Size: $30,000 USDC

Total HM: 8

Participants: 43

Period: 3 days

Judge: gzeon

Total Solo HM: 5

Id: 100

League: ETH

prePO

Findings Distribution

Researcher Performance

Rank: 41/43

Findings: 1

Award: $32.46

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

32.4612 USDC - $32.46

Labels

bug
G (Gas Optimization)

External Links

  1. No need to initialize variables with default values

Source file : https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/AccountAccessController.sol

Finding : In this loops at line 44-47 value is set 0. If a variable is not set/initialized, it is assumed to have the default value (0, false, 0x0 etc depending on the data type). So we can save gas.

for (uint256 _i = 0; _i < _accounts.length; _i++) { _allowedAccounts[_allowedAccountsIndex][_accounts[_i]] = true; emit AccountAllowed(_accounts[_i]); }

Change to

for (uint256 _i; _i < _accounts.length; _i++) { _allowedAccounts[_allowedAccountsIndex][_accounts[_i]] = true; emit AccountAllowed(_accounts[_i]); }

Other line at 55-58.

  1. Better using ++i than i++ to save gas Source file : https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/AccountAccessController.sol

Finding : Using i++ in loop is more expensive than ++i. For example, using remix to declare variable i and using i++ we need 43446 and when we use ++i we need 43440. If we use this in loops, we will need more gas each loop. Change to this:

for (uint256 _i; _i < _accounts.length; ++_i) { _allowedAccounts[_allowedAccountsIndex][_accounts[_i]] = true; emit AccountAllowed(_accounts[_i]); }

Other line at 55-58

  1. Using ternary operator to save more gas and readability Source file : https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/CollateralDepositRecord.sol

Finding : If we want to save more line of code, readability and gas, we can use a ternary operator. In line 46-55 we have this 2 if-else conditional statement.

if (_globalDepositAmount > _amount) { _globalDepositAmount -= _amount; } else { _globalDepositAmount = 0; } if (_accountToNetDeposit[_sender] > _amount) { _accountToNetDeposit[_sender] -= _amount; } else { _accountToNetDeposit[_sender] = 0; }

///gas cost is 89098

Change to :

_globalDepositAmount = _globalDepositAmount > _amount ? _globalDepositAmount -= _amount : 0; _accountToNetDeposit[_sender] = _accountToNetDeposit[_sender] > _amount ? _accountToNetDeposit[_sender] -= _amount : 0;

/// gas cost is 70632

#0 - ramenforbreakfast

2022-03-24T03:31:13Z

  1. Duplicate of allowAccounts no need to set if already set #15
  2. Postfix/Prefix duplicate of #5
  3. Valid suggestion, we will consider this.
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