Giter Club home page Giter Club logo

pasta_curves's Introduction

Zcash 5.9.1

What is Zcash?

Zcash is HTTPS for money.

Initially based on Bitcoin's design, Zcash has been developed from the Zerocash protocol to offer a far higher standard of privacy and anonymity. It uses a sophisticated zero-knowledge proving scheme to preserve confidentiality and hide the connections between shielded transactions. More technical details are available in our Protocol Specification.

The zcashd Full Node

This repository hosts the zcashd software, a Zcash consensus node implementation. It downloads and stores the entire history of Zcash transactions. Depending on the speed of your computer and network connection, the synchronization process could take several days.

The zcashd code is derived from a source fork of Bitcoin Core. The code was forked initially from Bitcoin Core v0.11.2, and the two codebases have diverged substantially.

๐Ÿ”’ Security Warnings

See important security warnings on the Security Information page.

Zcash is experimental and a work in progress. Use it at your own risk.

๐Ÿ“’ Deprecation Policy

This release is considered deprecated 16 weeks after the release day. There is an automatic deprecation shutdown feature which will halt the node some time after this 16-week period. The automatic feature is based on block height.

Other Zcash Implementations

The Zebra project offers a different Zcash consensus node implementation, written largely from the ground up.

Getting Started

Please see our user guide for instructions on joining the main Zcash network.

Need Help?

  • ๐Ÿ“˜ See the documentation at the ReadTheDocs for help and more information.
  • ๐Ÿ“จ Ask for help on the Zcash forum.
  • ๐Ÿ’ฌ Join our community on Discord
  • ๐Ÿง‘โ€๐ŸŽ“: Learn at ZecHub

Participation in the Zcash project is subject to a Code of Conduct.

Building

Build Zcash along with most dependencies from source by running the following command:

./zcutil/build.sh -j$(nproc)

Currently, Zcash is only officially supported on Debian and Ubuntu. See the Debian / Ubuntu build for detailed instructions.

License

For license information see the file COPYING.

pasta_curves's People

Contributors

daira avatar davidnevadoc avatar dependabot[bot] avatar dignifiedquire avatar dot-asm avatar ebfull avatar krnak avatar nuttycom avatar porcuquine avatar r3ld3v avatar rex4539 avatar samuelburnham avatar str4d avatar therealyingtong avatar vmx avatar xxuejie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pasta_curves's Issues

Check whether the libsecp256k1 optimization that uses an isomorphic curve is applicable

They sometimes switch from $y^2 = x^3 + 7$ to $y^2 = x^3 + 7 t^6$ in order to use Jacobian coordinates. I haven't looked at why this is useful or whether a similar optimization applies to Pallas and Vesta. (The same structure of isomorphisms between curves is present; the question is whether it is useful for us.)

https://github.com/bitcoin-core/secp256k1/blob/60556c9f49a9384efd7f16b734820ae19108f053/src/ecmult_impl.h#L83-L93

Kill `FieldExt` trait

This (along with its other related traits) was a helper trait that we created to provide additional methods needed for halo2_proofs that the ff crate traits didn't have, while we figured out what those needed additional methods were. Now that we've cut halo2_proofs 0.1.0, we need to finish the job:

  • Figure out how to better abstract these additional methods if necessary.
  • Add these abstractions to ff.
  • Delete the FieldExt trait.

Kill `CurveExt` and `CurveAffine` traits

These were helper traits that we created to provide additional methods needed for halo2_proofs that the group crate traits didn't have, while we figured out what those needed additional methods were. Now that we've cut halo2_proofs 0.1.0, we need to finish the job:

  • Figure out how to better abstract these additional methods.
  • Add these abstractions to group.
  • Delete the CurveExt and CurveAffine traits.

Enable `ec-gpu` to generate MSM and FFT code for `pasta_curves`

We want to be able to leverage GPUs in halo2, via the ec-gpu crate. This requires two changes:

  • The curve implementation needs to support producing the GPU kernel for finite field arithmetic.
  • halo2 needs to use GPU-aware MSM and FFT algorithms.

This issue covers the second change. We should implement the GpuEngine trait from the ec-gpu crate (behind a gpu feature flag), and then the ec-gpu-gen crate should be able to generate the necessary CUDA/OpenCL source code for MSMs and FFTs.

Add `alloc` feature flag

In #4 we introduced a std feature flag, to enable downstream users to disable anything relying on std. This happened to gate all of the traits, because both FieldExt and CurveAffine depended on std::io.

We removed std::io usage from FieldExt in #20, so it could now be removed from any feature flag. CurveAffine still relies on std::io, but I want to remove that as well. Then we're just left with the fact that CurveExt requires FieldExt, FieldExt is bound on SqrtRatio, and the only way we can implement SqrtRatio right now depends on SqrtTables, which requires alloc.

So, we should add an alloc feature flag, and move everything behind it. We might also be able to remove the std feature flag as a result (which has not been in a release yet). There's no point in having the traits themselves be no-std accessible if we can't implement them without alloc. Once we have a fallback for SqrtRatio we can consider making the other traits no-std usable.

Add `ec-gpu` support

We want to be able to leverage GPUs in halo2, via the ec-gpu crate. This requires two changes:

  • The curve implementation needs to support producing the GPU kernel for finite field arithmetic.
  • halo2 needs to use GPU-aware MSM and FFT algorithms.

This issue covers the first change. We should implement the GpuField trait from the ec-gpu crate (behind a gpu feature flag), and then the ec-gpu-gen crate should be able to generate the necessary CUDA/OpenCL source code.

Add shift operators to FieldExt

