Count each reference script UTxO once toward the fee - #505
Open
theeldermillenial wants to merge 1 commit into
Open
theeldermillenial wants to merge 1 commit into
theeldermillenial wants to merge 1 commit into
Conversation
A reference script UTxO that several redeemers resolve their script from (for example a pool spend and a withdraw-zero validated by the same script) was appended to _reference_scripts once per use, so _ref_script_size() charged its size once per use. reference_inputs is a set, so the UTxO appears in the transaction once, and the ledger charges the scripts of a transaction's inputs and reference inputs once per UTxO. The inflated size overpaid the fee by the full tiered reference-script fee of every extra use, and also inflated max_tx_fee, which sizes the collateral. _add_reference_script(utxo) now records each UTxO's script once, keyed by its input, at all five sites (add_input, add_script_input, add_minting_script, add_withdrawal_script, add_certificate_script). The same script held by two different UTxOs still counts twice, as the ledger charges it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VAhmCntFmrPj5dnjaBBFeG
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #505 +/- ##
==========================================
+ Coverage 90.79% 90.80% +0.01%
==========================================
Files 37 37
Lines 5422 5429 +7
Branches 825 826 +1
==========================================
+ Hits 4923 4930 +7
Misses 309 309
Partials 190 190 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
TransactionBuildercounted a reference script once per redeemer that used it, not once per reference input. A transaction that spends a script UTxO and also withdraws through the same script, both resolved from one reference UTxO, got that script's size added to_ref_script_size()twice.reference_inputsis a set, so the UTxO appears in the transaction once, and the ledger charges each input's and reference input's script once. The builder overpaid the fee by the full tiered reference-script fee for every extra use, andmax_tx_fee(which sizes the collateral) was inflated the same way._add_reference_script(utxo)now records each UTxO's script once, keyed by its input, at every site that appends one:add_input,add_script_input,add_minting_script,add_withdrawal_scriptandadd_certificate_script. The same script held by two different UTxOs still counts twice, matching the ledger.Example
A mainnet transaction with a 9,851-byte Plutus V3 reference script shared by a spend and a withdrawal:
fee_buffer=100)Replaying the transaction through
TransactionBuilderbefore the fix reproduces its on-chain fee, collateral, change and script data hash exactly. After the fix, the fee is the ledger minimum plus the buffer.Tests
test_reference_script_shared_by_spend_and_withdrawal_counted_once: one reference UTxO used by a spend and a withdrawal counts once (failed before the fix: 38 vs 19)test_same_script_in_two_reference_utxos_counted_per_utxo: the same script in two reference UTxOs counts twicepytest test: 643 passed, 5 xfailed; flake8, mypy and black clean🤖 Generated with Claude Code
https://claude.ai/code/session_01VAhmCntFmrPj5dnjaBBFeG