Skip to content

Commit

Permalink
range panic
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstam committed Feb 14, 2024
1 parent 2d972bf commit b62eb2c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions plonky2x/verifier/system/groth16.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"math/big"
"os"
Expand Down Expand Up @@ -268,13 +269,23 @@ func (s *Groth16System) ProveCircuit(r1cs constraint.ConstraintSystem, pk groth1

const fpSize = 4 * 8

// read in proof.json and extract the proof bytes
proofBytes := _proof.Ar.Marshal()

// Ensure proofBytes contains enough data for the expected operation
expectedLength := fpSize * 8
if len(proofBytes) < expectedLength {
return nil, nil, fmt.Errorf("proofBytes length is %d, expected at least %d", len(proofBytes), expectedLength)
}

proofs := make([]string, 8)
// Print out the proof
for i := 0; i < 8; i++ {
proofs[i] = "0x" + hex.EncodeToString(proofBytes[i*fpSize:(i+1)*fpSize])
start := i * fpSize
end := (i + 1) * fpSize
// Additional check to prevent slice bounds out of range panic
if end > len(proofBytes) {
return nil, nil, fmt.Errorf("attempt to slice beyond proofBytes length at segment %d", i)
}
proofs[i] = "0x" + hex.EncodeToString(proofBytes[start:end])
}

publicWitness, _ := witness.Public()
Expand Down

0 comments on commit b62eb2c

Please sign in to comment.