Introduction to Debug Arena
Relevant source files
The following files were used as context for generating this wiki page:
Debug Arena is a secure, real-time competitive debugging platform designed for live coding events and hackathons. Built using Flask and Python, the system challenges participants to solve progressive levels of logical and syntactical bugs within a strictly controlled environment. The platform integrates automated code evaluation, a persistent anti-cheat system, and dynamic scoring to facilitate fair competition.
Sources: README.md:1-10
System Architecture
The Debug Arena follows a multi-layered architecture where the frontend serves an interactive IDE (CodeMirror), and the backend handles secure code execution and state management.
Architectural Overview
The system is divided into several core modules:
- Authentication Layer: Manages team registration and session-based access.
- Proctoring System: A JavaScript-based security layer that monitors user behavior.
- Evaluation Engine: Executes Python code in a subprocess with strict safety constraints.
- Scoring & Persistence: Tracks team progress, time taken, and penalties using SQLAlchemy.
The following diagram illustrates the high-level data flow from the client to the evaluation engine:
Sources: README.md:57-75
Core Components
1. Level Management and Content
Levels are defined in a centralized manager that specifies the title, buggy source code, expected output, and difficulty. Each level includes a specific hint that, when accessed, applies a pre-defined point penalty.
| Feature | Description |
|---|---|
| Buggy Code | Initial code snippet containing errors for the user to fix. |
| Expected Output | The exact string output the corrected code must produce. |
| Penalty | Points deducted from the base score if a hint is revealed. |
| Difficulty | Classification ranging from "Easy" to "Hard". |
Sources: levels/level_manager.py:3-108, routes/arena_routes.py:35-42
2. Evaluation and Security Engine
The platform uses a subprocess to execute user-submitted code safely. Before execution, a security utility scans the code for forbidden keywords such as import os, eval(, or .system( to prevent shell injection or unauthorized system access.
3. Proctoring and Anti-Cheat System
The proctor.js module enforces event integrity by monitoring fullscreen status and tab visibility. The system allows a maximum of 3 violations before a team is automatically disqualified.
- Fullscreen Enforcement: Users must play in fullscreen mode; exiting triggers a violation.
- Tab Switching: Detecting
visibilitychange(switching tabs) logs a violation to the database. - Persistent Tracking: Violations are stored in the
Teammodel, preventing bypass via page refreshes.
Sources: static/js/proctor.js:1-75, routes/arena_routes.py:108-128
Scoring Logic
The scoring system calculates points based on completion speed and usage of the "Oracle" hint system.
- Base Score: 100 points per level.
- Time Penalty: 1 point is deducted for every 10 seconds elapsed (
time_taken // 10). - Hint Penalty: If a hint is used, the level's specific penalty value is subtracted.
- Hard Minimum: Regardless of penalties, the minimum score for a successful level completion is 30 points.
Sources: routes/submit_routes.py:44-60
Data Model
The application uses SQLAlchemy to manage team states and submission history.
Sources: models/team.py:5-25, app.py:50-55
Conclusion
Debug Arena provides a robust infrastructure for competitive programming by combining secure code execution with active proctoring. By centralizing level logic in the level_manager and enforcing security through both static analysis and runtime constraints, the platform ensures a fair and challenging environment for participants to demonstrate their Python debugging proficiency.