Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make merkle signer SNARK friendly #3263

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
23 changes: 10 additions & 13 deletions compactcert/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ func (s *testWorkerStubs) CompactCertVoters(r basics.Round) (*ledgercore.VotersF
for i, k := range s.keysForVoters {
voters.AddrToPos[k.Parent] = uint64(i)
voters.Participants = append(voters.Participants, basics.Participant{
PK: *k.StateProofSecrets.GetVerifier(),
Weight: 1,
FirstValid: uint64(k.FirstValid),
PK: *k.StateProofSecrets.GetVerifier(),
Weight: 1,
})
}

Expand Down Expand Up @@ -265,11 +264,10 @@ func TestWorkerAllSigs(t *testing.T) {
require.False(t, overflowed)

ccparams := compactcert.Params{
Msg: signedHdr,
ProvenWeight: provenWeight,
SigRound: basics.Round(signedHdr.Round),
SecKQ: proto.CompactCertSecKQ,
CompactCertRounds: proto.CompactCertRounds,
Msg: signedHdr,
ProvenWeight: provenWeight,
SigRound: basics.Round(signedHdr.Round),
SecKQ: proto.CompactCertSecKQ,
}

voters, err := s.CompactCertVoters(tx.Txn.CertRound - basics.Round(proto.CompactCertRounds) - basics.Round(proto.CompactCertVotersLookback))
Expand Down Expand Up @@ -329,11 +327,10 @@ func TestWorkerPartialSigs(t *testing.T) {
require.False(t, overflowed)

ccparams := compactcert.Params{
Msg: signedHdr,
ProvenWeight: provenWeight,
SigRound: basics.Round(signedHdr.Round),
SecKQ: proto.CompactCertSecKQ,
CompactCertRounds: proto.CompactCertRounds,
Msg: signedHdr,
ProvenWeight: provenWeight,
SigRound: basics.Round(signedHdr.Round),
SecKQ: proto.CompactCertSecKQ,
}

voters, err := s.CompactCertVoters(tx.Txn.CertRound - basics.Round(proto.CompactCertRounds) - basics.Round(proto.CompactCertVotersLookback))
Expand Down
20 changes: 2 additions & 18 deletions crypto/compactcert/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package compactcert

import (
"fmt"

"github.com/algorand/go-algorand/data/basics"

"github.com/algorand/go-algorand/crypto"
Expand Down Expand Up @@ -102,7 +101,7 @@ func (b *Builder) Add(pos uint64, sig merklekeystore.Signature, verifySig bool)
// Check signature

if verifySig {
if err := p.PK.Verify(p.FirstValid, uint64(b.SigRound), b.CompactCertRounds, b.Msg, sig); err != nil {
if err := p.PK.Verify(uint64(b.SigRound), b.Msg, sig); err != nil {
return err
}
}
Expand All @@ -126,21 +125,6 @@ func (b *Builder) SignedWeight() uint64 {
return b.signedWeight
}

//msgp:ignore sigsToCommit
type sigsToCommit []sigslot

func (sc sigsToCommit) Length() uint64 {
return uint64(len(sc))
}

func (sc sigsToCommit) Marshal(pos uint64) ([]byte, error) {
if pos >= uint64(len(sc)) {
return nil, fmt.Errorf("pos %d past end %d", pos, len(sc))
}

return crypto.HashRep(&sc[pos].sigslotCommit), nil
}

// coinIndex returns the position pos in the sigs array such that the sum
// of all signature weights before pos is less than or equal to coinWeight,
// but the sum of all signature weights up to and including pos exceeds
Expand Down Expand Up @@ -192,7 +176,7 @@ func (b *Builder) Build() (*Cert, error) {
b.sigsHasValidL = true

hfactory := crypto.HashFactory{HashType: HashType}
sigtree, err := merklearray.Build(sigsToCommit(b.sigs), hfactory)
sigtree, err := merklearray.Build(committableSignatureSlotArray(b.sigs), hfactory)
if err != nil {
return nil, err
}
Expand Down
Loading