Skip to content

optimize some bls operations#731

Merged
cmmarslender merged 1 commit intomainfrom
bls-ops
Mar 6, 2026
Merged

optimize some bls operations#731
cmmarslender merged 1 commit intomainfrom
bls-ops

Conversation

@arvidn
Copy link
Contributor

@arvidn arvidn commented Mar 4, 2026

Note

Medium Risk
Touches consensus-critical BLS op argument validation and introduces new allocator-side caching that could affect error behavior and memory usage if not cleared on all exit paths.

Overview
Optimizes strict BLS negation ops by caching successful G1Element::from_bytes/G2Element::from_bytes validations in Allocator (keyed by raw point bytes) and reusing that cache in op_bls_g1_negate_strict and op_bls_g2_negate_strict.

Adds Allocator::validate_g1, validate_g2, and clear_validation_caches, and clears these caches after run_program finishes to avoid carrying validation state across program executions.

Written by Cursor Bugbot for commit bb93035. This will update automatically on new commits. Configure here.

@coveralls-official
Copy link

coveralls-official bot commented Mar 4, 2026

Pull Request Test Coverage Report for Build 22763067844

Details

  • 34 of 36 (94.44%) changed or added relevant lines in 3 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.05%) to 88.215%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/allocator.rs 20 22 90.91%
Files with Coverage Reduction New Missed Lines %
src/allocator.rs 3 96.7%
Totals Coverage Status
Change from base Build 22681542686: -0.05%
Covered Lines: 6984
Relevant Lines: 7917

💛 - Coveralls

@arvidn arvidn force-pushed the bls-ops branch 2 times, most recently from 43f6d00 to b598207 Compare March 4, 2026 22:30
@arvidn arvidn requested a review from richardkiss March 6, 2026 08:40
richardkiss added a commit that referenced this pull request Mar 6, 2026
Add process-global validation cache for G1/G2 point validation in
strict negate operations. This approach has several advantages over
deferred validation:

- No changes to Allocator (no new fields, no checkpoint interaction)
- No changes to run_program (no deferred validation at end-of-run)
- Fails fast: invalid point returns immediate error
- Cache persists across transactions and blocks
- Thread-safe using RwLock with read-path for cached lookups
- Exploits BLS12-381 property: negation flips bit 5, so -p has same
  validity as p, allowing us to cache both with one validation

The cache is explicitly temporary until HF3 fixes the cost model.

Alternative to #731 for mitigating g1/g2_negate_strict DoS attack.

Made-with: Cursor
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@arvidn arvidn enabled auto-merge March 6, 2026 10:16
@arvidn arvidn closed this Mar 6, 2026
auto-merge was automatically disabled March 6, 2026 12:16

Pull request was closed

@arvidn arvidn reopened this Mar 6, 2026
@arvidn arvidn enabled auto-merge March 6, 2026 12:16
@cmmarslender cmmarslender disabled auto-merge March 6, 2026 15:26
@cmmarslender cmmarslender merged commit ff3efc2 into main Mar 6, 2026
51 checks passed
@cmmarslender cmmarslender deleted the bls-ops branch March 6, 2026 15:26
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.

3 participants