Skip to content

Fix reference script fee calculation#376

Open
colll78 wants to merge 5 commits into
dcSpark:developfrom
Anastasia-Labs:develop
Open

Fix reference script fee calculation#376
colll78 wants to merge 5 commits into
dcSpark:developfrom
Anastasia-Labs:develop

Conversation

@colll78
Copy link
Copy Markdown
Contributor

@colll78 colll78 commented May 29, 2026

This PR updates min_fee_with_exunits to match Conway ledger reference-script fee accounting.

Previously, CML only counted reference-script bytes when a reference input’s script hash matched a spent script-address input. That missed cases where a transaction spends a regular input carrying a reference script, and it also did not match the ledger’s actual txNonDistinctRefScriptsSize behavior.

Changes:

Count reference scripts from regular inputs ∪ reference inputs.
De-duplicate by TransactionInput, so the same TxIn appearing in both sets counts once.
Count the same script multiple times when it appears on different UTxOs, matching ledger behavior.
Handle native reference scripts without panicking.
Change reference-script tier fee rounding from ceil to floor, matching Conway tierRefScriptFee.

Comment thread scripts/publish-helper.js
const oldPkg = require(`${pathToRepo}/publish/package.json`);

const packageNameRoot = hyphenRepoName.split("-wasm")[0];
oldPkg.name = '@dcspark/' + packageNameRoot + buildType;
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.

you'll need to revert this one

script_ref.hash(),
script_ref
.raw_plutus_bytes()
.expect("TODO: handle this")
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.

TODO?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TODO is what was already there prior to any of my changes.

None => builder.min_fee(include_exunits),
// generating the change output involves changing the fee
Some(_x) => return Ok(false),
Some(set_fee) => Ok(set_fee.clone()),
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.

I think this now contradicts the comment directly above it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment was already contradicted, generating the change output did not change the fee if there was a fee set.

Comment thread chain/wasm/src/lib.rs
pub type SubCoin = Rational;
#[derive(Clone, Debug)]
#[wasm_bindgen]
pub struct SubCoin(cml_chain::SubCoin);
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.

Is this needed for anything?

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.

3 participants