IntersectMBO / IntersectMBO/evolution-sdk

improvement: tx size includes IsValid field, Haskell omits it

Open
#179 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
22
Forks
30
Avg merge
5h 29m
Merged PRs (30d)
12

Description

## Summary

`calculateFeeIteratively` serializes the transaction using a 4-element CBOR array (body, witnessSet, isValid, auxiliaryData). The Cardano node computes the fee-relevant size using `toCBORForSizeComputation`, which omits `IsValid` and produces a **3-element array**.

This results in a tx size ~1 byte larger than the node calculates, causing a fee over-estimate of ~44 lovelace (1 byte × minFeeCoefficient).

## Haskell Reference

```haskell
-- eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs
toCBORForSizeComputation AlonzoTx {atBody, atWits, atAuxData} =
encodeListLen 3 -- 3 elements, no IsValid
<> encCBOR atBody
<> encCBOR atWits
<> encodeNullStrictMaybe encCBOR atAuxData
```

## Our Code

```ts
// TxBuilderImpl.ts — calculateFeeIteratively
const transaction = new Transaction.Transaction({
body,
witnessSet: fakeWitnessSet,
isValid: true, // included in CBOR, node does not count this
auxiliaryData: ...
})
const size = yield* calculateTransactionSize(transaction)
```

## Impact

~44 lovelace over-charge per transaction. Safe (node accepts fees above minimum) but imprecise.

## Fix

Serialize only `[body, witnessSet, auxiliaryData]` (3-element array) for size computation, or subtract the `isValid` CBOR overhead (~2 bytes) from the measured size.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.