IntersectMBO / IntersectMBO/evolution-sdk

improvement: scriptRef size double-counted when UTxO appears in both spent and reference inputs

Offen
#180 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
TypeScript
Sterne
22
Forks
30
Ø Merge
5 Std. 29 Min.
Gemergte PRs (30 T.)
12

Beschreibung

## Summary

`calculateReferenceScriptFee` receives `[...state.selectedUtxos, ...state.referenceInputs]`. If the same UTxO appears in both arrays (e.g. spent via `collectFrom` and also listed via `readFrom`), its `scriptRef` size is counted **twice**.

The Cardano node deduplicates using `Set.union` before scanning:

```haskell
-- eras/conway/impl/src/Cardano/Ledger/Conway/UTxO.hs
txNonDistinctRefScriptsSize utxo tx = ...
where
inputs = (tx ^. bodyTxL . referenceInputsTxBodyL)
`Set.union` (tx ^. bodyTxL . inputsTxBodyL) -- union deduplicates
```

## Impact

Only affects the edge case where the same UTxO is both spent and read. Over-charges the ref script fee for that UTxO. Safe (node accepts fees above minimum) but imprecise.

## Fix

Deduplicate by UTxO output reference before scanning:

```ts
const seen = new Set()
const deduped = [...state.selectedUtxos, ...state.referenceInputs].filter(utxo => {
const key = `${utxo.txHash}#${utxo.outputIndex}`
if (seen.has(key)) return false
seen.add(key)
return true
})
```

## Affected File

`packages/evolution/src/sdk/builders/phases/FeeCalculation.ts` — the call site that builds the utxo array passed to `calculateReferenceScriptFee`

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start in packages/evolution/src/sdk/builders/phases/FeeCalculation.ts at the call site that combines state.selectedUtxos and state.referenceInputs for calculateReferenceScriptFee. Verify how output references are represented, then ensure a UTxO present in both inputs is scanned once; done means the duplicate edge case no longer overcharges the reference script fee.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
blockchain
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
55/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.