Skip to content

Commit

Permalink
Merge pull request algorand#5110 from Algo-devops-service/relstable3.…
Browse files Browse the repository at this point in the history
…14.2
  • Loading branch information
algojohnlee authored Feb 3, 2023
2 parents 642f6a7 + ae13ce5 commit 24ced4e
Show file tree
Hide file tree
Showing 71 changed files with 149 additions and 86 deletions.
18 changes: 9 additions & 9 deletions batchverifier.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -53,7 +53,7 @@ const minBatchVerifierAlloc = 16

// Batch verifications errors
var (
ErrBatchVerificationFailed = errors.New("At least one signature didn't pass verification")
ErrBatchHasFailedSigs = errors.New("At least one signature didn't pass verification")
)

//export ed25519_randombytes_unsafe
Expand Down Expand Up @@ -104,8 +104,8 @@ func (b *BatchVerifier) expand() {
b.signatures = signatures
}

// getNumberOfEnqueuedSignatures returns the number of signatures current enqueue onto the batch verifier object
func (b *BatchVerifier) getNumberOfEnqueuedSignatures() int {
// GetNumberOfEnqueuedSignatures returns the number of signatures currently enqueued into the BatchVerifier
func (b *BatchVerifier) GetNumberOfEnqueuedSignatures() int {
return len(b.messages)
}

Expand All @@ -120,18 +120,18 @@ func (b *BatchVerifier) Verify() error {
// 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 {
if b.GetNumberOfEnqueuedSignatures() == 0 {
return nil, nil
}
var messages = make([][]byte, b.getNumberOfEnqueuedSignatures())
for i, m := range b.messages {
messages[i] = HashRep(m)
var messages = make([][]byte, b.GetNumberOfEnqueuedSignatures())
for i := range b.messages {
messages[i] = HashRep(b.messages[i])
}
allValid, failed := batchVerificationImpl(messages, b.publicKeys, b.signatures)
if allValid {
return failed, nil
}
return failed, ErrBatchVerificationFailed
return failed, ErrBatchHasFailedSigs
}

// batchVerificationImpl invokes the ed25519 batch verification algorithm.
Expand Down
74 changes: 68 additions & 6 deletions batchverifier_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand All @@ -17,6 +17,7 @@
package crypto

import (
"fmt"
"math/rand"
"runtime"
"testing"
Expand Down Expand Up @@ -64,7 +65,7 @@ func TestBatchVerifierBulk(t *testing.T) {
sig := sigSecrets.Sign(msg)
bv.EnqueueSignature(sigSecrets.SignatureVerifier, msg, sig)
}
require.Equal(t, n, bv.getNumberOfEnqueuedSignatures())
require.Equal(t, n, bv.GetNumberOfEnqueuedSignatures())
require.NoError(t, bv.Verify())
}

Expand Down Expand Up @@ -121,6 +122,67 @@ func BenchmarkBatchVerifier(b *testing.B) {
require.NoError(b, bv.Verify())
}

// BenchmarkBatchVerifierBig with b.N over 1000 will report the expected performance
// gain as the batchsize increases. All sigs are valid.
func BenchmarkBatchVerifierBig(b *testing.B) {
c := makeCurve25519Secret()
for batchSize := 1; batchSize <= 96; batchSize++ {
bv := MakeBatchVerifierWithHint(batchSize)
for i := 0; i < batchSize; i++ {
str := randString()
bv.EnqueueSignature(c.SignatureVerifier, str, c.Sign(str))
}
b.Run(fmt.Sprintf("running batchsize %d", batchSize), func(b *testing.B) {
totalTransactions := b.N
count := totalTransactions / batchSize
if count*batchSize < totalTransactions {
count++
}
for x := 0; x < count; x++ {
require.NoError(b, bv.Verify())
}
})
}
}

// BenchmarkBatchVerifierBigWithInvalid builds over BenchmarkBatchVerifierBig by introducing
// invalid sigs to even numbered batch sizes. This shows the impact of invalid sigs on the
// performance. Basically, all the gains from batching disappear.
func BenchmarkBatchVerifierBigWithInvalid(b *testing.B) {
c := makeCurve25519Secret()
badSig := Signature{}
for batchSize := 1; batchSize <= 96; batchSize++ {
bv := MakeBatchVerifierWithHint(batchSize)
for i := 0; i < batchSize; i++ {
str := randString()
if batchSize%2 == 0 && (i == 0 || rand.Float32() < 0.1) {
bv.EnqueueSignature(c.SignatureVerifier, str, badSig)
} else {
bv.EnqueueSignature(c.SignatureVerifier, str, c.Sign(str))
}
}
b.Run(fmt.Sprintf("running batchsize %d", batchSize), func(b *testing.B) {
totalTransactions := b.N
count := totalTransactions / batchSize
if count*batchSize < totalTransactions {
count++
}
for x := 0; x < count; x++ {
failed, err := bv.VerifyWithFeedback()
if err != nil {
for i, f := range failed {
if bv.signatures[i] == badSig {
require.True(b, f)
} else {
require.False(b, f)
}
}
}
}
})
}
}

func TestEmpty(t *testing.T) {
partitiontest.PartitionTest(t)
bv := MakeBatchVerifier()
Expand Down Expand Up @@ -155,10 +217,10 @@ func TestBatchVerifierIndividualResults(t *testing.T) {
}
bv.EnqueueSignature(sigSecrets.SignatureVerifier, msg, sig)
}
require.Equal(t, n, bv.getNumberOfEnqueuedSignatures())
require.Equal(t, n, bv.GetNumberOfEnqueuedSignatures())
failed, err := bv.VerifyWithFeedback()
if hasBadSig {
require.ErrorIs(t, err, ErrBatchVerificationFailed)
require.ErrorIs(t, err, ErrBatchHasFailedSigs)
} else {
require.NoError(t, err)
}
Expand All @@ -185,10 +247,10 @@ func TestBatchVerifierIndividualResultsAllValid(t *testing.T) {
sig := sigSecrets.Sign(msg)
bv.EnqueueSignature(sigSecrets.SignatureVerifier, msg, sig)
}
require.Equal(t, n, bv.getNumberOfEnqueuedSignatures())
require.Equal(t, n, bv.GetNumberOfEnqueuedSignatures())
failed, err := bv.VerifyWithFeedback()
require.NoError(t, err)
require.Equal(t, bv.getNumberOfEnqueuedSignatures(), len(failed))
require.Equal(t, bv.GetNumberOfEnqueuedSignatures(), len(failed))
for _, f := range failed {
require.False(t, f)
}
Expand Down
2 changes: 1 addition & 1 deletion crypto_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion cryptoerror.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion curve25519.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion curve25519_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion digest.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion encoding_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion falconWrapper.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
5 changes: 3 additions & 2 deletions falconWrapper_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand All @@ -17,10 +17,11 @@
package crypto

import (
"testing"

"github.com/algorand/falcon"
"github.com/algorand/go-algorand/test/partitiontest"
"github.com/stretchr/testify/require"
"testing"
)

func TestSignAndVerifyFalcon(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion hashes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion hashes_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion memcpy_chk_windows.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklearray/array.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklearray/layer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklearray/merkle.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklearray/merkle_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklearray/partial.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklearray/proof.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklearray/proof_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklearray/vectorCommitmentArray.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklearray/vectorCommitmentArray_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklearray/worker.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
4 changes: 2 additions & 2 deletions merklesignature/committablePublicKeys.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -34,7 +34,7 @@ type (
keyLifetime uint64
}

// CommittablePublicKey is used to create a binary representation of public keys in the merkle
// CommittablePublicKey is used to create a binary representation of public keys in the merkle
// signature scheme.
CommittablePublicKey struct {
VerifyingKey crypto.FalconVerifier
Expand Down
2 changes: 1 addition & 1 deletion merklesignature/committablePublicKeys_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklesignature/const.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklesignature/kats_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklesignature/keysBuilder.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklesignature/keysBuilder_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklesignature/merkleSignatureScheme.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklesignature/merkleSignatureScheme_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklesignature/persistentMerkleSignatureScheme.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklesignature/persistentMerkleSignatureScheme_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklesignature/posdivs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merklesignature/posdivs_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merkletrie/bitset.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion merkletrie/bitset_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
Expand Down
Loading

0 comments on commit 24ced4e

Please sign in to comment.