tweag / cooked-validators

MIT License
39 stars 11 forks source link

"Type sensitive" `Eq` and `Ord` instances in `Cooked.Skeleton` #319

Closed carlhammann closed 1 year ago

carlhammann commented 1 year ago

The Ord instance of MintsRedeemer and the Eq instance of TxSkelOut were implemented as comparing the on-chain representation of the data they describe, throwing away the type information in existential types hidden in their constructors.

For example, with this PR, Pays a == Pays b can only evaluate to true if a and b are of the same type. At the moment, they are considered equal if they have the same TxInfo representation. This means for example that the current Eq instance cannot distinguish between

The second case actually happened in the tests for the datum hijacking attack, and I adapted the reference scripts on all of the smart constructors for transaction outputs without explicit reference scripts (like paysScript, paysPK, ...) to be Nothing @(Pl.Versioned Pl.Script) (instead of Nothing @(Pl.TypedValidator Pl.Any) as before). This is the most generic choice and conforms with the return type of txSkelOutOwnerTypeP, which the attack relies on.