Skip to content

Commit

Permalink
Test additional invalid justifications (#626)
Browse files Browse the repository at this point in the history
Test validation for invalid justifications with:
* inconsistent supplemental data
* insufficient power
* unknown signer
* evidence from another instance

Fixes #235

part of #249
  • Loading branch information
masih authored Sep 4, 2024
1 parent 5f7b362 commit e912882
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
4 changes: 4 additions & 0 deletions emulator/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (i *Instance) NewJustification(round uint64, step gpbft.Phase, vote gpbft.E
SupplementalData: i.supplementalData,
Value: vote,
}
return i.NewJustificationWithPayload(payload, from...)
}

func (i *Instance) NewJustificationWithPayload(payload gpbft.Payload, from ...gpbft.ActorID) *gpbft.Justification {
msg := signing.MarshalPayloadForSigning(networkName, &payload)
qr := gpbft.QuorumResult{
Signers: make([]int, len(from)),
Expand Down
72 changes: 72 additions & 0 deletions gpbft/gpbft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,78 @@ func TestGPBFT_Validation(t *testing.T) {
},
errContains: "justification with unexpected phase",
},
{
name: "justification without strong quorum",
message: func(instance *emulator.Instance, driver *emulator.Driver) *gpbft.GMessage {
return &gpbft.GMessage{
Sender: 1,
Vote: instance.NewPrepare(3, gpbft.ECChain{}),
Ticket: emulator.ValidTicket,
Justification: instance.NewJustification(2, gpbft.COMMIT_PHASE, gpbft.ECChain{}, 0),
}
},
errContains: "has justification with insufficient power",
},
{
name: "justification with unknown signer",
message: func(instance *emulator.Instance, driver *emulator.Driver) *gpbft.GMessage {
otherInstance := emulator.NewInstance(t, 0, append(participants, gpbft.PowerEntry{
ID: 42,
Power: gpbft.NewStoragePower(1),
}), tipset0, tipSet1, tipSet2)

return &gpbft.GMessage{
Sender: 1,
Vote: instance.NewPrepare(3, gpbft.ECChain{}),
Ticket: emulator.ValidTicket,
Justification: otherInstance.NewJustificationWithPayload(gpbft.Payload{
Instance: instance.ID(),
Round: 2,
Step: gpbft.COMMIT_PHASE,
SupplementalData: instance.SupplementalData(),
Value: gpbft.ECChain{},
}, 0, 1, 2, 42),
}
},
errContains: "invalid signer index: 3",
},
{
name: "justification for another instance",
message: func(instance *emulator.Instance, driver *emulator.Driver) *gpbft.GMessage {
otherInstance := emulator.NewInstance(t, 33, participants, instance.Proposal()...)
return &gpbft.GMessage{
Sender: 1,
Vote: instance.NewPrepare(3, gpbft.ECChain{}),
Ticket: emulator.ValidTicket,
Justification: otherInstance.NewJustification(0, gpbft.PREPARE_PHASE, gpbft.ECChain{}, 0, 1, 2),
}
},
errContains: "message with instanceID 0 has evidence from instanceID: 33",
},
{
name: "justification with inconsistent supplemental data",
message: func(instance *emulator.Instance, driver *emulator.Driver) *gpbft.GMessage {
someCid, err := cid.Decode("bafy2bzacedgbq7e3eb4l3ryhbfckvez5mty6ylw5ulofkxql5bfxxji7xt5a2")
require.NoError(t, err)
require.NotEqual(t, instance.SupplementalData().PowerTable, someCid)
return &gpbft.GMessage{
Sender: 1,
Vote: instance.NewPrepare(3, gpbft.ECChain{}),
Ticket: emulator.ValidTicket,
Justification: instance.NewJustificationWithPayload(gpbft.Payload{
Instance: instance.ID(),
Round: 2,
Step: gpbft.COMMIT_PHASE,
SupplementalData: gpbft.SupplementalData{
Commitments: [32]byte{},
PowerTable: someCid,
},
Value: gpbft.ECChain{},
}, 0, 1, 2),
}
},
errContains: "message and justification have inconsistent supplemental data",
},
{
name: "justification aggregate with unsorted signatures",
message: func(instance *emulator.Instance, driver *emulator.Driver) *gpbft.GMessage {
Expand Down

0 comments on commit e912882

Please sign in to comment.