Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(crypto_blake3s)
barretenberg_module(crypto_blake3s common)
3 changes: 3 additions & 0 deletions barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <iostream>
#include <type_traits>

#include "barretenberg/common/assert.hpp"
#include "blake3s.hpp"

namespace blake3 {
Expand Down Expand Up @@ -240,6 +241,8 @@ constexpr void blake3_hasher_finalize(const blake3_hasher* self, uint8_t* out)

std::vector<uint8_t> blake3s(std::vector<uint8_t> const& input)
{
ASSERT(input.size() <= 1024, "Barretenberg does not support blake3s with input lengths greater than 1024 bytes.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test here as well that triggers this ASSERT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was actually not building. Since this is outside stdlib, I decided to change it to an error throw and catch it in the test.


blake3_hasher hasher;
blake3_hasher_init(&hasher);
blake3_hasher_update(&hasher, static_cast<const uint8_t*>(input.data()), input.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,9 @@ TEST(MiscBlake3s, TestVectors)
static_assert(result_constexpr == v.output);
});
}

TEST(MiscBlake3s, TooLargeInputTest)
{
std::vector<uint8_t> input(1025, 0);
EXPECT_DEATH(blake3::blake3s(input), "Assertion failed");
}
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,6 @@ std::vector<uint8_t> blake3s(std::vector<uint8_t> const& input,
// Initialize the hasher.
blake3_hasher hasher;
blake3_hasher_init(&hasher);

switch (mode_id) {
case HASH_MODE:
blake3_hasher_init(&hasher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ template <typename Builder> void create_blake3_constraints(Builder& builder, con

// XXX: The implementation requires us to truncate the element to the nearest byte and not bit
auto num_bytes = round_to_nearest_byte(num_bits);

ASSERT(num_bytes <= 1024, "barretenberg does not support blake3 inputs with more than 1024 bytes");
field_ct element = to_field_ct(witness_index, builder);
byte_array_ct element_bytes(element, num_bytes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ using namespace blake3_internal;

template <typename Builder> byte_array<Builder> blake3s(const byte_array<Builder>& input)
{
ASSERT(input.size() <= 1024, "Barretenberg does not support blake3s with input lengths greater than 1024 bytes.");
Copy link
Contributor

Choose a reason for hiding this comment

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

nice! Could you please also add tests that trigger this ASSERT for completeness? You probably need to use EXPECT_DEATH for such a test, see this test for example.


if constexpr (HasPlookup<Builder>) {
return blake3s_plookup::blake3s<Builder>(input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,14 @@ TEST(stdlib_blake3s, test_double_block_plookup)
bool proof_result = CircuitChecker::check(builder);
EXPECT_EQ(proof_result, true);
}

TEST(stdlib_blake3s, test_too_large_input_plookup)
{
auto builder = UltraBuilder();

std::vector<uint8_t> input_v(1025, 0);

byte_array_plookup input_arr(&builder, input_v);
EXPECT_DEATH(stdlib::blake3s(input_arr),
"Barretenberg does not support blake3s with input lengths greater than 1024 bytes.");
}
5 changes: 3 additions & 2 deletions barretenberg/noir/bb_proof_verification/src/lib.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Constants for UltraHonk recursive verifier inputs
pub global PROOF_TYPE_HONK: u32 = 1; // identifier for UltraHonk verfier
pub global RECURSIVE_PROOF_LENGTH: u32 = 456;
pub global RECURSIVE_PROOF_LENGTH: u32 = 456;
pub global HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 112;

pub type UltraHonkProof = [Field; RECURSIVE_PROOF_LENGTH];
Expand All @@ -10,7 +10,8 @@ pub type UltraHonkVerificationKey = [Field; HONK_VERIFICATION_KEY_LENGTH_IN_FIEL
pub global PROOF_TYPE_ROLLUP_HONK: u32 = 5; // identifier for rollup-UltraHonk verfier
pub global IPA_CLAIM_SIZE: u32 = 10;
pub global IPA_PROOF_LENGTH: u32 = 69;
pub global RECURSIVE_ROLLUP_HONK_PROOF_LENGTH: u32 = RECURSIVE_PROOF_LENGTH + IPA_CLAIM_SIZE + IPA_PROOF_LENGTH;
pub global RECURSIVE_ROLLUP_HONK_PROOF_LENGTH: u32 =
RECURSIVE_PROOF_LENGTH + IPA_CLAIM_SIZE + IPA_PROOF_LENGTH;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the formatter just made these changes

pub global ROLLUP_HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 113;

pub type RollupHonkProof = [Field; RECURSIVE_ROLLUP_HONK_PROOF_LENGTH];
Expand Down
Loading