Skip to content

crypto/keccak: vendor in golang.org/x/crypto/sha3#33323

Merged
lightclient merged 5 commits intoethereum:masterfrom
fjl:crypto-keccak-vendoring
Feb 3, 2026
Merged

crypto/keccak: vendor in golang.org/x/crypto/sha3#33323
lightclient merged 5 commits intoethereum:masterfrom
fjl:crypto-keccak-vendoring

Conversation

@fjl
Copy link
Copy Markdown
Contributor

@fjl fjl commented Nov 28, 2025

The upstream libray has removed the assembly-based implementation of keccak. We need to maintain our own library to avoid a peformance regression.

Copy link
Copy Markdown
Member

@gballet gballet left a comment

Choose a reason for hiding this comment

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

Should both go.mod not be updated in order to remove the reference to the other package?

@fjl
Copy link
Copy Markdown
Contributor Author

fjl commented Nov 30, 2025

We use some other packages from golang.org/x/crypto still

@rvagg
Copy link
Copy Markdown

rvagg commented Dec 2, 2025

Since go-ethereum isn't the only project impacted by this (Filecoin is too, there's likely many more), perhaps a separate repo to maintain the extracted package would be good? It could even be a shared concern among those of us that depend on it so we can collectively maintain it.

@cuiweixie
Copy link
Copy Markdown
Contributor

will this be merged?

@cuiweixie
Copy link
Copy Markdown
Contributor

any update? fork golang.org/x/crypto/sha3 or using this vendor?

@fjl
Copy link
Copy Markdown
Contributor Author

fjl commented Jan 21, 2026

Sorry for the non-progress. I have considered it a bit more, and we could make another repository for this code. For most crypto code used by Ethereum, we vendored the implementation into the repo because it makes it easier to pin to a very specific version and perform security fixes. It seems less necessary to vendor it here for sha3 because it is very stable.

However, creating a fork repo would have the downside that someone has to be the maintainer of it. I'm not looking forward to being that person. I'd honestly be fine if go-ethereum just had its own copy that we never have to touch until Go changes the assembler interface again.

@fjl
Copy link
Copy Markdown
Contributor Author

fjl commented Jan 21, 2026

@Kubuxu @rvagg wdyt?

@rvagg
Copy link
Copy Markdown

rvagg commented Jan 22, 2026

@fjl I was about to pull the trigger on putting one in the filecoin-project org, it'd be more prominent if it lived in the ethereum org--you'd be more likely to have downstream users of it, and you'd get other contributors showing up to update things as interfaces break of Go versions need updating etc. Of course that creates its own burden. We have a bunch of automated tooling to keep various things like Go version, linting etc. updated that we'd plug in, but as you said, I wouldn't expect much churn for sha3. Happy to go either way on this but we're probably not vendoring it in to individual codebases because we have a few separate ones that'll need it.

rvagg added a commit to filecoin-project/go-f3 that referenced this pull request Jan 28, 2026
… x/crypto

Replace all usage of golang.org/x/crypto/sha3.NewLegacyKeccak256() with
github.com/filecoin-project/go-keccak, which vendors the assembly-optimised
Keccak permutation from x/crypto@v0.43.0. Starting with x/crypto v0.44.0,
the upstream package removed its amd64 assembly in favor of Go's standard
library crypto/sha3, which does not provide an assembly fast path for
legacy Keccak functions.

With the keccak dependency decoupled, upgrade golang.org/x/crypto to v0.47.0.

Ref: #1055
Ref: filecoin-project/lotus#13443
Ref: ethereum/go-ethereum#33323
rvagg added a commit to filecoin-project/lotus that referenced this pull request Jan 28, 2026
… x/crypto

Replace all usage of golang.org/x/crypto/sha3.NewLegacyKeccak256() with
github.com/filecoin-project/go-keccak, which vendors the assembly-optimised
Keccak permutation from x/crypto@v0.43.0. Starting with x/crypto v0.44.0,
the upstream package removed its amd64 assembly in favor of Go's standard
library crypto/sha3, which does not provide an assembly fast path for
legacy Keccak functions.

With the keccak dependency decoupled, upgrade golang.org/x/crypto to v0.47.0.

Ref: filecoin-project/go-f3#1055
Ref: #13443
Ref: ethereum/go-ethereum#33323
rvagg added a commit to filecoin-project/lotus that referenced this pull request Jan 28, 2026
… x/crypto

Replace all usage of golang.org/x/crypto/sha3.NewLegacyKeccak256() with
github.com/filecoin-project/go-keccak, which vendors the assembly-optimised
Keccak permutation from x/crypto@v0.43.0. Starting with x/crypto v0.44.0,
the upstream package removed its amd64 assembly in favor of Go's standard
library crypto/sha3, which does not provide an assembly fast path for
legacy Keccak functions.

