Repository navigation
fix(evolution): order withdrawal and voter redeemer indices type-first to match ledger Ord (#404) - #643
Open
Kshot3000 wants to merge 1 commit into
Open
fix(evolution): order withdrawal and voter redeemer indices type-first to match ledger Ord (#404)#643Kshot3000 wants to merge 1 commit into
Kshot3000 wants to merge 1 commit into
Conversation
…t to match ledger Ord (IntersectMBO#404)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #404. The builder assigned reward and vote redeemer indices in hash-only order, but the ledger resolves a redeemer pointer by the key's position in a map ordered by
Ord— for credentials that is type-first (ScriptHashObjsorts beforeKeyHashObj), then by hash. When a transaction mixed a script credential and a key credential whose hashes interleaved against the type order, the SDK placed the redeemer at a different index than the ledger resolves, and the transaction was rejected (MissingRedeemers/ExtraRedeemers).What was wrong
txBuilder.ts(assembly) sorted withdrawals by credential hash only (localeCompareon the hash hex), discarding the credential type.Evaluation.tsmirrored the same hash-only withdrawal sort, so assembly and evaluation agreed with each other but not with the ledger.voterToKeygave key-hash and script-hash DRep/committee voters the same key prefix, so sorting voter keys again ordered purely by hash and discarded the type.Fix
compareCredentialsinTransactionBuilder.ts: rank script-hash credentials before key-hash credentials, then compare hash bytes (explicit</>on the hex, nolocaleCompare).txBuilder.tsandEvaluation.ts, so assembly and evaluation assign the same, ledger-correct index.voterToKeynow encodes the credential'sOrdrank in the key —cc:0:/drep:0:for script-hash credentials,cc:1:/drep:1:for key-hash credentials,pool:unchanged — so the existing lexicographic sort of voter keys reproducesOrd Voter(voter kind first, then script-before-key, then hash). All voter keys are produced throughvoterToKey, so the format change is internal and consistent across Vote, txBuilder and Evaluation.Note the direction trap from the issue: this is deliberately not serialized-byte order — a reward account's header byte puts key-stake (
0xE_) before script-stake (0xF_), the opposite ofOrd Credential— so the sort is by explicit type rank, never by address/credential bytes.Tests
New
test/TxBuilder.RedeemerIndexOrd.test.ts, built through the real txBuilder with a stub (echo) evaluator, using a Plutus V3 script whose hash (a24924…) interleaves against a0x11…key hash:Full suite: 1682 passed / 75 skipped / 0 failed (main baseline 1678 + 4 new),
tsc --noEmitand eslint clean. Patch changeset added.Independent builder — not affiliated with the Cardano Foundation, IOG or Intersect.
@Kshot9000 (https://x.com/kshot9000) · ADA donations: addr1q8hnl6vl5a6k3rw3n5g3jtte696zcl76kfatzv7gpswa9r0dj7fma6klq55y4ffm7tf0em09udnyhuk4ah92pl5x9jpqjae44v
cc @cardano-foundation @IntersectMBO