Coder Social home page Coder Social logo

Comments (6)

lunfardo314 avatar lunfardo314 commented on September 23, 2024

.. unless foundy serial numbers start at 1 for some reason

from iota.go.

lunfardo314 avatar lunfardo314 commented on September 23, 2024

another finding. It seems it happens when all tokens in inputs are destroyed.
The following test case fails:

  • inputs has 50 of tokens with ID in ExtendedOutput
  • inputs has foundry with ID and 100 of circulating supply
  • outputs has no tokens with ID
  • outputs has foundry with ID and 50 of circulating supply
    It is destroying 50 tokens of supply with ID. It fails with chain 08c48c52bbaee81e74514e0e6f7386b369ae94db4e0100000000 (*iotago.FoundryOutput) state transition failed: native token sums are unbalanced: unbalanced circulating supply change -50 of 08c48c52bbaee81e74514e0e6f7386b369ae94db4e0100000000000000000000000000000000: foundry state transition does not balance NativeToken 08c48c52bbaee81e74514e0e6f7386b369ae94db4e0100000000000000000000000000000000

from iota.go.

luca-moser avatar luca-moser commented on September 23, 2024

Case 1:
TIP-0018 specifies that:

When the current state of the foundry with Foundry ID is empty, it must hold true for Serial Number in the next state, that:
Foundry Counter(InputAlias) < Serial Number <= Foundry Counter(OutputAlias)

which means that the Serial Number of a Foundry can never be 0.

Case 2:
Looking at the numbers you are not actually burning tokens since you are transferring the 50 input tokens (of the extended output) to the foundry output on the output side. The error correctly states that you are short -50 because the tokens of the input side are not burned as you have transferred them to the output side. It would be good if you could show some code just to ensure we are talking about the same thing.

from iota.go.

lunfardo314 avatar lunfardo314 commented on September 23, 2024
  1. yes, it may be this strange requirement to start serial numbers from 1, it is ok then. However then I propose to rename startSerial to something else

  2. No, it is not true, it is destroying 50 tokens. The foundry output does not contain any tokens . Simply logic does not work when absense of tokens in the outputs means 0.

It is very difficult to point to the code, I would need to spend a lot of time to extract it. It is hidden in the VM's transactio builder. I see that transaction it produces is valid (according to my check), but it fails with validation.
Specifically, this test (among other) fails but it is not very helpful, I guess. https://github.com/iotaledger/wasp/blob/e7b676bef065d640dfdb0527e6b2e021e99da28f/packages/vm/core/testcore_stardust/accounts_test.go#L564
The common diagnosis: if we have N tokens in input and no tokens in outputs (all destroyed by foundry), it fails
In ISC VM foundries never contain any native tokens

from iota.go.

luca-moser avatar luca-moser commented on September 23, 2024

I can not reproduce the issue you've outlined in case 2 (this works):

func TestCirculatingSupplyBurn(t *testing.T) {
	_, ident1, ident1AddrKeys := tpkg.RandEd25519Identity()
	aliasIdent1 := tpkg.RandAliasAddress()

	tokenTag := tpkg.Rand12ByteArray()

	inputIDs := tpkg.RandOutputIDs(3)
	inputs := iotago.OutputSet{
		inputIDs[0]: &iotago.ExtendedOutput{
			Address: ident1,
			Amount:  OneMi,
		},
		inputIDs[1]: &iotago.AliasOutput{
			Amount:               OneMi,
			NativeTokens:         nil,
			AliasID:              aliasIdent1.AliasID(),
			StateController:      ident1,
			GovernanceController: ident1,
			StateIndex:           1,
			StateMetadata:        nil,
			FoundryCounter:       1,
			Blocks:               nil,
		},
		inputIDs[2]: &iotago.FoundryOutput{
			Address:           aliasIdent1,
			Amount:            OneMi,
			NativeTokens:      nil,
			SerialNumber:      1,
			TokenTag:          tokenTag,
			CirculatingSupply: big.NewInt(50),
			MaximumSupply:     big.NewInt(50),
			TokenScheme:       &iotago.SimpleTokenScheme{},
			Blocks:            nil,
		},
	}
	
	// set input ExtendedOutput NativeToken to 50 which get burned
	foundryNativeTokenID := inputs[inputIDs[2]].(*iotago.FoundryOutput).MustNativeTokenID()
	inputs[inputIDs[0]].(*iotago.ExtendedOutput).NativeTokens = iotago.NativeTokens{
		{
			ID:     foundryNativeTokenID,
			Amount: new(big.Int).SetInt64(50),
		},
	}

	essence := &iotago.TransactionEssence{
		Inputs: inputIDs.UTXOInputs(),
		Outputs: iotago.Outputs{
			&iotago.AliasOutput{
				Amount:               OneMi,
				NativeTokens:         nil,
				AliasID:              aliasIdent1.AliasID(),
				StateController:      ident1,
				GovernanceController: ident1,
				StateIndex:           1,
				StateMetadata:        nil,
				FoundryCounter:       1,
				Blocks:               nil,
			},
			&iotago.FoundryOutput{
				Address:           aliasIdent1,
				Amount:            2 * OneMi,
				NativeTokens:      nil,
				SerialNumber:      1,
				TokenTag:          tokenTag,
				// burn supply by -50
				CirculatingSupply: big.NewInt(0),
				MaximumSupply:     big.NewInt(50),
				TokenScheme:       &iotago.SimpleTokenScheme{},
				Blocks:            nil,
			},
		},
	}

	sigs, err := essence.Sign(ident1AddrKeys)
	require.NoError(t, err)

	tx := &iotago.Transaction{
		Essence: essence,
		UnlockBlocks: iotago.UnlockBlocks{
			&iotago.SignatureUnlockBlock{Signature: sigs[0]},
			&iotago.ReferenceUnlockBlock{Reference: 0},
			&iotago.AliasUnlockBlock{Reference: 1},
		},
	}

	require.NoError(t, tx.SemanticallyValidate(&iotago.SemanticValidationContext{
		ExtParas:   nil,
		WorkingSet: nil,
	}, inputs))
}

from iota.go.

luca-moser avatar luca-moser commented on September 23, 2024

Case 2 was fixed via 5e2f585

from iota.go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.