10#include "msgpack/v3/sbuffer_decl.hpp"
11#include <gtest/gtest.h>
34template <
typename T>
class BBApiMsgpack :
public ::testing::Test {};
43 EXPECT_EQ(actual_command, expected_command);
45 typename TypeParam::Response response{};
47 EXPECT_EQ(actual_response, expected_response);
54TEST(BBApiInputValidation, NonCanonicalPublicInputRejected)
62 EXPECT_THROW(bbapi::concatenate_proof<Flavor>(bad_public_inputs, proof), std::runtime_error);
65TEST(BBApiInputValidation, NonCanonicalProofElementRejected)
73 EXPECT_THROW(bbapi::concatenate_proof<Flavor>(public_inputs, bad_proof), std::runtime_error);
76TEST(BBApiInputValidation, CanonicalValuesAccepted)
84 EXPECT_NO_THROW(bbapi::concatenate_proof<Flavor>(public_inputs, proof));
87TEST(BBApiInputValidation, TrailingBytesInBinaryInputRejected)
90 std::vector<uint8_t> buf(32 + 1, 0);
91 EXPECT_THROW(many_from_buffer_exact<uint256_t>(buf,
"test input"), std::runtime_error);
94TEST(BBApiInputValidation, ExactBinaryInputAccepted)
97 std::vector<uint8_t> buf(64, 0);
98 EXPECT_NO_THROW(many_from_buffer_exact<uint256_t>(buf,
"test input"));
99 auto result = many_from_buffer_exact<uint256_t>(buf,
"test input");
100 EXPECT_EQ(result.size(), 2UL);
103TEST(BBApiInputValidation, VkWithTrailingBytesRejectedOnProveSide)
106 const size_t expected_size = VK::calc_num_data_types() *
sizeof(
bb::fr);
108 std::vector<uint8_t> bad_vk(expected_size + 1, 0);
109 EXPECT_THROW(bbapi::validate_vk_size<VK>(bad_vk), std::runtime_error);
112TEST(BBApiInputValidation, VkWithCorrectSizeAccepted)
115 const size_t expected_size = VK::calc_num_data_types() *
sizeof(
bb::fr);
116 std::vector<uint8_t> good_vk(expected_size, 0);
117 EXPECT_NO_THROW(bbapi::validate_vk_size<VK>(good_vk));
120TEST(BBApiInputValidation, ChonkVerifyWrongVkSizeReturnsInvalid)
123 EXPECT_FALSE(response.valid);
126TEST(BBApiInputValidation, ChonkVerifyFromFieldsWrongVkSizeReturnsInvalid)
129 EXPECT_FALSE(response.valid);
132TEST(BBApiInputValidation, ChonkBatchVerifyWrongVkSizeReturnsInvalid)
135 EXPECT_FALSE(response.valid);
142 std::stringstream ss;
143 msgpack::pack(ss, steps);
144 const std::string s = ss.str();
145 return { s.begin(), s.end() };
149TEST(BBApiInputValidation, MsgpackParseUncompressedAcceptsCleanInput)
152 .
bytecode = { 0xCA, 0xFE }, .witness = { 0xBE, 0xEF }, .vk = {}, .function_name =
"test_fn"
155 auto buf = pack_steps({ step });
158 ASSERT_EQ(result.size(), 1);
159 EXPECT_EQ(result[0].
bytecode, step.bytecode);
160 EXPECT_EQ(result[0].witness, step.witness);
161 EXPECT_EQ(result[0].function_name,
"test_fn");
164TEST(BBApiInputValidation, MsgpackParseUncompressedRejectsTrailingData)
168 auto buf = pack_steps({ step });
174TEST(BBApiInputValidation, MsgpackLoadAcceptsCleanFile)
178 auto buf = pack_steps({ step });
180 auto tmp = std::filesystem::temp_directory_path() /
"bb_test_clean.msgpack";
181 std::ofstream out(tmp, std::ios::binary);
182 out.write(
reinterpret_cast<const char*
>(buf.data()),
static_cast<std::streamsize>(buf.size()));
186 std::filesystem::remove(tmp);
188 ASSERT_EQ(result.size(), 1);
189 EXPECT_EQ(result[0].function_name,
"file_fn");
192TEST(BBApiInputValidation, MsgpackLoadRejectsTrailingData)
196 auto buf = pack_steps({ step });
199 auto tmp = std::filesystem::temp_directory_path() /
"bb_test_tailed.msgpack";
200 std::ofstream out(tmp, std::ios::binary);
201 out.write(
reinterpret_cast<const char*
>(buf.data()),
static_cast<std::streamsize>(buf.size()));
205 std::filesystem::remove(tmp);
212TEST(BBApiInputValidation, AesEncryptRejectsLengthMismatch)
219TEST(BBApiInputValidation, AesEncryptRejectsNonBlockAlignedLength)
226TEST(BBApiInputValidation, AesDecryptRejectsLengthMismatch)
233TEST(BBApiInputValidation, AesDecryptRejectsNonBlockAlignedLength)
#define EXPECT_THROW_OR_ABORT(statement, matcher)
std::shared_ptr< Napi::ThreadSafeFunction > bytecode
TYPED_TEST_SUITE(BBApiMsgpack, Commands)
TEST(BBApiInputValidation, NonCanonicalPublicInputRejected)
TYPED_TEST(BBApiMsgpack, DefaultConstructorRoundtrip)
::testing::Types< bbapi::CircuitProve, bbapi::CircuitComputeVk, bbapi::CircuitStats, bbapi::CircuitVerify, bbapi::VkAsFields, bbapi::CircuitWriteSolidityVerifier, bbapi::ChonkStart, bbapi::ChonkLoad, bbapi::ChonkAccumulate, bbapi::ChonkProve, bbapi::ChonkComputeVk, bbapi::ChonkCheckPrecomputedVk, bbapi::ChonkBatchVerify > Commands
Cryptographic primitives command definitions for the Barretenberg RPC API.
Shared type definitions for the Barretenberg RPC API.
NativeVerificationKey_< PrecomputedEntities< Commitment >, Codec, HashFunction, CommitmentKey > VerificationKey
The verification key stores commitments to the precomputed (non-witness) polynomials used by the veri...
Entry point for Barretenberg command-line interface.
field< Bn254FrParams > fr
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string msgpack_schema_to_string(const auto &obj)
Print's an object's derived msgpack schema as a string.
This is the msgpack encoding of the objects returned by the following typescript: const stepToStruct ...
std::vector< uint8_t > bytecode
static std::vector< PrivateExecutionStepRaw > parse_uncompressed(const std::vector< uint8_t > &buf)
static std::vector< PrivateExecutionStepRaw > load(const std::filesystem::path &input_path)
std::vector< uint8_t > ciphertext
std::vector< uint8_t > plaintext
Accumulate the previously loaded circuit into the IVC proof.
Batch-verify multiple Chonk proofs with batched IPA SRS MSMs.
std::vector< ChonkProof > proofs
Verify that a precomputed verification key matches the circuit.
Compute MegaHonk verification key for a circuit to be accumulated in Chonk.
Load a circuit into the Chonk instance for accumulation.
Generate a proof for all accumulated circuits.
Initialize a new Chonk instance for incremental proof accumulation.
Verify a Chonk proof passed as a flat field-element array (with public inputs prepended).
std::vector< bb::fr > proof
Flat proof field elements with public inputs prepended.
Verify a Chonk proof with its verification key.
ChonkProof proof
The Chonk proof to verify.
Represents a request to generate a proof. Currently, UltraHonk is the only proving system supported b...
Consolidated command for retrieving circuit information. Combines gate count, circuit size,...
Verify a proof against a verification key and public inputs.
Command to generate Solidity verifier contract.
Convert a verification key to field elements representation. WORKTODO(bbapi): this should become most...
static constexpr uint256_t modulus
std::pair< T, T > msgpack_roundtrip(const T &object)