Skip to content

Commit

Permalink
Eval: Feature/heartbeats (algorand#6189)
Browse files Browse the repository at this point in the history
Co-authored-by: cce <51567+cce@users.noreply.github.com>
Co-authored-by: Gary Malouf <982483+gmalouf@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 3e85ec3 commit 7eec510
Show file tree
Hide file tree
Showing 3 changed files with 346 additions and 0 deletions.
236 changes: 236 additions & 0 deletions msgp_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions msgp_gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions onetimesig.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,56 @@ type OneTimeSignature struct {
PK2Sig ed25519Signature `codec:"p2s"`
}

// A HeartbeatProof is functionally equivalent to a OneTimeSignature, but it has
// been cleaned up for use as a transaction field in heartbeat transactions.
type HeartbeatProof struct {
_struct struct{} `codec:",omitempty,omitemptyarray"`

// Sig is a signature of msg under the key PK.
Sig ed25519Signature `codec:"s"`
PK ed25519PublicKey `codec:"p"`

// PK2 is used to verify a two-level ephemeral signature.
PK2 ed25519PublicKey `codec:"p2"`
// PK1Sig is a signature of OneTimeSignatureSubkeyOffsetID(PK, Batch, Offset) under the key PK2.
PK1Sig ed25519Signature `codec:"p1s"`
// PK2Sig is a signature of OneTimeSignatureSubkeyBatchID(PK2, Batch) under the master key (OneTimeSignatureVerifier).
PK2Sig ed25519Signature `codec:"p2s"`
}

// ToOneTimeSignature converts a HeartbeatProof to a OneTimeSignature.
func (hbp HeartbeatProof) ToOneTimeSignature() OneTimeSignature {
return OneTimeSignature{
Sig: hbp.Sig,
PK: hbp.PK,
PK2: hbp.PK2,
PK1Sig: hbp.PK1Sig,
PK2Sig: hbp.PK2Sig,
}
}

// ToHeartbeatProof converts a OneTimeSignature to a HeartbeatProof.
func (ots OneTimeSignature) ToHeartbeatProof() HeartbeatProof {
return HeartbeatProof{
Sig: ots.Sig,
PK: ots.PK,
PK2: ots.PK2,
PK1Sig: ots.PK1Sig,
PK2Sig: ots.PK2Sig,
}
}

// BatchPrep enqueues the necessary checks into the batch. The caller must call
// batchVerifier.verify() to verify it.
func (hbp HeartbeatProof) BatchPrep(voteID OneTimeSignatureVerifier, id OneTimeSignatureIdentifier, msg Hashable, batchVerifier BatchVerifier) {
offsetID := OneTimeSignatureSubkeyOffsetID{SubKeyPK: hbp.PK, Batch: id.Batch, Offset: id.Offset}
batchID := OneTimeSignatureSubkeyBatchID{SubKeyPK: hbp.PK2, Batch: id.Batch}
batchVerifier.EnqueueSignature(PublicKey(voteID), batchID, Signature(hbp.PK2Sig))
batchVerifier.EnqueueSignature(PublicKey(batchID.SubKeyPK), offsetID, Signature(hbp.PK1Sig))
batchVerifier.EnqueueSignature(PublicKey(offsetID.SubKeyPK), msg, Signature(hbp.Sig))

}

// A OneTimeSignatureSubkeyBatchID identifies an ephemeralSubkey of a batch
// for the purposes of signing it with the top-level master key.
type OneTimeSignatureSubkeyBatchID struct {
Expand Down

0 comments on commit 7eec510

Please sign in to comment.