Skip to content

Commit

Permalink
working serialized proving key size and circuit change test for ultra (
Browse files Browse the repository at this point in the history
  • Loading branch information
vezenovm authored Apr 3, 2023
1 parent 0ab3760 commit 6119f1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ WASM_EXPORT void join_split__release_key()

WASM_EXPORT uint32_t join_split__get_new_proving_key_data(uint8_t** output)
{
// Computing the size of the serialized key is non trivial. We know it's ~331mb.
// Allocate a buffer large enough to hold it, and abort if we overflow.
// This is to keep memory usage down.
// Computing the size of the serialized key is non trivial. We know it's ~331mb.
// Allocate a buffer large enough to hold it, and abort if we overflow.
// This is to keep memory usage down.
#ifdef USE_TURBO
size_t total_buf_len = 350 * 1024 * 1024;
auto raw_buf = (uint8_t*)malloc(total_buf_len);
auto raw_buf_end = raw_buf;
Expand All @@ -56,6 +57,15 @@ WASM_EXPORT uint32_t join_split__get_new_proving_key_data(uint8_t** output)
std::abort();
}
return len;
#else
auto proving_key = get_proving_key();
auto buffer = to_buffer(*proving_key);
auto raw_buf = (uint8_t*)malloc(buffer.size());
memcpy(raw_buf, (void*)buffer.data(), buffer.size());
*output = raw_buf;

return static_cast<uint32_t>(buffer.size());
#endif
}

WASM_EXPORT void join_split__init_verification_key(void* pippenger, uint8_t const* g2x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,17 @@ TEST_F(join_split_tests, test_0_input_notes_and_detect_circuit_change)

EXPECT_TRUE(result.valid);

// The below part detects any changes in the join-split circuit
// The below part detects any changes in the join-split circuit
#ifdef USE_TURBO
constexpr uint32_t CIRCUIT_GATE_COUNT = 64000;
constexpr uint32_t GATES_NEXT_POWER_OF_TWO = 65536;
const uint256_t VK_HASH("bb2062d006d31d3234766277711eb28577d5f6082d0f484b87e8235628f8e864");
#else
constexpr uint32_t CIRCUIT_GATE_COUNT = 522850;
constexpr uint32_t GATES_NEXT_POWER_OF_TWO = 524288;
const uint256_t VK_HASH("012959f86e485f3a8f0b06c900082fca1c34b535cdf4f1088f03154ea655b401");

#endif
auto number_of_gates_js = result.number_of_gates;
auto vk_hash_js = get_verification_key()->sha256_hash();

Expand Down Expand Up @@ -2613,11 +2619,15 @@ TEST_F(join_split_tests, test_send_two_virtual_notes_full_proof)
// Miscellaneous
// *************************************************************************************************************

TEST_F(join_split_tests, serialzed_proving_key_size)
TEST_F(join_split_tests, serialized_proving_key_size)
{
uint8_t* ptr;
auto len = join_split__get_new_proving_key_data(&ptr);
#ifdef USE_TURBO
EXPECT_LE(len, 2 * 170 * 1024 * 1024);
#else
EXPECT_LE(len, 2315258552);
#endif
}

} // namespace join_split_example::proofs::join_split

0 comments on commit 6119f1e

Please sign in to comment.