Skip to content

Commit

Permalink
root rollup cbind working
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanks12 committed Mar 29, 2023
1 parent eb24af7 commit f62a97a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ template <typename NCT> void read(uint8_t const*& it, RootRollupInputs<NCT>& 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 <typename NCT> void write(std::vector<uint8_t>& buf, RootRollupInputs<NCT> const& obj)
{
using serialize::write;

write(buf, obj.previous_rollup_data);
write(buf, obj.new_historic_private_data_tree_roots);
write(buf, obj.new_historic_contract_tree_roots);
write(buf, obj.new_historic_private_data_tree_root_sibling_path);
write(buf, obj.new_historic_contract_tree_root_sibling_path);
};

template <typename NCT> std::ostream& operator<<(std::ostream& os, RootRollupInputs<NCT> const& obj)
Expand Down
6 changes: 2 additions & 4 deletions cpp/src/aztec3/circuits/rollup/base/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> 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
Expand All @@ -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...");
}

Expand Down
66 changes: 66 additions & 0 deletions cpp/src/aztec3/circuits/rollup/root/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <aztec3/circuits/apps/test_apps/escrow/deposit.hpp>
#include <aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.hpp>
Expand Down Expand Up @@ -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<uint8_t> 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<uint8_t> 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<NullifierLeafPreimage<NT>, 2 * KERNEL_NEW_NULLIFIERS_LENGTH> low_nullifier_leaf_preimages;
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion cpp/src/aztec3/circuits/rollup/root/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/aztec3/circuits/rollup/root/c_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit f62a97a

Please sign in to comment.