Ananth Vivekanand

WebMine

Computers beware?

What’s cryptomining? #

Cryptomining is the action of mining cryptocurrencies, which involves validating transactions on the blockchain. Mining requires high amounts of computation power, and in exchange for validating these transactions, “miners” recieve tokens of a cryptocurrency as a reward.

Mining is usually done on expensive and specialized hardware such as graphics cards or chips known as ASICS, which require thousands of dollars for initial investment to begin mining from tiny margins. I (and apparently a few others!) wondered if this computation could be outsourced so miners don’t have to pay for their hardware or electricity - tada, introducing the browser!

Mining hashrates

The good: 👍

  • Websites can harness traffic for revenue
  • Easily scales, all computation work is preformed by the user
  • Can use spare CPU cycles that the client isn’t using

The bad: 👎

  • Easily injected as malware
  • Abuse causing high resource drain (more on this later)

I wanted to see how easy it could be to use web traffic to make money through cryptomining.

My Approach #

Most miners are written in languages that maximize performance, such as C, but a browser based miner would have to use Javascript, a client side scripting language. Finding javascript miners was scarce since no miner written in Javascript could comapare to one written in C, but I forged one. It was difficult finding resrouces online on how miners work.

I researched C implementations of cryptocurrency mining software, and ported the code over to Javascript to run in web browsers. It turned out that some of the hashing code that miners is use is incredibly complex and porting it to a pure javascript implementation would be extraordinarily time consuming. Then, I found that tools such as Emscripten could compile C code to WebAssembly, a new and experimental code that runs in multiple environments, including browsers. Compiling the Allium C code (the hashing algorithm) to WebAssembly proved to be straightforward and I used it as a drop-in module for my miner’s hashing purposes. I chose Garlicoin as my target cryptocurrency to mine, and set up a TCP Socket <–> WebSocket proxy to connect to the Garlicoin network.

Mining hashrates

Miner UI

All of my code can be found at: github.com/AnanthVivekanand/WebMine

What I found #

My browser miner had a peak efficiency of 42% of the native speed, which is an impressive feat considering futher optimization can be done and it was done in Javascript/WebAssembly..

Regarding the concept, malicious actors could exploit this new technology, but I envision that this could be considered a valid source of website revenue in the future. I can see that it could be a considered an alternative to obstructive ads or privacy-intrusive ads that sell personal data. I firmly believe that this technology can change the internet.