Skip to content
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

Fix False Positive Alerts in Incorrect Bond Balance Monitor #7

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

narendravarma7
Copy link
Collaborator

Context & Root Cause

The existing Gatelang monitor for Dispute Game Incorrect Bond Balance was producing false positive alerts due to a race condition between the real-time Events data source and HistoricalEvents. This issue occurs when:

  1. The HistoricalEvents source retrieves past withdrawal events, but its indexing does not always include transactions from the most recent block.
  2. The current block's withdrawals are not accounted for in HistoricalEvents, causing a temporary imbalance in calculations.
  3. This results in the monitor detecting an ETH discrepancy and incorrectly triggering an alert.

Recommended Fix by Hexagate

Hexagate suggested excluding the current block's withdrawals from HistoricalEvents and tracking real-time withdrawals separately using the Events source. This prevents race conditions and ensures accurate ETH balance monitoring.

Implemented Fix

modified the monitor script with the following changes:

1. Separate Tracking for Current and Historical Withdrawals

  • Added currentWithdrawal source using Events to track real-time ETH withdrawals from the Dispute Game contract.
  • Updated pastWithdrawalEvents to exclude current block withdrawals by filtering based on BlockNumber {}.
  • Introduced currentWithdrawals to extract amounts from currentWithdrawal events and sum them correctly.

2. Ensured Correct Balance Calculation

  • The total ETH balance now includes both past and current withdrawals.
  • The final invariant condition verifies that the total balance is correct by ensuring:
    totalDisputeEthBalance - (futureEthUnlocked + Sum { sequence: unlockAmounts }) == 0
    

Testing & Validation

Next Steps

  • Deploy the updated monitor using Tines Automation and observe performance over multiple blocks.

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Jan 31, 2025

✅ Heimdall Review Status

Requirement Status More Info
Reviews 1/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

Copy link
Collaborator

@awilliams1-cb awilliams1-cb left a comment

Choose a reason for hiding this comment

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

  • Left a couple nits, overall the logic looks good
  • Looks like the current tests still work, but parsing the past and current withdrawals separately and adding them together is new logic that should have its own test
  • I checked the other two gate files that make use of HistoricalEvents and their invocations of it shouldn't encounter this issue

monitors/incorrect_bond_balance.gate Show resolved Hide resolved
monitors/incorrect_bond_balance.gate Outdated Show resolved Hide resolved
monitors/incorrect_bond_balance.gate Outdated Show resolved Hide resolved
monitors/incorrect_bond_balance.gate Show resolved Hide resolved
@cb-heimdall
Copy link
Collaborator

Review Error for awilliams1-cb @ 2025-01-31 19:39:16 UTC
User failed mfa authentication, public email is not set on your github profile. see go/mfa-help

narendravarma7 and others added 5 commits January 31, 2025 15:27
Co-authored-by: Alexis Williams <148368153+awilliams1-cb@users.noreply.github.com>
Co-authored-by: Alexis Williams <148368153+awilliams1-cb@users.noreply.github.com>
Co-authored-by: Alexis Williams <148368153+awilliams1-cb@users.noreply.github.com>
@awilliams1-cb awilliams1-cb self-requested a review February 1, 2025 19:16
@cb-heimdall
Copy link
Collaborator

Review Error for awilliams1-cb @ 2025-02-01 19:16:15 UTC
User cannot review their own commit

@tomryan-cb tomryan-cb self-requested a review February 3, 2025 16:39
Copy link
Collaborator

@tomryan-cb tomryan-cb left a comment

Choose a reason for hiding this comment

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

lgtm!

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.

4 participants