Skip to content

feat: implement max invalid proof retries to prevent DoS attacks #1665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

crStiv
Copy link

@crStiv crStiv commented May 23, 2025

Purpose or design rationale of this PR

What does this PR do?
Implements a configurable limit for the number of invalid proof submissions per prover per task, addressing the TODO comment in proof_receiver.go.

Why does it do it?
Prevents DoS attacks where malicious provers could overwhelm the coordinator by repeatedly submitting invalid proofs, consuming computational resources and blocking legitimate provers.

How does it do it?

  • Adds MaxInvalidProofRetries configuration field to ProverManager
  • Introduces validation logic in validator() function that checks previous failed attempts using existing ORM methods
  • Creates new error type ProverTaskFailureTypeMaxRetriesExceeded for proper error handling
  • Adds Prometheus metric coordinator_validate_failure_max_retries_exceeded for monitoring
  • Maintains backward compatibility by defaulting to 0 (disabled)

Key changes:

  • coordinator/internal/config/config.go: New MaxInvalidProofRetries field
  • common/types/db.go: New failure type and string representation
  • coordinator/internal/logic/submitproof/proof_receiver.go: Validation logic and metrics
  • common/types/db_test.go: Test coverage for new failure type
  • coordinator/conf/config.json: Example configuration

The feature is production-ready with comprehensive error handling, logging, and monitoring capabilities.

PR title types

  • feat: A new feature

Deployment tag versioning

  • No, this PR doesn't involve a new deployment, git tag, docker image tag

Breaking change label

  • No, this PR is not a breaking change

Summary by CodeRabbit

  • New Features
    • Introduced a configurable limit for the number of invalid proof retries allowed per prover.
    • Added a new error message and user-facing feedback when the maximum retry limit is exceeded.
  • Bug Fixes
    • Improved validation to prevent repeated invalid proof submissions beyond the configured threshold.
  • Chores
    • Updated configuration files to include a new parameter for maximum invalid proof retries.
    • Enhanced monitoring with a new metric to track exceeded retry limits.
  • Tests
    • Expanded test coverage to verify new failure scenarios and string representations.

Copy link

coderabbitai bot commented May 23, 2025

Walkthrough

A new mechanism was added to limit the number of invalid proof retries a prover can make. This includes updates to enums, configuration files, and logic to enforce and track the retry limit. New tests and metrics were added to support and verify this functionality, along with corresponding configuration and error handling updates.

Changes

File(s) Change Summary
common/types/db.go Added ProverTaskFailureTypeMaxRetriesExceeded to the enum and updated its String() method to handle the new value.
common/types/db_test.go Added test cases for new and existing ProverTaskFailureType enum values, including the new max retries exceeded case.
coordinator/conf/config.json Introduced "max_invalid_proof_retries" parameter under "prover_manager" with a value of 3.
coordinator/internal/config/config.go Added MaxInvalidProofRetries uint8 field to the ProverManager struct.
coordinator/internal/logic/submitproof/proof_receiver.go Added error ErrValidatorFailureMaxRetriesExceeded, Prometheus counter, and logic in validator to enforce and track the invalid proof retry limit. Updated constructor for metric initialization.

Sequence Diagram(s)

sequenceDiagram
    participant Prover
    participant ProofReceiverLogic
    participant DB
    participant Metrics
    participant Config

    Prover->>ProofReceiverLogic: Submit Proof
    ProofReceiverLogic->>Config: Read MaxInvalidProofRetries
    alt MaxInvalidProofRetries > 0
        ProofReceiverLogic->>DB: Query failed prover tasks for proof hash
        DB-->>ProofReceiverLogic: Return failed tasks
        ProofReceiverLogic->>ProofReceiverLogic: Count invalid proof retries for prover
        alt Retries >= MaxInvalidProofRetries
            ProofReceiverLogic->>Metrics: Increment validateFailureMaxRetriesExceeded
            ProofReceiverLogic->>Prover: Return ErrValidatorFailureMaxRetriesExceeded
        else Retries < MaxInvalidProofRetries
            ProofReceiverLogic->>ProofReceiverLogic: Continue with normal validation
        end
    else MaxInvalidProofRetries == 0
        ProofReceiverLogic->>ProofReceiverLogic: Continue with normal validation
    end
