diff --git a/gjkr/evidence_log.go b/gjkr/evidence_log.go index a2bc12a..8d344af 100644 --- a/gjkr/evidence_log.go +++ b/gjkr/evidence_log.go @@ -27,43 +27,36 @@ import ( // sent by the accused party. To do this, they read the round 3 message from the // log, and decrypt it using the symmetric key used between the accuser and // accused party. The key is publicly revealed by the accuser. -type evidenceLog interface { - // getEphemeralPublicKeyMessage returns the `ephemeralPublicKeyMessage` - // broadcast in the first protocol round by the given sender. - getEphemeralPublicKeyMessage(sender memberIndex) *ephemeralPublicKeyMessage - - // putEphemeralMessage is a function that takes a single - // EphemeralPubKeyMessage, and stores that as evidence for future - // accusation trials for a given (sender, receiver) pair. If a message - // already exists for the given sender, we return an error to the user. - putEphemeralPublicKeyMessage(pubKeyMessage *ephemeralPublicKeyMessage) error -} - -// dkgEvidenceLog is the default implementation of an evidenceLog. -type dkgEvidenceLog struct { +type evidenceLog struct { // senderIndex -> *ephemeralPublicKeyMessage pubKeyMessageLog *messageStorage } -func newDkgEvidenceLog() *dkgEvidenceLog { - return &dkgEvidenceLog{ +func newEvidenceLog() *evidenceLog { + return &evidenceLog{ pubKeyMessageLog: newMessageStorage(), } } -func (d *dkgEvidenceLog) putEphemeralPublicKeyMessage( +// putEphemeralMessage is a function that takes a single +// EphemeralPubKeyMessage, and stores that as evidence for future +// accusation trials for a given (sender, receiver) pair. If a message +// already exists for the given sender, we return an error to the user. +func (e *evidenceLog) putEphemeralPublicKeyMessage( pubKeyMessage *ephemeralPublicKeyMessage, ) error { - return d.pubKeyMessageLog.putMessage( + return e.pubKeyMessageLog.putMessage( pubKeyMessage.senderIndex, pubKeyMessage, ) } -func (d *dkgEvidenceLog) getEphemeralPublicKeyMessage( +// getEphemeralPublicKeyMessage returns the `ephemeralPublicKeyMessage` +// broadcast in the first protocol round by the given sender. +func (e *evidenceLog) getEphemeralPublicKeyMessage( sender memberIndex, ) *ephemeralPublicKeyMessage { - storedMessage := d.pubKeyMessageLog.getMessage(sender) + storedMessage := e.pubKeyMessageLog.getMessage(sender) switch message := storedMessage.(type) { case *ephemeralPublicKeyMessage: return message diff --git a/gjkr/evidence_log_test.go b/gjkr/evidence_log_test.go index 3ad0187..a7c86b4 100644 --- a/gjkr/evidence_log_test.go +++ b/gjkr/evidence_log_test.go @@ -8,8 +8,8 @@ import ( ) func TestPutEphemeralPublicKeyMessageTwice(t *testing.T) { - dkgEvidenceLog := newDkgEvidenceLog() - err := dkgEvidenceLog.putEphemeralPublicKeyMessage( + evidenceLog := newEvidenceLog() + err := evidenceLog.putEphemeralPublicKeyMessage( &ephemeralPublicKeyMessage{ senderIndex: memberIndex(1), }) @@ -17,7 +17,7 @@ func TestPutEphemeralPublicKeyMessageTwice(t *testing.T) { t.Fatalf("unexpected error: [%v]", err) } - err = dkgEvidenceLog.putEphemeralPublicKeyMessage( + err = evidenceLog.putEphemeralPublicKeyMessage( &ephemeralPublicKeyMessage{ senderIndex: memberIndex(1), }) @@ -34,23 +34,23 @@ func TestPutEphemeralPublicKeyMessageTwice(t *testing.T) { } func TestPutGetEphemeralPublicKeyMessage(t *testing.T) { - dkgEvidenceLog := newDkgEvidenceLog() + evidenceLog := newEvidenceLog() message := &ephemeralPublicKeyMessage{ senderIndex: memberIndex(1), } - m := dkgEvidenceLog.getEphemeralPublicKeyMessage(memberIndex(1)) + m := evidenceLog.getEphemeralPublicKeyMessage(memberIndex(1)) if m != nil { t.Fatalf("expected message not to be found but has [%v]", m) } - err := dkgEvidenceLog.putEphemeralPublicKeyMessage(message) + err := evidenceLog.putEphemeralPublicKeyMessage(message) if err != nil { t.Fatalf("unexpected error: [%v]", err) } - m = dkgEvidenceLog.getEphemeralPublicKeyMessage(memberIndex(1)) + m = evidenceLog.getEphemeralPublicKeyMessage(memberIndex(1)) if !reflect.DeepEqual(message, m) { t.Fatalf( "unexpected message\nexpected: %v\nactual: %v",