Skip to content

Commit

Permalink
validate tx hash supplied for ticket ownership validation
Browse files Browse the repository at this point in the history
  • Loading branch information
itswisdomagain committed Mar 12, 2020
1 parent 9fcb75a commit 1b6bd32
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 85 deletions.
35 changes: 28 additions & 7 deletions backend/stakepoold/stakepool/stakepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ type ticketMetadata struct {
}

type ticketInfo struct {
multiSigAddress string
vspRewardAddress string
userRewardAddress string
MultiSigAddress string
VspRewardAddress string
UserRewardAddress string
}

// EvaluateStakePoolTicket evaluates a voting service ticket to see if it's
Expand Down Expand Up @@ -435,13 +435,34 @@ func (spd *Stakepoold) GetTicketInfo(ticketHash string) (*ticketInfo, error) {
return nil, err
}

// get txout addresses using tx hex
msgTx, err := MsgTxFromHex(res.Hex)
if err != nil {
log.Errorf("GetTicketInfo: MsgTxFromHex failed for %v: %v", res.Hex, err)
return nil, err
}

if !stake.IsSStx(msgTx) {
log.Errorf("GetTicketInfo: %s not a ticket purchase transaction", ticketHash)
return nil, fmt.Errorf("%s not a ticket purchase transaction", ticketHash)
}

ticketBlockHash, err := chainhash.NewHashFromStr(res.BlockHash)
if err != nil {
log.Warnf("GetTicketInfo: NewHashFromStr failed for %v: %v", res.BlockHash, err)
return nil, err
}

ticketBlockHeader, err := spd.NodeConnection.GetBlockHeader(ticketBlockHash)
if err != nil {
log.Warnf("GetTicketInfo: GetBlockHeader failed for %v: %v", ticketBlockHash, err)
return nil, err
}

if knownByVsp, _ := spd.EvaluateStakePoolTicket(msgTx, int32(ticketBlockHeader.Height)); !knownByVsp {
log.Errorf("GetTicketInfo: ticket (%s) not watched by this VSP", ticketHash)
return nil, fmt.Errorf("ticket (%s) not watched by this VSP", ticketHash)
}

p2shOut := msgTx.TxOut[0]
_, p2shOutAddresses, _, err := txscript.ExtractPkScriptAddrs(p2shOut.Version, p2shOut.PkScript, spd.Params)
if err != nil {
Expand All @@ -465,9 +486,9 @@ func (spd *Stakepoold) GetTicketInfo(ticketHash string) (*ticketInfo, error) {
}

return &ticketInfo{
multiSigAddress: multiSigAddress.Address(),
vspRewardAddress: vspCommitAddr.Address(),
userRewardAddress: ownerCommitAddr.Address(),
MultiSigAddress: multiSigAddress.Address(),
VspRewardAddress: vspCommitAddr.Address(),
UserRewardAddress: ownerCommitAddr.Address(),
}, nil
}

Expand Down
6 changes: 0 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ require (
github.com/decred/dcrd/chaincfg/chainhash v1.0.2
github.com/decred/dcrd/chaincfg/v2 v2.3.0
github.com/decred/dcrd/dcrec v1.0.0
github.com/decred/dcrd/dcrutil v1.4.0 // indirect
github.com/decred/dcrd/dcrutil/v2 v2.0.1
github.com/decred/dcrd/hdkeychain/v2 v2.1.0
github.com/decred/dcrd/rpcclient v1.1.0 // indirect
github.com/decred/dcrd/rpcclient/v4 v4.0.0
github.com/decred/dcrd/txscript/v2 v2.1.0
github.com/decred/dcrd/wire v1.3.0
github.com/decred/dcrdata/api/types/v4 v4.0.4
github.com/decred/dcrdata/txhelpers/v3 v3.0.5 // indirect
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.4.0
github.com/decred/dcrwallet/wallet v1.3.0 // indirect
github.com/decred/dcrwallet/wallet/v3 v3.2.1
github.com/decred/slog v1.0.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible
Expand All @@ -40,8 +37,5 @@ require (
github.com/zenazn/goji v0.9.0
github.com/ziutek/mymysql v1.5.4 // indirect
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect
google.golang.org/grpc v1.27.1
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
)
Loading

0 comments on commit 1b6bd32

Please sign in to comment.