Skip to content

Commit 04cf201

Browse files
author
Ryan Kim
authored
Merge pull request #340 from kroma-network/build/use-ffiasm
build: use ffiasm to produce x86 assembly of prime fields
2 parents 19abab9 + 5a414e4 commit 04cf201

File tree

80 files changed

+1292
-2761
lines changed

Some content is hidden

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

80 files changed

+1292
-2761
lines changed

.bazelrc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ build:cuda --define absl=0
8484
# gmp needs exception.
8585
build --//:has_exception
8686

87-
# Enable polygon zkevm backend for prime field.
88-
build:polygon_zkevm_backend --//:polygon_zkevm_backend
89-
9087
test --test_tag_filters -benchmark,-manual,-cuda,-rust
9188

9289
build:linux --build_tag_filters -objc,-cuda,-rust

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ jobs:
3636
run: sudo apt-get install -y libomp-dev
3737

3838
- name: Build
39-
run: bazel build -c fastbuild --config ${{ matrix.bazel_config }} //...
39+
# NOTE(chokobole): Since https://github.com/kroma-network/tachyon/pull/340, fastbuild config on mac fails.
40+
run: bazel build -c dbg --config ${{ matrix.bazel_config }} //...
4041

4142
- name: Test Tachyon
42-
run: bazel test -c fastbuild --config ${{ matrix.bazel_config }} --test_output=errors --test_tag_filters -benchmark,-manual,-cuda //...
43+
# NOTE(chokobole): Since https://github.com/kroma-network/tachyon/pull/340, fastbuild config on mac fails.
44+
run: bazel test -c dbg --config ${{ matrix.bazel_config }} --test_output=errors --test_tag_filters -benchmark,-manual,-cuda //...
4345

4446
- name: Test OpenMP
4547
if: matrix.os == 'ubuntu-latest'

BUILD.bazel

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
load("@bazel_skylib//lib:selects.bzl", "selects")
21
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
32
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
43

@@ -34,12 +33,6 @@ bool_flag(
3433
build_setting_default = False,
3534
)
3635

