This article outlines the journey taken towards creating a new independent Proof-of-Work algorithm for Ubiq which we have called Ubqhash.

Implementing a hard fork for a new Proof-of-Work algorithm isn’t as easy as it sounds since there are many things to consider such as GPU mining software and how it would effect end users. There are many challenges to take into consideration such that the community is fully involved and the ecosystem doesn’t suffer.

Very few blockchains have performed a Proof-of-Work algorithm hard fork and even when they have, it has primarily been the same algorithm but with modified parameters such as using more RAM. Hard forks are also easier to perform on Bitcoin-based codebases with other examples to reference.

Ubiq has pioneered the implementation of several changes with Ethereum forks being the first to implement a monetary policy and the only chain with a modified difficulty algorithm (Flux) enabling an 88 second block time. Ubiq will soon be the first Ethereum fork with its own independent Proof-of-Work algorithm!

The beginnings and motivations

We had started to observe the increased frequency of 51% double-spend attacks against various Proof-of-Work blockchains at around May of 2018 across the crypto industry and wanted to do something about this. Attackers had used the same modus operandi which was to set up private mining pools of a coin, rented hash power, mined to their private pool and then initiated a 51% attack (via a block withholding attack) to perform double-spend on the network.

We started some discussions and brought this matter up to the community via our Ubiq Discord in a quick “show of hands” that would then become a formalized proposal for the community to vote on with our Escher voting system.

Ubiq Discord

UIP 1

At the end of May, UIP 1 (Ubiq Improvement Proposal 1) was presented to the community, discussed and voted upon. The community gave clear direction to the development team, with 56.4% of all the Escher supply taking part and a resounding 95.7% of participants voting to design and implement a new Proof-of-Work algorithm.

UIP1 voting numbers

Once the results came in, work began immediately on coding the new algorithm.

Initial development and internal testing

We had come up with and coded up an initial algorithm very early on however we soon found that the hard part of this hard fork wouldn’t be coming up with an algorithm but the surrounding pieces. We also took the chance to clean up the Go-Ubiq (Gubiq) node codebase and released a couple of versions at the end of July.

The first version of Ubqhash modified Ethash and swapped out the “Keccak-256” and “Keccak-512” algorithms with different ones. Once the initial code had been written, the new algorithm was then implemented onto a private version of Gubiq and then tested between the development team by CPU mining on private networks. This is an entirely feasible solution and we found that in CPU testing the hash rate gains were several times higher over Ethash.

It was necessary to extensively test the swap code, as this is the first time an Ethereum code-based network has swapped from its current algo to a new algo at a certain block number. The development ethos behind Ubiq values stability above all else.

On top of the standard node hard fork code, we felt it was also necessary to provide a version of Ethminer (the open source GPU miner) software that would support Ubqhash.

Building a development mining rig

To test and build a version of Ethminer to support Ubqhash, I built a GPU testing rig. It has an AMD RX 560 (11.9 MH ethash) and a NVIDIA GeForce GTX 1050 Ti (12.5 MH ethash) housed in a Micro ATX motherboard/case.

This runs at 160 Watts when both GPU’s are hashing away with Ethminer. The objective was not to build a powerhouse mining rig but one for development, benchmarking and testing.

This has been the first PC I’ve built in over 15 years and my first GPU mining rig (previously mined with CPU, ASIC’s and rented) so it’s been a fun and learning experience.

Micro ATX rig with a NVIDIA GeForce GTX 1050 Ti and an AMD RX 560. Thanks to @Coroto @Whitepaper @Sven Hoek @xocel @Eleven for the tips regarding building the rig

The GPU mining rig proved very helpful in putting some things into real-world perspective for miners and other parties who would integrate Ubqhash.

Looking at the challenges more and discussing with others, we decided to reduce the scope of the algorithm change. It will still be a hard fork and modified PoW but the changes will largely be on the DAG file side of things. Therefore the hashing will remain the same in terms of speed across all hardware. Other factors like node sync and block verification speed are also not negatively impacted.

This gave us greater confidence in the hard fork as it touches less code and still achieves the objectives set out in UIP 1.

Additional work and prepping for public testnet

Once the coding and benchmarking for the next iteration of Ubqhash had been completed, we surveyed the Ubiq community once again, this time for volunteers who are willing to contribute towards testing Ubqhash. In total we had 20 participants who stepped forward.

20 Community members volunteering to help out testing Ubqhash

We then moved to preparing the public Testnet. The network upgrade was implemented into a private repo and was timed for a DAG/epoch switch which occurs on the mainnet every 30,000 blocks (approximately 30.5 days). The Testnet block time was reduced to 5 seconds, so that the simulated hard fork will happen about 1.73 days from the Testnet launch.

We also built and tested a fork of Ethminer to work with Ubqhash. A big thank-you to the contribution from Paweł Bylica (one of the Ethminer developers) in assisting with modifying the C/C++ code to work with our algo.

Our fork of Ethminer will be called Ubqminer, to work with Ubqhash.

Technical details for Ubqhash

Ubqhash creates a totally incompatible version of the DAG file by using a different hash function on the cache.

In Python code the current function looks like this:

def mkcache(cache_size, seed):

n = cache_size // HASH_BYTES # Sequentially produce the initial dataset

o = [sha3_512(seed)]

for i in range(1, n):

o.append(sha3_512(o[-1])) # Use a low-round version of randmemohash

for _ in range(CACHE_ROUNDS):

for i in range(n):

v = o[i][0] % n

o[i] = sha3_512(map(xor, o[(i-1+n) % n], o[v])) return o

Ubqhash modifies the function like this:

def mkcache(cache_size, seed):

n = cache_size // HASH_BYTES # Sequentially produce the initial dataset

o = [blake2b_512(seed)]

for i in range(1, n):

o.append(blake2b_512(o[-1])) # Use a low-round version of randmemohash

for _ in range(CACHE_ROUNDS):

for i in range(n):

v = o[i][0] % n

o[i] = blake2b_512(map(xor, o[(i-1+n) % n], o[v])) return o

Instances of sha3_512 hashing are replaced by blake2b_512.

While this change may appear “simple” at first glance, it meant we had to port and implement this code change across several code bases.

Namely:

Go-Ubiq: Our full node software

Our full node software Ubqhash: The C/C++ implementation library Ethash was forked to Ubqhash

The C/C++ implementation library Ethash was forked to Ubqhash Ubqminer: The AMD/NVIDIA GPU software Ethminer was forked to support Ubqhash

The AMD/NVIDIA GPU software Ethminer was forked to support Ubqhash Open Ubiq Pool: The Open Ethereum Pool software was forked to initially support Ubiq and then code changes were added to support Ubqhash

Under the Testnet, the switch from Ethash to Ubqhash occurs at epoch 1 (block 30,000). We will publish the epoch and hard fork block for Mainnet at a later date.

Public Testnet

We have thoroughly tested out Ubqhash as well as simulated the hard fork multiple times privately. Will be running a public Testnet so that miners and integrators can run further tests. This is also an opportunity to ask any 3rd Party GPU writers to add support for Ubqhash.

Further details will be in Ubiq Discord so please join to collaborate further.

Please contact any 3rd parties you currently use such as HiveOS, SimpleMining OS, ethOS, Claymore and Phoenix miner to ask them to support Ubqhash. The community and developers are happy to assist.

We will be posting another post with further details when the hard fork is officially announced!