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
Expand Up @@ -8,7 +8,6 @@
#include "barretenberg/common/assert.hpp"
#include "barretenberg/stdlib/hash/blake2s/blake2s.hpp"
#include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp"
#include "round.hpp"

namespace acir_format {

Expand All @@ -24,16 +23,12 @@ template <typename Builder> void create_blake2s_constraints(Builder& builder, co

for (const auto& witness_index_num_bits : constraint.inputs) {
auto witness_index = witness_index_num_bits.blackbox_input;
auto num_bits = witness_index_num_bits.num_bits;

// 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);
BB_ASSERT_LTE(num_bytes, 32U, "Input num_bytes exceeds 32 per element in blake2s");

field_ct element = to_field_ct(witness_index, builder);

// byte_array_ct(field, num_bytes) constructor adds range constraints for each byte
byte_array_ct element_bytes(element, num_bytes);
// byte_array_ct(field, num_bytes) constructor adds range constraints for each byte. Note that num_bytes =
// ceil(witness_index_num_bits.num_bits/8). Here, num_bits is set to 8 when constructing the vector of inputs in
// the Blake2s constraint. Hence, we set num_bytes = 1.
byte_array_ct element_bytes(element, 1);

// Safe write: both arr and element_bytes are constrained
arr.write(element_bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "barretenberg/common/assert.hpp"
#include "barretenberg/stdlib/hash/blake3s/blake3s.hpp"
#include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp"
#include "round.hpp"

namespace acir_format {

Expand All @@ -22,15 +21,12 @@ template <typename Builder> void create_blake3_constraints(Builder& builder, con

for (const auto& witness_index_num_bits : constraint.inputs) {
auto witness_index = witness_index_num_bits.blackbox_input;
auto num_bits = witness_index_num_bits.num_bits;

// 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);
BB_ASSERT_LTE(num_bytes, 32U, "Input num_bytes exceeds 32 per element in blake3s");
field_ct element = to_field_ct(witness_index, builder);

// byte_array_ct(field, num_bytes) constructor adds range constraints for each byte
byte_array_ct element_bytes(element, num_bytes);
// byte_array_ct(field, num_bytes) constructor adds range constraints for each byte. Note that num_bytes =
// ceil(witness_index_num_bits.num_bits/8). Here, num_bits is set to 8 when constructing the vector of inputs in
// the Blake3 constraint. Hence, we set num_bytes = 1.
byte_array_ct element_bytes(element, 1);

// Safe write: both arr and element_bytes are constrained
arr.write(element_bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ template <typename Builder> inline constexpr size_t ECDSA_SECP256K1 = 41994 + ZE
template <typename Builder>
inline constexpr size_t ECDSA_SECP256R1 = 72209 + ZERO_GATE + (IsMegaBuilder<Builder> ? 2 : 0);

template <typename Builder> inline constexpr size_t BLAKE2S = 2959 + ZERO_GATE + MEGA_OFFSET<Builder>;
template <typename Builder> inline constexpr size_t BLAKE3 = 2165 + ZERO_GATE + MEGA_OFFSET<Builder>;
template <typename Builder> inline constexpr size_t BLAKE2S = 2952 + ZERO_GATE + MEGA_OFFSET<Builder>;
template <typename Builder> inline constexpr size_t BLAKE3 = 2158 + ZERO_GATE + MEGA_OFFSET<Builder>;
template <typename Builder> inline constexpr size_t KECCAK_PERMUTATION = 17387 + ZERO_GATE + MEGA_OFFSET<Builder>;
template <typename Builder> inline constexpr size_t POSEIDON2_PERMUTATION = 73 + ZERO_GATE + MEGA_OFFSET<Builder>;
template <typename Builder> inline constexpr size_t MULTI_SCALAR_MUL = 3550 + ZERO_GATE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "keccak_constraint.hpp"
#include "barretenberg/stdlib/hash/keccak/keccak.hpp"
#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp"
#include "round.hpp"

namespace acir_format {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ TYPED_TEST(OpcodeGateCountTests, Blake2s)

blake2s_constraint.inputs.push_back(Blake2sInput{
.blackbox_input = WitnessOrConstant<bb::fr>::from_index(0),
.num_bits = 32,
.num_bits = 8,
});

for (size_t i = 0; i < 32; ++i) {
Expand Down Expand Up @@ -466,7 +466,7 @@ TYPED_TEST(OpcodeGateCountTests, Blake3)

blake3_constraint.inputs.push_back(Blake3Input{
.blackbox_input = WitnessOrConstant<bb::fr>::from_index(0),
.num_bits = 32,
.num_bits = 8,
});

for (size_t i = 0; i < 32; ++i) {
Expand Down
29 changes: 0 additions & 29 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/round.cpp

This file was deleted.

18 changes: 0 additions & 18 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/round.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "sha256_constraint.hpp"
#include "barretenberg/serialize/msgpack_impl.hpp"
#include "barretenberg/stdlib/hash/sha256/sha256.hpp"
#include "round.hpp"

namespace acir_format {

Expand Down
Loading