Skip to content
This repository has been archived by the owner on Feb 17, 2025. It is now read-only.

Commit

Permalink
Merge pull request #170 from NilFoundation/168-update-get-component-id
Browse files Browse the repository at this point in the history
Updated component id mechanism.
  • Loading branch information
Luannet authored Jul 4, 2023
2 parents 5990182 + e762e27 commit 6f926b5
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 8 deletions.
16 changes: 10 additions & 6 deletions include/nil/blueprint/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace nil {
using witness_container_type = std::array<std::uint32_t, WitnessAmount>;
using constant_container_type = std::array<std::uint32_t, ConstantAmount>;
using public_input_container_type = std::array<std::uint32_t, PublicInputAmount>;

public:

witness_container_type _W;
Expand All @@ -63,7 +63,7 @@ namespace nil {

/**
* Get Witness column global index by its internal index.
*
*
* @param[in] internal witness signed index. For -1, last witness assumed.
*/
typename witness_container_type::value_type W(std::int32_t index) const {
Expand All @@ -72,7 +72,7 @@ namespace nil {

/**
* Get Constant column global index by its internal index.
*
*
* @param[in] internal constant signed index. For -1, last constant assumed.
*/
typename constant_container_type::value_type C(std::int32_t index) const {
Expand All @@ -81,7 +81,7 @@ namespace nil {

/**
* Get Public Input column global index by its internal index.
*
*
* @param[in] internal public input signed index. For -1, last public input assumed.
*/
typename public_input_container_type::value_type PI(std::int32_t index) const {
Expand All @@ -93,7 +93,7 @@ namespace nil {

/**
* Constructor from arbitrary container types.
*
*
* @tparam WitnessContainerType Input Witness Container Type
* @tparam ConstantContainerType Input Constant Container Type
* @tparam PublicInputContainerType Input PublicInput Container Type
Expand Down Expand Up @@ -122,6 +122,8 @@ namespace nil {
return _PI.size();
}

virtual detail::blueprint_component_id_type get_id() const { return std::string(""); };

template <typename ComponentType>
friend detail::blueprint_component_id_type detail::get_component_id (ComponentType component);
};
Expand All @@ -135,7 +137,7 @@ namespace nil {
// ConstantAmount, PublicInputAmount>
// std::size_t operator() (const component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, WitnessAmount,
// ConstantAmount, PublicInputAmount> &node) const {

// }
// };

Expand All @@ -155,6 +157,8 @@ namespace nil {
public:
r1cs_component(blueprint<ArithmetizationType> &bp) : bp(bp) {
}

virtual detail::blueprint_component_id_type get_id() const { return std::string(""); };
};

} // namespace components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/component.hpp>
#include <nil/blueprint/detail/get_component_id.hpp>

#include <nil/blueprint/components/algebra/fields/plonk/non_native/detail/bit_builder_component.hpp>
#include <nil/blueprint/components/algebra/fields/plonk/non_native/bit_composition.hpp>
#include <nil/blueprint/components/algebra/fields/plonk/non_native/bit_decomposition.hpp>

#include <algorithm>
#include <utility>
#include <sstream>
#include <string>

namespace nil {
namespace blueprint {
Expand Down Expand Up @@ -119,6 +122,12 @@ namespace nil {
}
};

nil::blueprint::detail::blueprint_component_id_type get_id() const override {
std::stringstream ss;
ss << "_" << WitnessesAmount << "_" << mode << "_" << shift;
return ss.str();
}

template<typename ContainerType>
bit_shift_constant(ContainerType witness, std::uint32_t bits_amount, std::uint32_t shift_,
bit_shift_mode mode_) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@
#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/component.hpp>
#include <nil/blueprint/detail/get_component_id.hpp>

#include <nil/blueprint/components/algebra/fields/plonk/non_native/detail/bit_builder_component.hpp>

#include <utility>
#include <sstream>
#include <string>

using nil::blueprint::components::detail::bit_builder_component;
using nil::blueprint::components::detail::bit_composition_mode;
Expand Down Expand Up @@ -86,6 +89,12 @@ namespace nil {
}
};

nil::blueprint::detail::blueprint_component_id_type get_id() const override {
std::stringstream ss;
ss << "_" << WitnessesAmount << "_" << mode << "_" << this->bits_amount << "_" << this->check_bits;
return ss.str();
}

template<typename ContainerType>
bit_composition(ContainerType witness, std::uint32_t bits_amount, bool check_input,
bit_composition_mode mode_) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/component.hpp>
#include <nil/blueprint/detail/get_component_id.hpp>

#include <nil/blueprint/components/algebra/fields/plonk/non_native/detail/bit_builder_component.hpp>

#include <type_traits>
#include <utility>
#include <sstream>
#include <string>

using nil::blueprint::components::detail::bit_builder_component;
using nil::blueprint::components::detail::bit_composition_mode;
Expand All @@ -60,7 +63,7 @@ namespace nil {
WitnessesAmount>
: public
bit_builder_component<crypto3::zk::snark::plonk_constraint_system<
BlueprintFieldType, ArithmetizationParams>,
BlueprintFieldType, ArithmetizationParams>,
WitnessesAmount> {

using component_type =
Expand Down Expand Up @@ -95,6 +98,12 @@ namespace nil {
}
};

nil::blueprint::detail::blueprint_component_id_type get_id() const override {
std::stringstream ss;
ss << "_" << WitnessesAmount << "_" << mode << "_" << this->bits_amount;
return ss.str();
}

template<typename ContainerType>
bit_decomposition(ContainerType witness, std::uint32_t bits_amount,
bit_composition_mode mode_) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@
#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/component.hpp>
#include <nil/blueprint/detail/get_component_id.hpp>

#include <nil/blueprint/components/algebra/fields/plonk/non_native/detail/comparison_mode.hpp>

#include <type_traits>
#include <utility>
#include <sstream>
#include <string>

namespace nil {
namespace blueprint {
Expand Down Expand Up @@ -149,6 +152,12 @@ namespace nil {
result_type(const comparison_checked &component, std::size_t start_row_index) {}
};

nil::blueprint::detail::blueprint_component_id_type get_id() const override {
std::stringstream ss;
ss << "_" << WitnessesAmount << "_" << bits_amount << "_" << mode;
return ss.str();
}

#define __comparison_checked_init_macro(bits_amount_, mode_) \
bits_amount(bits_amount_), \
mode(mode_), \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@
#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/component.hpp>
#include <nil/blueprint/detail/get_component_id.hpp>

#include <nil/blueprint/components/algebra/fields/plonk/non_native/detail/comparison_mode.hpp>

#include <utility>
#include <type_traits>
#include <sstream>
#include <string>

namespace nil {
namespace blueprint {
Expand Down Expand Up @@ -163,6 +166,12 @@ namespace nil {
}
};

nil::blueprint::detail::blueprint_component_id_type get_id() const override {
std::stringstream ss;
ss << "_" << WitnessesAmount << "_" << bits_amount << "_" << mode;
return ss.str();
}

#define __comparison_flag_init_macro(bits_amount_, mode_) \
bits_amount(bits_amount_), \
mode(mode_), \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@
#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/component.hpp>
#include <nil/blueprint/detail/get_component_id.hpp>

#include <nil/blueprint/components/algebra/fields/plonk/non_native/detail/comparison_mode.hpp>
#include <nil/blueprint/components/algebra/fields/plonk/range_check.hpp>

#include <type_traits>
#include <utility>
#include <sstream>
#include <string>

namespace nil {
namespace blueprint {
Expand Down Expand Up @@ -106,6 +109,12 @@ namespace nil {
result_type(const comparison_unchecked &component, std::size_t start_row_index) {}
};

nil::blueprint::detail::blueprint_component_id_type get_id() const override {
std::stringstream ss;
ss << "_" << WitnessesAmount << "_" << bits_amount << "_" << mode;
return ss.str();
}

#define __comparison_unchecked_init_macro(witness, constant, public_input, bits_amount_, mode_) \
bits_amount(bits_amount_), \
mode(mode_), \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/component.hpp>
#include <nil/blueprint/detail/get_component_id.hpp>

#include <nil/blueprint/components/algebra/fields/plonk/range_check.hpp>

#include <nil/crypto3/random/algebraic_engine.hpp>

#include <type_traits>
#include <utility>
#include <sstream>
#include <string>

namespace nil {
namespace blueprint {
Expand Down Expand Up @@ -122,6 +125,12 @@ namespace nil {
}
};

nil::blueprint::detail::blueprint_component_id_type get_id() const override {
std::stringstream ss;
ss << "_" << WitnessesAmount << "_" << bits_amount << "_" << check_inputs;
return ss.str();
}

#define __division_remainder_init_macro(witness, constant, public_input, \
bits_amount_, check_inputs_) \
bits_amount(bits_amount_), \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
#include <nil/blueprint/blueprint/plonk/circuit.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/component.hpp>
#include <nil/blueprint/detail/get_component_id.hpp>

#include <utility>
#include <type_traits>
#include <sstream>
#include <string>

namespace nil {
namespace blueprint {
Expand Down Expand Up @@ -116,6 +119,12 @@ namespace nil {
result_type(const range_check &component, std::size_t start_row_index) {}
};

nil::blueprint::detail::blueprint_component_id_type get_id() const override {
std::stringstream ss;
ss << "_" << WitnessesAmount << "_" << bits_amount;
return ss.str();
}

#define __range_check_init_macro(bits_amount_) \
bits_amount(bits_amount_), \
rows_amount(rows(bits_amount_)), \
Expand Down
4 changes: 3 additions & 1 deletion include/nil/blueprint/detail/get_component_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define CRYPTO3_BLUEPRINT_DETAIL_COMPONENT_ID_HPP

#include <typeinfo>
#include <string>
#include <sstream>

namespace nil {
namespace blueprint {
Expand All @@ -38,7 +40,7 @@ namespace nil {
blueprint_component_id_type get_component_id(const ComponentType& component) {
std::stringstream id;

id << typeid(component).name();
id << typeid(component).name() << component.get_id();
return id.str();
}
} // namespace detail
Expand Down

0 comments on commit 6f926b5

Please sign in to comment.