With the keccak dependency decoupled, upgrade golang.org/x/crypto to v0.47.0.

Ref: filecoin-project/go-f3#1055
Ref: #13443
Ref: ethereum/go-ethereum#33323
rvagg added a commit to filecoin-project/lotus that referenced this pull request Jan 28, 2026
… x/crypto

Replace all usage of golang.org/x/crypto/sha3.NewLegacyKeccak256() with
github.com/filecoin-project/go-keccak, which vendors the assembly-optimised
Keccak permutation from x/crypto@v0.43.0. Starting with x/crypto v0.44.0,
the upstream package removed its amd64 assembly in favor of Go's standard
library crypto/sha3, which does not provide an assembly fast path for
legacy Keccak functions.

With the keccak dependency decoupled, upgrade golang.org/x/crypto to v0.47.0.

Ref: filecoin-project/go-f3#1055
Ref: #13443
Ref: ethereum/go-ethereum#33323
rvagg added a commit to filecoin-project/lotus that referenced this pull request Jan 28, 2026
… x/crypto

Replace all usage of golang.org/x/crypto/sha3.NewLegacyKeccak256() with
github.com/filecoin-project/go-keccak, which vendors the assembly-optimised
Keccak permutation from x/crypto@v0.43.0. Starting with x/crypto v0.44.0,
the upstream package removed its amd64 assembly in favor of Go's standard
library crypto/sha3, which does not provide an assembly fast path for
legacy Keccak functions.

With the keccak dependency decoupled, upgrade golang.org/x/crypto to v0.47.0.

Ref: filecoin-project/go-f3#1055
Ref: #13443
Ref: ethereum/go-ethereum#33323
@rvagg
Copy link
Copy Markdown

rvagg commented Jan 28, 2026

@fjl we set up a package with the code extracted, coupled up to our CI to keep it fresh: https://github.com/filecoin-project/go-keccak, you're welcome to use it if you like.
Drop in for us @ filecoin-project/lotus#13477 & filecoin-project/go-f3#1064 so far.

