Tuesday, November 21, 2017

Best difficulty algorithms

# Tom Harold (Degnr8) "wt-144" 
# Modified by Zawy to be Weighted, weighted Harmonic Mean (WWHM)
# Zawy-selected N=30 and timestamp handling for all coins.
# No limits in rise or fall rate should be employed.
# MTP should not be used

# set constants
T=600 # (target solvetime)
adjust=0.98 # 0.98 for N=30
k = (N+1)/2 *adjust * T

# algorithm
d=0, t=0, j=0
for i = height - N+1 to height  # (N most recent blocks)
solvetime = TS[i] - TS[i-1] 
solvetime = 7*T if solvetime > 7*T
solvetime = -6*T if solvetime < -6*T
    t +=  solvetime * j 
    d +=D[i]
next i
t=T if t < T # in case of startup weirdness, keep t reasonable
next_D = d * k / t 
and apparently better and amazing in that there's not even a loop or looking at old data:


# Jacob Eliosoff  EMA (exponential moving average)
# ST = previous solvetime
# N=15 (Zawy-selected)
# MTP should not be used

ST = previous timestamp - timestamp before that
ST = max(T/50,min(T*10, ST))
next_D = previous_D * ( T/ST + e^(-ST/T/N) * (1-T/ST) )

Saturday, November 18, 2017

Richard Bach quotes (modified)

If you love someone, set them free. If they come back, they're yours; if they don't, they never were.

If your happiness depends on what someone else does then you have a problem.

One of the great cosmic laws, I think, is that whatever we hold in our thought will come true in our experience. When we hold something, anything, in our thought, then somehow coincidence leads us in the direction that we've been wishing to lead ourselves.

Our soulmate is the one that brings life to life.

True love stories never have an ending.

Monday, November 13, 2017

Maximizing options as the basis of memory-less intelligence

There seems to be some big news in A.I. and cosmology. To give an example of how far-reaching this idea is, view walking upright and the ability to use our hands as something that maximizes our options rather than something that gives us more power in any other sense. This simple algorithm can be most of us at apparently any Atari game without any training at all, other than defining "maximize future options" for a given set of rules.

Ted Talk

General idea:

How it's good at playing atari without training:

On freedom in society making us more powerful:

Basic physics of causal entropy and intelligence

How it can predict the cosmological constant by following the anthropic principle:

Wednesday, November 1, 2017

Why Degnr8's WT difficulty algorithm is the best

