Skip to content
This repository was archived by the owner on Jun 8, 2025. It is now read-only.

Commit 36be977

Browse files
authored
Merge pull request #207 from chfast/remove_progpow
Remove deprecated ProgPoW implementation
2 parents 55440f9 + f9c5fba commit 36be977

20 files changed

+23
-1038
lines changed

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![readme style standard](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
44

5-
> C/C++ implementation of Ethash and ProgPoW – the Ethereum Proof of Work algorithms
5+
> C/C++ implementation of Ethash – the Ethereum Proof of Work algorithm
66
77

88
## Table of Contents
@@ -31,20 +31,16 @@ cmake --build .
3131
See [ethash.hpp] for list of exported function and documentation.
3232

3333

34-
## Test vectors
35-
36-
- [ProgPoW test vectors](test/unittests/progpow_test_vectors.hpp)
37-
38-
3934
## Optimizations
4035

41-
This section decscribes the optimizations, modification and tweaks applied
36+
This section describes the optimizations, modification and tweaks applied
4237
in this library in relation to [Ethash reference implementation].
4338

44-
The library contains a set of micro-benchmarks. Build and run `bench` tool.
39+
The library contains a set of micro-benchmarks.Build and run the `ethash-bench`
40+
tool.
4541

4642
### Seed hash is computed on the fly.
47-
43+
4844
Seed hash is sequence of keccak256 hashes applied the epoch number of times.
4945
Time needed to compute seed hash is negligible comparing to time needed to build
5046
light cache. Computing seed hash for epoch 10000 takes ~ 5 ms, building light
@@ -55,9 +51,9 @@ cache for epoch 1 takes ~ 500 ms.
5551
Computing the size of full dataset and light cache requires finding the largest
5652
prime number given an upper bound. For similar reasons as with seed hash, this
5753
is computed on the fly. The procedure used is quite naive and forks well only
58-
up to 40-bit number, so some additional improvement can be done in future.
59-
60-
54+
up to 40-bit number, so some additional improvement can be done in the future.
55+
56+
6157
## Maintainer
6258

6359
Paweł Bylica [@chfast]

include/ethash/ethash.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ struct ethash_epoch_context
6464
const int epoch_number;
6565
const int light_cache_num_items;
6666
const union ethash_hash512* const light_cache;
67-
const uint32_t* const l1_cache;
6867
const int full_dataset_num_items;
6968
};
7069

include/ethash/hash_types.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ union ethash_hash1024
3636
char str[128];
3737
};
3838

39-
union ethash_hash2048
40-
{
41-
union ethash_hash512 hash512s[4];
42-
uint64_t word64s[32];
43-
uint32_t word32s[64];
44-
uint8_t bytes[256];
45-
char str[256];
46-
};
47-
4839
#ifdef __cplusplus
4940
}
5041
#endif

include/ethash/hash_types.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ namespace ethash
1111
using hash256 = ethash_hash256;
1212
using hash512 = ethash_hash512;
1313
using hash1024 = ethash_hash1024;
14-
using hash2048 = ethash_hash2048;
1514
} // namespace ethash

include/ethash/progpow.hpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

lib/ethash/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@ set_target_properties(ethash PROPERTIES C_EXTENSIONS OFF CXX_EXTENSIONS OFF)
1111
target_link_libraries(ethash PRIVATE ethash::keccak)
1212
target_include_directories(ethash PUBLIC $<BUILD_INTERFACE:${include_dir}>$<INSTALL_INTERFACE:include>)
1313
target_sources(ethash PRIVATE
14-
bit_manipulation.h
1514
builtins.h
1615
endianness.hpp
1716
${include_dir}/ethash/ethash.h
1817
${include_dir}/ethash/ethash.hpp
1918
ethash-internal.hpp
2019
ethash.cpp
2120
${include_dir}/ethash/hash_types.h
22-
kiss99.hpp
2321
primes.h
2422
primes.c
25-
${include_dir}/ethash/progpow.hpp
26-
progpow.cpp
2723
)
2824

2925

lib/ethash/bit_manipulation.h

Lines changed: 0 additions & 81 deletions
This file was deleted.

lib/ethash/ethash-internal.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ extern "C" struct ethash_epoch_context_full : ethash_epoch_context
1717
ethash_hash1024* full_dataset;
1818

1919
constexpr ethash_epoch_context_full(int epoch, int light_num_items, const ethash_hash512* light,
20-
const uint32_t* l1, int dataset_num_items, ethash_hash1024* dataset) noexcept
21-
: ethash_epoch_context{epoch, light_num_items, light, l1, dataset_num_items},
20+
int dataset_num_items, ethash_hash1024* dataset) noexcept
21+
: ethash_epoch_context{epoch, light_num_items, light, dataset_num_items},
2222
full_dataset{dataset}
2323
{}
2424
};
@@ -51,7 +51,6 @@ void build_light_cache(hash512 cache[], int num_items, const hash256& seed) noex
5151

