bitcoin core – How a real mining code treats difficulty?

The difficulty is really a human readable expression. Under the hood, the Bitcoin protocol uses the target. The target is a custom 4-byte float value encoding an exponent and a mantissa that is to represent a number used as the upper bound for the block hash of valid blocks.

The target is updated every 2016 blocks after the last block of a difficulty period has been found. It depends on the timestamps of the first and the last block of the difficulty period and the previous target:

new_target = old_target × (t_last - t_first)/14 days

Every full node that has seen these two blocks can calculate the new target.

Miners assemble unconfirmed transactions into block templates, create coinbase transactions and fill up the remaining header fields to produce block candidates, test each block candidate by hashing its header and comparing the candidate’s hash to the target to determine whether a block has been found. The current target since height 693,504 is 0x17136aa2 which is a compact representation for 0x000000000000000000136aa20000000000000000000000000000000000000000. If I counted right, this hexadecimal number would translate to a binary number with 75 leading zeroes. At the current hashrate of about 109.7 EH/s, the network will try about 6.6×1022 block candidates until a block is found.

Would Bitcoin still work without a target difficulty?

Suppose that Bitcoin nodes had no target difficulty at all, and instead just accepted the block with the largest PoW every 10 minutes. Ignoring the increased bandwidth (since nodes would be broadcasting several block candidates), would this work? Or is there some technical need for an adjustable target difficulty?

difficulty – How much Bitcoin did I mine in December 2013?

You can go to https://en.bitcoin.it/wiki/Non-specialized_hardware_comparison for a table of mining performance of many different CPUs and GPUs. The GT650M is reported as doing 17.8 Mhash/s; let’s round it up to 20. There is a range of values for various Core i5 CPUs from 5 to 20 Mhash/s; let’s be generous and call it 20 also. So you were mining at a combined rate of say 40 Mhash/s; in scientific notation that’s 4.0e7 hash per second. You mined for 28 days which is 2.4e6 seconds, so you performed a total of 9.6e13 hashes.

Next we need to know the mining difficulty around that time. There is a chart at Blockchain.info. It was increasing rapidly during that time but in early December it was around 707,000,000, or 7.1e8. Each 1 unit of difficulty corresponds to 2^32 = 4.3e9 hashes needed to mine one block. So at that time, it took about 3.0e18 hashes to mine one block.

As such, you would expect to have mined 9.6e13 / 3.0e18 = 3.2e-5 blocks. The block reward at that time was 25 BTC per block (see https://en.bitcoin.it/wiki/Controlled_supply) and so you would have earned, on average, BTC 8e-4, or in other words BTC 0.0008.

At today’s exchange rate of USD 6149 per bitcoin, that is worth just under USD 5.00.

This is of course an average, or expected value. If you were mining for a pool, this may or may not have been enough to actually earn a payout. If you were solo mining, you would have had to mine a full block worth BTC 25; the probability that you did so is about 3.2e-5.

blockchain fork – Choosing main chain based on difficulty

If a node observes a fork in the bitcoin chain, then the node will choose the chain that has the highest difficulty (sum of difficulty in each block of the chain).

But the difficulty changes only once every 2016 blocks. So, if a fork occurs somewhere in between, then the difficulty is the same for both the side chains right? How does the node pick the main chain then? Just randomly?

c# – How do i set conditions for an IF statement as the game progress through “difficulty”?

It looks like your approach should more or less work. It seems like there are probably two different situations where you will need to consider difficulty in your game.

1.) Increase/Decrease probability with regards to difficulty.

private IEnumerator SpawnFallingRockRoutine()
{
    while (playing)
    {
        float spawnCooldown = Mathf.Lerp(minSpawnRate, maxSpawnRate, Difficulty.GetCurrentDifficulty());
        // spawn falling rock logic
        yield return new WaitForSeconds(spawnCooldown);
    }
}

2.) Trigger events only if at a certain difficulty.

private IEnumerator EvilMonkeySpawnRoutine()
{
    while (playing)
    {
        float cooldown = 1.0f;
        if (Difficulty.GetCurrentDifficulty() >= evilMonkeyDifficulty)
        {
            // spawn evil monkey
            cooldown = evilMonkeyCooldown;
        }

        yield return cooldown;
     }
}

