Monday, December 25, 2017

Bitcoin vs Bitcoin Cash

Bitcoin transaction fees are too damn high!

The rising transaction fees for Bitcoin have caused a major split, leaving the Bitcoin community divided into two camps: Bitcoin (BTC) and Bitcoin Cash (BCH). The two cryptocurrencies have unique ideas for how to reduce transaction fees: increase the blocksize, or build a new network on top of the blockchain.

The Bitcoin Cash camp is making the blocksize bigger (from 1MB up to 8MB). This results in much lower transaction fees as compared to Bitcoin. However, the problem with the Bitcoin Cash approach is that it's only a matter of time until the blocksize needs to be increased again. So it's a bandaid solution. In the eventual limit of gigantic blocksizes (give it a few years), this means that the blocks will be so large that average person will no longer be able to validate the blockchain. The current blocksize is 1MB/6 minutes ~= 87GB/year ~=150GB total as of now. If you make it larger, then an average harddrive will no longer be able to download and validate the blockchain. If you extrapolate this pattern to include the types of transaction volumes that VISA handles, then eventually only one giant corporation (Google?) will have a harddrive big enough to validate the blockchain. So this scenario ends in: "trust Google, your money is safe" or perhaps people will switch to an alternative currency that they trust more. But then again, human beings have been known to engage in some moral hazard in exchange for short-term monetary gains. Nobody lives forever, so pushing out the problem to the future may be OK. Maybe a band-aid is good enough.

The Bitcoin camp has taken a more creative approach than simply increasing the blocksize, and is building an entirely new transaction layer on top of the blockchain, that they call "The Lightning Network." The Lightning Network will allow people with Bitcoin to open a channel, and then do lots of little microtransactions outside of the blockchain, without having to pay a fee for every little transaction. It is only when they open and close a channel that the main Bitcoin blockchain learns about the final transaction, and so the fees are significantly reduced. This new system will allow for orders of magnitude more transactions, and therefore The Lightning Network is certainly not a band-aid solution. I would argue that The Lightning Network has the potential to be the killer app that the blockchain has been waiting for. The Lightning Network is in its infancy, and growth can be tracked here:

In the future, you will be able open an account with a deposit of Bitcoin (with a small fee), and then make payments with zero fees to anyone else that is a member of The Lightning Network (instantly). This will enable the microtransactions that have been the promise of Bitcoin for the last 7 years. And no, you won't need to provide your driver's license, address, passport, date of birth, and mother's maiden name to open a Lightning account! There is even an app that lets you try the test version of the lightning network:

