diff --git a/pkg/chains/chains.go b/pkg/chains/chains.go index 651051da3c..8ac188e8fe 100644 --- a/pkg/chains/chains.go +++ b/pkg/chains/chains.go @@ -122,7 +122,8 @@ func GoerliLocalnetChain() Chain { } } -func BtcDustOffset() int64 { +// BtcNonceMarkOffset is the offset satoshi amount to calculate the nonce mark output +func BtcNonceMarkOffset() int64 { return 2000 } diff --git a/pkg/chains/conversion.go b/pkg/chains/conversion.go index 6a6a6f4091..200061c3ae 100644 --- a/pkg/chains/conversion.go +++ b/pkg/chains/conversion.go @@ -11,7 +11,7 @@ import ( // A very special value to mark current nonce in UTXO func NonceMarkAmount(nonce uint64) int64 { // #nosec G701 always in range - return int64(nonce) + BtcDustOffset() // +2000 to avoid being a dust rejection + return int64(nonce) + BtcNonceMarkOffset() } // HashToString convert hash bytes to string diff --git a/pkg/constant/constant.go b/pkg/constant/constant.go index 447eca98e5..62f898e85d 100644 --- a/pkg/constant/constant.go +++ b/pkg/constant/constant.go @@ -4,8 +4,13 @@ const ( // DonationMessage is the message for donation transactions // Transaction sent to the TSS or ERC20 Custody address containing this message are considered as a donation DonationMessage = "I am rich!" + // CmdWhitelistERC20 is used for CCTX of type cmd to give the instruction to the TSS to whitelist an ERC20 on an exeternal chain CmdWhitelistERC20 = "cmd_whitelist_erc20" + // CmdMigrateTssFunds is used for CCTX of type cmd to give the instruction to the TSS to transfer its funds on a new address CmdMigrateTssFunds = "cmd_migrate_tss_funds" + + // BTCWithdrawalDustAmount is the minimum satoshis that can be withdrawn from zEVM to avoid outbound dust output + BTCWithdrawalDustAmount = 1000 ) diff --git a/zetaclient/bitcoin/bitcoin_client.go b/zetaclient/bitcoin/bitcoin_client.go index 6fe3b75040..515236e545 100644 --- a/zetaclient/bitcoin/bitcoin_client.go +++ b/zetaclient/bitcoin/bitcoin_client.go @@ -25,6 +25,7 @@ import ( "github.com/rs/zerolog" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/coin" + "github.com/zeta-chain/zetacore/pkg/constant" "github.com/zeta-chain/zetacore/pkg/proofs" "github.com/zeta-chain/zetacore/x/crosschain/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" @@ -1403,12 +1404,11 @@ func (ob *BTCChainClient) checkTSSVout(params *types.OutboundTxParams, vouts []b return fmt.Errorf("checkTSSVout: output address %s not match params receiver %s", receiverVout, params.Receiver) } - // hotfix/v17.0.1: check against 2000 satoshis because we've adjusted the dust amount to 2000 satoshi. + // hotfix/v17.0.1: check against 'BTCWithdrawalDustAmount' because we've adjusted the dust amount to 1000 satoshi. // #nosec G701 always in range - dustAmount := uint64(chains.BtcDustOffset()) - if params.Amount.Uint64() < dustAmount { - if amount != chains.BtcDustOffset() { - return fmt.Errorf("checkTSSVout: output amount %d not match dust amount %d", amount, dustAmount) + if params.Amount.Uint64() < constant.BTCWithdrawalDustAmount { + if amount != constant.BTCWithdrawalDustAmount { + return fmt.Errorf("checkTSSVout: output amount %d not match dust amount %d", amount, constant.BTCWithdrawalDustAmount) } ob.logger.OutTx.Info().Msgf("checkTSSVout: amount was successfully modified to %d", amount) continue // move to the 3rd vout diff --git a/zetaclient/zetacore_observer.go b/zetaclient/zetacore_observer.go index 96aa5f4a6c..63b7c06c9e 100644 --- a/zetaclient/zetacore_observer.go +++ b/zetaclient/zetacore_observer.go @@ -9,6 +9,7 @@ import ( ethcommon "github.com/ethereum/go-ethereum/common" "github.com/rs/zerolog" "github.com/zeta-chain/zetacore/pkg/chains" + "github.com/zeta-chain/zetacore/pkg/constant" "github.com/zeta-chain/zetacore/x/crosschain/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" appcontext "github.com/zeta-chain/zetacore/zetaclient/app_context" @@ -351,12 +352,12 @@ func (co *CoreObserver) scheduleCctxBTC( break } - // hotfix/v17.0.1: before scheduling keysign, we adjust tiny amount to 2000 satoshi to avoid dust output + // hotfix/v17.0.1: before scheduling keysign, we adjust tiny amount to 1000 satoshi to avoid dust output // #nosec G701 always in range - dustAmount := uint64(chains.BtcDustOffset()) - if params.Amount.Uint64() < dustAmount { - params.Amount = sdkmath.NewUint(dustAmount) - co.logger.ZetaChainWatcher.Warn().Msgf("scheduleCctxBTC: outtx %s amount %d is too small, adjusted to %d", outTxID, params.Amount, chains.BtcDustOffset()) + if params.Amount.Uint64() < constant.BTCWithdrawalDustAmount { + params.Amount = sdkmath.NewUint(constant.BTCWithdrawalDustAmount) + co.logger.ZetaChainWatcher.Warn().Msgf( + "scheduleCctxBTC: outtx %s amount %d is too small, adjusted to %d", outTxID, params.Amount, constant.BTCWithdrawalDustAmount) } // try confirming the outtx or scheduling a keysign