The Game
contract in ./src/Game.sol
suffers from inefficient storage layout and over-allocated data types, both of which increase gas usage and waste precious storage slots on-chain. Specifically:
Data or Storage Packing must be optimal and take less storage space and less execution cost.
Variables such as currentKing
, gameEnded
, and _locked
are not packed optimally. Several variables like lastClaimTime
, gracePeriod
, and feeIncreasePercentage
use unnecessarily large types like uint256
, even though their actual range of values can easily be represented using smaller types like uint64
, uint32
, or uint8
. These inefficiencies not only increase deployment costs and runtime transaction gas, but also violate Solidity best practices for state variable layout and packing.
Solidity stores state variables in 32-byte storage slots and packs multiple smaller variables only if they are defined consecutively and fit within a single slot.
currentKing
(address, 20 bytes) is placed alone in slot 1.
gameEnded
and _locked
(bools, 1 byte each) are isolated in slots 6 and 16, wasting 62 bytes of storage.
Variable | Purpose | Current Type | Optimal Type | Notes |
---|---|---|---|---|
lastClaimTime |
Timestamp | uint256 |
uint64 |
Unix timestamps fit in 64 bits |
gracePeriod |
Time duration in seconds | uint256 |
uint32/64 |
Timeouts rarely exceed 2^32 |
initialGracePeriod |
Same | uint256 |
uint32/64 |
|
feeIncreasePercentage |
Percent value (0–100) | uint256 |
uint8 |
Max 100% |
platformFeePercentage |
Same | uint256 |
uint8 |
Likelihood: It's currently inevitable therefore, The likelihood is High.
Updating variables like gameEnded
, _locked
, or currentKing
individually results in separate slot writes, each costing up to 20,000 gas. When packed, these writes can share slots, reducing gas to ~5,000–8,000 or even less.
Impact: Low
High Gas Costs:
More storage slots touched → more SSTORE
ops → higher gas fees.
Wasted Storage Space:
Misaligned and over-allocated types lead to bloated memory footprint.
Reduced Scalability:
Larger contracts hit block gas limits sooner.
Bad Engineering Practice:
Makes audits harder and reflects lack of low-level optimization awareness.
Expected result:
GameOptimized
consumes 1,500–15,000 less gas per write, especially on warm slots or grouped writes.
Foundry Test Suite
Chat-GPT AI Assistance (Report Grammar Check & Improvements)
Foundry's Black box utility commands i.e., forge inspect
Manual Review
Use Proper Integer Sizes
Variable | Type |
---|---|
lastClaimTime |
uint64 |
gracePeriod |
uint64 |
initialGracePeriod |
uint64 |
feeIncreasePercentage |
uint8 |
platformFeePercentage |
uint8 |
Pack them together like so:
Pack booleans together or with small integers (e.g., uint8
).
forge inspect
to Check LayoutConfirm slot usage using:
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.