Nobody knows which camp will win (Bitcoin or Bitcoin Cash), but odds are currently ~80% in favor of Bitcoin and the Lightning network, and ~20% in favor of Bitcoin Cash and increased blocksize (

As of the writing of this article, 1 BTC = $15,340 USD

Sunday, December 3, 2017

A bold strategy for The Government of Venezuela: buy Bitcoin

The promise of eliminating runaway inflation by irresponsible governments was one of the major reasons I became interested in Bitcoin. I always imagined that a country like Venezuela or Zimbabwe would be the first to switch away from their fiat currency and adopt Bitcoin. Today, Venezuela announced that they are trying to launch their own cryptocurrency, the Petro. I imagine President Maduro saying: "I have an idea: let's combine all the security risks of cryptocurrencies (theft, lost wallets, etc) with the monetary policy of the Government of Venezuela." To him I say: good luck with that!

I have an alternative. The Govt of Venezuela should buy large amounts of Bitcoin. If they put 15% of their resources into buying bitcoins and another 15% into mining bitcoins, they would become the first country to have BTC as their official currency. They have the power to make Bitcoin price skyrocket. They should do this in secret. If they delay the official announcement, then with the backing of a large government, Bitcoin price will skyrocket, and the government that buys at a low price will have made a direct profit on that investment after the official announcement. Venezuela could be a global version of the "the rich get richer." Furthermore, the investment in mining equipment that I am suggesting will be an investment into the future, as future Bitcoin mining will profit more from the transaction fee than they will from the raw currency creation. This would position Venezuela as a global processor of transactions, resulting in a net trade surplus due to skimming profits from international transactions. Ironically, the instability of the Bolivar makes it possible for Venezuela to profit immensely. They could turn their weakness into a strength. A country with a stable currency wouldn't have the political will to attempt such a bold (but in my opinion profitable) strategy.

Instead, what will probably happen is a bunch of Venezuelan politicians will flirt with some ideas and then possibly launch the next Dogecoin that has the same inflation problems as their existing currency and the Government of Venezuela will miss a golden opportunity.

Saturday, April 4, 2015

Satellite tracking with telescope

So after years of trying to get a video of the International Space Station, we finally did it! Here's the result:

This video is centered by using a weighted-average of the following video:

So how do you get a video like that? Well here's what the setup looked like a few minutes before ISS passed overhead! A telescope, some computers, in a parking lot 10 meters from our front door.

Here's a schematic diagram of the setup:

How does it work? Well, you need a telescope and a camera. A classic orange Celestron C8 (30+ years old) and a Celestron NexImage webcam get the job done. It helps to have a Telrad to center the telescope on moving targets. This is all you really need! Oh, maybe a broomstick to manually slew the telescope to ISS.

If you want automated tracking, then things get a bit more tricky. From this point on, everything is custom. For the guidescope, a Logitech webcam that has the lenses removed is attached via some Thorlabs optics to a 150mm lens. So the light coming from infinite distance (ISS is pretty far away) is focused onto the detector at a distance of 150mm. The webcam is held onto the optics with packing tape.

A custom guidescope: a Logitech webcam with lenses and case removed attached via Thorlabs optics to a 150mm lens

The guidescope sends low resolution images over a relatively large field of view, and because it's a small 25.4mm diameter lens, the amount of light collected is pretty low so it can only track bright objects such as planets, bright stars, or ISS. The guidescope is connected to a Gateway laptop that is running Labview software. The Labview software finds the coordinates of the brightest object in the image using a simple algorithm: weighted mean of all pixels above a user-defined threshold. The user also inputs desired coordinates. So there's a deltaX and a deltaY of coordinates which are used to control the Right Ascension (RA) and Declination (D) velocities. The user-defined X and Y are set to line up such that the satellite is in frame on the imaging webcam. Here's a video of the setup tracking Jupiter (before alignment of 3 axes):

At the end of the video you can see the Telrad pretty close to aligned with Jupiter!

Here it is after alignment of all 3 axes, and you can see Jupiter in the main imaging webcam.

To control the telescope, Labview sends commands via ASCOM Telescope MoveAxis rate commands. So we are updating the desired RA and D rates. These commands are sent via a USB to serial port to the Celestron Advanced GT mount hand controller. Here's a screen shot of the custom tracking software GUI:
Labview GUI screenshot

This is where it's refreshing that blogs are not peer reviewed. The following works, but I don't know why! I don't know exactly how to solve the control system for this telescope. If someone has ideas for this, please let me know. Attached is my best guess for what I'm doing, but I haven't solved it using Laplace transforms or anything like that due to the mysterious motor controller black box. Perhaps someone has a good model for how the motor controller and physical response of telescope?  The factor of 1/cos(D) is because as the declination approaches the polar axis (D=90 degrees), the RA becomes less and less sensitive. In fact, at D=90 degrees, moving RA only rotates the image, it does not actually move laterally!

It would be nice if Celestron or ASCOM allowed us to control the current (in Amps) directly to the motor. Any insight here would be appreciated! But the bottom line is that despite the uncertainty in why exactly it works, it does in fact work!

Warmup schedule

2 weeks before ISS pass:

2 days before ISS pass:

2 hours before:

  • start up laptop, check software (Labview has a tendency to crash randomly!)
  • bring telescope outside, set up telescope mount such that highest point of transit is perpendicular to polar axis of equatorial mount. So the perpendicular-to-equatorial plane should intersect the highest point of the transit. We want the highest point of the trajectory at declination = 0 degrees to get highest sensitivity on our motors.
  • Align 3 axes: Telrad, guidescope, main telescope
  • Focus main tube on bright object (moon, jupiter, bright star). 
  • check that telescope can slew over entire predicted trajectory (or as much as possible)

2 min before

  • switch to manual mode, use XBox controller to move around, get familiar with up/down, control, etc
  • start scanning the sky for ISS 

During ISS pass

  • use Xbox controller and Telrad to point telescope at moving target
  • once ISS is in the center of the Telrad and velocity is approximately correct, press "A" button to enable automatic tracking
    • if program "locks on" then great!
    • if program loses lock, then press "B" to enable manual mode and try again
  • Use Sharpcap running on second laptop to save video file from Celestron Neximage webcam, adjust exposure using Philips webcam control driver

1 minute after

90% of the time: Curse and cry due to fog on lens, algorithm error, incorrect alignment of axes, clouds, car driving by, etc etc.

10% of the time: PARTY!

1 hour after

Postprocessing of AVI file in Matlab (cropped to weighted centroid). No color adjustements, etc, performed.

Any comments or questions definitely welcome!


Oom Hank Verwest and late Aunt Barbara Verwest for kindly giving me the Celestron C8 telescope tube.

Tim Long and Rick Burke of ASCOM for posting useful information online

Thierry Legault's websiteRalf van de BerghSylvain Weiller and Atroguyz for inspiration

Thanks to my girlfriend Fernanda for spotting ISS, but mostly for keeping me company through all the failed attempts at capturing ISS :)

