Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Epirme #713

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Fix Epirme #713

wants to merge 3 commits into from

Conversation

feiqihang
Copy link
Contributor

I think the result of x/y should be a prime number.

I think the result of x/y should be a prime number.
@feiqihang
Copy link
Contributor Author

feiqihang commented Aug 4, 2018

To this end, I specifically looked at the source code of the go-ethereum project and the ethereumj project.
go-ethereum/consensus/ethash/algorithm.go:

// calcCacheSize calculates the cache size for epoch. The cache size grows linearly,
// however, we always take the highest prime below the linearly growing threshold in order
// to reduce the risk of accidental regularities leading to cyclic behavior.
func calcCacheSize(epoch int) uint64 {
	size := cacheInitBytes + cacheGrowthBytes*uint64(epoch) - hashBytes
	for !new(big.Int).SetUint64(size / hashBytes).ProbablyPrime(1) { // Always accurate for n < 2^64
		size -= 2 * hashBytes
	}
	return size
}

org.ethereum.mine.EthashParams:

    /**
     * The parameters for Ethash's cache and dataset depend on the block number.
     * The cache size and dataset size both grow linearly; however, we always take the highest
     * prime below the linearly growing threshold in order to reduce the risk of accidental
     * regularities leading to cyclic behavior.
     */
    public long getCacheSize(long blockNumber) {
        long sz = CACHE_BYTES_INIT + CACHE_BYTES_GROWTH * (blockNumber / EPOCH_LENGTH);
        sz -= HASH_BYTES;
        while (!isPrime(sz / HASH_BYTES)) {
            sz -= 2 * HASH_BYTES;
        }
        return sz;
    }

@vasilevskykv
Copy link

I would like to ask one more question. Why in function PoW, construction sum from i=0 to nmix is used?
The term sh(h,n) doesn't depend on i. And we can calculate that nmix = 128/64 = 2. Thus, we can write not the sum, but 3 sh(h,n)

Fix the SHA3 instruction gas calculation in Gas Cost function.
Fix the SHA3 instruction gas calculation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants