Skip to content

Commit ec74383

Browse files
committed
Ledger/transaction_logic: extract zkapp_statement module to separate file
Extract the zkapp_statement module from transaction_logic/mod.rs into its own file. This module contains the TransactionCommitment and ZkappStatement types used for zkApp transaction commitments. Changes: - Extract zkapp_statement module to transaction_logic/zkapp_statement.rs - Use explicit imports instead of 'use super::*' - Import zkapp_command module as 'self' to access AccountUpdateRef trait - Update mod.rs to reference the new module file
1 parent 55e674c commit ec74383

File tree

2 files changed

+97
-99
lines changed

2 files changed

+97
-99
lines changed

ledger/src/scan_state/transaction_logic/mod.rs

Lines changed: 3 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use std::{
66
use ark_ff::Zero;
77
use itertools::{FoldWhile, Itertools};
88
use mina_core::constants::ConstraintConstants;
9-
use mina_hasher::{Fp, Hashable, ROInput};
9+
use mina_hasher::Fp;
1010
use mina_macros::SerdeYojsonEnum;
1111
use mina_p2p_messages::{
1212
bigint::InvalidBigInt,
1313
binprot,
1414
v2::{MinaBaseUserCommandStableV2, MinaTransactionTransactionStableV2},
1515
};
16-
use mina_signer::{CompressedPubKey, NetworkId};
16+
use mina_signer::CompressedPubKey;
1717
use poseidon::hash::{
1818
hash_with_kimchi,
1919
params::{CODA_RECEIPT_UC, MINA_ZKAPP_MEMO},
@@ -608,103 +608,7 @@ impl Memo {
608608
pub mod signed_command;
609609

610610
pub mod zkapp_command;
611-
pub mod zkapp_statement {
612-
use poseidon::hash::params::MINA_ACCOUNT_UPDATE_CONS;
613-
614-
use super::{
615-
zkapp_command::{CallForest, Tree},
616-
*,
617-
};
618-
619-
#[derive(Copy, Clone, Debug, derive_more::Deref, derive_more::From)]
620-
pub struct TransactionCommitment(pub Fp);
621-
622-
impl TransactionCommitment {
623-
/// <https://github.com/MinaProtocol/mina/blob/3753a8593cc1577bcf4da16620daf9946d88e8e5/src/lib/mina_base/zkapp_command.ml#L1365>
624-
pub fn create(account_updates_hash: Fp) -> Self {
625-
Self(account_updates_hash)
626-
}
627-
628-
/// <https://github.com/MinaProtocol/mina/blob/3753a8593cc1577bcf4da16620daf9946d88e8e5/src/lib/mina_base/zkapp_command.ml#L1368>
629-
pub fn create_complete(&self, memo_hash: Fp, fee_payer_hash: Fp) -> Self {
630-
Self(hash_with_kimchi(
631-
&MINA_ACCOUNT_UPDATE_CONS,
632-
&[memo_hash, fee_payer_hash, self.0],
633-
))
634-
}
635-
636-
pub fn empty() -> Self {
637-
Self(Fp::zero())
638-
}
639-
}
640-
641-
impl Hashable for TransactionCommitment {
642-
type D = NetworkId;
643-
644-
fn to_roinput(&self) -> ROInput {
645-
let mut roi = ROInput::new();
646-
roi = roi.append_field(self.0);
647-
roi
648-
}
649-
650-
fn domain_string(network_id: NetworkId) -> Option<String> {
651-
match network_id {
652-
NetworkId::MAINNET => mina_core::network::mainnet::SIGNATURE_PREFIX,
653-
NetworkId::TESTNET => mina_core::network::devnet::SIGNATURE_PREFIX,
654-
}
655-
.to_string()
656-
.into()
657-
}
658-
}
659-
660-
#[derive(Clone, Debug)]
661-
pub struct ZkappStatement {
662-
pub account_update: TransactionCommitment,
663-
pub calls: TransactionCommitment,
664-
}
665-
666-
impl ZkappStatement {
667-
pub fn to_field_elements(&self) -> Vec<Fp> {
668-
let Self {
669-
account_update,
670-
calls,
671-
} = self;
672-
673-
vec![**account_update, **calls]
674-
}
675-
676-
pub fn of_tree<AccUpdate: Clone + zkapp_command::AccountUpdateRef>(
677-
tree: &Tree<AccUpdate>,
678-
) -> Self {
679-
let Tree {
680-
account_update: _,
681-
account_update_digest,
682-
calls,
683-
} = tree;
684-
685-
Self {
686-
account_update: TransactionCommitment(account_update_digest.get().unwrap()),
687-
calls: TransactionCommitment(calls.hash()),
688-
}
689-
}
690-
691-
pub fn zkapp_statements_of_forest_prime<Data: Clone>(
692-
forest: CallForest<(AccountUpdate, Data)>,
693-
) -> CallForest<(AccountUpdate, (Data, Self))> {
694-
forest.map_with_trees_to(|(account_update, data), tree| {
695-
(account_update.clone(), (data.clone(), Self::of_tree(tree)))
696-
})
697-
}
698-
699-
fn zkapp_statements_of_forest(
700-
forest: CallForest<AccountUpdate>,
701-
) -> CallForest<(AccountUpdate, Self)> {
702-
forest.map_with_trees_to(|account_update, tree| {
703-
(account_update.clone(), Self::of_tree(tree))
704-
})
705-
}
706-
}
707-
}
611+
pub mod zkapp_statement;
708612

709613
pub mod verifiable {
710614
use std::ops::Neg;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
use ark_ff::Zero;
2+
use mina_hasher::{Fp, Hashable, ROInput};
3+
use mina_signer::NetworkId;
4+
use poseidon::hash::{hash_with_kimchi, params::MINA_ACCOUNT_UPDATE_CONS};
5+
6+
use super::zkapp_command::{self, AccountUpdate, CallForest, Tree};
7+
8+
#[derive(Copy, Clone, Debug, derive_more::Deref, derive_more::From)]
9+
pub struct TransactionCommitment(pub Fp);
10+
11+
impl TransactionCommitment {
12+
/// <https://github.com/MinaProtocol/mina/blob/3753a8593cc1577bcf4da16620daf9946d88e8e5/src/lib/mina_base/zkapp_command.ml#L1365>
13+
pub fn create(account_updates_hash: Fp) -> Self {
14+
Self(account_updates_hash)
15+
}
16+
17+
/// <https://github.com/MinaProtocol/mina/blob/3753a8593cc1577bcf4da16620daf9946d88e8e5/src/lib/mina_base/zkapp_command.ml#L1368>
18+
pub fn create_complete(&self, memo_hash: Fp, fee_payer_hash: Fp) -> Self {
19+
Self(hash_with_kimchi(
20+
&MINA_ACCOUNT_UPDATE_CONS,
21+
&[memo_hash, fee_payer_hash, self.0],
22+
))
23+
}
24+
25+
pub fn empty() -> Self {
26+
Self(Fp::zero())
27+
}
28+
}
29+
30+
impl Hashable for TransactionCommitment {
31+
type D = NetworkId;
32+
33+
fn to_roinput(&self) -> ROInput {
34+
let mut roi = ROInput::new();
35+
roi = roi.append_field(self.0);
36+
roi
37+
}
38+
39+
fn domain_string(network_id: NetworkId) -> Option<String> {
40+
match network_id {
41+
NetworkId::MAINNET => mina_core::network::mainnet::SIGNATURE_PREFIX,
42+
NetworkId::TESTNET => mina_core::network::devnet::SIGNATURE_PREFIX,
43+
}
44+
.to_string()
45+
.into()
46+
}
47+
}
48+
49+
#[derive(Clone, Debug)]
50+
pub struct ZkappStatement {
51+
pub account_update: TransactionCommitment,
52+
pub calls: TransactionCommitment,
53+
}
54+
55+
impl ZkappStatement {
56+
pub fn to_field_elements(&self) -> Vec<Fp> {
57+
let Self {
58+
account_update,
59+
calls,
60+
} = self;
61+
62+
vec![**account_update, **calls]
63+
}
64+
65+
pub fn of_tree<AccUpdate: Clone + zkapp_command::AccountUpdateRef>(
66+
tree: &Tree<AccUpdate>,
67+
) -> Self {
68+
let Tree {
69+
account_update: _,
70+
account_update_digest,
71+
calls,
72+
} = tree;
73+
74+
Self {
75+
account_update: TransactionCommitment(account_update_digest.get().unwrap()),
76+
calls: TransactionCommitment(calls.hash()),
77+
}
78+
}
79+
80+
pub fn zkapp_statements_of_forest_prime<Data: Clone>(
81+
forest: CallForest<(AccountUpdate, Data)>,
82+
) -> CallForest<(AccountUpdate, (Data, Self))> {
83+
forest.map_with_trees_to(|(account_update, data), tree| {
84+
(account_update.clone(), (data.clone(), Self::of_tree(tree)))
85+
})
86+
}
87+
88+
fn zkapp_statements_of_forest(
89+
forest: CallForest<AccountUpdate>,
90+
) -> CallForest<(AccountUpdate, Self)> {
91+
forest
92+
.map_with_trees_to(|account_update, tree| (account_update.clone(), Self::of_tree(tree)))
93+
}
94+
}

0 commit comments

Comments
 (0)