-
Notifications
You must be signed in to change notification settings - Fork 79
RPO STARK-based signature DSA (with zero knowledge) #349
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d74e746
chore: merge v0.11.0 release
bobbinth 3909b01
chore: merge v0.12.0 release from 0xPolygonMiden/next
bobbinth cd579d1
feat: STARK-based signature scheme
Al-Kindi-0 ec09539
fix: clippy
Al-Kindi-0 cb15287
fix: clippy
Al-Kindi-0 2fa0422
wip
Al-Kindi-0 c64f43b
chore: merge v0.13.0 release
bobbinth eaa1db6
fix: updated after Winterfell updates
Al-Kindi-0 866fda6
chore: update prover
Al-Kindi-0 068ecf8
Merge branch 'main' into al-stark-signature-dev-masm
Al-Kindi-0 c41b45f
chore: rebased on main
Al-Kindi-0 e67dc6f
feat: add constructor for sk from Word
Al-Kindi-0 9044792
chore: address feedback
Al-Kindi-0 f0ef609
chore: conflict resolve
Al-Kindi-0 1bbadff
chore: address feedback 2
Al-Kindi-0 5854a70
chore: remove from random_bytes
Al-Kindi-0 d7a23c4
chore: address feedback
Al-Kindi-0 cb7d22a
Merge branch 'next' into al-stark-signature-dev-masm
Al-Kindi-0 e30c18d
chore: add flag
Al-Kindi-0 b815e03
chore: remove optional
Al-Kindi-0 edc3843
fix: clippy
Al-Kindi-0 8c67eeb
fix: clippy
Al-Kindi-0 4de39ad
fix: add changelog
Al-Kindi-0 c4931b6
chore: fix std gate
Al-Kindi-0 a7e4843
fix: imports
Al-Kindi-0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| //! Digital signature schemes supported by default in the Miden VM. | ||
|
|
||
| pub mod rpo_falcon512; | ||
|
|
||
| pub mod rpo_stark; | ||
bobbinth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| mod signature; | ||
| pub use signature::{PublicKey, SecretKey, Signature}; | ||
|
|
||
| mod stark; | ||
| pub use stark::{PublicInputs, RescueAir}; | ||
|
|
||
| // TESTS | ||
| // ================================================================================================ | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::println; | ||
|
|
||
| use rand::SeedableRng; | ||
| use rand_chacha::ChaCha20Rng; | ||
|
|
||
| use super::SecretKey; | ||
|
|
||
| #[test] | ||
| fn test_signature() { | ||
| use rand_utils::rand_array; | ||
|
|
||
| let seed = [0_u8; 32]; | ||
| let mut rng = ChaCha20Rng::from_seed(seed); | ||
| let sk = SecretKey::with_rng(&mut rng); | ||
|
|
||
| let message = rand_array(); | ||
| let signature = sk.sign(message); | ||
| let pk = sk.public_key(); | ||
| println!("verify {:?}", pk.verify(message, &signature)); | ||
| assert!(pk.verify(message, &signature)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| use rand::{distributions::Uniform, prelude::Distribution, Rng}; | ||
| use winter_math::{fields::f64::BaseElement, FieldElement, StarkField}; | ||
| use winter_prover::Proof; | ||
| use winter_utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable}; | ||
| use winterfell::{FieldExtension, ProofOptions}; | ||
|
|
||
| use crate::{ | ||
| dsa::rpo_stark::stark::RpoSignatureScheme, | ||
| hash::{rpo::Rpo256, DIGEST_SIZE}, | ||
| Word, ZERO, | ||
| }; | ||
|
|
||
| // CONSTANTS | ||
| // ================================================================================================ | ||
|
|
||
| /// Specifies the parameters of the STARK underlying the signature scheme. These parameters provide | ||
| /// at least 102 bits of security under the conjectured security of the toy protocol in | ||
| /// the ethSTARK paper [1]. | ||
| /// | ||
| /// [1]: https://eprint.iacr.org/2021/582 | ||
| pub const PROOF_OPTIONS: ProofOptions = | ||
| ProofOptions::new(30, 8, 12, FieldExtension::Quadratic, 4, 7, true); | ||
|
|
||
| // PUBLIC KEY | ||
| // ================================================================================================ | ||
|
|
||
| /// A public key for verifying signatures. | ||
| /// | ||
| /// The public key is a [Word] (i.e., 4 field elements) that is the hash of the secret key. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub struct PublicKey(Word); | ||
|
|
||
| impl PublicKey { | ||
| /// Returns the [Word] defining the public key. | ||
| pub fn inner(&self) -> Word { | ||
| self.0 | ||
| } | ||
bobbinth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| impl PublicKey { | ||
| /// Verifies the provided signature against provided message and this public key. | ||
| pub fn verify(&self, message: Word, signature: &Signature) -> bool { | ||
| signature.verify(message, *self) | ||
| } | ||
| } | ||
|
|
||
| impl Serializable for PublicKey { | ||
| fn write_into<W: ByteWriter>(&self, target: &mut W) { | ||
| self.0.write_into(target); | ||
| } | ||
| } | ||
|
|
||
| impl Deserializable for PublicKey { | ||
| fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> { | ||
| let pk = <Word>::read_from(source)?; | ||
| Ok(Self(pk)) | ||
| } | ||
| } | ||
|
|
||
| // SECRET KEY | ||
| // ================================================================================================ | ||
|
|
||
| /// A secret key for generating signatures. | ||
| /// | ||
| /// The secret key is a [Word] (i.e., 4 field elements). | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub struct SecretKey(Word); | ||
|
|
||
| impl SecretKey { | ||
| /// Generates a secret key from OS-provided randomness. | ||
| pub fn new(word: Word) -> Self { | ||
| Self(word) | ||
| } | ||
|
|
||
| /// Generates a secret key from a [Word]. | ||
| #[cfg(feature = "std")] | ||
| pub fn random() -> Self { | ||
| use rand::{rngs::StdRng, SeedableRng}; | ||
|
|
||
| let mut rng = StdRng::from_entropy(); | ||
| Self::with_rng(&mut rng) | ||
| } | ||
|
|
||
| /// Generates a secret_key using the provided random number generator `Rng`. | ||
| #[cfg(feature = "std")] | ||
| pub fn with_rng<R: Rng>(rng: &mut R) -> Self { | ||
bobbinth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let mut sk = [ZERO; 4]; | ||
| let uni_dist = Uniform::from(0..BaseElement::MODULUS); | ||
|
|
||
| for s in sk.iter_mut() { | ||
| let sampled_integer = uni_dist.sample(rng); | ||
| *s = BaseElement::new(sampled_integer); | ||
| } | ||
|
|
||
| Self(sk) | ||
| } | ||
|
|
||
| /// Computes the public key corresponding to this secret key. | ||
| pub fn public_key(&self) -> PublicKey { | ||
| let mut elements = [BaseElement::ZERO; 8]; | ||
| elements[..DIGEST_SIZE].copy_from_slice(&self.0); | ||
| let pk = Rpo256::hash_elements(&elements); | ||
| PublicKey(pk.into()) | ||
| } | ||
|
|
||
| /// Signs a message with this secret key. | ||
| pub fn sign(&self, message: Word) -> Signature { | ||
| let signature: RpoSignatureScheme<Rpo256> = RpoSignatureScheme::new(PROOF_OPTIONS); | ||
| let proof = signature.sign(self.0, message); | ||
| Signature { proof } | ||
| } | ||
| } | ||
|
|
||
| impl Serializable for SecretKey { | ||
| fn write_into<W: ByteWriter>(&self, target: &mut W) { | ||
| self.0.write_into(target); | ||
| } | ||
| } | ||
|
|
||
| impl Deserializable for SecretKey { | ||
| fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> { | ||
| let sk = <Word>::read_from(source)?; | ||
| Ok(Self(sk)) | ||
| } | ||
| } | ||
|
|
||
| // SIGNATURE | ||
| // ================================================================================================ | ||
|
|
||
| /// An RPO STARK-based signature over a message. | ||
| /// | ||
| /// The signature is a STARK proof of knowledge of a pre-image given an image where the map is | ||
| /// the RPO permutation, the pre-image is the secret key and the image is the public key. | ||
| /// The current implementation follows the description in [1] but relies on the conjectured security | ||
| /// of the toy protocol in the ethSTARK paper [2], which gives us using the parameter set | ||
| /// given in `PROOF_OPTIONS` a signature with $102$ bits of average-case existential unforgeability | ||
| /// security against $2^{113}$-query bound adversaries that can obtain up to $2^{64}$ signatures | ||
| /// under the same public key. | ||
| /// | ||
| /// [1]: https://eprint.iacr.org/2024/1553 | ||
| /// [2]: https://eprint.iacr.org/2021/582 | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub struct Signature { | ||
| proof: Proof, | ||
| } | ||
|
|
||
| impl Signature { | ||
| /// Returns the STARK proof constituting the signature. | ||
| pub fn inner(&self) -> Proof { | ||
| self.proof.clone() | ||
| } | ||
bobbinth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Returns true if this signature is a valid signature for the specified message generated | ||
| /// against the secret key matching the specified public key. | ||
| pub fn verify(&self, message: Word, pk: PublicKey) -> bool { | ||
| let signature: RpoSignatureScheme<Rpo256> = RpoSignatureScheme::new(PROOF_OPTIONS); | ||
|
|
||
| let res = signature.verify(pk.inner(), message, self.proof.clone()); | ||
| res.is_ok() | ||
| } | ||
| } | ||
|
|
||
| impl Serializable for Signature { | ||
| fn write_into<W: ByteWriter>(&self, target: &mut W) { | ||
| self.proof.write_into(target); | ||
| } | ||
| } | ||
|
|
||
| impl Deserializable for Signature { | ||
| fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> { | ||
| let proof = Proof::read_from(source)?; | ||
| Ok(Self { proof }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.