~edwargix/tallyard

0d9ca2b4c761df52873615087aaa8f84fd761c8a — David Florness 2 years ago 693014c
Check for nil pointer

We've been seeing nil pointer panics in this function.
1 files changed, 20 insertions(+), 13 deletions(-)

M election/msg.go
M election/msg.go => election/msg.go +20 -13
@@ 598,10 598,17 @@ func (elections *ElectionsMap) onEvalsMessage(evt *event.Event) (success bool) {
		return
	}

	// here to find bugs
	if el.FinalJoinIDs == nil {
		errorf("FinalJoinIDs is nil")
		return
	}
	FinalJoinIDs := *el.FinalJoinIDs

	// KeysIDs
	if len(content.KeysIDs) != len(*el.FinalJoinIDs) {
	if len(content.KeysIDs) != len(FinalJoinIDs) {
		warnf("the number of keys IDs is wrong (%s instead of %s)",
			len(content.KeysIDs), len(*el.FinalJoinIDs))
			len(content.KeysIDs), len(FinalJoinIDs))
		return
	}
	for i, keysID := range content.KeysIDs {


@@ 610,17 617,17 @@ func (elections *ElectionsMap) onEvalsMessage(evt *event.Event) (success bool) {
			debugf("we couldn't get the keys event, %s", keysID)
			return
		}
		if keysEvent.JoinID != (*el.FinalJoinIDs)[i] {
		if keysEvent.JoinID != FinalJoinIDs[i] {
			warnf("the join ID (%s) of a key (%s) does not match the start event's join ID (%s)",
				keysEvent.JoinID, keysID, (*el.FinalJoinIDs)[i])
				keysEvent.JoinID, keysID, FinalJoinIDs[i])
			return
		}
		contents = append(contents, keysEvent.Content)
	}

	if len(content.Evals) != len(*el.FinalJoinIDs) {
	if len(content.Evals) != len(FinalJoinIDs) {
		warnf("the number of evals is wrong (%s instead of %s)",
			len(content.Evals), len(*el.FinalJoinIDs))
			len(content.Evals), len(FinalJoinIDs))
		return
	}



@@ 705,7 712,7 @@ func (elections *ElectionsMap) onEvalsMessage(evt *event.Event) (success bool) {
		}
	}

	outputHashes := make([][]byte, len(*el.FinalJoinIDs))
	outputHashes := make([][]byte, len(FinalJoinIDs))
	for i, eval := range content.Evals {
		var err error
		outputHashes[i], err = base64.StdEncoding.DecodeString(eval.OutputHash)


@@ 721,18 728,18 @@ func (elections *ElectionsMap) onEvalsMessage(evt *event.Event) (success bool) {

		// public
		publicCircuit.HashSeed = el.GetHashSeed()
		publicCircuit.Inputs = make([]frontend.Variable, len(*el.FinalJoinIDs))
		for i, joinID := range *el.FinalJoinIDs {
		publicCircuit.Inputs = make([]frontend.Variable, len(FinalJoinIDs))
		for i, joinID := range FinalJoinIDs {
			publicCircuit.Inputs[i].Assign(&el.Joins[joinID].Input)
		}
		publicCircuit.OutputHashes = make([]frontend.Variable, len(*el.FinalJoinIDs))
		publicCircuit.OutputHashes = make([]frontend.Variable, len(FinalJoinIDs))
		for i, outputHash := range outputHashes {
			publicCircuit.OutputHashes[i].Assign(outputHash)
		}

		// private
		publicCircuit.BallotBits = make([]frontend.Variable, len(el.Candidates)*len(el.Candidates))
		publicCircuit.Coeffs = make([]frontend.Variable, len(*el.FinalJoinIDs)-1)
		publicCircuit.Coeffs = make([]frontend.Variable, len(FinalJoinIDs)-1)

		if el.LocalVoter.EvalVerifyingKey == nil {
			// should never happen because we processed all keys


@@ 766,13 773,13 @@ func (elections *ElectionsMap) onEvalsMessage(evt *event.Event) (success bool) {
	voter.OutputHashes = &outputHashes

	// calculate our sum if we have everyone's outputs
	for _, voterID := range *el.FinalJoinIDs {
	for _, voterID := range FinalJoinIDs {
		if el.Joins[voterID].Output == nil {
			return true
		}
	}
	sum := new(fr.Element).SetZero()
	for _, voterID := range *el.FinalJoinIDs {
	for _, voterID := range FinalJoinIDs {
		sum.Add(sum, el.Joins[voterID].Output)
	}
	el.LocalVoter.Sum = sum