diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp index bc0bcef35c84..82d8457848d0 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp @@ -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 { @@ -24,16 +23,12 @@ template 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); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake3_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake3_constraint.cpp index b36189451ac3..14b0b0f3c321 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake3_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake3_constraint.cpp @@ -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 { @@ -22,15 +21,12 @@ template 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); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/gate_count_constants.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/gate_count_constants.hpp index d6f71781772c..e625cf109237 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/gate_count_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/gate_count_constants.hpp @@ -38,8 +38,8 @@ template inline constexpr size_t ECDSA_SECP256K1 = 41994 + ZE template inline constexpr size_t ECDSA_SECP256R1 = 72209 + ZERO_GATE + (IsMegaBuilder ? 2 : 0); -template inline constexpr size_t BLAKE2S = 2959 + ZERO_GATE + MEGA_OFFSET; -template inline constexpr size_t BLAKE3 = 2165 + ZERO_GATE + MEGA_OFFSET; +template inline constexpr size_t BLAKE2S = 2952 + ZERO_GATE + MEGA_OFFSET; +template inline constexpr size_t BLAKE3 = 2158 + ZERO_GATE + MEGA_OFFSET; template inline constexpr size_t KECCAK_PERMUTATION = 17387 + ZERO_GATE + MEGA_OFFSET; template inline constexpr size_t POSEIDON2_PERMUTATION = 73 + ZERO_GATE + MEGA_OFFSET; template inline constexpr size_t MULTI_SCALAR_MUL = 3550 + ZERO_GATE; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.cpp index 41f66a3b6b6e..8d46642d2bca 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.cpp @@ -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 { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/opcode_gate_count.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/opcode_gate_count.test.cpp index c589795de80a..2b6e937d5980 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/opcode_gate_count.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/opcode_gate_count.test.cpp @@ -436,7 +436,7 @@ TYPED_TEST(OpcodeGateCountTests, Blake2s) blake2s_constraint.inputs.push_back(Blake2sInput{ .blackbox_input = WitnessOrConstant::from_index(0), - .num_bits = 32, + .num_bits = 8, }); for (size_t i = 0; i < 32; ++i) { @@ -466,7 +466,7 @@ TYPED_TEST(OpcodeGateCountTests, Blake3) blake3_constraint.inputs.push_back(Blake3Input{ .blackbox_input = WitnessOrConstant::from_index(0), - .num_bits = 32, + .num_bits = 8, }); for (size_t i = 0; i < 32; ++i) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/round.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/round.cpp deleted file mode 100644 index 6e9645229981..000000000000 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/round.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// === AUDIT STATUS === -// internal: { status: Planned, auditors: [], commit: } -// external_1: { status: not started, auditors: [], commit: } -// external_2: { status: not started, auditors: [], commit: } -// ===================== - -#include "round.hpp" - -namespace acir_format { - -// Rounds a number to the nearest multiple of 8 -uint32_t round_to_nearest_mul_8(uint32_t num_bits) -{ - BB_ASSERT(num_bits <= UINT32_MAX - 8, "round_to_nearest_mul_8: num_bits too large, calculation would overflow."); - uint32_t remainder = num_bits % 8; - if (remainder == 0) { - return num_bits; - } - - return num_bits + 8 - remainder; -} - -// Rounds the number of bits to the nearest byte -uint32_t round_to_nearest_byte(uint32_t num_bits) -{ - return round_to_nearest_mul_8(num_bits) / 8; -} - -} // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/round.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/round.hpp deleted file mode 100644 index 4fc17a08211b..000000000000 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/round.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// === AUDIT STATUS === -// internal: { status: Planned, auditors: [], commit: } -// external_1: { status: not started, auditors: [], commit: } -// external_2: { status: not started, auditors: [], commit: } -// ===================== - -#include "barretenberg/common/assert.hpp" -#include - -namespace acir_format { - -// Rounds a number to the nearest multiple of 8 -uint32_t round_to_nearest_mul_8(uint32_t num_bits); - -// Rounds the number of bits to the nearest byte -uint32_t round_to_nearest_byte(uint32_t num_bits); - -} // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp index d4ec8342235b..123b7f0d6fe2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp @@ -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 {