Skip to content

Commit

Permalink
reduce dust btc amount to 1000 satoshis and renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Jun 6, 2024
1 parent b40b511 commit 8a34fbe
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion pkg/chains/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/chains/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
10 changes: 5 additions & 5 deletions zetaclient/bitcoin/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions zetaclient/zetacore_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8a34fbe

Please sign in to comment.