Commit graph

93 commits

Author SHA1 Message Date
Olaoluwa Osuntokun
e454fa7762
Merge pull request #2545 from Lrifton92/fix/wif-private-key-range-validation
Some checks are pending
Build and Test / Build (push) Waiting to run
Build and Test / Unit coverage (push) Waiting to run
Build and Test / Unit race (push) Waiting to run
Build and Test / Unit rpctest (push) Waiting to run
btcutil: reject out-of-range private keys in DecodeWIF
2026-07-20 18:52:27 -05:00
Boris Nagaev
e72a65de00
btcutil: test byte constructors reject trailing data 2026-06-26 12:17:37 -05:00
Boris Nagaev
41d537d85e
btcutil: reject trailing data in byte constructors 2026-06-26 12:17:37 -05:00
Boris Nagaev
def22fa88e
btcutil/bloom: fix malformed filter test transaction 2026-06-26 12:17:37 -05:00
Lrifton92
f10224dd13 btcutil: zero range-check scalar before returning from DecodeWIF
Wipe the secp256k1 scalar used for the [1, N-1] range validation as
soon as DecodeWIF returns, so the decoded private key value does not
linger in this local after use. Addresses review feedback on #2545.
2026-06-24 11:55:30 +02:00
Lrifton92
b23f560a91 btcutil: reject out-of-range private keys in DecodeWIF
DecodeWIF did not validate that the decoded private key falls within the
valid range [1, N-1] for a secp256k1 private key. The raw 32-byte key
material was passed straight to btcec.PrivKeyFromBytes, which reduces the
scalar modulo the group order N and clamps to zero, returning no error.

As a result, a WIF encoding a private key of zero, the group order N, or
any value >= N was silently accepted. For keys >= N this is particularly
dangerous: DecodeWIF returned a private key that differs from the one
actually encoded in the WIF (e.g. a WIF for N+5 decoded to the key 5),
so an application importing such a WIF would obtain a valid-looking but
wrong key pair, with no indication that anything was off. This is also
inconsistent with hdkeychain.NewKeyFromString in the same package, which
already rejects private keys outside [1, N-1].

Validate the range using a ModNScalar (constant time): SetByteSlice
reports an overflow when the value is >= N, and IsZero covers the zero
key. Out-of-range keys now return ErrMalformedPrivateKey.

Add regression test cases (zero, N, and N+5) to TestEncodeDecodeWIF.

Signed-off-by: Lrifton92 <Lrifton92@users.noreply.github.com>
2026-06-11 17:14:02 +02:00
Olaoluwa Osuntokun
fdad1fab1f multi: pin new v2 submodule tags and bump to v0.26.0-beta.rc1
In this commit, we strip all of the local `replace ... => ../...`
directives that were introduced as part of #1825 (the v2 module
restructuring), now that proper tags exist for every freshly carved-out
submodule. Every in-tree go.mod is pinned to the newly published tags:
chainhash/v2.0.0, wire/v2.0.0, chaincfg/v2.0.0, address/v2.0.0,
txscript/v2.0.0, btcutil/v2.0.0, psbt/v2.0.0, and btcec is bumped to
v2.5.0 since it now depends on chainhash/v2 (previously
chaincfg/chainhash).

While here, we also unify the Go toolchain to 1.25 across every
submodule so the workspace resolves a consistent set of language
features.

Finally, we bump the main btcd version to v0.26.0-beta.rc1 in
preparation for the upcoming release candidate.
2026-05-14 19:25:06 -07:00
Oliver Gugger
dccea8feba multi: use new v2 modules everywhere 2026-05-14 18:05:33 -07:00
Oliver Gugger
c0db6dfa11 psbt: move to top-level module, use v2, remove btcutil dep 2026-05-14 18:01:00 -07:00
Oliver Gugger
e9ec6ec506 btcutil: remove circular dependency, use v2 2026-05-14 18:00:53 -07:00
Oliver Gugger
3000c455f8 address: move to top-level module, use v2 2026-05-14 17:56:18 -07:00
Olaoluwa Osuntokun
1863073cb0 multi: bump Go toolchain to 1.25, build CI with 1.26.3
In this commit, we update every in-tree go.mod to declare go 1.25 and
have CI build with 1.26.3 (Dockerfile uses the golang:1.26-alpine base).
Docs that mention the minimum required Go version are aligned with the
new floor as well.

