Skip to content

Fix triple CBOR encoding of Plutus scripts causing error 3116#31

Merged
SynthLuvr merged 2 commits into
mainfrom
copilot/fix-signing-wallets-issue
Mar 1, 2026
Merged

Fix triple CBOR encoding of Plutus scripts causing error 3116#31
SynthLuvr merged 2 commits into
mainfrom
copilot/fix-signing-wallets-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 1, 2026

Transactions generated by src/mint.ts were rejected by the Cardano node with error 3116 (malformed Plutus scripts) due to triple CBOR encoding of the script in the witness set.

Root cause

UPLC.applyParamsToScript() returns a double CBOR-encoded hex string. Passing that directly to hexToBytes() and then PlutusV3({ bytes }) stores double-CBOR bytes in the script object. The transaction serializer then wraps script.bytes in a CBOR byte string, producing triple encoding — one layer too many.

Fix

Apply UPLC.applySingleCborEncoding() to strip the outer CBOR layer before constructing PlutusV3, so the serializer produces the required double CBOR on-chain.

// Before — triple CBOR when serialized ❌
const scriptHex = UPLC.applyParamsToScript(plutus, [...]);
return new PlutusV3({ bytes: hexToBytes(scriptHex) });

// After — double CBOR when serialized ✓
const scriptHex = UPLC.applySingleCborEncoding(
  UPLC.applyParamsToScript(plutus, [...])
);
return new PlutusV3({ bytes: hexToBytes(scriptHex) });

Same fix applied to the equivalent createScript in src/nft.ts.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: SynthLuvr <131367121+SynthLuvr@users.noreply.github.com>
Comment thread src/mint.ts
Comment thread src/nft.ts
Copilot AI changed the title [WIP] Fix signing wallets error for Plutus scripts Fix triple CBOR encoding of Plutus scripts causing error 3116 Mar 1, 2026
@SynthLuvr SynthLuvr marked this pull request as ready for review March 1, 2026 19:43
@SynthLuvr SynthLuvr merged commit 3b63332 into main Mar 1, 2026
1 check passed
@SynthLuvr SynthLuvr deleted the copilot/fix-signing-wallets-issue branch March 1, 2026 19:43
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.

2 participants