Skip to content

Commit

Permalink
2087 - remove dead code from cbind of private kernel circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmon committed Sep 7, 2023
1 parent f0aa3ca commit 32d93e0
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 97 deletions.
13 changes: 0 additions & 13 deletions circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,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
29 changes: 0 additions & 29 deletions circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,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);
46 changes: 0 additions & 46 deletions yarn-project/circuits.js/src/kernel/private_kernel.ts
Original file line number Diff line number Diff line change
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;
}

0 comments on commit 32d93e0

Please sign in to comment.