Ever since I started with Bitcoin I always thought that cryptocurrency itself is unhackable. We hear in the news that exchanges get hacked and Bitcoin / Ethereum was stolen. We hear stories of people being tricked to send their Bitcoin to scammers and never getting it back. But one thing we don’t hear about is the actual blockchain, the cryptocurrency being hacked…. until now.

Ravencoin is a fork of Bitcoin that launched on January 2018. It has a great development team, passionate community and a broad support by a number of cryptocurrency exchanges. Ravencoin did a number of enhancements to the Bitcoin code with a most notable enhancement of an ability to issue tokens on chain. Users of Ravencoin can use the native protocol and issue assets, then send those assets digitally to any other Ravencoin users, or reissue those assets which can change the characteristics of that asset on chain. Same as Bitcoin, Ravencoin is also an open source project hosted on Github with a core development team having ability to approve Github pull requests (PRs) and build installable assemblies for miners and users of Ravencoin network. The members of development team are volunteering and the network is forever in debt to them for their services in development of Ravencoin ecosystem. This article reviews the Ravencoin hack for educational and information purposes and does not blame anyone for what happened.

Just like Bitcoin network, Ravencoin has a consensus code that runs to make sure all miners agree that a transaction is valid. This consensus code runs on every node to validate the transaction and add it to the network’s mempool. That code was enhanced in Ravencoin to enable on chain transactions of native assets with a critical check put in place by the core development team that no asset transaction can go through, unless it has 0 Ravencoin value. The core developers wanted to make sure that if you are creating a Ravencoin asset it has no Ravencoin value associated with it.

I highlighted the area of an asset transaction check in pink on this screenshot.

Lines 263-266 are a part of the tx_verify.cpp file which are a part of the consensus code of Ravencoin. These lines check if this is an asset transaction and if it is, the code also checks for transaction value in Ravencoin is 0. If it’s not 0, it would reject this transaction as invalid.

The attacker decided to use this block of code to orchestrate his/her attack. He or she created a pull request in Github recommending to refactor the code for better readability and custom error messages.

The code highlighted in pink was removed allowing for attack to occur, but to trick the core dev team to commit this PR the attacker “refactored” this check into further logic. The code highlighted in green is showing how attacker suggests to check for the transaction value in Ravencoin to be 0 within “if (isAsset)” block on line 268 or 264 in the attacker’s version of the code.

We can see from the code that attacker suggested to reject a non-zero Ravencoin asset transactions if transaction type is TX_TRANSFER_ASSET. Further on line 307 the attacker suggests to check for non-zero Ravencoin asset transaction if transaction type is TX_NEW_ASSET. In all this, the attacker conveniently “forgot” to check the transaction type of TX_REISSUE_ASSET. The attacker’s hope was that Ravencoin core developers allow for this refactor PR to get approved to the Master branch and ultimately get into a formal Ravencoin binary wallet. Specifically, once this code was live the attacker hoped to execute a Ravencoin asset reissue transaction with an additional 500,000 Ravencoins associated with each transaction bypassing the checks and keeping all Ravencoin nodes operating at consensus even with additional Ravencoins being issued. This is exactly what happened.

What’s clever about this hack is that to exploit this vulnerability the attacker would have to use Ravecoin Command Line Interface (CLI) to create a custom reissue transaction. So once the code was live, regular users of the QT wallet couldn’t really stumble upon this vulnerability by accident when running legitimate asset reissue transactions.

This code was live on the Ravencoin network for just a few months but generated approximately 315 million additional Ravencoins for the attacker. These coins are valued at approximately $5.7 million at current prices. Important to note that all transactions on public blockchain are immutable and public. The illegally minted coins are traceable, so advanced analytics software can identify the movement of funds to exchange accounts and ultimately lead to the identity of an attacker. Please don’t attempt such hacks for any cryptocurrency – it can ruin your reputation, career, and even get you in trouble with law enforcement.

If you liked this article, please subscribe to my newsletter here.

Get more cryptocurrency news, charts, developments at our Facebook Group: Learn Bitcoin
Follow me on Twitter at https://twitter.com/nlukin