Cally contest - 0xkatana's results

Earn yield on your NFTs or tokens via covered call vaults.

General Information

Platform: Code4rena

Start Date: 10/05/2022

Pot Size: $50,000 USDC

Total HM: 13

Participants: 100

Period: 5 days

Judge: HardlyDifficult

Total Solo HM: 1

Id: 122

League: ETH

Cally

Findings Distribution

Researcher Performance

Rank: 84/100

Findings: 1

Award: $30.12

🌟 Selected for report: 0

🚀 Solo Findings: 0

[G-01] Redundant zero initialization

Solidity does not recognize null as a value, so uint variables are initialized to zero. Setting a uint variable to zero is redundant and can waste gas.

There was one place where an int is initialized to zero https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Cally.sol#L94 https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Cally.sol#L95 https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Cally.sol#L282 https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/CallyNft.sol#L244

Remove the redundant zero initialization uint256 i; instead of uint256 i = 0;

[G-02] Short require strings save gas

Strings in solidity are handled in 32 byte chunks. A require string longer than 32 bytes uses more gas. Shortening these strings will save gas.

One instance was found https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/CallyNft.sol#L89

Shorten all require strings to less than 32 characters

[G-03] Use prefix not postfix in loops

Using a prefix increment (++i) instead of a postfix increment (i++) saves gas for each loop cycle and so can have a big gas impact when the loop executes on a large number of elements.

There is one example of this in for loops https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Cally.sol#L244

Use prefix not postfix to increment in a loop

[G-04] Use != 0 instead of > 0

Using > 0 uses slightly more gas than using != 0. Use != 0 when comparing uint variables to zero, which cannot hold values below zero

Locations where this was found include https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Cally.sol#L170 https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Cally.sol#L283

Replace > 0 with != 0 to save gas

[G-05] Add payable to functions that won't receive ETH

Identifying a function as payable saves gas. Functions that have the onlyOwner modifier cannot be called by normal users and will not mistakenly receive ETH. These functions can be payable to save gas. This is especially relevant because withdrawAll functions exist to withdraw any ETH accidentally sent.

There are many functions that have the onlyOwner modifier in the contracts. Some examples are https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Cally.sol#L119 https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Cally.sol#L124

Add payable to these functions for gas savings

[G-06] Cache array length before loop

Caching the array length outside a loop saves reading it on each iteration, as long as the array's length is not changed during the loop. This saves gas.

This was found in one place https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Cally.sol#L244

Cache the array length before the for loop

[G-07] Use existing cached vault value

getPremium caches the value of _vaults[vaultId] and then returns the value premiumOptions[vault.premiumIndex]. But everywhere that getPremium is used, the _vaults[vaultId] value is already cached, so using the value premiumOptions[vault.premiumIndex] directly saves gas by removing a function call.

There are two places where this improvement can be made https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Cally.sol#L223 https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Cally.sol#L464

Replace getPremium calls with the value premiumOptions[vault.premiumIndex]

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