-
Notifications
You must be signed in to change notification settings - Fork 270
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
feat: add poseidon2 hashing to native transcript #3718
Changes from 21 commits
29a0d28
61c9eca
a8204fb
05085c5
99bd01d
029350c
a045b6d
86065bc
d50ac92
5f46e2d
d157087
f769528
e8702c7
86eae85
4a04326
2d16e5d
2c6406d
c0c715c
dd3366c
b37bed8
09f7ea2
7346629
1484030
97c2f88
e2f7526
f67148d
c0b5fb6
d3e110b
330c0c8
7fd7553
bbfb92b
a53a144
e12cb61
fe43adf
b1d5678
cab1312
54bb864
9cc55d1
87078b3
850ec4d
9f6293c
777e8b1
de5b619
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#include "crypto/keccak/keccak.hpp" | ||
#include "crypto/pedersen_commitment/pedersen.hpp" | ||
#include "crypto/pedersen_hash/pedersen.hpp" | ||
#include "crypto/poseidon2/poseidon2.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added in an attempt to solve linker error, but probably still needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like this file is unused so adding this is just for documentation about what is in barretenberg |
||
#include "crypto/schnorr/schnorr.hpp" | ||
#include "crypto/sha256/sha256.hpp" | ||
#include "ecc/curves/bn254/fq.hpp" | ||
|
@@ -41,6 +42,7 @@ | |
#include "stdlib/hash/blake2s/blake2s.hpp" | ||
#include "stdlib/hash/blake3s/blake3s.hpp" | ||
#include "stdlib/hash/pedersen/pedersen.hpp" | ||
#include "stdlib/hash/poseidon2/poseidon2.hpp" | ||
#include "stdlib/merkle_tree/hash.hpp" | ||
#include "stdlib/merkle_tree/membership.hpp" | ||
#include "stdlib/merkle_tree/memory_store.hpp" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
barretenberg_module(ecc numeric crypto_keccak crypto_sha256) | ||
barretenberg_module(ecc numeric crypto_keccak crypto_sha256 ecc_fields) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, an attempt to solve linker errors but not sure if this is needed at all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing this caused no problems |
||
|
||
if(DISABLE_ADX) | ||
message(STATUS "Disabling ADX assembly variant.") | ||
|
@@ -14,7 +14,10 @@ target_precompile_headers( | |
$<$<COMPILE_LANGUAGE:CXX>:"${CMAKE_CURRENT_SOURCE_DIR}/fields/asm_macros.hpp"> | ||
$<$<COMPILE_LANGUAGE:CXX>:"${CMAKE_CURRENT_SOURCE_DIR}/fields/field_declarations.hpp"> | ||
$<$<COMPILE_LANGUAGE:CXX>:"${CMAKE_CURRENT_SOURCE_DIR}/fields/field_impl.hpp"> | ||
$<$<COMPILE_LANGUAGE:CXX>:"${CMAKE_CURRENT_SOURCE_DIR}/fields/field_conversion_utils.hpp"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assume this is necessary? |
||
$<$<COMPILE_LANGUAGE:CXX>:"${CMAKE_CURRENT_SOURCE_DIR}/fields/field_impl_generic.hpp"> | ||
$<$<COMPILE_LANGUAGE:CXX>:"${CMAKE_CURRENT_SOURCE_DIR}/fields/field_impl_x64.hpp"> | ||
$<$<COMPILE_LANGUAGE:CXX>:"${CMAKE_CURRENT_SOURCE_DIR}/fields/field.hpp"> | ||
) | ||
|
||
add_subdirectory(fields) | ||
lucasxia01 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
barretenberg_module(ecc_fields) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
#include "barretenberg/ecc/fields/field_conversion_utils.hpp" | ||
lucasxia01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace barretenberg::field_conversion_utils { | ||
|
||
lucasxia01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static constexpr uint64_t NUM_CONVERSION_LIMB_BITS = 64; | ||
|
||
/** | ||
* @brief Decomposes a barretenberg::fr into two 64-bit limbs. Helper function for | ||
* convert_barretenberg_frs_to_grumpkin_fr. | ||
* | ||
* @param field_val | ||
* @return std::array<uint64_t, 2> | ||
*/ | ||
std::array<uint64_t, 2> decompose_bn254_fr_to_two_limbs(const barretenberg::fr& field_val) | ||
{ | ||
ASSERT(uint256_t(field_val) < (uint256_t(1) << (2 * NUM_CONVERSION_LIMB_BITS))); // should be 128 bits or less | ||
constexpr uint256_t LIMB_MASK = | ||
(uint256_t(1) << NUM_CONVERSION_LIMB_BITS) - 1; // split bn254_fr into two 64 bit limbs | ||
const uint256_t value = field_val; | ||
const uint64_t low = static_cast<uint64_t>(value & LIMB_MASK); | ||
const uint64_t hi = static_cast<uint64_t>(value >> NUM_CONVERSION_LIMB_BITS); | ||
ASSERT(static_cast<uint256_t>(low) + (static_cast<uint256_t>(hi) << NUM_CONVERSION_LIMB_BITS) == value); | ||
|
||
return std::array<uint64_t, 2>{ low, hi }; | ||
} | ||
|
||
/** | ||
* @brief Converts 2 barretenberg::fr elements to grumpkin::fr | ||
* @details Checks that each barretenberg::fr must be at most 128 bits (to ensure no overflow), and decomposes each | ||
* barretenberg::fr into two 64-bit limbs, and the 4 64-bit limbs form the grumpkin::fr | ||
* @param low_bits_in | ||
* @param high_bits_in | ||
* @return grumpkin::fr | ||
*/ | ||
grumpkin::fr convert_barretenberg_frs_to_grumpkin_fr(const barretenberg::fr& low_bits_in, | ||
const barretenberg::fr& high_bits_in) | ||
{ | ||
// TODO: figure out can_overflow, maximum_bitlength in stdlib version | ||
ASSERT(uint256_t(low_bits_in) < (uint256_t(1) << (NUM_CONVERSION_LIMB_BITS * 2))); | ||
ASSERT(uint256_t(high_bits_in) < (uint256_t(1) << (NUM_CONVERSION_LIMB_BITS * 2))); | ||
auto low_bit_decomp = decompose_bn254_fr_to_two_limbs(low_bits_in); | ||
uint256_t tmp; | ||
tmp.data[0] = low_bit_decomp[0]; | ||
tmp.data[1] = low_bit_decomp[1]; | ||
auto high_bit_decomp = decompose_bn254_fr_to_two_limbs(high_bits_in); | ||
tmp.data[2] = high_bit_decomp[0]; | ||
tmp.data[3] = high_bit_decomp[1]; | ||
grumpkin::fr result(tmp); | ||
return result; | ||
} | ||
|
||
/** | ||
* @brief Converts grumpkin::fr to 2 barretenberg::fr elements | ||
* @details Does the reverse of convert_barretenberg_frs_to_grumpkin_fr, by merging the two pairs of limbs back into the | ||
* 2 barretenberg::fr elements. | ||
* @param input | ||
* @return std::array<barretenberg::fr, 2> | ||
*/ | ||
std::array<barretenberg::fr, 2> convert_grumpkin_fr_to_barretenberg_frs(const grumpkin::fr& input) | ||
{ | ||
auto tmp = static_cast<uint256_t>(input); | ||
std::array<barretenberg::fr, 2> result; | ||
result[0] = static_cast<uint256_t>(tmp.data[0]) + (static_cast<uint256_t>(tmp.data[1]) << NUM_CONVERSION_LIMB_BITS); | ||
result[1] = static_cast<uint256_t>(tmp.data[2]) + (static_cast<uint256_t>(tmp.data[3]) << NUM_CONVERSION_LIMB_BITS); | ||
return result; | ||
} | ||
|
||
} // namespace barretenberg::field_conversion_utils |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what this is doing but this helped me resolve some annoying linker errors, presumably introduced because goblin was introduced to main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is necessary from building without it/with it since transcript uses it, which is used by main.cpp in goblin_verify