spacemeshos / post

Spacemesh POST protocol implementation
MIT License
20 stars 21 forks source link

Instead of returning the first Nonce below difficulty, return the absolute lowest #90

Closed fasmat closed 1 year ago

fasmat commented 1 year ago

Summary:

The work oracle is implemented to return the index of the first hash that is below the given difficulty threshold for Pow when calculating labels.

Instead it should return the index of the hash with the lowest value between StartPosition and EndPosition. Additionally when calculating leaves in batches the Initializer should continue to look for indices where the resulting hash is lower than the one already found.

The reason for this is that instead of finding the first Nonce that satisfies the given difficulty, this finds the "best" (lowest) nonce. If a smesher decides to increase their PoST storage in the future this gives them a higher chance of being able to re-use the nonce instead of being required to search for a new one. Additionally if the lowest found nonce doesn't satisfy the difficulty for the larger PoST they can be sure no index in the PoST already calculated does.

Acceptance criteria:

Implementation hints:

noamnelke commented 1 year ago

if a nonce was found in a batch during the initialization procedure use the value of the found nonce for the next batch to look for "better" nonces

If easier to implement, can also return all nonces below threshold and use CPU to find the lowest one among those found. Should have negligible impact on performance, if at all.

fasmat commented 1 year ago

With the recent move of the initialization to OpenCL the code was updated to look for and store the absolute lowest nonce instead of the first below threshold