rvagg added a commit to filecoin-project/lotus that referenced this pull request Jan 29, 2026
… x/crypto (#13477)

Replace all usage of golang.org/x/crypto/sha3.NewLegacyKeccak256() with
github.com/filecoin-project/go-keccak, which vendors the assembly-optimised
Keccak permutation from x/crypto@v0.43.0. Starting with x/crypto v0.44.0,
the upstream package removed its amd64 assembly in favor of Go's standard
library crypto/sha3, which does not provide an assembly fast path for
legacy Keccak functions.

With the keccak dependency decoupled, upgrade golang.org/x/crypto to v0.47.0.

Ref: filecoin-project/go-f3#1055
Ref: ethereum/go-ethereum#33323
Closes: #13476
Closes: #13443
rvagg added a commit to filecoin-project/go-f3 that referenced this pull request Jan 29, 2026
… x/crypto (#1064)

Replace all usage of golang.org/x/crypto/sha3.NewLegacyKeccak256() with
github.com/filecoin-project/go-keccak, which vendors the assembly-optimised
Keccak permutation from x/crypto@v0.43.0. Starting with x/crypto v0.44.0,
the upstream package removed its amd64 assembly in favor of Go's standard
library crypto/sha3, which does not provide an assembly fast path for
legacy Keccak functions.

With the keccak dependency decoupled, upgrade golang.org/x/crypto to v0.47.0.

Closes: #1055
Ref: filecoin-project/lotus#13443
Ref: ethereum/go-ethereum#33323
@fjl fjl removed the status:triage label Feb 3, 2026
fjl added 3 commits February 3, 2026 09:42
The upstream libray has removed the assembly-based implementation of keccak.
We need to maintain our own library to avoid a peformance regression.
@lightclient lightclient force-pushed the crypto-keccak-vendoring branch from b02ab37 to bac1bda Compare February 3, 2026 16:42
@lightclient
Copy link
Copy Markdown
Member

lightclient commented Feb 3, 2026

After further discussion, we decided to vendor it into go-ethereum. Ultimately, keccak is an important dependency for us and we want to stay on top of it. Sorry @rvagg for being so indecisive.

--

Was able to verify that keccakf.go, keccakf_amd64.go, keccakf_amd64.s, and sha3.go are identical matches to golang.org/x/crypto@v0.43.0, the version right before the asm was removed.

$ gh api "repos/golang/crypto/contents/sha3/keccakf.go?ref=v0.43.0" --jq '.content' | base64 -d > /tmp/upstream_keccakf.go
$ gh api "repos/golang/crypto/contents/sha3/keccakf_amd64.go?ref=v0.43.0" --jq '.content' | base64 -d > /tmp/upstream_keccakf_amd64.go
$ gh api "repos/golang/crypto/contents/sha3/keccakf_amd64.s?ref=v0.43.0" --jq '.content' | base64 -d > /tmp/upstream_keccakf_amd64.s
$ gh api 'repos/golang/crypto/contents/sha3/sha3.go?ref=v0.43.0' --jq '.content' | base64 -d > /tmp/upstream_sha3.go

$ diff -u /tmp/upstream_keccakf_amd64.go crypto/keccak/keccakf_amd64.go
$ diff -u /tmp/upstream_keccakf_amd64.s crypto/keccak/keccakf_amd64.s
$ diff -u /tmp/upstream_legacy_keccakf.go crypto/keccak/keccakf.go
$ diff -u /tmp/upstream_sha3.go crypto/keccak/sha3.go

The hashes.go and sha3_test.go just consists of deletions of unrelated sha3 code.

$ gh api "repos/golang/crypto/contents/sha3/hashes.go?ref=v0.43.0" --jq '.content' | base64 -d > /tmp/upstream_hashes.go
$ gh api "repos/golang/crypto/contents/sha3/sha3_test.go?ref=v0.43.0" --jq '.content' | base64 -d > /tmp/upstream_sha3_test.go

$ diff -u /tmp/upstream_hashes.go crypto/keccak/hashes.go
$ diff -u /tmp/upstream_sha3_test.go crypto/keccak/sha3_test.go

You can check that the asm optimization is still working by running:

go test ./crypto/keccak/... -bench=. -benchmem -count=5 | tee bench_asm.txt
go test -tags=purego ./crypto/keccak/... -bench=. -benchmem -count=5 | tee bench_purego.txt
benchstat bench_purego.txt bench_asm.txt

And all internal uses were successfully ported to our vendored packaged.

$ grep -r 'golang.org/x/crypto/sha3' --include='*.go' .
$

@lightclient lightclient added this to the 1.17.0 milestone Feb 3, 2026
@lightclient lightclient merged commit 8e1de22 into ethereum:master Feb 3, 2026
7 of 8 checks passed
rjan90 pushed a commit to filecoin-project/lotus that referenced this pull request Feb 5, 2026
… x/crypto (#13477)

Replace all usage of golang.org/x/crypto/sha3.NewLegacyKeccak256() with
github.com/filecoin-project/go-keccak, which vendors the assembly-optimised
Keccak permutation from x/crypto@v0.43.0. Starting with x/crypto v0.44.0,
the upstream package removed its amd64 assembly in favor of Go's standard
library crypto/sha3, which does not provide an assembly fast path for
legacy Keccak functions.

With the keccak dependency decoupled, upgrade golang.org/x/crypto to v0.47.0.

Ref: filecoin-project/go-f3#1055
Ref: ethereum/go-ethereum#33323
Closes: #13476
Closes: #13443
gzliudan pushed a commit to gzliudan/XDPoSChain that referenced this pull request Feb 10, 2026
The upstream libray has removed the assembly-based implementation of
keccak. We need to maintain our own library to avoid a peformance
regression.

---------

Co-authored-by: lightclient <lightclient@protonmail.com>
gzliudan pushed a commit to gzliudan/XDPoSChain that referenced this pull request Feb 11, 2026
The upstream libray has removed the assembly-based implementation of
keccak. We need to maintain our own library to avoid a peformance
regression.

---------

Co-authored-by: lightclient <lightclient@protonmail.com>
gzliudan pushed a commit to gzliudan/XDPoSChain that referenced this pull request Feb 11, 2026
The upstream libray has removed the assembly-based implementation of
keccak. We need to maintain our own library to avoid a peformance
regression.

---------

Co-authored-by: lightclient <lightclient@protonmail.com>
@Sahil-4555
Copy link
Copy Markdown

Since we’re maintaining a vendored keccak now, has anyone looked at fastkeccak?
It seems to provide additional optimizations. Might be worth benchmarking against the current vendored sha3 implementation.

gzliudan pushed a commit to gzliudan/XDPoSChain that referenced this pull request Feb 28, 2026
The upstream libray has removed the assembly-based implementation of
keccak. We need to maintain our own library to avoid a peformance
regression.

---------

Co-authored-by: lightclient <lightclient@protonmail.com>
AnilChinchawale pushed a commit to XinFinOrg/XDPoSChain that referenced this pull request Feb 28, 2026
…2046)

The upstream libray has removed the assembly-based implementation of
keccak. We need to maintain our own library to avoid a peformance
regression.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: lightclient <lightclient@protonmail.com>
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.

7 participants