Code Monkey home page Code Monkey logo

ethash's Introduction

Ethash

readme style standard GitPOAP Badge

C/C++ implementation of Ethash – the Ethereum Proof of Work algorithm

Table of Contents

Install

Build from source using CMake.

mkdir build
cd build
cmake ..
cmake --build .

Usage

See ethash.hpp for a list of exported functions and documentation.

Optimizations

This section describes the optimizations, modifications and tweaks applied in this library in relation to Ethash reference implementation.

The library contains a set of micro-benchmarks.Build and run the ethash-bench tool.

Seed hash is computed on the fly.

Seed hash is a sequence of keccak256 hashes applied the epoch number of times. Time needed to compute seed hash is negligible compared to time needed to build light cache. Computing seed hash for epoch 10000 takes ~ 5 ms, building light cache for epoch 1 takes ~ 500 ms.

Dataset size is computed on the fly

Computing the size of the full dataset and light cache requires finding the largest prime number given an upper bound. For similar reasons as with seed hash, this is computed on the fly. The procedure used is quite naive and forks well only up to 40-bit number, so some additional improvement can be done in the future.

Maintainer

Paweł Bylica @chfast

License

Licensed under the Apache License, Version 2.0.

ethash's People

Contributors

axic avatar chfast avatar ethercoreadmin avatar gumb0 avatar jyap808 avatar kayla-henrie avatar omahs avatar samwilsn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ethash's Issues

WASI Build steps

Can you provide some more detail on the commands needed to get the WASI build to compile? I installed the WASI SDK following the steps from the circle.yml section on WASI and also just tried cmake -DTOOLCHAIN=wasm32-wasi and it doesn't compile anything. I'm completely new to cmake and compiling anything to WASM and have spent a fair bit of time trying to understand how to do this but nothing seems to work.

can't compile on 32 bits

openSUSE Tumbleweed, gcc 9.2.1

[ 39%] Building C object test/integration/compilation/CMakeFiles/test-compile-c90.dir/__/__/__/lib/ethash/keccak.c.o
cd /home/abuild/rpmbuild/BUILD/ethash-0.4.4/build/test/integration/compilation && /usr/bin/cc  -I/home/abuild/rpmbuild/BUILD/ethash-0.4.4/include  -fomit-frame-pointer -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=6 -g -DNDEBUG -O2 -g -DNDEBUG   -pedantic -Werror -Wall -Wextra -Wconversion -Wsign-conversion -Wno-unknown-pragmas -fno-stack-protector -Wimplicit-fallthrough -mtune=generic -std=c90 -o CMakeFiles/test-compile-c90.dir/__/__/__/lib/ethash/keccak.c.o   -c /home/abuild/rpmbuild/BUILD/ethash-0.4.4/lib/ethash/keccak.c
/home/abuild/rpmbuild/BUILD/ethash-0.4.4/lib/ethash/keccak.c: In function 'keccak':
/home/abuild/rpmbuild/BUILD/ethash-0.4.4/lib/ethash/keccak.c:89:5: error: integer constant is too large for 'long' type [-Werror=long-long]
   89 |     state[(block_size / word_size) - 1] ^= 0x8000000000000000;
      |     ^~~~~
cc1: all warnings being treated as errors

Upload 0.9.0-alpha.0 to PyPi

@chfast Hello!

I want to upload a new package version (0.9.0-alpha.0) on PyPi.
I made a fork of the repository with following changes: andrei-kondakov@633cdc7.

I renamed the package name to ethash2 in my fork and add myself as maintainer of this package. I did not change the author parameter, you are still listed there. Is it okay?

I want to use this package on ubuntu 20.04 later.
I'm creating a wheel on a Mac (m1) and got following error during upload to pypi:

