# ethmocre **Repository Path**: iiisct/ethmcore ## Basic Information - **Project Name**: ethmocre - **Description**: 以太坊 核心算法研究库 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-05-25 - **Last Updated**: 2022-06-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ethmcore ## 以太坊 核心算法研究库 ### follows > 1. There exists a seed which can be computed for each block by scanning through the block headers up until that point. 2. From the seed, one can compute a 16 MB pseudorandom cache. Light clients store the cache. 3. From the cache, we can generate a 1 GB dataset, with the property that each item in the dataset depends on only a small number of items from the cache. Full clients and miners store the dataset. The dataset grows linearly with time. 4. Mining involves grabbing random slices of the dataset and hashing them together. Verification can be done with low memory by using the cache to regenerate the specific pieces of the dataset that you need, so you only need to store the cache. ```c++ int main() { // { // "jsonrpc": "2.0", // "id": 0, // "result": [ // "0x990a7b593e4a43f203636687d3b362ea4496bd0593cddb5f6ea62aac2326ec74", // "0x3646e1f9abad7750d559c03326ae5841c98e2fff3ee4ef7e1bc354b4499c946d", // "0x000000007fffffffffffffffffffffffffffffffffffffffffffffffffffffff" // ] // } std::string sHeaderHash ="0x990a7b593e4a43f203636687d3b362ea4496bd0593cddb5f6ea62aac2326ec74"; sHeaderHash = "0x3d36e0e4bf38e352bdde11dabd8beed9da63647b69fc6dcfbac3a8d53653da8f"; std::string sSeedHash ="0x3646e1f9abad7750d559c03326ae5841c98e2fff3ee4ef7e1bc354b4499c946d"; std::string sShareTarget="0x000000007fffffffffffffffffffffffffffffffffffffffffffffffffffffff"; // test h256 hash256 seed = hash256_from_string(sSeedHash); hash256 header = hash256_from_string(sHeaderHash); hash256 boundary = hash256_from_string(sShareTarget); cout << "seed : " << hash256_to_string(seed) << endl; cout << "header : " << hash256_to_string(header) << endl; cout << "boundary : " << hash256_to_string(boundary) << endl; int epoch = find_epoch_number(seed); std::cout << "epoch : " << epoch << endl; auto start_time = timer::now(); std::shared_ptr context = get_eth_context(epoch, true); auto current_duration = double(duration_cast(timer::now() - start_time).count()); std::cout << "get_eth_context init times:" << current_duration / 1000.0 << "s" << endl; std::cout << "lightSize : " << context->light_cache_num_items * 64 / 1024.0 / 1024.0 << "MB" << endl; std::cout << "dagSize : " << (size_t)context->full_dataset_num_items * 128 / 1024.0 / 1024.0/1024.0 << "GB" << endl; std::cout << "full_dataset_num_items : " << context->full_dataset_num_items << endl; if(context->full_dataset) { cout << "full_dataset[0] : " << hash1024_to_string(context->full_dataset[0]) << endl; cout << "full_dataset[1] : " << hash1024_to_string(context->full_dataset[1]) << endl; cout << "full_dataset[2] : " << hash1024_to_string(context->full_dataset[2]) << endl; } ////////////////////////////// for PCIE(virtual) initDevice(); initEpoch_internal(context); set_header(header); uint64_t upper64OfBoundary; memcpy(&upper64OfBoundary, boundary.bytes, 8); upper64OfBoundary = __bswap_constant_64(upper64OfBoundary); std::cout << "upper64OfBoundary : " << upper64OfBoundary << endl; set_target(upper64OfBoundary); pcie_debug(); uint64_t start_nonce = 0xd1e631d90c618489; size_t iterations = 0x100; search_results sr; ethash_search(sr,start_nonce, iterations); if(sr.isfound){ std::cout << "nonce = " << sr.nonce << " result_hash = " << hash256_to_string(sr.result_hash)<< " header_hash = " << hash256_to_string(sr.header_hash) << endl; } else { std::cout << " not found!" << std::endl; } return 0; } ``` ``` seed : 0x3646E1F9ABAD7750D559C03326AE5841C98E2FFF3EE4EF7E1BC354B4499C946D header : 0x3D36E0E4BF38E352BDDE11DABD8BEED9DA63647B69FC6DCFBAC3A8D53653DA8F boundary : 0x000000007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF epoch : 415 get_eth_context init times:128.696s lightSize : 67.8746MB dagSize : 4.24218GB full_dataset_num_items : 35586017 full_dataset[0] : 0xA5F3656C41016C6335D3E0B52AA2397CAD7AE79DD67D5FB8149F58B566DAA56D85B5BF3A505DF706809AC3F8E2D7588B4D50E968A62E01811B850951BC2265D544F19C8820511367593A3F9C8AF560516D169EAD7071F0911DCA9428E2D6B73A3C4AA984DB9C8F923FB46FA9CA40E6706C234C17C415F76B0D08C409685227B0 full_dataset[1] : 0xE27AA86CA03D4D98BE1B95BB69FBDFC92A9CC7BA82160B4F7DA8D0B5CB862FB505EB941BCBD03718B293C0BE1559B2081DE6DAA555BC4E62077FBECB12772188EE5E479E15FD6D54D942D9A367470F2C99B9CC5432E7A4DC4C5CF46AFA6ABC8D08B08ACA53B54CCEEAB4ADFA3B100FCD957BDF7DD268C17897AF3D8912CAEC60 full_dataset[2] : 0xEC76CC309B5396BAD5CA21DFE321A0D40E01979A766F70DE8B572C2B73B5CA5A42B46159EEF219DDA15CECE99B4B684F642C8CC0212BA01752EE208C8DF7403938BFDA81C225D38807FB54D86049F28EEBCB55B721D1A65E9D83270EA875BA89F95FF891C503CB3351C3102A33CB5A26519D38EFD278C6591269476F7D6B42D7 upper64OfBoundary : 2147483647 d_dag[0] : 0xA5F3656C41016C6335D3E0B52AA2397CAD7AE79DD67D5FB8149F58B566DAA56D85B5BF3A505DF706809AC3F8E2D7588B4D50E968A62E01811B850951BC2265D544F19C8820511367593A3F9C8AF560516D169EAD7071F0911DCA9428E2D6B73A3C4AA984DB9C8F923FB46FA9CA40E6706C234C17C415F76B0D08C409685227B0 d_dag[1] : 0xE27AA86CA03D4D98BE1B95BB69FBDFC92A9CC7BA82160B4F7DA8D0B5CB862FB505EB941BCBD03718B293C0BE1559B2081DE6DAA555BC4E62077FBECB12772188EE5E479E15FD6D54D942D9A367470F2C99B9CC5432E7A4DC4C5CF46AFA6ABC8D08B08ACA53B54CCEEAB4ADFA3B100FCD957BDF7DD268C17897AF3D8912CAEC60 d_dag[2] : 0xEC76CC309B5396BAD5CA21DFE321A0D40E01979A766F70DE8B572C2B73B5CA5A42B46159EEF219DDA15CECE99B4B684F642C8CC0212BA01752EE208C8DF7403938BFDA81C225D38807FB54D86049F28EEBCB55B721D1A65E9D83270EA875BA89F95FF891C503CB3351C3102A33CB5A26519D38EFD278C6591269476F7D6B42D7 nonce = 15124831206855771273 final_hash = 0x0F8BC1E9863282466E4A9E1E1939AFA8CB491E1EB6F9CBBBE7B9F38D8B025E41 mix_hash = 0x3D36E0E4BF38E352BDDE11DABD8BEED9DA63647B69FC6DCFBAC3A8D53653DA8F ``` [ref]https://eth.wiki/concepts/ethash/ethash [ref]https://github.com/ethereum/ethash