-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add c bindings for variable length multi-exponentiations (PROOF…
…-896) (#167) * add variable length multiexponentiation * add stub for c api * add c api stub * fill in c bridge * reformat * fill in tests * fill in backend * fill in cpu backend * refactor * fill in cbindings * add no output tests * fill in tests * doc * minor changes
- Loading branch information
Showing
14 changed files
with
304 additions
and
0 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
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,51 @@ | ||
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU. | ||
* | ||
* Copyright 2024-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/cbindings/backend/computational_backend_utility.h" | ||
|
||
#include <algorithm> | ||
|
||
#include "sxt/base/error/assert.h" | ||
#include "sxt/base/num/divide_up.h" | ||
|
||
namespace sxt::cbnbck { | ||
//-------------------------------------------------------------------------------------------------- | ||
// make_scalars_span | ||
//-------------------------------------------------------------------------------------------------- | ||
basct::cspan<uint8_t> make_scalars_span(const uint8_t* data, | ||
basct::cspan<unsigned> output_bit_table, | ||
basct::cspan<unsigned> output_lengths) noexcept { | ||
auto num_outputs = output_bit_table.size(); | ||
SXT_DEBUG_ASSERT(output_lengths.size() == num_outputs); | ||
|
||
unsigned output_bit_sum = 0; | ||
unsigned n = 0; | ||
unsigned prev_len = 0; | ||
for (unsigned output_index = 0; output_index < num_outputs; ++output_index) { | ||
auto width = output_bit_table[output_index]; | ||
SXT_RELEASE_ASSERT(width > 0, "output bit width must be positive"); | ||
auto len = output_lengths[output_index]; | ||
SXT_RELEASE_ASSERT(len >= prev_len, "output lengths must be sorted in ascending order"); | ||
|
||
output_bit_sum += width; | ||
n = std::max(n, len); | ||
prev_len = len; | ||
} | ||
|
||
auto output_num_bytes = basn::divide_up(output_bit_sum, 8u); | ||
return basct::cspan<uint8_t>{data, output_num_bytes * n}; | ||
} | ||
} // namespace sxt::cbnbck |
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,30 @@ | ||
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU. | ||
* | ||
* Copyright 2024-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 <cstdint> | ||
|
||
#include "sxt/base/container/span.h" | ||
|
||
namespace sxt::cbnbck { | ||
//-------------------------------------------------------------------------------------------------- | ||
// make_scalars_span | ||
//-------------------------------------------------------------------------------------------------- | ||
basct::cspan<uint8_t> make_scalars_span(const uint8_t* data, | ||
basct::cspan<unsigned> output_bit_table, | ||
basct::cspan<unsigned> output_lengths) noexcept; | ||
} // namespace sxt::cbnbck |
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,46 @@ | ||
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU. | ||
* | ||
* Copyright 2024-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/cbindings/backend/computational_backend_utility.h" | ||
|
||
#include <vector> | ||
|
||
#include "sxt/base/test/unit_test.h" | ||
|
||
using namespace sxt; | ||
using namespace sxt::cbnbck; | ||
|
||
TEST_CASE("we can make a span for the referenced scalars") { | ||
uint8_t data[16]; | ||
|
||
std::vector<unsigned> output_bit_table, output_lengths; | ||
|
||
SECTION("we handle an output of length 1") { | ||
output_bit_table = {1}; | ||
output_lengths = {1}; | ||
auto span = make_scalars_span(data, output_bit_table, output_lengths); | ||
REQUIRE(span.size() == 1); | ||
REQUIRE(span.data() == data); | ||
} | ||
|
||
SECTION("we handle multiple outputs") { | ||
output_bit_table = {1, 8}; | ||
output_lengths = {1, 2}; | ||
auto span = make_scalars_span(data, output_bit_table, output_lengths); | ||
REQUIRE(span.size() == 4); | ||
REQUIRE(span.data() == data); | ||
} | ||
} |
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
Oops, something went wrong.