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

Tachyon integration spike #143

Open
oskarth opened this issue May 23, 2024 · 4 comments
Open

Tachyon integration spike #143

oskarth opened this issue May 23, 2024 · 4 comments

Comments

@oskarth
Copy link
Collaborator

oskarth commented May 23, 2024

Problem

For Groth16, we currently rely on wasm3 for witness generation and circom-compat for proof generation. There's circom-witness-rs which seems promising and would be roughly comparable with rapidsnark+witnesscalc.

Recently a new library has emerged, Tachyon, https://github.com/kroma-network/tachyon which seems promising and could lead to further performance gains. It seems useful to experimentally integrate this.

Currently it doesn't support mobile (Android or iOS), so this is the first step.

Details

See https://docs.google.com/spreadsheets/d/1irKg_TOP-yXms8igwCN_3OjVrtFe5gTHkuF0RbrVuho/edit#gid=289866675 for benchmarks @vivianjeng has done on MacOS.

First step here is to get Tachyon to work on iOS, which requires getting libgmpxx (libgmp for C++) and some other things to work. This is quite gnarly.

@vivianjeng has done a bunch of work to get this to compile and added to the https://github.com/zkmopro/benchmark benchmark app but not quite there.

See:

Acceptance criteria

Tachyon running on mobile real device with iOS.

Next steps

Once this is working, we want to integrate it with mopro. This would be better as a separate issue but here's a sketch of what it would likely involve:

  • Adding a C header around C++ interface (currently this relies on some C++ template for curve etc)
  • Using rust-bindgen to create a Rust shim layer for dealing with witness generation/proof generation
  • Integrating it into mopro-core as a new adapter
  • Exposing this in mopro-ffi and as template example app

(The same logic would apply to rapidsnark+witnesscalc).

@Meyanis95
Copy link
Collaborator

Hey,
I was looking into Tachyon and would be interested in benchmarking it as well for Anon Aadhaar
@vivianjeng let me know how I can help

@vivianjeng
Copy link
Collaborator

Hey, I was looking into Tachyon and would be interested in benchmarking it as well for Anon Aadhaar @vivianjeng let me know how I can help

Thank you @Meyanis95 !
AFAIK, Tachyon now only supports linux/win/macos
and in tachyon, they define how it responses to each system like
https://github.com/kroma-network/tachyon/blob/8b6aec7d39a3f6e7c8764dddbaccbac508440eae/BUILD.bazel#L112
and I guess if we can define ios_arm64 and successfully run

bazel build --config ios_arm64 //...

It might be able to build in bazel's app
https://github.com/vivianjeng/bazel-ios-app/tree/tachyon

The question is that it sometimes show the error and difficult to know how to fix
e.g.

✗ CARGO_BAZEL_REPIN=true bazel build --ios_multi_cpus=arm64 --platforms=//:ios_arm64 //Cpp:prover_main --verbose_failures --sandbox_debug
INFO: Analyzed target //Cpp:prover_main (1 packages loaded, 99 targets configured).
ERROR: /private/var/tmp/_bazel_zhengyawen/fe4a1850bfded67e7176592107efb57e/external/kroma_network_tachyon/tachyon/math/elliptic_curves/bn/bn254/BUILD.bazel:150:19: Action external/kroma_network_tachyon/tachyon/math/elliptic_curves/bn/bn254/g2.h failed: (Killed): generator failed: error executing Action command (from target @@kroma_network_tachyon//tachyon/math/elliptic_curves/bn/bn254:g2_gen_hdr) 
  (cd /private/var/tmp/_bazel_zhengyawen/fe4a1850bfded67e7176592107efb57e/execroot/_main && \
  exec env - \
  bazel-out/ios_arm64-opt/bin/external/kroma_network_tachyon/tachyon/math/elliptic_curves/short_weierstrass/generator/generator '--out=bazel-out/ios_arm64-opt/bin/external/kroma_network_tachyon/tachyon/math/elliptic_curves/bn/bn254/g2.h' '--namespace=tachyon::math::bn254' '--base_field=Fq2' '--base_field_degree=2' '--base_field_hdr=tachyon/math/elliptic_curves/bn/bn254/fq2.h' '--scalar_field=Fr' '--scalar_field_hdr=tachyon/math/elliptic_curves/bn/bn254/fr.h' '--cpu_hdr_tpl_path=external/kroma_network_tachyon/tachyon/math/elliptic_curves/short_weierstrass/generator/cpu.h.tpl' '--gpu_hdr_tpl_path=external/kroma_network_tachyon/tachyon/math/elliptic_curves/short_weierstrass/generator/gpu.h.tpl' '--class=G2' '-a=0' '-a=0' '-b=19485874751759354771024239261021720505790618469301721065564631296452457478373' '-b=266929791119991161246907387137283842545076965332900288569378510910307636690' '-x=10857046999023057135944570762232829481370756359578518086990519993285655852781' '-x=11559732032986387107991004021392285783925812861821192530917403151452391805634' '-y=8495653923123431417604973247489272438418190587263600148770280649306958101930' '-y=4082367875863433681332203403145435568316851327593401208105741076214120093531' '--endomorphism_coefficient=21888242871839275220042445260109153167277707414472061641714758635765020556616' '--endomorphism_coefficient=0' '--lambda=4407920970296243842393367215006156084916469457145843978461' '--glv_coefficients=-147946756881789319010696353538189108491' '--glv_coefficients=-9931322734385697763' '--glv_coefficients=9931322734385697763' '--glv_coefficients=-147946756881789319000765030803803410728')
# Configuration: bf3972a02adbb15cade8f58d8a6135b2970c25f65eaf2dd7f94d39c7355f3c11
# Execution platform: @@local_config_platform//:host
Target //Cpp:prover_main failed to build

I also suggest that you join their telegram group
https://t.me/zktachyon
they are very kind and response very fast

@vivianjeng
Copy link
Collaborator

@Meyanis95
To factorize this issue, I think we can try to build each element for ios separately
e.g.

bazel build --config ios_arm64 //tachyon/math/finite_field:finite_field

it could sometimes give more useful messages.

@Meyanis95
Copy link
Collaborator

Sounds good!
So starting tomorrow I'll read about Bazel and how it works, clone your Bazel project, and see if I can help make it build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants