{"record":{"id":"245e51bebb73fa57","repo":"ethereum/go-ethereum","slug":"libsecp256k1-internal-consistency-check-failed","errorCode":null,"errorMessage":"[libsecp256k1] internal consistency check failed: %s\\n","messagePattern":"\\[libsecp256k1\\] internal consistency check failed: (.+?)\\\\n","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crypto/secp256k1/libsecp256k1/src/util.h","lineNumber":104,"sourceCode":"\ntypedef struct {\n    void (*fn)(const char *text, void* data);\n    const void* data;\n} secp256k1_callback;\n\nstatic SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback * const cb, const char * const text) {\n    cb->fn(text, (void*)cb->data);\n}\n\n#ifndef USE_EXTERNAL_DEFAULT_CALLBACKS\nstatic void secp256k1_default_illegal_callback_fn(const char* str, void* data) {\n    (void)data;\n    fprintf(stderr, \"[libsecp256k1] illegal argument: %s\\n\", str);\n    abort();\n}\nstatic void secp256k1_default_error_callback_fn(const char* str, void* data) {\n    (void)data;\n    fprintf(stderr, \"[libsecp256k1] internal consistency check failed: %s\\n\", str);\n    abort();\n}\n#else\nvoid secp256k1_default_illegal_callback_fn(const char* str, void* data);\nvoid secp256k1_default_error_callback_fn(const char* str, void* data);\n#endif\n\nstatic const secp256k1_callback default_illegal_callback = {\n    secp256k1_default_illegal_callback_fn,\n    NULL\n};\n\nstatic const secp256k1_callback default_error_callback = {\n    secp256k1_default_error_callback_fn,\n    NULL\n};\n\n","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/ethereum/go-ethereum/blob/6bb0588ad8e7f922e4ad5580f51265a4097af08f/crypto/secp256k1/libsecp256k1/src/util.h#L86-L122","documentation":"This is libsecp256k1's default error callback, invoked from CHECK/CHECK_BREAK internal consistency macros when an invariant inside the library itself fails (as opposed to ARG_CHECK for caller arguments). The default handler prints the message and abort()s. Seeing it means either a library bug, an ABI mismatch (e.g. struct sizes changed between the header and the linked library), or heap corruption caused by the host application.","triggerScenarios":"Struct layout mismatch from mixing headers of one libsecp256k1 version with a shared library of another; buffer overflows in caller code corrupting secp256k1's scratch/context memory; rarely, genuine internal bugs on extreme/adversarial inputs; building with inconsistent SECP256K1_ build flags across translation units.","commonSituations":"Upgrading libsecp256k1 without a full rebuild of dependents (stale objects linking old struct layouts); race conditions where one thread destroys a context another still uses; FFI bindings whose struct mirroring drifted from the C source.","solutions":["Do a clean rebuild of the library and ALL code that includes its headers so layouts match","Run the failing program under ASan/valgrind to catch host-side memory corruption feeding bogus state into the library","Verify one single version of headers and library is on the include/link path (ldd, include order)","If it reproduces with a minimal self-contained case on the latest release, report upstream with the CHECK message text"],"exampleFix":"# before\n# app built against system headers, linked against local older .so\ncc app.c -I/usr/include -L./build -lsecp256k1   # layout mismatch -> consistency check abort\n\n# after\ncc app.c -I./libsecp256k1/include -L./libsecp256k1/build -Wl,-rpath,./libsecp256k1/build -lsecp256k1","handlingStrategy":"validation","validationCode":"/* Prevent the common causes before they reach the library */\n_Static_assert(sizeof(secp256k1_ecdsa_signature) == 64, \"ABI mismatch: rebuild all objects against the same headers\");\n/* and always check buffer sizes at the boundary */\nif (output_len < 33) return -1;","typeGuard":null,"tryCatchPattern":"/* abort() cannot be caught; contain it instead:\n   - build a minimal reproducer,\n   - run under ASan/valgrind to find the heap corruption,\n   - crash-log (corefile/backtrace) and restart the process */","preventionTips":["Rebuild the library and every dependent translation unit together after any header/version change","Run integration tests under ASan to catch host-side corruption that later manifests as CHECK failures","Keep exactly one libsecp256k1 version on include and link paths; verify with ldd and preprocessor dumps"],"tags":["secp256k1","c","abort","abi-mismatch","memory-corruption"],"backgroundTag":null,"analyzedSha":"6bb0588ad8e7f922e4ad5580f51265a4097af08f","analyzedAt":"2026-08-15T10:06:53.996Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}