Skip to content

feat(simulator): pass scoped-transaction options to live calls - #195

Merged
0xisk merged 4 commits into
mainfrom
feat/simulator-live-enc-key-mappings
Sep 25, 2026
Merged

0xisk merged 4 commits into
mainfrom
feat/simulator-live-enc-key-mappings

Conversation

@0xisk

@0xisk 0xisk commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

A live circuit could not send a shielded coin to a wallet other than the caller. midnight-js encrypts that output to the recipient's encryption key, knows only the caller's, and throws Unable to resolve encryption public key.

withContractScopedTransaction is the midnight-js entry point that takes the key mappings. With scopedTransactionOptions set, each call runs through the handle's own callTx in a scope holding just that call, so the .private.result that LiveBackend reads is unchanged. Without the option, handles are untouched.

Inside a scope, midnight-js wraps circuit and submission errors (Unexpected error executing scoped transaction ...). The original message stays inside, so substring matches still hold.

The end-to-end check is a compact-contracts live spec where one pool wallet pays another, which lands there once this is released.

PR Checklist

  • I have read the Contributing Guide
  • I have added tests that prove my fix is effective or that my feature works
  • I have added documentation of new methods and any new behavior or changes to existing behavior
  • CI Workflows Are Passing

Further comments

Rebuilding callTx on createCallTxOptions + submitCallTx avoids the error wrapping, but copies midnight-js's callTx body and needs an option type carved out of CallOptionsBase.

midnight-js encrypts each shielded coin a circuit creates to its
recipient's encryption key and only knows the calling wallet's, so a
live circuit that sent a coin to another wallet's coin public key
failed to build. The deployed handle's callTx leaves the
additionalCoinEncPublicKeyMappings slot empty, so with the option set
each call is rebuilt on createCallTxOptions + submitCallTx, the pair
callTx itself runs.
@0xisk
0xisk requested review from a team as code owners September 25, 2026 02:28
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 6c0fb8da-b59b-43d1-bfa2-29fa9754c773

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 68b88130-616e-4376-9280-45bc44836110

📥 Commits

Reviewing files that changed from the base of the PR and between d98fc26 and 486cfbf.

📒 Files selected for processing (4)
  • packages/simulator/CHANGELOG.md
  • packages/simulator/README.md
  • packages/simulator/src/live/createLiveContext.ts
  • packages/simulator/test/unit/createLiveContext.test.ts

Included review availability: 4 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.


Walkthrough

The live context accepts optional coin-to-encryption-public-key mappings. When mappings are supplied, circuit calls use them to create and submit transactions. The README and changelog describe the option and its use for shielded recipients.

Changes

Live coin encryption key mappings

Layer / File(s) Summary
Mapping options and contracts loading
packages/simulator/src/live/createLiveContext.ts
CreateLiveContextOptions adds optional encryption-key mappings. The loader caches the dynamically imported contracts module and uses it to find deployed handles and create and submit calls.
Mapped circuit calls
packages/simulator/src/live/createLiveContext.ts, packages/simulator/test/unit/createLiveContext.test.ts, packages/simulator/README.md, packages/simulator/CHANGELOG.md
When mappings are supplied, the live context rebuilds deployed handle call methods to use them. Tests cover mapped and unmapped calls. The README and changelog describe the option and document the build failure when a recipient mapping is missing.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature · Severity of issue fixed: Low

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant LiveContext
  participant ContractsModule
  participant AliasProviders
  Caller->>LiveContext: Resolve handle with encryption mappings
  LiveContext->>ContractsModule: Find deployed handle
  LiveContext-->>Caller: Return handle with rebuilt call methods
  Caller->>LiveContext: Invoke circuit call
  LiveContext->>ContractsModule: Create call options with mappings and arguments
  LiveContext->>AliasProviders: Submit call transaction
  AliasProviders-->>Caller: Return finalized call result
Loading

Suggested reviewers: andrew-fleming

Merge Risk: ⚪ Minimal · up to 486cf

The mapped-call path has no established merge-blocking issue; normal checks can proceed.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title is misleading. The change adds additionalCoinEncPublicKeyMappings for shielded recipients and does not pass scoped-transaction options or use withContractScopedTransaction. Rename the pull request to describe the main change, such as feat(simulator): support encryption key mappings for live calls.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (2 skipped: 2 …
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

A rabbit maps the keys with care,
A coin can reach a wallet there.
The circuit calls, the options flow,
The tests confirm the paths they know.
Then hops away through moonlit snow.

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

The lazy module and the mappings option take their types from
midnight-js-contracts instead of local copies. The imports are
type-only, so the dependency wall is unchanged.
Each call runs through the handle's own callTx inside
withContractScopedTransaction, the midnight-js entry point that takes
these options, instead of a callTx rebuilt from createCallTxOptions and
submitCallTx. New scope options pass through without a simulator change.
@0xisk 0xisk changed the title feat(simulator): add live encryption-key mappings feat(simulator): pass scoped-transaction options to live calls Sep 25, 2026
@0xisk
0xisk added this pull request to stack #197 September 25, 2026 07:15

@pepebndc pepebndc 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.

LGTM

@0xisk
0xisk merged commit dd6e0b6 into main Sep 25, 2026
11 checks passed
@0xisk
0xisk deleted the feat/simulator-live-enc-key-mappings branch September 25, 2026 07:53
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