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

Algod: Compcert msg into struct #3742

Merged
merged 34 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e82dec5
compactcert msgpo type and domain separator
algonathan Mar 6, 2022
5ed385f
compactcert msgpo type and domain separator
algonathan Mar 6, 2022
913f01d
compcerts to work with fixed size messages
algonathan Mar 6, 2022
f90f5d1
copying message.Hash instead of saving it while cfalcon isn't fixec
algonathan Mar 10, 2022
1715082
fix: working with Message struct instead of []byte
algonathan Mar 10, 2022
ebcfbb0
fix: import order
algonathan Mar 10, 2022
4a1aa4a
fix: used the wrong variable inside test
algonathan Mar 10, 2022
e305a7a
Renamed message into stateproofMessage
algonathan Mar 10, 2022
e41e8db
Renamed message into stateproofMessage
algonathan Mar 10, 2022
7fe0ed9
added todo comment
algonathan Mar 10, 2022
2749532
renamed the hashtype
algonathan Mar 10, 2022
14936b5
moving stateProofMessage from crypto/compcert to compcert
algonathan Mar 10, 2022
f46ada1
moving stateProofMessage from crypto/compcert to data/stateproof
algonathan Mar 10, 2022
cf4d4b2
using stateproof messages
algonathan Mar 10, 2022
99c78da
fix: unit test which i've edited by accident
algonathan Mar 10, 2022
f4e508a
fix: e2e-test
algonathan Mar 10, 2022
e269493
fix: e2e-test
algonathan Mar 10, 2022
4fbd24b
fix: missing liscense
algonathan Mar 10, 2022
06b528c
removed empty line
algonathan Mar 10, 2022
813ffef
removing pointer usage
algonathan Mar 10, 2022
8abfa25
modified v1 certMsg into a msgpacked msg
algonathan Mar 14, 2022
ebb3ac0
modified v1 certMsg into a msgpacked msg
algonathan Mar 14, 2022
24e41ac
adding '.' at end of sentence
algonathan Mar 14, 2022
41de811
renaming stateproof.Message field name
algonathan Mar 14, 2022
fc5eb4e
rebuild_swagger
algonathan Mar 14, 2022
615bb47
Merge branch 'feature/stateproofs' into compcert-msg
algonathan Mar 14, 2022
cec1aac
changed comment
algonathan Mar 14, 2022
0ea40c2
ToBeHashed using protocol.Encode
algonathan Mar 14, 2022
70a364f
ToBeHashed using protocol.Encode
algonathan Mar 14, 2022
51f8f88
import order
algonathan Mar 14, 2022
1a466d3
removed extra space
algonathan Mar 14, 2022
46a7237
moved creating the messageGeneration out of the loop
algonathan Mar 14, 2022
6cd86ab
fix: changed by accident some unit test
algonathan Mar 14, 2022
6c00224
fix: ordering the domain separators
algonathan Mar 14, 2022
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
5 changes: 3 additions & 2 deletions compactcert/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (ccw *Worker) builderForRound(rnd basics.Round) (builder, error) {
return builder{}, err
}

