From f62a97ac6209a59a8e3d1a7889e345ada2c9a875 Mon Sep 17 00:00:00 2001 From: dbanks12 Date: Wed, 29 Mar 2023 14:57:08 +0000 Subject: [PATCH] root rollup cbind working --- .../abis/rollup/root/root_rollup_inputs.hpp | 8 +-- cpp/src/aztec3/circuits/rollup/base/.test.cpp | 6 +- cpp/src/aztec3/circuits/rollup/root/.test.cpp | 66 +++++++++++++++++++ .../aztec3/circuits/rollup/root/c_bind.cpp | 2 +- cpp/src/aztec3/circuits/rollup/root/c_bind.h | 8 +-- 5 files changed, 77 insertions(+), 13 deletions(-) diff --git a/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp b/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp index 2e6082da..76efda0d 100644 --- a/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp +++ b/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp @@ -31,8 +31,8 @@ template void read(uint8_t const*& it, RootRollupInputs& obj using serialize::read; read(it, obj.previous_rollup_data); - read(it, obj.new_historic_private_data_tree_roots); - read(it, obj.new_historic_contract_tree_roots); + read(it, obj.new_historic_private_data_tree_root_sibling_path); + read(it, obj.new_historic_contract_tree_root_sibling_path); }; template void write(std::vector& buf, RootRollupInputs const& obj) @@ -40,8 +40,8 @@ template void write(std::vector& buf, RootRollupInputs std::ostream& operator<<(std::ostream& os, RootRollupInputs const& obj) diff --git a/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/cpp/src/aztec3/circuits/rollup/base/.test.cpp index d2ce4a24..50300a01 100644 --- a/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -137,13 +137,11 @@ class base_rollup_tests : public ::testing::Test { for (size_t i = 0; i < public_inputs.calldata_hash.size(); i++) { ASSERT_EQ(public_inputs.calldata_hash[i], expected_public_inputs.calldata_hash[i]); } - info("after assert..."); - // TODO why do the post-write buffers not match? - // something in aggregation object [de]serialization? info("about to write expected..."); std::vector expected_public_inputs_vec; write(expected_public_inputs_vec, expected_public_inputs); + info("about to assert buffers eq..."); ASSERT_EQ(public_inputs_size, expected_public_inputs_vec.size()); // Just compare the first 10 bytes of the serialized public outputs @@ -162,7 +160,7 @@ class base_rollup_tests : public ::testing::Test { free((void*)vk_buf); // free((void*)proof_data); // SCARY WARNING TODO FIXME why does this free cause issues - // free((void*)public_inputs_buf); + free((void*)public_inputs_buf); info("finished retesting via cbinds..."); } diff --git a/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/cpp/src/aztec3/circuits/rollup/root/.test.cpp index ff4ba52a..6fc079bf 100644 --- a/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -17,6 +17,8 @@ #include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" #include "index.hpp" #include "init.hpp" +#include "c_bind.h" + #include "aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp" #include #include @@ -108,9 +110,71 @@ namespace aztec3::circuits::rollup::root::native_root_rollup_circuit { class root_rollup_tests : public ::testing::Test { protected: + void run_cbind(RootRollupInputs& root_rollup_inputs, + RootRollupPublicInputs& expected_public_inputs, + bool compare_pubins = true) + { + // TODO might be able to get rid of proving key buffer + uint8_t const* pk_buf; + size_t pk_size = root_rollup__init_proving_key(&pk_buf); + info("Proving key size: ", pk_size); + + // TODO might be able to get rid of verification key buffer + uint8_t const* vk_buf; + size_t vk_size = root_rollup__init_verification_key(pk_buf, &vk_buf); + info("Verification key size: ", vk_size); + + std::vector root_rollup_inputs_vec; + write(root_rollup_inputs_vec, root_rollup_inputs); + + // uint8_t const* proof_data; + // size_t proof_data_size; + uint8_t const* public_inputs_buf; + info("creating proof"); + size_t public_inputs_size = root_rollup__sim(root_rollup_inputs_vec.data(), &public_inputs_buf); + // info("Proof size: ", proof_data_size); + info("PublicInputs size: ", public_inputs_size); + + if (compare_pubins) { + RootRollupPublicInputs public_inputs; + info("about to read..."); + uint8_t const* public_inputs_buf_tmp = public_inputs_buf; + read(public_inputs_buf_tmp, public_inputs); + info("about to assert..."); + ASSERT_EQ(public_inputs.calldata_hash.size(), expected_public_inputs.calldata_hash.size()); + for (size_t i = 0; i < public_inputs.calldata_hash.size(); i++) { + ASSERT_EQ(public_inputs.calldata_hash[i], expected_public_inputs.calldata_hash[i]); + } + + info("about to write expected..."); + std::vector expected_public_inputs_vec; + write(expected_public_inputs_vec, expected_public_inputs); + + info("about to assert buffers eq..."); + ASSERT_EQ(public_inputs_size, expected_public_inputs_vec.size()); + // Just compare the first 10 bytes of the serialized public outputs + if (public_inputs_size > 10) { + // for (size_t 0; i < public_inputs_size; i++) { + for (size_t i = 0; i < 10; i++) { + ASSERT_EQ(public_inputs_buf[i], expected_public_inputs_vec[i]); + } + } + } + (void)root_rollup_inputs; // unused + (void)expected_public_inputs; // unused + (void)compare_pubins; // unused + + free((void*)pk_buf); + free((void*)vk_buf); + // free((void*)proof_data); + free((void*)public_inputs_buf); + info("finished retesting via cbinds..."); + } + protected: BaseRollupInputs getEmptyBaseRollupInputs() { + // TODO standardize function naming ConstantRollupData constantRollupData = ConstantRollupData::empty(); std::array, 2 * KERNEL_NEW_NULLIFIERS_LENGTH> low_nullifier_leaf_preimages; @@ -227,6 +291,8 @@ TEST_F(root_rollup_tests, calldata_hash_empty_blocks) } ASSERT_EQ(hash, calldata_hash); + + run_cbind(inputs, outputs, true); } } // namespace aztec3::circuits::rollup::root::native_root_rollup_circuit \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp b/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp index 1ebee283..6bf4fa76 100644 --- a/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp +++ b/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp @@ -72,7 +72,7 @@ WASM_EXPORT size_t root_rollup__sim(uint8_t const* root_rollup_inputs_buf, return public_inputs_vec.size(); } -WASM_EXPORT size_t private_kernel__verify_proof(uint8_t const* vk_buf, uint8_t const* proof, uint32_t length) +WASM_EXPORT size_t root_rollup__verify_proof(uint8_t const* vk_buf, uint8_t const* proof, uint32_t length) { (void)vk_buf; // unused (void)proof; // unused diff --git a/cpp/src/aztec3/circuits/rollup/root/c_bind.h b/cpp/src/aztec3/circuits/rollup/root/c_bind.h index afe24daf..e05f2e53 100644 --- a/cpp/src/aztec3/circuits/rollup/root/c_bind.h +++ b/cpp/src/aztec3/circuits/rollup/root/c_bind.h @@ -5,11 +5,11 @@ extern "C" { -WASM_EXPORT size_t base_rollup__init_proving_key(uint8_t const** pk_buf); -WASM_EXPORT size_t base_rollup__init_verification_key(uint8_t const* pk_buf, uint8_t const** vk_buf); -WASM_EXPORT size_t base_rollup__sim(uint8_t const* root_rollup_inputs_buf, +WASM_EXPORT size_t root_rollup__init_proving_key(uint8_t const** pk_buf); +WASM_EXPORT size_t root_rollup__init_verification_key(uint8_t const* pk_buf, uint8_t const** vk_buf); +WASM_EXPORT size_t root_rollup__sim(uint8_t const* root_rollup_inputs_buf, uint8_t const** root_rollup_public_inputs_buf); -WASM_EXPORT size_t base_rollup__verify_proof(uint8_t const* vk_buf, +WASM_EXPORT size_t root_rollup__verify_proof(uint8_t const* vk_buf, uint8_t const* proof, uint32_t length);