Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make sumcheck generic (PROOF-913) #247

Merged
merged 83 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
3eaf235
add field concept
rnburn Feb 17, 2025
0287bb9
fill in field concept
rnburn Feb 17, 2025
5ac444b
fill in field concept
rnburn Feb 17, 2025
111f060
rework
rnburn Feb 18, 2025
8b1d3c1
rework sumcheck
rnburn Feb 18, 2025
fb85a67
rework sumcheck
rnburn Feb 18, 2025
6f81e62
rework sumcheck
rnburn Feb 18, 2025
5b957b4
rework sumchecK
rnburn Feb 18, 2025
8d29a9d
rework sumcheck
rnburn Feb 18, 2025
19db19a
rework sumcheck
rnburn Feb 19, 2025
6981f31
rework reference transcript
rnburn Feb 19, 2025
29a3fc4
fill in reference transcript
rnburn Feb 19, 2025
6b071b3
rework sumcheck
rnburn Feb 19, 2025
2bff522
add tests
rnburn Feb 19, 2025
605b349
rework sumcheck
rnburn Feb 19, 2025
94b94f2
add stub for proof computation
rnburn Feb 19, 2025
80921d8
rework sumcheck
rnburn Feb 19, 2025
704637e
rework sumcheck
rnburn Feb 20, 2025
58763a4
rework cpu driver
rnburn Feb 20, 2025
4ee310a
rework sumcheck
rnburn Feb 20, 2025
d6186d4
rework sumcheck
rnburn Feb 20, 2025
84a29a0
rework sumcheck
rnburn Feb 20, 2025
21b4d9e
rework sumcheck
rnburn Feb 20, 2025
22ebc2f
rework sumcheck
rnburn Feb 20, 2025
15dc8fb
rework sumcheck
rnburn Feb 20, 2025
2efca8c
fill in polynomial utility tests
rnburn Feb 20, 2025
6a61ffe
fill in cpu driver
rnburn Feb 20, 2025
d5574b0
add driver test
rnburn Feb 20, 2025
ce2abd0
fill in cpu driver
rnburn Feb 20, 2025
09a0660
rework sumcheck
rnburn Feb 21, 2025
d73d9e8
rework sumcheck
rnburn Feb 21, 2025
8e992f1
rework sumcheck
rnburn Feb 21, 2025
c21efbe
rework sumcheck
rnburn Feb 21, 2025
d20097e
rework sumcheck
rnburn Feb 21, 2025
5990f59
rework sumcheck
rnburn Feb 21, 2025
d704599
rework sumcheck
rnburn Feb 21, 2025
d79c241
rework sumcheck
rnburn Feb 21, 2025
a629759
rework sumcheck
rnburn Feb 21, 2025
3c3a56b
rework sumcheck
rnburn Feb 21, 2025
8fefe56
rework sumcheck
rnburn Feb 21, 2025
707b826
rework sumcheck
rnburn Feb 21, 2025
0a163c0
rework sumcheck
rnburn Feb 21, 2025
8f39701
rework sumcheck
rnburn Feb 21, 2025
2462a49
rework sumcheck
rnburn Feb 22, 2025
f0548c5
rework sumcheck
rnburn Feb 22, 2025
cc6d388
rework sumcheck
rnburn Feb 22, 2025
0327047
rework sumcheck
rnburn Feb 22, 2025
589043c
rework sumcheck
rnburn Feb 22, 2025
a24c2d9
rework sumcheck
rnburn Feb 22, 2025
3c35207
rework sumcheck
rnburn Feb 22, 2025
80baa5f
rework sumcheck
rnburn Feb 22, 2025
265db5e
rework sumcheck
rnburn Feb 24, 2025
ef1d2e7
add field accumulator
rnburn Feb 24, 2025
43cdbae
rework sumcheck
rnburn Feb 24, 2025
ca68de6
rework sumcheck
rnburn Feb 24, 2025
c6ebaf8
rework sumcheck
rnburn Feb 24, 2025
2f0a952
rework sumcheck
rnburn Feb 24, 2025
f09aab1
rework sumcheck
rnburn Feb 24, 2025
e38643d
rework sumcheck
rnburn Feb 24, 2025
826682a
rework sumcheck
rnburn Feb 24, 2025
5ca3e73
rework sumcheck
rnburn Feb 24, 2025
7712358
rework sumcheck
rnburn Feb 24, 2025
7cf50bc
rework sumcheck
rnburn Feb 24, 2025
6f0b014
rework sumcheck
rnburn Feb 24, 2025
adc44eb
fill in chunked driver
rnburn Feb 24, 2025
8c7958c
rework sumcheck
rnburn Feb 24, 2025
641a6ea
rework sumcheck
rnburn Feb 25, 2025
96e775c
rework sumcheck
rnburn Feb 25, 2025
9223f8c
rework sumcheck
rnburn Feb 25, 2025
dc2f966
reformat
rnburn Feb 25, 2025
9dc06dd
update benchmark
rnburn Feb 25, 2025
e50c455
rework sumcheck
rnburn Feb 25, 2025
913176a
rework sumcheck
rnburn Feb 25, 2025
a0dde1c
rework sumcheck
rnburn Feb 25, 2025
25693c4
rework sumcheck
rnburn Feb 25, 2025
3b9dcba
rework sumcheck
rnburn Feb 26, 2025
ecbde38
rework sumcheck
rnburn Feb 26, 2025
85659b3
rework sumcheck
rnburn Feb 26, 2025
606e38a
rework sumcheck
rnburn Feb 26, 2025
4f236ca
rework sumcheck
rnburn Feb 26, 2025
52d9376
refactor sumcheck
rnburn Feb 26, 2025
81603bd
refactor sumcheck
rnburn Feb 26, 2025
084caf6
refactor
rnburn Feb 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/sumcheck/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ sxt_cc_benchmark(
"//sxt/proof/sumcheck:reference_transcript",
"//sxt/proof/transcript",
"//sxt/scalar25/random:element",
"//sxt/scalar25/type:element",
"//sxt/scalar25/realization:field",
],
)
14 changes: 7 additions & 7 deletions benchmark/sumcheck/benchmark.m.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "sxt/proof/sumcheck/reference_transcript.h"
#include "sxt/proof/transcript/transcript.h"
#include "sxt/scalar25/random/element.h"
#include "sxt/scalar25/type/element.h"
#include "sxt/scalar25/realization/field.h"

