Workaround for Plutus Scripts that excesses the max Tx Size. Framework or examples for splitted or modular validators?

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.