-
Notifications
You must be signed in to change notification settings - Fork 113
pyethash C++ acceleration not supported on Python 3.13 #976
Copy link
Copy link
Open
Description
Summary
Removed pyethash (C++ ethash acceleration) from ethpow.py due to incompatibility with Python 3.13. The pure Python implementation is now the only code path.
Problem
pyethash 0.1.27 crashes with segfault or floating point exception on Python 3.13 when calling hashimoto_light().
The root cause is a bug in src/python/core.c: PyArg_ParseTuple uses "y#" format which writes Py_ssize_t (8 bytes on 64-bit) into int variables (4 bytes),
causing stack corruption.
// core.c line 76-77 (pyethash 0.1.27)
int cache_size, header_size; // BUG: should be Py_ssize_t
if (!PyArg_ParseTuple(args, "k" PY_STRING_FORMAT PY_STRING_FORMAT "K",
&block_number, &cache_bytes, &cache_size, &header, &header_size, &nonce))
This is undefined behavior — the outcome depends on compiler-generated stack layout:
┌────────────────────┬──────────┬────────┬────────────────────────────┐
│ Environment │ Compiler │ Python │ Result │
├────────────────────┼──────────┼────────┼────────────────────────────┤
│ WSL (Ubuntu 22.04) │ gcc 11.4 │ 3.13.8 │ Works (~60-100x speedup) │
├────────────────────┼──────────┼────────┼────────────────────────────┤
│ ax101 bare metal │ gcc 13.3 │ 3.13.8 │ Segfault │
├────────────────────┼──────────┼────────┼────────────────────────────┤
│ Docker (Debian) │ gcc 14.2 │ 3.13.8 │ Segfault (-O2) / FPE (-O0) │
└────────────────────┴──────────┴────────┴────────────────────────────┘
Performance Impact
Pure Python hashimoto_light is ~60-100x slower than the C++ version. This only affects PoW verification/mining performance, not consensus correctness.
Future Fix
If C++ acceleration is needed, fork https://github.com/ethereum/ethash and fix the type mismatch in src/python/core.c:
Py_ssize_t cache_size, header_size;
Related
- upstream repo: https://github.com/ethereum/ethash (unmaintained)
- pyethash PyPI: https://pypi.org/project/pyethash/Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels