-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f0a803
commit 0905eea
Showing
14 changed files
with
2,123 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2022 Mikhail Komarov <[email protected]> | ||
// Copyright (c) 2022 Nikita Kaskov <[email protected]> | ||
// | ||
// MIT License | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
//---------------------------------------------------------------------------// | ||
|
||
#ifndef CRYPTO3_ASSIGNER_BLS12_381_PAIRING_HPP | ||
#define CRYPTO3_ASSIGNER_BLS12_381_PAIRING_HPP | ||
|
||
#include "llvm/IR/Type.h" | ||
#include "llvm/IR/TypeFinder.h" | ||
#include "llvm/IR/TypedPointerType.h" | ||
|
||
#include <nil/crypto3/algebra/curves/bls12.hpp> | ||
#include <nil/crypto3/algebra/curves/ed25519.hpp> | ||
#include <nil/crypto3/algebra/curves/curve25519.hpp> | ||
#include <nil/crypto3/algebra/curves/pallas.hpp> | ||
#include <nil/crypto3/algebra/curves/vesta.hpp> | ||
|
||
#include <nil/blueprint/handle_component.hpp> | ||
|
||
namespace nil { | ||
namespace blueprint { | ||
|
||
template<typename BlueprintFieldType, typename ArithmetizationParams> | ||
void handle_bls12381_pairing( | ||
const llvm::Instruction *inst, | ||
stack_frame<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &frame, | ||
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp, | ||
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> | ||
&assignment, | ||
std::uint32_t start_row, std::uint32_t target_prover_idx) { | ||
|
||
using var = crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>; | ||
|
||
using component_type = components::bls12_381_pairing< | ||
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, | ||
BlueprintFieldType>; | ||
|
||
ASSERT(frame.vectors[inst->getOperand(0)].size() == 2); | ||
ASSERT(frame.vectors[inst->getOperand(1)].size() == 4); | ||
std::vector<var> operand0_vars = frame.vectors[inst->getOperand(0)]; | ||
std::vector<var> operand1_vars = frame.vectors[inst->getOperand(1)]; | ||
|
||
std::array<var,2> P = { | ||
operand0_vars[0], | ||
operand0_vars[1]}; | ||
std::array<var,4> Q = { | ||
operand1_vars[0], | ||
operand1_vars[1], | ||
operand1_vars[2], | ||
operand1_vars[3]}; | ||
|
||
typename component_type::input_type instance_input; | ||
instance_input.P = P; | ||
instance_input.Q = Q; | ||
|
||
const auto& component_result = get_component_result<BlueprintFieldType, ArithmetizationParams, component_type> | ||
(bp, assignment, start_row, target_prover_idx, instance_input); | ||
|
||
handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type> | ||
(assignment, inst, frame, component_result); | ||
} | ||
|
||
} // namespace blueprint | ||
} // namespace nil | ||
|
||
#endif // CRYPTO3_ASSIGNER_BLS12_381_PAIRING_HPP |
90 changes: 90 additions & 0 deletions
90
include/nil/blueprint/bls_signature/fp12_multiplication.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2022 Mikhail Komarov <[email protected]> | ||
// Copyright (c) 2022 Nikita Kaskov <[email protected]> | ||
// | ||
// MIT License | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
//---------------------------------------------------------------------------// | ||
|
||
#ifndef CRYPTO3_ASSIGNER_FP12_MULTIPLICATION_HPP | ||
#define CRYPTO3_ASSIGNER_FP12_MULTIPLICATION_HPP | ||
|
||
#include "llvm/IR/Type.h" | ||
#include "llvm/IR/TypeFinder.h" | ||
#include "llvm/IR/TypedPointerType.h" | ||
|
||
#include <nil/crypto3/algebra/curves/bls12.hpp> | ||
#include <nil/crypto3/algebra/curves/ed25519.hpp> | ||
#include <nil/crypto3/algebra/curves/curve25519.hpp> | ||
#include <nil/crypto3/algebra/curves/pallas.hpp> | ||
#include <nil/crypto3/algebra/curves/vesta.hpp> | ||
|
||
#include <nil/blueprint/handle_component.hpp> | ||
|
||
namespace nil { | ||
namespace blueprint { | ||
|
||
template<typename BlueprintFieldType, typename ArithmetizationParams> | ||
void handle_fp12_mul( | ||
const llvm::Instruction *inst, | ||
stack_frame<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &frame, | ||
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp, | ||
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> | ||
&assignment, | ||
std::uint32_t start_row, std::uint32_t target_prover_idx) { | ||
|
||
using var = crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>; | ||
|
||
using component_type = components::fp12_multiplication< | ||
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, | ||
BlueprintFieldType>; | ||
|
||
std::vector<var> x = frame.vectors[inst->getOperand(0)]; | ||
ASSERT(x.size() == 12); | ||
|
||
std::vector<var> y = frame.vectors[inst->getOperand(1)]; | ||
ASSERT(y.size() == 12); | ||
|
||
std::array<var,12> x_arr = { | ||
x[0], x[1], x[2], x[3], | ||
x[4], x[5], x[6], x[7], | ||
x[8], x[9], x[10], x[11] | ||
}; | ||
std::array<var,12> y_arr = { | ||
y[0], y[1], y[2], y[3], | ||
y[4], y[5], y[6], y[7], | ||
y[8], y[9], y[10], y[11] | ||
}; | ||
|
||
typename component_type::input_type instance_input; | ||
instance_input.a = x_arr; | ||
instance_input.b = y_arr; | ||
|
||
const auto& component_result = get_component_result<BlueprintFieldType, ArithmetizationParams, component_type> | ||
(bp, assignment, start_row, target_prover_idx, instance_input); | ||
|
||
handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type> | ||
(assignment, inst, frame, component_result); | ||
} | ||
|
||
} // namespace blueprint | ||
} // namespace nil | ||
|
||
#endif // CRYPTO3_ASSIGNER_FP12_MULTIPLICATION_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2022 Mikhail Komarov <[email protected]> | ||
// Copyright (c) 2022 Nikita Kaskov <[email protected]> | ||
// | ||
// MIT License | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
//---------------------------------------------------------------------------// | ||
|
||
#ifndef CRYPTO3_ASSIGNER_H2C_HPP | ||
#define CRYPTO3_ASSIGNER_H2C_HPP | ||
|
||
#include "llvm/IR/Type.h" | ||
#include "llvm/IR/TypeFinder.h" | ||
#include "llvm/IR/TypedPointerType.h" | ||
|
||
#include <nil/crypto3/algebra/curves/bls12.hpp> | ||
#include <nil/crypto3/algebra/curves/ed25519.hpp> | ||
#include <nil/crypto3/algebra/curves/curve25519.hpp> | ||
#include <nil/crypto3/algebra/curves/pallas.hpp> | ||
#include <nil/crypto3/algebra/curves/vesta.hpp> | ||
|
||
#include <nil/blueprint/handle_component.hpp> | ||
|
||
namespace nil { | ||
namespace blueprint { | ||
|
||
template<typename BlueprintFieldType, typename ArithmetizationParams> | ||
void handle_h2c( | ||
const llvm::Instruction *inst, | ||
stack_frame<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &frame, | ||
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp, | ||
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> | ||
&assignment, | ||
std::uint32_t start_row, std::uint32_t target_prover_idx) { | ||
|
||
using var = crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>; | ||
|
||
using component_type = components::h2c< | ||
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, | ||
BlueprintFieldType>; | ||
|
||
var input = frame.scalars[inst->getOperand(0)]; | ||
|
||
typename component_type::input_type instance_input; | ||
instance_input.input = input; | ||
|
||
const auto& component_result = get_component_result<BlueprintFieldType, ArithmetizationParams, component_type> | ||
(bp, assignment, start_row, target_prover_idx, instance_input); | ||
|
||
handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type> | ||
(assignment, inst, frame, component_result); | ||
} | ||
|
||
} // namespace blueprint | ||
} // namespace nil | ||
|
||
#endif // CRYPTO3_ASSIGNER_H2C_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2022 Mikhail Komarov <[email protected]> | ||
// Copyright (c) 2022 Nikita Kaskov <[email protected]> | ||
// | ||
// MIT License | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
//---------------------------------------------------------------------------// | ||
|
||
#ifndef CRYPTO3_ASSIGNER_IS_IN_G1_HPP | ||
#define CRYPTO3_ASSIGNER_IS_IN_G1_HPP | ||
|
||
#include "llvm/IR/Type.h" | ||
#include "llvm/IR/TypeFinder.h" | ||
#include "llvm/IR/TypedPointerType.h" | ||
|
||
#include <nil/crypto3/algebra/curves/bls12.hpp> | ||
#include <nil/crypto3/algebra/curves/ed25519.hpp> | ||
#include <nil/crypto3/algebra/curves/curve25519.hpp> | ||
#include <nil/crypto3/algebra/curves/pallas.hpp> | ||
#include <nil/crypto3/algebra/curves/vesta.hpp> | ||
|
||
#include <nil/blueprint/handle_component.hpp> | ||
|
||
namespace nil { | ||
namespace blueprint { | ||
|
||
template<typename BlueprintFieldType, typename ArithmetizationParams> | ||
void handle_is_in_g1( | ||
const llvm::Instruction *inst, | ||
stack_frame<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &frame, | ||
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp, | ||
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> | ||
&assignment, | ||
std::uint32_t start_row, std::uint32_t target_prover_idx) { | ||
|
||
using var = crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>; | ||
|
||
using component_type = components::is_in_g1< | ||
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, | ||
BlueprintFieldType>; | ||
|
||
ASSERT(frame.vectors[inst->getOperand(0)].size() == 2); | ||
std::vector<var> operand0_vars = frame.vectors[inst->getOperand(0)]; | ||
|
||
std::array<var,2> input = { | ||
operand0_vars[0], | ||
operand0_vars[1]}; | ||
|
||
typename component_type::input_type instance_input; | ||
instance_input.input = input; | ||
|
||
const auto& component_result = get_component_result<BlueprintFieldType, ArithmetizationParams, component_type> | ||
(bp, assignment, start_row, target_prover_idx, instance_input); | ||
|
||
handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type> | ||
(assignment, inst, frame, component_result); | ||
} | ||
|
||
} // namespace blueprint | ||
} // namespace nil | ||
|
||
#endif // CRYPTO3_ASSIGNER_IS_IN_G1_HPP |
Oops, something went wrong.