Skip to content

Commit 81b3048

Browse files
authored
Merge pull request #149 from renproject/fix/decode-segwit-address
Network check when decoding address
2 parents 0325fe4 + 69c68db commit 81b3048

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

chain/bitcoin/address.go

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ func (decoder AddressDecoder) DecodeAddress(addr address.Address) (address.RawAd
102102
if err != nil {
103103
return nil, fmt.Errorf("decode address: %v", err)
104104
}
105+
if !decodedAddr.IsForNet(decoder.params) {
106+
return nil, fmt.Errorf("address of different network")
107+
}
105108

106109
switch a := decodedAddr.(type) {
107110
case *btcutil.AddressPubKeyHash, *btcutil.AddressScriptHash:

chain/bitcoin/utxo.go

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ func (txBuilder TxBuilder) BuildTx(inputs []utxo.Input, recipients []utxo.Recipi
5656
if err != nil {
5757
return nil, err
5858
}
59+
if !addr.IsForNet(txBuilder.params) {
60+
return nil, fmt.Errorf("addr of a different network")
61+
}
5962
script, err := txscript.PayToAddrScript(addr)
6063
if err != nil {
6164
return nil, err

chain/bitcoincash/address.go

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ func (encoder AddressEncoder) EncodeAddress(rawAddr address.RawAddress) (address
9797
func (decoder AddressDecoder) DecodeAddress(addr address.Address) (address.RawAddress, error) {
9898
// Legacy address decoding
9999
if legacyAddr, err := btcutil.DecodeAddress(string(addr), decoder.params); err == nil {
100+
if !legacyAddr.IsForNet(decoder.params) {
101+
return nil, fmt.Errorf("address of different network")
102+
}
100103
switch legacyAddr.(type) {
101104
case *btcutil.AddressPubKeyHash, *btcutil.AddressScriptHash, *btcutil.AddressPubKey:
102105
return decodeLegacyAddress(addr, decoder.params)

chain/dogecoin/address_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
11
package dogecoin_test
2+
3+
import (
4+
"github.com/renproject/multichain"
5+
"github.com/renproject/multichain/chain/bitcoin"
6+
"github.com/renproject/multichain/chain/dogecoin"
7+
8+
. "github.com/onsi/ginkgo"
9+
. "github.com/onsi/gomega"
10+
)
11+
12+
var _ = Describe("Dogecoin", func() {
13+
Context("when decoding segwit address", func() {
14+
Context("when decoding an address from a different network ", func() {
15+
It("should return an error ", func() {
16+
// A valid bitcoin segwit address which is not a valid doge address
17+
addr := multichain.Address("bc1qk6yk2ctcu2pmtxfzhya692h774562vlv2g7dvl")
18+
decoder := bitcoin.NewAddressDecoder(&dogecoin.MainNetParams)
19+
_, err := decoder.DecodeAddress(addr)
20+
Expect(err).To(HaveOccurred())
21+
})
22+
})
23+
})
24+
})

infra/terra/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ RUN tar -C /usr/local -xzf go1.16.8.linux-amd64.tar.gz
77
ENV PATH=$PATH:/usr/local/go/bin
88

99
WORKDIR /app
10-
RUN git clone https://github.com/terra-money/core.git
11-
WORKDIR /app/core
10+
RUN git clone https://github.com/terra-money/classic-core.git
11+
WORKDIR /app/classic-core
1212
RUN git fetch --all -p
1313
RUN git checkout v0.5.5
1414
RUN make install

0 commit comments

Comments
 (0)