Skip to content

keccak: Rework absorption of the final input bytes - #1620

Merged
chfast merged 1 commit into
masterfrom
chfast/keccak-tail-no-memcpy
Aug 9, 2026
Merged

keccak: Rework absorption of the final input bytes#1620
chfast merged 1 commit into
masterfrom
chfast/keccak-tail-no-memcpy

Conversation

@chfast

@chfast chfast commented Aug 8, 2026

Copy link
Copy Markdown
Member

In the Keccak input processing loop, rework the code handling the last
0–7 bytes of input and the padding byte. The new code is not
spectacularly better than the old one, but it fixes edge case where
a compiler may decide to replace the old code with memcpy call.

@chfast
chfast force-pushed the chfast/keccak-tail-no-memcpy branch from aa25d86 to f332889 Compare August 8, 2026 23:02
@chfast
chfast requested a lite review from Copilot August 8, 2026 23:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes Keccak input absorption for the final partial (1–7 byte) tail by constructing the last word via shifts instead of a byte-copy loop that GCC may recognize and lower into a small-size memcpy() call (notably affecting some RISC-V targets and zkVM cost models).

Changes:

  • Replace the byte-by-byte tail copy into a stack uint64_t (and subsequent to_le64() swap) with a shift/OR construction of the partial word plus padding byte.
  • Keep the Keccak padding behavior the same by placing 0x01 at byte index size and XORing into the next state lane.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.46%. Comparing base (8cc8e36) to head (87b4530).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1620      +/-   ##
==========================================
- Coverage   97.46%   97.46%   -0.01%     
==========================================
  Files         170      170              
  Lines       15402    15395       -7     
  Branches     3604     3604              
==========================================
- Hits        15012    15005       -7     
  Misses        282      282              
  Partials      108      108              
Flag Coverage Δ
eest-develop 88.33% <100.00%> (-0.02%) ⬇️
eest-develop-gmp 25.74% <100.00%> (-0.04%) ⬇️
eest-legacy 17.33% <100.00%> (-0.04%) ⬇️
eest-libsecp256k1 27.88% <100.00%> (-0.04%) ⬇️
eest-stable 88.29% <100.00%> (-0.02%) ⬇️
evmone-unittests 93.00% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
core 95.98% <100.00%> (-0.01%) ⬇️
tooling 90.42% <ø> (ø)
tests 99.80% <ø> (ø)
Files with missing lines Coverage Δ
lib/evmone_precompiles/keccak.c 99.09% <100.00%> (-0.03%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chfast
chfast force-pushed the chfast/keccak-tail-no-memcpy branch from f332889 to c2e3966 Compare August 9, 2026 10:16
In the Keccak input processing loop, rework the code handling the last
0–7 bytes of input and the padding byte. The new code is not
spectacularly better than the old one, but it fixes edge case where
a compiler may decide to replace the old code with memcpy call.
@chfast
chfast force-pushed the chfast/keccak-tail-no-memcpy branch from c2e3966 to 87b4530 Compare August 9, 2026 10:29
@chfast chfast changed the title keccak: Absorb the final partial word without a byte copy keccak: Rework absorption of the final input bytes Aug 9, 2026
@chfast
chfast requested a lite review from Copilot August 9, 2026 10:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@chfast
chfast merged commit 426c4da into master Aug 9, 2026
24 checks passed
@chfast
chfast deleted the chfast/keccak-tail-no-memcpy branch August 9, 2026 10:44
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.

2 participants