Giter Club home page Giter Club logo

zk-nullifier-sig's Issues

320 bytes used to store Secp256k1 coordinate

A point $(x,y)$ on Secp256k1 curve is of 64 bytes in its uncompressed form (32 byte for each coordinate).

hash_to_curve.rs#L45-L62 uses 320 bytes for each coordinate. Arkworks uses 40 bytes to store a coordinate.

Recommendation:
Although the test passes, you can use 40 bytes instead of 320:

-let num_field_bytes = 320;
+let num_field_bytes = 40;

Different implementations use sha256 or sha512

Circom and js use sha256.
Rust implementations use sha512.

So these implementations are not compatible.

I suggest passing all these implementations through a common test to ensure consistency.

Refactor `CryptoError`

At ark crate it's used quite suboptimal now, also see branch:43 for a further suggestion.

Add tests for wrapping `c` over $p$

It might be a RustCrypto thing which just panics on certain methods when bytes yields the value larger than $p$, but it's still a worthy case to have in the suite across implementation to be sure that wrapping is done correctly, and that signatures equality can be facilitated.

autotest skips <circuits>

Two possible solutions were mentioned. Both require some experience/research to implement.

Replace Jest with cargo-test for ?

Is there any specific in that test suit which won't work better in Rust? I guess circom crate can be just a dev dependency there (instead of external call), which potentially might enable tests parallelization. Also there's small chance of running it in GitHub action that way (though I guess it would hit some bottleneck along the way).

circom-tester

#24 (comment)

Are bad/malicious inputs tested?

I didn't check, but it seems to me that cases when c is zero, or EC points are at infinity aren't covered by tests, and in couple of recent PRs such tests would be helpful. I guess there also maybe such important inputs which would be good to test.

(Super cool would be to have a file of test vectors.)

prevention of PK recovery with two signatures on the same message

          I totally trust you just trying to understand.

Deterministic as "to know c beforehand of signing"; or is it just the fact that V2 wouldn't work since it lacks the point $r$ value? Or something else?

I mean I kind of don't see yet the essential difference if signer adds to the message point $r$ instead of the info/data you mentioned. ๐Ÿค”

Originally posted by @skaunov in #98 (comment)

Error handling in _rust_k256_

fn encode_pt(point: ProjectivePoint) -> Result<Vec<u8>, Error> always returns Ok(..) currently. Should be analyzed to either introduce error handling or made it infallible.

unnecessity of indifferentiability

I am recently reading into the PLUME design and the use of Geometry's map. Note that Geometry's map was designed for a different purpose. If we target at making a nullifier, there is at least one trick that we can use.

