Skip to content

Commit c5fab07

Browse files
authored
Fix incorrect spend amount is zero checks. should check that spend amount equals sum of additional fees (#1449)
1 parent 733edf7 commit c5fab07

File tree

3 files changed

+155
-63
lines changed

3 files changed

+155
-63
lines changed

lib/block_view_stake.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,10 +1154,10 @@ func (bc *Blockchain) CreateStakeTxn(
11541154
)
11551155
}
11561156

1157-
// Sanity-check that the spendAmount is zero.
1158-
if spendAmount != 0 {
1157+
// Sanity-check that the spendAmount equals the sum of the additional outputs.
1158+
if err = amountEqualsAdditionalOutputs(spendAmount, additionalOutputs); err != nil {
11591159
return nil, 0, 0, 0, fmt.Errorf(
1160-
"Blockchain.CreateStakeTxn: spend amount is non-zero: %d", spendAmount,
1160+
"Blockchain.CreateStakeTxn: %v", err,
11611161
)
11621162
}
11631163
return txn, totalInput, changeAmount, fees, nil
@@ -1226,10 +1226,10 @@ func (bc *Blockchain) CreateUnstakeTxn(
12261226
)
12271227
}
12281228

1229-
// Sanity-check that the spendAmount is zero.
1230-
if spendAmount != 0 {
1229+
// Sanity-check that the spendAmount equals the sum of the additional outputs.
1230+
if err = amountEqualsAdditionalOutputs(spendAmount, additionalOutputs); err != nil {
12311231
return nil, 0, 0, 0, fmt.Errorf(
1232-
"Blockchain.CreateUnstakeTxn: spend amount is non-zero: %d", spendAmount,
1232+
"Blockchain.CreateUnstakeTxn: %v", err,
12331233
)
12341234
}
12351235
return txn, totalInput, changeAmount, fees, nil
@@ -1298,10 +1298,10 @@ func (bc *Blockchain) CreateUnlockStakeTxn(
12981298
)
12991299
}
13001300

1301-
// Sanity-check that the spendAmount is zero.
1302-
if spendAmount != 0 {
1301+
// Sanity-check that the spendAmount equals the sum of the additional outputs.
1302+
if err = amountEqualsAdditionalOutputs(spendAmount, additionalOutputs); err != nil {
13031303
return nil, 0, 0, 0, fmt.Errorf(
1304-
"Blockchain.CreateUnlockStakeTxn: spend amount is non-zero: %d", spendAmount,
1304+
"Blockchain.CreateUnlockStakeTxn: %v", err,
13051305
)
13061306
}
13071307
return txn, totalInput, changeAmount, fees, nil

lib/block_view_validator.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,10 +1060,10 @@ func (bc *Blockchain) CreateRegisterAsValidatorTxn(
10601060
)
10611061
}
10621062

1063-
// Sanity-check that the spendAmount is zero.
1064-
if spendAmount != 0 {
1063+
// Sanity-check that the spendAmount equals the sum of the additional outputs.
1064+
if err = amountEqualsAdditionalOutputs(spendAmount, additionalOutputs); err != nil {
10651065
return nil, 0, 0, 0, fmt.Errorf(
1066-
"Blockchain.CreateRegisterAsValidatorTxn: spend amount is non-zero: %d", spendAmount,
1066+
"Blockchain.CreateRegisterAsValidatorTxn: %v", err,
10671067
)
10681068
}
10691069
return txn, totalInput, changeAmount, fees, nil
@@ -1132,10 +1132,10 @@ func (bc *Blockchain) CreateUnregisterAsValidatorTxn(
11321132
)
11331133
}
11341134

1135-
// Sanity-check that the spendAmount is zero.
1136-
if spendAmount != 0 {
1135+
// Sanity-check that the spendAmount equals the sum of the additional outputs.
1136+
if err = amountEqualsAdditionalOutputs(spendAmount, additionalOutputs); err != nil {
11371137
return nil, 0, 0, 0, fmt.Errorf(
1138-
"Blockchain.CreateUnregisterAsValidatorTxn: spend amount is non-zero: %d", spendAmount,
1138+
"Blockchain.CreateUnregisterAsValidatorTxn: %v", err,
11391139
)
11401140
}
11411141
return txn, totalInput, changeAmount, fees, nil
@@ -1204,10 +1204,10 @@ func (bc *Blockchain) CreateUnjailValidatorTxn(
12041204
)
12051205
}
12061206

1207-
// Sanity-check that the spendAmount is zero.
1208-
if spendAmount != 0 {
1207+
// Sanity-check that the spendAmount equals the sum of the additional outputs.
1208+
if err = amountEqualsAdditionalOutputs(spendAmount, additionalOutputs); err != nil {
12091209
return nil, 0, 0, 0, fmt.Errorf(
1210-
"Blockchain.CreateUnjailValidatorTxn: spend amount is non-zero: %d", spendAmount,
1210+
"Blockchain.CreateUnjailValidatorTxn: %v", err,
12111211
)
12121212
}
12131213
return txn, totalInput, changeAmount, fees, nil

0 commit comments

Comments
 (0)