Lazily load the proving key at time of first pour.

This commit is contained in:
Sean Bowe
2016-03-15 14:16:05 -06:00
parent 3af297cc57
commit 8f8c4c6c0c
4 changed files with 32 additions and 12 deletions

View File

@@ -132,6 +132,7 @@ void PourTransaction::init(uint16_t version_num,
const Coin& c_1_new,
const Coin& c_2_new)
{
params.loadProvingKey();
this->version = version_num;
convertIntToBytesVector(v_pub_old, this->publicOldValue);

View File

@@ -127,6 +127,17 @@ ZerocashParams::ZerocashParams(
params_vk_v1 = new zerocash_pour_verification_key<ZerocashParams::zerocash_pp>(keypair->vk);
}
ZerocashParams::ZerocashParams(
const unsigned int tree_depth,
zerocash_pour_verification_key<ZerocashParams::zerocash_pp>* p_vk_1,
std::string proving_key_path
) :
treeDepth(tree_depth), provingKeyPath(proving_key_path)
{
params_vk_v1 = new zerocash_pour_verification_key<ZerocashParams::zerocash_pp>(*p_vk_1);
params_pk_v1 = NULL;
}
ZerocashParams::ZerocashParams(
const unsigned int tree_depth,
zerocash_pour_proving_key<ZerocashParams::zerocash_pp>* p_pk_1,

View File

@@ -35,6 +35,12 @@ public:
zerocash_pour_verification_key<ZerocashParams::zerocash_pp>* p_vk_1
);
ZerocashParams(
const unsigned int tree_depth,
zerocash_pour_verification_key<ZerocashParams::zerocash_pp>* p_vk_1,
std::string proving_key_path
);
const zerocash_pour_proving_key<zerocash_pp>& getProvingKey();
const zerocash_pour_verification_key<zerocash_pp>& getVerificationKey();
int getTreeDepth();
@@ -49,10 +55,21 @@ public:
static void SaveVerificationKeyToFile(const zerocash_pour_verification_key<ZerocashParams::zerocash_pp>* p_vk_1, std::string path);
static zerocash_pour_proving_key<ZerocashParams::zerocash_pp> LoadProvingKeyFromFile(std::string path, const unsigned int tree_depth);
static zerocash_pour_verification_key<ZerocashParams::zerocash_pp> LoadVerificationKeyFromFile(std::string path, const unsigned int tree_depth);
void loadProvingKey()
{
if (params_pk_v1 == NULL) {
std::cout << "loading proving key from path: " << provingKeyPath << std::endl;
params_pk_v1 = new zerocash_pour_proving_key<ZerocashParams::zerocash_pp>(
LoadProvingKeyFromFile(provingKeyPath, treeDepth));
std::cout << "done loading proving key!" << std::endl;
}
}
private:
int treeDepth;
zerocash_pour_proving_key<ZerocashParams::zerocash_pp>* params_pk_v1;
zerocash_pour_verification_key<ZerocashParams::zerocash_pp>* params_vk_v1;
std::string provingKeyPath;
};
} /* namespace libzerocash */