Skip to content

PlutusData fixes and tests#669

Merged
scarmuega merged 2 commits into
txpipe:mainfrom
KtorZ:plutus-data-fixes
Jul 12, 2025
Merged

PlutusData fixes and tests#669
scarmuega merged 2 commits into
txpipe:mainfrom
KtorZ:plutus-data-fixes

Conversation

@KtorZ
Copy link
Copy Markdown
Member

@KtorZ KtorZ commented Jul 4, 2025

Note

It would be really nice if this could also be backported on top of v0.32.0 and released as we (Amaru & Aiken) aren't ready to upgrade to v1.0.0 and those are critical fixes. We can always keep a fork but that prevents publishing to crates.io which is quite annoying.

  • 📍 fix: ensure PlutusData encoding can roundtrip.

  • 📍 fix: PlutusData ordering and equality
    This has been broken for a while, and would ultimately result in all kind of errors and unexpected behaviours and errors. An example is when comparing two data in the Plutus Virtual Machine, they must match regardless of the chosen encoding (if one used an indefinite array and the other used a definite array, that shouldn't matter).

    It gets really subtle, for example with 'BigInt', as we now need to match the behaviour that's also present in the Haskell node. So for example, a serialized bigint with a payload [14], is equal to a simple serialized int of 14.

    Because of this, and because it is way too sensitive, we cannot rely on the auto-derived traits for any of the PartialEq and Ord implementations. They have to be carefully crafted to ensure that runtime behaviour closely follows the "specification".

    Note that I took the approach of preserving the PlutusData representation; which is an arguable choice in itself. An alternative could have been to use Rust data structure that could allow auto-deriving the traits. Although now, re-serializing isn't guaranteed to yield the same bytes and means PlutusData would also require some KeepRaw wrapper around. And, it would still demand a lot of care to ensure that the derived PartialEq and Ord traits are valid and remain conform to the Haskell implementation. So all-in-all, it's probably still better to keep hand-written instances.

scarmuega
scarmuega previously approved these changes Jul 10, 2025
  This has been broken for a while, and would ultimately result in all kind of errors and unexpected behaviours and errors. An example is when comparing two data in the Plutus Virtual Machine, they must match regardless of the chosen encoding (if one used an indefinite array and the other used a definite array, that shouldn't matter).

  It gets really subtle, for example with 'BigInt', as we now need to match the behaviour that's also present in the Haskell node. So for example, a serialized bigint with a payload [14], is equal to a simple serialized int of 14.

  Because of this, and because it is way too sensitive, we cannot rely on the auto-derived traits for any of the PartialEq and Ord implementations. They have to be carefully crafted to ensure that runtime behaviour closely follows the "specification".

  Note that I took the approach of preserving the PlutusData representation; which is an arguable choice in itself. An alternative could have been to use Rust data structure that could allow auto-deriving the traits. Although now, re-serializing isn't guaranteed to yield the same bytes and means PlutusData would also require some `KeepRaw` wrapper around. And, it would still demand a lot of care to ensure that the derived PartialEq and Ord traits are valid and remain conform to the Haskell implementation. So all-in-all, it's probably still better to keep hand-written instances.
@scarmuega scarmuega merged commit cefc5ab into txpipe:main Jul 12, 2025
0 of 7 checks passed
@github-project-automation github-project-automation Bot moved this to ✅ Done in Development Jul 12, 2025
scarmuega pushed a commit that referenced this pull request Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants