From 32d93e0ee89b3c48c11c079c4e399440ba64c826 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Thu, 7 Sep 2023 08:37:04 +0000 Subject: [PATCH] 2087 - remove dead code from cbind of private kernel circuit --- .../aztec3/circuits/kernel/private/.test.cpp | 13 ------ .../aztec3/circuits/kernel/private/c_bind.cpp | 29 ------------ .../aztec3/circuits/kernel/private/c_bind.h | 9 ---- .../circuits.js/src/kernel/private_kernel.ts | 46 ------------------- 4 files changed, 97 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp index 34e1a1d33f0..0b88021bcc9 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp @@ -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(private_kernel__sim_init, private_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp index 08292c727b8..91b3b8095b9 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp @@ -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 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 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 private_inputs) { diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h index 782b3126e3e..b88b051c326 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h @@ -4,16 +4,7 @@ #include #include -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); diff --git a/yarn-project/circuits.js/src/kernel/private_kernel.ts b/yarn-project/circuits.js/src/kernel/private_kernel.ts index 9a51c75ed5c..640fd98387b 100644 --- a/yarn-project/circuits.js/src/kernel/private_kernel.ts +++ b/yarn-project/circuits.js/src/kernel/private_kernel.ts @@ -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; -}