Can we find an algorithm to compute the average price (as energy consumption) of 1 BTC being generated if we know: hash rate, difficulty, energy price?
The parameters you need to calculate this are:
E - the mining efficiency, measured in MHash/J. Data on this for various hardware is available in Mining hardware comparison (though this take into account only the card's power and not of the system it is in). Or you can calculate it for a given system by dividing the total hashrate (in MHash/s) by the power consumed (in W).
c - the cost of electricity, measured in $/KWh.
B - the bitcoin reward per block.
D - the difficulty.
The cost to generate 1 BTC is:
For example, if E=2, c=0.1, B=50 and D=1,500,000, this is 0.1*1500000/(838*50*2) = $1.79
The 838 "magic number" comes from the various unit conversion factors - 2^32 hashes per difficulty-1 hash, 3,600,000 Joules per Kilowatt-hour, 1,000,000 Hashes per MHash.
As Bitcoin mining is very heterogeneous (that is, a lot of people use a wide variety of hardware), figuring this out would be really hard without the use of polling (as in, asking people questions, not long polling). One would need to get some statistical data on what hardware people have, how much they spend on electricity, and how much hashpower they have, not to mention how much they mine each day. Having all that, we could average it out and calculate something.
If you want to check how much your coin costs you, check out my calculator: http://tpbitcalc.appspot.com/ .
Meni Rosenfeld's formula is what you are you are looking for. It is not possible to calculate the production cost of one bitcoin because of these two variables:
E - the mining efficiency, measured in MHash/J.
c - the cost of electricity, measured in $/KWh.
There is a broad range of hardware which is not limited to GPUs - some people are mining with FPGAs for example - so you can't easily calculate the mining efficiency. The same happens with the cost of electricity because there are different prices for each country, hour of the day, residential/industrial systems, etc. And there are other factors such as the temperature (which reduces cooling costs) and alternative electricity sources (some people could be using solar panels for example).
That being said, you could grab the formula, find the average electricity price per country, estimate an average mining efficiency (maybe based on the hardware wiki list) and reach a number, but it would be very inaccurate.
I made a script with a few examples:
B = 50 D = 1500000 Cost: $0.536992840095 E = 2 c = 0.03 Cost: $2.14797136038 E = 2 c = 0.12 Cost: $3.75894988067 E = 2 c = 0.21 Cost: $0.894988066826 E = 1.2 c = 0.03 Cost: $3.5799522673 E = 1.2 c = 0.12 Cost: $6.26491646778 E = 1.2 c = 0.21 Cost: $3.5799522673 E = 0.3 c = 0.03 Cost: $14.3198090692 E = 0.3 c = 0.12 Cost: $25.0596658711 E = 0.3 c = 0.21 Cost: $0.171837708831 E = 25 c = 0.12
I chose 3 values for mining efficiency in Mhash/J: 2, 1.2 and 0.3 (the greater the better) and 3 values for electricity cost in USD: 0.03, 0.12, 0.21 (the smaller the better).
Some boards, such as the 5850, have higher efficiency but we have to consider the system as a whole so 2 is still a high value. The average price of electricity per country can be found here, but I am going to list a few examples:
- High electricity price - Ireland, Italy, Japan
- Medium electricity price - US, France, Poland
- Low electricity price - Mexico, Taiwan, Kazakhstan
Using GPUs, the value ranges from $0.5 to $25 so it's not a small interval. The last line corresponds to the price of one bitcoin produced by an FPGA with electricity cost at $0.12 per KW/h: $0.17.
As Meni Rosenfeld example indicates you can estimate the cost per coin for an individual system given you know the hashing hardware efficiency and electrical cost.
There is currently no way to estimate this for entire global network as hashing hardware and energy costs estimates.
One could use geo-location to determine the physical location from the IP of generating block and if you had a database of energy costs (even estimate per country) could get energy cost per block.
One extra complexity is that currently about 92% of blocks are created by pools so you will get the pool's IP address not the actual miner. Pool's can have miners from all over the world making it difficult to estimate cost.
It would be possible to calculate this in real time however you would need the support of miners, miner software developers, and pool operators. OpenCL library allows a miner software to query device name. If miner's returned that data to the pool operators could see what hardware is being used in realtime. If pool operators shared that data you could get an aggregate of global hardware distribution giving you the aproximate global efficiency. With that you could use data on geolocation of nodes to aproximate average energy cost and thus determine global production price per coin.