F-2025-0017·gas-optimization
Redundant positionId in Position struct
TL;DR
Position struct stores positionId, duplicating the mapping key and incurring extra storage writes plus drift risk between key and field.
Severity
INFO
Impact
LOW
Likelihood
LOW
Method
MManual review
CAT.
Complexity
LOW
Exploitability
LOW
02Section · Description
Description
The Position struct includes a positionId field that duplicates the key used in the positions mapping:
solidity
struct Position {uint positionId; // Redundant with mapping keyaddress walletAddress;// ... other fields}mapping(uint => Position) public positions; // positionId is already the key
While this might seem convenient for frontend integration or event emission, it:
- Wastes gas by storing the same data twice.
- Requires maintaining consistency between mapping key and struct field.
- Increases contract deployment cost.
03Section · Recommendation
Recommendation
Remove the redundant positionId from the struct and use the mapping key when needed.

