Commit graph

289 commits

Author SHA1 Message Date
Daniel Liu
99749a2381
feat(crypto): use the ziren keccak precompile and implement ziren keccak state #32816 #32996 (#1991)
* feat(crypto): use the ziren keccak precompile #32816

Uses the go module's `replace` directive to delegate keccak computation
to precompiles.

This is still in draft because it needs more testing. Also, it relies on
a PR that I created, that hasn't been merged yet.

_Note that this PR doesn't implement the stateful keccak state
structure, and it reverts to the current behavior. This is a bit silly
since this is what is used in the tree root computation. The runtime
doesn't currently export the sponge. I will see if I can fix that in a
further PR, but it is going to take more time. In the meantime, this is
a useful first step_

* feat(crypto): implement ziren keccak state #32996

The #32816 was only using the keccak precompile for some minor task.
This PR implements a keccak state, which is what is used for hashing the
tree.

---------

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
2026-02-05 14:43:53 +05:30
Daniel Liu
934c8d0679
perf(all): use big.Int.Sign() to compare with 0 (#1969) 2026-02-05 11:45:44 +05:30
Daniel Liu
e77ac510d0
all: replace Div/Mul with Rsh/Lsh if possible #29911 (#1966) 2026-01-29 11:31:58 +05:30
Daniel Liu
03da570aca
crypto/ecies: use aes blocksize (#1946)
Co-authored-by: lightclient <lightclient@protonmail.com>
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2026-01-19 11:25:15 +05:30
wit liu
ea3a55aef4
all: fix invalid directive syntax for golangci-lint nolint (#1799) 2025-12-08 13:02:54 +05:30
wit liu
733b6e2b37
crypto: validate hash length in nocgo Sign #33104 (#1773) 2025-11-14 20:10:48 +05:30
Daniel Liu
241a5b3fb2
all: using testing.B.Loop (#1554)
* p2p: using testing.B.Loop

* core/state: using testing.B.Loop

* eth: using testing.B.Loop

* log: using testing.B.Loop

* core: using testing.B.Loop

* core/vm: using testing.B.Loop

* core/types: using testing.B.Loop

* crypto: using testing.B.Loop
2025-09-24 07:59:48 +08:00
Daniel Liu
2826b1e9c0
crypto/bn256: switch to gnark again #32659 (#1552)
We recently update our default implementation to gnark in
https://github.com/ethereum/go-ethereum/pull/32024
Then we found a consensus issue and reverted it in
65d77c5129
We fixed the consensus issue and have been fuzzing it more since then in
https://github.com/ethereum/go-ethereum/pull/32055/files
https://github.com/ethereum/go-ethereum/pull/32065
https://github.com/ethereum/go-ethereum/pull/32055/files

So I think now is the time to update it back to gnark

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
2025-09-24 07:48:52 +08:00
wit liu
d9ae317a38
all: format golang files (#1548)
Co-authored-by: wit <wit765765346@gmail>
2025-09-21 19:41:54 +08:00
wit765
e4fd044fa0
crypto: fix unknown linters (#1488)
Co-authored-by: wit <wit765765346@gmail>
2025-09-12 14:45:26 +08:00
Daniel Liu
c7f17cb300
crypto/bn256: refactor to use bitutil.TestBytes #32435 (#1436)
Co-authored-by: cui <cuiweixie@gmail.com>
2025-09-06 17:15:07 +08:00
Daniel Liu
57612d9826
crypto/secp256k1: use ReadBits from common/math #32430 (#1435)
Co-authored-by: cui <cuiweixie@gmail.com>
2025-09-06 17:14:33 +08:00
Daniel Liu
9cad0a0cc0
all: create global hasher pool #31769 (#1233)
This PR creates a global hasher pool that can be used by all packages.
It also removes a bunch of the package local pools.

It also updates a few locations to use available hashers or the global
hashing pool to reduce allocations all over the codebase.
This change should reduce global allocation count by ~1%

---------

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2025-08-20 15:11:09 +08:00
Daniel Liu
6b31dedf03
crypto/bn256/gnark: align marshaling behavior #32065 (#1231)
Aligns the marshaling behavior of gnark to google and cloudflare

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: kevaundray <kevtheappdev@gmail.com>
2025-08-20 15:09:36 +08:00
Daniel Liu
9f360824a9
crypto/bn256: add documentation on subgroup checks for G2 #32066 (#1232)
This PR improves the IsOnCurve methods for BN254 G2 points by:

* Clarifying its behavior the docstring, making it explicit that it
verifies both the point being on the curve and in the correct subgroup.

* Adding an in-line comment explaining the subgroup membership check
(c.Mul(Order)).

 * Minor wording adjustments for readability and consistency.

Co-authored-by: Antonio Sanso <antonio.sanso@gmail.com>
2025-07-26 17:41:09 +08:00
Daniel Liu
f5ad8091e2
crypto/bn256/cloudflare: pull in upstream fix for R27 and R29 usage #32057 (#1229)
Pulls in https://github.com/cloudflare/bn256/pull/48 to remove usage of
R27 and R29 [which are reserved](https://go.dev/doc/asm#arm64).

Co-authored-by: Stephen Buttolph <stephen@avalabs.org>
2025-07-26 17:39:28 +08:00
Daniel Liu
0fd51f13a1
tests/fuzzers: added bn marshaling fuzzers #32053 (#1228)
Adds marshaling fuzzing for G1 and G2 to oss-fuzz.

Also aligns the behavior of the google library to that of gnark and
cloudflare, which only ever read the first 64 / 128 bytes of the input,
regardless of how long the input is

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
2025-07-26 17:36:58 +08:00
Daniel Liu
f30a126380
crypto/bn256: fix gnark deserialisation #32055 (#1227)
fixes the gnark deserialisation

---------

Co-authored-by: kevaundray <kevtheappdev@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-07-26 17:35:13 +08:00
Daniel Liu
d06f219dc3
crypto: use pure Go signature implementation in tinygo #31878 (#1226)
tinygo is having problems compiling the C implementation

Co-authored-by: Ömer Faruk Irmak <omerfirmak@gmail.com>
2025-07-26 17:33:55 +08:00
Daniel Liu
badb46ce2b
crypto: remove kgz4844 (#1225) 2025-07-26 17:32:07 +08:00
Marius van der Wijden
5bf4da1f47 crypto/secp256k1: update libsecp256k1 (#31242)
Updates the libsecp256k1 dependency to commit:
c0d9480fbbf8eccbd4be23ed27f6f2af6f3b211e

PR:
```
BenchmarkSign-24    	   57756	     21214 ns/op	     164 B/op	       3 allocs/op
BenchmarkRecover-24    	   37156	     33044 ns/op	      80 B/op	       1 allocs/op
BenchmarkEcrecoverSignature-24    	   36889	     32935 ns/op	      80 B/op	       1 allocs/op
BenchmarkVerifySignature-24    	   41163	     29207 ns/op	       0 B/op	       0 allocs/op
BenchmarkDecompressPubkey-24    	  318624	      4062 ns/op	     304 B/op	       6 allocs/op
```

Master:
```
BenchmarkSign-24    	   34509	     35330 ns/op	     164 B/op	       3 allocs/op
BenchmarkRecover-24    	   25418	     47725 ns/op	      80 B/op	       1 allocs/op
BenchmarkEcrecoverSignature-24    	   25735	     47591 ns/op	      80 B/op	       1 allocs/op
BenchmarkVerifySignature-24    	   29108	     41097 ns/op	       0 B/op	       0 allocs/op
BenchmarkDecompressPubkey-24    	  294747	      4143 ns/op	     304 B/op	       6 allocs/op
```

Performance seems to be improved significantly:
```
Sign-24      34.86µ ± 3%   21.66µ ± 2%  -37.86% (p=0.000 n=10)
Recover-24   46.14µ ± 3%   33.24µ ± 2%  -27.95% (p=0.000 n=10)
```
2025-03-19 18:02:46 +08:00
Marius van der Wijden
31cc9b0d5f crypto: add comment to FromECDSAPub (#31241)
closes https://github.com/ethereum/go-ethereum/issues/26240
2025-03-19 18:02:46 +08:00
Daniel Liu
6ec0d13873 core/txpool, crypto, node: fix os.CreateTemp in test (#31172) 2025-03-19 18:02:46 +08:00
Ryan Tinianov
76a5008ec7 all: add build tags for wasip1 (#31090) 2025-03-19 18:02:46 +08:00
Felix Lange
98ad241607 crypto: add IsOnCurve check (#31100) 2025-03-19 18:02:46 +08:00
Daniel Liu
f7c46d0ad7 crypto: fix some typos in comments and names (#31023) 2025-03-19 18:02:46 +08:00
Daniel Liu
77ad10c890 crypto/kz4844: pass blobs by ref (#29050) 2025-02-11 18:26:56 +08:00
Daniel Liu
ed67fd4200 crypto/secp256k1: remove external LGPL dependencies (#17239) 2025-01-24 16:18:28 +08:00
gitglorythegreat
9ca3d10001 crypto/bn256: fix MulScalar (#30974)
The `a` parameter should be used in the `MulScalar` function. The
upstream cloudflare and google repos have already merged fixes.

Reference:
*
8d7daa0c54
* https://github.com/cloudflare/bn256/pull/33
2025-01-04 11:00:57 +08:00
kevaundray
e581093ce1 crypto, tests/fuzzers: add gnark bn254 precompile methods for fuzzing (#30585)
Makes the gnark precompile methods more amenable to fuzzing
2025-01-04 11:00:57 +08:00
Daniel Liu
15be5ba464 crypto: use decred secp256k1 directly (#30595) 2025-01-04 11:00:57 +08:00
zhiqiangxu
e19093f344 crypto: remove hardcoded value for secp256k1.N (#30126) 2025-01-04 11:00:57 +08:00
SuiYuan
104a97354a crypto/secp256k1: change receiver variable name to lowercase (#29889) 2025-01-04 11:00:57 +08:00
George Ma
136e87fa4c crypto: fix docstrings and comments 2025-01-04 11:00:57 +08:00
Daniel Liu
efad15f9f4 crypto: use clear from go1.21 (#29307) 2025-01-04 11:00:57 +08:00
Daniel Liu
d0566e4165 crypto: update to go version 1.22 (#28946) 2025-01-04 11:00:57 +08:00
Daniel Liu
3fbbc9da9f crypto: fix typos in comments (#29186) 2024-12-09 17:49:00 +08:00
Daniel Liu
727855752c crypto: add support for blobs in eth_fillTransaction (#28839) 2024-12-09 17:49:00 +08:00
Daniel Liu
fabfcc7f6c crypto: fix docstring names (#28923) 2024-12-09 17:49:00 +08:00
Daniel Liu
cae53aa7fd crypto/kzg4844: add helpers for versioned blob hashes (#28827) 2024-12-09 17:49:00 +08:00
Daniel Liu
824dea669c crypto/kzg4844: use the new trusted setup file and format (#28383) 2024-12-09 17:49:00 +08:00
Daniel Liu
b5cc7e6fc0 crypto/blake2b: put architecture-dependent features behind build-tag (#28381)
This change to fixes a compilation-flaw on master, by putting architecture-specific functions behind corresponding build tags.
2024-12-09 17:49:00 +08:00
Daniel Liu
f7b6ad67a7 crypto, tests: update fuzzers to native go fuzzing (#28352) 2024-12-09 17:49:00 +08:00
Daniel Liu
247ebd6a6d crypto/kzg4844: do lazy init in all ckzg funcs (#27679)
* crypto/kzg4844: remove unnecessary init call & fix typo

* Fix kzg4844 tests/benchmarks

* Make init lazy & revert changes to tests
2024-12-09 17:49:00 +08:00
Daniel Liu
bd93c59bae crypto: replace noarg fmt.Errorf with errors.New (#27333) 2024-12-09 17:49:00 +08:00
Daniel Liu
ed03a99770 crypto/kzg4844: upgrade c-kzg-4844 to v0.2.0 (#27257) 2024-12-09 17:49:00 +08:00
Daniel Liu
bedd571091 crypto/kzg4844: pull in the C and Go libs for KZG cryptography (#27155) 2024-12-09 17:49:00 +08:00
Daniel Liu
797efe74af crypto: more linters and fix typo (#24783) 2024-12-09 17:49:00 +08:00
Daniel Liu
cb3edac2c7 crypto: use btcec/v2 for no-cgo (#24533) 2024-12-09 17:49:00 +08:00
Daniel Liu
949fa6358e crypto/ecies: use AES-192 for curve P384 (#24139)
Using curve P384 for encryption causes the error "ecies: shared key params
are too big". Also, readme.md says curve P384 should use AES192 not AES256.

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
2024-12-09 17:49:00 +08:00