Skip to content

Cross-assign signed context for intra clear3#457

Closed
Siddharth2207 wants to merge 1 commit into
masterfrom
fix-clear3-signed-context-cross-assign
Closed

Cross-assign signed context for intra clear3#457
Siddharth2207 wants to merge 1 commit into
masterfrom
fix-clear3-signed-context-cross-assign

Conversation

@Siddharth2207

@Siddharth2207 Siddharth2207 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes oracle clear3 reverts (panic 0x32) on RaindexV6 by cross-assigning signed context when building intra-orderbook calldata.
  • PR Add signedContext to clear3/4 #456 stopped passing empty [], [] but still wired each order's context into the same-named calldata slot; Raindex actually evaluates alice with bobSignedContext and bob with aliceSignedContext.
  • Adds getClearSignedContexts() and uses it for both V5 and V6 clear3 calldata builders.

Context

For a clear where the oracle order is bob (0x571b97e3…), oracle context must land in aliceSignedContext. With #456's direct assignment it ended up in bobSignedContext, so bob's eval saw an empty array and reverted on signed-context<0 0>().

Test plan

  • Unit test for getClearSignedContexts() cross-assignment
  • Updated getCalldataForV4Order test to expect swapped context args
  • CI test job

Summary by CodeRabbit

  • Bug Fixes
    • Improved consistency when building trade-related calldata so signed context data is passed in the correct order, with safer fallback handling when it’s unavailable.
  • Tests
    • Added coverage for signed-context ordering and updated existing expectations to match the new shared handling.

Raindex evaluates each order with the counterparty's signed context slot, so oracle context fetched onto an order struct must be swapped when building clear3 args.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a getClearSignedContexts() method to IntraOrderbookTradeSimulator that derives counterparty and own signed-context arrays with [] fallback. Both V6 and V5 clear3 calldata builders now use this method via spread. Tests updated/added to cover the new method and calldata expectations.

Changes

Signed context centralization

Layer / File(s) Summary
getClearSignedContexts helper and calldata wiring
src/core/modes/intra/simulation.ts
Adds a SignedContextV2 import and a new getClearSignedContexts() method returning a tuple of counterparty/own signed-context arrays (defaulting to []), and updates both Orderbook V6 and V5 clear3 calldata builders to use ...this.getClearSignedContexts() instead of directly referencing struct.signedContext.
Test coverage for signed context ordering
src/core/modes/intra/simulation.test.ts
Adds a test verifying getClearSignedContexts() returns counterparty context before own context, and updates the getCalldataForV4Order clear3 expectation to use the spread helper.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: hardyjosh

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: swapping signed context assignment for intra clear3.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-clear3-signed-context-cross-assign

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/core/modes/intra/simulation.test.ts (1)

637-694: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Add V6 calldata coverage for the swapped signed contexts. This file only covers getCalldataForV4Order; add the same clear3 signed-context expectation for getCalldataForV4OrderV6() (or a dedicated V6 case) so the Orderbook V6 path is covered too.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/modes/intra/simulation.test.ts` around lines 637 - 694, The current
test only validates the V4 calldata path in getCalldataForV4Order, so add
coverage for the V6 variant as well. Extend the simulation.test.ts suite with a
getCalldataForV4OrderV6 case (or equivalent) that asserts the clear3 call
includes the swapped signed contexts via getClearSignedContexts, using the same
style of encodeFunctionData expectations already present for the V4 test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/core/modes/intra/simulation.test.ts`:
- Around line 637-694: The current test only validates the V4 calldata path in
getCalldataForV4Order, so add coverage for the V6 variant as well. Extend the
simulation.test.ts suite with a getCalldataForV4OrderV6 case (or equivalent)
that asserts the clear3 call includes the swapped signed contexts via
getClearSignedContexts, using the same style of encodeFunctionData expectations
already present for the V4 test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 46b1c527-0c5b-41b2-b0f0-35d96dd1a922

📥 Commits

Reviewing files that changed from the base of the PR and between 62c725d and 1542d92.

📒 Files selected for processing (2)
  • src/core/modes/intra/simulation.test.ts
  • src/core/modes/intra/simulation.ts

@rouzwelt

rouzwelt commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

moved to #458

@rouzwelt rouzwelt closed this Jul 7, 2026
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