From bfa1cb88675d81ecef91aea90d18c4664749c98c Mon Sep 17 00:00:00 2001 From: charliec Date: Thu, 2 Nov 2023 16:07:49 -0500 Subject: [PATCH] skip mainnet addresses in cctxs --- zetaclient/bitcoin_client.go | 16 ++++++++++++++++ zetaclient/btc_signer.go | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/zetaclient/bitcoin_client.go b/zetaclient/bitcoin_client.go index 672bec4132..cd41a18f5e 100644 --- a/zetaclient/bitcoin_client.go +++ b/zetaclient/bitcoin_client.go @@ -1073,6 +1073,22 @@ func (ob *BitcoinChainClient) checkTSSVout(vouts []btcjson.Vout, params types.Ou } // 2nd vout: payment to recipient if vout.N == 1 { + // Re-encode address with the correct network HRP so we allow the incorrect addresses to pass in Athens3 + // TODO: remove this special handling after fixing the issue in zetacore + cctxAddress, err := btcutil.DecodeAddress(params.Receiver, config.BitconNetParams) + if err != nil { + return fmt.Errorf("checkTSSVout: error decoding receiver address %s", params.Receiver) + } + if !cctxAddress.IsForNet(config.BitconNetParams) { + ob.logger.ObserveOutTx.Error().Msgf("checkTSSVout: address %s is not intended for the network %s", params.Receiver, config.BitconNetParams.Name) + correctAddress, err := btcutil.NewAddressWitnessPubKeyHash(cctxAddress.ScriptAddress(), config.BitconNetParams) + if err != nil { + return errors.Wrapf(err, "checkTSSVout: error re-encoding address %s", params.Receiver) + } + params.Receiver = correctAddress.EncodeAddress() + ob.logger.ObserveOutTx.Info().Msgf("checkTSSVout: re-encoded address %s to %s", params.Receiver, correctAddress.EncodeAddress()) + } + if recvAddress != params.Receiver { return fmt.Errorf("checkTSSVout: output address %s not match params receiver %s", recvAddress, params.Receiver) } diff --git a/zetaclient/btc_signer.go b/zetaclient/btc_signer.go index 8f131f5814..e89f201362 100644 --- a/zetaclient/btc_signer.go +++ b/zetaclient/btc_signer.go @@ -279,12 +279,17 @@ func (signer *BTCSigner) TryProcessOutTx(send *types.CrossChainTx, outTxMan *Out return } - // FIXME: config chain params + // Check receiver P2WPKH address addr, err := btcutil.DecodeAddress(params.Receiver, config.BitconNetParams) if err != nil { logger.Error().Err(err).Msgf("cannot decode address %s ", params.Receiver) return } + // TODO: enable this check after fixing the issue in zetacore + // if !addr.IsForNet(config.BitconNetParams) { + // logger.Error().Msgf("address %s is not for network %s", params.Receiver, config.BitconNetParams.Name) + // return + // } to, ok := addr.(*btcutil.AddressWitnessPubKeyHash) if err != nil || !ok { logger.Error().Err(err).Msgf("cannot convert address %s to P2WPKH address", params.Receiver) @@ -295,6 +300,7 @@ func (signer *BTCSigner) TryProcessOutTx(send *types.CrossChainTx, outTxMan *Out networkInfo, err := signer.rpcClient.GetNetworkInfo() if err != nil { logger.Error().Err(err).Msgf("cannot get bitcoin network info") + return } satPerByte := feeRateToSatPerByte(networkInfo.RelayFee) gasprice.Add(gasprice, satPerByte)