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

chore(circuits): - remove dead code from cbind of private kernel circuit #2088

Merged
merged 1 commit into from
Sep 7, 2023
Merged
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
14 changes: 0 additions & 14 deletions circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "c_bind.h"
#include "index.hpp"
#include "init.hpp"
#include "testing_harness.hpp"
Expand Down Expand Up @@ -94,19 +93,6 @@ TEST_F(private_kernel_tests, circuit_cbinds)
DummyBuilder builder = DummyBuilder("private_kernel_tests__circuit_create_proof_cbinds");
auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs);

// ***************************************************************************
// Now run the simulate/prove cbinds to make sure their outputs match
// ***************************************************************************
// TODO(david): might be able to get rid of proving key buffer
uint8_t const* pk_buf = nullptr;
private_kernel__init_proving_key(&pk_buf);
// info("Proving key size: ", pk_size);

// TODO(david): might be able to get rid of verification key buffer
// uint8_t const* vk_buf;
// size_t vk_size = private_kernel__init_verification_key(pk_buf, &vk_buf);
// info("Verification key size: ", vk_size);

auto exp_result = builder.result_or_error(public_inputs);
// Does not compile. See https://github.com/AztecProtocol/aztec-packages/issues/1998
auto res = call_msgpack_cbind<decltype(exp_result)>(private_kernel__sim_init, private_inputs);
Expand Down
31 changes: 0 additions & 31 deletions circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ namespace {
using Builder = UltraCircuitBuilder;
using NT = aztec3::utils::types::NativeTypes;
using DummyCircuitBuilder = aztec3::utils::DummyCircuitBuilder;
using aztec3::circuits::abis::TxRequest;
using aztec3::circuits::abis::private_kernel::PrivateCallData;
using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInit;
using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner;
using aztec3::circuits::abis::private_kernel::PrivateKernelInputsOrdering;
Expand All @@ -30,35 +28,6 @@ using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel;

// WASM Cbinds

// TODO(dbanks12): might be able to get rid of proving key buffer
WASM_EXPORT size_t private_kernel__init_proving_key(uint8_t const** pk_buf)
{
std::vector<uint8_t> pk_vec(42, 0);

auto* raw_buf = (uint8_t*)malloc(pk_vec.size());
memcpy(raw_buf, (void*)pk_vec.data(), pk_vec.size());
*pk_buf = raw_buf;

return pk_vec.size();
}

WASM_EXPORT size_t private_kernel__init_verification_key(uint8_t const* pk_buf, uint8_t const** vk_buf)
{
(void)pk_buf;

// TODO(dbanks12) actual verification key?
// NT:VKData vk_data = { 0 };

std::vector<uint8_t> vk_vec(42, 0);
// write(vk_vec, vk_data);

auto* raw_buf = (uint8_t*)malloc(vk_vec.size());
memcpy(raw_buf, (void*)vk_vec.data(), vk_vec.size());
*vk_buf = raw_buf;

return vk_vec.size();
}

CBIND(private_kernel__dummy_previous_kernel, []() { return dummy_previous_kernel(); });

CBIND(private_kernel__sim_init, [](PrivateKernelInputsInit<NT> private_inputs) {
Expand Down
9 changes: 0 additions & 9 deletions circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@
#include <cstddef>
#include <cstdint>

WASM_EXPORT size_t private_kernel__init_proving_key(uint8_t const** pk_buf);
WASM_EXPORT size_t private_kernel__init_verification_key(uint8_t const* pk_buf, uint8_t const** vk_buf);
CBIND_DECL(private_kernel__dummy_previous_kernel);
CBIND_DECL(private_kernel__sim_init);
CBIND_DECL(private_kernel__sim_inner);
CBIND_DECL(private_kernel__sim_ordering);
WASM_EXPORT size_t private_kernel__prove(uint8_t const* tx_request_buf,
uint8_t const* previous_kernel_buf,
uint8_t const* private_call_buf,
uint8_t const* pk_buf,
bool first,
uint8_t const** proof_data_buf);
WASM_EXPORT size_t private_kernel__verify_proof(uint8_t const* vk_buf, uint8_t const* proof, uint32_t length);
50 changes: 2 additions & 48 deletions yarn-project/circuits.js/src/kernel/private_kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { BufferReader } from '@aztec/foundation/serialize';

import { Buffer } from 'buffer';

import { FUNCTION_TREE_HEIGHT, Fr, PreviousKernelData, PrivateCallData, TxRequest } from '../index.js';
import { serializeBufferArrayToVector, uint8ArrayToNum } from '../utils/serialize.js';
import { FUNCTION_TREE_HEIGHT, Fr } from '../index.js';
import { serializeBufferArrayToVector } from '../utils/serialize.js';
import { CircuitsWasm } from '../wasm/index.js';

export { privateKernelSimOrdering, privateKernelSimInit, privateKernelSimInner } from '../cbind/circuits.gen.js';
Expand Down Expand Up @@ -40,49 +40,3 @@ export function computeFunctionTree(wasm: CircuitsWasm, leaves: Fr[]): Fr[] {

return output;
}

/**
* Computes proof of the private kernel.
* @param wasm - The circuits wasm instance.
* @param txRequest - The signed transaction request.
* @param previousKernel - The previous kernel data (dummy if this is the first kernel in the chain).
* @param privateCallData - The private call data.
* @param firstIteration - Whether this is the first iteration of the private kernel.
* @returns The proof of the private kernel.
*/
export function privateKernelProve(
wasm: CircuitsWasm,
txRequest: TxRequest,
previousKernel: PreviousKernelData,
privateCallData: PrivateCallData,
firstIteration: boolean,
): Buffer {
wasm.call('pedersen__init');
const txRequestBuffer = txRequest.toBuffer();
const previousKernelBuffer = previousKernel.toBuffer();
const privateCallDataBuffer = privateCallData.toBuffer();
const previousKernelBufferOffset = txRequestBuffer.length;
const privateCallDataOffset = previousKernelBufferOffset + previousKernelBuffer.length;
// This is an unused pointer argument at the moment.
const provingKeyOffset = privateCallDataOffset + privateCallDataBuffer.length;
wasm.writeMemory(0, txRequestBuffer);
wasm.writeMemory(previousKernelBufferOffset, previousKernelBuffer);
wasm.writeMemory(privateCallDataOffset, privateCallDataBuffer);

const proofOutputAddressPtr = wasm.call('bbmalloc', 4);
const proofSize = wasm.call(
'private_kernel__prove',
0,
previousKernelBufferOffset,
privateCallDataOffset,
provingKeyOffset,
firstIteration,
proofOutputAddressPtr,
);
// for whenever we actually use this method, we need to do proper error handling in C++ via bberg.
const address = uint8ArrayToNum(wasm.getMemorySlice(proofOutputAddressPtr, proofOutputAddressPtr + 4));
const proof = Buffer.from(wasm.getMemorySlice(address, address + proofSize));
wasm.call('bbfree', proofOutputAddressPtr);
wasm.call('bbfree', address);
return proof;
}