9

While writing validation as:

mkValidator :: SomeContractParam -> SomeDatum -> () -> ScriptContext -> Bool 

Could't we pass the same thing to Datum instead of using Contract Parameter?

7

Yes. It's important to have both options though.

Remember that the script address is derived from a hash of the compiled script code. So, if you parameterize parts of the script, the script address will be different with each parameter.

An example Lars gives in the PPP is an NFT. If you parameterize the forging policy to take a specific UTxO, and that script consumes that UTxO, you guarantee that there is only one instance of that policy. Only the person who owned that UTxO could possibly create that token, thus guaranteeing the creation only happens once.

If you had the same UTxO field in the datum, any instantiator of the script could specify some UTxO they own and the script address would be the same. Since the Currency Symbol is in fact the Script Address, any caller could create duplicates of the token and those tokens would be fungible.

2

Are you proposing using SomeDatum' = (SomeContractParam, SomeDatum) in lieu of SomeDatum as the actual datum to use so that you can drop the SomeContractParam mkValidator argument?

If so, then here is a problem. It is easy to find all the UTXOs at an address (including script address), by using utxoAt, so when you have different script addresses associated with different SomeContractParam values, utxoAt will separate out the UTXOs for you by the SomeContractParam. If you use (SomeContractParam, SomeDatum) as the actual datum and one script address for handling all the different SomeContractParam values, you can't easily segregate the UTXOs by SomeContractParam especially when the blockchain stores only DatumHash and not Datum. So e.g. you can't easily specify "spend UTXOs from among those that match a certain SomeContractParam" -- you would have to lookup the datum of all the UTXOs somehow.

Furthermore you would have to include the datum in the ScriptLookups submitted for the transaction in order for the validator to get the SomeContractParam value from the datum, resulting in needing to encode the transaction request with more bytes.

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.