Note that for provable indifferentiability, Geometry's map does hashing to curves twice and adds the results together. This is not necessary if we use the signature as the nullifier because you don't need to reveal the signature (see #11, I am referring to the GDH undeniable signature, the signature part), and to hide the signature, just hash the final result.

This ideally should be able to reduce the cost by half (given that clearing the cofactor is not necessary for secp256k1).

Unit tests would help reference implementation readability

It's kind of #72 (comment), but letting moving forward meanwhile.

I added a test which should be showing that hashing to curve isn't correct (at least on signing; before #84 ). As there's many conversions and different formats/endings the test isn't super readable, so it's quite probable I just messed up along the way. This is quite easy to check if anybody would add a hash_to_curve test which a current implementation would pass.

Anyway this/such test is a good contribution to the code. Mine was born when my implementation yielded a signature (V1) different from the current one using the same inputs which correctness I double-checked. (Yep, it's quite probable I messed up implementation and that test; it's enough to have just two errors for this. On the other hand it's god enough signal to dig into this.)

`tests` in <./rust-k256> are confusing

Tests in rust_k256 use the same function while producing test data as the function they test. So actually they test wrapping (which is useful too), but c_sha256_vec_signal is left untested in fact.

Crates API and documentation

Both crates basically lacks documentation, and <./rust-k256> lacks API choices.

Also their name are ...temporary.

PS It would be nice to think about traits used and reexported so that it would not clash with versions that downstream use. Though most likely Cargo will do its job on it, just it's better to be sure.
This one is more about releasing the crates when things will come to it.

Introduce DST specific for the protocol!

Current used DST is taken from the example, so it will collide with other projects which didn't introduce their own DST, which defies its purpose. I see it as quite a priority since if it won't be done until people start to use the thing it will be quite painful to change as it's not backward compatible in no way.

On the other hand there's quite an amount of tests alignment and small modifications due to change of the DST to proper one. Though not a horrific amount.

So the choice is better be done once and never changed, so it worth to put some effort in it. While it should be done in reasonable time. Obvious step is to start the string with "PLUME", and maybe it would be enough to be aligned with usual string, maybe some more information is nice to put there. Too long string bring small burden, btw.

PS Sorry for brevity, am writing in hurry; hope to edit for better readability, or clarify anything in discussion.

<./rust-arkworks> is over generalized

The crate is quite complex and I fail to see any reason behind it. It offers a complex trait, but its type system requires further development to be really useful. (And error handling isn't well-compatible with other crates.) It's very generic over curves and its generators, but the only curve other implementations support is deprecated, and I can't find a case when another curve would be plugged into it.

I well might be just fail to see the big idea though. @weijiekoh , could you explain these since I struggled to pick-up the reasons from code but it doesn't add up well in my mind. =(

My current proposal is to ditch the defined trait, simplify few places, and decide on the level of generality. If we don't expect no other curves for PLUME in foreseeable future then further simplify to make it concrete, if do expect then [try] to preserve this part.
[try]: deprecation of the curve definition makes this more a grounding and reference work (than just use) until the whole thing isn't maintained to be compatible with current arkworks version

Refactor `verify_signals`

In rust_k256 crate this fn seems to be fundamental. I'd make it pub, redo some internals (at least better separate computed and input values), and got rid of println! which are suitable for a bin crate, not for a lib.

`sha256_preimage_bit_length` is a free signal

verify_nullifier.circom#L33

Prover is free to choose any value forsha256_preimage_bit_length to generate the sha256 hash for c. Since the length of the hash pre-image is fixed, it can be removed as an input signal. The TODO comment indicates this too:

// ...TODO: calculate internally in circom to simplify API
signal input sha256_preimage_bit_length;

Recommendation: sha256_preimage_bit_length should always be equal to message_bits (6*33*8).

`SecretKeyMaterial` is handled recklessly in <./rust-arkworks>

It's yet named SecretKey, oncoming PR renames it to not give false impression of security.

here arkworks should be checked for proper methods for keys handling
at least zeroize should be applied
also would be nice to check that proper RNG is enforced

SHA-512 in `rust-arkworks`

I noticed that both c are produced with SHA-256 in <./javascript>. Is it ok to that crate to do it with SHA-512?

Add `sign` method to <./rust-k256>

Seems like <./rust-k256> designed only for verification of a signature, as there's no ready outlet to pub which could sign a message. Should it be so, or does it just lacking it?

Differential test to verify all implementations

It's important to have consistency across these impls. A few examples:

  • sha256 in js, circom vs sha512 in rust.
  • c is returned as a plain number in js, circom vs a field element in rust.
  • More issues may be uncovered, like encoding/decoding across different formats.

You should run a differential test on random values for message and private key (maybe pre-generate and freeze them).

alternative security proof

Just to add, there is a quick way to prove the PLUME security, in case anyone asks.

This is the GDH undeniable signature with the confirmation protocol replaced with NIZK, and here the NIZK is a classical Chaum-Pedersen protocol.

The GDH undeniable signature can be found here: Tatsuaki Okamoto and David Pointcheval. The gap-problems: A new class of problems for the security of cryptographic schemes. In PKC โ€™01

This is also discussed in the BLS signature paper. Section 2.2.

Uniqueness comes from hashing to the curve.

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.