Interoperability Design Patterns #705
Replies: 1 comment 11 replies
-
You can use an NFT for this. Every pool gets a unique NFT identifier (Pool ID) that must be stored with the pool. The NFT name can be the hash of the output reference for the pool's UTxO - this guarantees uniqueness of the Pool IDs. Creating a new pool and minting the Pool ID can be done in a single step. Now, when a pool UTxO is consumed, the contract can just look for the output with the corresponding Pool ID. Since the Pool ID is guaranteed to be unique, double satisfaction is impossible. Each dApp can have its own Pool ID minting policy which further guarantees uniqueness of Pool IDs. Using Pool IDs, these pools can freely be composed together. I use this technique extensively. IMO this is a better approach than using reference scripts since reference scripts will likely be larger than a single NFT. If composability is the goal, smaller UTxOs are better. |
Beta Was this translation helpful? Give feedback.
-
Design Patterns For an Interoperable Ecosystem
Primer Section on What Double Satisfaction is
TODO: For now here's a link. https://github.com/input-output-hk/plutus/blob/master/doc/read-the-docs-site/reference/writing-scripts/common-weaknesses/double-satisfaction.rst
Let's Start with the batching model
The batching model typically has a batch action to apply user orders to a pool. There is some level of interoperability where you can make a order that goes to some script address with a datum hash. But right now Dexes are limited to one pool validator with one pool input per transaction.
So how do we change that model to allow not just any number of pools, but also any number of defi apps also executing in the same transaction while also protecting every user from double satisfaction. The easiest way I would tackle it is ensure one output per input. Right but how do we make sure we aren't accidentally validating an output that is used by another contract?
The answer is to first find a unique output that is unique to our validator. And then
More TODO here. Going to come back to this. But the main idea is to use the script ref field as an additional guarantee of uniqueness without having to restrict datums.
(Script Ref trick works only in PlutusV3)
Onchain steps to get a unique script ref hash:
First take the hash of the spending output reference for uniqueness
Next shove that into a script via bytearray concat.
Given a 32 byte array which can always be made by doing serialize_data |> blake256hash
you add 5828010000488120 to the front and 0001 to the back of that bytearray to make a valid script.
(Also can be made 4 bytes smaller by using blake224 hash instead. I'll update that here later.)
Next hash that script using the new Blake224 builtin.
Then check for the specified output index that should contain a Some with the same hash.
Beta Was this translation helpful? Give feedback.
All reactions