5252
hash512 calculate_dataset_item_512(const epoch_context& context, int64_t index) noexcept;
5353
hash1024 calculate_dataset_item_1024(const epoch_context& context, uint32_t index) noexcept;
54-
hash2048 calculate_dataset_item_2048(const epoch_context& context, uint32_t index) noexcept;
5554

5655
namespace generic
5756
{

lib/ethash/ethash.cpp

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
#include "ethash-internal.hpp"
66

7-
#include "bit_manipulation.h"
87
#include "primes.h"
98
#include <ethash/keccak.hpp>
10-
#include <ethash/progpow.hpp>
119
#include <cstdlib>
1210
#include <cstring>
1311

@@ -30,7 +28,15 @@ static_assert(full_dataset_item_size == ETHASH_FULL_DATASET_ITEM_SIZE, "");
3028

3129
namespace
3230
{
33-
using ::fnv1;
31+
/// The core transformation of the FNV-1 hash function.
32+
/// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1_hash.
33+
NO_SANITIZE("unsigned-integer-overflow")
34+
inline uint32_t fnv1(uint32_t u, uint32_t v) noexcept
35+
{
36+
static const uint32_t fnv_prime = 0x01000193;
37+
return (u * fnv_prime) ^ v;
38+
}
39+
3440

3541
inline hash512 fnv1(const hash512& u, const hash512& v) noexcept
3642
{
@@ -133,8 +139,7 @@ epoch_context_full* create_epoch_context(
133139
const int full_dataset_num_items = calculate_full_dataset_num_items(epoch_number);
134140
const size_t light_cache_size = get_light_cache_size(light_cache_num_items);
135141
const size_t full_dataset_size =
136-
full ? static_cast<size_t>(full_dataset_num_items) * sizeof(hash1024) :
137-
progpow::l1_cache_size;
142+
full ? static_cast<size_t>(full_dataset_num_items) * sizeof(hash1024) : 0;
138143

139144
const size_t alloc_size = context_alloc_size + light_cache_size + full_dataset_size;
140145

@@ -146,23 +151,18 @@ epoch_context_full* create_epoch_context(
146151
const hash256 epoch_seed = calculate_epoch_seed(epoch_number);
147152
build_fn(light_cache, light_cache_num_items, epoch_seed);
148153

149-
uint32_t* const l1_cache =
150-
reinterpret_cast<uint32_t*>(alloc_data + context_alloc_size + light_cache_size);
151-
152-
hash1024* full_dataset = full ? reinterpret_cast<hash1024*>(l1_cache) : nullptr;
154+
hash1024* const full_dataset =
155+
full ? reinterpret_cast<hash1024*>(alloc_data + context_alloc_size + light_cache_size) :
156+
nullptr;
153157

154158
epoch_context_full* const context = new (alloc_data) epoch_context_full{
155159
epoch_number,
156160
light_cache_num_items,
157161
light_cache,
158-
l1_cache,
159162
full_dataset_num_items,
160163
full_dataset,
161164
};
162165

163-
auto* full_dataset_2048 = reinterpret_cast<hash2048*>(l1_cache);
164-
for (uint32_t i = 0; i < progpow::l1_cache_size / sizeof(full_dataset_2048[0]); ++i)
165-
full_dataset_2048[i] = calculate_dataset_item_2048(*context, i);
166166
return context;
167167
}
168168
} // namespace generic
@@ -227,24 +227,6 @@ hash1024 calculate_dataset_item_1024(const epoch_context& context, uint32_t inde
227227
return hash1024{{item0.final(), item1.final()}};
228228
}
229229

230-
hash2048 calculate_dataset_item_2048(const epoch_context& context, uint32_t index) noexcept
231-
{
232-
item_state item0{context, int64_t(index) * 4};
233-
item_state item1{context, int64_t(index) * 4 + 1};
234-
item_state item2{context, int64_t(index) * 4 + 2};
235-
item_state item3{context, int64_t(index) * 4 + 3};
236-
237-
for (uint32_t j = 0; j < full_dataset_item_parents; ++j)
238-
{
239-
item0.update(j);
240-
item1.update(j);
241-
item2.update(j);
242-
item3.update(j);
243-
}
244-
245-
return hash2048{{item0.final(), item1.final(), item2.final(), item3.final()}};
246-
}
247-
248230
namespace
249231
{
250232
using lookup_fn = hash1024 (*)(const epoch_context&, uint32_t);

0 commit comments

Comments
 (0)