<p>You should checkout my open source cardano lottery repo which has code that worked on the testnet and does logic splitting across validators as well as some other optimization techniques.   That said, with Vasil coming, there will be additional ways to improve transaction size (eg. reference scripts), but you still may run into limitations with cpu and mem execution units.</p>
<p><a href="https://github.com/lley154/cardano-lottery" rel="nofollow noreferrer">https://github.com/lley154/cardano-lottery</a></p>

CC BY-SA 4.0
2022-09-09T00:12:56.490Z
2022-09-09T00:12:56.490Z
lley154
<p>Im very interested in how you can split the validation in several validator.</p>
<p>There is any model or framework to follow?</p>
<p>Any example around?</p>
<p>Could somebody at least share some words of insights about it?</p>
<p>I come with this idea:</p>
<ul>
<li><p>There is one main script, where all the Ada and Tokens are hold in different utxos with different types of Datums.</p>
</li>
<li><p>There is several other minting scripts witch produces NFTS.</p>
</li>
<li><p>OffChain, I create a data type containing all the datums and values of the inputs and outputs of the tx I want to validate. I will call this structure txInfoForValidation.</p>
</li>
<li><p>I need to send all that data to the minting validators because they can't access to the utxos located at the main validator script. They will have only this data structure that mimics the real tx I want to validate.</p>
</li>
<li><p>The minting validator checks the tx represented in txInfoForValidation and applies the business logic to approve or not the tx.</p>
</li>
<li><p>If the validation goes well, they mint an NFT.</p>
</li>
<li><p>The main validator doesn't have the business logic, but just check if a valid NFT is there. If it is present, its approves the consume of the utxos at his address.</p>
</li>
<li><p>The way for the minting validators and the main validator to communicate is trough the NFT TokenName</p>
</li>
<li><p>The NFT TokenName is based in the data structure I mentioned before. Different txs has different inputs, datums, values and outputs, and I can calculate the sha2_256 of all that structure I called txInfoForValidation. The hash of that data type is specific to that tx. The minting validators checks that the TokenName is right and then checks if it approves or not the tx that is represented there.</p>
</li>
<li><p>The main validator receives a context with inputs and outputs and OnChain recreates the data structure txInfoForValidation with all datums and values and then calculates the sha2_hash of it. If the hash calculated match an NFT present in the tx then it aproves the tx.</p>
</li>
</ul>
<p>What do you think about this idea?</p>
<p>It looks in principle that it can work. Can you see any security hole here?</p>
<p>Anyways, I'm having some problems with this idea. It reduces Plutus Script size. I can have many minting validators with different operations in each one. But I need to compute the HASH of the data structure txInfoForValidation in the minting validators and in the main validator. This is taking too much ram and I'm getting overspent resources now.</p>
<p>If this idea is correct, maybe there is a better way to compute the hash of the data structure txInfoForValidation. I did it by hand, field by field, because can't use dataHash from Plutus.Script.Utils.Scripts. It requires BuiltinData and i'm struggling trying to convert my data type to BuiltinData. So I access field by field, convert each one to BuiltInByteString, concatenate all the ByteStrings with &lt;&gt; and calculate the hash in the end.</p>
<p>Thanks for your time.</p>
<p>Any advice will be very much appreciated.</p>

<script><on-chain><hash><offchain><builtindata>
Workaround for Plutus Scripts that excesses the max Tx Size. Framework or examples for splitted or modular validators?
# Workaround for Plutus Scripts that excesses the max Tx Size. Framework or examples for splitted or modular validators?

(Asked by: username_0 on 2022-09-06)

Im very interested in how you can split the validation in several validator.

There is any model or framework to follow?

Any example around?

Could somebody at least share some words of insights about it?

I come with this idea:

* There is one main script, where all the Ada and Tokens are hold in different utxos with different types of Datums.
* There is several other minting scripts witch produces NFTS.
* OffChain, I create a data type containing all the datums and values of the inputs and outputs of the tx I want to validate. I will call this structure txInfoForValidation.
* I need to send all that data to the minting validators because they can't access to the utxos located at the main validator script. They will have only this data structure that mimics the real tx I want to validate.
* The minting validator checks the tx represented in txInfoForValidation and applies the business logic to approve or not the tx.
* If the validation goes well, they mint an NFT.
* The main validator doesn't have the business logic, but just check if a valid NFT is there. If it is present, its approves the consume of the utxos at his address.
* The way for the minting validators and the main validator to communicate is trough the NFT TokenName
* The NFT TokenName is based in the data structure I mentioned before. Different txs has different inputs, datums, values and outputs, and I can calculate the sha2\_256 of all that structure I called txInfoForValidation. The hash of that data type is specific to that tx. The minting validators checks that the TokenName is right and then checks if it approves or not the tx that is represented there.
* The main validator receives a context with inputs and outputs and OnChain recreates the data structure txInfoForValidation with all datums and values and then calculates the sha2\_hash of it. If the hash calculated match an NFT present in the tx then it aproves the tx.

What do you think about this idea?

It looks in principle that it can work. Can you see any security hole here?

Anyways, I'm having some problems with this idea. It reduces Plutus Script size. I can have many minting validators with different operations in each one. But I need to compute the HASH of the data structure txInfoForValidation in the minting validators and in the main validator. This is taking too much ram and I'm getting overspent resources now.

If this idea is correct, maybe there is a better way to compute the hash of the data structure txInfoForValidation. I did it by hand, field by field, because can't use dataHash from Plutus.Script.Utils.Scripts. It requires BuiltinData and i'm struggling trying to convert my data type to BuiltinData. So I access field by field, convert each one to BuiltInByteString, concatenate all the ByteStrings with <> and calculate the hash in the end.

Thanks for your time.

Any advice will be very much appreciated.

**Tags:** script, on-chain, hash, offchain, builtindata

---

## 1 answers

### Answer by username_1 on 2022-09-09. Score: 0

You should checkout my open source cardano lottery repo which has code that worked on the testnet and does logic splitting across validators as well as some other optimization techniques. That said, with Vasil coming, there will be additional ways to improve transaction size (eg. reference scripts), but you still may run into limitations with cpu and mem execution units.

<https://github.com/lley154/cardano-lottery>


---

