<p>I see you used the <code>plu-ts</code> tag, I assume you are working with it.</p>
<p>plu-ts re-exports the <code>@harmoniclabs/uplc</code> module](<a href="https://github.com/harmoniclabs/uplc/" rel="nofollow noreferrer">https://github.com/harmoniclabs/uplc/</a>) as is.</p>
<p>so you have it already with plu-ts</p>
<p>as you can read from the <a href="https://github.com/harmoniclabs/uplc/?tab=readme-ov-file#parse-serialized-uplc" rel="nofollow noreferrer">uplc module readme</a>, there are functionalities to parse the bytes of the contract and print a prettified uplc textual form</p>
<p>this is the example reported in the package</p>
<pre class="lang-typescript prettyprint-override"><code>import { fromHex } from &quot;@harmoniclabs/uint8array-utils&quot;;
import { parseUPLC, prettyUPLC } from &quot;@harmoniclabs/uplc&quot;;

const serialized: Uint8Array = fromHex( &quot;0100003233700900219b8248050005200801&quot; );

const program = parseUPLC( serialized, &quot;flat&quot; );

console.log(
    prettyUPLC(
        program.body, // UPLCTerm 
        4 // indentation spaces
    )
);
/*
expected output:

[
    (lam a 
        [
            [
                (builtin addInteger) 
                (con integer 2)
            ] 
            [
                [
                    (builtin multiplyInteger) 
                    (con integer 10)
                ] 
                a
            ]
        ]
    ) 
    (con integer 4)
]
    
*/
</code></pre>
<p>you probably don't need to specify <code>&quot;flat&quot;</code> as second argument of <code>parseUPlC</code>  as I assume you are working with cbor.</p>
<p>have fun</p>

CC BY-SA 4.0
2024-01-05T16:46:20.413Z
2024-01-05T16:46:20.413Z
Michele Nuzzi
<p>It will depend on the format used. I'll give an example of converting the text envelope file format used by cardano-cli into PlutusIR. The text envelope contains the plutus flat binary format that is double-wrapped in cbor hex format.</p>
<p>This is the example text envelope script json file:</p>
<pre><code>{ &quot;type&quot;: &quot;PlutusScriptV2&quot;,
  &quot;description&quot;: &quot;&quot;,
  &quot;cborHex&quot;: &quot;59082e59082b010000323232323322323232323232323232332232323232322232325335323232325335001101a133573892011077726f6e6720746f6b656e206e616d650001932333573466e24005200001901a32323230010033200135501f223350014800088d4008894cd4ccd5cd19b8f0020070210201300a0011300600335002223333500123263201f335738921024c680001f200123263201f3357389201024c680001f23263201f3357389201024c680001f323500122222222222200835001220023333573466e1cd55cea80224000466442466002006004646464646464646464646464646666ae68cdc39aab9d500c480008cccccccccccc88888888888848cccccccccccc00403403002c02802402001c01801401000c008cd405805cd5d0a80619a80b00b9aba1500b33501601835742a014666aa034eb94064d5d0a804999aa80d3ae501935742a01066a02c0426ae85401cccd54068089d69aba150063232323333573466e1cd55cea801240004664424660020060046464646666ae68cdc39aab9d5002480008cc8848cc00400c008cd40b1d69aba15002302d357426ae8940088c98c80c4cd5ce01901881789aab9e5001137540026ae854008c8c8c8cccd5cd19b8735573aa004900011991091980080180119a8163ad35742a004605a6ae84d5d1280111931901899ab9c03203102f135573ca00226ea8004d5d09aba2500223263202d33573805c05a05626aae7940044dd50009aba1500533501675c6ae854010ccd540680788004d5d0a801999aa80d3ae200135742a00460406ae84d5d1280111931901499ab9c02a029027135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d55cf280089baa00135742a00860206ae84d5d1280211931900d99ab9c01c01b0193200135501b223350014800088d4008894cd4ccd5cd19b8f00200701d01c100113006003375c0082030264c6403066ae712410350543500018135573ca00226ea800448c88c008dd6000990009aa80b111999aab9f0012500a233500930043574200460066ae880080588c8c8cccd5cd19b8735573aa004900011991091980080180118061aba150023005357426ae8940088c98c8058cd5ce00b80b00a09aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a9aba1500233500f014357426ae8940088c98c806ccd5ce00e00d80c89aab9e5001137540026ae854010ccd54021d728039aba150033232323333573466e1d4005200423212223002004357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403a66ae7007807406c0680644d55cea80089baa00135742a00466a016eb8d5d09aba2500223263201733573803002e02a26ae8940044d5d1280089aab9e500113754002266aa002eb9d6889119118011bab00132001355013223233335573e0044a010466a00e66442466002006004600c6aae754008c014d55cf280118021aba200301413574200222440042442446600200800624464646666ae68cdc3a800a40004642446004006600a6ae84d55cf280191999ab9a3370ea0049001109100091931900919ab9c01301201000f135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900919ab9c01301201000f00e00d135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900719ab9c00f00e00c135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8030cd5ce00680600509baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c8054cd5ce00b00a80980900880800780700689aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401c66ae7003c03803002c4d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200b33573801801601201026aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401866ae700340300280240204d55cea80089baa0012323333573466e1d40052002200523333573466e1d40092000200523263200833573801201000c00a26aae74dd5000891001091000a4c240029210350543100112323001001223300330020020011&quot;}
</code></pre>
<ol>
<li>Extract the cborHex value to a new file &quot;cbor-script-file&quot;.</li>
<li>Remove the cbor headers (first 6 bytes). The value now starts with <code>10000</code> indicating the plutus compiler version used (1.0.0).</li>
<li>Convert this to binary format and write to a new file by running <code>cat cbor-script-file | xxd -r -p &gt; binary-script-file</code></li>
<li>Run the follow cmd from the plutus repo to convert to PlutusIR format (executable is available in nix shell) <code>cabal run uplc convert -- --if flat -i binary-script-file</code></li>
</ol>
<p>The PlutusIR output looks like</p>
<pre><code>(program
  1.0.0
  [
  (lam
    i_0
    [
      (lam
        i_1
        [
          (lam
            i_2
            ...
</code></pre>

CC BY-SA 4.0
2023-12-05T11:53:38.157Z
2023-12-05T11:53:38.157Z
james
<p>I'm working with Plutus Core smart contracts, and I have the binary encoding of a Plutus Core script. I'm curious to explore the higher-level Plutus code or any human-readable representation of the script. Does anyone have insights on how to decompile or disassemble the binary encoding back into untyped Plutus code or something higher-level than bytecode?</p>
<p>I appreciate any guidance or recommendations on tools, techniques, or resources that can assist in this process.</p>
<p>Thank you!</p>

<cardano-cli><cardano-node><smart-contract><plu-ts><plutus-core>
Decompiling Plutus Core Binary Encoding
# Decompiling Plutus Core Binary Encoding

(Asked by: username_0 on 2023-11-28)

I'm working with Plutus Core smart contracts, and I have the binary encoding of a Plutus Core script. I'm curious to explore the higher-level Plutus code or any human-readable representation of the script. Does anyone have insights on how to decompile or disassemble the binary encoding back into untyped Plutus code or something higher-level than bytecode?

I appreciate any guidance or recommendations on tools, techniques, or resources that can assist in this process.

Thank you!

**Tags:** cardano-cli, cardano-node, smart-contract, plu-ts, plutus-core

---

## 2 answers

### Answer by username_1 on 2024-01-05. Score: 0 | Accepted answer

I see you used the plu-ts tag, I assume you are working with it.
plu-ts re-exports the @harmoniclabs/uplc module](https://github.com/harmoniclabs/uplc/) as is.
so you have it already with plu-ts
as you can read from the uplc module readme, there are functionalities to parse the bytes of the contract and print a prettified uplc textual form
this is the example reported in the package
import { fromHex } from "@harmoniclabs/uint8array-utils";
import { parseUPLC, prettyUPLC } from "@harmoniclabs/uplc";

const serialized: Uint8Array = fromHex( "0100003233700900219b8248050005200801" );

const program = parseUPLC( serialized, "flat" );

console.log(
    prettyUPLC(
        program.body, // UPLCTerm 
        4 // indentation spaces
    )
);
/*
expected output:

[
    (lam a 
        [
            [
                (builtin addInteger) 
                (con integer 2)
            ] 
            [
                [
                    (builtin multiplyInteger) 
                    (con integer 10)
                ] 
                a
            ]
        ]
    ) 
    (con integer 4)
]
    
*/

you probably don't need to specify "flat" as second argument of parseUPlC  as I assume you are working with cbor.
have fun


---

### Answer by username_2 on 2023-12-05. Score: 1

It will depend on the format used. I'll give an example of converting the text envelope file format used by cardano-cli into PlutusIR. The text envelope contains the plutus flat binary format that is double-wrapped in cbor hex format.
This is the example text envelope script json file:
{ "type": "PlutusScriptV2",
  "description": "",
  "cborHex": "59082e59082b010000323232323322323232323232323232332232323232322232325335323232325335001101a133573892011077726f6e6720746f6b656e206e616d650001932333573466e24005200001901a32323230010033200135501f223350014800088d4008894cd4ccd5cd19b8f0020070210201300a0011300600335002223333500123263201f335738921024c680001f200123263201f3357389201024c680001f23263201f3357389201024c680001f323500122222222222200835001220023333573466e1cd55cea80224000466442466002006004646464646464646464646464646666ae68cdc39aab9d500c480008cccccccccccc88888888888848cccccccccccc00403403002c02802402001c01801401000c008cd405805cd5d0a80619a80b00b9aba1500b33501601835742a014666aa034eb94064d5d0a804999aa80d3ae501935742a01066a02c0426ae85401cccd54068089d69aba150063232323333573466e1cd55cea801240004664424660020060046464646666ae68cdc39aab9d5002480008cc8848cc00400c008cd40b1d69aba15002302d357426ae8940088c98c80c4cd5ce01901881789aab9e5001137540026ae854008c8c8c8cccd5cd19b8735573aa004900011991091980080180119a8163ad35742a004605a6ae84d5d1280111931901899ab9c03203102f135573ca00226ea8004d5d09aba2500223263202d33573805c05a05626aae7940044dd50009aba1500533501675c6ae854010ccd540680788004d5d0a801999aa80d3ae200135742a00460406ae84d5d1280111931901499ab9c02a029027135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d55cf280089baa00135742a00860206ae84d5d1280211931900d99ab9c01c01b0193200135501b223350014800088d4008894cd4ccd5cd19b8f00200701d01c100113006003375c0082030264c6403066ae712410350543500018135573ca00226ea800448c88c008dd6000990009aa80b111999aab9f0012500a233500930043574200460066ae880080588c8c8cccd5cd19b8735573aa004900011991091980080180118061aba150023005357426ae8940088c98c8058cd5ce00b80b00a09aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a9aba1500233500f014357426ae8940088c98c806ccd5ce00e00d80c89aab9e5001137540026ae854010ccd54021d728039aba150033232323333573466e1d4005200423212223002004357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403a66ae7007807406c0680644d55cea80089baa00135742a00466a016eb8d5d09aba2500223263201733573803002e02a26ae8940044d5d1280089aab9e500113754002266aa002eb9d6889119118011bab00132001355013223233335573e0044a010466a00e66442466002006004600c6aae754008c014d55cf280118021aba200301413574200222440042442446600200800624464646666ae68cdc3a800a40004642446004006600a6ae84d55cf280191999ab9a3370ea0049001109100091931900919ab9c01301201000f135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900919ab9c01301201000f00e00d135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900719ab9c00f00e00c135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8030cd5ce00680600509baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c8054cd5ce00b00a80980900880800780700689aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401c66ae7003c03803002c4d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200b33573801801601201026aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401866ae700340300280240204d55cea80089baa0012323333573466e1d40052002200523333573466e1d40092000200523263200833573801201000c00a26aae74dd5000891001091000a4c240029210350543100112323001001223300330020020011"}


Extract the cborHex value to a new file "cbor-script-file".
Remove the cbor headers (first 6 bytes). The value now starts with 10000 indicating the plutus compiler version used (1.0.0).
Convert this to binary format and write to a new file by running cat cbor-script-file | xxd -r -p > binary-script-file
Run the follow cmd from the plutus repo to convert to PlutusIR format (executable is available in nix shell) cabal run uplc convert -- --if flat -i binary-script-file

The PlutusIR output looks like
(program
  1.0.0
  [
  (lam
    i_0
    [
      (lam
        i_1
        [
          (lam
            i_2
            ...


---

