Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
snark/user_command_verify
Service
To check signatures and verify proofs contained in zkapps
- Loading branch information
1 parent
ce1f4f8
commit b31fced
Showing
15 changed files
with
399 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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,32 @@ | ||
mod snark_user_command_verify_state; | ||
pub use snark_user_command_verify_state::*; | ||
|
||
mod snark_user_command_verify_actions; | ||
pub use snark_user_command_verify_actions::*; | ||
|
||
mod snark_user_command_verify_reducer; | ||
|
||
mod snark_user_command_verify_effects; | ||
|
||
mod snark_user_command_verify_service; | ||
pub use snark_user_command_verify_service::*; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
pub struct SnarkUserCommandVerifyIdType; | ||
impl openmina_core::requests::RequestIdType for SnarkUserCommandVerifyIdType { | ||
fn request_id_type() -> &'static str { | ||
"SnarkUserCommandVerifyId" | ||
} | ||
} | ||
|
||
pub type SnarkUserCommandVerifyId = | ||
openmina_core::requests::RequestId<SnarkUserCommandVerifyIdType>; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, thiserror::Error)] | ||
pub enum SnarkUserCommandVerifyError { | ||
#[error("verification failed")] | ||
VerificationFailed, | ||
#[error("validator thread crashed")] | ||
ValidatorThreadCrashed, | ||
} |
66 changes: 66 additions & 0 deletions
66
snark/src/user_command_verify/snark_user_command_verify_actions.rs
This file contains 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,66 @@ | ||
use ledger::scan_state::transaction_logic::verifiable; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use openmina_core::{snark::Snark, ActionEvent}; | ||
|
||
use super::{SnarkUserCommandVerifyError, SnarkUserCommandVerifyId}; | ||
|
||
pub type SnarkUserCommandVerifyActionWithMeta = redux::ActionWithMeta<SnarkUserCommandVerifyAction>; | ||
pub type SnarkUserCommandVerifyActionWithMetaRef<'a> = | ||
redux::ActionWithMeta<&'a SnarkUserCommandVerifyAction>; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, ActionEvent)] | ||
#[action_event(level = trace, fields(display(req_id), display(error)))] | ||
pub enum SnarkUserCommandVerifyAction { | ||
#[action_event(level = info)] | ||
Init { | ||
req_id: SnarkUserCommandVerifyId, | ||
#[serde(skip)] // TODO | ||
commands: Vec<verifiable::UserCommand>, | ||
sender: String, | ||
}, | ||
Pending { | ||
req_id: SnarkUserCommandVerifyId, | ||
}, | ||
Error { | ||
req_id: SnarkUserCommandVerifyId, | ||
error: SnarkUserCommandVerifyError, | ||
}, | ||
#[action_event(level = info)] | ||
Success { | ||
req_id: SnarkUserCommandVerifyId, | ||
}, | ||
Finish { | ||
req_id: SnarkUserCommandVerifyId, | ||
}, | ||
} | ||
|
||
impl redux::EnablingCondition<crate::SnarkState> for SnarkUserCommandVerifyAction { | ||
fn is_enabled(&self, state: &crate::SnarkState, _time: redux::Timestamp) -> bool { | ||
match self { | ||
SnarkUserCommandVerifyAction::Init { | ||
req_id, commands, .. | ||
} => !commands.is_empty() && state.user_command_verify.jobs.next_req_id() == *req_id, | ||
SnarkUserCommandVerifyAction::Pending { req_id } => state | ||
.user_command_verify | ||
.jobs | ||
.get(*req_id) | ||
.map_or(false, |v| v.is_init()), | ||
SnarkUserCommandVerifyAction::Error { req_id, .. } => state | ||
.user_command_verify | ||
.jobs | ||
.get(*req_id) | ||
.map_or(false, |v| v.is_pending()), | ||
SnarkUserCommandVerifyAction::Success { req_id } => state | ||
.user_command_verify | ||
.jobs | ||
.get(*req_id) | ||
.map_or(false, |v| v.is_pending()), | ||
SnarkUserCommandVerifyAction::Finish { req_id } => state | ||
.user_command_verify | ||
.jobs | ||
.get(*req_id) | ||
.map_or(false, |v| v.is_finished()), | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
snark/src/user_command_verify/snark_user_command_verify_effects.rs
This file contains 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 @@ | ||
use redux::ActionMeta; | ||
|
||
use super::{SnarkUserCommandVerifyAction, SnarkUserCommandVerifyService}; | ||
|
||
impl SnarkUserCommandVerifyAction { | ||
pub fn effects<Store, S>(self, _: &ActionMeta, store: &mut Store) | ||
where | ||
Store: crate::SnarkStore<S>, | ||
Store::Service: SnarkUserCommandVerifyService, | ||
SnarkUserCommandVerifyAction: redux::EnablingCondition<S>, | ||
{ | ||
match self { | ||
SnarkUserCommandVerifyAction::Init { | ||
req_id, commands, .. | ||
} => { | ||
let verifier_index = store.state().work_verify.verifier_index.clone(); | ||
let verifier_srs = store.state().work_verify.verifier_srs.clone(); | ||
store | ||
.service() | ||
.verify_init(req_id, verifier_index, verifier_srs, commands); | ||
store.dispatch(SnarkUserCommandVerifyAction::Pending { req_id }); | ||
} | ||
SnarkUserCommandVerifyAction::Error { req_id, .. } => { | ||
store.dispatch(SnarkUserCommandVerifyAction::Finish { req_id }); | ||
} | ||
SnarkUserCommandVerifyAction::Success { req_id } => { | ||
store.dispatch(SnarkUserCommandVerifyAction::Finish { req_id }); | ||
} | ||
SnarkUserCommandVerifyAction::Pending { .. } => {} | ||
SnarkUserCommandVerifyAction::Finish { .. } => {} | ||
} | ||
} | ||
} |
Oops, something went wrong.