Skip to content

Commit 137f1e8

Browse files
authored
feat: make sumcheck generic (PROOF-913) (#247)
* add field concept * fill in field concept * fill in field concept * rework * rework sumcheck * rework sumcheck * rework sumcheck * rework sumchecK * rework sumcheck * rework sumcheck * rework reference transcript * fill in reference transcript * rework sumcheck * add tests * rework sumcheck * add stub for proof computation * rework sumcheck * rework sumcheck * rework cpu driver * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * fill in polynomial utility tests * fill in cpu driver * add driver test * fill in cpu driver * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * add field accumulator * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * fill in chunked driver * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * reformat * update benchmark * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * rework sumcheck * refactor sumcheck * refactor sumcheck * refactor
1 parent 0e59204 commit 137f1e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1788
-1899
lines changed

benchmark/sumcheck/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ sxt_cc_benchmark(
1919
"//sxt/proof/sumcheck:reference_transcript",
2020
"//sxt/proof/transcript",
2121
"//sxt/scalar25/random:element",
22-
"//sxt/scalar25/type:element",
22+
"//sxt/scalar25/realization:field",
2323
],
2424
)

benchmark/sumcheck/benchmark.m.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "sxt/proof/sumcheck/reference_transcript.h"
3333
#include "sxt/proof/transcript/transcript.h"
3434
#include "sxt/scalar25/random/element.h"
35-
#include "sxt/scalar25/type/element.h"
35+
#include "sxt/scalar25/realization/field.h"
3636

3737
using namespace sxt;
3838

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

117117
// initial run
118118
{
119-
auto fut = prfsk::prove_sum(polynomials, evaluation_point, transcript, drv, mles, product_table,
120-
product_terms, p.n);
119+
auto fut = prfsk::prove_sum<s25t::element>(polynomials, evaluation_point, transcript, drv, mles,
120+
product_table, product_terms, p.n);
121121
xens::get_scheduler().run();
122122
}
123123

124124
// sample
125125
double elapse = 0;
126126
for (unsigned i = 0; i < (p.num_samples + 1u); ++i) {
127127
auto t1 = std::chrono::steady_clock::now();
128-
auto fut = prfsk::prove_sum(polynomials, evaluation_point, transcript, drv, mles, product_table,
129-
product_terms, p.n);
128+
auto fut = prfsk::prove_sum<s25t::element>(polynomials, evaluation_point, transcript, drv, mles,
129+
product_table, product_terms, p.n);
130130
xens::get_scheduler().run();
131131
auto t2 = std::chrono::steady_clock::now();
132132
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1);

cbindings/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ sxt_cc_component(
226226
"//sxt/base/test:unit_test",
227227
"//sxt/proof/sumcheck:reference_transcript",
228228
"//sxt/scalar25/operation:overload",
229-
"//sxt/scalar25/type:element",
229+
"//sxt/scalar25/realization:field",
230230
"//sxt/scalar25/type:literal",
231231
],
232232
deps = [

cbindings/sumcheck.t.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
#include "sxt/base/test/unit_test.h"
2323
#include "sxt/proof/sumcheck/reference_transcript.h"
2424
#include "sxt/scalar25/operation/overload.h"
25-
#include "sxt/scalar25/type/element.h"
25+
#include "sxt/scalar25/realization/field.h"
2626
#include "sxt/scalar25/type/literal.h"
2727

2828
using namespace sxt;
2929
using s25t::operator""_s25;
3030

3131
TEST_CASE("we can create sumcheck proofs") {
3232
prft::transcript base_transcript{"abc"};
33-
prfsk::reference_transcript transcript{base_transcript};
33+
prfsk::reference_transcript<s25t::element> transcript{base_transcript};
3434

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

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

@@ -70,7 +70,7 @@ TEST_CASE("we can create sumcheck proofs") {
7070
REQUIRE(polynomials[1] == mles[1] - mles[0]);
7171
{
7272
prft::transcript base_transcript_p{"abc"};
73-
prfsk::reference_transcript transcript_p{base_transcript_p};
73+
prfsk::reference_transcript<s25t::element> transcript_p{base_transcript_p};
7474
s25t::element r;
7575
transcript_p.round_challenge(r, polynomials);
7676
REQUIRE(evaluation_point[0] == r);
@@ -88,7 +88,7 @@ TEST_CASE("we can create sumcheck proofs") {
8888
REQUIRE(polynomials[1] == mles[1] - mles[0]);
8989
{
9090
prft::transcript base_transcript_p{"abc"};
91-
prfsk::reference_transcript transcript_p{base_transcript_p};
91+
prfsk::reference_transcript<s25t::element> transcript_p{base_transcript_p};
9292
s25t::element r;
9393
transcript_p.round_challenge(r, polynomials);
9494
REQUIRE(evaluation_point[0] == r);

sxt/base/concept/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ sxt_cc_component(
99
"//sxt/base/test:unit_test",
1010
],
1111
)
12+
13+
sxt_cc_component(
14+
name = "field",
15+
with_test = False,
16+
)

sxt/base/concept/field.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU.
2+
*
3+
* Copyright 2025-present Space and Time Labs, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "sxt/base/concept/field.h"

sxt/base/concept/field.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU.
2+
*
3+
* Copyright 2025-present Space and Time Labs, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#pragma once
18+
19+
namespace sxt::bascpt {
20+
//--------------------------------------------------------------------------------------------------
21+
// field
22+
//--------------------------------------------------------------------------------------------------
23+
template <class T>
24+
concept field = requires(T& res, const T& e) {
25+
neg(res, e);
26+
add(res, e, e);
27+
sub(res, e, e);
28+
mul(res, e, e);
29+
muladd(res, e, e, e);
30+
};
31+
} // namespace sxt::bascpt

sxt/base/field/BUILD

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,17 @@ sxt_cc_component(
1414
"//sxt/base/type:narrow_cast",
1515
],
1616
)
17+
18+
sxt_cc_component(
19+
name = "element",
20+
with_test = False,
21+
)
22+
23+
sxt_cc_component(
24+
name = "accumulator",
25+
with_test = False,
26+
deps = [
27+
":element",
28+
"//sxt/base/macro:cuda_callable",
29+
],
30+
)

sxt/base/field/accumulator.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU.
2+
*
3+
* Copyright 2025-present Space and Time Labs, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "sxt/base/field/accumulator.h"

sxt/base/field/accumulator.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/** Proofs GPU - Space and Time's cryptographic proof algorithms on the CPU and GPU.
2+
*
3+
* Copyright 2025-present Space and Time Labs, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#pragma once
18+
19+
#include "sxt/base/field/element.h"
20+
#include "sxt/base/macro/cuda_callable.h"
21+
22+
namespace sxt::basfld {
23+
//--------------------------------------------------------------------------------------------------
24+
// accumulator
25+
//--------------------------------------------------------------------------------------------------
26+
template <basfld::element T> struct accumulator {
27+
using value_type = T;
28+
29+
CUDA_CALLABLE static void accumulate_inplace(T& res, T& e) noexcept { add(res, res, e); }
30+
};
31+
} // namespace sxt::basfld

0 commit comments

Comments
 (0)