Fix atomic proof finalization - #85
Open
Devadakene wants to merge 9 commits into
Open
Conversation
cybermax4200
requested changes
Aug 22, 2026
cybermax4200
left a comment
Contributor
There was a problem hiding this comment.
The ci checks are failing please fix them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #52
Description
Fixes a critical race condition where a single proof could be finalized multiple times by independent actors (auto-verification worker, admin review, and quorum validators), which resulted in duplicated
RewardPayoutrows, double notifications, and leaked task completion slots.To address this, the finalization logic has been extracted into a single shared service (
src/services/proofFinalizationService.ts). We replaced the vulnerableupdateManyapproach with an atomicSELECT ... FOR UPDATEquery at the start of the finalization transaction, which serializes concurrent requests. Additionally, state-based access control was implemented (viaexpectedStatuses) to strictly enforce which statuses can be finalized by which actors, preventing admins from finalizing proofs that are currently being processed by the verification worker.Fixes #52
Type of Change
How Has This Been Tested?
npm testpassesnpm run buildsucceedsA new concurrency integration test
tests/integration/proofFinalization.test.tswas added to fire all three actors simultaneously. It asserts that only one actor succeeds while producing exactly oneVerificationrow, oneRewardPayoutrow, and incrementing the task's completion count by exactly 1.Checklist
Additional Context
reviewProof,verificationWorker, andresolveQuorumnow share the identical finalization code path instead of relying on their own separate DB interactions.