DatingDapp

First Flight #33
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

[G-1] Missing constant/immutable variable declarations leads to unnecessary storage reads (Incorrect Variable Type + Gas Loss)

Description: Several state variables in the codebase are not marked as constant or immutable despite being set only once. Using these modifiers can save gas as:

  • constant variables are replaced by their value at compile time

  • immutable variables are read from code instead of storage

The following instances were found:

  1. In MultiSigWallet.sol:

// Should be immutable as they're only set in constructor
address public owner1;
address public owner2;
  1. In LikeRegistry.sol:

// Should be constant as it's a fixed value
uint256 immutable FIXEDFEE = 10;
// Should be immutable as it's only set in constructor
SoulboundProfileNFT public profileNFT;

Impact:

  • Each storage read costs 2100 gas (cold access) or 100 gas (warm access)

  • Using constant or immutable can save significant gas:

    • constant: No storage reads, value is embedded in bytecode

    • immutable: Single PUSH32 operation (3 gas) instead of SLOAD (100+ gas)

Proof of Concept:

Deploy the following contract in Remix to see the gas difference:

contract GasTest {
address public regularAddress = address(1); // 2593
address public immutable immutableAddress = address(1); // 439
address public constant CONSTANT_ADDRESS = address(1); // 417
function testRegularRead() public view returns (address) {
return regularAddress; // More expensive 2515
}
function testImmutableRead() public view returns (address) {
return immutableAddress; // Cheaper 402
}
function testConstantRead() public pure returns (address) {
return CONSTANT_ADDRESS; // Cheapest 358
}
}

Recommended Mitigation:

  1. For MultiSigWallet.sol:

- address public owner1;
- address public owner2;
+ address public immutable owner1;
+ address public immutable owner2;
  1. For LikeRegistry.sol:

- uint256 immutable FIXEDFEE = 10;
+ uint256 public constant FIXED_FEE = 10;
- SoulboundProfileNFT public profileNFT;
+ SoulboundProfileNFT public immutable profileNFT;
Updates

Appeal created

n0kto Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.