Fixes #2527, which flagged the README.md / go.mod version mismatch (the
README claimed 1.22 while the root + v2transport go.mod files already
required 1.23.2).
2026-05-14 17:32:02 -07:00
Olaoluwa Osuntokun
e59dfeb949 multi: bump in-tree go.mod files to newly tagged submodule versions
In this commit, we pin every in-tree go.mod to the freshly cut submodule
tags ahead of a btcd point release: btcec/v2.4.0, btcutil/v1.2.0,
btcutil/psbt/v1.2.0, and chaincfg/chainhash/v1.2.0. The btcec bump also
drags secp256k1 up to v4.4.0 (and blake256 to v1.1.0 transitively) for
every module that imports btcec.

v2transport stays at v1.0.1 since no v2transport code changed since the
last tag, but its go.mod is bumped here so the workspace resolves to a
consistent set of internal deps.
2026-05-14 17:02:20 -07:00
Olaoluwa Osuntokun
73af4d6f88 btcutil: rename interfaceAddrs to InterfaceAddrs in appengine variant
The previous commit exported the interfaceAddrs helper in net.go but
missed the parallel definition in net_noop.go (build tag: appengine),
which left builds with -tags appengine broken with:

    ./certgen.go:79:16: undefined: InterfaceAddrs

Rename the appengine no-op variant to match, restoring the appengine
build.
2026-05-14 16:22:44 -07:00
Calvin Kim
c90e88ee23 btcutil: export interfaceAddr 2026-05-14 16:16:14 -07:00
Calvin Kim
153bf6d828 btcutil: use anet instead of net for android builds
Golang's net package has been broken for android since android 11
and the node will not be able to call net.InterfaceAddr() without
root.

For android builds, we use anet so that the btcd node can be used
without root.
2026-05-14 16:16:14 -07:00
Olaoluwa Osuntokun
939b9394dc btcutil: add new AddressPayToAnchor addr type 2026-05-12 10:56:34 -07:00
Olaoluwa Osuntokun
c002ea3196
Merge pull request #2320 from gosunuts/feature/fix-ci
feat: fix ci / makefile
2025-08-19 18:09:43 -07:00
Kim
f19065176b multi: apply make fmt to all files 2025-08-05 18:39:30 +09:00
Gijs van Dam
5e69e56cb8
btcutil/bloom: align hash function count with filter capacity
In this commit, we ensure hash function parameters are consistent with
filter size to avoid unnecessary operations. A filter with no capacity
doesn't actually require any hash functions, so we can cut that loop
short.
2025-07-14 11:03:36 +02:00
Yong
9adca7479d
Merge pull request #2375 from Aharonee/chore/update_psbt_deps
psbt: upgrade dependencies and fix unit test
2025-07-14 05:17:05 +03:00
Or Aharonee
4727f323ed
Update Go module and dependencies
Upgrade several package versions and fix a test case for transaction serialization.
2025-07-11 23:30:28 +03:00
ffranr
565a7a8822
psbt: limit value size in ReadTaprootBip32Derivation to prevent OOM
Cap the `value` slice to `MaxPsbtValueLength` to prevent potential
out-of-memory conditions during parsing. This ensures that total
allocation remains bounded and consistent with other PSBT fields.
2025-05-23 14:36:06 +01:00
ffranr
16c2b92afd
psbt: overflow checks when computing Taproot BIP32 derivation min size
Protect against overflows when parsing malformed Taproot BIP32
derivation fields. This ensures that deserialization fails safely if the
declared number of leaf hashes would otherwise cause an integer
overflow.
2025-05-22 13:34:28 +01:00
Oliver Gugger
990d9528d7
psbt: check path minimum length 2025-04-04 10:03:53 +02:00
petersssong
5ace0a6879 multi: deprecation gocov 2025-03-19 09:45:48 +08:00
Kim
ca8059b59d bump go mod versions 2025-02-10 16:37:15 +09:00
Oliver Gugger
bda0481701
psbt: add global XPubs to packet
Adds support for the PSBT_GLOBAL_XPUB type as defined in BIP-0174.
2025-01-14 21:19:35 +01:00
Oliver Gugger
bdb0b3d821
psbt: cleanup code 2024-12-26 11:13:57 +01:00
Alexsandro
913f95b2b2
Updated github.com/btcsuite/btcd to address CVE-2024-34478
synchronize dependencies
2024-08-15 11:16:41 -03:00
Oliver Gugger
4bff778564
psbt: decode keytype as compact size
Fixes #2199.

