Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect min amount for multiasset transaction #31

Closed
visopsys opened this issue Jul 4, 2022 · 5 comments · Fixed by #33
Closed

Incorrect min amount for multiasset transaction #31

visopsys opened this issue Jul 4, 2022 · 5 comments · Fixed by #33

Comments

@visopsys
Copy link
Contributor

visopsys commented Jul 4, 2022

I think this min value calculation for multiasset transaction is incorrect:

func (tb *TxBuilder) MinCoinsForTxOut(txOut *TxOutput) Coin {
	var size uint
	if txOut.Amount.OnlyCoin() {
		size = 1
	} else {
		numAssets := txOut.Amount.MultiAsset.numAssets()
		assetsLength := txOut.Amount.MultiAsset.assetsLength()
		numPIDs := txOut.Amount.MultiAsset.numPIDs()

		size = 6 + uint(math.Floor(
			float64(numAssets*12+assetsLength+numPIDs*28+7)/8,
		))
	}
	return Coin(utxoEntrySizeWithoutVal+size) * tb.protocol.CoinsPerUTXOWord
}

I have a multi-asset input and my values are as follow:

numAssets = 1, assetsLength = 8, numPIDs = 1, utxoEntrySizeWithoutVal = 27, tb.protocol.CoinsPerUTXOWord
 = 4310

Total coin amount = 168090 (or 0.16809 ADA)

This number is clearly smaller than min 1.3 ADA required to transfer multiasset. I got BabbageOutputTooSmallUTxO error when submitting this. Please check this function again for multi-asset

@visopsys
Copy link
Contributor Author

visopsys commented Jul 4, 2022

How do you come up with the calculation formula?

@echovl
Copy link
Owner

echovl commented Jul 7, 2022

The equation comes from the ledger spec, let me check this out

@core-dev-crypto
Copy link

Hi @echovl,

I'll check the general formula and it seem corret. I think that the error is in the rounding of size calculation:

size = 6 + uint(math.Floor( float64(numAssets*12+assetsLength+numPIDs*28+7)/8, ))

The +7 is used in case of truncation to flooring the number. So

size = 6 + uint(math.Trunc( float64(numAssets*12+assetsLength+numPIDs*28+7)/8, ))

or

size = 6 + uint(math.Floor( float64(numAssets*12+assetsLength+numPIDs*28)/8, ))

are the possible solutions.

@echovl
Copy link
Owner

echovl commented Sep 9, 2022

@core-dev-crypto can u make a PR?, I'm really busy these days, will check it out later

@core-dev-crypto
Copy link

Yes, sure.

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 a pull request may close this issue.

3 participants