Skip to content

fix(toolkit): support user-owned Zswap inputs in custom contract builder - #2093

Open
alba-press wants to merge 1 commit into
midnightntwrk:mainfrom
alba-press:fix/toolkit-custom-contract-user-zswap-input
Open

alba-press wants to merge 1 commit into
midnightntwrk:mainfrom
alba-press:fix/toolkit-custom-contract-user-zswap-input

Conversation

@alba-press

Copy link
Copy Markdown

Fixes #2092

Summary

CustomContractBuilder previously interpreted unmatched
EncodedZswapLocalState.inputs as contract-owned and always
constructed them through Input::new_contract_owned.

That is incorrect when the referenced shielded coin belongs to
the funding wallet.

The builder now resolves an exact funding-wallet coin and uses
the existing canonical wallet spend path:

InputInfo<WalletSeed> -> WalletState::spend

which produces SenderEvidence::User.

True contract-owned inputs continue using the existing
Input::new_contract_owned path.

Why

The old path produces commitment/nullifier evidence for
SenderEvidence::Contract, which cannot authenticate a
user-owned shielded coin.

Safety

Selection is exact and does not choose another coin merely
because token type/value match.

Existing contract-owned semantics are preserved.

Tests

  • user-owned custom shielded input: PASS after fix
  • contract-owned input: PASS
  • wrong nullifier: REJECT
  • ambiguous token/value: does not select wrong coin
  • contract_custom::tests: 14/14 PASS across ledger 8 + 9
  • cargo test -p midnight-node-toolkit --lib:
    149 passed, 0 failed

Scope is one toolkit builder file only.

No runtime, BEEFY, bridge, or consensus changes.

Made with Cursor

@alba-press
alba-press requested a review from a team as a code owner September 4, 2026 01:00
@github-actions github-actions Bot added the bot:ai-assisted Authored or substantially edited by an AI agent label Sep 4, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 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-09-04T01:06:18.796978Z e8bd9e6 PR opened
ℹ️ 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.

…pend

CustomContractBuilder treated every EncodedZswapLocalState input as
contract-owned (Input::new_contract_owned / SenderEvidence::Contract).
When the funding wallet actually owns the coin, use exact nullifier
match and InputInfo → WalletState::spend (SenderEvidence::User).

Signed-off-by: alba-press <70040824+alba-press@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@alba-press
alba-press force-pushed the fix/toolkit-custom-contract-user-zswap-input branch from e8bd9e6 to 78827da Compare September 4, 2026 01:01

@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: e8bd9e607f

ℹ️ 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 +475 to +477
// EncodedZswapLocalState.inputs carries no ownership discriminator.
// Prefer the funding wallet's exact coin (nonce+color+value) and the
// canonical user spend path (WalletState::spend → SenderEvidence::User).

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 Add the required toolkit change file

This changes product-facing send-intent behavior in util/toolkit, but the commit adds no entry under changes/toolkit/added/ or changes/toolkit/changed/, so the fix will be omitted from the toolkit change record. Add a toolkit change file describing support for user-owned shielded inputs.

AGENTS.md reference: AGENTS.md:L195-L201

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:ai-assisted Authored or substantially edited by an AI agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

toolkit: CustomContractBuilder treats user-owned Zswap inputs as contract-owned

1 participant