How to Retrieve OLGA’s Image From the Blockchain

An eternal token of love, OLGA’s image is stored on the most permanent medium known to man – the Bitcoin blockchain.

Here I will explain how the image is encoded, present a script which retrieves the image from the blockchain, and how to upscale the image.

The Blockchain Image

This exact image is saved on the blockchain:

The file is a miniature png file. A very small size was required to have it fit inside a bitcoin transaction.

Upscaled Version

Apply color grading and cubic resizing and – voila – the image looks more like the original drawing:

The algorithm is called Mantiuk Tone Mapping. I’ll explain the process at the end of this article. But first let’s retrieve the original file.

Base64 Encoding

The image is stored on the blockchain as a base64 string with the recognizable data:image/png;base64 prefix.

I predicted that if someone ever were to discover this string, they would easily be able to regenerate the image. Indeed, this is exactly what happened when OLGA was ‘unearthed’ in 2021.

Bitcoin Transaction

The base64 string is included in a transaction with ID 627ae48d6b4cffb2ea734be1016dedef4cee3f8ffefaea5602dd58c696de6b74.

You can look it up in any Bitcoin explorer: BlockCypher – Blockchain.com – Blockstream

The transaction has multiple outputs. Here’s the first of them:

The hex codes in blue and yellow contain some of the data. However, it took a full 165 such outputs to to fit the entire image. All of these are concatenated into one long hex string.

RC4 Stream Cipher

The string is RC4 encoded. It must be decoded with the input coin as the key. The input can be seen on Blockstream’s explorer:

Hex To String

The last step is to convert the hex string into a text string. Now you’ll find that it begins with CNTRPRTY and several more characters before data:image/png;base64, followed by the image data.

CNTRPRTY is the prefix which indicates the data is Counterparty encoded. This is a standard for encoding token data on Bitcoin. For this article this is irrelevant since I only want to show that OLGA’s image can be retrieved directly from Bitcoin. However, it’s worth mentioning that anyone running a Bitcoin node with the Counterparty extension can open the database and view OLGA’s code there.

String To Image

As mentioned before, this string can be opened with HTML. Include it in an img tag.

Save the below code as olga.html and open it in a browser:

<!DOCTYPE html>
<html>
  <head><title>OLGA</title></head>
  <body>
    <div style="text-align: center;">
      <h1>OLGA</h1>
      <img width="178" height="130" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABBCAYAAAC6jghZAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8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a9/HNulanfwwj+D8aUsBp48sJcvTRV9i7r2ufwT4aiH0isubZ2S56IzNl38XDjo+ZbP4m0+XXensbWNetd6CXQXh36Cpz4+IbGzG80dfB7CWxAuHzVrE6zzpArRxQXtdBeEFoZPz0oPMDr4swBw4w3+4KXSCKeSEC1srWWDvR7UALvZdB7KzLYOriGKc/38T4aszULXb0KcAMiL8sFZjByPnbdwFe21HwySO7L+/t">
    </div>
  </body>
</html> 

Raw Transaction To Image

The below code generates OLGA’s image from the raw Bitcoin transaction. It gathers the data from Blockcypher’s API, decodes, converts to text, extracts the image data and finally displays the image.