37-
# prime field backend
38-
bool_flag(
39-
name = "polygon_zkevm_backend",
40-
build_setting_default = False,
41-
)
42-
4336
bool_flag(
4437
name = "has_matplotlib",
4538
build_setting_default = False,
@@ -143,11 +136,6 @@ config_setting(
143136
flag_values = {":has_openmp": "true"},
144137
)
145138

146-
config_setting(
147-
name = "tachyon_polygon_zkevm_backend",
148-
flag_values = {":polygon_zkevm_backend": "true"},
149-
)
150-
151139
config_setting(
152140
name = "tachyon_has_matplotlib",
153141
flag_values = {":has_matplotlib": "true"},
@@ -168,14 +156,6 @@ config_setting(
168156
flag_values = {"node_binding": "true"},
169157
)
170158

171-
selects.config_setting_group(
172-
name = "x86_64_and_polygon_zkevm",
173-
match_all = [
174-
"@platforms//cpu:x86_64",
175-
"@kroma_network_tachyon//:tachyon_polygon_zkevm_backend",
176-
],
177-
)
178-
179159
buildifier(
180160
name = "buildifier",
181161
)

WORKSPACE

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,41 @@ pybind11_deps()
8282
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
8383

8484
rules_pkg_dependencies()
85+
86+
# Start of rules_js
87+
load("//bazel:js_deps.bzl", "js_deps")
88+
89+
js_deps()
90+
91+
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
92+
93+
rules_js_dependencies()
94+
95+
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")
96+
97+
aspect_bazel_lib_dependencies()
98+
99+
# Fetch and register node, if you haven't already
100+
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
101+
102+
nodejs_register_toolchains(
103+
name = "nodejs",
104+
node_version = DEFAULT_NODE_VERSION,
105+
)
106+
107+
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")
108+
109+
npm_translate_lock(
110+
name = "npm",
111+
data = ["@iden3_ffiasm//:package.json"],
112+
npm_package_lock = "@iden3_ffiasm//:package-lock.json",
113+
pnpm_lock = "@iden3_ffiasm//:pnpm-lock.yaml",
114+
update_pnpm_lock = True,
115+
verify_node_modules_ignored = "@iden3_ffiasm//:.bazelignore",
116+
)
117+
118+
load("@npm//:repositories.bzl", "npm_repositories")
119+
120+
npm_repositories()
121+
122+
# End of rules_js

bazel/js_deps.bzl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
3+
def js_deps():
4+
if not native.existing_rule("aspect_bazel_lib"):
5+
http_archive(
6+
name = "aspect_bazel_lib",
7+
sha256 = "262e3d6693cdc16dd43880785cdae13c64e6a3f63f75b1993c716295093d117f",
8+
strip_prefix = "bazel-lib-1.38.1",
9+
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.38.1/bazel-lib-v1.38.1.tar.gz",
10+
)
11+
12+
if not native.existing_rule("aspect_rules_js"):
13+
http_archive(
14+
name = "aspect_rules_js",
15+
sha256 = "d9ceb89e97bb5ad53b278148e01a77a3e9100db272ce4ebdcd59889d26b9076e",
16+
strip_prefix = "rules_js-1.34.0",
17+
url = "https://github.com/aspect-build/rules_js/releases/download/v1.34.0/rules_js-v1.34.0.tar.gz",
18+
)
19+
20+
if not native.existing_rule("rules_nodejs"):
21+
http_archive(
22+
name = "rules_nodejs",
23+
sha256 = "a50986c7d2f2dc43a5b9b81a6245fd89bdc4866f1d5e316d9cef2782dd859292",
24+
strip_prefix = "rules_nodejs-6.0.5",
25+
url = "https://github.com/bazelbuild/rules_nodejs/releases/download/v6.0.5/rules_nodejs-v6.0.5.tar.gz",
26+
)

bazel/tachyon.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,27 @@ def if_has_openmp(a, b = []):
9494
"//conditions:default": b,
9595
})
9696

97-
def if_polygon_zkevm_backend(a, b = []):
97+
def if_has_matplotlib(a, b = []):
9898
return select({
99-
"@kroma_network_tachyon//:tachyon_polygon_zkevm_backend": a,
99+
"@kroma_network_tachyon//:tachyon_has_matplotlib": a,
100100
"//conditions:default": b,
101101
})
102102

103-
def if_x86_64_and_polygon_zkevm_backend(a, b = []):
103+
def if_has_numa(a, b = []):
104104
return select({
105-
"@kroma_network_tachyon//:x86_64_and_polygon_zkevm": a,
105+
"@kroma_network_tachyon//:tachyon_has_numa": a,
106106
"//conditions:default": b,
107107
})
108108

109-
def if_has_matplotlib(a, b = []):
109+
def if_c_shared_object(a, b = []):
110110
return select({
111-
"@kroma_network_tachyon//:tachyon_has_matplotlib": a,
111+
"@kroma_network_tachyon//:tachyon_c_shared_object": a,
112112
"//conditions:default": b,
113113
})
114114

115-
def if_has_numa(a, b = []):
115+
def if_cc_shared_object(a, b = []):
116116
return select({
117-
"@kroma_network_tachyon//:tachyon_has_numa": a,
117+
"@kroma_network_tachyon//:tachyon_cc_shared_object": a,
118118
"//conditions:default": b,
119119
})
120120

