fix: division by zero in leaderboard calculation#29
fix: division by zero in leaderboard calculation#29mohansinghi wants to merge 1 commit intoPlatformNetwork:mainfrom
Conversation
📝 WalkthroughWalkthroughUpdated Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Add defensive check for empty scores vector before division to prevent potential panic. While evaluations.is_empty() is checked above, this adds an extra layer of safety in case the mapping produces an empty vector. Fixes division by zero bug in update_leaderboard function.
a3bfd39 to
e165d4c
Compare
|
@echobt Could you please review my pr? |
* feat(challenges): add term-challenge WASM evaluation crate Add a new WASM challenge crate that implements terminal benchmark evaluation as a no_std-compatible WASM module using the platform-challenge-sdk-wasm. The term-challenge crate provides: - Task definitions: 10 built-in terminal tasks (file creation, process listing, nginx setup, firewall rules, etc.) spanning Easy/Medium/Hard difficulty levels, with a seeded selection function for deterministic task sampling. - Evaluation logic: deserializes task definitions and agent submissions from bincode-encoded EvaluationInput, validates task IDs against expected set, scores results, and persists metrics via host storage. - Scoring algorithm: computes pass rate from individual task results, maps to a 0-10000 score range, tracks execution time and per-task pass/fail counts in EvalMetrics. - Challenge-specific types: TaskDefinition, TaskResult, Submission, EvalParams, EvalMetrics, and Difficulty enum, all serde-serializable. - TermChallenge struct implementing the Challenge trait with evaluate() and validate() methods, registered via register_challenge! macro. Also extends the SDK register_challenge! macro to accept an optional custom const initializer expression, needed when Default::default() is not const-evaluable (e.g. for unit struct constructors). Updated workspace Cargo.toml to include the new crate and added the term-challenge entry to challenges/README.md. * fix: add missing metrics field to EvaluationOutput initializer
Summary
Division by Zero in Leaderboard Calculation
Severity: Medium
File:
crates/platform-server/src/db/queries.rs:341Effort: Small (4 lines)
Current - can panic if scores vector is empty:
Impact: When scores vector is empty, division by zero causes panic and crashes the leaderboard update endpoint.
Fix: Add defensive check before division:
Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=158349177
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.