Skip to content

calculateMinimumUtxoLovelace underestimates min ADA for scriptRef outputs #167

@SynthLuvr

Description

@SynthLuvr

When building an output that includes a scriptRef, the SDK helper calculateMinimumUtxoLovelace can return a value that is too low for minimum UTxO requirements. This causes transactions to be rejected due to insufficient lovelace on the output.

Expected Behavior

calculateMinimumUtxoLovelace should return a minimum lovelace amount that satisfies the min-UTxO rule for the produced output, including:

  • the 160-byte UTxO entry overhead, and
  • correct CBOR sizing behavior for the lovelace field.

Actual Behavior

calculateMinimumUtxoLovelace appears to omit the 160-byte UTxO entry overhead, and the computed CBOR size can vary depending on whether the output’s lovelace is encoded as 0 (1-byte CBOR) versus a typical final amount (≥ 65,536 → 5-byte CBOR). This can lead to under-calculation of the required lovelace.

Reproduction (High-level)

  1. Construct a transaction output that includes a scriptRef.
  2. Use calculateMinimumUtxoLovelace to determine the lovelace amount.
  3. Submit the transaction.
  4. Observe rejection due to insufficient lovelace in the output.

Workaround

Compute the output CBOR size via the SDK helper using coinsPerUtxoByte: 1n to obtain a raw byte count, then apply the missing overhead and actual coinsPerUtxoByte:

  • Fetch coinsPerUtxoByte from protocol parameters
  • Use a 1 ADA placeholder (instead of zero) to ensure the lovelace field uses the same 5-byte CBOR encoding as the final value
  • Compute: minLovelace = (cborSize + 160) * coinsPerUtxoByte

Link to workaround: MynthAI/mint-chocolate-chip#32

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions