Skip to content

Commit

Permalink
the used random must be cleared as soon as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Oct 6, 2022
1 parent 2dbbe4d commit f98ec8e
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions kernel/cosi.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (chain *Chain) checkActionSanity(m *CosiAction) error {
if a := chain.CosiAggregators[m.SnapshotHash]; a != nil {
s = a.Snapshot
}
case CosiActionExternalAnnouncement, CosiActionExternalFullChallenge:
case CosiActionExternalAnnouncement:
if chain.ChainId == chain.node.IdForNetwork {
return fmt.Errorf("external action announcement chain %s %s", chain.ChainId, chain.node.IdForNetwork)
}
Expand All @@ -150,24 +150,35 @@ func (chain *Chain) checkActionSanity(m *CosiAction) error {
if ov != nil && s.RoundNumber > 0 && ov.Snapshot.RoundNumber == s.RoundNumber && s.Timestamp < ov.Snapshot.Timestamp+config.SnapshotRoundGap {
return fmt.Errorf("a transaction %s only in one round %d of one chain %s", s.SoleTransaction(), s.RoundNumber, chain.ChainId)
}
case CosiActionExternalChallenge:
case CosiActionExternalFullChallenge:
if chain.ChainId == chain.node.IdForNetwork {
return fmt.Errorf("external action challenge chain %s %s", chain.ChainId, chain.node.IdForNetwork)
return fmt.Errorf("external action announcement chain %s %s", chain.ChainId, chain.node.IdForNetwork)
}
if chain.ChainId != m.PeerId {
return fmt.Errorf("external action challenge peer %s %s", chain.ChainId, m.PeerId)
return fmt.Errorf("external action announcement peer %s %s", chain.ChainId, m.PeerId)
}
if v := chain.CosiVerifiers[m.SnapshotHash]; v != nil {
s = v.Snapshot
if s.Signature != nil || s.Timestamp == 0 || m.Challenge == nil {
return fmt.Errorf("only empty snapshot with timestamp and challenge can be fully challenged")
}
}

if m.Challenge != nil && m.Action == CosiActionExternalFullChallenge {
m.random = chain.cosiRetrieveRandom(m.SnapshotHash, m.PeerId, m.Challenge)
if m.random == nil {
err := chain.cosiPrepareRandomsAndSendCommitments(m.PeerId, true)
return fmt.Errorf("no match random for the commitment %v %v", m, err)
}
ov := chain.CosiVerifiers[s.SoleTransaction()]
if ov != nil && s.RoundNumber > 0 && ov.Snapshot.RoundNumber == s.RoundNumber && s.Timestamp < ov.Snapshot.Timestamp+config.SnapshotRoundGap {
return fmt.Errorf("a transaction %s only in one round %d of one chain %s", s.SoleTransaction(), s.RoundNumber, chain.ChainId)
}
case CosiActionExternalChallenge:
if chain.ChainId == chain.node.IdForNetwork {
return fmt.Errorf("external action challenge chain %s %s", chain.ChainId, chain.node.IdForNetwork)
}
if chain.ChainId != m.PeerId {
return fmt.Errorf("external action challenge peer %s %s", chain.ChainId, m.PeerId)
}
if v := chain.CosiVerifiers[m.SnapshotHash]; v != nil {
s = v.Snapshot
}
}

if s == nil {
Expand Down

0 comments on commit f98ec8e

Please sign in to comment.