Skip to content

Commit

Permalink
skip mainnet addresses in cctxs
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Nov 2, 2023
1 parent 6e1fb4a commit bfa1cb8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 16 additions & 0 deletions zetaclient/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 7 additions & 1 deletion zetaclient/btc_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit bfa1cb8

Please sign in to comment.