I previously said difficulty is not open to debate or opinion. By this
I mean a scientific measurement should be followed by a mathematical
calculation. We should measure current hashrate and then
mathematically set difficulty based on that to get the desired average
solvetime. The only discussion (debate and opinion) needed is to
determine how to make the measurement and how to do the math. This
coincidentally provides the perfect protection to hash attacks and
delays (unless you change the Poisson by shifting consensus from POW
to better time restrictions set by the nodes, i.e. Andrew Stone's

The difficulty math should be: difficulty = 600 * hashrate. Hashrate
= current difficulty / current solvetime. This part is not open for
debate. The problem is determining current hashrate because the only
way to measure it is to see the network response to current
difficulty, and it's current difficulty that we're looking for. (I
should mention schancel has an idea on how to get a true "current
hashrate", but as with long tail and block reward adjustment I
consider it "for the future"). So the best we can do is to base the
math on the hashrate on the previous difficulty. The problem is
random variation. What observations and math should we use to
estimate current hash rate? This is open for debate, but it's not
debatable in a sense because there should be some provable optimum.

With this background I want to "prove" Degnr8's WT with low N is the
optimal formula. Bitcoin measures avg hashrate of past 2 weeks of
blocks by using the perfectly correct next_D = sum (D) / sum(solvetimes)
times a proportionality constant. So it is measuring hashrate as it
was 1 week in the past, and only adjusts once every two weeks.
(Hashrate = difficulty times a proportionality constant)
Obviously this is not the best measure of current hashrate. So,
everyone started using the same equation, but applying it every block
and using a smaller N. There have been many attempts to improve this
math, but every attempt I am aware of made it worse. The amount of
time wasted trying to improvement it is incredible. They go by a lot
of fancy names. They often apply a "filter" to try to reduce the
"noise", but they don't understand that the random variation is not
real noise that has a forcing function that needs to be filtered out
with something analogous to a capacitor and/or inductor on an
electrical signal. It can be noisy from miners jumping on and off or
from network effects, but we have no way to estimate the nature of
that noise in order to justify a specific filter design. The random
variation is, as far as we can measure, precise data that needs to be
included. Devs will also hurt the incontrovertible math by making
asymmetrical changes such as preventing negative timestamps. They have
their reasoning processes, but their reasoning is not as good as the
required math.

The simple average with low N is the state of the art. But it
has a problem: it is measuring the hashrate as it was N/2 blocks into
the past. Lower N helps, but there starts to be accidental variation
that causes longer delays. Fear of this is greatly exaggerated.
Filters do not help because the end result is not as good as just
going to a longer N. Degnr8's algo does not address the tradeoff
between faster response and accidental changes in difficulty that
occurs with low N. But by letting the weighting factor for the blocks
linearly reduce as they get further in the past, he's made possibly
the best possible measurement of the hashrate as it stood in the
PREVIOUS block rather than looking at N/2. There might be a slightly
more complex equation to make it a little more accurate, but if it
overestimates what the previous, current, or future block hashrates
are, it will send it into oscillations by overshooting, leaving it
open to exploit that amplifies the oscillations. Industrial process
controllers (PID controllers) do something better, but they depend on
the process being stable in its characteristic, not something like
miners seeking profit and thereby able to change how they react to the
controller. In other words diff algos can't try to predict the future
hashrate. The best they can do is estimate what the hashrate was in
the previous block. In watching Degnr8's WT respond to step
functions, it is a very linear increase. This is the hallmark of a
controller that is NOT trying to predict the future. It responds
faster than the simple equation, but does not overshoot or undershoot
in any sense.

This is the basis for me claiming there is no alternative to using
Degnr8's TW. The only thing to quibble over is the setting of N. I'm
down for 30. I'm working on getting an exposition of what it looks
like when small alts use N=16, 30, and 63.

Saturday, October 21, 2017

bits field relation to hashing and difficulty

In the block explorer you can see a "bits" field determines the difficulty that can be compared between all coins. It is a compact form of the maximum value the hash of the block header must have before nodes will accept the miner's hash. A miner's job is to hash until he can find a hash that is less than the hash value stated in the bits field. The difficulty algorithm sets the bits field value. In HUSH's block 190703 the bits field is 1d 08 ec fa. The 1d in decimal is 29, which means the max hash value is 29 bytes long. The 08 ec fa gives the value of the first 3 of those 29 bytes. The rest of them are 00. If you convert those 1st three to decimal and multiple that by 256^(29-3) it is 2.4E68. The hash of a block header is 32 bytes long, which can take on 2^32 = 1.15E77 different values. The miner's job is to keeping hashing, changing the nonce field between each hash (with a starting point given to him by the pool) to get a different hash each time, until he finds a 32 byte hash that is below that 2.4E68 number. 2.4E68 is 481 million tmies less than 1.16E77. So the miner has to hash that many times in 150 seconds to have a 50% chance of winning. 481 / 150 = 3.21 million hashes per second, which was the network hashrate during that block. The difficulty in hush-cli as you said was 239 M. 2^1 * 239 / 150 = 3.19 M Hashes/s network rate. For some reason, in Zcash replace the 2^1 with 2^13.

Friday, October 20, 2017

Blockchain timestamps, difficulty, and the stars.

posted to Zcash github:

Any upper limit you apply to timestamps should be reflected in a lower limit. For example, you could follow the rule that the next timestamp is limited to +/- 750 seconds from the previous timestamp +150 seconds (+900 / -600). If you don't allow the "negative" timestamp (-600 from previous timestamp) AND if miners can assign timestamps without a real-time limit from nodes, then a miner with > 20% of the network hashrate can drive the difficulty as low as he wants, letting everyone get blocks as fast as he wants, in less than a day.

A symmetrical limit on timestamps allows honest miner timestamps to completely erase the effect of bad timestamps. ( You do not need to wait 6 blocks for MTP like Zcash does in delaying the use of timestamps for difficulty, see footnote. ) If you allow the symmetrical "negative" timestamps, you do not need nodes to have the correct time with NTP or GPS unless miners collude with > 51% agreement on setting the timestamps further and further ahead of time to drive difficulty down. It's a real possibility if miners decide they do not like a certain fork due to not providing them with enough fees.

But if your nodes have an accurate time, you do not need mining at all. The only fundamental reason for mining is to act as a timestamp server to prevent double spending.

BTC and ETH depend on nodes to limit the future time assigned to blocks. This seems like a bad joke. Zooko was the only one here who seemed to know there is something fishy about strong reliance on nodes having the correct time. The extent to which BTC and ETH need those forward-time limits to be enforced by real time is the extent to which they do not need mining.

Since gmaxwell (and apparently Satoshi) reject the idea of relying on state-sponsored and crash-able GPS, NTP, or cellphone systems to eliminate the need for miners, the ideal solution is to have nodes that use a camera with a good zoom, known location, and accelerometer (if their camera is a cell phone not correctly mounted) to determine star position and to periodically calibrate their time based on that. @fluffypony was the only one I could get to "like" this idea on twitter. Every honest desktop node could reject transactions with bad timestamps, within some small window like 1 minute (with good optics). Science like this does not need to ask for consensus. Every node on his own could give the middle finger to every node that disagrees with him. Nodes with correct time would naturally comprise the biggest network, all saying F-you to the miners. Blocks could be 2 minutes apart and need only 1 confirmation. Science began with looking at the stars and time is the only thing I can think of that computers can determine in isolation and then agree on without a trusted 3rd party. Colluding miners bullying us with > 51% hashrate into more total fees at the expense of security is a trusted 3rd party.

MTP does not stop a 25% attacker who can set timestamps > 4 blocks ahead if other miners are not allowed to assign a "negative" timestamp to eliminate the error in the next block. But if you allow the "negatives" then MTP is not needed. Putting your tempering aside, this assumes you use

next_D = avg(D's) * T / avg(solvetimes, allowing negative solvetime)
instead of

next_D=sum(D's) * T / [max(Timestamps) - min(Timestamps) ]
because the N's of the denominator and number of the first equation do not cancel like you would think and hope (in order to use the second equation) when there are bad timestamps at the beginning and end of the window. With the MTP, your difficulty is delayed 5 blocks in responding to big ETH miners who jump on about twice a day. That's like a gift to them at the expense of your constant miners.

Also, your tempered N=17 gives almost the same results as a straight average N=63. I would use N=40 instead, without the tempering. It should reduce the cheap blocks the big ETH miners are getting.

Your 16% / 32% limits are rarely reached due to the N=63 slowness. This is good because it is a symmetry problem, although it would not be as bad as BCH. Use "limit" and "1/limit" where limit = X^(2/N) where N=63 for your current tempering and X = the size of the larger ETH attackers as a fraction of your total hashrate, which is about 3. This allows the the fastest response up or down at N for a given X with 80% probability. Change the 2 to 3 to get a higher probability of an adequately-fast response. The benefit is that it is a really loose timestamp limit on individual values, as long as the aggregate is not too far from the expected range.

Wednesday, October 18, 2017

Hold coins w/ nLocktime (or burn) as a source of price appreciation (via velocity theory of money)

post to HUSH chat:

Now I see we can't even charge HUSH fees for sending email because if the value increases a lot it will be too expensive. to email. Is it possible for the protocol to measure the swap rate between dollars and HUSH? If yes, then that seems to be a way you could charge say $0.0025 per tx output plus $0.000001 per tx byte . I'm allergic to blockchain bloat. You could burn 1/3 for price appreciation, send 1/3 to devs, and 1/3 to miners. If you don't burn HUSH (or enforcing holding times), what is the market incentive to increase its value if Zcash and other alts are going to attract most of the people seeking an anonymous store of value? There's a similar problem when spending HUSH for XHCP. How is XHCP automatically lowering in HUSH price so that you don't have to fork when HUSH increases 10x? Is burning some of that HUSH the only sure way to get market appreciation? Instead of burning in both cases you could require an nLocktime holding time to enforce the velocity theory of money. Previously I mentioned putting a locktime on the HUSH (for XHCP) before it can be spent, so devs can't spend it right away, giving a contuned work motivation just like stocks. But now I see it has a price appreciation effect. Dollars have value because they are being HELD in many places. It's not merely for savings, but as a requirement of doing business. But in a blockchain that is not being used to make purchases for goods or services in order to get other goods and services that have shipping and production times, there is no hold time. True, XHCP is a service, but if this "gas" should have a constant value, then the exchange rate between it and HUSHJ should fluctuate and in doing so, it removes the incentive to hold HUSH. As a speculator, I would have to trust the devs to hold their HUSH. That trust seems to be the primary source of objective (aka real aka justified) price appreciation.
Are there coins requiring a hold time on transactions as a source of price appreciation? I previously described making receivers also hold HUSH in order to receive but that seems to make it complicated without benefit. In this simpler holding time scheme, the sender would be required to send an amount of HUSH (determined by dollar or commodity basket exchange rate) with a locktime on it to himself.