Skip to content

Commit 488421b

Browse files
authored
Feat: Blake3 (#733)
1 parent eab9c50 commit 488421b

File tree

27 files changed

+1569
-67
lines changed

27 files changed

+1569
-67
lines changed

.github/workflows/cpp-golang-rust.yml

+59-52
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Spell Check, C++/CUDA/Go/RUST & Examples
1+
name: C++/CUDA/Go/RUST
22

33
on:
44
pull_request:
@@ -31,6 +31,8 @@ jobs:
3131
name: Check Code Format
3232
runs-on: ubuntu-22.04
3333
needs: check-changed-files
34+
container:
35+
image: silkeh/clang:19-bookworm # Replace with a container having the desired clang-format version
3436
steps:
3537
- name: Checkout
3638
uses: actions/checkout@v4
@@ -41,7 +43,9 @@ jobs:
4143
go-version: '1.22.0'
4244
- name: Check clang-format
4345
if: needs.check-changed-files.outputs.cpp == 'true'
44-
run: ./scripts/format_all.sh . --check --exclude "build|wrappers"
46+
run: |
47+
clang-format --version
48+
./scripts/format_all.sh . --check --exclude "build|wrappers"
4549
- name: Check gofmt
4650
if: needs.check-changed-files.outputs.golang == 'true'
4751
run: if [[ $(go list ./... | xargs go fmt) ]]; then echo "Please run go fmt"; exit 1; fi
@@ -82,23 +86,23 @@ jobs:
8286
- name: Checkout Repo
8387
uses: actions/checkout@v4
8488
- name: Checkout CUDA Backend
85-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
89+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true' || needs.check-changed-files.outputs.rust == 'true'
8690
uses: actions/checkout@v4
8791
with:
8892
repository: ingonyama-zk/icicle-cuda-backend
8993
path: ./icicle/backend/cuda
9094
ssh-key: ${{ secrets.CUDA_PULL_KEY }}
9195
ref: ${{ needs.extract-cuda-backend-branch.outputs.cuda-backend-branch }}
9296
- name: Get CUDA Backend Commit SHA
93-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
97+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true' || needs.check-changed-files.outputs.rust == 'true'
9498
working-directory: ./icicle/backend/cuda
9599
id: extract-cuda-sha
96100
run: |
97101
CUDA_BACKEND_SHA=$(git rev-parse HEAD)
98102
echo "CUDA Backend Commit SHA: $CUDA_BACKEND_SHA"
99103
echo "cuda-backend-sha=$CUDA_BACKEND_SHA" >> $GITHUB_OUTPUT
100104
- name: Set CUDA backend flag
101-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
105+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true' || needs.check-changed-files.outputs.rust == 'true'
102106
id: cuda-flag
103107
run: |
104108
CUDA_BACKEND_SHA=${{ steps.extract-cuda-sha.outputs.cuda-backend-sha }}
@@ -136,33 +140,17 @@ jobs:
136140
echo "CMAKE_INSTALL_PREFIX=-DCMAKE_INSTALL_PREFIX=${INSTALL_PATH}" >> $GITHUB_OUTPUT
137141
echo "ICICLE_BACKEND_INSTALL_DIR=${INSTALL_PATH}/lib" >> $GITHUB_OUTPUT
138142
fi
139-
- name: Setup go
140-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
141-
timeout-minutes: 15
142-
uses: actions/setup-go@v5
143-
with:
144-
go-version: '1.22.0'
145143
146144
- name: Build curve
147145
working-directory: ./icicle
148-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
146+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true' || needs.check-changed-files.outputs.rust == 'true'
149147
run: |
150148
mkdir -p build && rm -rf build/*
151149
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON -DCURVE=${{ matrix.curve.name }} ${{ matrix.curve.build_args }} ${{ steps.cuda-flag.outputs.CUDA_FLAG }} ${{ steps.cuda-flag.outputs.CMAKE_INSTALL_PREFIX }} -S . -B build
152150
cmake --build build --target install -j
153151
rm -rf ${{ steps.cuda-flag.outputs.INSTALL_PATH }}/lib/gh_commit_sha_${{ matrix.curve.name }}*
154152
touch ${{ steps.cuda-flag.outputs.COMMIT_FILE_PATH }}
155-
- name: Run RUST Curve Tests
156-
working-directory: ./wrappers/rust/icicle-curves
157-
if: needs.check-changed-files.outputs.rust == 'true' || needs.check-changed-files.outputs.cpp == 'true'
158-
run: |
159-
CURVE=${{ matrix.curve.name }}
160-
CURVE_DIR=icicle-${CURVE//_/-}
161-
export ICICLE_BACKEND_INSTALL_DIR=${{ steps.cuda-flag.outputs.INSTALL_PATH }}
162-
cd ./$CURVE_DIR
163-
cargo test --release --verbose -- --skip phase
164-
cargo test phase2 --release
165-
cargo test phase3 --release
153+
166154
- name: Run C++ Curve Tests
167155
working-directory: ./icicle/build/tests
168156
if: needs.check-changed-files.outputs.cpp == 'true'
@@ -183,6 +171,23 @@ jobs:
183171
cd -
184172
fi
185173
done
174+
- name: Run RUST Curve Tests
175+
working-directory: ./wrappers/rust/icicle-curves
176+
if: needs.check-changed-files.outputs.rust == 'true' || needs.check-changed-files.outputs.cpp == 'true'
177+
run: |
178+
CURVE=${{ matrix.curve.name }}
179+
CURVE_DIR=icicle-${CURVE//_/-}
180+
export ICICLE_BACKEND_INSTALL_DIR=${{ steps.cuda-flag.outputs.INSTALL_PATH }}
181+
cd ./$CURVE_DIR
182+
cargo test --release --verbose -- --skip phase
183+
cargo test phase2 --release
184+
cargo test phase3 --release
185+
- name: Setup go
186+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
187+
timeout-minutes: 15
188+
uses: actions/setup-go@v5
189+
with:
190+
go-version: '1.22.0'
186191
- name: Run Golang curve Tests
187192
working-directory: ./wrappers/golang/curves
188193
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
@@ -214,23 +219,23 @@ jobs:
214219
- name: Checkout Repo
215220
uses: actions/checkout@v4
216221
- name: Checkout CUDA Backend
217-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
222+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true' || needs.check-changed-files.outputs.rust == 'true'
218223
uses: actions/checkout@v4
219224
with:
220225
repository: ingonyama-zk/icicle-cuda-backend
221226
path: ./icicle/backend/cuda
222227
ssh-key: ${{ secrets.CUDA_PULL_KEY }}
223228
ref: ${{ needs.extract-cuda-backend-branch.outputs.cuda-backend-branch }}
224229
- name: Get CUDA Backend Commit SHA
225-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
230+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true' || needs.check-changed-files.outputs.rust == 'true'
226231
working-directory: ./icicle/backend/cuda
227232
id: extract-cuda-sha
228233
run: |
229234
CUDA_BACKEND_SHA=$(git rev-parse HEAD)
230235
echo "CUDA Backend Commit SHA: $CUDA_BACKEND_SHA"
231236
echo "cuda-backend-sha=$CUDA_BACKEND_SHA" >> $GITHUB_OUTPUT
232237
- name: Set CUDA backend flag
233-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
238+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true' || needs.check-changed-files.outputs.rust == 'true'
234239
id: cuda-flag
235240
run: |
236241
CUDA_BACKEND_SHA=${{ steps.extract-cuda-sha.outputs.cuda-backend-sha }}
@@ -268,12 +273,6 @@ jobs:
268273
echo "CMAKE_INSTALL_PREFIX=-DCMAKE_INSTALL_PREFIX=${INSTALL_PATH}" >> $GITHUB_OUTPUT
269274
echo "ICICLE_BACKEND_INSTALL_DIR=${INSTALL_PATH}/lib" >> $GITHUB_OUTPUT
270275
fi
271-
- name: Setup go
272-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
273-
timeout-minutes: 15
274-
uses: actions/setup-go@v5
275-
with:
276-
go-version: '1.22.0'
277276
278277
- name: Build field
279278
working-directory: ./icicle
@@ -284,17 +283,7 @@ jobs:
284283
cmake --build build --target install -j
285284
rm -rf ${{ steps.cuda-flag.outputs.INSTALL_PATH }}/lib/gh_commit_sha_${{ matrix.field.name }}*
286285
touch ${{ steps.cuda-flag.outputs.COMMIT_FILE_PATH }}
287-
- name: Run RUST Field Tests
288-
working-directory: ./wrappers/rust/icicle-fields
289-
if: needs.check-changed-files.outputs.rust == 'true' || needs.check-changed-files.outputs.cpp == 'true'
290-
run: |
291-
FIELD=${{ matrix.field.name }}
292-
FIELD_DIR=icicle-${FIELD//_/-}
293-
export ICICLE_BACKEND_INSTALL_DIR=${{ steps.cuda-flag.outputs.INSTALL_PATH }}
294-
cd ./$FIELD_DIR
295-
cargo test --release --verbose -- --skip phase
296-
cargo test phase2 --release
297-
cargo test phase3 --release
286+
298287
- name: Run C++ field Tests
299288
working-directory: ./icicle/build/tests
300289
if: needs.check-changed-files.outputs.cpp == 'true'
@@ -317,6 +306,24 @@ jobs:
317306
fi
318307
done
319308
309+
- name: Run RUST Field Tests
310+
working-directory: ./wrappers/rust/icicle-fields
311+
if: needs.check-changed-files.outputs.rust == 'true' || needs.check-changed-files.outputs.cpp == 'true'
312+
run: |
313+
FIELD=${{ matrix.field.name }}
314+
FIELD_DIR=icicle-${FIELD//_/-}
315+
export ICICLE_BACKEND_INSTALL_DIR=${{ steps.cuda-flag.outputs.INSTALL_PATH }}
316+
cd ./$FIELD_DIR
317+
cargo test --release --verbose -- --skip phase
318+
cargo test phase2 --release
319+
cargo test phase3 --release
320+
321+
- name: Setup go
322+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
323+
timeout-minutes: 15
324+
uses: actions/setup-go@v5
325+
with:
326+
go-version: '1.22.0'
320327
- name: Run Golang field Tests
321328
working-directory: ./wrappers/golang/fields
322329
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
@@ -343,23 +350,23 @@ jobs:
343350
- name: Checkout Repo
344351
uses: actions/checkout@v4
345352
- name: Checkout CUDA Backend
346-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
353+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true' || needs.check-changed-files.outputs.rust == 'true'
347354
uses: actions/checkout@v4
348355
with:
349356
repository: ingonyama-zk/icicle-cuda-backend
350357
path: ./icicle/backend/cuda
351358
ssh-key: ${{ secrets.CUDA_PULL_KEY }}
352359
ref: ${{ needs.extract-cuda-backend-branch.outputs.cuda-backend-branch }}
353360
- name: Get CUDA Backend Commit SHA
354-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
361+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true' || needs.check-changed-files.outputs.rust == 'true'
355362
working-directory: ./icicle/backend/cuda
356363
id: extract-cuda-sha
357364
run: |
358365
CUDA_BACKEND_SHA=$(git rev-parse HEAD)
359366
echo "CUDA Backend Commit SHA: $CUDA_BACKEND_SHA"
360367
echo "cuda-backend-sha=$CUDA_BACKEND_SHA" >> $GITHUB_OUTPUT
361368
- name: Set CUDA backend flag
362-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
369+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true' || needs.check-changed-files.outputs.rust == 'true'
363370
id: cuda-flag
364371
run: |
365372
CUDA_BACKEND_SHA=${{ steps.extract-cuda-sha.outputs.cuda-backend-sha }}
@@ -396,12 +403,6 @@ jobs:
396403
echo "CMAKE_INSTALL_PREFIX=-DCMAKE_INSTALL_PREFIX=${INSTALL_PATH}" >> $GITHUB_OUTPUT
397404
echo "ICICLE_BACKEND_INSTALL_DIR=${INSTALL_PATH}/lib" >> $GITHUB_OUTPUT
398405
fi
399-
- name: Setup go
400-
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
401-
timeout-minutes: 15
402-
uses: actions/setup-go@v5
403-
with:
404-
go-version: '1.22.0'
405406
- name: Build
406407
working-directory: ./icicle
407408
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
@@ -420,6 +421,12 @@ jobs:
420421
cargo test --release --verbose -- --skip phase
421422
cargo test phase2 --release
422423
cargo test phase3 --release
424+
- name: Setup go
425+
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'
426+
timeout-minutes: 15
427+
uses: actions/setup-go@v5
428+
with:
429+
go-version: '1.22.0'
423430
- name: Test GoLang Hashes
424431
working-directory: ./wrappers/golang/hash
425432
if: needs.check-changed-files.outputs.golang == 'true' || needs.check-changed-files.outputs.cpp == 'true'

docs/docs/icicle/libraries.md

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Each library has a corresponding crate. See [programmers guide](./programmers_gu
5353
| [Keccak](primitives/hash#keccak-and-sha3) | supporting 256b and 512b digest |
5454
| [SHA3](primitives/hash#keccak-and-sha3) | supporting 256b and 512b digest |
5555
| [Blake2s](primitives/hash#blake2s) | digest is 256b |
56+
| [Blake3](primitives/hash#blake3) | digest is 256b |
5657
| [Merkle-Tree](primitives/merkle) | works with any combination of hash functions |
5758

5859

docs/docs/icicle/primitives/hash.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ ICICLE supports the following hash functions:
2323
3. **SHA3-256**
2424
4. **SHA3-512**
2525
5. **Blake2s**
26-
6. **Poseidon**
27-
7. **Poseidon2**
26+
6. **Blake3**
27+
7. **Poseidon**
28+
8. **Poseidon2**
2829

2930
:::info
3031
Additional hash functions might be added in the future. Stay tuned!
@@ -40,6 +41,10 @@ Keccak can take input messages of any length and produce a fixed-size hash. It u
4041

4142
[Blake2s](https://www.rfc-editor.org/rfc/rfc7693.txt) is an optimized cryptographic hash function that provides high performance while ensuring strong security. Blake2s is ideal for hashing small data (such as field elements), especially when speed is crucial. It produces a 256-bit (32-byte) output and is often used in cryptographic protocols.
4243

44+
### Blake3
45+
46+
[Blake3](https://www.ietf.org/archive/id/draft-aumasson-blake3-00.html) is a high-performance cryptographic hash function designed for both small and large data. With a a tree-based design for efficient parallelism, it offers strong security, speed, and scalability for modern cryptographic applications.
47+
4348
### Poseidon
4449

4550
[Poseidon](https://eprint.iacr.org/2019/458) is a cryptographic hash function designed specifically for field elements. It is highly optimized for zero-knowledge proofs (ZKPs) and is commonly used in ZK-SNARK systems. Poseidon’s main strength lies in its arithmetization-friendly design, meaning it can be efficiently expressed as arithmetic constraints within a ZK-SNARK circuit.

examples/c++/best-practice-ntt/example.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ int main(int argc, char* argv[])
116116
// Clean-up
117117
for (int i = 0; i < 2; i++) {
118118
ICICLE_CHECK(icicle_free(d_vec[i]));
119-
delete[](h_inp[i]);
120-
delete[](h_out[i]);
119+
delete[] (h_inp[i]);
120+
delete[] (h_out[i]);
121121
}
122122
ICICLE_CHECK(icicle_destroy_stream(stream_compute));
123123
ICICLE_CHECK(icicle_destroy_stream(stream_d2h));

icicle/backend/cpu/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ if (HASH)
6767
target_sources(icicle_hash PRIVATE
6868
src/hash/cpu_keccak.cpp
6969
src/hash/cpu_blake2s.cpp
70+
src/hash/cpu_blake3.cpp
71+
src/hash/blake3.c
72+
src/hash/blake3_dispatch.c
73+
src/hash/blake3_portable.c
7074
src/hash/cpu_merkle_tree.cpp
7175
)
7276
target_include_directories(icicle_hash PUBLIC include)

icicle/backend/cpu/src/field/cpu_vec_ops.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class VectorOpTask : public TaskBase
372372
public:
373373
T m_intermidiate_res; // pointer to the output. Can be a vector or scalar pointer
374374
uint64_t m_idx_in_batch; // index in the batch. Used in intermediate res tasks
375-
};
375+
}; // class VectorOpTask
376376

377377
#define NOF_OPERATIONS_PER_TASK 512
378378
#define CONFIG_NOF_THREADS_KEY "n_threads"

0 commit comments

Comments
 (0)