p, err := ledger.CompactCertParams(msg, votersHdr, hdr)
p, err := ledger.CompactCertParams(*msg, votersHdr, hdr)
if err != nil {
return builder{}, err
}
Expand Down Expand Up @@ -357,7 +357,8 @@ func (ccw *Worker) tryBuilding() {
stxn.Txn.GenesisHash = ccw.ledger.GenesisHash()
stxn.Txn.CertIntervalLatestRound = rnd
stxn.Txn.Cert = *cert
stxn.Txn.CertMsg = b.Msg

algonathan marked this conversation as resolved.
Show resolved Hide resolved
stxn.Txn.CertMsg = b.Params.StateProofMessage
err = ccw.txnSender.BroadcastSignedTxGroup([]transactions.SignedTxn{stxn})
if err != nil {
ccw.log.Warnf("ccw.tryBuilding: broadcasting compact cert txn for %d: %v", rnd, err)
Expand Down
8 changes: 5 additions & 3 deletions compactcert/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/crypto/compactcert"
"github.com/algorand/go-algorand/crypto/merklearray"
"github.com/algorand/go-algorand/crypto/merklesignature"
"github.com/algorand/go-algorand/data/account"
Expand Down Expand Up @@ -109,7 +110,7 @@ restart:
// GenerateStateProofMessage builds a merkle tree from the block headers of the entire interval (up until current round), and returns the root
// for the account to sign upon. The tree can be stored for performance but does not have to be since it can always be rebuilt from scratch.
// This is the message the Compact Certificate will attest to.
func GenerateStateProofMessage(ledger Ledger, compactCertRound basics.Round, compactCertInterval uint64) ([]byte, error) {
func GenerateStateProofMessage(ledger Ledger, compactCertRound basics.Round, compactCertInterval uint64) (*compactcert.StateProofMessage, error) {
algonathan marked this conversation as resolved.
Show resolved Hide resolved
if compactCertRound < basics.Round(compactCertInterval) {
return nil, fmt.Errorf("GenerateStateProofMessage compactCertRound must be >= than compactCertInterval (%w)", errInvalidParams)
}
Expand All @@ -131,7 +132,7 @@ func GenerateStateProofMessage(ledger Ledger, compactCertRound basics.Round, com
return nil, err
}

return tree.Root().ToSlice(), nil
return &compactcert.StateProofMessage{Payload: tree.Root().ToSlice()}, nil
}

func (ccw *Worker) signBlock(hdr bookkeeping.BlockHeader) {
Expand Down Expand Up @@ -183,7 +184,8 @@ func (ccw *Worker) signBlock(hdr bookkeeping.BlockHeader) {
ccw.log.Warnf("ccw.signBlock(%d): GenerateStateProofMessage: %v", hdr.Round, err)
continue
}
sig, err := key.StateProofSecrets.SignBytes(commitment)
tmp := commitment.Hash()
algonathan marked this conversation as resolved.
Show resolved Hide resolved
sig, err := key.StateProofSecrets.SignBytes(tmp[:])
if err != nil {
ccw.log.Warnf("ccw.signBlock(%d): StateProofSecrets.Sign: %v", hdr.Round, err)
continue
Expand Down
20 changes: 10 additions & 10 deletions compactcert/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,16 @@ func TestWorkerAllSigs(t *testing.T) {

msg, err := GenerateStateProofMessage(s, tx.Txn.CertIntervalLatestRound, proto.CompactCertRounds)
require.NoError(t, err)
require.Equal(t, msg, tx.Txn.CertMsg)
require.Equal(t, *msg, tx.Txn.CertMsg)

provenWeight, overflowed := basics.Muldiv(uint64(s.totalWeight), uint64(proto.CompactCertWeightThreshold), 1<<32)
require.False(t, overflowed)

ccparams := compactcert.Params{
Msg: tx.Txn.CertMsg,
ProvenWeight: provenWeight,
SigRound: tx.Txn.CertIntervalLatestRound,
SecKQ: proto.CompactCertSecKQ,
StateProofMessage: tx.Txn.CertMsg,
ProvenWeight: provenWeight,
SigRound: tx.Txn.CertIntervalLatestRound,
SecKQ: proto.CompactCertSecKQ,
}

voters, err := s.CompactCertVoters(tx.Txn.CertIntervalLatestRound - basics.Round(proto.CompactCertRounds) - basics.Round(proto.CompactCertVotersLookback))
Expand Down Expand Up @@ -353,16 +353,16 @@ func TestWorkerPartialSigs(t *testing.T) {

msg, err := GenerateStateProofMessage(s, tx.Txn.CertIntervalLatestRound, proto.CompactCertRounds)
require.NoError(t, err)
require.Equal(t, msg, tx.Txn.CertMsg)
require.Equal(t, *msg, tx.Txn.CertMsg)

provenWeight, overflowed := basics.Muldiv(uint64(s.totalWeight), uint64(proto.CompactCertWeightThreshold), 1<<32)
require.False(t, overflowed)

ccparams := compactcert.Params{
Msg: msg,
ProvenWeight: provenWeight,
SigRound: basics.Round(tx.Txn.CertIntervalLatestRound),
SecKQ: proto.CompactCertSecKQ,
StateProofMessage: *msg,
ProvenWeight: provenWeight,
SigRound: basics.Round(tx.Txn.CertIntervalLatestRound),
SecKQ: proto.CompactCertSecKQ,
}

voters, err := s.CompactCertVoters(tx.Txn.CertIntervalLatestRound - basics.Round(proto.CompactCertRounds) - basics.Round(proto.CompactCertVotersLookback))
Expand Down
10 changes: 8 additions & 2 deletions crypto/compactcert/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Builder struct {
// Cached cert, if Build() was called and no subsequent
// Add() calls were made.
cert *Cert
Msg StateProofMessageHash
}

// MkBuilder constructs an empty builder (with no signatures). The message
Expand All @@ -62,7 +63,9 @@ func MkBuilder(param Params, part []basics.Participant, parttree *merklearray.Tr
npart := len(part)

b := &Builder{
Params: param,
Params: param,
Msg: param.StateProofMessage.Hash(),

sigs: make([]sigslot, npart),
sigsHasValidL: false,
signedWeight: 0,
Expand Down Expand Up @@ -98,7 +101,10 @@ func (b *Builder) IsValid(pos uint64, sig merklesignature.Signature, verifySig b
if err := sig.ValidateSigVersion(merklesignature.SchemeVersion); err != nil {
return err
}
if err := p.PK.VerifyBytes(uint64(b.SigRound), b.Msg, sig); err != nil {

cpy := make([]byte, len(b.Msg))
copy(cpy, b.Msg[:])
if err := p.PK.VerifyBytes(uint64(b.SigRound), cpy, sig); err != nil {
return err
}
}
Expand Down
24 changes: 16 additions & 8 deletions crypto/compactcert/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func TestBuildVerify(t *testing.T) {
npart := npartHi + npartLo

param := Params{
Msg: testMessage("hello world"),
StateProofMessage: StateProofMessage{Payload: testMessage("hello world")},

ProvenWeight: uint64(totalWeight / 2),
SigRound: currentRound,
SecKQ: compactCertSecKQForTests,
Expand All @@ -103,7 +104,8 @@ func TestBuildVerify(t *testing.T) {
parts = append(parts, createParticipantSliceWithWeight(totalWeight, npartLo, key.GetVerifier())...)

signerInRound := key.GetSigner(uint64(currentRound))
sig, err := signerInRound.SignBytes(param.Msg)
tmp := param.StateProofMessage.Hash()
sig, err := signerInRound.SignBytes(tmp[:])
require.NoError(t, err, "failed to create keys")

for i := 0; i < npart; i++ {
Expand Down Expand Up @@ -230,7 +232,8 @@ func TestSignatureCommitmentBinaryFormat(t *testing.T) {
numPart := 4

param := Params{
Msg: testMessage("test!"),
StateProofMessage: StateProofMessage{Payload: testMessage("test!")},

ProvenWeight: uint64(totalWeight / (2 * numPart)),
SigRound: currentRound,
SecKQ: compactCertSecKQForTests,
Expand All @@ -248,7 +251,8 @@ func TestSignatureCommitmentBinaryFormat(t *testing.T) {
}
parts = append(parts, part)

sig, err := key.GetSigner(uint64(currentRound)).SignBytes(param.Msg)
tmp := param.StateProofMessage.Hash()
sig, err := key.GetSigner(uint64(currentRound)).SignBytes(tmp[:])
require.NoError(t, err, "failed to create keys")
sigs = append(sigs, sig)

Expand Down Expand Up @@ -426,7 +430,8 @@ func BenchmarkBuildVerify(b *testing.B) {
a := require.New(b)

param := Params{
Msg: testMessage("hello world"),
StateProofMessage: StateProofMessage{Payload: testMessage("hello world")},

ProvenWeight: uint64(totalWeight / 2),
SigRound: compactCertRoundsForTests,
SecKQ: compactCertSecKQForTests,
Expand All @@ -443,7 +448,8 @@ func BenchmarkBuildVerify(b *testing.B) {
}

signerInRound := signer.GetSigner(uint64(currentRound))
sig, err := signerInRound.SignBytes(param.Msg)
tmp := param.StateProofMessage.Hash()
sig, err := signerInRound.SignBytes(tmp[:])
require.NoError(b, err, "failed to create keys")

partkeys = append(partkeys, signer)
Expand Down Expand Up @@ -520,7 +526,8 @@ func TestBuilder_AddRejectsInvalidSigVersion(t *testing.T) {
npartLo := 9

param := Params{
Msg: testMessage("hello world"),
StateProofMessage: StateProofMessage{Payload: testMessage("hello world")},

ProvenWeight: uint64(totalWeight / 2),
SigRound: currentRound,
SecKQ: compactCertSecKQForTests,
Expand All @@ -539,7 +546,8 @@ func TestBuilder_AddRejectsInvalidSigVersion(t *testing.T) {

// actual test:
signerInRound := key.GetSigner(uint64(currentRound))
sig, err := signerInRound.SignBytes(param.Msg)
tmp := param.Hash()
sig, err := signerInRound.SignBytes(tmp[:])
require.NoError(t, err, "failed to create keys")
// Corrupting the version of the signature:
sig.Signature[1]++
Expand Down
12 changes: 6 additions & 6 deletions crypto/compactcert/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import (
type coinChoice struct {
_struct struct{} `codec:",omitempty,omitemptyarray"`

J uint64 `codec:"j"`
SignedWeight uint64 `codec:"sigweight"`
ProvenWeight uint64 `codec:"provenweight"`
Sigcom crypto.GenericDigest `codec:"sigcom"`
Partcom crypto.GenericDigest `codec:"partcom"`
Msg []byte `codec:"msg"`
J uint64 `codec:"j"`
SignedWeight uint64 `codec:"sigweight"`
ProvenWeight uint64 `codec:"provenweight"`
Sigcom crypto.GenericDigest `codec:"sigcom"`
Partcom crypto.GenericDigest `codec:"partcom"`
Msg StateProofMessageHash `codec:"msg"`
}

// ToBeHashed implements the crypto.Hashable interface.
Expand Down
4 changes: 2 additions & 2 deletions crypto/compactcert/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestHashCoin(t *testing.T) {
var slots [32]uint64
var sigcom = make(crypto.GenericDigest, HashSize)
var partcom = make(crypto.GenericDigest, HashSize)
var msgHash = make(crypto.GenericDigest, HashSize)
var msgHash = StateProofMessageHash{}

crypto.RandBytes(sigcom[:])
crypto.RandBytes(partcom[:])
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestHashCoin(t *testing.T) {
func BenchmarkHashCoin(b *testing.B) {
var sigcom = make(crypto.GenericDigest, HashSize)
var partcom = make(crypto.GenericDigest, HashSize)
var msgHash = make(crypto.GenericDigest, HashSize)
var msgHash = StateProofMessageHash{}

crypto.RandBytes(sigcom[:])
crypto.RandBytes(partcom[:])
Expand Down
Loading