Description
Summary
I just found myself in a situation where the builder does not produces an output with enough minAda. This situation happens when the Tx is only doing a mint, and the builder picks up first a utxo that is already using the minimum ada for its native tokens.
Concretely, my txbuilder is:
- txIn specific utxo for mint unicity
- mint
- change address
- select utxos from (all utxos)
- collateral
And this produced a Tx with just 1 input and 1 output. The one input (selected randomly for unicity) was containing 2 CNT, and becoming an output with 3 CNT and same ada minus fees. Obviously adding a token and removing the fees makes it so it became below the minAda.
In that situation, when doing utxo selection, the builder should check whether there is enough ada in the change output to cover the minAda. And if not, it should add another input with some free ada to compensate.
Steps to reproduce the bug
Here is the exact code I’m using for building:
const tx = await txBuilder()
// required UTxO to be spent (for unicity)
.txIn(
pickedUtxo.input.txHash,
pickedUtxo.input.outputIndex,
pickedUtxo.output.amount, // optional, but can avoid api provider requests
pickedUtxo.output.address, // optional, but can avoid api provider requests
0, // script size: optional, but can avoid api provider requests
)
// Badge being minted
.mintPlutusScript(ctx.uniqueMint.validator.version) // this is a bit WTF to split
.mint("1", policyId, "")
.mintingScript(ctx.uniqueMint.validator.code) // this is a bit WTF to split
.mintRedeemerValue([]) // WTF the split
// send change back to wallet
.changeAddress(walletAddress)
// Provide the list of UTxOs to use for selection
.selectUtxosFrom(utxos)
// set collateral
// Remark: this could fail if the wallet has no UTxO "declared" for collateral
.txInCollateral(
collateral.input.txHash,
collateral.input.outputIndex,
collateral.output.amount,
collateral.output.address,
)
.complete();
I think this problem is reproducible by recreating the same situation and doing a mint. Or maybe even simpler by just consuming the utxo already at minAda and sending it back to the change without doing anything except pay for fees.
Actual Result
Here is the Tx cbor it produced, with the output under minAda:
84a700d901028182582010bfb3d4fd1dada189bf24896f8b97658fcf85d1e02183aea77556f9f163a1fe000181825839001d737b7461f723d962b5c47092d3ad6d15d6cd2956fe29ad42a6cf6670b46e985fa50328fcb3d80594b6c5c54974a08d2c766a47570bfa36821a001150cea3581c493f77bfb97e7daddad6b5df8be9677b8962fdb4aa10287e6d1a2b75a14001581cb2324c5d4a0441228370e610f8630696bf98e0d87b5a541c9d671c7aa14001581cc667283b27ffdf5c8eed17d6d4ba67fef862d683fb61481123db611ea14001021a00030625075820bdaa99eb158414dea0a91d6c727e2268574b23efe6e08ab3b841abe8059a030c09a1581c493f77bfb97e7daddad6b5df8be9677b8962fdb4aa10287e6d1a2b75a140010b582016cb69c3ee240c8284a8eefac30ed0562834620c447911edc033bc86b2067e400dd9010281825820564ec19880c0a3d76fbcd99522f1ac16adea122c65c7132df02b9b0501e7710a05a300d9010281825820699fcb42601d00a1735f7fd03c7e68adace25339a8444bcb384756b71fdd4a7e58408c24438288c684702192b5068ef245bc7d79419d280f48481f0eb6cc07e24a035f7f77e178a63c5401accb047cb5dd13399b0c4f596fdffc0762029f0214710a07d90102815901895901860101003229800aba2aba1aba0aab9faab9eaab9dab9a488888896600264653001300800198041804800cc0200092225980099b8748000c01cdd500144c8c966002601c0031325980099b880014800229462b30013370e002900144c8cc004004dd6180798061baa0052259800800c528456600266ebcc040c034dd51808000809c528c4cc008008c04400500b201c8a5040248048dd69806800c5900b1919800800992cc004cdc3a400460146ea8006297adef6c6089bab300e300b37540028048c8cc004004dd59807180798079807980798059baa0042259800800c5300103d87a8000899192cc004cdc8803000c56600266e3c018006266e95200033010300e0024bd7045300103d87a80004031133004004301200340306eb8c030004c03c00500d112cc004006297ae089980698059807000998010011807800a018375c601660106ea800a2c8030601000260066ea802229344d9590011300127d8799f582010bfb3d4fd1dada189bf24896f8b97658fcf85d1e02183aea77556f9f163a1fe00ff000105a1820100828082199f561a00d842aff5d90103a0
Expected Result
In that situation, when doing utxo selection, the builder should check whether there is enough ada in the change output to cover the minAda. And if not, it should add another input with some free ada to compensate.
SDK version
1.9.0-beta.37 with the fix in #608
Environment type
- Node.js
- Browser
- Browser Extension
- Other
Environment details
No response