Rock Paper Scissors

First Flight #38
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: high
Invalid

[H-02] Stack Too Deep Vulnerability Report: Overly Large Game Struct in `RockPaperScissor` contract

Summary

The Game struct in the Rock Paper Scissors contract contains 16 storage variables, risking "Stack Too Deep" errors during compilation and inefficient gas usage. The EVM has a 16-slot stack limit, and large structs such as this causes the contract compilation failure.

Vulnerability Details

struct Game {
address playerA;
address playerB;
uint256 bet;
uint256 timeoutInterval;
uint256 revealDeadline;
uint256 creationTime;
uint256 joinDeadline;
uint256 totalTurns;
uint256 currentTurn;
bytes32 commitA;
bytes32 commitB;
Move moveA;
Move moveB;
uint8 scoreA;
uint8 scoreB;
GameState state;
}

Impact

  • Compilation Failures: Solidity throws Stack too deep errors when compiling the contract

    CompilerError: Stack too deep. Try compiling with `--via-ir` or removing local variables.
  • Increased gas costs for players

  • Storage inefficiencies

Tools Used

  • Remix IDE: Confirmed compilation error

Recommendations

  • Split the Struct

    struct GameConfig {
    address playerA;
    address playerB;
    uint256 bet;
    uint256 timeoutInterval;
    uint256 totalTurns;
    }
    struct GameState {
    uint256 currentTurn;
    bytes32 commitA;
    bytes32 commitB;
    Move moveA;
    Move moveB;
    uint8 scoreA;
    uint8 scoreB;
    GameState status;
    }
    struct GameTiming {
    uint256 revealDeadline;
    uint256 creationTime;
    uint256 joinDeadline;
    }
    mapping(uint256 => GameConfig) public gameConfigs;
    mapping(uint256 => GameState) public gameStates;
    mapping(uint256 => GameTiming) public gameTimings;

The oversized Game struct poses compilation risks and gas inefficiencies. Splitting the struct is the most robust solution, while --via-ir offers a temporary workaround. Recommended actions:

  • Short-term: Enable via_ir for deployment.

  • Long-term: Refactor into smaller structs (Solution 1).

Updates

Appeal created

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

Gas Optimization

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

Gas Optimization

Support

FAQs

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