@@ -23,6 +23,7 @@ use crate::storage::model::BitcoinWithdrawalOutput;
23
23
use crate :: storage:: model:: QualifiedRequestId ;
24
24
use crate :: storage:: model:: SignerVotes ;
25
25
use crate :: storage:: DbRead ;
26
+ use crate :: DEPOSIT_DUST_LIMIT ;
26
27
use crate :: DEPOSIT_LOCKTIME_BLOCK_BUFFER ;
27
28
28
29
use super :: utxo:: DepositRequest ;
@@ -264,7 +265,7 @@ impl BitcoinPreSignRequest {
264
265
. deposit_reports
265
266
. get ( & key)
266
267
// This should never happen because we have already validated that we have all the reports.
267
- . ok_or ( InputValidationResult :: Unknown . into_error ( btc_ctx) ) ?;
268
+ . ok_or_else ( || InputValidationResult :: Unknown . into_error ( btc_ctx) ) ?;
268
269
deposits. push ( ( report. to_deposit_request ( votes) , report. clone ( ) ) ) ;
269
270
}
270
271
@@ -273,7 +274,7 @@ impl BitcoinPreSignRequest {
273
274
. withdrawal_reports
274
275
. get ( id)
275
276
// This should never happen because we have already validated that we have all the reports.
276
- . ok_or ( WithdrawalValidationResult :: Unknown . into_error ( btc_ctx) ) ?;
277
+ . ok_or_else ( || WithdrawalValidationResult :: Unknown . into_error ( btc_ctx) ) ?;
277
278
withdrawals. push ( ( report. to_withdrawal_request ( votes) , report. clone ( ) ) ) ;
278
279
}
279
280
@@ -508,6 +509,9 @@ impl SbtcReports {
508
509
pub enum InputValidationResult {
509
510
/// The deposit request passed validation
510
511
Ok ,
512
+ /// The deposit request amount, less the fees, would be rejected from
513
+ /// the smart contract during the complete-deposit contract call.
514
+ MintAmountBelowDustLimit ,
511
515
/// The deposit request amount exceeds the allowed per-deposit cap.
512
516
AmountTooHigh ,
513
517
/// The assessed fee exceeds the max-fee in the deposit request.
@@ -730,6 +734,10 @@ impl DepositRequestReport {
730
734
return InputValidationResult :: FeeTooHigh ;
731
735
}
732
736
737
+ if self . amount . saturating_sub ( assessed_fee. to_sat ( ) ) < DEPOSIT_DUST_LIMIT {
738
+ return InputValidationResult :: MintAmountBelowDustLimit ;
739
+ }
740
+
733
741
// Let's check whether we rejected this deposit.
734
742
match self . can_accept {
735
743
Some ( true ) => ( ) ,
@@ -1063,6 +1071,38 @@ mod tests {
1063
1071
status: InputValidationResult :: FeeTooHigh ,
1064
1072
chain_tip_height: 2 ,
1065
1073
} ; "one-sat-too-high-fee-amount" ) ]
1074
+ #[ test_case( DepositReportErrorMapping {
1075
+ report: DepositRequestReport {
1076
+ status: DepositConfirmationStatus :: Confirmed ( 0 , BitcoinBlockHash :: from( [ 0 ; 32 ] ) ) ,
1077
+ can_sign: Some ( true ) ,
1078
+ can_accept: Some ( true ) ,
1079
+ amount: TX_FEE . to_sat( ) + DEPOSIT_DUST_LIMIT - 1 ,
1080
+ max_fee: TX_FEE . to_sat( ) ,
1081
+ lock_time: LockTime :: from_height( DEPOSIT_LOCKTIME_BLOCK_BUFFER + 3 ) ,
1082
+ outpoint: OutPoint :: null( ) ,
1083
+ deposit_script: ScriptBuf :: new( ) ,
1084
+ reclaim_script: ScriptBuf :: new( ) ,
1085
+ signers_public_key: * sbtc:: UNSPENDABLE_TAPROOT_KEY ,
1086
+ } ,
1087
+ status: InputValidationResult :: MintAmountBelowDustLimit ,
1088
+ chain_tip_height: 2 ,
1089
+ } ; "one-sat-under-dust-amount" ) ]
1090
+ #[ test_case( DepositReportErrorMapping {
1091
+ report: DepositRequestReport {
1092
+ status: DepositConfirmationStatus :: Confirmed ( 0 , BitcoinBlockHash :: from( [ 0 ; 32 ] ) ) ,
1093
+ can_sign: Some ( true ) ,
1094
+ can_accept: Some ( true ) ,
1095
+ amount: TX_FEE . to_sat( ) + DEPOSIT_DUST_LIMIT ,
1096
+ max_fee: TX_FEE . to_sat( ) ,
1097
+ lock_time: LockTime :: from_height( DEPOSIT_LOCKTIME_BLOCK_BUFFER + 3 ) ,
1098
+ outpoint: OutPoint :: null( ) ,
1099
+ deposit_script: ScriptBuf :: new( ) ,
1100
+ reclaim_script: ScriptBuf :: new( ) ,
1101
+ signers_public_key: * sbtc:: UNSPENDABLE_TAPROOT_KEY ,
1102
+ } ,
1103
+ status: InputValidationResult :: Ok ,
1104
+ chain_tip_height: 2 ,
1105
+ } ; "at-dust-amount" ) ]
1066
1106
#[ test_case( DepositReportErrorMapping {
1067
1107
report: DepositRequestReport {
1068
1108
status: DepositConfirmationStatus :: Confirmed ( 0 , BitcoinBlockHash :: from( [ 0 ; 32 ] ) ) ,
0 commit comments