You may also want to change how your Difficulty class works to make it a bit more extendable in your project:

public class Difficulty
{
    private static float maxDifficultyTime = 30.0f;
    private static float gameStartTime = 0.0f;
    private static float difficultyIncreaseRate = 1.0f;
    private static float difficultyBump = 0.0f;

    public static void SetStartTime(float time)
    {
        gameStartTime = time;
    }

    // Use if you want to make the game temporarily harder
    public static void BumpUpDifficulty(float increase)
    {
        difficultyBump += increase;
    }

    // Use if you want to make the game temporarily easier
    public static void BumpDownDifficulty(float decrease)
    {
        difficultyBump -= decrease;
    }

    // Gets current difficulty in range of 0.0 - 1.0
    public static float GetCurrentDifficulty()
    {
        return Mathf.Clamp01(GetCurrentDifficultyUnclamped());
    }

    // Get current difficulty in range of min - max
    public static float GetCurrentDifficultyClamped(float minDifficulty, float maxDifficulty)
    {
        return Mathf.Clamp(GetCurrentDifficultyUnclamped(), minDifficulty, maxDifficulty);
    }

    // Gets the raw current difficulty (careful with this one)
    public static float GetCurrentDifficultyUnclamped()
    {
        return difficultyBump + (Time.time - gameStartTime) * (difficultyIncreaseRate / maxDifficultyStartTime);
    }
}

    

difficulty – Why does the Genesis block appear to have a lower hash than necessary?

The hash of the genesis block of bitcoin has two extra 0 as compared to other block hashes. According to the logic, it should have been the same as they all have the same difficulty. Why is it so? Was any special reason for doing so?

Hash of genesis block :
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

Hash of block 1 :
00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048

Hash of block 2 :
000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd

difficulty – Different hash of genesis block

The hash of the genesis block of bitcoin has two extra 0 as compared to other block hashes. According to the logic, it should have been the same as they all have the same difficulty. Why is it so? Was any special reason for doing so?

Hash of genesis block :
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

Hash of block 1 :
00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048

Hash of block 2 :
000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd

dnd 5e – How does fighting underwater increase the encounter difficulty of combat?

It might increase the difficulty of the encounter one step.

There is some guidance in the encounter design section of the Dungeon Master’s Guide that is relevant here:

Increase the difficulty of the encounter by one step (from easy to medium, for example) if the characters have a drawback that their enemies don’t. Reduce the difficulty by one step if the characters have a benefit that their enemies don’t. Any additional benefit or drawback pushes the encounter one step in the appropriate direction. If the characters have both a benefit and a drawback, the two cancel each other out.

In your scenario, if none of the party have a swim speed, the encounter taking place under water would definitely count as a drawback here for the purposes of estimating encounter difficulty. The Chuul, having a swim speed will find underwater combat to be as easy as combat out of water, your party however, will be at a disadvantage:

When making a melee weapon attack, a creature that doesn’t have a swimming speed (either natural or granted by magic) has disadvantage on the attack roll unless the weapon is a dagger, javelin, shortsword, spear, or trident.

A ranged weapon attack automatically misses a target beyond the weapon’s normal range. Even against a target within normal range, the attack roll has disadvantage unless the weapon is a crossbow, a net, or a weapon that is thrown like a javelin (including a spear, trident, or dart).

On the other hand, if the party would be mostly unimpeded by fighting underwater (by everyone having a swimming speed), fighting underwater would not affect the encounter difficulty at all.

tails of equestria – Should I tell players the difficulty of checks?

I’ll be running Tails of Equestria with my daughter and her friend soon. (For reference, I’ve previously played D&D 5e before and DMed it a little, including with children.)

Should the PCs be told the difficulty of checks they make?

I never would in D&D, and the main reason I’m wondering whether it’s done in TOE is the sections on Exploding Hoof and ponies helping each other.

What is the reason for limiting the maximum factor by which difficulty can change?

Is there a security reason for limiting the difficult adjustment to a factor of 4?