Skip to content

Commit

Permalink
fix withdrawal custodian signature verification
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Oct 10, 2023
1 parent 784e73a commit f54d24a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
8 changes: 3 additions & 5 deletions common/withdrawal.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,15 @@ func (tx *Transaction) validateWithdrawalClaim(store DataStore, inputs map[strin
if err != nil {
return err
}
var domainValid bool
view := custodian.Custodian.PublicSpendKey.DeterministicHashDerive()
for _, utxo := range inputs {
for _, key := range utxo.Keys {
ghost := crypto.ViewGhostOutputKey(key, &view, &utxo.Mask, uint64(utxo.Index))
valid := *ghost == custodian.Custodian.PublicSpendKey
domainValid = domainValid && valid
if !valid {
return fmt.Errorf("invalid domain signature for withdrawal claim %s", key.String())
}
}
}
if !domainValid {
return fmt.Errorf("invalid domain signature for withdrawal claim")
}
return nil
}
11 changes: 3 additions & 8 deletions domains/bitcoin/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ import (
)

const (
BitcoinChainAssetKey = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"
BitcoinOmniUSDTAssetKey = "815b0b1a-2764-3736-8faa-42d694fa620a"
BitcoinChainAssetKey = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"
)

var (
BitcoinChainId crypto.Hash
BitcoinOmniUSDTId crypto.Hash
BitcoinChainId crypto.Hash
)

func init() {
BitcoinChainId = crypto.Sha256Hash([]byte(BitcoinChainAssetKey))
BitcoinOmniUSDTId = crypto.Sha256Hash([]byte(BitcoinOmniUSDTAssetKey))
}

func VerifyAssetKey(assetKey string) error {
if assetKey == BitcoinChainAssetKey || assetKey == BitcoinOmniUSDTAssetKey {
if assetKey == BitcoinChainAssetKey {
return nil
}
return fmt.Errorf("invalid bitcoin asset key %s", assetKey)
Expand Down Expand Up @@ -62,8 +59,6 @@ func GenerateAssetId(assetKey string) crypto.Hash {
switch assetKey {
case BitcoinChainAssetKey:
return BitcoinChainId
case BitcoinOmniUSDTAssetKey:
return BitcoinOmniUSDTId
default:
panic(assetKey)
}
Expand Down
6 changes: 0 additions & 6 deletions domains/bitcoin/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,24 @@ func TestValidation(t *testing.T) {
require := require.New(t)

btc := "c6d0c728-2624-429b-8e0d-d9d19b6592fa"
usdt := "815b0b1a-2764-3736-8faa-42d694fa620a"
tx := "c5945a8571fc84cd6850b26b5771d76311ed56957a04e993927de07b83f07c91"
addrLeg := "1zgmvYi5x1wy3hUh7AjKgpcVgpA8Lj9FA"
addrSeg := "bc1qxenlll5m5zyp778j8jd6arkn99h956zkcye93n"
addrTaproot := "bc1paardr2nczq0rx5rqpfwnvpzm497zvux64y0f7wjgcs7xuuuh2nnqwr2d5c"
addrCash := "qptz5xa5dd670f453grrplt6d4llaxlm05qmwktdc5"

require.Nil(VerifyAssetKey(btc))
require.Nil(VerifyAssetKey(usdt))
require.NotNil(VerifyAssetKey(tx))
require.NotNil(VerifyAssetKey(addrLeg))
require.NotNil(VerifyAssetKey(addrSeg))
require.NotNil(VerifyAssetKey(addrTaproot))
require.NotNil(VerifyAssetKey(addrCash))
require.NotNil(VerifyAssetKey(strings.ToUpper(btc)))
require.NotNil(VerifyAssetKey(strings.ToUpper(usdt)))

require.Nil(VerifyAddress(addrLeg))
require.Nil(VerifyAddress(addrSeg))
require.Nil(VerifyAddress(addrTaproot))
require.NotNil(VerifyAddress(btc))
require.NotNil(VerifyAddress(usdt))
require.NotNil(VerifyAddress(addrCash))
require.NotNil(VerifyAddress(addrLeg[1:]))
require.NotNil(VerifyAddress(strings.ToUpper(addrLeg)))
Expand All @@ -54,7 +50,5 @@ func TestValidation(t *testing.T) {
require.NotNil(VerifyTransactionHash(strings.ToUpper(tx)))

require.Equal(crypto.Sha256Hash([]byte("c6d0c728-2624-429b-8e0d-d9d19b6592fa")), GenerateAssetId(btc))
require.Equal(crypto.Sha256Hash([]byte("815b0b1a-2764-3736-8faa-42d694fa620a")), GenerateAssetId(usdt))
require.Equal(crypto.Sha256Hash([]byte("c6d0c728-2624-429b-8e0d-d9d19b6592fa")), BitcoinChainId)
require.Equal(crypto.Sha256Hash([]byte("815b0b1a-2764-3736-8faa-42d694fa620a")), BitcoinOmniUSDTId)
}

0 comments on commit f54d24a

Please sign in to comment.