Note that no libraries are needed. Only some RC4 helper functions are required. The code will stop working if Blockcypher goes down, but the same data can be collected from any Bitcoin node. All of them keep an exact copy. That’s the entire point of Bitcoin – and Bitcoin NFTs!

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>OLGA</title>
    <script>

      let tx = '627ae48d6b4cffb2ea734be1016dedef4cee3f8ffefaea5602dd58c696de6b74'

      async function get(tx) {
        let url = 'https://api.blockcypher.com/v1/btc/main/txs/' + tx + '?instart=0&outstart=0&limit=200';
        let obj = await (await fetch(url)).json();
        return obj;
      }
      let json;
      setTimeout(() => { get_json(tx); }, 1402);
      
      function get_json(tx) {
        (async () => {
          json = await get(tx)
          decode(json);
        })()
      }

      function decode(json) {
        //GET INPUT ID AND OUTPUT SCRIPTS
        json = JSON.parse(JSON.stringify(json));
        let utxo = json['inputs'][0]['prev_hash'];
        let script = [];
        for (const x of json['outputs']) {
          if (x['script_type'] == 'pay-to-multi-pubkey-hash') {
            script.push(x['script']);
          }
        }

        //HEX DATA FROM BITCOIN OUTPUTS
        let hex_data = '';
        for (let i = 0; i < script.length; i++) {
          let raw = script[i].substring(6, 68) + script[i].substring(74, 136);
          raw = xcp_rc4(utxo, raw);
          let len = raw.substring(0, 2);
          len = parseInt(len, 16);
          raw = raw.substring(2, 2+(len*2));
          raw = raw.substring(16);      
          hex_data += raw;
        }

        //HEX TO ASCII STRING
        let raw_ascii = hex2a(hex_data);

        //IMAGE DATA FROM ASCII STRING
        let img_data = raw_ascii.substring(raw_ascii.indexOf('data:image/'));
        img_data = img_data.slice(0,-1);

        //OUTPUT HTML
        let img_tag = '<img src="' + img_data + '">';
        let img_tag_double = '<img width="178" height="130" src="' + img_data + '">';
        let html = '<h1>OLGA</h1>';
        html += '<p><br><b>ORIGINAL</b><br>(89x65)<br>' + img_tag + '</p>';
        html += '<p><br><b>DOUBLE</b><br>(178x130)<br>' + img_tag_double + '</p>';
        document.getElementById('content').innerHTML = html;
      }

      //HELPER FUNCTIONS
      function hex2a(hexx) {
        var hex = hexx.toString();//force conversion
        var str = '';
        for (var i = 0; i < hex.length; i += 2)
          str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
        return str;
      }

      function xcp_rc4(key, datachunk) {
        return bin2hex(rc4(hex2bin(key), hex2bin(datachunk)));
      }

      function hex2bin(hex) {
        var bytes = [];
        var str;
        for (var i = 0; i < hex.length - 1; i += 2) {
          var ch = parseInt(hex.substr(i, 2), 16);
          bytes.push(ch);
        }
        str = String.fromCharCode.apply(String, bytes);
        return str;
      };

      function bin2hex(s) {
        // http://kevin.vanzonneveld.net
        var i, l, o = "",
            n;
        s += "";
        for (i = 0, l = s.length; i < l; i++) {
          n = s.charCodeAt(i).toString(16);
          o += n.length < 2 ? "0" + n : n;
        }
        return o;
      }; 

      function rc4(key, str) {
        //https://gist.github.com/farhadi/2185197
        var s = [], j = 0, x, res = '';
        for (var i = 0; i < 256; i++) {
          s[i] = i;
        }
        for (i = 0; i < 256; i++) {
          j = (j + s[i] + key.charCodeAt(i % key.length)) % 256;
          x = s[i];
          s[i] = s[j];
          s[j] = x;
        }
        i = 0;
        j = 0;
        for (var y = 0; y < str.length; y++) {
          i = (i + 1) % 256;
          j = (j + s[i]) % 256;
          x = s[i];
          s[i] = s[j];
          s[j] = x;
          res += String.fromCharCode(str.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]);
        }
        return res;
      }
    </script>

  </head>
  <body>
    <div id="content" style="text-align: center;">
      <h2>Loading Blockcypher API..</h2>
    </div>
  </body>
</html>

Upscaling with GIMP

The blokchain image was overexposed on purpose. The intent was to make a near-invisible engraving that would pop out when looking from an angle. On a modern screen this may not hold true anymore, but that’s how I presented it to Olga on our old LCD monitor.

Anyway, for showcasing OLGA it may be desired to show a version more similar to the original pencil drawing.

Thankfully, it’s easy to upscale the blockchain original with GIMP. It only takes three steps;

  1. Image → Crop to Content
    The blockchain image had the last few characters cut off due to a wallet bug. Therefore the bottom line is shown as transparent pixels. This command simply removes that line.
  2. Image → Tone Mapping → Mantiuk 2006…
    Leave the default settings and click OK.
  3. Image → Scale Image
    Set Width and Height to 300% and Interpolation to Cubic.

That’s all!

It’s on my TODO to do this programmatically with the gimpfu library.

Categories: Uncategorized