FIAT DAO veFDT contest - medikko's results

Unlock liquidity for your DeFi fixed income assets.

General Information

Platform: Code4rena

Start Date: 12/08/2022

Pot Size: $35,000 USDC

Total HM: 10

Participants: 126

Period: 3 days

Judge: Justin Goro

Total Solo HM: 3

Id: 154

League: ETH

FIAT DAO

Findings Distribution

Researcher Performance

Rank: 87/126

Findings: 2

Award: $44.84

🌟 Selected for report: 0

🚀 Solo Findings: 0

Unspecific Compiler Version Pragma

While floating pragmas make sense for libraries to allow them to be included with multiple different versions of applications, it may be a security risk for application implementations.

There are 4 instances of this issue:

File: /contracts/VotingEscrow.sol
2:      pragma solidity ^0.8.3;
File:  /contracts/features/Blocklist.sol
2:      pragma solidity ^0.8.3;
File: ./contracts/mocks/MockERC20.sol

7:    pragma solidity ^0.8.0;
File: ./contracts/mocks/MockSmartWallet.sol

2:     pragma solidity ^0.8.3;

Intializing the variables to zero that aren't constant or immutable will cost more gas rather than use default value of zero.

If you not overwritte the default value you will save 8 gas for stack variables and more for storage and memory variables.

There are 10 instances of this issue:

File: ./contracts/VotingEscrow.sol

298: uint256 blockSlope = 0; // dblock/dt

309: for (uint256 i = 0; i < 255; i++) {

714: uint256 min = 0;

717: for (uint256 i = 0; i < 128; i++) {

737: uint256 min = 0;

739: for (uint256 i = 0; i < 128; i++) {

793: uint256 dBlock = 0;

794: uint256 dTime = 0;

834: for (uint256 i = 0; i < 255; i++) {

889: uint256 dTime = 0;

If you use ++i should be unchecked{++i} in for-loops

Not using a `unchecked{++i} will cost more gas because the default compiler overflow and underflow safety checks. This is true from version 0.8.0, code below match that requirments.

There are 4 instances of this issue:

File: ./contracts/VotingEscrow.sol

309: for (uint256 i = 0; i < 255; i++) {

717: for (uint256 i = 0; i < 128; i++) {

739: for (uint256 i = 0; i < 128; i++) {

834: for (uint256 i = 0; i < 255; i++) {

You can use ++i instead of i++ to save a gas (same for --i/i--)

This will save you 6 gas per instance/loop

There are 4 instances of this issue:

File: ./contracts/VotingEscrow.sol

309: for (uint256 i = 0; i < 255; i++) {

717: for (uint256 i = 0; i < 128; i++) {

739: for (uint256 i = 0; i < 128; i++) {

834: for (uint256 i = 0; i < 255; i++) {

x = x + y will be more cheap rather than x += y for state variables.

There are 1 instances of this issue:

File: ./contracts/VotingEscrow

654:    penaltyAccumulated += penaltyAmount;

Use uints/ints that aren't 256 bits may cost more gas because of EVM.

EVM operates on 256 bits at the time and to use small varibles than 256 bits, they will need to resize and that may cost more gas.

There are 2 instances of this issue:

File: ./contracts/VotingEscrow

567:    int128 value = locked_.amount;

836:    int128 dSlope = 0;

Use Shift Right/Left instead of Division/Multiplication if possible Using of bit shifting is more cheap rather than normal Multiplication/Division

Use bit shifting will be may harder to code read rather than normal multiplication/division but it will save some gas. In the EVM MUl/DIV cost 5 gas rather than SHL/SHR that costs 3 gas.

There are 2 instances of this issue:

File: ./contracts/VotingEscrow

719:    uint256 mid = (min + max + 1) / 2;

743:    uint256 mid = (min + max + 1) / 2;

Ordering righ struct will save a slot and instead use 4 you will use 3

Instead of this you can order struct diffrent to save a slot

There are 1 instances of this issue:

75:    struct LockedBalance {

76:        int128 amount;

77:        uint256 end;

78:        int128 delegated;

79:        address delegatee;

80:    }

Order like this will save one slot also and gas.

75:    struct LockedBalance {

76:        int128 amount;

77:        int128 delegated;

78:        uint256 end;

79:        address delegatee;

80:    }
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