Neptune-Crypto / neptune-core

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

Check that each UTXO references a type script only once #164

Open Sword-Smith opened 1 month ago

Sword-Smith commented 1 month ago

I don't think this check is in place, and I think it would be a good idea to add it. However, if ordering is well-defined, then maybe we can just consider the 1st Coin if multiple coins reference the same typescript?

aszepieniec commented 1 month ago

I can't think of anything that could go wrong in terms of consensus when a UTXO is allowed to have more than one coin of the same type script. However, I do see pitfalls regarding serialization and equality testing of UTXOs. You could have the "same" UTXO that serializes to something different and therefore yields a different hash. I can imagine this being used in an attack to exact payment for a UTXO which the receiver then cannot spend.

To fix it, I propose the following solution. Except for (potentially) genesis UTXOs, all coins in the UTXO's coins dictionary are sorted by type script hash. The CollectTypeScripts script checks that for all output UTXOs, no consecutive pair of coins have the same type script hash.

Sword-Smith commented 1 month ago

I added an lt for Digest in tasm-lib, so now we can use that to enforce that coins are sorted by type_script_hash, and that there are no repeated type_script_hash values.