coinbase / kryptology

Apache License 2.0
847 stars 123 forks source link

"cap out of range error" in pkg/signatures/bbs/pok_signature_proof.go #31

Closed boumba100 closed 2 years ago

boumba100 commented 2 years ago

Expected Behaviour

Calling GetContributionChallenge for all revealed proof messages should not throw an error.

Actual Behaviour

The function throws the following error:\ panic: runtime error: makeslice: cap out of range

Steps to Reproduce the Problem

In the test file, replace proofMsgs with the following

    proofMsgs := []common.ProofMessage{
        &common.RevealedMessage{
            Message: msgs[0],
        },
        &common.RevealedMessage{
            Message: msgs[1],
        },
        &common.RevealedMessage{
            Message: msgs[2],
        },
        &common.RevealedMessage{
            Message: msgs[3],
        },
    }

and replace the revealedMsgs with

    revealedMsgs := map[int]curves.Scalar{
        0: msgs[0],
        1: msgs[1],
        2: msgs[2],
        3: msgs[3],
    }

Issue

The following expression calculates an expected array capacity that is smaller than the length of proof2Points and proof2Scalars.

Suggested Fix

Replace pts := 2 + generators.length - len(revealedMessages) with pts := 3 + generators.length - len(revealedMessages)

Replace 2 with 3 since the affected arrays have a minimum length of 3.

mikelodder7 commented 2 years ago

Good catch. Looks like you already submitted a PR. Will review.