Skip to content

pyethash C++ acceleration not supported on Python 3.13 #976

@ping-ke

Description

@ping-ke

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 behaviorthe outcome depends on compiler-generated stack layout:

┌────────────────────┬──────────┬────────┬────────────────────────────┐
│    EnvironmentCompilerPythonResult           │
├────────────────────┼──────────┼────────┼────────────────────────────┤
│ WSL (Ubuntu 22.04) │ gcc 11.43.13.8Works (~60-100x speedup)   │
├────────────────────┼──────────┼────────┼────────────────────────────┤
│ ax101 bare metalgcc 13.33.13.8Segfault                   │
├────────────────────┼──────────┼────────┼────────────────────────────┤
│ Docker (Debian)    │ gcc 14.23.13.8Segfault (-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/

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions