Skip to content

Order script_purpose.compare by the ledger's script purpose ordering - #134

Open
MavenRain wants to merge 1 commit into
aiken-lang:nextfrom
MavenRain:fix/125-redeemers-script-purpose-ordering
Open

Order script_purpose.compare by the ledger's script purpose ordering#134
MavenRain wants to merge 1 commit into
aiken-lang:nextfrom
MavenRain:fix/125-redeemers-script-purpose-ordering

Conversation

@MavenRain

Copy link
Copy Markdown

Fixes #125.

Problem

cardano/transaction/script_purpose.compare follows the constructor order of ScriptPurpose (Mint first, Withdraw before Publish). The redeemers list in the script context follows the internal ledger's ordering of script purposes instead: spending purposes come first, and certificate publications come before withdrawals. So sorting or searching redeemers with compare disagrees with the on-chain order.

Fix

  • Reorder the constructor arms of compare to the ledger ordering: Spend < Mint < Publish < Withdraw < Vote < Propose. The within-constructor comparators already match the ledger (inputs are a set ordered by output reference, mint policies are ordered lexicographically, Publish/Propose carry their pointer index, and credential.compare already puts Script below VerificationKey as reward accounts are ordered).
  • Flip the four affected expectations in compare_matrix (done first, to confirm they fail against the old implementation).
  • Reword the redeemers doc note on Transaction, and document the ordering on compare itself.
  • CHANGELOG entry with the breaking-change marker.

Prepared against next since the issue is milestoned v4.0.0; I'd be happy to retarget main instead.

Testing

aiken check: 977 passed, 0 failed. With only the test flips applied, exactly those four assertions fail, so the matrix does exercise the new ordering.

The redeemers list in the script context follows the internal ledger's
ordering of script purposes (Spend < Mint < Publish < Withdraw < Vote <
Propose), not the constructor order of ScriptPurpose.  Adjust compare,
flip the four affected compare_matrix expectations, and reword the
Transaction.redeemers doc note.

Fixes aiken-lang#125

Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant