Skip to content

fix(op-stack): wait for the dispute game in getTimeToFinalize - #5298

Merged
jxom merged 3 commits into
mainfrom
claude/op-stack-finalize-waits-for-game
Oct 26, 2026
Merged

jxom merged 3 commits into
mainfrom
claude/op-stack-finalize-waits-for-game

Conversation

@jxom

@jxom jxom commented Oct 26, 2026

Copy link
Copy Markdown
Member

Supersedes #5295. It keeps @Anirudh-712's commit as is and adds one follow-up commit.

getTimeToFinalize (and so waitToFinalize) only counted proofMaturityDelaySeconds from the proof timestamp. The portal also needs the proof's dispute game to be resolved and past disputeGameFinalityDelaySeconds. On Base the maturity is 1 day, but a type 621 game resolves 5 days after it is created. So waitToFinalize returned days early, and finalizeWithdrawal reverted with OptimismPortal_InvalidRootClaim.

Change (from #5295)

  • Read the game's resolvedAt(). While it is 0, estimate the resolution from expectedResolution() or createdAt() + maxClockDuration(). Add the portal's disputeGameFinalityDelaySeconds(), and return whichever is later: that time or the end of the proof maturity delay.
  • Added the game getters to disputeGameAbi, a docs line, a patch changeset, and a Base fork test.

Follow-up commit

  • While the game is unresolved, the estimated resolution is at least now. An overdue game (estimate passed, but nobody has called resolve() yet, or a challenge extended the clock) now waits at least the finality delay instead of returning seconds: 0.
  • Updated the period TSDoc (proof maturity delay). Reworded the getter comments. The docs now say the resolution time is an estimate while the game is unresolved.

Verified

Read on-chain at L1 block 26271000:

  • Base portal v6.0.1: maturity 86400, finality delay 0.
  • Game 0xE32c…D148: createdAt 1792832195, expectedResolution 1793264195, resolvedAt 0. That matches the test snapshot seconds: 317170.

OP Mainnet portal 5.8.0 (latest block): maturity 604800, finality delay 302400, and type-9 games have maxClockDuration 302400. So OP results don't change.

tsc -p src and biome check pass. I didn't run the op-stack fork tests (no anvil available, and src/op-stack/** isn't in the core project).

Needs reviewer attention

On Base the finality delay is 0, so an overdue game still gets only the 10 s buffer. Fully fixing that would need waitToFinalize to poll resolvedAt, which I left out of scope.


Generated by Claude Code

Cryppit and others added 2 commits October 26, 2026 05:08
getTimeToFinalize (and waitToFinalize) only counted the proof maturity delay. The portal also needs the proof's dispute game to be resolved and past its finality delay, which on Base (1-day maturity, 5-day games) comes days later. Read the game's resolution (or its expected resolution while unresolved) and the finality delay, and return the later of the two.
@changeset-bot

changeset-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 333367c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
viem Ready Ready Preview Oct 26, 2026 5:22am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T05:18:36.113459Z 333367c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/viem@5298

commit: 2f4fb1f

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f4fb1fccc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +221 to +223
// Without an estimate, only the proof maturity delay applies.
if (estimate === undefined) return 0
return Math.max(Number(estimate), now)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Recheck unresolved games instead of timing an estimate

When a fault game is challenged or has not been explicitly resolved by the estimated timestamp, maxClockDuration/expectedResolution is not the actual resolvedAt. This path nevertheless starts the finality delay from that estimate (or from now), while waitToFinalize calls this action only once and then sleeps, so it can return while the game is still in progress or before the full delay following a later resolution. The OP Stack specification requires the delay to run from the game's actual resolution; unresolved cases therefore need to be rechecked rather than treated as resolved at an estimate.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The path is real. On Base the finality delay is 0, so once an unresolved game passes its estimate, waitToFinalize waits only the 10 s buffer and returns. For a delay above 0, the follow-up commit already makes an unresolved game wait at least the full delay. Fully fixing it means waitToFinalize re-checks until seconds is 0. That needs getTimeToFinalize to return 0 only once the game is resolved, which the current clamp already guarantees. The catch is the existing waitToFinalize fork tests: they freeze Date with vi.setSystemTime, so a re-check loop would never end there, and they would need reworking. I'm leaving this open for a maintainer to decide whether it belongs in this PR or a follow-up.


Generated by Claude Code

test('default', async () => {
// Base: the proof maturity delay is 1 day, but the proof's dispute game
// (proven 2026-10-24) only resolves 5 days after it was created.
vi.setSystemTime(new Date(1792947035000))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Replace vi usage in the new test

The newly added scenario uses vi.setSystemTime and vi.useRealTimers, but the repository explicitly prohibits vi in tests and requires exercising real behavior against the configured chain or an ephemeral server. Rewrite this coverage without fake system time so it follows the required test strategy.

AGENTS.md reference: AGENTS.md:L153-L157

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This matches the existing tests in this file and in waitToFinalize.test.ts, which all use vi.setSystemTime. getTimeToFinalize reads Date.now(), so a snapshot at a pinned fork block only stays deterministic with a fixed clock. Without it, this case returns seconds: 10 once real time passes the game's expectedResolution (2026-10-29). Dropping vi would need a clock input on the action, which is an API change, so I'm leaving it as is for now and the maintainers can decide.


Generated by Claude Code

@jxom
jxom merged commit a69e96c into main Oct 26, 2026
7 of 8 checks passed
@jxom
jxom deleted the claude/op-stack-finalize-waits-for-game branch October 26, 2026 05:16
@github-actions github-actions Bot mentioned this pull request Oct 26, 2026

This branch was successfully deployed

1 active deployment
Preview — 333367ce Deployed Oct 26, 2026 by vercel[bot]
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