fix(lang): only capture a policy's ref where its script runs#333
Merged
Conversation
PR #332 captured a ref-backed policy's `ref` UTxO whenever the policy appeared in an address position, keyed on `is_address_expr()`. But that flag is also set for an output's `to`, so sending funds *to* a script address wrongly pulled the policy's reference script into the transaction — the script does not run when receiving, only when spending. Drive the capture solely off the explicit `capture_policy_ref` signal, set at the script-executing sites: an input's `from` and mint/burn amounts. Output `to` keeps its address lowering but no longer captures. Add a `send_to_policy` example tx that outputs to a ref-backed policy without spending from it, asserting it contributes no reference input. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
38a2eea to
d351217
Compare
This was referenced Jun 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #332.
Bug
#332 captured a ref-backed policy's
refUTxO whenever the policy appeared in an address position, gated onis_address_expr(). That flag is set for both an input'sfromand an output'sto. So:Sending funds to a script address does not run the script (it runs later, when those funds are spent), so no reference input should be attached. The over-capture bloats the tx and can make it unresolvable if that UTxO is gone.
Fix
Capture is now driven solely by the explicit
capture_policy_refsignal, set only at the sites where the policy's script actually executes in this tx:from→enter_address_expr().capturing_policy_refs()Symbol::PolicyDefno longer captures onis_address_expr(); theBuildScriptAddresslowering stays keyed on it. Outputtokeeps its address lowering but no longer captures.Net rule: capture iff the policy's script runs in this transaction — input
from,mint,burn.Test
New
send_to_policyexample tx outputs to a ref-backed policy without spending from it; assertsreferencesis empty. Existing ref-backedfrom/mint/burn checks still expect 1.cargo test -p tx3-lang: 167 passed, 0 failed — no snapshot regressions (no committed example used a ref-backed policy as an output recipient).🤖 Generated with Claude Code