(venv) andrei@m1 ethash % pip install twine              
...
(venv) andrei@m1 ethash % python setup.py bdist_wheel    
....
(venv) andrei@m1 ethash % twine upload -r testpypi dist/*
Uploading distributions to https://test.pypi.org/legacy/
InvalidDistribution: Unknown distribution format: 'include'

Can u tell me how you published the package on PyPI?

Thank you!

search() is not useful

The search() function is not useful, because it does not return the mix and final hash. Extend result type with nonce and return it from search().

complete pow in python from eth_getwork or mining.notify to golden nonce

Hi,
I am trying to understand ethash algo to make a cache and dag and pow to get the final golden nonce and hash.
I found some reference implementations in go language, but i am not familier with it.
is it possible to get a setp by step func or logic to get complete pow including dag generation logic and cache generation logic in python or c with actual blockheader or from block-explorer.

for mining here is so far i understand.
->pool will send a seed hash from which we need to determine block number.
-> from block number generate cache and dag
->pow(this i dont understand how it interacts with dag)

Roadmap

  • Add README file.
  • Cross-compile for mips64.
  • Add support for big-endian.
  • Add CI.
  • Add code coverage.
  • Build with asserts.
  • CMake: add install.
  • CMake: export config.
  • Switch to C only API.
  • Add C++ wrapper for C API.
  • Add 32-bit builds (Windows, linux?)
  • Test with sanitizers on CIs
  • Switch to UBSan from clang.
  • Export keccack.
  • Add PowerPC build.
  • Extend UBSan build with clang 6.
  • Build with PGO.

Get hash boundary from difficulty

A nice to have feature would be to have the computation of hash256 boundary from the difficulty value as specified in block header

How to add ECIP-1099 here?

I want to make a Python package for verifying an ETC mining shares.

Tried to integrate ECIP-1099: https://ecips.ethereumclassic.org/ECIPs/ecip-1099
I looked at the repository which already tried to do this: https://github.com/etclabscore/cpp-etchash
My same attemp here: andrei-kondakov@2699d03

Etclabscore and my solution don't work on this case of real mining ETC share:

  • height - 14790284
  • nonce - 0x4f29c0e5dc784d8b
  • mining_hash - 0x32d6c83f7fc493aa224a8fcc3ac007e6113d28ed70717e7d5a7505d72d4bdd7f
  • mix_hash - 0xb27518ae34f7e81c56a4dedb81df93c4d4301d90643678044b3445ded0b331ce
  • final_hash - 000000016454ac15829b7d6158f4be151ba9a9aa42e905153c7c43f211decb9f
import unittest

import ethash


class TestEthash(unittest.TestCase):
    epoch_number = 493 # (we used old epoch here: 493 like in ETH?, real is 246)
    nonce = 0x4f29c0e5dc784d8b
    header_hash = bytes.fromhex(
        '32d6c83f7fc493aa224a8fcc3ac007e6113d28ed70717e7d5a7505d72d4bdd7f')
    mix_hash = bytes.fromhex(
        'b27518ae34f7e81c56a4dedb81df93c4d4301d90643678044b3445ded0b331ce')
    final_hash = bytes.fromhex(
        '000000016454ac15829b7d6158f4be151ba9a9aa42e905153c7c43f211decb9f')

    def test_hash(self):
        f, m = ethash.hash(self.epoch_number, self.header_hash, self.nonce)
        print(f.hex()) # <- 8a678cdfc607962405f0f543b9a3a046072079d197b4e364be04f2cd175ab31f
        print(m.hex()) # <- 3d93eb7ff453d852bf95e98e6c73ab92f64628a7c1e3f3b4110f80970a0af96d
        self.assertEqual(m, self.mix_hash) # fail
        self.assertEqual(f, self.final_hash) # fail

Whats wrong here? How to integrate ECIP-1099 correctly?
Thanks!

There are a problem with the file encoding type in ethash~

I am studying "aleth" in "windows 10 pro" environment.
However, I am worried about the following error during the build.

"C:.hunter_Base\c4cfcc0\e941b8e\402d68a\Build\ethash\Source\lib\ethash\progpow.cpp"
Since this file(progpow.cpp) is only UTF-8 encoded, the following error occurs.
All other files are ANSI encoded.
Please correct this problem.


[hunter ** FATAL ERROR **] Build step failed (dir: C:/.hunter/_Base/c4cfcc0/e941b8e/402d68a/Build/ethash
[hunter ** FATAL ERROR **] [Directory:C:/.hunter/_Base/Download/Hunter/0.23.44/c4cfcc0/Unpacked/cmake/projects/ethash]

Return codes on ethash::verify method

Actually method verify only returns true if verification is success or false otherwise.

Would be nice to have a return code instead to assert

  • 0 verification ok
  • 1 bad nonce / over boundary
  • 2 mismatching mix hash

setup.py issue

When trying to install on python, I get this error:

Creating library build\temp.win32-3.9\Release\build\temp.win32-3.9\Release\_ethash.lib and object build\temp.win32-3.9\Release\build\temp.win32-3.9\Release\_ethash.exp
_ethash.obj : error LNK2001: unresolved external symbol _ethash_keccak512
_ethash.obj : error LNK2001: unresolved external symbol _ethash_hash
_ethash.obj : error LNK2001: unresolved external symbol _ethash_verify_against_boundary
_ethash.obj : error LNK2001: unresolved external symbol _ethash_keccak256
_ethash.obj : error LNK2001: unresolved external symbol _ethash_get_global_epoch_context
build\lib.win32-3.9\_ethash.pyd : fatal error LNK1120: 5 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x86\\link.exe' failed with exit code 1120

Could anyone help me out?

need to updates README.md on win64 builds

I have try to build this repository, in win10.

cmake .. 
cmake --build .

has several error or link errors.

So, I've tried following way , on ethminer builds.

cmake .. -G "Visual Studio 15 2017 Win64" -T v140
cmake --build . --config Release

will compile well for generate library.

Verify against difficulty

The final hash verification is

final_hash <= 2^256 / difficulty

The current verify() API takes boundary = 2^256 / difficulty instead of difficulty. The boundary is commonly used in mining for efficiency. However, for block hash verification this is not optimal because clients have to compute 2^256 / difficulty inversion for every block hash.

We propose to add additional function which takes difficulty argument directly: verify_against_difficulty().
Internally, we can perform much more efficient check:

final_hash * difficulty <= 2^256

This has been tested and the formula is also valid for difficulty 0 and 1.

We also propose to rename verify() to verify_against_boundary() to disambiguate.
And change verify_final_hash() to verify_final_hash_against_difficulty() as this function is suppose to be used for quick block hash verification.

The generated cache is different from that generated in go-ethereum

In build_light_cache() function, the address of variable `cache' changes in each loop
for (int i = 0; i < num_items; ++i)
{
const uint32_t index_limit = static_cast<uint32_t>(num_items);

        // Fist index: 4 first bytes of the item as little-endian integer.
        const uint32_t t = le::uint32(cache[i].word32s[0]);
        const uint32_t v = t % index_limit;

        // Second index.
        const uint32_t w = static_cast<uint32_t>(num_items + (i - 1)) % index_limit;

        cache[i] = keccak512(bitwise_xor(cache[v], cache[w]));
    }

In particular, for i=0, cache[0] is the first element of array cache (as expected). However, for i=1, cache[0] is the second element of array cache, and for i=2, cache[0] is the third element of array cache, ...
By observing the address of cache, I found that the address of cache changes each time when arriving at
" const uint32_t t = le::uint32(cache[i].word32s[0]);".

As a result, the generated cache is different from that generated in go-ethereum.

cant compile on centos

CMake Error at CMakeLists.txt:229 (message):
Failed to determine the source files for the regular expression backend

-- Configuring incomplete, errors occurred!
See also "/home/IC/.hunter/_Base/18e57a4/c197bbe/5c48e6d/Build/benchmark/Build/benchmark-Release-prefix/src/benchmark-Release-build/CMakeFiles/CMakeOutput.log".
See also "/home/IC/.hunter/_Base/18e57a4/c197bbe/5c48e6d/Build/benchmark/Build/benchmark-Release-prefix/src/benchmark-Release-build/CMakeFiles/CMakeError.log".
gmake[2]: *** [benchmark-Release-prefix/src/benchmark-Release-stamp/benchmark-Release-configure] Error 1
gmake[1]: *** [CMakeFiles/benchmark-Release.dir/all] Error 2
gmake: *** [all] Error 2

[hunter ** FATAL ERROR **] Build step failed (dir: /home/IC/.hunter/_Base/18e57a4/c197bbe/5c48e6d/Build/benchmark
[hunter ** FATAL ERROR **] [Directory:/home/IC/.hunter/_Base/Download/Hunter/0.23.224/18e57a4/Unpacked/cmake/projects/benchmark]

------------------------------ ERROR -----------------------------
https://docs.hunter.sh/en/latest/reference/errors/error.external.build.failed.html

CMake Error at /home/IC/.hunter/_Base/Download/Hunter/0.23.224/18e57a4/Unpacked/cmake/modules/hunter_error_page.cmake:12 (message):
Call Stack (most recent call first):
/home/IC/.hunter/_Base/Download/Hunter/0.23.224/18e57a4/Unpacked/cmake/modules/hunter_fatal_error.cmake:20 (hunter_error_page)
/home/IC/.hunter/_Base/Download/Hunter/0.23.224/18e57a4/Unpacked/cmake/modules/hunter_download.cmake:617 (hunter_fatal_error)
/home/IC/.hunter/_Base/Download/Hunter/0.23.224/18e57a4/Unpacked/cmake/projects/benchmark/hunter.cmake:32 (hunter_download)
/home/IC/.hunter/_Base/Download/Hunter/0.23.224/18e57a4/Unpacked/cmake/modules/hunter_add_package.cmake:62 (include)
test/benchmarks/CMakeLists.txt:5 (hunter_add_package)

-- Configuring incomplete, errors occurred!
See also "/home/IC/ethash/test/chfast/ethash/build/CMakeFiles/CMakeOutput.log".
See also "/home/IC/ethash/test/chfast/ethash/build/CMakeFiles/CMakeError.log".

how to use it in my project

When I link the libethash.a ,I get the following errors
/usr/bin/ld: //usr/local/lib/libethash.a(ethash.cpp.o): relocation R_X86_64_32 against `__gxx_personality_v0' can not be used when making a shared object; recompile with -fPIC
//usr/local/lib/libethash.a: error adding symbols: Bad value

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.