Skip to content

Commit

Permalink
Make merkle signer SNARK friendly (#3263)
Browse files Browse the repository at this point in the history
* The index of the merklearray can now be found in the merkle signature

* The merkle signature scheme commits on a raw  representation of the public keys.

* CC uses a non-msgpack representation of signatures

* add tests so the pk commitment stays as expected

* add test to validate that the part commitment format

* add tests to verifiy signature commitments

* add the support for signature format conversion

* commit on the  all the fields in merkle scheme signature

* remove interval from the merkle scheme verification.

* CR fixes

* integrate with falcon's CT format

* bind cert creation to falcon scheme

* verify signature's salt version

* signatureslot refacotr

* refactor participation for CC

* refactor and renaming

* protocol changes

* update license

* add MSS signature verification test

* remove the verification of the version in falcon

* handle an empty slot in the signature array

* minor changes

* CR fix

* renaming and comments clarification
  • Loading branch information
id-ms authored Jan 11, 2022
1 parent 244b5f2 commit b93f0e5
Show file tree
Hide file tree
Showing 35 changed files with 1,269 additions and 595 deletions.
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

0 comments on commit b93f0e5

Please sign in to comment.