diff --git a/include/nil/blueprint/components/hashes/sha2/plonk/decomposition.hpp b/include/nil/blueprint/components/hashes/sha2/plonk/decomposition.hpp index 729110815..7affad397 100644 --- a/include/nil/blueprint/components/hashes/sha2/plonk/decomposition.hpp +++ b/include/nil/blueprint/components/hashes/sha2/plonk/decomposition.hpp @@ -203,7 +203,6 @@ namespace nil { integral_type(var_value(assignment, instance_input.data[1]).data)}; std::array, 4>, 2> range_chunks; std::array, 2> output_chunks; - std::size_t shift = 0; for (std::size_t data_idx = 0; data_idx < 2; data_idx++) { for (std::size_t chunk_idx = 0; chunk_idx < 4; chunk_idx++) { @@ -275,15 +274,18 @@ namespace nil { } template - std::size_t generate_gates( + std::array generate_gates( const plonk_native_decomposition &component, circuit> &bp, assignment> &assignment, const typename plonk_native_decomposition::input_type - &instance_input) { + &instance_input, + const typename lookup_library::left_reserved_type &lookup_tables_indices) { using var = typename plonk_native_decomposition::var; + using constraint = crypto3::zk::snark::plonk_constraint; + using lookup_constraint = crypto3::zk::snark::plonk_lookup_constraint; const typename BlueprintFieldType::integral_type one = 1; std::array selectors; diff --git a/include/nil/blueprint/components/hashes/sha2/plonk/sha256_process.hpp b/include/nil/blueprint/components/hashes/sha2/plonk/sha256_process.hpp index a988e4cff..d1a2d6408 100644 --- a/include/nil/blueprint/components/hashes/sha2/plonk/sha256_process.hpp +++ b/include/nil/blueprint/components/hashes/sha2/plonk/sha256_process.hpp @@ -1213,9 +1213,13 @@ namespace nil { &instance_input, const std::size_t start_row_index) { - std::size_t row = start_row_index + 2; using var = typename plonk_sha256_process::var; + std::size_t row = start_row_index; + for (std::size_t i = 0; i < 8; ++i) { + bp.add_copy_constraint({var(component.W(i), row, false), instance_input.input_state[i]}); + } + row = start_row_index + 2; for (std::size_t i = 1; i <= 15; ++i) { bp.add_copy_constraint( {var(component.W(0), row + (i - 1) * 5 + 0, false), instance_input.input_words[i]}); @@ -1389,7 +1393,7 @@ namespace nil { typename BlueprintFieldType::value_type h = input_state[7]; std::array sparse_values {}; - for (std::size_t i = 0; i < 4; i++) { + for (std::size_t i = 0; i < 8; i++) { assignment.witness(component.W(i), row) = input_state[i]; typename BlueprintFieldType::integral_type integral_input_state_sparse = typename BlueprintFieldType::integral_type(input_state[i].data); @@ -1404,32 +1408,12 @@ namespace nil { } std::vector input_state_sparse_sizes = {32}; + const auto base = i < 4 ? plonk_sha256_process::base4 + : plonk_sha256_process::base7; std::array, 2> input_state_sparse_chunks = detail::split_and_sparse( input_state_sparse, input_state_sparse_sizes, - plonk_sha256_process::base4); - assignment.witness(component.W(i), row + 1) = input_state_sparse_chunks[1][0]; - sparse_values[i] = input_state_sparse_chunks[1][0]; - } - for (std::size_t i = 4; i < 8; i++) { - assignment.witness(component.W(i), row) = input_state[i]; - typename BlueprintFieldType::integral_type integral_input_state_sparse = - typename BlueprintFieldType::integral_type(input_state[i].data); - std::vector input_state_sparse(32); - { - nil::marshalling::status_type status; - std::vector input_state_sparse_all = - nil::marshalling::pack(integral_input_state_sparse, - status); - std::copy(input_state_sparse_all.end() - 32, input_state_sparse_all.end(), - input_state_sparse.begin()); - } - - std::vector input_state_sparse_sizes = {32}; - std::array, 2> input_state_sparse_chunks = - detail::split_and_sparse( - input_state_sparse, input_state_sparse_sizes, - plonk_sha256_process::base7); + base); assignment.witness(component.W(i), row + 1) = input_state_sparse_chunks[1][0]; sparse_values[i] = input_state_sparse_chunks[1][0]; } diff --git a/include/nil/blueprint/utils/connectedness_check.hpp b/include/nil/blueprint/utils/connectedness_check.hpp index fbfa251a8..a0938a4ff 100644 --- a/include/nil/blueprint/utils/connectedness_check.hpp +++ b/include/nil/blueprint/utils/connectedness_check.hpp @@ -82,13 +82,13 @@ namespace nil { const std::size_t end_row = start_row_index + rows_amount; nil::blueprint::assignment> output_assignment( - assignment.witnesses_amount(), assignment.constants_amount(), - assignment.public_inputs_amount(), assignment.selectors_amount() + assignment.witnesses_amount(), assignment.public_inputs_amount(), + assignment.constants_amount(), assignment.selectors_amount() ); // We do '+1' in all the assignments to separate the unassigned cells (0 by default) // from the ones which actually got checked. - for (std::size_t witness_column = 0; witness_column < row_size; witness_column++) { + for (std::size_t witness_column = 0; witness_column < assignment.witnesses_amount(); witness_column++) { std::size_t last_row = std::min(end_row, assignment.witness_column_size(witness_column)); for (std::size_t row = start_row_index; row < last_row; row++) { @@ -114,15 +114,16 @@ namespace nil { const auto output_value = zones.find_set(copy_var_address( row_size, start_row_index, rows_amount, variable)) + 1; - switch (variable.type) { + const auto &variable_ref = variable.get(); + switch (variable_ref.type) { case var::column_type::constant: - output_assignment.constant(variable.index, variable.rotation) = output_value; + output_assignment.constant(variable_ref.index, variable_ref.rotation) = output_value; break; case var::column_type::public_input: - output_assignment.public_input(variable.index, variable.rotation) = output_value; + output_assignment.public_input(variable_ref.index, variable_ref.rotation) = output_value; break; case var::column_type::witness: - output_assignment.witness(variable.index, variable.rotation) = output_value; + output_assignment.witness(variable_ref.index, variable_ref.rotation) = output_value; break; case var::column_type::selector: BOOST_ASSERT_MSG(false, "Selector variables should not be input variables."); diff --git a/test/hashes/plonk/decomposition.cpp b/test/hashes/plonk/decomposition.cpp index 50d6c971c..89d6faa88 100644 --- a/test/hashes/plonk/decomposition.cpp +++ b/test/hashes/plonk/decomposition.cpp @@ -75,29 +75,29 @@ void test_decomposition(std::vector pub auto result_check = [&expected_res](AssignmentType &assignment, typename component_type::result_type &real_res) { - for (std::size_t i = 0; i < real_res.output.size(); i++){ - std::cout << var_value(assignment, real_res.output[i]).data << std::endl; - } - for (std::size_t i = 0; i < expected_res.size(); i++){ - std::cout << expected_res[i].data << std::endl; - } + // for (std::size_t i = 0; i < real_res.output.size(); i++){ + // std::cout << var_value(assignment, real_res.output[i]).data << std::endl; + // } + // for (std::size_t i = 0; i < expected_res.size(); i++){ + // std::cout << expected_res[i].data << std::endl; + // } for (std::size_t i = 0; i < real_res.output.size(); i++){ assert(expected_res[i] == var_value(assignment, real_res.output[i])); } }; - auto result_check_to_fail = [&expected_res](AssignmentType &assignment, - typename component_type::result_type &real_res) { }; + auto result_check_to_fail = [](AssignmentType &assignment, + typename component_type::result_type &real_res) {}; component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8},{},{}); if (expected_to_pass) { - crypto3::test_component( + crypto3::test_component( component_instance, desc, public_input, result_check, instance_input, - nil::crypto3::detail::connectedness_check_type::WEAK); + nil::blueprint::connectedness_check_type::type::WEAK); } else { - crypto3::test_component_to_fail( + crypto3::test_component_to_fail( component_instance, desc, public_input, result_check_to_fail, instance_input, - nil::crypto3::detail::connectedness_check_type::WEAK); + nil::blueprint::connectedness_check_type::type::WEAK); } } diff --git a/test/hashes/plonk/sha256_process.cpp b/test/hashes/plonk/sha256_process.cpp index a84c92050..d3e94d04e 100644 --- a/test/hashes/plonk/sha256_process.cpp +++ b/test/hashes/plonk/sha256_process.cpp @@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(blueprint_plonk_sha256_process) { using BlueprintFieldType = typename curve_type::base_field_type; constexpr std::size_t WitnessColumns = 9; constexpr std::size_t PublicInputColumns = 1; - constexpr std::size_t ConstantColumns = 20; + constexpr std::size_t ConstantColumns = 33; constexpr std::size_t SelectorColumns = 30; using hash_type = nil::crypto3::hashes::keccak_1600<256>; constexpr std::size_t Lambda = 1;