Sunday, June 15, 2014

How does World Cup Spray work?

World Cup ball
Hassan Ammar/Associated Press

In this World Cup, I was surprised when I saw a referee draw a white line on the ground for a free kick. "What a great idea!" I thought. But how does it work? Numerous google searches turned up meaningless articles such as this that basically describe the working principle of the spray as "you spray it on the ground and it leaves a line." NO SHIT SHERLOCK...
So how does it really work? Well, the can is under pressure, probably somewhere around 5 atmospheres of pressure, depending on the strength of the can. The main ingredient is water (80%). A mixture of gases are used to propel the surfactant out of the can, including butane, isobutane, and propane. Once the high pressure mixture of ingredients leave the can and enters the atmosphere, they expand and create a foam on the grass.

The most important ingredient is "polyoxyethylenated sorbitan monolaurate" (aka Tween20 at a concentration of around 1%). This molecule is known as a surfactant (more about this later!) The chemical structure is shown here (from Wikipedia):

Looking at this molecule, the left side is hydrophillic (likes water) and the right side is hydrophobic (likes sticking to hydrocarbon molecules such as butane, isobutane, and propane!) This is the key concept of how a surfactant works: it will stick to the interface between the water and the butane, to form surfaces. This allows the butane to form small drops in water (an emulsion) instead of just phase-separating with all the butane in one half of the can and the water in the other half of the can.

The other key concept is the phase change that Butane undergoes. The hydrocarbons that are under pressure (I would guess 5 atmospheres of pressure) in the can, expand to many times their volume when the enter the atmosphere. This is because Butane is a liquid at room temperature, for pressures greater than 2.5 atmospheres (density of 599 kg/m^3), but it is a gas at pressures below 2.5 atmospheres (density of 2.48 kg/m^3). So the Butane expands to ~250 times its volume when it leaves the can. It turns from a liquid into a gas and expands into massive bubbles. The water in the can doesn't change volume because it's a liquid at both atmospheric and can pressures.

So the expanded butane drops make a foam on the grass, which scatters light and makes it white in appearance. In my drawing, I only showed a few bubbles, but in reality there will be billions of them.

Eventually, the bubbles of propane will combine, pop, and evaporate, leaving only a residue of the surfactant (Tween20) and water on the grass. What makes the bubbles scatter light is the billions of interfaces of differing refractive indexes. Once these interfaces combine to form a thin layer of Tween20, they no longer scatter light, and become invisible.

Now you know: that's how World Cup Spray works!

Some of the other ingredients in the can are: a chelating agent "tetrasodium EDTA acid" at around 2% composition. A chelating agent is basically just a chemical that binds to metal ions. Who cares about metal ions? Well, metal ions (such as those that make up the can) have a tendency to break polymer chains such as the one that is used in the foam. So basically, the chelating agent helps preserve the important Tween20 chains from breaking down during storage in the can.

