This does not answers your question directly, but might you give you an idea how to solve it in a different and potencialy better way.
In case you wondered, here are some quick clarifications about the infamous 'collaterals' in #Cardano.
There was an interesting conversation I was brought into and thought it could be interesting to turn it into a proper thread.
All you ever wanted to know about collaterals 👇
With the Alonzo era and the introduction of Plutus scripts was also added a new feature to transactions: collaterals.
In essence, a collateral is an input which is consumed when a script fails to execute in a transaction.
But, aren't scripts supposed to be deterministic?
Precisely.
So in principle, any user in their right mind would not submit a transaction with a failing script, because they would know the outcome in advance.
Yet, an attacker of the system might find that interesting...
In fact, a failed transaction consumes resources but does not reward block producers for it. No fees are collected. For basic transactions only involving public key signatures, that's okay since the resources involved are negligible.
Yet for Plutus scripts, that's another story.
Hence why a 'collateral' was introduced to transactions.
It is an input (or, UTxO) that is consumed when a well-formed transaction with a failing script is submitted through the system. It acts as a mechanism to prevent bad actors to waste resources of the network at no cost.
Any transaction that executes a script is required to have a collateral, but it's only consumed if the result of the script execution turns out wrong.
The amount of collateral depends on the cost of the script and some protocol parameters. Plus, some extra rules.
In particular, the collateral cannot itself be an input locked by a script.
Moreso, it must NOT contain any native asset, but be a pure Ada UTxO.
Of course, it must also be an existing input that can be rightfully spent by the transaction.
In practice, it means that wallets must manage this collateral. Wallets must make sure to keep a large enough Ada-only UTxO available for collateral.
This can be a little tricky, and also, a bit odd from a user perspective.
Most Ada holders that have interacted with DApps have probably went through the steps of 'setting a collateral' in their wallet prior to making any transaction to a smart-contract.
This is a, relatively transparent, way for wallet providers to inform users about collaterals.
Overall, this is an unsatisfactory user and developer experience, for both > Ada holders and wallet providers alike.
While the management of collaterals doesn't require users to explicitly set one, it's cumbersome and confusing to manage over time behind the scene.
So, with the Babbage era, a new feature was introduced called the 'collateral return'.
This allows wallets to not only define a collateral input to consume on failure, but also an output to send some change to in case it happens.
And this makes everyone's life a lot easier.
Remember the constraints about the collateral? In particular, that it needs to be Ada-only?
Well now, what matters is that the remainder between the collateral input > and return is an Ada value, of a minimum quantity depending on the script cost and protocol parameters.
Said differently, it makes management of collaterals easier for wallets that decide to make use of it. They no longer need to keep a particular Ada-only UTxO around but can simply use any sufficiently large input as collateral and dump whatever is left in a change output.
It's interesting to note that collaterals were never meant to be a user-facing feature in the first place.
This was supposed to happen behind the scene only, because in principle, users (or by extension wallets) do not normally submit failing transactions.
Yet, this somehow made its way through UIs in such a way that as Cardano users, we've grown accustomed to it.
Up to the point where, new wallets would even have to adopt the same strategy to not confuse people.
UX is a funny thing 😶
Moving forward, and with collateral return available in the protocol, we can hope that wallet providers will gradually update to adopt this new approach and, put collaterals back in the shadow and not bother us users about them anymore 😊