Skip to content

Commit ab49f22

Browse files
holimanMariusVanDerWijdenfjl
authored
all: update to go version 1.22.1 (#28946)
Since Go 1.22 has deprecated certain elliptic curve operations, this PR removes references to the affected functions and replaces them with a custom implementation in package crypto. This causes backwards-incompatible changes in some places. --------- Co-authored-by: Marius van der Wijden <[email protected]> Co-authored-by: Felix Lange <[email protected]>
1 parent c611924 commit ab49f22

14 files changed

+147
-74
lines changed

.travis.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
os: linux
1717
arch: amd64
1818
dist: bionic
19-
go: 1.21.x
19+
go: 1.22.x
2020
env:
2121
- docker
2222
services:
@@ -33,7 +33,7 @@ jobs:
3333
os: linux
3434
arch: arm64
3535
dist: bionic
36-
go: 1.21.x
36+
go: 1.22.x
3737
env:
3838
- docker
3939
services:
@@ -51,7 +51,7 @@ jobs:
5151
os: linux
5252
dist: bionic
5353
sudo: required
54-
go: 1.21.x
54+
go: 1.22.x
5555
env:
5656
- azure-linux
5757
git:
@@ -85,7 +85,7 @@ jobs:
8585
if: type = push
8686
os: osx
8787
osx_image: xcode14.2
88-
go: 1.21.x
88+
go: 1.22.x
8989
env:
9090
- azure-osx
9191
git:
@@ -101,7 +101,7 @@ jobs:
101101
os: linux
102102
arch: amd64
103103
dist: bionic
104-
go: 1.21.x
104+
go: 1.22.x
105105
script:
106106
- travis_wait 30 go run build/ci.go test $TEST_PACKAGES
107107

@@ -110,14 +110,14 @@ jobs:
110110
os: linux
111111
arch: arm64
112112
dist: bionic
113-
go: 1.20.x
113+
go: 1.21.x
114114
script:
115115
- travis_wait 30 go run build/ci.go test $TEST_PACKAGES
116116

117117
- stage: build
118118
os: linux
119119
dist: bionic
120-
go: 1.20.x
120+
go: 1.21.x
121121
script:
122122
- travis_wait 30 go run build/ci.go test $TEST_PACKAGES
123123

@@ -126,7 +126,7 @@ jobs:
126126
if: type = cron || (type = push && tag ~= /^v[0-9]/)
127127
os: linux
128128
dist: bionic
129-
go: 1.21.x
129+
go: 1.22.x
130130
env:
131131
- ubuntu-ppa
132132
git:
@@ -149,7 +149,7 @@ jobs:
149149
if: type = cron
150150
os: linux
151151
dist: bionic
152-
go: 1.21.x
152+
go: 1.22.x
153153
env:
154154
- azure-purge
155155
git:
@@ -162,7 +162,7 @@ jobs:
162162
if: type = cron
163163
os: linux
164164
dist: bionic
165-
go: 1.21.x
165+
go: 1.22.x
166166
script:
167167
- travis_wait 30 go run build/ci.go test -race $TEST_PACKAGES
168168

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ARG VERSION=""
44
ARG BUILDNUM=""
55

66
# Build Geth in a stock Go builder container
7-
FROM golang:1.21-alpine as builder
7+
FROM golang:1.22-alpine as builder
88

99
RUN apk add --no-cache gcc musl-dev linux-headers git
1010

Dockerfile.alltools

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ARG VERSION=""
44
ARG BUILDNUM=""
55

66
# Build Geth in a stock Go builder container
7-
FROM golang:1.21-alpine as builder
7+
FROM golang:1.22-alpine as builder
88

99
RUN apk add --no-cache gcc musl-dev linux-headers git
1010

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ archives are published at https://geth.ethereum.org/downloads/.
1616

1717
For prerequisites and detailed build instructions please read the [Installation Instructions](https://geth.ethereum.org/docs/getting-started/installing-geth).
1818

19-
Building `geth` requires both a Go (version 1.19 or later) and a C compiler. You can install
19+
Building `geth` requires both a Go (version 1.21 or later) and a C compiler. You can install
2020
them using your favourite package manager. Once the dependencies are installed, run
2121

2222
```shell

accounts/scwallet/securechannel.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"bytes"
2121
"crypto/aes"
2222
"crypto/cipher"
23-
"crypto/elliptic"
2423
"crypto/rand"
2524
"crypto/sha256"
2625
"crypto/sha512"
@@ -72,11 +71,11 @@ func NewSecureChannelSession(card *pcsc.Card, keyData []byte) (*SecureChannelSes
7271
if err != nil {
7372
return nil, fmt.Errorf("could not unmarshal public key from card: %v", err)
7473
}
75-
secret, _ := key.Curve.ScalarMult(cardPublic.X, cardPublic.Y, key.D.Bytes())
74+
secret, _ := crypto.S256().ScalarMult(cardPublic.X, cardPublic.Y, key.D.Bytes())
7675
return &SecureChannelSession{
7776
card: card,
7877
secret: secret.Bytes(),
79-
publicKey: elliptic.Marshal(crypto.S256(), key.PublicKey.X, key.PublicKey.Y),
78+
publicKey: crypto.FromECDSAPub(&key.PublicKey),
8079
}, nil
8180
}
8281

build/checksums.txt

+15-15
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
# https://github.com/ethereum/execution-spec-tests/releases/download/v2.1.0/
66
ca89c76851b0900bfcc3cbb9a26cbece1f3d7c64a3bed38723e914713290df6c fixtures_develop.tar.gz
77

8-
# version:golang 1.21.6
8+
# version:golang 1.22.1
99
# https://go.dev/dl/
10-
124926a62e45f78daabbaedb9c011d97633186a33c238ffc1e25320c02046248 go1.21.6.src.tar.gz
11-
31d6ecca09010ab351e51343a5af81d678902061fee871f912bdd5ef4d778850 go1.21.6.darwin-amd64.tar.gz
12-
0ff541fb37c38e5e5c5bcecc8f4f43c5ffd5e3a6c33a5d3e4003ded66fcfb331 go1.21.6.darwin-arm64.tar.gz
13-
a1d1a149b34bf0f53965a237682c6da1140acabb131bf0e597240e4a140b0e5e go1.21.6.freebsd-386.tar.gz
14-
de59e1217e4398b1522eed8dddabab2fa1b97aecbdca3af08e34832b4f0e3f81 go1.21.6.freebsd-amd64.tar.gz
15-
05d09041b5a1193c14e4b2db3f7fcc649b236c567f5eb93305c537851b72dd95 go1.21.6.linux-386.tar.gz
16-
3f934f40ac360b9c01f616a9aa1796d227d8b0328bf64cb045c7b8c4ee9caea4 go1.21.6.linux-amd64.tar.gz
17-
e2e8aa88e1b5170a0d495d7d9c766af2b2b6c6925a8f8956d834ad6b4cacbd9a go1.21.6.linux-arm64.tar.gz
18-
6a8eda6cc6a799ff25e74ce0c13fdc1a76c0983a0bb07c789a2a3454bf6ec9b2 go1.21.6.linux-armv6l.tar.gz
19-
e872b1e9a3f2f08fd4554615a32ca9123a4ba877ab6d19d36abc3424f86bc07f go1.21.6.linux-ppc64le.tar.gz
20-
92894d0f732d3379bc414ffdd617eaadad47e1d72610e10d69a1156db03fc052 go1.21.6.linux-s390x.tar.gz
21-
65b38857135cf45c80e1d267e0ce4f80fe149326c68835217da4f2da9b7943fe go1.21.6.windows-386.zip
22-
27ac9dd6e66fb3fd0acfa6792ff053c86e7d2c055b022f4b5d53bfddec9e3301 go1.21.6.windows-amd64.zip
23-
b93aff8f3c882c764c66a39b7a1483b0460e051e9992bf3435479129e5051bcd go1.21.6.windows-arm64.zip
10+
79c9b91d7f109515a25fc3ecdaad125d67e6bdb54f6d4d98580f46799caea321 go1.22.1.src.tar.gz
11+
3bc971772f4712fec0364f4bc3de06af22a00a12daab10b6f717fdcd13156cc0 go1.22.1.darwin-amd64.tar.gz
12+
f6a9cec6b8a002fcc9c0ee24ec04d67f430a52abc3cfd613836986bcc00d8383 go1.22.1.darwin-arm64.tar.gz
13+
99f81c10d5a3f8a886faf8fa86aaa2aaf929fbed54a972ae5eec3c5e0bdb961a go1.22.1.freebsd-386.tar.gz
14+
51c614ddd92ee4a9913a14c39bf80508d9cfba08561f24d2f075fd00f3cfb067 go1.22.1.freebsd-amd64.tar.gz
15+
8484df36d3d40139eaf0fe5e647b006435d826cc12f9ae72973bf7ec265e0ae4 go1.22.1.linux-386.tar.gz
16+
aab8e15785c997ae20f9c88422ee35d962c4562212bb0f879d052a35c8307c7f go1.22.1.linux-amd64.tar.gz
17+
e56685a245b6a0c592fc4a55f0b7803af5b3f827aaa29feab1f40e491acf35b8 go1.22.1.linux-arm64.tar.gz
18+
8cb7a90e48c20daed39a6ac8b8a40760030ba5e93c12274c42191d868687c281 go1.22.1.linux-armv6l.tar.gz
19+
ac775e19d93cc1668999b77cfe8c8964abfbc658718feccfe6e0eb87663cd668 go1.22.1.linux-ppc64le.tar.gz
20+
7bb7dd8e10f95c9a4cc4f6bef44c816a6e7c9e03f56ac6af6efbb082b19b379f go1.22.1.linux-s390x.tar.gz
21+
0c5ebb7eb39b7884ec99f92b425d4c03a96a72443562aafbf6e7d15c42a3108a go1.22.1.windows-386.zip
22+
cf9c66a208a106402a527f5b956269ca506cfe535fc388e828d249ea88ed28ba go1.22.1.windows-amd64.zip
23+
85b8511b298c9f4199ecae26afafcc3d46155bac934d43f2357b9224bcaa310f go1.22.1.windows-arm64.zip
2424

2525
# version:golangci 1.55.2
2626
# https://github.com/golangci/golangci-lint/releases/

crypto/crypto.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ var (
5151

5252
var errInvalidPubkey = errors.New("invalid secp256k1 public key")
5353

54+
// EllipticCurve contains curve operations.
55+
type EllipticCurve interface {
56+
elliptic.Curve
57+
58+
// Point marshaling/unmarshaing.
59+
Marshal(x, y *big.Int) []byte
60+
Unmarshal(data []byte) (x, y *big.Int)
61+
}
62+
5463
// KeccakState wraps sha3.state. In addition to the usual hash methods, it also supports
5564
// Read to get a variable amount of data from the hash state. Read is faster than Sum
5665
// because it doesn't copy the internal state, but also modifies the internal state.
@@ -148,7 +157,7 @@ func toECDSA(d []byte, strict bool) (*ecdsa.PrivateKey, error) {
148157
return nil, errors.New("invalid private key, zero or negative")
149158
}
150159

151-
priv.PublicKey.X, priv.PublicKey.Y = priv.PublicKey.Curve.ScalarBaseMult(d)
160+
priv.PublicKey.X, priv.PublicKey.Y = S256().ScalarBaseMult(d)
152161
if priv.PublicKey.X == nil {
153162
return nil, errors.New("invalid private key")
154163
}
@@ -165,7 +174,7 @@ func FromECDSA(priv *ecdsa.PrivateKey) []byte {
165174

166175
// UnmarshalPubkey converts bytes to a secp256k1 public key.
167176
func UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error) {
168-
x, y := elliptic.Unmarshal(S256(), pub)
177+
x, y := S256().Unmarshal(pub)
169178
if x == nil {
170179
return nil, errInvalidPubkey
171180
}
@@ -176,7 +185,7 @@ func FromECDSAPub(pub *ecdsa.PublicKey) []byte {
176185
if pub == nil || pub.X == nil || pub.Y == nil {
177186
return nil
178187
}
179-
return elliptic.Marshal(S256(), pub.X, pub.Y)
188+
return S256().Marshal(pub.X, pub.Y)
180189
}
181190

182191
// HexToECDSA parses a secp256k1 private key.

crypto/ecies/ecies.go

+32-24
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import (
4040
"hash"
4141
"io"
4242
"math/big"
43+
44+
"github.com/ethereum/go-ethereum/crypto"
4345
)
4446

4547
var (
@@ -95,15 +97,15 @@ func ImportECDSA(prv *ecdsa.PrivateKey) *PrivateKey {
9597
// Generate an elliptic curve public / private keypair. If params is nil,
9698
// the recommended default parameters for the key will be chosen.
9799
func GenerateKey(rand io.Reader, curve elliptic.Curve, params *ECIESParams) (prv *PrivateKey, err error) {
98-
pb, x, y, err := elliptic.GenerateKey(curve, rand)
100+
sk, err := ecdsa.GenerateKey(curve, rand)
99101
if err != nil {
100102
return
101103
}
102104
prv = new(PrivateKey)
103-
prv.PublicKey.X = x
104-
prv.PublicKey.Y = y
105+
prv.PublicKey.X = sk.X
106+
prv.PublicKey.Y = sk.Y
105107
prv.PublicKey.Curve = curve
106-
prv.D = new(big.Int).SetBytes(pb)
108+
prv.D = new(big.Int).Set(sk.D)
107109
if params == nil {
108110
params = ParamsFromCurve(curve)
109111
}
@@ -255,12 +257,15 @@ func Encrypt(rand io.Reader, pub *PublicKey, m, s1, s2 []byte) (ct []byte, err e
255257

256258
d := messageTag(params.Hash, Km, em, s2)
257259

258-
Rb := elliptic.Marshal(pub.Curve, R.PublicKey.X, R.PublicKey.Y)
259-
ct = make([]byte, len(Rb)+len(em)+len(d))
260-
copy(ct, Rb)
261-
copy(ct[len(Rb):], em)
262-
copy(ct[len(Rb)+len(em):], d)
263-
return ct, nil
260+
if curve, ok := pub.Curve.(crypto.EllipticCurve); ok {
261+
Rb := curve.Marshal(R.PublicKey.X, R.PublicKey.Y)
262+
ct = make([]byte, len(Rb)+len(em)+len(d))
263+
copy(ct, Rb)
264+
copy(ct[len(Rb):], em)
265+
copy(ct[len(Rb)+len(em):], d)
266+
return ct, nil
267+
}
268+
return nil, ErrInvalidCurve
264269
}
265270

266271
// Decrypt decrypts an ECIES ciphertext.
@@ -297,21 +302,24 @@ func (prv *PrivateKey) Decrypt(c, s1, s2 []byte) (m []byte, err error) {
297302

298303
R := new(PublicKey)
299304
R.Curve = prv.PublicKey.Curve
300-
R.X, R.Y = elliptic.Unmarshal(R.Curve, c[:rLen])
301-
if R.X == nil {
302-
return nil, ErrInvalidPublicKey
303-
}
304305

305-
z, err := prv.GenerateShared(R, params.KeyLen, params.KeyLen)
306-
if err != nil {
307-
return nil, err
308-
}
309-
Ke, Km := deriveKeys(hash, z, s1, params.KeyLen)
306+
if curve, ok := R.Curve.(crypto.EllipticCurve); ok {
307+
R.X, R.Y = curve.Unmarshal(c[:rLen])
308+
if R.X == nil {
309+
return nil, ErrInvalidPublicKey
310+
}
310311

311-
d := messageTag(params.Hash, Km, c[mStart:mEnd], s2)
312-
if subtle.ConstantTimeCompare(c[mEnd:], d) != 1 {
313-
return nil, ErrInvalidMessage
314-
}
312+
z, err := prv.GenerateShared(R, params.KeyLen, params.KeyLen)
313+
if err != nil {
314+
return nil, err
315+
}
316+
Ke, Km := deriveKeys(hash, z, s1, params.KeyLen)
315317

316-
return symDecrypt(params, Ke, c[mStart:mEnd])
318+
d := messageTag(params.Hash, Km, c[mStart:mEnd], s2)
319+
if subtle.ConstantTimeCompare(c[mEnd:], d) != 1 {
320+
return nil, ErrInvalidMessage
321+
}
322+
return symDecrypt(params, Ke, c[mStart:mEnd])
323+
}
324+
return nil, ErrInvalidCurve
317325
}

crypto/secp256k1/secp256_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ package secp256k1
1010
import (
1111
"bytes"
1212
"crypto/ecdsa"
13-
"crypto/elliptic"
1413
"crypto/rand"
1514
"encoding/hex"
1615
"io"
@@ -24,7 +23,7 @@ func generateKeyPair() (pubkey, privkey []byte) {
2423
if err != nil {
2524
panic(err)
2625
}
27-
pubkey = elliptic.Marshal(S256(), key.X, key.Y)
26+
pubkey = S256().Marshal(key.X, key.Y)
2827

2928
privkey = make([]byte, 32)
3029
blob := key.D.Bytes()

crypto/signature_cgo.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package crypto
2121

2222
import (
2323
"crypto/ecdsa"
24-
"crypto/elliptic"
2524
"errors"
2625
"fmt"
2726

@@ -40,9 +39,7 @@ func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) {
4039
if err != nil {
4140
return nil, err
4241
}
43-
44-
x, y := elliptic.Unmarshal(S256(), s)
45-
return &ecdsa.PublicKey{Curve: S256(), X: x, Y: y}, nil
42+
return UnmarshalPubkey(s)
4643
}
4744

4845
// Sign calculates an ECDSA signature.
@@ -84,6 +81,6 @@ func CompressPubkey(pubkey *ecdsa.PublicKey) []byte {
8481
}
8582

8683
// S256 returns an instance of the secp256k1 curve.
87-
func S256() elliptic.Curve {
84+
func S256() EllipticCurve {
8885
return secp256k1.S256()
8986
}

0 commit comments

Comments
 (0)