Skip to content

Commit 2ca4f4c

Browse files
authored
Merge pull request #1901 from Roasbeef/v-0-22-branch
release: create release branch for v0.22.2 to backport block parsing issue
2 parents d40789f + ba2fba5 commit 2ca4f4c

File tree

6 files changed

+44
-31
lines changed

6 files changed

+44
-31
lines changed

btcec/signature.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ func recoverKeyFromSignature(curve *KoblitzCurve, sig *Signature, msg []byte,
353353
// step to prevent the jacobian conversion back and forth.
354354
Qx, Qy := curve.Add(sRx, sRy, minuseGx, minuseGy)
355355

356+
if Qx.Sign() == 0 && Qy.Sign() == 0 {
357+
return nil, errors.New("point (Qx, Qy) equals the point at infinity")
358+
}
359+
356360
return &PublicKey{
357361
Curve: curve,
358362
X: Qx,

mempool/mempool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ func TestOrphanReject(t *testing.T) {
560560

561561
// Ensure no transactions were reported as accepted.
562562
if len(acceptedTxns) != 0 {
563-
t.Fatal("ProcessTransaction: reported %d accepted "+
563+
t.Fatalf("ProcessTransaction: reported %d accepted "+
564564
"transactions from failed orphan attempt",
565565
len(acceptedTxns))
566566
}

mempool/policy.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,10 @@ func checkPkScriptStandard(pkScript []byte, scriptClass txscript.ScriptClass) er
172172
return nil
173173
}
174174

175-
// isDust returns whether or not the passed transaction output amount is
176-
// considered dust or not based on the passed minimum transaction relay fee.
177-
// Dust is defined in terms of the minimum transaction relay fee. In
178-
// particular, if the cost to the network to spend coins is more than 1/3 of the
179-
// minimum transaction relay fee, it is considered dust.
180-
func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
181-
// Unspendable outputs are considered dust.
182-
if txscript.IsUnspendable(txOut.PkScript) {
183-
return true
184-
}
185-
175+
// GetDustThreshold calculates the dust limit for a *wire.TxOut by taking the
176+
// size of a typical spending transaction and multiplying it by 3 to account
177+
// for the minimum dust relay fee of 3000sat/kvb.
178+
func GetDustThreshold(txOut *wire.TxOut) int64 {
186179
// The total serialized size consists of the output and the associated
187180
// input script to redeem it. Since there is no input script
188181
// to redeem it yet, use the minimum size of a typical input script.
@@ -253,6 +246,20 @@ func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
253246
totalSize += 107
254247
}
255248

249+
return 3 * int64(totalSize)
250+
}
251+
252+
// IsDust returns whether or not the passed transaction output amount is
253+
// considered dust or not based on the passed minimum transaction relay fee.
254+
// Dust is defined in terms of the minimum transaction relay fee. In
255+
// particular, if the cost to the network to spend coins is more than 1/3 of the
256+
// minimum transaction relay fee, it is considered dust.
257+
func IsDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
258+
// Unspendable outputs are considered dust.
259+
if txscript.IsUnspendable(txOut.PkScript) {
260+
return true
261+
}
262+
256263
// The output is considered dust if the cost to the network to spend the
257264
// coins is more than 1/3 of the minimum free transaction relay fee.
258265
// minFreeTxRelayFee is in Satoshi/KB, so multiply by 1000 to
@@ -265,7 +272,7 @@ func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
265272
//
266273
// The following is equivalent to (value/totalSize) * (1/3) * 1000
267274
// without needing to do floating point math.
268-
return txOut.Value*1000/(3*int64(totalSize)) < int64(minRelayTxFee)
275+
return txOut.Value*1000/GetDustThreshold(txOut) < int64(minRelayTxFee)
269276
}
270277

271278
// checkTransactionStandard performs a series of checks on a transaction to
@@ -351,7 +358,7 @@ func checkTransactionStandard(tx *btcutil.Tx, height int32,
351358
// "dust".
352359
if scriptClass == txscript.NullDataTy {
353360
numNullDataOutputs++
354-
} else if isDust(txOut, minRelayTxFee) {
361+
} else if IsDust(txOut, minRelayTxFee) {
355362
str := fmt.Sprintf("transaction output %d: payment "+
356363
"of %d is dust", i, txOut.Value)
357364
return txRuleError(wire.RejectDust, str)

mempool/policy_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func TestCheckPkScriptStandard(t *testing.T) {
204204
}
205205
}
206206

207-
// TestDust tests the isDust API.
207+
// TestDust tests the IsDust API.
208208
func TestDust(t *testing.T) {
209209
pkScript := []byte{0x76, 0xa9, 0x21, 0x03, 0x2f, 0x7e, 0x43,
210210
0x0a, 0xa4, 0xc9, 0xd1, 0x59, 0x43, 0x7e, 0x84, 0xb9,
@@ -268,7 +268,7 @@ func TestDust(t *testing.T) {
268268
},
269269
}
270270
for _, test := range tests {
271-
res := isDust(&test.txOut, test.relayFee)
271+
res := IsDust(&test.txOut, test.relayFee)
272272
if res != test.isDust {
273273
t.Fatalf("Dust test '%s' failed: want %v got %v",
274274
test.name, test.isDust, res)

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr
1818
const (
1919
appMajor uint = 0
2020
appMinor uint = 22
21-
appPatch uint = 1
21+
appPatch uint = 2
2222

2323
// appPreRelease MUST only contain characters from semanticAlphabet
2424
// per the semantic versioning spec.

wire/msgtx.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,28 @@ const (
103103
maxWitnessItemsPerInput = 500000
104104

105105
// maxWitnessItemSize is the maximum allowed size for an item within
106-
// an input's witness data. This number is derived from the fact that
107-
// for script validation, each pushed item onto the stack must be less
108-
// than 10k bytes.
109-
maxWitnessItemSize = 11000
106+
// an input's witness data. This value is bounded by the largest
107+
// possible block size, post segwit v1 (taproot).
108+
maxWitnessItemSize = 4_000_000
110109
)
111110

112111
// TxFlagMarker is the first byte of the FLAG field in a bitcoin tx
113112
// message. It allows decoders to distinguish a regular serialized
114113
// transaction from one that would require a different parsing logic.
115114
//
116115
// Position of FLAG in a bitcoin tx message:
117-
// ┌─────────┬────────────────────┬─────────────┬─────┐
118-
// │ VERSION │ FLAG │ TX-IN-COUNT │ ... │
119-
// │ 4 bytes │ 2 bytes (optional) │ varint │ │
120-
// └─────────┴────────────────────┴─────────────┴─────┘
116+
//
117+
// ┌─────────┬────────────────────┬─────────────┬─────┐
118+
// │ VERSION │ FLAG │ TX-IN-COUNT │ ... │
119+
// │ 4 bytes │ 2 bytes (optional) │ varint │ │
120+
// └─────────┴────────────────────┴─────────────┴─────┘
121121
//
122122
// Zooming into the FLAG field:
123-
// ┌── FLAG ─────────────┬────────┐
124-
// │ TxFlagMarker (0x00) │ TxFlag │
125-
// │ 1 byte │ 1 byte │
126-
// └─────────────────────┴────────┘
123+
//
124+
// ┌── FLAG ─────────────┬────────┐
125+
// │ TxFlagMarker (0x00) │ TxFlag │
126+
// │ 1 byte │ 1 byte │
127+
// └─────────────────────┴────────┘
127128
const TxFlagMarker = 0x00
128129

129130
// TxFlag is the second byte of the FLAG field in a bitcoin tx message.
@@ -586,8 +587,9 @@ func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
586587
// item itself.
587588
txin.Witness = make([][]byte, witCount)
588589
for j := uint64(0); j < witCount; j++ {
589-
txin.Witness[j], err = readScript(r, pver,
590-
maxWitnessItemSize, "script witness item")
590+
txin.Witness[j], err = readScript(
591+
r, pver, maxWitnessItemSize, "script witness item",
592+
)
591593
if err != nil {
592594
returnScriptBuffers()
593595
return err

0 commit comments

Comments
 (0)