Skip to content

Commit

Permalink
Refactor & Implement explicit justification within modular framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ranchalp committed Jan 11, 2024
1 parent 6ed3e3d commit d5f3ee3
Show file tree
Hide file tree
Showing 9 changed files with 502 additions and 83 deletions.
32 changes: 30 additions & 2 deletions adversary/equiv.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package adversary

import (
"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-f3/f3"
"github.com/filecoin-project/go-f3/sim"
)
Expand All @@ -14,6 +15,7 @@ type WitholdCommit struct {
// The first victim is the target, others are those who need to confirm.
victims []f3.ActorID
victimValue f3.ECChain
senderIndex *f3.SenderIndex
}

// A participant that never sends anything.
Expand All @@ -29,6 +31,10 @@ func (w *WitholdCommit) SetVictim(victims []f3.ActorID, victimValue f3.ECChain)
w.victimValue = victimValue
}

func (w *WitholdCommit) SetSenderIndex(powerTable f3.PowerTable) {
w.senderIndex = f3.NewSenderIndex(powerTable)
}

func (w *WitholdCommit) ID() f3.ActorID {
return w.id
}
Expand Down Expand Up @@ -64,14 +70,36 @@ func (w *WitholdCommit) Begin() {
Value: w.victimValue,
Signature: w.host.Sign(w.id, f3.SignaturePayload(0, 0, f3.PREPARE, w.victimValue)),
})
w.host.BroadcastSynchronous(w.id, f3.GMessage{

message := f3.GMessage{
Sender: w.id,
Instance: 0,
Round: 0,
Step: f3.COMMIT,
Value: w.victimValue,
Signature: w.host.Sign(w.id, f3.SignaturePayload(0, 0, f3.COMMIT, w.victimValue)),
})
}
payload := f3.SignaturePayload(0, 0, f3.PREPARE, w.victimValue)
aggEvidence := f3.AggEvidence{
Step: f3.PREPARE,
Value: w.victimValue,
Instance: 0,
Round: 0,
Signers: bitfield.New(),
Signature: nil,
}
for _, actorID := range w.victims {
signature := w.host.Sign(actorID, payload)
aggSignature, signers := w.host.Aggregate(signature, actorID, aggEvidence.Signature, &aggEvidence.Signers, w.senderIndex.Actor2Index)
aggEvidence.Signature = aggSignature
aggEvidence.Signers = *signers
}
signature := w.host.Sign(w.id, payload)
aggSignature, signers := w.host.Aggregate(signature, w.id, aggEvidence.Signature, &aggEvidence.Signers, w.senderIndex.Actor2Index)
aggEvidence.Signature = aggSignature
aggEvidence.Signers = *signers
message.Evidence = aggEvidence
w.host.BroadcastSynchronous(w.id, message)
}

func (w *WitholdCommit) AllowMessage(_ f3.ActorID, to f3.ActorID, msg f3.Message) bool {
Expand Down
6 changes: 4 additions & 2 deletions f3/api.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package f3

import "github.com/filecoin-project/go-bitfield"

// Receives EC chain values.
type ChainReceiver interface {
// Receives a chain appropriate for use as initial proposals for a Granite instance.
Expand Down Expand Up @@ -53,9 +55,9 @@ type Signer interface {

type Aggregator interface {
// Aggregates signatures from a participant to an existing signature.
Aggregate(msg, sig []byte, aggSignature []byte) []byte
Aggregate(sig []byte, senderID ActorID, aggSignature []byte, signers *bitfield.BitField, actor2Index map[ActorID]uint64) ([]byte, *bitfield.BitField)
// VerifyAggregate verifies an aggregate signature.
VerifyAggregate(msg, aggSig []byte, signers []byte) bool
VerifyAggregate(msg, aggSig []byte, signers *bitfield.BitField, actor2Index map[ActorID]uint64) bool
}

// Participant interface to the host system resources.
Expand Down
4 changes: 0 additions & 4 deletions f3/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ func NewChain(base TipSet, suffix ...TipSet) ECChain {
return append([]TipSet{base}, suffix...)
}

func ZeroECChain() ECChain {
return ECChain{}
}

func (c ECChain) IsZero() bool {
return len(c) == 0
}
Expand Down
Loading

0 comments on commit d5f3ee3

Please sign in to comment.