Skip to content

Commit ed9c8c5

Browse files
committed
Add server-side check for insanely high fees.
Goal is to prevent a situation like decred/dcrwallet#2000 from happening again even if users are running the buggy client code.
1 parent e0e1340 commit ed9c8c5

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

coinjoin/coinjoin.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ func feeForSerializeSize(relayFeePerKb int64, txSerializeSize int) int64 {
219219
return fee
220220
}
221221

222+
func paysHighFees(relayFeePerKb, fee int64, txSerializeSize int) bool {
223+
maxFee := feeForSerializeSize(50*relayFeePerKb, txSerializeSize)
224+
return fee > maxFee
225+
}
226+
222227
func (t *Tx) ValidateUnmixed(unmixed []byte, mcount int) error {
223228
var fee int64
224229
other := new(wire.MsgTx)
@@ -254,10 +259,15 @@ func (t *Tx) ValidateUnmixed(unmixed []byte, mcount int) error {
254259
for i := 0; i < mcount; i++ {
255260
other.AddTxOut(bogusMixedOut)
256261
}
257-
requiredFee := feeForSerializeSize(t.feeRate, other.SerializeSize())
262+
size := other.SerializeSize()
263+
requiredFee := feeForSerializeSize(t.feeRate, size)
258264
if fee < requiredFee {
259265
return errors.New("coinjoin: unmixed transaction does not pay enough network fees")
260266
}
267+
if paysHighFees(t.feeRate, fee, size) {
268+
return errors.New("coinjoin: unmixed transaction pays insanely high fees")
269+
}
270+
261271
return nil
262272
}
263273

integration/honest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func TestHonest(t *testing.T) {
196196
i := i
197197
go func() {
198198
input := &wire.TxIn{ValueIn: inputValue * 1e8}
199-
change := &wire.TxOut{Value: 1e8 - int64(1+i)*0.001e8, PkScript: change}
199+
change := &wire.TxOut{Value: 1e8 - 0.0001e8 + int64(i+1), PkScript: change}
200200
con := newConfirmer(input, change)
201201
conn, err := tls.Dial("tcp", s.Addr, nettest.ClientTLS)
202202
if err != nil {

0 commit comments

Comments
 (0)