Eggstravaganza

First Flight #37
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

String Return Type Increases Gas Consumption

Description: The EggHuntGame::getGameStatus function returns a human-readable string, which is not gas-efficient. Using strings in smart contracts, especially as return types, can significantly increase gas costs and should be avoided unless absolutely necessary.

Recommended Mitigation: Return a uint8 or a custom enum instead of a string, which can then be interpreted off-chain.

+ enum GameState { NotStarted, Active, Elapsed, Inactive }
function getGameStatus() external view returns (GameState) {
if (gameActive) {
if (block.timestamp < startTime) {
- return "Game not started yet";
+ return GameState.NotStarted;
} else if (block.timestamp >= startTime && block.timestamp <= endTime) {
- return GameState.Active;
+ return true;
} else {
- return "Game time elapsed";
+ return GameState.Elapsed;
}
} else {
- return "Game is not active";
+ return GameState.Inactive;
}
}
Updates

Lead Judging Commences

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

Gas optimization

Strategy to save gas and minimize transaction costs

Support

FAQs

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