Skip to content

Commit

Permalink
Added groth16_prover_zkey_file function. Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
OBrezhniev committed Jan 18, 2024
1 parent b1c2e91 commit 9c7555d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/binfile_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ BinFile::BinFile(std::string fileName, std::string _type, uint32_t maxVersion) {

BinFile::BinFile(const void *fileData, size_t fileSize, std::string _type, uint32_t maxVersion) {

is_fd = false;
fd = -1;

size = fileSize;
addr = malloc(size);
memcpy(addr, fileData, size);
Expand Down
2 changes: 0 additions & 2 deletions src/binfile_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ namespace BinFileUtils {
BinFile(std::string fileName, std::string _type, uint32_t maxVersion);
~BinFile();

void *getSetcionData(u_int32_t sectionId, u_int32_t sectionPos = 0);

void startReadSection(u_int32_t sectionId, u_int32_t setionPos = 0);
void endReadSection(bool check = true);

Expand Down
28 changes: 21 additions & 7 deletions src/prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "wtns_utils.hpp"
#include "groth16.hpp"
#include "binfile_utils.hpp"
#include "fileloader.hpp"

using json = nlohmann::json;

Expand Down Expand Up @@ -65,13 +66,11 @@ unsigned long CalcPublicBufferSize(const void *zkey_buffer, unsigned long zkey_s
return 0;
}

int
groth16_prover(const void *zkey_buffer, unsigned long zkey_size,
const void *wtns_buffer, unsigned long wtns_size,
char *proof_buffer, unsigned long *proof_size,
char *public_buffer, unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize)
{
int groth16_prover(const void *zkey_buffer, unsigned long zkey_size,
const void *wtns_buffer, unsigned long wtns_size,
char *proof_buffer, unsigned long *proof_size,
char *public_buffer, unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize) {
try {
BinFileUtils::BinFile zkey(zkey_buffer, zkey_size, "zkey", 1);
auto zkeyHeader = ZKeyUtils::loadHeader(&zkey);
Expand Down Expand Up @@ -160,3 +159,18 @@ groth16_prover(const void *zkey_buffer, unsigned long zkey_size,

return PROVER_OK;
}

int groth16_prover_zkey_file(const std::string& zkey_filename,
const void *wtns_buffer, unsigned long wtns_size,
char *proof_buffer, unsigned long *proof_size,
char *public_buffer, unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize) {

BinFileUtils::FileLoader fileLoader(zkey_filename);

return groth16_prover(fileLoader.dataBuffer(), fileLoader.dataSize(),
wtns_buffer, wtns_size,
proof_buffer, proof_size,
public_buffer, public_size,
error_msg, error_msg_maxsize);
}
24 changes: 18 additions & 6 deletions src/prover.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@ unsigned long CalcPublicBufferSize(const void *zkey_buffer, unsigned long zkey_s
* PPOVER_ERROR - in case of an error
* PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error, also updates proof_size and public_size with actual proof and public sizess
*/
int
groth16_prover(const void *zkey_buffer, unsigned long zkey_size,
const void *wtns_buffer, unsigned long wtns_size,
char *proof_buffer, unsigned long *proof_size,
char *public_buffer, unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize);
int groth16_prover(const void *zkey_buffer, unsigned long zkey_size,
const void *wtns_buffer, unsigned long wtns_size,
char *proof_buffer, unsigned long *proof_size,
char *public_buffer, unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize);

/**
* groth16_prover
* @return error code:
* PROVER_OK - in case of success
* PPOVER_ERROR - in case of an error
* PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error, also updates proof_size and public_size with actual proof and public sizess
*/
int groth16_prover_zkey_file(const std::string &zkey_filename,
const void *wtns_buffer, unsigned long wtns_size,
char *proof_buffer, unsigned long *proof_size,
char *public_buffer, unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 9c7555d

Please sign in to comment.