Neptune-Crypto / neptune-core

anonymous peer-to-peer cash
Apache License 2.0
23 stars 7 forks source link

How to Manage TypeScripts? #92

Open aszepieniec opened 6 months ago

aszepieniec commented 6 months ago

A type script determines how the state of a UTXO evolves. For plain money, the states are just amounts and the type script specifies that a) sum of all inputs minus sum of all outputs minus fee is non-negative and b) all outputs are positive. User-defined tokens can either use the same evolution logic or invent their own.

Neptune-core needs to have a way to look up the type scripts based on their hash digests, because in order to generate a transaction, it needs to produce a proof that all type scripts involved halted gracefully. Except for the native coin type script, type scripts can be defined by anyone and do not need to be a part of the software. So how does neptune-core know about them and where does it store them?

dan-da commented 5 months ago

So my first question would be: how is neptune made aware of user-defined tokens and also type-scripts? I would presume that it is through a transaction, meaning that both the token-type and type-script would be stored in the blockchain.

If not, then why not? That would seem to be entirely out-of-band....

If stored in the blockchain, then perhaps the problem becomes one of efficient lookup. When first encountered, we should store these items in a database. Then we need to be diligent to update the database when rolling back blocks, for example.

aszepieniec commented 5 months ago

how is neptune made aware of user-defined tokens and also type-scripts?

In principle, through out-of-band communication. Type scripts can be tailored to the particular participants. It might be prohibitively expensive to transmit type scripts over the blockchain for this use case.

That said, for some type scripts, such as e.g. those governing open-to-anyone user-defined tokens, the cost of transaction fees might be worth the benefit of wide dissemination. But even so, users who do not care about the token (or even other non-standard type scripts) can ignore them. To the extent that there is less cheap blockchain space, the type script users are paying for that in fees.

Users who want to use the blockchain for transmitting type scripts can use the public announcement field for that purpose.

Then we need to be diligent to update the database when rolling back blocks, for example.

I think the cost of keeping a type script database in sync with the blockchain does not justify the cost. Might as well store all type scripts and ignore rollbacks.