Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added groth16_prover_zkey_file function #8

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 23 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,20 @@ groth16_prover(const void *zkey_buffer, unsigned long zkey_size,

return PROVER_OK;
}

int groth16_prover_zkey_file(const char *zkey_file_path,
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) {

std::string zkey_filename(zkey_file_path);

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 char *zkey_file_path,
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