Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 0 additions & 1 deletion barretenberg/cpp/src/barretenberg/api/api_client_ivc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ bool ClientIVCAPI::verify([[maybe_unused]] const Flags& flags,
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1163): Set these dynamically
init_bn254_crs(1);
init_grumpkin_crs(1 << CONST_ECCVM_LOG_N);

const auto proof = ClientIVC::Proof::from_file_msgpack(proof_path);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the problematic function on the verifier side

const auto vk = from_buffer<ClientIVC::VerificationKey>(read_file(vk_path));

Expand Down
20 changes: 20 additions & 0 deletions barretenberg/cpp/src/barretenberg/common/serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <iostream>
#include <map>
#include <memory>
#include <msgpack.hpp> // Include the header for msgpack::sbuffer

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still causing some compilation errors

#include <optional>
#include <type_traits>
#include <vector>
Expand Down Expand Up @@ -452,6 +453,24 @@ template <typename T> uint8_t* to_heap_buffer(T const& value)
return ptr;
}

// TODO: make this compile
template <typename T> uint8_t* to_heap_msgpack_buffer(T const& value)
{
using serialize::write;
msgpack::sbuffer buffer;
msgpack::pack(buffer, value);

// Initial serialization of the value. Creates a vector of bytes.
std::vector<char> buf(buffer.data(), buffer.data() + buffer.size());

// Serialize this byte vector, giving us a length prefixed buffer of bytes.
auto heap_buf = to_buffer(buf);

auto* ptr = (uint8_t*)aligned_alloc(64, heap_buf.size()); // NOLINT
std::copy(heap_buf.begin(), heap_buf.end(), ptr);
return ptr;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from Adam, a reading function should contain:

msgpack::sbuffer buffer;
buffer.write(reinterpret_cast<char*>(buffer.data()), buffer.size());
T value;
msgpack::unpack(buffer, value);

template <typename T> std::vector<T> many_from_buffer(std::vector<uint8_t> const& buffer)
{
const size_t num_elements = buffer.size() / sizeof(T);
Expand Down Expand Up @@ -539,6 +558,7 @@ inline void write(auto& buf, const msgpack_concepts::HasMsgPack auto& obj)
(_write_msgpack_field(buf, obj_fields), ...);
});
}

} // namespace serialize
// clang-format off
// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast, cert-dcl58-cpp)
Expand Down
4 changes: 4 additions & 0 deletions barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ WASM_EXPORT void acir_prove_aztec_client(uint8_t const* acir_stack,
uint8_t** out_vk)
{
using Program = acir_format::AcirProgram;
vinfo("In prove aztec client");
info("In prove aztec client");

std::vector<std::vector<uint8_t>> witnesses = from_buffer<std::vector<std::vector<uint8_t>>>(witness_stack);
std::vector<std::vector<uint8_t>> acirs = from_buffer<std::vector<std::vector<uint8_t>>>(acir_stack);
Expand Down Expand Up @@ -276,6 +278,8 @@ WASM_EXPORT void acir_prove_aztec_client(uint8_t const* acir_stack,
vinfo("time to construct, accumulate, prove all circuits: ", diff.count());

start = std::chrono::steady_clock::now();

// this needs to use to_heap_msgpack_buffer
*out_proof = to_heap_buffer(to_buffer(proof));
end = std::chrono::steady_clock::now();
diff = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/ivc-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"testRegex": "./src/rollup_ivc_integration.test\\.(js|mjs|ts)$",
"rootDir": "./src",
"extensionsToTreatAsEsm": [
".ts"
Expand Down
20 changes: 20 additions & 0 deletions yarn-project/ivc-integration/src/prove_wasm.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import { ClientIvcProof } from '@aztec/stdlib/proofs';

import { ungzip } from 'pako';

function base64ToUint8Array(base64: string): Uint8Array {
return Uint8Array.from(atob(base64), c => c.charCodeAt(0));
}

export async function proveClientIVC(
bytecodes: string[],
witnessStack: Uint8Array[],
threads?: number,
): Promise<ClientIvcProof> {
const { AztecClientBackend } = await import('@aztec/bb.js');
const backend = new AztecClientBackend(
bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr)),
{ threads },
);
try {
const [proof] = await backend.prove(witnessStack.map((arr: Uint8Array) => ungzip(arr)));
return new ClientIvcProof(Buffer.from(proof));
} finally {
await backend.destroy();
}
}

export async function proveThenVerifyAztecClient(
bytecodes: string[],
witnessStack: Uint8Array[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
witnessGenMockRollupRootCircuit,
} from './index.js';
import { proveAvm, proveClientIVC, proveRollupHonk, proveTube } from './prove_native.js';
import { proveClientIVC as proveClientIVCWASM } from './prove_wasm.js';
import type { KernelPublicInputs } from './types/index.js';

/* eslint-disable camelcase */
Expand Down Expand Up @@ -58,7 +59,7 @@ describe('Rollup IVC Integration', () => {

const [bytecodes, witnessStack, tailPublicInputs] = await generate3FunctionTestingIVCStack();
clientIVCPublicInputs = tailPublicInputs;
const proof = await proveClientIVC(bbBinaryPath, clientIVCWorkingDirectory, witnessStack, bytecodes, logger);
const proof = await proveClientIVCWASM(bytecodes, witnessStack, 16);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to run LOG_LEVEL=debug yarn test to test this rigged thing given the modifications in package.json

await writeClientIVCProofToOutputDirectory(proof, clientIVCWorkingDirectory);
const verifyResult = await verifyClientIvcProof(
bbBinaryPath,
Expand Down Expand Up @@ -93,7 +94,7 @@ describe('Rollup IVC Integration', () => {
workingDirectory = await fs.mkdtemp(path.join(os.tmpdir(), 'bb-rollup-ivc-integration-'));
});

it('Should be able to generate a proof of a 3 transaction rollup', async () => {
it.only('Should be able to generate a proof of a 3 transaction rollup', async () => {
const privateBaseRollupWitnessResult = await witnessGenMockRollupBasePrivateCircuit({
tube_data: {
public_inputs: clientIVCPublicInputs,
Expand Down