zkmopro / mopro

Making client-side proving on mobile simple.
Apache License 2.0
102 stars 28 forks source link

Tachyon integration spike #143

Open oskarth opened 1 month ago

oskarth commented 1 month ago

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:

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

Meyanis95 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

@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 commented 4 weeks ago

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.