Previous to this fix the keytype was only interpreted as a single byte,
even though BIP-0174 states it is to be parsed as a CompactSize/VarInt.
2024-06-25 16:03:05 +02:00
marcoezekiel
2492b01f69 btcutil/bech32: Added DecodeNoLimitWithVersion
This exposes publicly the ability to decode arbitrary-length bech32
strings and return the bech32 version that was used in the encoding. It
provides the underlying functionality for both DecodeNoLimit and
DecodeGeneric.
2024-05-13 12:02:40 -06:00
MarkDaveny
6b197d38d7
chore: fix some function names (#2180)
Signed-off-by: MarkDaveny <peicuiping@aliyun.com>
2024-04-29 11:45:39 -04:00
snoppy
9851d96c06
chore: fix typos 2024-03-29 10:21:29 +08:00
xiaoxiangxianzi
95330bc1bb
chore: fix some comments (#2146)
Signed-off-by: xiaoxiangxianzi <zhaoyizheng@outlook.com>
2024-03-27 09:45:48 -04:00
mattn
3cb9f602e8
fix typos (#2100) 2024-03-25 09:44:25 -04:00
theedtron
b66f5b8379
multi: fix ioutil deprecated function
update i/o functions to use os / io package functions instead
2024-03-08 17:41:41 -08:00
yyforyongyu
fbe65bfc01
gomod: run go mod tidy for all modules
Also add the `make tidy-module` copied from `lnd`.
2024-01-15 17:22:42 +08:00
vuittont60
7df46516b7
btcutil: fix typo 2024-01-09 17:12:23 +08:00
Olaoluwa Osuntokun
e102a81268
btcutil: add benchmarks for Hash + WitnessHash 2023-12-28 18:07:03 -08:00
Olaoluwa Osuntokun
56de9ca878
btcutil: align new serialization caching logic w/ codebase style 2023-12-28 17:47:11 -08:00
Calvin Kim
83605e476c btcutil: reuse serialized tx during TxHash
btcutil.Block caches the serialized raw bytes of the block during ibd.
This serialized block bytes includes the serialized tx. The current tx
hash generation will re-serialized the de-serialized tx to create the
raw bytes and it'll only then hash that.

This commit changes the code so that the re-serialization never happens,
saving tons of cpu and memory overhead.
2023-12-21 13:43:11 +09:00
Olaoluwa Osuntokun
4126760706
btcutil/psbt: update to btcutil btcutil/v1.1.4 2023-12-19 15:01:52 -08:00
Olaoluwa Osuntokun
28a816f050
btcutil/psbt: update to chaincfg/chainhash/v1.1.0 + btcutil/v1.1.3
We also remove the replace directives in place.
2023-12-15 14:55:10 -08:00
Olaoluwa Osuntokun
7745cbb679
btcutl/gcs: update filter logic to use new DoubleHashRaw 2023-12-15 14:42:35 -08:00
Olaoluwa Osuntokun
e22513c237
btcutil: update to chaincfg/chainhash/v1.1.0 2023-12-15 14:42:29 -08:00
ClaytonNorthey92
d988b86027 Added test for client.GetChainTxStatsAsync() in rpcclient. This sets up a test websocket server to run the tests. Also, ensure these are run within a timeout, since they rely on concurrency 2023-11-02 16:16:11 -04:00
yyforyongyu
d4f519f5dc
gomod: clean go mod files
Resulted from running `go mod tify`.
2023-09-04 12:04:16 +08:00
Olaoluwa Osuntokun
0aaa7c5e7b
Merge pull request #1979 from kcalvinalvin/merkle-calc-fast
blockchain, integration, mining, main: Rolling merkle root calculation
2023-08-10 15:05:40 -07:00
Calvin Kim
3ba9feeeee blockchain, btcutil/bloom: BuildMerkleTreeStore returns chainhash.Hash
BuildMerkleTreeStore used to return a pointer, but it is changed to
return a chainhash.Hash directly.  This allows the compiler to make
optimizations in some cases and avoids a memory allocation.
2023-08-03 15:23:17 +09:00