Subject: Re: [bitcoin-dev] reviving op_difficulty

From: Thomas Hartman <[email-masked]>
Date: Wed, 19 Aug 2020 17:15:08 -0400

> On Aug 16, 2020, at 2:59 PM, Tier Nolan via bitcoin-dev <[email-masked]> wrote:
> 
> Output 0:  Pay Alice if diff < 1.00 trillion else Bob

What is included in blocks is a packed representation of the difficulty target, not the difficulty per se as typically reported on blockchain explorer. 

https://en.bitcoin.it/wiki/Difficulty <https://en.bitcoin.it/wiki/Difficulty>

Perhaps what is best for speculation contracts is not the difficulty per se, but the ratio between some unknown future difficulty and the current difficulty. That is easily obtained from the packed representations already included in blocks. IE

Current difficulty / last difficulty = 1 / ( current target / last target )

To give a worked example, current difficulty is 16.94T, and last difficulty was 16.84T. 
Current packed target is 0x17109bac, last packed target is  0x1710b4f8	
16.94 / 16.84 is same as 1 / ( 0x109ba / 0x10b4f8  )  (the 17 is an exponent in both cases so leaving it out for clarity). 

So perhaps the way op_diff should work is take 2 packed targets, 1 known and 1 unknown at time of contract, and return the ratio. 

The contract could then work as previously described, except using the ratio for ticks instead of the difficulty.