Skip to content

Fix TOCTOU race condition for duplicate attestations#10210

Merged
lucassaldanha merged 4 commits into
Consensys:masterfrom
lucassaldanha:toctou-fix
Dec 9, 2025
Merged

Fix TOCTOU race condition for duplicate attestations#10210
lucassaldanha merged 4 commits into
Consensys:masterfrom
lucassaldanha:toctou-fix

Conversation

@lucassaldanha

@lucassaldanha lucassaldanha commented Dec 9, 2025

Copy link
Copy Markdown
Member

PR Description

When validating attestations, the node should not propagate an attestation that was previously seen. In our current implementation, the check if the attestation was seen and the resulting validation was not done atomically, which could lead to a race condition where we check two similar attestations but don't consider them seen.

This fix relies on our synchronised seenPayloadAttestations set add() function to perform a second check if the attestation has been seen.

Fixed Issue(s)

N/A

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if updates are required.

Changelog

  • I thought about adding a changelog entry, and added one if I deemed necessary.

Note

Makes duplicate payload attestation detection atomic in the gossip validator and adds tests to cover the race scenario.

  • Validation (PayloadAttestationMessageGossipValidator):
    • Atomically handle duplicates by checking seenPayloadAttestations.add(key) post-validation; return ignore(...) if already present.
    • Replace pre-check return with ignoreAttestationAlreadySeenValidationResult(...) helper and reuse it after add(...).
    • Add private helper ignoreAttestationAlreadySeenValidationResult(...) to centralize logging and ignore result.
  • Tests:
    • Add shouldIgnore_whenAlreadySeen_AfterInitialCheck to simulate concurrent validations and verify ignore-on-second.
    • Tighten existing tests to verify no further validations on duplicates and behavior when validation fails then succeeds.

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

Comment thread CHANGELOG.md Outdated
### Bug Fixes
- Fixed a storage issue which sometimes caused Teku to crash during shut down.
- Fixed `peer_count` metric when using `--metrics-publish-endpoint` feature.
- Fixed attestation validation checks to avoid broadcasting attestations already seen.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can remove this, the fix is gloas only and for payload attestations (PTC) not attestations.

@rolfyone rolfyone left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM just remove changelog imo.

@lucassaldanha lucassaldanha enabled auto-merge (squash) December 9, 2025 04:18
@lucassaldanha lucassaldanha merged commit ef4306f into Consensys:master Dec 9, 2025
50 of 53 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 9, 2025
@lucassaldanha lucassaldanha deleted the toctou-fix branch December 9, 2025 05:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants