Swivel v3 contest - CRYP70's results

The Capital-Efficient Protocol For Fixed-Rate Lending.

General Information

Platform: Code4rena

Start Date: 12/07/2022

Pot Size: $35,000 USDC

Total HM: 13

Participants: 78

Period: 3 days

Judge: 0xean

Total Solo HM: 6

Id: 135

League: ETH

Swivel

Findings Distribution

Researcher Performance

Rank: 77/78

Findings: 1

Award: $25.71

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

25.7062 USDC - $25.71

Labels

bug
duplicate
G (Gas Optimization)
wontfix

External Links

Hello! CRYP70 here and I appreciate the opportunity to be apart of this competition. I believe I have found something which may save you some gas over large arrays. See the details of my findings.

++i generally costs less gas than i++ or i = i + 1 (about 5 units per increment) because i++ must increment a value and then "return" the old value which means the program may need to hold two numbers in memory. When ++i is used, it will only ever use one number in memory.

See the example below for an simplified illustration:

pragma solidity ^0.8.13; contract MyFavouriteCounter { uint public count; function incrementPrefixCount() public returns (uint) { count = 1; return (++count); // returns 2 } function incrementPostfixCount() public returns (uint) { count = 1; return (count++); // returns 1 } }

I was able to identify this in the following locations:

Swivel.sol:100:initiate() - unchecked {i++;} Swivel.sol:269:exit() - unchecked {i++;} Swivel.sol:418:cancel() - i++; Swivel.sol:564:approveUnderlying() - i++;

Remediation: Simply using ++i can save some gas.

Thanks again!

#0 - robrobbins

2022-08-31T20:11:38Z

yep, but there are literally dozens pointing out this same thing so...

el dupo

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