diff --git a/erigon-lib/crypto/crypto.go b/erigon-lib/crypto/crypto.go index 35fdbfd0805..b1e017d2ff2 100644 --- a/erigon-lib/crypto/crypto.go +++ b/erigon-lib/crypto/crypto.go @@ -118,9 +118,9 @@ func Keccak512(data ...[]byte) []byte { // CreateAddress creates an ethereum address given the bytes and the nonce // DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account func CreateAddress(a common.Address, nonce uint64) common.Address { - len := 21 + rlp.U64Len(nonce) - data := make([]byte, len+1) - pos := rlp.EncodeListPrefix(len, data) + listLen := 21 + rlp.U64Len(nonce) + data := make([]byte, listLen+1) + pos := rlp.EncodeListPrefix(listLen, data) pos += rlp.EncodeAddress(a[:], data[pos:]) rlp.EncodeU64(nonce, data[pos:]) return common.BytesToAddress(Keccak256(data)[12:]) @@ -228,7 +228,8 @@ func MarshalPubkey(pubkey *ecdsa.PublicKey) []byte { // HexToECDSA parses a secp256k1 private key. func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error) { b, err := hex.DecodeString(hexkey) - if byteErr, ok := err.(hex.InvalidByteError); ok { + var byteErr hex.InvalidByteError + if errors.As(err, &byteErr) { return nil, fmt.Errorf("invalid hex character %q in private key", byte(byteErr)) } else if err != nil { return nil, errors.New("invalid hex data for private key") diff --git a/erigon-lib/crypto/crypto_test.go b/erigon-lib/crypto/crypto_test.go index 0d1af31a1e6..6c08f766115 100644 --- a/erigon-lib/crypto/crypto_test.go +++ b/erigon-lib/crypto/crypto_test.go @@ -23,17 +23,18 @@ import ( "bytes" "crypto/ecdsa" "encoding/hex" + "errors" "os" "reflect" "testing" + "github.com/holiman/uint256" "golang.org/x/crypto/sha3" "github.com/erigontech/erigon-lib/common" "github.com/erigontech/erigon-lib/common/hexutil" "github.com/erigontech/erigon-lib/common/hexutility" "github.com/erigontech/erigon-lib/common/u256" - "github.com/holiman/uint256" ) var testAddrHex = "970e8128ab834e8eac17ab8e3812f010678cf791" @@ -101,11 +102,11 @@ func BenchmarkSha3(b *testing.B) { func TestUnmarshalPubkey(t *testing.T) { key, err := UnmarshalPubkey(nil) - if err != errInvalidPubkey || key != nil { + if !errors.Is(err, errInvalidPubkey) || key != nil { t.Fatalf("expected error, got %v, %v", err, key) } key, err = UnmarshalPubkey([]byte{1, 2, 3}) - if err != errInvalidPubkey || key != nil { + if !errors.Is(err, errInvalidPubkey) || key != nil { t.Fatalf("expected error, got %v, %v", err, key) } @@ -325,6 +326,7 @@ func TestTransactionSignatureIsValid(t *testing.T) { } func checkhash(t *testing.T, name string, f func([]byte) []byte, msg, exp []byte) { + t.Helper() sum := f(msg) if !bytes.Equal(exp, sum) { t.Fatalf("hash %s mismatch: want: %x have: %x", name, exp, sum) @@ -332,6 +334,7 @@ func checkhash(t *testing.T, name string, f func([]byte) []byte, msg, exp []byte } func checkAddr(t *testing.T, addr0, addr1 common.Address) { + t.Helper() if addr0 != addr1 { t.Fatalf("address mismatch: want: %x have: %x", addr0, addr1) } diff --git a/erigon-lib/crypto/ecies/ecies_test.go b/erigon-lib/crypto/ecies/ecies_test.go index 27cdea48953..ba925c9e105 100644 --- a/erigon-lib/crypto/ecies/ecies_test.go +++ b/erigon-lib/crypto/ecies/ecies_test.go @@ -164,12 +164,12 @@ func TestTooBigSharedKey(t *testing.T) { } _, err = prv1.GenerateShared(&prv2.PublicKey, 32, 32) - if err != ErrSharedKeyTooBig { + if !errors.Is(err, ErrSharedKeyTooBig) { t.Fatal("ecdh: shared key should be too large for curve") } _, err = prv2.GenerateShared(&prv1.PublicKey, 32, 32) - if err != ErrSharedKeyTooBig { + if !errors.Is(err, ErrSharedKeyTooBig) { t.Fatal("ecdh: shared key should be too large for curve") } } @@ -310,6 +310,7 @@ func TestParamSelection(t *testing.T) { } func testParamSelection(t *testing.T, c testCase) { + t.Helper() params := ParamsFromCurve(c.Curve) if params == nil { t.Fatal("ParamsFromCurve returned nil") @@ -368,7 +369,7 @@ func TestBasicKeyValidation(t *testing.T) { for _, b := range badBytes { ct[0] = b _, err := prv.Decrypt(ct, nil, nil) - if err != ErrInvalidPublicKey { + if !errors.Is(err, ErrInvalidPublicKey) { t.Fatal("ecies: validated an invalid key") } } diff --git a/erigon-lib/go.mod b/erigon-lib/go.mod index 4c812f65ed4..b2fdd309050 100644 --- a/erigon-lib/go.mod +++ b/erigon-lib/go.mod @@ -16,6 +16,7 @@ require ( github.com/anacrolix/go-libutp v1.3.1 github.com/anacrolix/log v0.15.2 github.com/anacrolix/torrent v1.52.6-0.20231201115409-7ea994b6bbd8 + github.com/btcsuite/btcd/btcec/v2 v2.3.4 github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500 github.com/containerd/cgroups/v3 v3.0.3 github.com/crate-crypto/go-kzg-4844 v0.7.0 @@ -54,6 +55,7 @@ require ( require ( github.com/cespare/xxhash v1.1.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/ianlancetaylor/cgosymbolizer v0.0.0-20240503222823-736c933a666d // indirect github.com/klauspost/compress v1.17.9 // indirect diff --git a/erigon-lib/go.sum b/erigon-lib/go.sum index c2d86e6683e..c1ed7c228da 100644 --- a/erigon-lib/go.sum +++ b/erigon-lib/go.sum @@ -100,6 +100,10 @@ github.com/bradfitz/iter v0.0.0-20140124041915-454541ec3da2/go.mod h1:PyRFw1Lt2w github.com/bradfitz/iter v0.0.0-20190303215204-33e6a9893b0c/go.mod h1:PyRFw1Lt2wKX4ZVSQ2mk+PeDa1rxyObEDlApuIsUKuo= github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 h1:GKTyiRCL6zVf5wWaqKnf+7Qs6GbEPfd4iMOitWzXJx8= github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8/go.mod h1:spo1JLcs67NmW1aVLEgtA8Yy1elc+X8y5SRW1sFW4Og= +github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ= +github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500 h1:6lhrsTEnloDPXyeZBvSYvQf8u86jbKehZPVDDlkgDl4= github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -128,6 +132,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set/v2 v2.3.1 h1:vjmkvJt/IV27WXPyYQpAh4bRyWJc5Y435D17XQ9QU5A= github.com/deckarep/golang-set/v2 v2.3.1/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= +github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= +github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= diff --git a/go.mod b/go.mod index 30bd449f341..fab36580321 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/anacrolix/sync v0.5.1 github.com/anacrolix/torrent v1.52.6-0.20231201115409-7ea994b6bbd8 github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b - github.com/btcsuite/btcd/btcec/v2 v2.1.3 + github.com/btcsuite/btcd/btcec/v2 v2.3.4 github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500 github.com/cenkalti/backoff/v4 v4.2.1 github.com/consensys/gnark-crypto v0.12.1 @@ -149,7 +149,6 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.12.0 // indirect github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect - github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cilium/ebpf v0.11.0 // indirect diff --git a/go.sum b/go.sum index e6dee503a1c..f0c36a7cddf 100644 --- a/go.sum +++ b/go.sum @@ -175,8 +175,8 @@ github.com/bradfitz/iter v0.0.0-20140124041915-454541ec3da2/go.mod h1:PyRFw1Lt2w github.com/bradfitz/iter v0.0.0-20190303215204-33e6a9893b0c/go.mod h1:PyRFw1Lt2wKX4ZVSQ2mk+PeDa1rxyObEDlApuIsUKuo= github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 h1:GKTyiRCL6zVf5wWaqKnf+7Qs6GbEPfd4iMOitWzXJx8= github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8/go.mod h1:spo1JLcs67NmW1aVLEgtA8Yy1elc+X8y5SRW1sFW4Og= -github.com/btcsuite/btcd/btcec/v2 v2.1.3 h1:xM/n3yIhHAhHy04z4i43C8p4ehixJZMsnrVJkgl+MTE= -github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= +github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ= +github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=