Skip to content

Commit b17b9da

Browse files
authored
fix crypto formatting (#39)
1 parent 1a2250d commit b17b9da

3 files changed

Lines changed: 26 additions & 69 deletions

File tree

problems/ecc-point-negation/problem.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,23 @@ $$
3737
E: y^2 \equiv x^3 + 7 \pmod{p}, \quad p = 2^{61} - 1.
3838
$$
3939

40-
For each input point \($x_i, y_i$\):
40+
For each input point $(x_i, y_i)$:
4141

4242
$$
4343
(x_i, y_i) \mapsto (x_i,\; (p - y_i) \bmod p).
4444
$$
4545

46+
4647
## Input
4748

48-
- Arrays `xs[i]`, `ys[i]` of length \(N\), each element in \([0, p)\).
49-
- Prime modulus $p = 2^{61} - 1$.
50-
- Batch size \(N\).
49+
- Arrays `xs[i]`, `ys[i]` of length $N$, each element in $[0, p)$
50+
- Prime modulus $p = 2^{61} - 1$
51+
- Batch size $N$
52+
53+
Your kernel must produce the exact negation for every point in the batch.
5154

5255
## Output
5356

54-
- A single array `out_xy` of length \(2N\), storing the results as pairs:
57+
- A single array `out_xy` of length $2N$, storing the results as pairs:
5558
- `out_xy[2*i] = xs[i]`
5659
- `out_xy[2*i + 1] = (p - ys[i]) % p`
57-
58-
## Correctness
59-
60-
Your kernel must produce the exact negation for every point in the batch.

problems/poly-multiply-ff/problem.md

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ $$
5151
c_k = \sum_{i+j=k} a_i \, b_j \pmod{p}
5252
$$
5353

54-
---
55-
5654
## Input
5755

5856
- Two arrays `d_input1`, `d_input2` of length $n$, with values in $[0, p)$.
@@ -62,9 +60,7 @@ $$
6260

6361
- Array `d_output` of length $2n - 1$ with coefficients of $c(x)$ modulo $p$.
6462

65-
---
66-
67-
## Example
63+
## Notes
6864

6965
For small $n=3$:
7066

@@ -81,14 +77,11 @@ $$
8177

8278
So:
8379

84-
a = [1, 2, 3]
85-
b = [4, 5, 6]
86-
→ c = [4, 13, 28, 27, 18]
87-
88-
---
89-
90-
## Naive Baseline
80+
- $a = [1, 2, 3]$
81+
- $b = [4, 5, 6]$
82+
- $c = [4, 13, 28, 27, 18]$
9183

84+
A naive implementation:
9285
```cpp
9386
const uint32_t P = 2147483647u;
9487

@@ -102,15 +95,9 @@ static __host__ __device__ inline uint32_t mul_mod(uint32_t a, uint32_t b) {
10295
return (uint32_t)(prod % P);
10396
}
10497

105-
for (size_t i = 0; i < n; ++i)
106-
for (size_t j = 0; j < n; ++j)
98+
for (size_t i = 0; i < n; ++i) {
99+
for (size_t j = 0; j < n; ++j) {
107100
d_output[i + j] = add_mod(d_output[i + j], mul_mod(d_input1[i], d_input2[j]));
108-
```
109-
110-
## Optimizations to Explore
111-
112-
Shared memory tiling or register blocking for the naive $O(n^2)$ method.
113-
114-
Two-phase accumulation (local tile sums, then global merge).
115-
116-
(Advanced) NTT over moduli with large roots of unity, combined with CRT back to $p$.
101+
}
102+
}
103+
```

problems/vector-multiply-ff/problem.md

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,51 +38,22 @@ $$
3838
p = 2^{31} - 1 = 2147483647
3939
$$
4040

41-
---
42-
4341
## Input
44-
4542
- Vectors `a` and `b` of length $n$, with each element in $[0, p)$.
4643

4744
## Output
48-
4945
- Vector `c` of length $n$ such that:
5046
$$
5147
c_i = a_i \cdot b_i \bmod p
5248
$$
53-
54-
---
55-
56-
## Constraints
57-
49+
50+
## Notes
5851
- $1 \le n \le 2^{30}$
5952
- Inputs and outputs are 32-bit unsigned integers.
6053
- Intermediate products must be reduced modulo $p$.
61-
62-
---
63-
64-
## Baseline Implementation
65-
66-
A simple (correct) implementation:
67-
68-
```cpp
69-
const uint32_t P = 2147483647u;
70-
uint64_t prod = (uint64_t)a[i] * (uint64_t)b[i];
71-
c[i] = (uint32_t)(prod % P);
72-
73-
74-
```
75-
76-
## Optimizations to explore
77-
78-
Optimizations to Explore
79-
80-
- Use Mersenne-friendly reduction for $p = 2^{31} - 1$:
81-
82-
- exploit $2^{31} \equiv 1 \pmod p$ to fold high bits instead of %
83-
84-
- Inline your helpers with **forceinline**
85-
86-
- Fuse multiply-and-reduce to minimize temporaries
87-
88-
- Tune block/thread sizing for occupancy
54+
- A simple (correct) implementation:
55+
```cpp
56+
const uint32_t P = 2147483647u;
57+
uint64_t prod = (uint64_t)a[i] * (uint64_t)b[i];
58+
c[i] = (uint32_t)(prod % P);
59+
```

0 commit comments

Comments
 (0)