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));
124 std::stringstream ss;
125 msgpack::pack(ss, steps);
126 const std::string s = ss.str();
127 return { s.begin(), s.end() };
131TEST(BBApiInputValidation, MsgpackParseUncompressedAcceptsCleanInput)
134 .
bytecode = { 0xCA, 0xFE }, .witness = { 0xBE, 0xEF }, .vk = {}, .function_name =
"test_fn"
137 auto buf = pack_steps({ step });
140 ASSERT_EQ(result.size(), 1);
141 EXPECT_EQ(result[0].
bytecode, step.bytecode);
142 EXPECT_EQ(result[0].witness, step.witness);
143 EXPECT_EQ(result[0].function_name,
"test_fn");
146TEST(BBApiInputValidation, MsgpackParseUncompressedRejectsTrailingData)
150 auto buf = pack_steps({ step });
156TEST(BBApiInputValidation, MsgpackLoadAcceptsCleanFile)
160 auto buf = pack_steps({ step });
162 auto tmp = std::filesystem::temp_directory_path() /
"bb_test_clean.msgpack";
163 std::ofstream out(tmp, std::ios::binary);
164 out.write(
reinterpret_cast<const char*
>(buf.data()),
static_cast<std::streamsize>(buf.size()));
168 std::filesystem::remove(tmp);
170 ASSERT_EQ(result.size(), 1);
171 EXPECT_EQ(result[0].function_name,
"file_fn");
174TEST(BBApiInputValidation, MsgpackLoadRejectsTrailingData)
178 auto buf = pack_steps({ step });
181 auto tmp = std::filesystem::temp_directory_path() /
"bb_test_tailed.msgpack";
182 std::ofstream out(tmp, std::ios::binary);
183 out.write(
reinterpret_cast<const char*
>(buf.data()),
static_cast<std::streamsize>(buf.size()));
187 std::filesystem::remove(tmp);
194TEST(BBApiInputValidation, AesEncryptRejectsLengthMismatch)
201TEST(BBApiInputValidation, AesEncryptRejectsNonBlockAlignedLength)
208TEST(BBApiInputValidation, AesDecryptRejectsLengthMismatch)
215TEST(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 a single IPA SRS MSM.
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.
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)