There are also some preservatives to prevent Bacteria from growing in the spray can if it's left on a shelf for a long time.

I made a schematic diagram of how I understand the can's operating principles. If you have questions, or think that my interpretation is wrong, please let me know and I'll update it! In particular, I'm not sure about the exact state of the foam while it's on the grass surface. Are they bubbles of propane? Or maybe not spherical bubbles?

My interpretation of how the spray works is based mainly on the patent by the inventor that I found here:

Sunday, February 2, 2014

The thermodynamic limit of bitcoin mining

There has been a trend in improving energy efficiency of Bitcoin mining machines. But how good can they get? What are the fundamental limits to the hashrate? What is the ultimate GH/J?

We can use thermodynamics to explore this possibility. If we treat the computation of a SHA256 hash as a simple operation, with a single bit of entropy required to calculate, then the energy expended to perform the hash is equal to the Landuaer limit: k*T*ln2. The blackbody temperature of outer space (caused by the cosmic microwave background left over from the big bang) is: 2.7K. So if we built a computer that was operating at 2.8 K and was radiating waste heat into outer space at 2.7K, we could theoretically perform each hash at 1.38E-23 J/K * 2.7K = 3.7E-23 J/operation, or inversely, 2.7*10^13 GH/J, or around 13 orders of magnitude better than the current Bitcoin miners! So plenty of room for improvement.

If we assume a Moore's law type improvement in efficiency of doubling every 18 months, then the time it will take before someone develops a thermodynamically limited ASICminer will be 65 years or so. I expect that DNA-based and other soft-matter computers will be much more energy efficient than current CPUs. I think it's not crazy to believe that a soft-matter computer (ie DNA annealing computer) may improve the energy efficiency of Bitcoin mining by a few orders of magnitude. 

So now if we harnessed the entire power of the sun to perform bitcoin operations, with around 3.8*10^26W of power, in theory we could perform: 3.8*10^26W/ 3.7E-23 J/operation =10^49 operations per second. The current Bitcoin mining network performs around 2*10^16 Hash/s, and so there are around 33 orders of magnitude left before the entire power of the sun is consumed calculating Bitcoin hashes.

OK, now what if someone built a hyper-efficient computer? What would happen to the difficulty of mining? Well, currently, the "target" to create a new block while mining on the Bitcoin network is: 0000000000000001F52C00000000000000000000000000000000000000000000
This number means that if a miner stumbles upon a hash that is less than this value, he/she wins the block reward. So around in in every 15 and 1/16 hexadecimals will be rewarded, which is (15 1/16)^17 = 7*10^18 hashes. So we expect each block to be solved in around: 7*10^18 hashes/2*10^16 Hash/s = 350 seconds, or 6 minutes or so. Now if we want to keep the block generation rate of the Bitcoin network the same, but with massively increased hashrate, the target just need to be readjusted. So what would the target have to be if we are using all of the power of the sun in a thermodynamically limited computer that radiates energy into space? Well, the target would have to be 10^33 times more difficult, or 33ln10/(ln16)=27 hexadecimals further to the right. So the target would have to be approximately: 000000000000000000000000000000000000000001F52C00000000000000000

And so, the Bitcoin system is pretty much OK with any foreseeable improvements in computational speed.

