Skip to content

Revert XKCP alignment sanitizer suppression#46

Merged
koko1123 merged 1 commit intomainfrom
revert/xkcp-alignment-hack
Mar 13, 2026
Merged

Revert XKCP alignment sanitizer suppression#46
koko1123 merged 1 commit intomainfrom
revert/xkcp-alignment-hack

Conversation

@koko1123
Copy link
Contributor

@koko1123 koko1123 commented Mar 13, 2026

Summary

  • Reverts commit 47f5de5 which added -fno-sanitize=alignment to XKCP C flags
  • Suppressing sanitizers is a workaround, not a fix. The underlying issue (XKCP plain64 backend casting u8* to uint64_t* without alignment guarantees) should be fixed properly — either by finding a better XKCP vendor or adding an aligned wrapper

Context

The original commit was pushed directly to main by mistake. This PR reverts it properly.

Summary by CodeRabbit

  • Chores
    • Updated build configuration to enable stricter alignment checks during compilation. This improves code quality by activating additional validation that was previously suppressed.

@vercel
Copy link

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
eth-zig Ready Ready Preview, Comment Mar 13, 2026 7:38pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Walkthrough

The build configuration simplifies C source compilation flags by removing the alignment sanitizer suppression flag from the addXkcp function, leaving only the optimization level flag active. This enables alignment checks during builds while maintaining all other build logic and target-based backend selection.

Changes

Cohort / File(s) Summary
Build Configuration
build.zig
Simplified C source compile flags in addXkcp by removing "-fno-sanitize=alignment" flag, leaving only "-O3" optimization enabled.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A flag takes flight, alignment now shines,
No more suppression in build design,
Checks run true, the rabbit hops with glee,
Cleaner code is all we see!
twitch twitch

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: removing the alignment sanitizer suppression flag from the XKCP build configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch revert/xkcp-alignment-hack
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
build.zig (1)

126-126: Revert looks correct, but note the residual alignment risk.

Removing the sanitizer suppression is the right call—masking UB isn't a fix. However, the underlying issue persists: the plain64 backend (KeccakP-1600-opt64.c) performs unaligned 64-bit loads via u8* → uint64_t* casts. This affects:

  • aarch64 builds (lines 138-142)
  • x86_64 without AVX2/AVX512 (lines 159-163)
  • All other architectures (lines 167-171)

On strict-alignment targets or when UBSan is enabled, this may cause runtime crashes or sanitizer failures. Consider tracking a follow-up issue to either:

  1. Patch the XKCP vendor to use memcpy-based loads (compiler will optimize to unaligned load intrinsics)
  2. Switch to a maintained XKCP fork that handles alignment properly

,

Would you like me to open a tracking issue for the proper XKCP alignment fix?

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@build.zig` at line 126, The revert removed sanitizer suppression but left
unsafe unaligned 64-bit loads in the XKCP backend (KeccakP-1600-opt64.c) that
cast from u8* to uint64_t* and can crash on strict-alignment targets or under
UBSan; open a tracking issue referencing KeccakP-1600-opt64.c and the
problematic casts (unaligned u8* → uint64_t* loads), propose two remediation
options (patch XKCP to use memcpy-based loads or switch to a maintained XKCP
fork that fixes alignment), and document impacted targets (aarch64, x86_64
without AVX2/AVX512, others) so we can follow up rather than reintroduce
sanitizer suppression in build.zig.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@build.zig`:
- Line 126: The revert removed sanitizer suppression but left unsafe unaligned
64-bit loads in the XKCP backend (KeccakP-1600-opt64.c) that cast from u8* to
uint64_t* and can crash on strict-alignment targets or under UBSan; open a
tracking issue referencing KeccakP-1600-opt64.c and the problematic casts
(unaligned u8* → uint64_t* loads), propose two remediation options (patch XKCP
to use memcpy-based loads or switch to a maintained XKCP fork that fixes
alignment), and document impacted targets (aarch64, x86_64 without AVX2/AVX512,
others) so we can follow up rather than reintroduce sanitizer suppression in
build.zig.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b198b537-8d3e-4d53-b885-f46377c4a1be

📥 Commits

Reviewing files that changed from the base of the PR and between 47f5de5 and e20c8d2.

📒 Files selected for processing (1)
  • build.zig

@koko1123 koko1123 merged commit d369bd0 into main Mar 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant