Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/goal/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ func init() {

panicIfErr(methodAppCmd.MarkFlagRequired("method"))
panicIfErr(methodAppCmd.MarkFlagRequired("from"))
panicIfErr(appCmd.PersistentFlags().MarkHidden("app-arg"))
}

func panicIfErr(err error) {
Expand Down
2 changes: 1 addition & 1 deletion config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const VersionMajor = 3

// VersionMinor is the Minor semantic version number (x.#.z) - changed when backwards-compatible features are introduced.
// Not enforced until after initial public release (x > 0).
const VersionMinor = 10
const VersionMinor = 11

// Version is the type holding our full version information.
type Version struct {
Expand Down
31 changes: 22 additions & 9 deletions crypto/batchverifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,34 @@ func (b *BatchVerifier) getNumberOfEnqueuedSignatures() int {
}

// Verify verifies that all the signatures are valid. in that case nil is returned
// if the batch is zero an appropriate error is return.
func (b *BatchVerifier) Verify() error {
_, err := b.VerifyWithFeedback()
return err
}

// VerifyWithFeedback verifies that all the signatures are valid.
// if all sigs are valid, nil will be returned for err (failed will have all false)
// if some signatures are invalid, true will be set in failed at the corresponding indexes, and
// ErrBatchVerificationFailed for err
func (b *BatchVerifier) VerifyWithFeedback() (failed []bool, err error) {
if b.getNumberOfEnqueuedSignatures() == 0 {
return nil
return nil, nil
}

var messages = make([][]byte, b.getNumberOfEnqueuedSignatures())
for i, m := range b.messages {
messages[i] = HashRep(m)
}
if batchVerificationImpl(messages, b.publicKeys, b.signatures) {
return nil
allValid, failed := batchVerificationImpl(messages, b.publicKeys, b.signatures)
if allValid {
return failed, nil
}
return ErrBatchVerificationFailed

return failed, ErrBatchVerificationFailed
}

// batchVerificationImpl invokes the ed25519 batch verification algorithm.
// it returns true if all the signatures were authentically signed by the owners
func batchVerificationImpl(messages [][]byte, publicKeys []SignatureVerifier, signatures []Signature) bool {
// otherwise, returns false, and sets the indexes of the failed sigs in failed
func batchVerificationImpl(messages [][]byte, publicKeys []SignatureVerifier, signatures []Signature) (allSigsValid bool, failed []bool) {

numberOfSignatures := len(messages)

Expand Down Expand Up @@ -164,5 +172,10 @@ func batchVerificationImpl(messages [][]byte, publicKeys []SignatureVerifier, si
C.size_t(len(messages)),
(*C.int)(unsafe.Pointer(valid)))

return allValid == 0
failed = make([]bool, numberOfSignatures)
for i := 0; i < numberOfSignatures; i++ {
cint := *(*C.int)(unsafe.Pointer(uintptr(valid) + uintptr(i*C.sizeof_int)))
failed[i] = (cint == 0)
}
return allValid == 0, failed
}
69 changes: 69 additions & 0 deletions crypto/batchverifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package crypto

import (
"math/rand"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -123,4 +124,72 @@ func TestEmpty(t *testing.T) {
partitiontest.PartitionTest(t)
bv := MakeBatchVerifier()
require.NoError(t, bv.Verify())

failed, err := bv.VerifyWithFeedback()
require.NoError(t, err)
require.Empty(t, failed)
}

// TestBatchVerifierIndividualResults tests that VerifyWithFeedback
// returns the correct failed signature indexes
func TestBatchVerifierIndividualResults(t *testing.T) {
partitiontest.PartitionTest(t)

for i := 1; i < 64*2+3; i++ {
n := i
bv := MakeBatchVerifierWithHint(n)
var s Seed
badSigs := make([]bool, n, n)
hasBadSig := false
for i := 0; i < n; i++ {
msg := randString()
RandBytes(s[:])
sigSecrets := GenerateSignatureSecrets(s)
sig := sigSecrets.Sign(msg)
if rand.Float32() > 0.5 {
// make a bad sig
sig[0] = sig[0] + 1
badSigs[i] = true
hasBadSig = true
}
bv.EnqueueSignature(sigSecrets.SignatureVerifier, msg, sig)
}
require.Equal(t, n, bv.getNumberOfEnqueuedSignatures())
failed, err := bv.VerifyWithFeedback()
if hasBadSig {
require.ErrorIs(t, err, ErrBatchVerificationFailed)
} else {
require.NoError(t, err)
}
require.Equal(t, len(badSigs), len(failed))
for i := range badSigs {
require.Equal(t, badSigs[i], failed[i])
}
}
}

// TestBatchVerifierIndividualResultsAllValid tests that VerifyWithFeedback
// returns the correct failed signature indexes when all are valid
func TestBatchVerifierIndividualResultsAllValid(t *testing.T) {
partitiontest.PartitionTest(t)

for i := 1; i < 64*2+3; i++ {
n := i
bv := MakeBatchVerifierWithHint(n)
var s Seed
for i := 0; i < n; i++ {
msg := randString()
RandBytes(s[:])
sigSecrets := GenerateSignatureSecrets(s)
sig := sigSecrets.Sign(msg)
bv.EnqueueSignature(sigSecrets.SignatureVerifier, msg, sig)
}
require.Equal(t, n, bv.getNumberOfEnqueuedSignatures())
failed, err := bv.VerifyWithFeedback()
require.NoError(t, err)
require.Equal(t, bv.getNumberOfEnqueuedSignatures(), len(failed))
for _, f := range failed {
require.False(t, f)
}
}
}
4 changes: 2 additions & 2 deletions crypto/onetimesig.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,12 @@ func (v OneTimeSignatureVerifier) Verify(id OneTimeSignatureIdentifier, message
Batch: id.Batch,
}

return batchVerificationImpl(
allValid, _ := batchVerificationImpl(
[][]byte{HashRep(batchID), HashRep(offsetID), HashRep(message)},
[]PublicKey{PublicKey(v), PublicKey(batchID.SubKeyPK), PublicKey(offsetID.SubKeyPK)},
[]Signature{Signature(sig.PK2Sig), Signature(sig.PK1Sig), Signature(sig.Sig)},
)

return allValid
}

// DeleteBeforeFineGrained deletes ephemeral keys before (but not including) the given id.
Expand Down
2 changes: 1 addition & 1 deletion daemon/kmd/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# kmd - Key Management Daemon

## Overview
kmd is the Key Management Daemon, the process responsible for securely managing spending keys. It is the implementation of the design [specified here.](https://docs.google.com/document/d/1j7sLC2BphSFqd76GEIJvw4GpY2tNW7nmk_Ea7UfBEWc/edit?usp=sharing)
kmd is the Key Management Daemon, the process responsible for securely managing spending keys.

## Useful facts
- kmd has a data directory separate from algod's data directory. By default, however, the kmd data directory is in the `kmd` subdirectory of algod's data directory.
Expand Down
Loading