Inefficient Storage Reads Causes Expensive Deployment Gas Costs
In the Game
contract’s constructor, after validating and storing the incoming parameters (_initialClaimFee
, _gracePeriod
, etc.), the code re-reads those newly-written storage variables (initialClaimFee
and initialGracePeriod
) in order to initialize claimFee
and gracePeriod
.
Because storage reads are expensive (2100 gas cold, 100 gas warm) compared to using the constructor’s memory parameters directly, this pattern unnecessarily increases deployment gas. By reading from initialClaimFee
and initialGracePeriod
(storage), instead of using _initialClaimFee
and _gracePeriod
(stack/memory), each deployment pays extra gas for two storage loads.
Likelihood: High but once
Location: Game.sol
-> constructor
Issue: After writing initialClaimFee
and initialGracePeriod
to storage, the constructor immediately reads them back in order to set claimFee
and gracePeriod
.
Gas Costs:
SSTORE writing initialClaimFee
and initialGracePeriod
: unavoidable.
SLOAD reading them back: avoidable by using the original parameters.
Impact: Low
Higher Deployment Fees: Every contract deployment pays extra gas for redundant storage loads.
Cumulative Cost: In large systems with many deployments (e.g., factory patterns, upgradable proxies), these inefficiencies compound.
Bad Practice Propagation: Encourages a pattern of reading back from storage when original data is still available in memory.
Gas Griefing Potential: Though not directly exploitable for theft, high base gas costs can deter legitimate use or be weaponized in DOS campaigns (e.g., forcing expensive redeployments in automated scripts).
Tools Used:
Foundry Test Suite
Chat-GPT AI Assistance (Report Grammar Check & Improvements)
Manual Review
Step 1: Add the following test to test/Game.t.sol
:
Step 2: Paste the above code snippet ⬆️
Step 3: Run the test suite with the following command:
Step 4: Observe the output gas report, which will show the difference in gas usage before and after the optimization.
Scenario
Baseline: Deploy Game
with the current constructor.
Optimized: Modify the constructor to assign directly from parameters:
Use Constructor Parameters Directly
Replace:
With:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.