If you know how a quantum computer might affect these calculations (I don't), then please comment below!

Saturday, November 30, 2013

Bitcoin mining

For fun, I just put together a Bitcoin mining machine! The machine does brute-force calculations to try to solve the mathematical problem of what input (random string), in combination with the current Bitcoin block header (that contains a list of transactions) will produce the desired output, a series of numbers that starts with a bunch of zeroes. As an example, here is a script that will calculate the hash of Bitcoin Block number 125552:

import hashlib
header_hex = ("01000000" +
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +
"c7f5d74d" +
"f2b9441a" +
header_bin = header_hex.decode('hex')
hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
print "The hash of block 125552: ", testblock;

I got this from here . You can test this script for yourself by pasting and executing it here: Note that the first few digits of the resulting hash are zeroes, which is the criteria for mining a new block. This block was mined by trying numbers in the place of the '42a14695' until one of them worked. Note that the number 2504433986 is 9546A142 in hexadecimal, which becomes 42a14695 when re-arranged between little and big endian. So we can speculate that perhaps the miner had to try more than 2 billion combinations before finding the one that worked! All the current Bitcoin miners in the network are brute-force trying numbers, hoping to get lucky and collect the 25 Bitcoin reward. By performing this work, miners verify that the transactions are valid and secure the network as a whole since other miners scrutinize the block header looking for any mistakes that would invalidate it and prevent it from being widely accepted.
The mining setup that I built uses an ASICMiner Erupter Blade. I mounted the Blade in an old broken lab power supply that had a working fan in it already. The power supply is a 12V 10A LED power supply. I read some reports of the wires overheating so I went overkill and put some super beefy wires (AWG 8) between the power supply and the Blade. It took a lot of tinkering to set up. Eventually I settled on using 32 bit bfgminer since it has built in stratum proxy capability. I ran it with "bfgminer --http-port 8330" where I configured the Blade through a browser at as follows:

UPDATE: I created a .bat file, and put a shortcut to it in my startup folder. Now, everytime I start up my computer, it automatically starts mining. I had to set the properties of the shortcut to run as administrator in order for it to work. The bat file contains:
"cd Desktop/bfgminer-3.7.0-win32
bfgminer --http-port 8330 -o -u username -p 123"

Currently, the device mines approximately 293 micro-BTC/hr, but this is likely to decrease in the near future with faster mining machines. Update: down to 99 micro-BTC/hr :(

Update: I stopped mining because electricity costs became greater than the mining reward!

Comments/questions welcome! And of course donations :) 1EXhFqvXkwcXRfhUxmbaUSZgLhGCsWsUcu

Tuesday, October 23, 2012

DIY sonar using PC speaker and microphone

Together with my friend and colleague John Berezney, I decided to make a sonar system using a microphone and speaker. The idea is to make an active sonar system using PC speakers as output and a microphone as an input. I got some inspiration for this project from this website:

The first step is to make a chirp, which is just a type of pulse that changes frequency (see Figure). The audio speakers I have can only make pulses up to 20kHz (I think?), so I make chirps that vary between around 4kHz and 16kHz. I used Labview software to program the chirp and make it come out of my speakers.
The equation for this chirp, C(t) is a function of the pulse length T as well as the minimum and maximum frequencies in the chirp f_min and f_max. Typically I would choose a pulse length of T=2 milliseconds and f_min=4kHz and f_max=12kHz. The first part of the equation with the exponential is just an envelope function that prevents the frequency content from leaking into adjacent frequencies. The equation is:

Once we have a chirp coming out of the speakers, the next trick is to process the recorded audio that is coming in through the microphone. There are many ways to do this. I chose to use a matched filter. The idea is that whenever the microphone picks up a chirp that matches the one I sent, it makes a spike. This trick (matched filters) is used in radar all the time. The math for turning the microphone recording R(t) into a useful sonar signal S(t) using a matched filter is:

Note that we have to take the complex conjugate of the Fourier tranform of the chirp signal, multiply that by the Fourier transform of the Recording in frequency space, and then inverse Fourier transform to get a signal as a function of time. The signal S(t) has spikes wherever there is a reflection. Here you see S(t) which has a strong signal where the microphone picks up the direct wave, and a weaker signal for all the reflections.

The final step is to keep making chirps (my program could make around 4 per second) and then plot the intensity vs distance vs time (yes a 3D graph on a 2D plot!). To do this, I made an intensity graph, where height represents distance away in the reflection, and the time scrolls horizontally. I was holding a sound-reflecting clipboard, and walked away around 3 meters, and then returned to the computer. You can see that as a high intensity reflection going vertical on the graph (far away) and then closer.

John and I have some fun ideas for improving our sonar, I will keep the world updated as we make more improvements! I would be happy to hear if you guys have some fun ideas for improvements! I did all the signal processing and speaker output using Labview software. I am happy to give you the source code if you are interested.