19 Commits

Author SHA1 Message Date
skaunov
03e132597f improve plume_arkworks::sec1_affine to be used downstream 2025-06-06 17:42:10 +03:00
Sergey Kaunov
2bca61f809 Pr (#130)
* fix `zeroize` minimal version

* fix `dev-dependencies` minimal versions

* re-exports `rand` from `arkworks`
2025-06-05 23:25:36 +03:00
skaunov
c281e3223b plume_arkworks improvement 2025-05-28 19:21:59 +03:00
skaunov
5d83129648 re-export few items needed to use with Poseidon 2025-05-24 14:22:18 +03:00
skaunov
7b8c77a60f [plume_arkworks] fmt 2024-11-17 10:33:09 +03:00
skaunov
f7206ab581 upgrade <rust-arkworks> to the current arkworks version
# "Hazmat"
was removed since `arkworks` security model differs significantly from RustCrypto, and approaching it from the standpoint of the PLUME crate published earlier isn't really a correct way. \
Still I'd like to have a better look into `zeroize` for this crate before calling it `v.0.1`.
# `test_vectors`
were taken from the deprecated crate for SEC1 encoding testing.
2024-11-17 10:21:57 +03:00
Yush G
5bb3dda0d6 Add docs and tests (#100)
See issues #67 and #84 .

Few snippets of other paths I considered.
```rust
        ...
        [ProjectivePoint::GENERATOR.to_encoded_point(true).as_bytes(), &pk_bytes, enc!(hashed_to_curve)].map(|b| hashers[0].update(b));
        for b in [enc!(nullifier), enc![r_point], enc!(hashed_to_curve_r)] {
            hashers[0].update(b);
            hashers[1].update(b);
        }
        
        let c = hashers.map(|h| h.finalize());
        let c_scalar = c.clone().map(|c_i| NonZeroScalar::reduce_nonzero(U256::from_be_byte_array(c_i)));
        // Compute s = r + sk ⋅ c
        let s_scalar = c_scalar.map(|c_scalar_i| NonZeroScalar::new(*r_scalar + *(self.to_nonzero_scalar() * c_scalar_i))
            .expect("something is terribly wrong if the nonce is equal to negated product of the secret and the hash"));
        
        Ok(PlumeSignatureCombined{
            message: msg.to_owned(),
            pk: pk.into(),
            nullifier: nullifier.to_point(),
            v2_c: c[1],
            v2_s: *s_scalar[1],
            v1_c: c[0],
            v1_s: *s_scalar[0],
            v1_r_point: r_point.into(),
            v1_hashed_to_curve_r: hashed_to_curve_r.to_point(),
        })
    }
}
/// Struct holding mandatory signature data for ... PLUME signature
#[derive(Debug)]
pub struct PlumeSignatureCombined {
    /// The message that was signed.
    pub message: Vec<u8>,
    /// The public key used to verify the signature.
    pub pk: ProjectivePoint,
    /// The nullifier.
    pub nullifier: ProjectivePoint,
    /// Part of the signature data.
    pub v2_c: Output<Sha256>,
    /// Part of the signature data, a scalar value.
    pub v2_s: Scalar,
    /// Part of the signature data.
    pub v1_c: Output<Sha256>,
    /// Part of the signature data, a scalar value.
    pub v1_s: Scalar,
    /// Part of the V1 signature data, a curve point.  
    pub v1_r_point: ProjectivePoint,
    /// Part of the V1 signature data, a curve point.
    pub v1_hashed_to_curve_r: ProjectivePoint,
}
impl PlumeSignatureCombined {
    pub fn separate(self) -> (PlumeSignature, PlumeSignature) {
        let (pk, nullifier) = (self.pk, self.nullifier); 
        (
            PlumeSignature{ 
                message: self.message.clone(), pk, nullifier, c: self.v1_c, s: self.v1_s, v1specific: Some(
                    PlumeSignatureV1Fields{ r_point: self.v1_r_point, hashed_to_curve_r: self.v1_hashed_to_curve_r }
                ) 
            }, 
            PlumeSignature{ message: self.message, pk, nullifier, c: self.v2_c, s: self.v2_s, v1specific: None }, 
        )
    }
}
```
_____________________________________
```rust
pub enum PlumeSignature{
    V1(PlumeSignatureV1),
    V2(PlumeSignatureV2),
}
pub struct PlumeSignatureV1 {
    v2: PlumeSignatureV2,
    v1: PlumeSignatureV1Fields
}
/// Struct holding mandatory signature data for a PLUME signature.
pub struct PlumeSignatureV2 {
    /// The message that was signed.
    pub message: Vec<u8>,
    /// The public key used to verify the signature.
    pub pk: ProjectivePoint,
    /// The nullifier.
    pub nullifier: ProjectivePoint,
    /// Part of the signature data.
    pub c: Output<Sha256>,
    /// Part of the signature data, a scalar value.
    pub s: Scalar,
    // /// Optional signature data for variant 1 signatures.
    // pub v1: Option<PlumeSignatureV1Fields>,
}
/// struct holding additional signature data used in variant 1 of the protocol.
#[derive(Debug)]
pub struct PlumeSignatureV1Fields {
    /// Part of the signature data, a curve point.  
    pub r_point: ProjectivePoint,
    /// Part of the signature data, a curve point.
    pub hashed_to_curve_r: ProjectivePoint,
}

impl signature::RandomizedSigner<PlumeSignatureV1> for SecretKey {}
impl signature::RandomizedSigner<PlumeSignatureV2> for SecretKey {}
```
---------

Co-authored-by: skaunov <skaunov@disroot.org>
2024-02-28 12:17:58 +03:00
Sergey Kaunov
e5febe3cf3 Resolve half of #67 (Part 1/2) (#93)
* current progress

* link to relevant issue

* crate name edit

* Flat the docs entities

* meta information

* Update the crate name in `tests`

* current progress
2024-02-15 15:18:30 -05:00
Sergey Kaunov
602ec7bdab Solve #60 (#91)
* Sane error handling and some simplification (ditch unwrap)
* excessive code and entities were removed
2024-02-06 03:24:10 -05:00
Anton
79c602670b chore: clean up (#74)
* chore: clean up

- [x] Add checks for ci actions
- [x] Run prettier, clippy, fmt commands for all the files
- [x] Move circom circuits to a circom folder
- [x] Get rid of js var statements

* chore: add resolver version for cargo.toml

* chore: add circom tests

* chore: optimize check triggers

* chore: remove `check` command

* chore: use only `pnpm`

* chore: update readme

---------

Co-authored-by: 0xmad <0xmad@users.noreply.github.com>
2023-11-18 20:48:24 +03:00
skaunov
da9f5fb288 All modules naming is aligned. + refactoring&tests
[Discussion] results are incorporated. Naming groomed repository wide. \
Fun fact: I already was confused by that "hash2" naming, lol.

Note that `fn verify_signals` barely [benefit]
from renaming at all currently.

[Discussion]: 251fba6902 (commitcomment-130400727)
[benefit]: https://github.com/plume-sig/zk-nullifier-sig/issues/61
2023-10-20 17:59:39 +03:00
Yush G
68c69b831b Merge pull request #42 from plume-sig/39
Solve #39
2023-09-26 00:21:00 +02:00
skaunov
fce6b81c66 Solve #18
Also bump `ark-ec` minor version and fix some linting
2023-09-25 22:05:32 +03:00
skaunov
b66ade1189 Solve #39
Test values were taken from <./javascript/test/signals.test.ts> line 86
and further.
2023-09-25 00:09:41 +03:00
Sergey Kaunov
f787cb39f0 c switched to be hash in the crates
`c` conversion to number / field element moved to consuming functions
more like it's in <./javascript> now
2023-09-24 16:59:40 +03:00
Vu Vo
98d065699d setup workspace 2023-05-16 03:11:38 +07:00
Vu Vo
20d6025b52 add version to non-zk verify 2023-04-17 19:13:55 +07:00
Koh Wei Jie
17fd79cc71 use the correct the domain separator tag in hash-to-curve 2022-09-26 10:50:16 -07:00
Koh Wei Jie
832ea2dad9 moved arkworks impl to this repo 2022-09-15 11:29:12 -07:00