-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update Pedersen test component to use random elements in bn254…
… and bls12-381 curve tests (PROOF-891) (#152) * feat: add random affine element generation * chore: update pedersen tests to use random element generator
- Loading branch information
1 parent
4f590f5
commit db722fc
Showing
10 changed files
with
226 additions
and
16 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
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
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
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,17 @@ | ||
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU. | ||
* | ||
* Copyright 2023-present Space and Time Labs, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "sxt/curve_bng1/random/element_affine.h" |
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,38 @@ | ||
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU. | ||
* | ||
* Copyright 2023-present Space and Time Labs, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include <cstring> | ||
|
||
#include "sxt/base/macro/cuda_callable.h" | ||
#include "sxt/curve_bng1/random/element_p2.h" | ||
#include "sxt/curve_bng1/type/conversion_utility.h" | ||
#include "sxt/curve_bng1/type/element_affine.h" | ||
#include "sxt/curve_bng1/type/element_p2.h" | ||
|
||
namespace sxt::cn1rn { | ||
//-------------------------------------------------------------------------------------------------- | ||
// generate_random_element | ||
//-------------------------------------------------------------------------------------------------- | ||
CUDA_CALLABLE | ||
inline void generate_random_element(cn1t::element_affine& a, | ||
basn::fast_random_number_generator& rng) noexcept { | ||
cn1t::element_p2 p; | ||
generate_random_element(p, rng); | ||
cn1t::to_element_affine(a, p); | ||
} | ||
} // namespace sxt::cn1rn |
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,38 @@ | ||
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU. | ||
* | ||
* Copyright 2023-present Space and Time Labs, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "sxt/curve_bng1/random/element_affine.h" | ||
|
||
#include "sxt/base/num/fast_random_number_generator.h" | ||
#include "sxt/base/test/unit_test.h" | ||
#include "sxt/curve_bng1/property/curve.h" | ||
#include "sxt/curve_bng1/type/element_affine.h" | ||
|
||
using namespace sxt; | ||
using namespace sxt::cn1rn; | ||
|
||
TEST_CASE("random element generation") { | ||
basn::fast_random_number_generator rng{1, 2}; | ||
|
||
SECTION("will return different values on the curve if called multiple times") { | ||
cn1t::element_affine e1, e2; | ||
generate_random_element(e1, rng); | ||
generate_random_element(e2, rng); | ||
REQUIRE(e1 != e2); | ||
REQUIRE(cn1p::is_on_curve(e1)); | ||
REQUIRE(cn1p::is_on_curve(e2)); | ||
} | ||
} |
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
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,17 @@ | ||
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU. | ||
* | ||
* Copyright 2023-present Space and Time Labs, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "sxt/curve_g1/random/element_affine.h" |
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,38 @@ | ||
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU. | ||
* | ||
* Copyright 2023-present Space and Time Labs, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include <cstring> | ||
|
||
#include "sxt/base/macro/cuda_callable.h" | ||
#include "sxt/curve_g1/random/element_p2.h" | ||
#include "sxt/curve_g1/type/conversion_utility.h" | ||
#include "sxt/curve_g1/type/element_affine.h" | ||
#include "sxt/curve_g1/type/element_p2.h" | ||
|
||
namespace sxt::cg1rn { | ||
//-------------------------------------------------------------------------------------------------- | ||
// generate_random_element | ||
//-------------------------------------------------------------------------------------------------- | ||
CUDA_CALLABLE | ||
inline void generate_random_element(cg1t::element_affine& a, | ||
basn::fast_random_number_generator& rng) noexcept { | ||
cg1t::element_p2 p; | ||
generate_random_element(p, rng); | ||
cg1t::to_element_affine(a, p); | ||
} | ||
} // namespace sxt::cg1rn |
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,38 @@ | ||
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU. | ||
* | ||
* Copyright 2023-present Space and Time Labs, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "sxt/curve_g1/random/element_affine.h" | ||
|
||
#include "sxt/base/num/fast_random_number_generator.h" | ||
#include "sxt/base/test/unit_test.h" | ||
#include "sxt/curve_g1/property/curve.h" | ||
#include "sxt/curve_g1/type/element_affine.h" | ||
|
||
using namespace sxt; | ||
using namespace sxt::cg1rn; | ||
|
||
TEST_CASE("random element generation") { | ||
basn::fast_random_number_generator rng{1, 2}; | ||
|
||
SECTION("will return different values on the curve if called multiple times") { | ||
cg1t::element_affine e1, e2; | ||
generate_random_element(e1, rng); | ||
generate_random_element(e2, rng); | ||
REQUIRE(e1 != e2); | ||
REQUIRE(cg1p::is_on_curve(e1)); | ||
REQUIRE(cg1p::is_on_curve(e2)); | ||
} | ||
} |