The lack of these operators results in awkward constructions, especially when constructing constants larger than 128 bits.

a << k would be equivalent to a * TWO.pow(k).
a >> k would drop the low-order k bits.

These definitions satisfy

  • (a >> k) << k == a when a is a multiple of 2k;
  • (a << k) >> k == a when a << k does not overflow.

Add constructor for `Coordinates`

In order to implement the trait CurveExt for a curve it is necessary to implement the method:
fn coordinates(&self) -> CtOption<Coordinates<Self>>
This requires to create the struct Coordinates which cannot be done directly from outside the crate since its attributes x, y are pub(crate). There is also no method to create the struct.

If the visibility was changed to pub other curves could be implemented reusing this trait.

Release 0.3.0

This will include the API refactor and no-std / alloc support.

Consider implementing (de)serialization for base types (Fp, Fq)

It is quite typical, at least in my experience, for code using pasta_curves crate to have the necessity to persist or transfer structs with fields of types Fp and Fq, which requires (de)serialization.

As Rust doesn't allow implementing traits for imported structs, we have to manually write (de)serializers for every struct that contains Fp or Fq fields instead of being able to just do a simple #[derive].

Would you consider adding serialization impl's to these types? At least for some popular serialization libraries such as serde and borsh. The implementations could be behind a feature flag. The change, I believe, would be as much as adding a #[derive(Serialize,Deserialize,BorshSerialize,BorshDeserialize)] to the struct declaration.

I can do a PR, if you prefer.

Remove `std` feature flag

Once #25 has been closed by #26, we should refactor CurveAffine to remove its std::io APIs. Then we can place those traits behind the alloc feature flag, and remove the std feature flag (which has not been in a release yet).

Reduce code duplication in field implementations

Currently this library has two field implementations, the Pallas field and the Vesta field. They only differ in their prime modulus, and are otherwise almost identically implemented. This makes the library harder to maintain, as every change needs to be duplicated.

There are several possible approaches we could take to improve the situation:

  • Use a declarative macro.
    • We already use a declarative macro for implementing the curves, so it would be in keeping with the rest of the library.
    • This has been proposed and implemented here: e150cc5
  • Use a procedural macro, i.e. ff_derive
    • This is how we originally implemented BLS12-381 in the pairing crate, but we replaced that with a direct implementation of the field in the bls12_381 crate, and ff_derive hasn't been as effectively maintained since. If we switched to it, the majority of our field maintenance effort could go into ff_derive instead of here.
  • Use crypto-bigint to implement the internal field details.
    • This would reduce the amount of code we need to maintain, which would just be the mapping from a big integer element to a prime field element.
    • This would be quite a divergence from previous approaches. I also don't know how feature-complete crypto-bigint is, though progress is being made.
    • If this is a practical and performant approach, we could also combine it with either the declarative macro or ff_derive approach to make it easier to maintain as well.

Expose APIs for incomplete point addition

In the Orchard spec we use incomplete addition inside the circuit, in places where we want efficiency, and where finding an edge case in incomplete addition is isomorphic to breaking discrete log (which the rest of the protocol already relies on for balance integrity). For some of these, like Sinsemilla in the commitment tree, we will want to add consensus rules that the โŠฅ case never occurs (e.g. so transactions are only ever mined with anchors that exist in the chain). This will require implementing incomplete addition outside the circuit, but we default to impl std::ops::* using complete addition (for safety).

We should add Point::add_incomplete APIs that implement incomplete addition, are only usable with concrete knowledge of the point type (i.e. not generically), and document why you should not reach for them unless you have analysed the necessary edge cases.

Book deployment is broken

error[E0658]: the `unsafe_op_in_unsafe_fn` lint is unstable
Error:    --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/os_str_bytes-6.0.0/src/lib.rs:159:1
    |
159 | #![forbid(unsafe_op_in_unsafe_fn)]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #71668 <https://github.com/rust-lang/rust/issues/71668> for more information

error: aborting due to previous error
Error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.
error: could not compile `os_str_bytes`
Error: could not compile `os_str_bytes`
To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
Warning: error: failed to compile `mdbook-katex v0.2.10`, intermediate artifacts can be found at `/tmp/cargo-installOt9WtP`

Consider using the add-2007-bl and dbl-2009-l formulae

Addition (incomplete, any a): http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-add-2007-bl
Doubling for a = 0: http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-l

These are used in Arkworks for short Weierstrass curves. I also implemented a variant of them in the ChudnovskyPoint class in the Sage implementation of Pasta used to generate the hash-to-curve test vectors. (The latter actually modifies the addition formulae to be complete, at some extra cost.)

A possible alternative is https://eprint.iacr.org/2015/1060 (see also privacy-scaling-explorations/halo2curves#15).

Worth consider asmffi asm implementation for pasta fields?

I came across https://github.com/iden3/ffiasm and wondered if this asm code has ever been benched against the actual implementation. And if so, whether it is faster.

I did some initial exploration and saw that most of the asm backend we have at PSE (see here) is as optimized as what rust here compiles too. (At least for fns like double as seen in: #44 (comment)

From a quick look, to functions like double or square looks like the exact same thing or even slightly worse:

Square

Instruction asmffi PSE-ASM (Ash)
PUSH 4 0
MOV 20 19
XOR 1 2
MULX 36 36
ADCX 39 28
ADOX 28 0
BT 2 0
SHL 1 0
ADD 2 28
SUB 2 2
SBB 0 6
CMOVC 0 8
TOTAL 135 129

Double

From a superficial view is already obvious that PSE-ASM is has less ops.


So I just wonder if anyone has done a deep analysis on that. As from a short check, looks like is not worth even considering it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.