Skip to content

Commit

Permalink
Merge pull request #20 from reclaimprotocol/remove-proofjson
Browse files Browse the repository at this point in the history
[FEAT] remove proofJson and move proof one level up for simplicity
  • Loading branch information
Scratch-net authored Dec 27, 2024
2 parents 688f4bd + 60e33a3 commit c9df4f9
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 20 deletions.
Binary file modified bin/gnark/linux-arm64-libprove.so
Binary file not shown.
Binary file modified bin/gnark/linux-arm64-libverify.so
Binary file not shown.
Binary file modified bin/gnark/linux-x86_64-libprove.so
Binary file not shown.
Binary file modified bin/gnark/linux-x86_64-libverify.so
Binary file not shown.
12 changes: 6 additions & 6 deletions gnark/libraries/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestFullChaCha20(t *testing.T) {

inParams := &verifier.InputVerifyParams{
Cipher: inputParams.Cipher,
Proof: outParams.Proof.ProofJson,
Proof: outParams.Proof,
PublicSignals: signals,
}
inBuf, err := json.Marshal(inParams)
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestFullAES256(t *testing.T) {

inParams := &verifier.InputVerifyParams{
Cipher: inputParams.Cipher,
Proof: outParams.Proof.ProofJson,
Proof: outParams.Proof,
PublicSignals: signals,
}
inBuf, _ := json.Marshal(inParams)
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestFullAES128(t *testing.T) {

inParams := &verifier.InputVerifyParams{
Cipher: inputParams.Cipher,
Proof: outParams.Proof.ProofJson,
Proof: outParams.Proof,
PublicSignals: signals,
}
inBuf, _ := json.Marshal(inParams)
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestFullChaCha20OPRF(t *testing.T) {

inParams := &verifier.InputVerifyParams{
Cipher: inputParams.Cipher,
Proof: outParams.Proof.ProofJson,
Proof: outParams.Proof,
PublicSignals: publicSignals,
}
inBuf, _ := json.Marshal(inParams)
Expand Down Expand Up @@ -470,7 +470,7 @@ func TestFullAES128OPRF(t *testing.T) {

inParams := &verifier.InputVerifyParams{
Cipher: inputParams.Cipher,
Proof: outParams.Proof.ProofJson,
Proof: outParams.Proof,
PublicSignals: publicSignals,
}
inBuf, _ := json.Marshal(inParams)
Expand Down Expand Up @@ -610,7 +610,7 @@ func TestFullAES256OPRF(t *testing.T) {

inParams := &verifier.InputVerifyParams{
Cipher: inputParams.Cipher,
Proof: outParams.Proof.ProofJson,
Proof: outParams.Proof,
PublicSignals: publicSignals,
}
inBuf, _ := json.Marshal(inParams)
Expand Down
10 changes: 2 additions & 8 deletions gnark/libraries/prover/impl/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,8 @@ var provers = map[string]*ProverParams{
},
}

type Proof struct {
ProofJson []uint8 `json:"proofJson"`
}

type OutputParams struct {
Proof Proof `json:"proof"`
Proof []uint8 `json:"proof"`
PublicSignals []uint8 `json:"publicSignals"`
}

Expand Down Expand Up @@ -152,9 +148,7 @@ func Prove(params []byte) []byte {
proof, ciphertext := prover.Prove(inputParams)

res, er := json.Marshal(&OutputParams{
Proof: Proof{
ProofJson: proof,
},
Proof: proof,
PublicSignals: ciphertext,
})
if er != nil {
Expand Down
4 changes: 2 additions & 2 deletions js/src/gnark/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export function makeGnarkZkOperator({
async groth16Prove(witness, logger) {
const lib = await initGnark(logger)
const {
proof: { proofJson },
proof,
publicSignals
} = await executeGnarkFnAndGetJson(lib.prove, witness)
return {
proof: Base64.toUint8Array(proofJson),
proof: Base64.toUint8Array(proof),
publicSignals: Array.from(Base64.toUint8Array(publicSignals))
}
},
Expand Down
4 changes: 2 additions & 2 deletions js/src/gnark/toprf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export function makeGnarkOPRFOperator({
async groth16Prove(witness, logger) {
const lib = await initGnark(logger)
const {
proof: { proofJson }
proof
} = await executeGnarkFnAndGetJson(lib.prove, witness)
return { proof: Base64.toUint8Array(proofJson) }
return { proof: Base64.toUint8Array(proof) }
},
async groth16Verify(publicSignals, proof, logger) {
const lib = await initGnark(logger)
Expand Down
4 changes: 2 additions & 2 deletions js/src/gnark/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ export async function executeGnarkFnAndGetJson(
) {
const { free, koffi } = await globalGnarkLib!
const res = executeGnarkFn(fn, jsonInput)
const proofJson = Buffer.from(
const proof = Buffer.from(
koffi.decode(res.r0, 'unsigned char', res.r1)
).toString()
free(res.r0) // Avoid memory leak!
return JSON.parse(proofJson)
return JSON.parse(proof)
}

0 comments on commit c9df4f9

Please sign in to comment.