Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: All pedersen compress_native methods now return a grumpkin::fq #2956

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -55,27 +55,25 @@ grumpkin::fq compress_native_buffer_to_field(const std::vector<uint8_t>& input,
return result_fq;
}

std::vector<uint8_t> compress_native(const std::vector<uint8_t>& input, const size_t hash_index)
grumpkin::fq compress_native(const std::vector<uint8_t>& input, const size_t hash_index)
{
const auto result_fq = compress_native_buffer_to_field(input, hash_index);
uint256_t result_u256(result_fq);
const grumpkin::fq result_fq = compress_native_buffer_to_field(input, hash_index);
const size_t num_bytes = input.size();

// Check if the original input was zero and return the number of bytes.
// This is solely due to the fact that we cannot commit to all zeroes.
// TODO(Kev): when we switch to the new pedersen, this will
// become a hash and we will be able to remove the below lines
// because the hash will be able to commit to all zeroes.
bool is_zero = true;
for (const auto byte : input) {
is_zero = is_zero && (byte == static_cast<uint8_t>(0));
}
if (is_zero) {
result_u256 = num_bytes;
return num_bytes;
} else {
return result_fq;
}
std::vector<uint8_t> result_buffer;
result_buffer.reserve(32);
for (size_t i = 0; i < 32; ++i) {
const uint64_t shift = (31 - i) * 8;
uint256_t shifted = result_u256 >> uint256_t(shift);
result_buffer.push_back(static_cast<uint8_t>(shifted.data[0]));
}
return result_buffer;
}

} // namespace lookup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace lookup {
grumpkin::g1::element merkle_damgard_compress(const std::vector<grumpkin::fq>& inputs, const size_t iv);

grumpkin::fq compress_native(const std::vector<grumpkin::fq>& inputs, const size_t hash_index = 0);
std::vector<uint8_t> compress_native(const std::vector<uint8_t>& input, const size_t hash_index = 0);
grumpkin::fq compress_native(const std::vector<uint8_t>& input, const size_t hash_index = 0);
grumpkin::fq compress_native_buffer_to_field(const std::vector<uint8_t>& input, const size_t hash_index = 0);

grumpkin::g1::affine_element commit_native(const std::vector<grumpkin::fq>& inputs, const size_t hash_index = 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ barretenberg::fr verification_key_data::compress_native(const size_t hash_index)

barretenberg::fr compressed_key;
if (proof_system::CircuitType(circuit_type) == proof_system::CircuitType::ULTRA) {
compressed_key = from_buffer<barretenberg::fr>(
crypto::pedersen_commitment::lookup::compress_native(preimage_data, hash_index));
compressed_key = crypto::pedersen_commitment::lookup::compress_native(preimage_data, hash_index);
} else {
compressed_key = crypto::pedersen_commitment::compress_native(preimage_data, hash_index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ template <typename Curve> struct verification_key {

barretenberg::fr compressed_key;
if constexpr (HasPlookup<Builder>) {
compressed_key = from_buffer<barretenberg::fr>(
crypto::pedersen_commitment::lookup::compress_native(preimage_data, hash_index));
compressed_key = crypto::pedersen_commitment::lookup::compress_native(preimage_data, hash_index);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not related to this PR, I think this deserves a small comment -- seeing native computation being done in the stdlib always raises suspicions for me. This same computation is also done in the non-stdlib variant of this method

} else {
compressed_key = crypto::pedersen_commitment::compress_native(preimage_data, hash_index);
}
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/transcript/transcript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ void Transcript::apply_fiat_shamir(const std::string& challenge_name /*, const b
break;
}
case HashType::PlookupPedersenBlake3s: {
std::vector<uint8_t> compressed_buffer = crypto::pedersen_commitment::lookup::compress_native(buffer);
std::vector<uint8_t> compressed_buffer =
to_buffer(crypto::pedersen_commitment::lookup::compress_native(buffer));
base_hash = Blake3sHasher::hash_plookup(compressed_buffer);
break;
}
Expand Down