Loading

Poem

In the warren, proofs hop by,
But too many wrong, and we must sigh.
A counter now keeps careful score,
Three tries, then you hop no more!
With metrics tallied, and configs set,
The burrow’s safe—no worries yet!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

level=warning msg="[runner] Can't run linter goanalysis_metalinter: buildir: failed to load package zstd: could not load export data: no export data for "github.com/scroll-tech/da-codec/encoding/zstd""
level=error msg="Running error: can't run linter goanalysis_metalinter\nbuildir: failed to load package zstd: could not load export data: no export data for "github.com/scroll-tech/da-codec/encoding/zstd""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47b1a03 and 4334993.

📒 Files selected for processing (5)
  • common/types/db.go (2 hunks)
  • common/types/db_test.go (1 hunks)
  • coordinator/conf/config.json (1 hunks)
  • coordinator/internal/config/config.go (1 hunks)
  • coordinator/internal/logic/submitproof/proof_receiver.go (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
common/types/db_test.go (1)
common/types/db.go (3)
  • ProverTaskFailureTypeObjectAlreadyVerified (113-113)
  • ProverTaskFailureTypeReassignedByAdmin (115-115)
  • ProverTaskFailureTypeMaxRetriesExceeded (117-117)
coordinator/internal/logic/submitproof/proof_receiver.go (2)
common/types/message/message.go (1)
  • ProofType (21-21)
common/types/db.go (3)
  • ProvingStatus (144-144)
  • ProverProofInvalid (82-82)
  • ProverTaskFailureTypeMaxRetriesExceeded (117-117)
🔇 Additional comments (10)
coordinator/conf/config.json (1)

6-6: Good configuration addition for DoS protection.

The max_invalid_proof_retries parameter is well-named and the default value of 3 provides a reasonable balance between allowing legitimate retry attempts while preventing abuse.

coordinator/internal/config/config.go (1)

21-23: Well-designed configuration field addition.

The MaxInvalidProofRetries field is properly implemented with:

  • Appropriate uint8 data type for retry counts
  • Clear documentation explaining DoS prevention purpose
  • Correct JSON tag matching the configuration file
common/types/db_test.go (1)

315-329: Comprehensive test coverage for new failure types.

The test cases properly validate the string representations of the new ProverTaskFailureType enum values, including the newly added ProverTaskFailureTypeMaxRetriesExceeded for the DoS protection feature. The test structure follows the existing pattern consistently.

common/types/db.go (2)

116-117: Well-defined failure type constant.

The ProverTaskFailureTypeMaxRetriesExceeded constant is properly documented and follows the existing naming convention for failure types.


136-137: Clear and descriptive string representation.

The string representation accurately describes the failure scenario and maintains consistency with the existing descriptive format used by other failure types.

coordinator/internal/logic/submitproof/proof_receiver.go (5)

42-43: LGTM!

The new error definition follows the established pattern and has a clear, descriptive message.


74-74: LGTM!

The new Prometheus counter field follows the established naming convention for validation failure metrics.


133-136: LGTM!

The Prometheus counter initialization follows the established pattern with a clear metric name and descriptive help text.


262-262: LGTM!

The comment update correctly indicates that the MaxInvalidProofRetries configuration has been implemented.


313-337: Solid implementation of the retry limit validation!

The logic correctly:

  • Only activates when configured (backward compatible)
  • Efficiently queries with a limit to avoid performance issues
  • Properly counts only invalid proofs from the specific prover
  • Handles errors appropriately with logging
  • Updates metrics for monitoring
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Thegaram
Copy link
Contributor

Hi @crStiv, thank you for submitting this PR. Is this a feature required for your use case? In which setting/project do you use the Scroll coordinator service?

@crStiv
Copy link
Author

crStiv commented May 23, 2025

Hi @crStiv, thank you for submitting this PR. Is this a feature required for your use case? In which setting/project do you use the Scroll coordinator service?

Hi @Thegaram, thanks for reviewing!

I noticed the TODO comment about preventing DoS attacks and thought this would be a useful security feature. I'm not running a production coordinator myself, but figured this could help protect against malicious provers spamming invalid proofs.

The implementation is backward compatible (disabled by default) so existing setups won't be affected.

Happy to adjust anything if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants