Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
graph_description_sha256.test.cpp
Go to the documentation of this file.
6
7using namespace bb;
8using namespace bb::stdlib;
9using namespace cdg;
10
14
21template <size_t N> void fix_field_array(std::array<field_ct, N>& arr)
22{
23 for (auto& elem : arr) {
24 elem.fix_witness();
25 }
26}
27
36TEST(boomerang_stdlib_sha256, test_graph_for_sha256_block_single)
37{
38 auto builder = Builder();
39
40 // SHA-256 initial hash values
41 constexpr std::array<uint32_t, 8> H_INIT = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
42 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
43
44 // Create h_init witnesses
46 for (size_t i = 0; i < 8; i++) {
47 h_init[i] = witness_ct(&builder, H_INIT[i]);
48 }
49 fix_field_array(h_init);
50
51 // Create block witnesses (zeros)
53 for (size_t i = 0; i < 16; i++) {
54 block[i] = witness_ct(&builder, 0);
55 }
56 fix_field_array(block);
57
58 // Run compression
59 auto output = SHA256<Builder>::sha256_block(h_init, block);
60 fix_field_array(output);
61
62 // Analyze graph structure
64 auto connected_components = graph.find_connected_components();
65 EXPECT_EQ(connected_components.size(), 1);
66 auto variables_in_one_gate = graph.get_variables_in_one_gate();
67 EXPECT_EQ(variables_in_one_gate.size(), 0);
68}
69
80TEST(boomerang_stdlib_sha256, test_graph_for_sha256_block_chained)
81{
82 auto builder = Builder();
83
84 // SHA-256 initial hash values
85 constexpr std::array<uint32_t, 8> H_INIT = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
86 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
87
88 // Create h_init witnesses
90 for (size_t i = 0; i < 8; i++) {
91 h_init[i] = witness_ct(&builder, H_INIT[i]);
92 }
93 fix_field_array(h_init);
94
95 // Create two blocks
98 for (size_t i = 0; i < 16; i++) {
99 block1[i] = witness_ct(&builder, i); // Some arbitrary values
100 block2[i] = witness_ct(&builder, i + 16); // Different arbitrary values
101 }
102 fix_field_array(block1);
103 fix_field_array(block2);
104
105 // Chain two compression calls
106 auto h_mid = SHA256<Builder>::sha256_block(h_init, block1);
107 auto output = SHA256<Builder>::sha256_block(h_mid, block2);
108 fix_field_array(output);
109
110 // Analyze graph structure
112 auto connected_components = graph.find_connected_components();
113 EXPECT_EQ(connected_components.size(), 1);
114 auto variables_in_one_gate = graph.get_variables_in_one_gate();
115 EXPECT_EQ(variables_in_one_gate.size(), 0);
116}
static std::array< field_ct, 8 > sha256_block(const std::array< field_ct, 8 > &h_init, const std::array< field_ct, 16 > &input)
Apply the SHA-256 compression function to a single 512-bit message block.
Definition sha256.cpp:248
std::vector< ConnectedComponent > find_connected_components()
this methond finds all connected components in the graph described by adjacency lists and marks some ...
Definition graph.cpp:897
std::unordered_set< uint32_t > get_variables_in_one_gate()
this method returns a final set of variables that were in one gate
Definition graph.cpp:1396
AluTraceBuilder builder
Definition alu.test.cpp:124
void fix_field_array(std::array< field_ct, N > &arr)
Fix witness for an array of field elements.
UltraCircuitBuilder Builder
witness_t< Builder > witness_ct
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
Definition graph.cpp:14
UltraStaticAnalyzer StaticAnalyzer
Definition graph.hpp:187
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13