2

Why does the Plutus script need be provided in the transaction?

My understanding is that a script address is just a hash of the script. In order to spend a UTxO from a script address the spending transaction needs to include the script. The validator will check if the attached script's hash matches the script address and then execute the script to check if the input is allowed to be spent.

So the script needs to be known to whoever wants to spend a UTxo from a script address. The actual script can be attached to the UTxO when it is created on the script address so you can know what script needs to be used to unlock the funds. However, you still need to provide the script in the spending transaction.

This means that any time a UTxO from a smart contract address is spent, the transaction needs to include the script. If the script was stored separately on the address, then a spending transaction would only need to point to that script instead of spamming the blockchain with duplicate data. What am I missing here?

1

Having the script not attached to the UTxO outputs but to the spending transaction reduces the memory consumption of the nodes because UTxOs are stored in memory. Transactions can be pushed to the storage and erased from the cache once the transaction is confirmed and the slot added to the blockchain. Also (though I don't know if Cardano does this optimisation) you could reduce transaction sizes by having each script attached only once to the transaction when multiple UTxOs of the transaction need the same script.

2
  • Is the script attached to the block and counts towards blocksize? If it is then we would trade tps for lower memory consumption, correct?
    – Xiaofei
    Sep 16 at 11:30
  • 1
    The script is part of the transaction and adds to the block size (it is also counted when evaluating the max transaction size). As a transaction needs to contain all the information needed for nodes to validate it, it must include all scripts in an executable format (hence not as hash). There is no way around it. The only thing the blockchain can do, is decide where to attach the scripts, and having them attached to the transaction instead of the individual output UTxO seems to be the smarter way.
    – Jey
    Sep 16 at 20:22
0

If the script was stored separately on the address, then a spending transaction would only need to point to that script instead of spamming the blockchain with duplicate data.

It's true that you could minimalize the size of transactions gossiped around the network by storing the script on-chain, but there are other resources to consider. Storage on the blockchain is very expensive because everything on there is permanent. Once something is added, it will need to be included every time someone builds a node for all eternity (with the exception of pruned networks).

I think in a world where we stream Netflix at 4K, including the script in the transaction seems like a negligible cost to me. The payoff might not be there for the busiest dApps, but seems like a safer bet for a vast majority of junk on the chain.

2
  • 2
    But isn't the script that's attached to the transaction also stored on the chain? How else would a node be able to validate old transactions?
    – Xiaofei
    Sep 13 at 23:03
  • Ah. Very good point. Hmm... not sure then. Sep 13 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.