Skip to content

Commit

Permalink
fix some issues in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Feb 22, 2024
1 parent abb98e9 commit 5086694
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 62 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
### Features

*[1728] (https://github.com/zeta-chain/node/pull/1728) - allow aborted transactions to be refunded by minting tokens to zEvm.
*[1789] (https://github.com/zeta-chain/node/pull/1789) - block cross-chain transactions that involved banned addresses

### Refactor
* [1766](https://github.com/zeta-chain/node/pull/1766) - Refactors the `PostTxProcessing` EVM hook functionality to deal with invalid withdraw events
Expand Down
2 changes: 2 additions & 0 deletions cmd/zetaclientd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/zetaclient/config"
"github.com/zeta-chain/zetacore/zetaclient/testutils"
)

var InitCmd = &cobra.Command{
Expand Down Expand Up @@ -95,6 +96,7 @@ func Initialize(_ *cobra.Command, _ []string) error {
configData.KeyringBackend = config.KeyringBackend(initArgs.KeyringBackend)
configData.HsmMode = initArgs.HsmMode
configData.HsmHotKey = initArgs.HsmHotKey
configData.ComplianceConfig = testutils.ComplianceConfigTest()

//Save config file
return config.Save(&configData, rootArgs.zetaCoreHome)
Expand Down
130 changes: 84 additions & 46 deletions zetaclient/bitcoin/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,13 +513,6 @@ func (ob *BTCChainClient) IsSendOutTxProcessed(cctx *types.CrossChainTx, logger
res, included := ob.includedTxResults[outTxID]
ob.Mu.Unlock()

// compliance check, special handling the cancelled cctx
banned := clientcommon.IsCctxBanned(cctx)
if banned {
params.Amount = cosmosmath.ZeroUint() // use 0 to bypass the amount check
logger.Warn().Msgf("IsSendOutTxProcessed: special handling banned outTx %s", outTxID)
}

if !included {
if !broadcasted {
return false, false, nil
Expand All @@ -534,7 +527,7 @@ func (ob *BTCChainClient) IsSendOutTxProcessed(cctx *types.CrossChainTx, logger
}

// Try including this outTx broadcasted by myself
txResult, inMempool := ob.checkIncludedTx(txnHash, params)
txResult, inMempool := ob.checkIncludedTx(cctx, txnHash)
if txResult == nil { // check failed, try again next time
return false, false, nil

Check warning on line 532 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L530-L532

Added lines #L530 - L532 were not covered by tests
} else if inMempool { // still in mempool (should avoid unnecessary Tss keysign)
Expand Down Expand Up @@ -1107,16 +1100,9 @@ func (ob *BTCChainClient) observeOutTx() {
ob.logger.ObserveOutTx.Info().Err(err).Msgf("observeOutTx: can't find cctx for nonce %d", tracker.Nonce)
break
}
params := *cctx.GetCurrentOutTxParam()

// compliance check, special handling the cancelled cctx
banned := clientcommon.IsCctxBanned(cctx)
if banned {
params.Amount = cosmosmath.ZeroUint() // use 0 to bypass the amount check
ob.logger.ObserveOutTx.Warn().Msgf("observeOutTx: special handling banned outTx %s", outTxID)
}
if tracker.Nonce != params.OutboundTxTssNonce { // Tanmay: it doesn't hurt to check
ob.logger.ObserveOutTx.Error().Msgf("observeOutTx: tracker nonce %d not match cctx nonce %d", tracker.Nonce, params.OutboundTxTssNonce)
nonce := cctx.GetCurrentOutTxParam().OutboundTxTssNonce
if tracker.Nonce != nonce { // Tanmay: it doesn't hurt to check
ob.logger.ObserveOutTx.Error().Msgf("observeOutTx: tracker nonce %d not match cctx nonce %d", tracker.Nonce, nonce)

Check warning on line 1105 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1103-L1105

Added lines #L1103 - L1105 were not covered by tests
break
}
if len(tracker.HashList) > 1 {
Expand All @@ -1127,7 +1113,7 @@ func (ob *BTCChainClient) observeOutTx() {
txCount := 0
var txResult *btcjson.GetTransactionResult
for _, txHash := range tracker.HashList {
result, inMempool := ob.checkIncludedTx(txHash.TxHash, params)
result, inMempool := ob.checkIncludedTx(cctx, txHash.TxHash)

Check warning on line 1116 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1116

Added line #L1116 was not covered by tests
if result != nil && !inMempool { // included
txCount++
txResult = result
Expand Down Expand Up @@ -1155,8 +1141,8 @@ func (ob *BTCChainClient) observeOutTx() {

// checkIncludedTx checks if a txHash is included and returns (txResult, inMempool)
// Note: if txResult is nil, then inMempool flag should be ignored.
func (ob *BTCChainClient) checkIncludedTx(txHash string, params types.OutboundTxParams) (*btcjson.GetTransactionResult, bool) {
outTxID := ob.GetTxID(params.OutboundTxTssNonce)
func (ob *BTCChainClient) checkIncludedTx(cctx *types.CrossChainTx, txHash string) (*btcjson.GetTransactionResult, bool) {
outTxID := ob.GetTxID(cctx.GetCurrentOutTxParam().OutboundTxTssNonce)

Check warning on line 1145 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1144-L1145

Added lines #L1144 - L1145 were not covered by tests
hash, getTxResult, err := ob.GetTxResultByHash(txHash)
if err != nil {
ob.logger.ObserveOutTx.Error().Err(err).Msgf("checkIncludedTx: error GetTxResultByHash: %s", txHash)
Expand All @@ -1167,7 +1153,7 @@ func (ob *BTCChainClient) checkIncludedTx(txHash string, params types.OutboundTx
return nil, false
}
if getTxResult.Confirmations >= 0 { // check included tx only
err = ob.checkTssOutTxResult(hash, getTxResult, params, params.OutboundTxTssNonce)
err = ob.checkTssOutTxResult(cctx, hash, getTxResult)

Check warning on line 1156 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1156

Added line #L1156 was not covered by tests
if err != nil {
ob.logger.ObserveOutTx.Error().Err(err).Msgf("checkIncludedTx: error verify bitcoin outTx %s outTxID %s", txHash, outTxID)
return nil, false
Expand Down Expand Up @@ -1228,7 +1214,9 @@ func (ob *BTCChainClient) removeIncludedTx(nonce uint64) {
// - check if all inputs are segwit && TSS inputs
//
// Returns: true if outTx passes basic checks.
func (ob *BTCChainClient) checkTssOutTxResult(hash *chainhash.Hash, res *btcjson.GetTransactionResult, params types.OutboundTxParams, nonce uint64) error {
func (ob *BTCChainClient) checkTssOutTxResult(cctx *types.CrossChainTx, hash *chainhash.Hash, res *btcjson.GetTransactionResult) error {
params := cctx.GetCurrentOutTxParam()
nonce := params.OutboundTxTssNonce

Check warning on line 1219 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1217-L1219

Added lines #L1217 - L1219 were not covered by tests
rawResult, err := ob.getRawTxResult(hash, res)
if err != nil {
return errors.Wrapf(err, "checkTssOutTxResult: error GetRawTxResultByHash %s", hash.String())
Expand All @@ -1237,7 +1225,13 @@ func (ob *BTCChainClient) checkTssOutTxResult(hash *chainhash.Hash, res *btcjson
if err != nil {
return errors.Wrapf(err, "checkTssOutTxResult: invalid TSS Vin in outTx %s nonce %d", hash, nonce)
}
err = ob.checkTSSVout(rawResult.Vout, params, nonce)

// differentiate between normal and banned cctx
if clientcommon.IsCctxBanned(cctx) {
err = ob.checkTSSVoutCancelled(params, rawResult.Vout)
} else {
err = ob.checkTSSVout(params, rawResult.Vout)

Check warning on line 1233 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1230-L1233

Added lines #L1230 - L1233 were not covered by tests
}
if err != nil {
return errors.Wrapf(err, "checkTssOutTxResult: invalid TSS Vout in outTx %s nonce %d", hash, nonce)
}
Expand Down Expand Up @@ -1316,41 +1310,50 @@ func (ob *BTCChainClient) checkTSSVin(vins []btcjson.Vin, nonce uint64) error {
return nil
}

// DecodeP2WPKHVout decodes receiver and amount from P2WPKH output
func (ob *BTCChainClient) DecodeP2WPKHVout(vout btcjson.Vout) (string, int64, error) {
amount, err := GetSatoshis(vout.Value)
if err != nil {
return "", 0, errors.Wrap(err, "error getting satoshis")

Check warning on line 1317 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1314-L1317

Added lines #L1314 - L1317 were not covered by tests
}
// decode P2WPKH scriptPubKey
scriptPubKey := vout.ScriptPubKey.Hex
decodedScriptPubKey, err := hex.DecodeString(scriptPubKey)
if err != nil {
return "", 0, errors.Wrapf(err, "error decoding scriptPubKey %s", scriptPubKey)

Check warning on line 1323 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1320-L1323

Added lines #L1320 - L1323 were not covered by tests
}
if len(decodedScriptPubKey) != 22 { // P2WPKH script
return "", 0, fmt.Errorf("unsupported scriptPubKey: %s", scriptPubKey)

Check warning on line 1326 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1325-L1326

Added lines #L1325 - L1326 were not covered by tests
}
witnessVersion := decodedScriptPubKey[0]
witnessProgram := decodedScriptPubKey[2:]
if witnessVersion != 0 {
return "", 0, fmt.Errorf("unsupported witness in scriptPubKey %s", scriptPubKey)

Check warning on line 1331 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1328-L1331

Added lines #L1328 - L1331 were not covered by tests
}
recvAddress, err := ob.chain.BTCAddressFromWitnessProgram(witnessProgram)
if err != nil {
return "", 0, errors.Wrapf(err, "error getting receiver from witness program %s", witnessProgram)

Check warning on line 1335 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1333-L1335

Added lines #L1333 - L1335 were not covered by tests
}
return recvAddress, amount, nil

Check warning on line 1337 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1337

Added line #L1337 was not covered by tests
}

// checkTSSVout vout is valid if:
// - The first output is the nonce-mark
// - The second output is the correct payment to recipient
// - The third output is the change to TSS (optional)
func (ob *BTCChainClient) checkTSSVout(vouts []btcjson.Vout, params types.OutboundTxParams, nonce uint64) error {
func (ob *BTCChainClient) checkTSSVout(params *types.OutboundTxParams, vouts []btcjson.Vout) error {

Check warning on line 1344 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1344

Added line #L1344 was not covered by tests
// vouts: [nonce-mark, payment to recipient, change to TSS (optional)]
if !(len(vouts) == 2 || len(vouts) == 3) {
return fmt.Errorf("checkTSSVout: invalid number of vouts: %d", len(vouts))
}

nonce := params.OutboundTxTssNonce

Check warning on line 1350 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1350

Added line #L1350 was not covered by tests
tssAddress := ob.Tss.BTCAddress()
for _, vout := range vouts {
amount, err := GetSatoshis(vout.Value)
if err != nil {
return errors.Wrap(err, "checkTSSVout: error getting satoshis")
}
// decode P2WPKH scriptPubKey
scriptPubKey := vout.ScriptPubKey.Hex
decodedScriptPubKey, err := hex.DecodeString(scriptPubKey)
if err != nil {
return errors.Wrapf(err, "checkTSSVout: error decoding scriptPubKey %s", scriptPubKey)
}
if len(decodedScriptPubKey) != 22 { // P2WPKH script
return fmt.Errorf("checkTSSVout: unsupported scriptPubKey: %s", scriptPubKey)
}
witnessVersion := decodedScriptPubKey[0]
witnessProgram := decodedScriptPubKey[2:]
if witnessVersion != 0 {
return fmt.Errorf("checkTSSVout: unsupported witness in scriptPubKey %s", scriptPubKey)
}
recvAddress, err := ob.chain.BTCAddressFromWitnessProgram(witnessProgram)
recvAddress, amount, err := ob.DecodeP2WPKHVout(vout)

Check warning on line 1353 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1353

Added line #L1353 was not covered by tests
if err != nil {
return errors.Wrapf(err, "checkTSSVout: error getting receiver from witness program %s", witnessProgram)
return errors.Wrap(err, "checkTSSVout: error decoding P2WPKH vout")

Check warning on line 1355 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1355

Added line #L1355 was not covered by tests
}

// 1st vout: nonce-mark
if vout.N == 0 {
if recvAddress != tssAddress {
Expand Down Expand Up @@ -1380,6 +1383,41 @@ func (ob *BTCChainClient) checkTSSVout(vouts []btcjson.Vout, params types.Outbou
return nil
}

// checkTSSVoutCancelled vout is valid if:
// - The first output is the nonce-mark
// - The second output is the change to TSS (optional)
func (ob *BTCChainClient) checkTSSVoutCancelled(params *types.OutboundTxParams, vouts []btcjson.Vout) error {

Check warning on line 1389 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1389

Added line #L1389 was not covered by tests
// vouts: [nonce-mark, change to TSS (optional)]
if !(len(vouts) == 1 || len(vouts) == 2) {
return fmt.Errorf("checkTSSVoutCancelled: invalid number of vouts: %d", len(vouts))

Check warning on line 1392 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1391-L1392

Added lines #L1391 - L1392 were not covered by tests
}

nonce := params.OutboundTxTssNonce
tssAddress := ob.Tss.BTCAddress()
for _, vout := range vouts {
recvAddress, amount, err := ob.DecodeP2WPKHVout(vout)
if err != nil {
return errors.Wrap(err, "checkTSSVoutCancelled: error decoding P2WPKH vout")

Check warning on line 1400 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1395-L1400

Added lines #L1395 - L1400 were not covered by tests
}
// 1st vout: nonce-mark
if vout.N == 0 {
if recvAddress != tssAddress {
return fmt.Errorf("checkTSSVoutCancelled: nonce-mark address %s not match TSS address %s", recvAddress, tssAddress)

Check warning on line 1405 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1403-L1405

Added lines #L1403 - L1405 were not covered by tests
}
if amount != common.NonceMarkAmount(nonce) {
return fmt.Errorf("checkTSSVoutCancelled: nonce-mark amount %d not match nonce-mark amount %d", amount, common.NonceMarkAmount(nonce))

Check warning on line 1408 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1407-L1408

Added lines #L1407 - L1408 were not covered by tests
}
}
// 2nd vout: change to TSS (optional)
if vout.N == 2 {
if recvAddress != tssAddress {
return fmt.Errorf("checkTSSVoutCancelled: change address %s not match TSS address %s", recvAddress, tssAddress)

Check warning on line 1414 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1412-L1414

Added lines #L1412 - L1414 were not covered by tests
}
}
}
return nil

Check warning on line 1418 in zetaclient/bitcoin/bitcoin_client.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_client.go#L1418

Added line #L1418 was not covered by tests
}

func (ob *BTCChainClient) BuildBroadcastedTxMap() error {
var broadcastedTransactions []clienttypes.OutTxHashSQLType
if err := ob.db.Find(&broadcastedTransactions).Error; err != nil {
Expand Down
19 changes: 12 additions & 7 deletions zetaclient/bitcoin/bitcoin_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (signer *BTCSigner) SignWithdrawTx(
height uint64,
nonce uint64,
chain *common.Chain,
cancelTx bool,
) (*wire.MsgTx, error) {
estimateFee := float64(gasPrice.Uint64()*outTxBytesMax) / 1e8
nonceMark := common.NonceMarkAmount(nonce)
Expand Down Expand Up @@ -160,12 +161,14 @@ func (signer *BTCSigner) SignWithdrawTx(
tx.AddTxOut(txOut1)

// 2nd output: the payment to the recipient
pkScript, err := PayToWitnessPubKeyHashScript(to.WitnessProgram())
if err != nil {
return nil, err
if !cancelTx {
pkScript, err := PayToWitnessPubKeyHashScript(to.WitnessProgram())
if err != nil {
return nil, err

Check warning on line 167 in zetaclient/bitcoin/bitcoin_signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_signer.go#L164-L167

Added lines #L164 - L167 were not covered by tests
}
txOut2 := wire.NewTxOut(amountSatoshis, pkScript)
tx.AddTxOut(txOut2)

Check warning on line 170 in zetaclient/bitcoin/bitcoin_signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_signer.go#L169-L170

Added lines #L169 - L170 were not covered by tests
}
txOut2 := wire.NewTxOut(amountSatoshis, pkScript)
tx.AddTxOut(txOut2)

// 3rd output: the remaining btc to TSS self
if remainingSats > 0 {
Expand Down Expand Up @@ -322,12 +325,13 @@ func (signer *BTCSigner) TryProcessOutTx(
gasprice.Add(gasprice, satPerByte)

// compliance check
if clientcommon.IsCctxBanned(cctx) {
cancelTx := clientcommon.IsCctxBanned(cctx)
if cancelTx {
logMsg := fmt.Sprintf("Banned address detected in cctx: sender %s receiver %s chain %d nonce %d",
cctx.InboundTxParams.Sender, to, params.ReceiverChainId, outboundTxTssNonce)
logger.Warn().Msg(logMsg)
signer.loggerCompliance.Warn().Msg(logMsg)
amount = 0 // zero out the amount to cancel the tx
amount = 0.0 // zero out the amount to cancel the tx

Check warning on line 334 in zetaclient/bitcoin/bitcoin_signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_signer.go#L328-L334

Added lines #L328 - L334 were not covered by tests
}

logger.Info().Msgf("SignWithdrawTx: to %s, value %d sats", addr.EncodeAddress(), params.Amount.Uint64())
Expand All @@ -342,6 +346,7 @@ func (signer *BTCSigner) TryProcessOutTx(
height,
outboundTxTssNonce,
&btcClient.chain,
cancelTx,

Check warning on line 349 in zetaclient/bitcoin/bitcoin_signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/bitcoin_signer.go#L349

Added line #L349 was not covered by tests
)
if err != nil {
logger.Warn().Err(err).Msgf("SignOutboundTx error: nonce %d chain %d", outboundTxTssNonce, params.ReceiverChainId)
Expand Down
7 changes: 3 additions & 4 deletions zetaclient/bitcoin/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
)

const (
satoshiPerBitcoin = 1e8
bytesPerKB = 1000
bytesEmptyTx = 10 // an empty tx is about 10 bytes
bytesPerInput = 41 // each input is about 41 bytes
Expand Down Expand Up @@ -60,7 +59,7 @@ func PrettyPrintStruct(val interface{}) (string, error) {
// FeeRateToSatPerByte converts a fee rate in BTC/KB to sat/byte.
func FeeRateToSatPerByte(rate float64) *big.Int {
// #nosec G701 always in range
satPerKB := new(big.Int).SetInt64(int64(rate * satoshiPerBitcoin))
satPerKB := new(big.Int).SetInt64(int64(rate * btcutil.SatoshiPerBitcoin))

Check warning on line 62 in zetaclient/bitcoin/utils.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/bitcoin/utils.go#L62

Added line #L62 was not covered by tests
return new(big.Int).Div(satPerKB, big.NewInt(bytesPerKB))
}

Expand Down Expand Up @@ -102,7 +101,7 @@ func SegWitTxSizeWithdrawer() uint64 {
// DepositorFee calculates the depositor fee in BTC for a given sat/byte fee rate
// Note: the depositor fee is charged in order to cover the cost of spending the deposited UTXO in the future
func DepositorFee(satPerByte int64) float64 {
return float64(satPerByte) * float64(BtcOutTxBytesDepositor) / satoshiPerBitcoin
return float64(satPerByte) * float64(BtcOutTxBytesDepositor) / btcutil.SatoshiPerBitcoin
}

// CalcBlockAvgFeeRate calculates the average gas rate (in sat/vByte) for a given block
Expand Down Expand Up @@ -209,7 +208,7 @@ func GetSatoshis(btc float64) (int64, error) {
case btc < 0.0:
return 0, errors.New("cannot be less than zero")
}
return round(btc * satoshiPerBitcoin), nil
return round(btc * btcutil.SatoshiPerBitcoin), nil
}

func round(f float64) int64 {
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (c *Config) GetBannedAddressBook() map[string]bool {
bannedAddresses := make(map[string]bool)
if c.ComplianceConfig != nil {
for _, address := range c.ComplianceConfig.BannedAddresses {
if ethcommon.IsHexAddress(address) {
if address != "" {
bannedAddresses[strings.ToLower(address)] = true
}
}
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/evm/inbounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (ob *ChainClient) GetInboundVoteMsgForDepositedEvent(event *erc20custody.ER
if err == nil && parsedAddress != (ethcommon.Address{}) {
maybeReceiver = parsedAddress.Hex()

Check warning on line 304 in zetaclient/evm/inbounds.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/evm/inbounds.go#L301-L304

Added lines #L301 - L304 were not covered by tests
}
if config.AnyBannedAddress(sender.Hex(), maybeReceiver) {
if config.AnyBannedAddress(sender.Hex(), clienttypes.BytesToEthHex(event.Recipient), maybeReceiver) {
logMsg := fmt.Sprintf("Banned address detected in ERC20 Deposited event: sender %s receiver %s tx %s chain %d",
sender, maybeReceiver, event.Raw.TxHash, ob.chain.ChainId)
ob.logger.ExternalChainWatcher.Warn().Msg(logMsg)
Expand Down
15 changes: 12 additions & 3 deletions zetaclient/testutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import (

"github.com/btcsuite/btcd/btcjson"
"github.com/cosmos/cosmos-sdk/types"
"github.com/zeta-chain/zetacore/zetaclient/config"
"github.com/zeta-chain/zetacore/zetaclient/keys"
"github.com/zeta-chain/zetacore/zetaclient/zetabridge"
)

const (
TestDataPathEVM = "testdata/evm"
TestDataPathBTC = "testdata/btc"
TestDataPathCctx = "testdata/cctx"
TestDataPathEVM = "testdata/evm"
TestDataPathBTC = "testdata/btc"
TestDataPathCctx = "testdata/cctx"
BannedEVMAddressTest = "0x8a81Ba8eCF2c418CAe624be726F505332DF119C6"
BannedBtcAddressTest = "bcrt1qzp4gt6fc7zkds09kfzaf9ln9c5rvrzxmy6qmpp"
)

// SaveObjectToJSONFile saves an object to a file in JSON format
Expand Down Expand Up @@ -66,3 +69,9 @@ func DummyCoreBridge() *zetabridge.ZetaCoreBridge {
nil)
return bridge
}

func ComplianceConfigTest() *config.ComplianceConfig {
return &config.ComplianceConfig{
BannedAddresses: []string{BannedEVMAddressTest, BannedBtcAddressTest},
}
}

0 comments on commit 5086694

Please sign in to comment.