Skip to content

Commit

Permalink
Fix signature counter panic
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 committed Sep 2, 2024
1 parent 2d253e8 commit ebda061
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/taproot/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ const SignatureLen = 64
// can verify the integrity of the signature.
type Signature []byte

// SignatureCounter is an atomic counter used to add some fault
// signatureCounter is an atomic counter used to add some fault
// resistance in case we don't use a source of randomness for Sign
var SignatureCounter atomic.Uint64
var signatureCounter atomic.Uint64

// init initializes `SignatureCounter` to a random value
// init initializes `signatureCounter` to a random value
func init() {
binary.Read(rand.Reader, binary.BigEndian, &SignatureCounter)
var randSigCounter uint64
binary.Read(rand.Reader, binary.BigEndian, &randSigCounter)
signatureCounter.Store(randSigCounter)
}

// Sign uses a secret key to create a new signature.
Expand Down Expand Up @@ -133,7 +135,7 @@ func (sk SecretKey) Sign(rand io.Reader, m []byte) (Signature, error) {
}
} else {
// Need to use atomics, because of potential multi-threading
ctr := SignatureCounter.Add(1)
ctr := signatureCounter.Add(1)
binary.BigEndian.PutUint64(a, ctr)
}

Expand Down

0 comments on commit ebda061

Please sign in to comment.