Skip to content
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

Integrate STARK-based signature into VM #1593

Draft
wants to merge 1 commit into
base: al-stark-signature-masm
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions assembly/src/ast/instruction/advice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl From<&SystemEventNode> for SystemEvent {
InsertHperm => Self::HpermToMap,
PushSignature { kind } => match kind {
SignatureKind::RpoFalcon512 => Self::FalconSigToStack,
SignatureKind::RpoStark => Self::StarkSigToStack,
},
}
}
Expand Down Expand Up @@ -75,12 +76,14 @@ impl fmt::Display for SystemEventNode {
#[repr(u8)]
pub enum SignatureKind {
RpoFalcon512 = 0,
RpoStark = 1,
}

impl From<SignatureKind> for vm_core::SignatureKind {
fn from(kind: SignatureKind) -> Self {
match kind {
SignatureKind::RpoFalcon512 => Self::RpoFalcon512,
SignatureKind::RpoStark => Self::RpoStark,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions assembly/src/parser/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ extern {
"rcomb_base" => Token::RCombBase,
"repeat" => Token::Repeat,
"rpo_falcon512" => Token::RpoFalcon512,
"rpo_stark_sig" => Token::RpoStark,
"sdepth" => Token::Sdepth,
"stack" => Token::Stack,
"sub" => Token::Sub,
Expand Down Expand Up @@ -1587,6 +1588,7 @@ QualifiedName: (Ident, LibraryPath) = {

SignatureKind: SignatureKind = {
"rpo_falcon512" => SignatureKind::RpoFalcon512,
"rpo_stark_sig" => SignatureKind::RpoStark,
}

OpcodeName: Ident = {
Expand Down
3 changes: 3 additions & 0 deletions assembly/src/parser/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ pub enum Token<'input> {
RCombBase,
Repeat,
RpoFalcon512,
RpoStark,
Sdepth,
Stack,
Sub,
Expand Down Expand Up @@ -423,6 +424,7 @@ impl fmt::Display for Token<'_> {
Token::RCombBase => write!(f, "rcomb_base"),
Token::Repeat => write!(f, "repeat"),
Token::RpoFalcon512 => write!(f, "rpo_falcon512"),
Token::RpoStark => write!(f, "rpo_stark_sig"),
Token::Sdepth => write!(f, "sdepth"),
Token::Stack => write!(f, "stack"),
Token::Sub => write!(f, "sub"),
Expand Down Expand Up @@ -761,6 +763,7 @@ impl<'input> Token<'input> {
("rcomb_base", Token::RCombBase),
("repeat", Token::Repeat),
("rpo_falcon512", Token::RpoFalcon512),
("rpo_stark_sig", Token::RpoStark),
("sdepth", Token::Sdepth),
("stack", Token::Stack),
("sub", Token::Sub),
Expand Down
2 changes: 2 additions & 0 deletions core/src/operations/decorators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,14 @@ impl<'a> Iterator for DecoratorIterator<'a> {
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum SignatureKind {
RpoFalcon512,
RpoStark,
}

impl fmt::Display for SignatureKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::RpoFalcon512 => write!(f, "rpo_falcon512"),
Self::RpoStark => write!(f, "rpo_stark_sig"),
}
}
}
21 changes: 21 additions & 0 deletions core/src/sys_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod constants {
pub const EVENT_HDWORD_TO_MAP_WITH_DOMAIN: u32 = 2822590340;
pub const EVENT_HPERM_TO_MAP: u32 = 3297060969;
pub const EVENT_FALCON_SIG_TO_STACK: u32 = 3419226139;
pub const EVENT_STARK_SIG_TO_STACK: u32 = 3419226140;
}

/// Defines a set of actions which can be initiated from the VM to inject new data into the advice
Expand Down Expand Up @@ -300,6 +301,23 @@ pub enum SystemEvent {
/// Where PK is the public key corresponding to the signing key, MSG is the message, SIG_DATA
/// is the signature data.
FalconSigToStack,

/// Reads two words from the stack and pushes values onto the advice stack which are required
/// for verification of the RPO STARK-based DSA in Miden VM.
///
/// Inputs:
/// Operand stack: [PK, MSG, ...]
/// Advice stack: [...]
///
/// Outputs:
/// Operand stack: [PK, MSG, ...]
/// Advice stack: \[SIG_DATA\]
/// Advice store: \[SIG_DATA\]
/// Advice map: \[SIG_DATA\]
///
/// Where PK is the public key corresponding to the signing key, MSG is the message, SIG_DATA
/// is the signature data.
StarkSigToStack,
}

impl SystemEvent {
Expand All @@ -323,6 +341,7 @@ impl SystemEvent {
SystemEvent::HdwordToMapWithDomain => EVENT_HDWORD_TO_MAP_WITH_DOMAIN,
SystemEvent::HpermToMap => EVENT_HPERM_TO_MAP,
SystemEvent::FalconSigToStack => EVENT_FALCON_SIG_TO_STACK,
SystemEvent::StarkSigToStack => EVENT_STARK_SIG_TO_STACK,
}
}

Expand All @@ -348,6 +367,7 @@ impl SystemEvent {
EVENT_HDWORD_TO_MAP_WITH_DOMAIN => Some(SystemEvent::HdwordToMapWithDomain),
EVENT_HPERM_TO_MAP => Some(SystemEvent::HpermToMap),
EVENT_FALCON_SIG_TO_STACK => Some(SystemEvent::FalconSigToStack),
EVENT_STARK_SIG_TO_STACK => Some(SystemEvent::StarkSigToStack),
_ => None,
}
}
Expand Down Expand Up @@ -380,6 +400,7 @@ impl fmt::Display for SystemEvent {
Self::HdwordToMapWithDomain => write!(f, "hdword_to_map_with_domain"),
Self::HpermToMap => write!(f, "hperm_to_map"),
Self::FalconSigToStack => write!(f, "sig_to_stack.{}", SignatureKind::RpoFalcon512),
Self::StarkSigToStack => write!(f, "sig_to_stack.{}", SignatureKind::RpoStark),
}
}
}
4 changes: 4 additions & 0 deletions processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ testing = ["miden-air/testing"]
miden-air = { package = "miden-air", path = "../air", version = "0.11", default-features = false }
tracing = { version = "0.1", default-features = false, features = ["attributes"] }
vm-core = { package = "miden-core", path = "../core", version = "0.11", default-features = false }
verifier = { package = "miden-verifier", path = "../verifier", version = "0.11", default-features = false }
winter-prover = { package = "winter-prover", version = "0.11", default-features = false }
winter-fri = { package = "winter-fri", version = "0.11" }
winter-utils = { package = "winter-utils", version = "0.11" }
rand_chacha = { version = "0.3", default-features = false }

[dev-dependencies]
assembly = { package = "miden-assembly", path = "../assembly", version = "0.11", default-features = false }
Expand Down
8 changes: 7 additions & 1 deletion processor/src/host/advice/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use alloc::vec::Vec;

use vm_core::{
crypto::{hash::RpoDigest, merkle::MerklePath},
crypto::{
hash::RpoDigest,
merkle::{InnerNodeInfo, MerklePath},
},
Felt,
};

Expand Down Expand Up @@ -162,4 +165,7 @@ pub trait AdviceProvider: Sized {
/// It is not checked whether a Merkle tree for either of the specified roots can be found in
/// this advice provider.
fn merge_roots(&mut self, lhs: Word, rhs: Word) -> Result<Word, ExecutionError>;

/// Extends the Merkle store using an iterator.
fn extend_store<I: IntoIterator<Item = InnerNodeInfo>>(&mut self, iter: I);
}
15 changes: 15 additions & 0 deletions processor/src/host/advice/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ where
.map(|v| v.into())
.map_err(ExecutionError::MerkleStoreMergeFailed)
}

fn extend_store<I: IntoIterator<Item = vm_core::crypto::merkle::InnerNodeInfo>>(
&mut self,
iter: I,
) {
self.store.extend(iter);
}
}

// MEMORY ADVICE PROVIDER
Expand Down Expand Up @@ -273,6 +280,10 @@ impl AdviceProvider for MemAdviceProvider {
fn merge_roots(&mut self, lhs: Word, rhs: Word) -> Result<Word, ExecutionError> {
self.provider.merge_roots(lhs, rhs)
}

fn extend_store<I: IntoIterator<Item = vm_core::crypto::merkle::InnerNodeInfo>>(&mut self, iter: I) {
self.provider.extend_store(iter);
}
}

impl MemAdviceProvider {
Expand Down Expand Up @@ -379,6 +390,10 @@ impl AdviceProvider for RecAdviceProvider {
fn merge_roots(&mut self, lhs: Word, rhs: Word) -> Result<Word, ExecutionError> {
self.provider.merge_roots(lhs, rhs)
}

fn extend_store<I: IntoIterator<Item = vm_core::crypto::merkle::InnerNodeInfo>>(&mut self, iter: I) {
self.provider.extend_store(iter);
}
}

impl RecAdviceProvider {
Expand Down
75 changes: 0 additions & 75 deletions processor/src/operations/sys_ops/dsa.rs

This file was deleted.

Loading
Loading