using namespace sxt;

Expand Down Expand Up @@ -111,22 +111,22 @@ int main(int argc, char* argv[]) {
memmg::managed_array<s25t::element> polynomials((p.degree + 1u) * num_rounds);
memmg::managed_array<s25t::element> evaluation_point(num_rounds);
prft::transcript base_transcript{"abc123"};
prfsk::reference_transcript transcript{base_transcript};
prfsk::gpu_driver drv;
prfsk::reference_transcript<s25t::element> transcript{base_transcript};
prfsk::gpu_driver<s25t::element> drv;

// initial run
{
auto fut = prfsk::prove_sum(polynomials, evaluation_point, transcript, drv, mles, product_table,
product_terms, p.n);
auto fut = prfsk::prove_sum<s25t::element>(polynomials, evaluation_point, transcript, drv, mles,
product_table, product_terms, p.n);
xens::get_scheduler().run();
}

// sample
double elapse = 0;
for (unsigned i = 0; i < (p.num_samples + 1u); ++i) {
auto t1 = std::chrono::steady_clock::now();
auto fut = prfsk::prove_sum(polynomials, evaluation_point, transcript, drv, mles, product_table,
product_terms, p.n);
auto fut = prfsk::prove_sum<s25t::element>(polynomials, evaluation_point, transcript, drv, mles,
product_table, product_terms, p.n);
xens::get_scheduler().run();
auto t2 = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1);
Expand Down
2 changes: 1 addition & 1 deletion cbindings/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ sxt_cc_component(
"//sxt/base/test:unit_test",
"//sxt/proof/sumcheck:reference_transcript",
"//sxt/scalar25/operation:overload",
"//sxt/scalar25/type:element",
"//sxt/scalar25/realization:field",
"//sxt/scalar25/type:literal",
],
deps = [
Expand Down
10 changes: 5 additions & 5 deletions cbindings/sumcheck.t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
#include "sxt/base/test/unit_test.h"
#include "sxt/proof/sumcheck/reference_transcript.h"
#include "sxt/scalar25/operation/overload.h"
#include "sxt/scalar25/type/element.h"
#include "sxt/scalar25/realization/field.h"
#include "sxt/scalar25/type/literal.h"

using namespace sxt;
using s25t::operator""_s25;

TEST_CASE("we can create sumcheck proofs") {
prft::transcript base_transcript{"abc"};
prfsk::reference_transcript transcript{base_transcript};
prfsk::reference_transcript<s25t::element> transcript{base_transcript};

std::vector<s25t::element> polynomials(2);
std::vector<s25t::element> evaluation_point(1);
Expand All @@ -55,7 +55,7 @@ TEST_CASE("we can create sumcheck proofs") {

auto f = [](s25t::element* r, void* context, const s25t::element* polynomial,
unsigned polynomial_len) noexcept {
static_cast<prfsk::reference_transcript*>(context)->round_challenge(
static_cast<prfsk::reference_transcript<s25t::element>*>(context)->round_challenge(
*r, {polynomial, polynomial_len});
};

Expand All @@ -70,7 +70,7 @@ TEST_CASE("we can create sumcheck proofs") {
REQUIRE(polynomials[1] == mles[1] - mles[0]);
{
prft::transcript base_transcript_p{"abc"};
prfsk::reference_transcript transcript_p{base_transcript_p};
prfsk::reference_transcript<s25t::element> transcript_p{base_transcript_p};
s25t::element r;
transcript_p.round_challenge(r, polynomials);
REQUIRE(evaluation_point[0] == r);
Expand All @@ -88,7 +88,7 @@ TEST_CASE("we can create sumcheck proofs") {
REQUIRE(polynomials[1] == mles[1] - mles[0]);
{
prft::transcript base_transcript_p{"abc"};
prfsk::reference_transcript transcript_p{base_transcript_p};
prfsk::reference_transcript<s25t::element> transcript_p{base_transcript_p};
s25t::element r;
transcript_p.round_challenge(r, polynomials);
REQUIRE(evaluation_point[0] == r);
Expand Down
5 changes: 5 additions & 0 deletions sxt/base/concept/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ sxt_cc_component(
"//sxt/base/test:unit_test",
],
)

sxt_cc_component(
name = "field",
with_test = False,
)
17 changes: 17 additions & 0 deletions sxt/base/concept/field.cc
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 2025-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/base/concept/field.h"
31 changes: 31 additions & 0 deletions sxt/base/concept/field.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU.
*
* Copyright 2025-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

namespace sxt::bascpt {
//--------------------------------------------------------------------------------------------------
// field
//--------------------------------------------------------------------------------------------------
template <class T>
concept field = requires(T& res, const T& e) {
neg(res, e);
add(res, e, e);
sub(res, e, e);
mul(res, e, e);
muladd(res, e, e, e);
};
} // namespace sxt::bascpt
14 changes: 14 additions & 0 deletions sxt/base/field/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ sxt_cc_component(
"//sxt/base/type:narrow_cast",
],
)

sxt_cc_component(
name = "element",
with_test = False,
)

sxt_cc_component(
name = "accumulator",
with_test = False,
deps = [
":element",
"//sxt/base/macro:cuda_callable",
],
)
17 changes: 17 additions & 0 deletions sxt/base/field/accumulator.cc
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 2025-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/base/field/accumulator.h"
31 changes: 31 additions & 0 deletions sxt/base/field/accumulator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU.
*
* Copyright 2025-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 "sxt/base/field/element.h"
#include "sxt/base/macro/cuda_callable.h"

namespace sxt::basfld {
//--------------------------------------------------------------------------------------------------
// accumulator
//--------------------------------------------------------------------------------------------------
template <basfld::element T> struct accumulator {
using value_type = T;

CUDA_CALLABLE static void accumulate_inplace(T& res, T& e) noexcept { add(res, res, e); }
};
} // namespace sxt::basfld
17 changes: 17 additions & 0 deletions sxt/base/field/element.cc
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 2025-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/base/field/element.h"
35 changes: 35 additions & 0 deletions sxt/base/field/element.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU.
*
* Copyright 2025-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 <concepts>

namespace sxt::basfld {
//--------------------------------------------------------------------------------------------------
// element
//--------------------------------------------------------------------------------------------------
template <class T>
concept element = requires(T& res, const T& e) {
neg(res, e);
add(res, e, e);
sub(res, e, e);
mul(res, e, e);
muladd(res, e, e, e);
{ T::identity() } noexcept -> std::same_as<T>;
{ T::one() } noexcept -> std::same_as<T>;
};
} // namespace sxt::basfld
8 changes: 4 additions & 4 deletions sxt/cbindings/backend/callback_sumcheck_transcript.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ namespace sxt::cbnbck {
//--------------------------------------------------------------------------------------------------
// callback_sumcheck_transcript
//--------------------------------------------------------------------------------------------------
class callback_sumcheck_transcript final : public prfsk::sumcheck_transcript {
template <basfld::element T>
class callback_sumcheck_transcript final : public prfsk::sumcheck_transcript<T> {
public:
using callback_t = void (*)(s25t::element* r, void* context, const s25t::element* polynomial,
unsigned polynomial_len);
using callback_t = void (*)(T* r, void* context, const T* polynomial, unsigned polynomial_len);

callback_sumcheck_transcript(callback_t f, void* context) noexcept : f_{f}, context_{context} {}

void init(size_t /*num_variables*/, size_t /*round_degree*/) noexcept override {}

void round_challenge(s25t::element& r, basct::cspan<s25t::element> polynomial) noexcept override {
void round_challenge(T& r, basct::cspan<T> polynomial) noexcept override {
f_(&r, context_, polynomial.data(), static_cast<unsigned>(polynomial.size()));
}

Expand Down
16 changes: 5 additions & 11 deletions sxt/cbindings/backend/cpu_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,12 @@
#include "sxt/proof/transcript/transcript.h"
#include "sxt/ristretto/operation/compression.h"
#include "sxt/ristretto/type/compressed_element.h"
#include "sxt/scalar25/type/element.h"
#include "sxt/seqcommit/generator/precomputed_generators.h"

namespace sxt::cbnbck {
//--------------------------------------------------------------------------------------------------
// prove_sumcheck
//--------------------------------------------------------------------------------------------------
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-parameter"
void cpu_backend::prove_sumcheck(void* polynomials, void* evaluation_point, unsigned field_id,
const cbnb::sumcheck_descriptor& descriptor,
void* transcript_callback, void* transcript_context) noexcept {
Expand All @@ -83,8 +78,8 @@ void cpu_backend::prove_sumcheck(void* polynomials, void* evaluation_point, unsi
static_cast<cbnb::field_id_t>(field_id), [&]<class T>(std::type_identity<T>) noexcept {
static_assert(std::same_as<T, s25t::element>, "only support curve-255 right now");
// transcript
callback_sumcheck_transcript transcript{
reinterpret_cast<callback_sumcheck_transcript::callback_t>(
callback_sumcheck_transcript<T> transcript{
reinterpret_cast<callback_sumcheck_transcript<T>::callback_t>(
const_cast<void*>(transcript_callback)),
transcript_context};

Expand All @@ -109,14 +104,13 @@ void cpu_backend::prove_sumcheck(void* polynomials, void* evaluation_point, unsi
descriptor.product_terms,
descriptor.num_product_terms,
};
prfsk::cpu_driver drv;
prfsk::cpu_driver<T> drv;
auto fut =
prfsk::prove_sum(polynomials_span, evaluation_point_span, transcript, drv, mles_span,
product_table_span, product_terms_span, descriptor.n);
prfsk::prove_sum<T>(polynomials_span, evaluation_point_span, transcript, drv, mles_span,
product_table_span, product_terms_span, descriptor.n);
SXT_RELEASE_ASSERT(fut.ready());
});
}
#pragma clang diagnostic pop

//--------------------------------------------------------------------------------------------------
// compute_commitments
Expand Down
11 changes: 5 additions & 6 deletions sxt/cbindings/backend/gpu_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
#include "sxt/ristretto/operation/compression.h"
#include "sxt/ristretto/type/compressed_element.h"
#include "sxt/ristretto/type/literal.h"
#include "sxt/scalar25/type/element.h"
#include "sxt/seqcommit/generator/precomputed_generators.h"

using sxt::rstt::operator""_rs;
Expand Down Expand Up @@ -112,8 +111,8 @@ void gpu_backend::prove_sumcheck(void* polynomials, void* evaluation_point, unsi
static_cast<cbnb::field_id_t>(field_id), [&]<class T>(std::type_identity<T>) noexcept {
static_assert(std::same_as<T, s25t::element>, "only support curve-255 right now");
// transcript
callback_sumcheck_transcript transcript{
reinterpret_cast<callback_sumcheck_transcript::callback_t>(
callback_sumcheck_transcript<T> transcript{
reinterpret_cast<callback_sumcheck_transcript<T>::callback_t>(
const_cast<void*>(transcript_callback)),
transcript_context};

Expand All @@ -138,10 +137,10 @@ void gpu_backend::prove_sumcheck(void* polynomials, void* evaluation_point, unsi
descriptor.product_terms,
descriptor.num_product_terms,
};
prfsk::chunked_gpu_driver drv;
prfsk::chunked_gpu_driver<T> drv;
auto fut =
prfsk::prove_sum(polynomials_span, evaluation_point_span, transcript, drv, mles_span,
product_table_span, product_terms_span, descriptor.n);
prfsk::prove_sum<T>(polynomials_span, evaluation_point_span, transcript, drv, mles_span,
product_table_span, product_terms_span, descriptor.n);
xens::get_scheduler().run();
});
}
Expand Down
2 changes: 1 addition & 1 deletion sxt/cbindings/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ sxt_cc_component(
deps = [
":field_id",
"//sxt/base/error:panic",
"//sxt/scalar25/type:element",
"//sxt/scalar25/realization:field",
],
)

Expand Down
2 changes: 1 addition & 1 deletion sxt/cbindings/base/field_id_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "sxt/base/error/panic.h"
#include "sxt/cbindings/base/field_id.h"
#include "sxt/scalar25/type/element.h"
#include "sxt/scalar25/realization/field.h"

namespace sxt::cbnb {
//--------------------------------------------------------------------------------------------------
Expand Down
Loading