Skip to content

crypto/blake2b: run long F calls in preemptible chunks - #2490

Open
kamuikatsurgi wants to merge 2 commits into
upstream-merge-v1.17.4from
kamuikatsurgi/blake2f-preemptible-chunks
Open

kamuikatsurgi wants to merge 2 commits into
upstream-merge-v1.17.4from
kamuikatsurgi/blake2f-preemptible-chunks

Conversation

@kamuikatsurgi

Copy link
Copy Markdown
Member

Summary

Port of ethereum/go-ethereum#35550. On amd64 the blake2F precompile ran all of its rounds inside a single non-preemptible assembly call, with the round count taken from calldata. F now hands calls with more than 4090 rounds to fLong, which keeps the working vector in memory and runs the rounds in chunks through a new fAVX2Rounds entry point, so the goroutine can be preempted between chunks. 4090 is a multiple of the ten-round message schedule. Machines without AVX2 use the generic Go implementation for those long calls. Tracked in POS-3760.

Executed tests

  • go test ./crypto/blake2b on arm64, and GOARCH=amd64 go vet / cross-build.
  • Differential tests against fGeneric across chunk boundaries (TestFChunkedMatchesGeneric) and a preemption test (TestFLongRoundsIsPreemptible).
  • Under Rosetta with AVX2 advertised: old implementation vs this one, identical output for every round count from 0 to 19,999 plus random larger values, and an independent RFC 7693 reference up to 2^32-1 rounds.
  • Still to do: native amd64 AVX2 run; CI on this PR is the first native run. The preemption test is timing based and may need attention if it is noisy on CI.

Rollout notes

Consensus-sensitive code (the output must stay byte-identical), so it needs careful review and native amd64 validation before merge. No behaviour change is intended and no hardfork gate is needed. The upstream PR was still open and unreviewed when this was written.

Port of ethereum/go-ethereum#35550. F calls with more than 4090 rounds run the assembly rounds in chunks, so the goroutine can be preempted between them. The output is unchanged.
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.18519% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.62%. Comparing base (0348dbf) to head (f2b8c83).
⚠️ Report is 1 commits behind head on upstream-merge-v1.17.4.

Files with missing lines Patch % Lines
crypto/blake2b/blake2bAVX2_amd64.go 80.95% 3 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (85.18%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@                    Coverage Diff                     @@
##           upstream-merge-v1.17.4    #2490      +/-   ##
==========================================================
- Coverage                   56.62%   56.62%   -0.01%     
==========================================================
  Files                         944      944              
  Lines                      175181   175206      +25     
==========================================================
+ Hits                        99194    99203       +9     
- Misses                      69997    70008      +11     
- Partials                     5990     5995       +5     
Files with missing lines Coverage Δ
crypto/blake2b/blake2b.go 87.67% <100.00%> (+0.23%) ⬆️
crypto/blake2b/blake2b_generic.go 89.33% <100.00%> (ø)
crypto/blake2b/blake2bAVX2_amd64.go 88.57% <80.95%> (-11.43%) ⬇️

... and 18 files with indirect coverage changes

Files with missing lines Coverage Δ
crypto/blake2b/blake2b.go 87.67% <100.00%> (+0.23%) ⬆️
crypto/blake2b/blake2b_generic.go 89.33% <100.00%> (ø)
crypto/blake2b/blake2bAVX2_amd64.go 88.57% <80.95%> (-11.43%) ⬇️

... and 18 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kamuikatsurgi
kamuikatsurgi marked this pull request as ready for review October 13, 2026 17:51

@claude claude Bot 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.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@kamuikatsurgi

Copy link
Copy Markdown
Member Author

@claude review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Consensus-sensitive AVX2 assembly still requires mandatory native validation, and the tests can currently pass without exercising it.

1 open finding
What changed in this PR

Makes long BLAKE2b precompile calls preemptible while preserving consensus output.

Changes:

  • Chunks long AVX2 compression calls into 4,090-round segments.
  • Falls back to generic Go without AVX2.
  • Adds differential and preemption tests.
File Description
crypto/​blake2b/​blake2bAVX2_amd64.s Adds chunkable AVX2 round assembly.
crypto/​blake2b/​blake2bAVX2_amd64.go Implements chunked long-call processing.
crypto/​blake2b/​blake2b.go Selects the long-call path above the threshold.
crypto/​blake2b/​blake2b_ref.go Adds the generic long-call fallback.
crypto/​blake2b/​blake2b_generic.go Centralizes the schedule-cycle constant.
crypto/​blake2b/​blake2b_f_test.go Adds correctness and preemption tests.

🧠 Review effort: Balanced


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

Comment on lines +47 to +48
func TestFChunkedMatchesGeneric(t *testing.T) {
r := rand.New(rand.NewSource(1))

@claude claude Bot 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.

Code review found no issues

No high-confidence issues detected in this change.

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