Skip to content

Commit 0da5eb9

Browse files
committed
Ledger/transaction_logic: extract verifiable module to separate file
Extract the verifiable module from transaction_logic/mod.rs into its own file. This module contains the verifiable UserCommand enum (with serde traits) and signature verification functions. Changes: - Extract verifiable module to transaction_logic/verifiable.rs - Use explicit imports instead of 'use super::*' - Update mod.rs to reference the new module file
1 parent 3e8b2b3 commit 0da5eb9

File tree

2 files changed

+53
-50
lines changed

2 files changed

+53
-50
lines changed

ledger/src/scan_state/transaction_logic/mod.rs

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -610,56 +610,7 @@ pub mod signed_command;
610610
pub mod zkapp_command;
611611
pub mod zkapp_statement;
612612

613-
pub mod verifiable {
614-
use std::ops::Neg;
615-
616-
use ark_ff::{BigInteger, PrimeField};
617-
618-
use super::*;
619-
620-
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
621-
pub enum UserCommand {
622-
SignedCommand(Box<signed_command::SignedCommand>),
623-
ZkAppCommand(Box<zkapp_command::verifiable::ZkAppCommand>),
624-
}
625-
626-
pub fn compressed_to_pubkey(pubkey: &CompressedPubKey) -> mina_signer::PubKey {
627-
// Taken from https://github.com/o1-labs/proof-systems/blob/e3fc04ce87f8695288de167115dea80050ab33f4/signer/src/pubkey.rs#L95-L106
628-
let mut pt =
629-
mina_signer::CurvePoint::get_point_from_x_unchecked(pubkey.x, pubkey.is_odd).unwrap();
630-
631-
if pt.y.into_bigint().is_even() == pubkey.is_odd {
632-
pt.y = pt.y.neg();
633-
}
634-
635-
assert!(pt.is_on_curve());
636-
637-
// Safe now because we checked point pt is on curve
638-
mina_signer::PubKey::from_point_unsafe(pt)
639-
}
640-
641-
/// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/mina_base/signed_command.ml#L436>
642-
pub fn check_only_for_signature(
643-
cmd: Box<signed_command::SignedCommand>,
644-
) -> Result<valid::UserCommand, Box<signed_command::SignedCommand>> {
645-
// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/mina_base/signed_command.ml#L396>
646-
647-
let signed_command::SignedCommand {
648-
payload,
649-
signer: pubkey,
650-
signature,
651-
} = &*cmd;
652-
653-
let payload = TransactionUnionPayload::of_user_command_payload(payload);
654-
let pubkey = compressed_to_pubkey(pubkey);
655-
656-
if crate::verifier::common::legacy_verify_signature(signature, &pubkey, &payload) {
657-
Ok(valid::UserCommand::SignedCommand(cmd))
658-
} else {
659-
Err(cmd)
660-
}
661-
}
662-
}
613+
pub mod verifiable;
663614

664615
#[derive(Clone, Debug, PartialEq)]
665616
pub enum UserCommand {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use std::ops::Neg;
2+
3+
use ark_ff::{BigInteger, PrimeField};
4+
use mina_signer::CompressedPubKey;
5+
6+
use super::{
7+
signed_command, transaction_union_payload::TransactionUnionPayload, valid,
8+
zkapp_command,
9+
};
10+
11+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
12+
pub enum UserCommand {
13+
SignedCommand(Box<signed_command::SignedCommand>),
14+
ZkAppCommand(Box<zkapp_command::verifiable::ZkAppCommand>),
15+
}
16+
17+
pub fn compressed_to_pubkey(pubkey: &CompressedPubKey) -> mina_signer::PubKey {
18+
// Taken from https://github.com/o1-labs/proof-systems/blob/e3fc04ce87f8695288de167115dea80050ab33f4/signer/src/pubkey.rs#L95-L106
19+
let mut pt =
20+
mina_signer::CurvePoint::get_point_from_x_unchecked(pubkey.x, pubkey.is_odd).unwrap();
21+
22+
if pt.y.into_bigint().is_even() == pubkey.is_odd {
23+
pt.y = pt.y.neg();
24+
}
25+
26+
assert!(pt.is_on_curve());
27+
28+
// Safe now because we checked point pt is on curve
29+
mina_signer::PubKey::from_point_unsafe(pt)
30+
}
31+
32+
/// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/mina_base/signed_command.ml#L436>
33+
pub fn check_only_for_signature(
34+
cmd: Box<signed_command::SignedCommand>,
35+
) -> Result<valid::UserCommand, Box<signed_command::SignedCommand>> {
36+
// <https://github.com/MinaProtocol/mina/blob/05c2f73d0f6e4f1341286843814ce02dcb3919e0/src/lib/mina_base/signed_command.ml#L396>
37+
38+
let signed_command::SignedCommand {
39+
payload,
40+
signer: pubkey,
41+
signature,
42+
} = &*cmd;
43+
44+
let payload = TransactionUnionPayload::of_user_command_payload(payload);
45+
let pubkey = compressed_to_pubkey(pubkey);
46+
47+
if crate::verifier::common::legacy_verify_signature(signature, &pubkey, &payload) {
48+
Ok(valid::UserCommand::SignedCommand(cmd))
49+
} else {
50+
Err(cmd)
51+
}
52+
}

0 commit comments

Comments
 (0)