bazel/tachyon_cc.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library")
21
load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library", "if_cuda")
2+
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library")
33
load(
44
"//bazel:tachyon.bzl",
55
"if_has_exception",

bazel/tachyon_deps.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22
load("//third_party/eigen3:workspace.bzl", eigen3 = "repo")
33
load("//third_party/env:env_configure.bzl", "env_configure")
4+
load("//third_party/ffiasm:workspace.bzl", ffiasm = "repo")
45
load("//third_party/gmp:gmp_configure.bzl", "gmp_configure")
6+
load("//third_party/goldilocks:workspace.bzl", goldilocks = "repo")
57
load("//third_party/gpus:cuda_configure.bzl", "cuda_configure")
68
load("//third_party/gpus:rocm_configure.bzl", "rocm_configure")
79
load("//third_party/hwloc:workspace.bzl", hwloc = "repo")
810
load("//third_party/nasm:workspace.bzl", nasm = "repo")
911
load("//third_party/node_addon_api:install_node_addon_api.bzl", "install_node_addon_api")
1012
load("//third_party/pdqsort:workspace.bzl", pdqsort = "repo")
11-
load("//third_party/polygon_zkevm/goldilocks:workspace.bzl", goldilocks = "repo")
12-
load("//third_party/polygon_zkevm/zkevm_prover:workspace.bzl", zkevm_prover = "repo")
1313
load("//third_party/py:python_configure.bzl", "python_configure")
1414

1515
def tachyon_deps():
@@ -20,11 +20,11 @@ def tachyon_deps():
2020
python_configure(name = "local_config_python")
2121

2222
eigen3()
23+
ffiasm()
2324
goldilocks()
2425
hwloc()
2526
nasm()
2627
pdqsort()
27-
zkevm_prover()
2828

2929
install_node_addon_api(name = "node_addon_api")
3030

docs/how_to_contribute/math/how_to_add_prime_fields.md

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Begin by creating a directory named `<new_prime_field>_prime` in `/tachyon/math/
1010

1111
Choose among `generate_prime_fields()`, `generate_fft_prime_fields()`, or `generate_large_fft_prime_fields()` for code generation, depending on the prime field type. For more information, refer to [`prime_field_generator`](/tachyon/math/finite_fields/generator/prime_field_generator/build_defs.bzl).
1212

13-
For instance, to implement a FFT prime field, create a directory (`/tachyon/math/finite_field/<new_prime_field>`) and add a `BUILD.bazel` file as shown below:
13+
For instance, to implement a FFT prime field, create a directory (`/tachyon/math/finite_fields/<new_prime_field>`) and add a `BUILD.bazel` file as shown below:
1414

1515
```bazel
16-
# /tachyon/math/finite_field/<new_prime_field>/BUILD.bazel
16+
# /tachyon/math/finite_fields/<new_prime_field>/BUILD.bazel
1717

1818
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
1919
load("//bazel:tachyon_cc.bzl", "tachyon_cc_library")
@@ -26,7 +26,7 @@ load(
2626
package(default_visibility = ["//visibility:public"])
2727

2828
string_flag(
29-
name = "fr_" + SUBGROUP_GENERATOR,
29+
name = SUBGROUP_GENERATOR,
3030
build_setting_default = "{subgroup_generator}", # input Subgroup generator value
3131
)
3232

@@ -35,42 +35,23 @@ generate_fft_prime_fields( # NOTE: Choose generator type
3535
class_name = "NewPrimeField",
3636
modulus = "{modulus_value}", # input modulus value
3737
namespace = "tachyon::math",
38-
subgroup_generator = ":fr_" + SUBGROUP_GENERATOR,
39-
)
40-
41-
tachyon_cc_library(
42-
name = "prime_field_<new_prime_field>",
43-
hdrs = ["prime_field_<new_prime_field>.h"],
44-
defines = ["TACHYON_POLYGON_ZKEVM_BACKEND"],
45-
deps = [
46-
"//tachyon/math/base/gmp:gmp_util",
47-
"//tachyon/math/finite_fields:prime_field_base",
48-
],
38+
subgroup_generator = ":" + SUBGROUP_GENERATOR,
4939
)
5040
```
5141

5242
Use the following files for reference:
5343

54-
- [Goldilocks `Build.bazel`](/tachyon/math/finite_fields/goldilocks_prime/BUILD.bazel)
55-
- [Mersenne-31 `BUILD.bazel`](/tachyon/math/finite_fields/mersenne_31_prime/BUILD.bazel)
56-
57-
## 2. Add the header file
58-
59-
Next, implement the logic for the new prime field in a header file named `prime_field_<prime_field_name>.h`. The code will then be generated in `bazel-bin/tachyon/math/finite_fields/<new_prime_field_dir>/<prime_field_name>.h` when Bazel builds the correlating target.
60-
61-
Use the following files for reference:
62-
63-
- [`prime_field_goldilocks.h`](/tachyon/math/finite_fields/goldilocks_prime/prime_field_goldilocks.h)
64-
- [`prime_field_mersenne_31.h`](/tachyon/math/finite_fields/mersenne_31_prime/prime_field_mersenne_31.h)
44+
- [Goldilocks `BUILD.bazel`](/tachyon/math/finite_fields/goldilocks/BUILD.bazel)
45+
- [Mersenne31 `BUILD.bazel`](/tachyon/math/finite_fields/mersenne31/BUILD.bazel)
6546

66-
## 3. Add to `prime_field_generator_unittest.cc`
47+
## 2. Add to `prime_field_generator_unittest.cc`
6748

6849
Finally, ensure the prime field works well by incorporating it into `prime_field_generator_unittest.cc` at the two points shown below:
6950

7051
```cpp
7152
...
72-
#include "tachyon/math/finite_fields/goldilocks_prime/goldilocks.h"
73-
#include "tachyon/math/finite_fields/mersenne_31_prime/mersenne_31.h"
53+
#include "tachyon/math/finite_fields/goldilocks/goldilocks_prime_field.h"
54+
#include "tachyon/math/finite_fields/mersenne31/mersenne31.h"
7455
// ADD NEW PRIME FIELD HEADER FILE HERE
7556
// #include "tachyon/math/finite_fields/..."
7657
...

docs/how_to_use/how_to_build.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,6 @@ bazel build --config macos_arm64 //...
112112
bazel build --config macos_arm64 --config dbg //...
113113
```
114114

115-
### Polygon zkEVM backend prime field
116-
117-
_NOTE_: Only x86_64 is supported.
118-
119-
- `--//:polygon_zkevm_backend`: Enable [goldilocks](https://github.com/0xPolygonHermez/goldilocks) and [zkevm-prover](https://github.com/0xPolygonHermez/zkevm-prover) prime field backend.
120-
121-
```shell
122-
bazel build --config ${os} --config avx512_${os} --//:polygon_zkevm_backend //...
123-
```
124-
125115
### Hardware acceleration
126116

127117
#### CUDA backend
@@ -156,13 +146,12 @@ For example:
156146
157147
build --config linux
158148
build --config dbg
159-
build --config polygon_zkevm_backend
160149
```
161150

162151
```shell
163152
bazel build //...
164153
# With the preset options in .bazelrc.user, this is the same as:
165-
# bazel build --config linux --config dbg --config polygon_zkevm_backend //...
154+
# bazel build --config linux --config dbg //...
166155
```
167156

168157
## Building Tachyon from a Bazel repository
@@ -180,7 +169,7 @@ shasum -a 256 c6a38895cb6f9b9f73e3d64928d85a9762b66639.tar.gz
180169
Second, input the shasum output into your `WORKSPACE` file as the `sha256` argument like shown below:
181170

182171
```bzl
183-
# WORKSPACE
172+
# WORKSPACE
184173

185174
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
186175
http_archive(
@@ -194,11 +183,11 @@ http_archive(
194183
## Debian packaging
195184

196185
Build a Debian package with the supported scheme (only halo2 for now) and the [options](#options) you want.
197-
To build the Halo2 Debian package, `polygon_zkevm_backend` and `has_openmp` options are recommended. Run the following commands:
186+
To build the Halo2 Debian package, `halo2` and `has_openmp` options are recommended. Run the following commands:
198187

199188
```shell
200-
bazel build -c opt --config halo2 --//:polygon_zkevm_backend --//:has_openmp --//:c_shared_object //scripts/packages/debian/runtime:debian
201-
bazel build -c opt --config halo2 --//:polygon_zkevm_backend --//:has_openmp --//:c_shared_object //scripts/packages/debian/dev:debian
189+
bazel build -c opt --config halo2 --//:has_openmp --//:c_shared_object //scripts/packages/debian/runtime:debian
190+
bazel build -c opt --config halo2 --//:has_openmp --//:c_shared_object //scripts/packages/debian/dev:debian
202191

203192
sudo dpkg -i bazel-bin/scripts/packages/debian/runtime/libtachyon_0.0.1_amd64.deb
204193
sudo dpkg -i bazel-bin/scripts/packages/debian/dev/libtachyon-dev_0.0.1_amd64.deb

tachyon/c/BUILD.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda")
2+
load("//bazel:tachyon.bzl", "if_c_shared_object")
23
load(
34
"//bazel:tachyon_cc.bzl",
45
"collect_hdrs",
@@ -63,12 +64,12 @@ tachyon_cc_shared_library(
6364
linkstatic = True,
6465
soversion = VERSION,
6566
tags = ["manual"],
66-
deps = CURVE_DEPS + [
67+
deps = if_c_shared_object(CURVE_DEPS + [
6768
":version",
6869
"//tachyon/c/crypto/random:rng",
6970
"//tachyon/c/math:bn254_math",
7071
"//tachyon/c/zk:bn254_zk",
71-
] + if_cuda([
72+
]) + if_cuda([
7273
"@local_config_cuda//cuda:cudart_static",
7374
]),
7475
)

tachyon/cc/BUILD.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("//bazel:tachyon.bzl", "if_cc_shared_object")
12
load(
23
"//bazel:tachyon_cc.bzl",
34
"collect_hdrs",
@@ -59,10 +60,10 @@ tachyon_cc_shared_library(
5960
linkstatic = True,
6061
soversion = VERSION,
6162
tags = ["manual"],
62-
deps = [
63+
deps = if_cc_shared_object([
6364
"//tachyon/cc/math/elliptic_curves/bls12/bls12_381:g1",
6465
"//tachyon/cc/math/elliptic_curves/bn/bn254:g1",
65-
],
66+
]),
6667
)
6768

6869
collect_hdrs(

tachyon/crypto/commitments/fri/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tachyon_cc_unittest(
3535
":fri",
3636
"//tachyon/crypto/commitments/merkle_tree/binary_merkle_tree:simple_binary_merkle_tree_storage",
3737
"//tachyon/crypto/transcripts:simple_transcript",
38-
"//tachyon/math/finite_fields/goldilocks_prime:goldilocks",
38+
"//tachyon/math/finite_fields/goldilocks:goldilocks_prime_field",
3939
"//tachyon/math/finite_fields/test:finite_field_test",
4040
"//tachyon/math/polynomials/univariate:univariate_evaluation_domain_factory",
4141
],

tachyon/crypto/commitments/fri/fri_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "tachyon/base/containers/container_util.h"
99
#include "tachyon/crypto/commitments/merkle_tree/binary_merkle_tree/simple_binary_merkle_tree_storage.h"
1010
#include "tachyon/crypto/transcripts/simple_transcript.h"
11-
#include "tachyon/math/finite_fields/goldilocks_prime/goldilocks.h"
11+
#include "tachyon/math/finite_fields/goldilocks/goldilocks_prime_field.h"
1212
#include "tachyon/math/finite_fields/test/finite_field_test.h"
1313
#include "tachyon/math/polynomials/univariate/univariate_evaluation_domain_factory.h"
1414
#include "tachyon/math/polynomials/univariate/univariate_polynomial.h"

0 commit comments

Comments
 (0)