Skip to content

Commit 3b3f383

Browse files
committed
Add LedgerNonSnark
1 parent 4943634 commit 3b3f383

File tree

4 files changed

+42
-166
lines changed

4 files changed

+42
-166
lines changed

ledger/src/scan_state/scan_state.rs

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::{
3939
sparse_ledger::SparseLedger,
4040
staged_ledger::hash::AuxHash,
4141
verifier::Verifier,
42-
zkapps::intefaces::LedgerInterface,
42+
zkapps::{intefaces::LedgerInterface, non_snark::LedgerNonSnark},
4343
Account,
4444
};
4545

@@ -1437,7 +1437,7 @@ impl ScanState {
14371437
apply_first_pass_sparse_ledger: ApplyFirstSparse,
14381438
) -> Result<Pass, String>
14391439
where
1440-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
1440+
L: LedgerNonSnark,
14411441
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
14421442
ApplyFirst: Fn(
14431443
Slot,
@@ -1458,9 +1458,7 @@ impl ScanState {
14581458
let stop_at_first_pass = stop_at_first_pass.unwrap_or(false);
14591459

14601460
#[derive(Clone)]
1461-
enum PreviousIncompleteTxns<
1462-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
1463-
> {
1461+
enum PreviousIncompleteTxns<L: LedgerNonSnark> {
14641462
Unapplied(Vec<Arc<TransactionWithWitness>>),
14651463
PartiallyApplied(Vec<(TransactionStatus, TransactionPartiallyApplied<L>)>),
14661464
}
@@ -1474,12 +1472,7 @@ impl ScanState {
14741472
get_protocol_state: F,
14751473
) -> Result<TransactionPartiallyApplied<L>, String>
14761474
where
1477-
L: LedgerInterface<
1478-
W = (),
1479-
Bool = bool,
1480-
Account = Account,
1481-
AccountUpdate = AccountUpdate,
1482-
>,
1475+
L: LedgerNonSnark,
14831476
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
14841477
Apply: Fn(
14851478
Slot,
@@ -1546,12 +1539,7 @@ impl ScanState {
15461539
apply_second_pass: ApplySecond,
15471540
) -> Result<(), String>
15481541
where
1549-
L: LedgerInterface<
1550-
W = (),
1551-
Bool = bool,
1552-
Account = Account,
1553-
AccountUpdate = AccountUpdate,
1554-
>,
1542+
L: LedgerNonSnark,
15551543
ApplySecond:
15561544
Fn(&mut L, TransactionPartiallyApplied<L>) -> Result<TransactionApplied, String>,
15571545
{
@@ -1583,12 +1571,7 @@ impl ScanState {
15831571
apply_txns_second_pass: ApplySecondPass,
15841572
) -> Result<R, String>
15851573
where
1586-
L: LedgerInterface<
1587-
W = (),
1588-
Bool = bool,
1589-
Account = Account,
1590-
AccountUpdate = AccountUpdate,
1591-
>,
1574+
L: LedgerNonSnark,
15921575
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
15931576
ApplySecondPass: Fn(Acc<L>) -> Result<R, String>,
15941577
ApplyFirstSparse: Fn(
@@ -1731,12 +1714,7 @@ impl ScanState {
17311714
apply_txns_second_pass: &'a impl Fn(Acc<L>) -> Result<(), String>,
17321715
) -> Result<Pass, String>
17331716
where
1734-
L: LedgerInterface<
1735-
W = (),
1736-
Bool = bool,
1737-
Account = Account,
1738-
AccountUpdate = AccountUpdate,
1739-
>,
1717+
L: LedgerNonSnark,
17401718
{
17411719
use PreviousIncompleteTxns::{PartiallyApplied, Unapplied};
17421720

@@ -1887,7 +1865,7 @@ impl ScanState {
18871865
apply_first_pass_sparse_ledger: ApplyFirstSparse,
18881866
) -> Result<Pass, String>
18891867
where
1890-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
1868+
L: LedgerNonSnark,
18911869
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
18921870
ApplyFirst: Fn(
18931871
Slot,
@@ -1924,7 +1902,7 @@ impl ScanState {
19241902
apply_first_pass_sparse_ledger: ApplyFirstSparse,
19251903
) -> Result<Pass, String>
19261904
where
1927-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
1905+
L: LedgerNonSnark,
19281906
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
19291907
ApplyFirst: Fn(
19301908
Slot,
@@ -1964,7 +1942,7 @@ impl ScanState {
19641942
apply_first_pass_sparse_ledger: ApplyFirstSparse,
19651943
) -> Result<Pass, String>
19661944
where
1967-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
1945+
L: LedgerNonSnark,
19681946
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
19691947
ApplyFirst: Fn(
19701948
Slot,

ledger/src/scan_state/transaction_logic.rs

Lines changed: 15 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use openmina_macros::SerdeYojsonEnum;
1414
use crate::proofs::witness::Witness;
1515
use crate::scan_state::transaction_logic::transaction_partially_applied::FullyApplied;
1616
use crate::scan_state::transaction_logic::zkapp_command::MaybeWithStatus;
17-
use crate::zkapps::intefaces::LedgerInterface;
18-
use crate::zkapps::non_snark::ZkappNonSnark;
17+
use crate::zkapps::non_snark::{LedgerNonSnark, ZkappNonSnark};
1918
use crate::{
2019
hash_with_kimchi, zkapps, AccountIdOrderable, BaseLedger, ControlTag, Inputs,
2120
VerificationKeyWire,
@@ -5624,7 +5623,7 @@ pub mod local_state {
56245623

56255624
// impl<L> LocalStateEnv<L>
56265625
// where
5627-
// L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
5626+
// L: LedgerNonSnark,
56285627
// {
56295628
// pub fn add_new_failure_status_bucket(&self) -> Self {
56305629
// let mut failure_status_tbl = self.failure_status_tbl.clone();
@@ -5805,114 +5804,14 @@ pub mod local_state {
58055804
}
58065805
}
58075806

5808-
// let equal' (t1 : t) (t2 : t) =
5809-
// let ( ! ) f x y = Impl.run_checked (f x y) in
5810-
// let f eq acc f = Core_kernel.Field.(eq (get f t1) (get f t2)) :: acc in
5811-
// Mina_transaction_logic.Zkapp_command_logic.Local_state.Fields.fold ~init:[]
5812-
// ~stack_frame:(f Stack_frame.Digest.Checked.equal)
5813-
// ~call_stack:(f Call_stack_digest.Checked.equal)
5814-
// ~transaction_commitment:(f Field.equal)
5815-
// ~full_transaction_commitment:(f Field.equal)
5816-
// ~excess:(f !Currency.Amount.Signed.Checked.equal)
5817-
// ~supply_increase:(f !Currency.Amount.Signed.Checked.equal)
5818-
// ~ledger:(f !Ledger_hash.equal_var) ~success:(f Impl.Boolean.equal)
5819-
// ~account_update_index:(f !Mina_numbers.Index.Checked.equal)
5820-
// ~failure_status_tbl:(f (fun () () -> Impl.Boolean.true_))
5821-
// ~will_succeed:(f Impl.Boolean.equal)
5822-
5823-
pub enum Eff<
5824-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
5825-
> {
5826-
CheckValidWhilePrecondition(Numeric<Slot>, GlobalState<L>),
5827-
CheckAccountPrecondition(AccountUpdate, Account, bool, LocalStateEnv<L>),
5828-
CheckProtocolStatePrecondition(Box<ZkAppPreconditions>, GlobalState<L>),
5829-
InitAccount(AccountUpdate, Account),
5830-
}
5831-
5832-
pub struct Env<
5833-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
5834-
> {
5835-
account_update: AccountUpdate,
5836-
zkapp_command: ZkAppCommand,
5837-
account: Account,
5838-
ledger: L,
5839-
amount: Amount,
5840-
signed_amount: Signed<Amount>,
5841-
bool: bool,
5842-
token_id: TokenId,
5843-
global_state: GlobalState<L>,
5844-
local_state: LocalStateEnv<L>,
5845-
protocol_state_precondition: ZkAppPreconditions,
5846-
valid_while_precondition: Numeric<Slot>,
5847-
transaction_commitment: Fp,
5848-
full_transaction_commitment: Fp,
5849-
field: Fp,
5850-
failure: Option<TransactionFailure>,
5851-
}
5852-
5853-
pub enum PerformResult<
5854-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
5855-
> {
5856-
Bool(bool),
5857-
LocalState(Box<LocalStateEnv<L>>),
5858-
Account(Box<Account>),
5859-
}
5860-
5861-
impl<L> PerformResult<L>
5862-
where
5863-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
5864-
{
5865-
pub fn to_bool(self) -> bool {
5866-
match self {
5867-
PerformResult::Bool(v) => v,
5868-
_ => panic!("Not a bool"),
5869-
}
5870-
}
5871-
}
5872-
5873-
// impl<L> Env<L>
5874-
// where
5875-
// L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
5876-
// {
5877-
// pub fn perform(eff: Eff<L>) -> PerformResult<L> {
5878-
// match eff {
5879-
// Eff::CheckValidWhilePrecondition(valid_while, global_state) => PerformResult::Bool(
5880-
// valid_while
5881-
// .out_zcheck(
5882-
// || "valid_while_precondition".to_string(),
5883-
// &global_state.block_global_slot,
5884-
// )
5885-
// .is_ok(),
5886-
// ),
5887-
// Eff::CheckProtocolStatePrecondition(pred, global_state) => {
5888-
// PerformResult::Bool(pred.out_zcheck(&global_state.protocol_state).is_ok())
5889-
// }
5890-
// Eff::CheckAccountPrecondition(account_update, account, new_account, local_state) => {
5891-
// let local_state = {
5892-
// let precondition_account = &account_update.body.preconditions.account.0;
5893-
// let mut _local_state = local_state;
5894-
// let check = |failure, b| {
5895-
// _local_state = _local_state.add_check(failure, b);
5896-
// };
5897-
// precondition_account.out_zcheck(new_account, check, &account);
5898-
// _local_state
5899-
// };
5900-
// PerformResult::LocalState(Box::new(local_state))
5901-
// }
5902-
// Eff::InitAccount(_account_update, a) => PerformResult::Account(Box::new(a)),
5903-
// }
5904-
// }
5905-
// }
5906-
59075807
fn step_all<A, L>(
59085808
_constraint_constants: &ConstraintConstants,
59095809
f: &impl Fn(A, (&GlobalState<L>, &LocalStateEnv<L>)) -> A,
5910-
// handler: &Handler<L>,
59115810
mut user_acc: A,
59125811
(g_state, l_state): (&mut GlobalState<L>, &mut LocalStateEnv<L>),
59135812
) -> Result<(A, Vec<Vec<TransactionFailure>>), String>
59145813
where
5915-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
5814+
L: LedgerNonSnark,
59165815
{
59175816
while !l_state.stack_frame.calls.is_empty() {
59185817
zkapps::non_snark::step(g_state, l_state)?;
@@ -5936,7 +5835,7 @@ pub fn apply_zkapp_command_first_pass_aux<A, F, L>(
59365835
command: &ZkAppCommand,
59375836
) -> Result<(ZkappCommandPartiallyApplied<L>, A), String>
59385837
where
5939-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
5838+
L: LedgerNonSnark,
59405839
F: Fn(A, (&GlobalState<L>, &LocalStateEnv<L>)) -> A,
59415840
{
59425841
let fee_excess = fee_excess.unwrap_or_else(Signed::zero);
@@ -6025,7 +5924,7 @@ fn apply_zkapp_command_first_pass<L>(
60255924
command: &ZkAppCommand,
60265925
) -> Result<ZkappCommandPartiallyApplied<L>, String>
60275926
where
6028-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
5927+
L: LedgerNonSnark,
60295928
{
60305929
let (partial_stmt, _user_acc) = apply_zkapp_command_first_pass_aux(
60315930
constraint_constants,
@@ -6050,7 +5949,7 @@ pub fn apply_zkapp_command_second_pass_aux<A, F, L>(
60505949
c: ZkappCommandPartiallyApplied<L>,
60515950
) -> Result<(ZkappCommandApplied, A), String>
60525951
where
6053-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
5952+
L: LedgerNonSnark,
60545953
F: Fn(A, (&GlobalState<L>, &LocalStateEnv<L>)) -> A,
60555954
{
60565955
// let perform = |eff: Eff<L>| Env::perform(eff);
@@ -6236,7 +6135,7 @@ fn apply_zkapp_command_second_pass<L>(
62366135
c: ZkappCommandPartiallyApplied<L>,
62376136
) -> Result<ZkappCommandApplied, String>
62386137
where
6239-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
6138+
L: LedgerNonSnark,
62406139
{
62416140
let (x, _) =
62426141
apply_zkapp_command_second_pass_aux(constraint_constants, (), |a, _| a, ledger, c)?;
@@ -6255,7 +6154,7 @@ fn apply_zkapp_command_unchecked_aux<A, F, L>(
62556154
command: &ZkAppCommand,
62566155
) -> Result<(ZkappCommandApplied, A), String>
62576156
where
6258-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
6157+
L: LedgerNonSnark,
62596158
F: Fn(A, (&GlobalState<L>, &LocalStateEnv<L>)) -> A,
62606159
{
62616160
let (partial_stmt, user_acc) = apply_zkapp_command_first_pass_aux(
@@ -6281,7 +6180,7 @@ fn apply_zkapp_command_unchecked<L>(
62816180
command: &ZkAppCommand,
62826181
) -> Result<(ZkappCommandApplied, (LocalStateEnv<L>, Signed<Amount>)), String>
62836182
where
6284-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
6183+
L: LedgerNonSnark,
62856184
{
62866185
let zkapp_partially_applied: ZkappCommandPartiallyApplied<L> = apply_zkapp_command_first_pass(
62876186
constraint_constants,
@@ -6312,9 +6211,7 @@ pub mod transaction_partially_applied {
63126211
};
63136212

63146213
#[derive(Clone, Debug)]
6315-
pub struct ZkappCommandPartiallyApplied<
6316-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
6317-
> {
6214+
pub struct ZkappCommandPartiallyApplied<L: LedgerNonSnark> {
63186215
pub command: ZkAppCommand,
63196216
pub previous_hash: Fp,
63206217
pub original_first_pass_account_states:
@@ -6332,9 +6229,7 @@ pub mod transaction_partially_applied {
63326229
}
63336230

63346231
#[derive(Clone, Debug)]
6335-
pub enum TransactionPartiallyApplied<
6336-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
6337-
> {
6232+
pub enum TransactionPartiallyApplied<L: LedgerNonSnark> {
63386233
SignedCommand(FullyApplied<SignedCommandApplied>),
63396234
ZkappCommand(Box<ZkappCommandPartiallyApplied<L>>),
63406235
FeeTransfer(FullyApplied<FeeTransferApplied>),
@@ -6343,7 +6238,7 @@ pub mod transaction_partially_applied {
63436238

63446239
impl<L> TransactionPartiallyApplied<L>
63456240
where
6346-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
6241+
L: LedgerNonSnark,
63476242
{
63486243
pub fn command(self) -> Transaction {
63496244
use Transaction as T;
@@ -6370,7 +6265,7 @@ pub fn apply_transaction_first_pass<L>(
63706265
transaction: &Transaction,
63716266
) -> Result<TransactionPartiallyApplied<L>, String>
63726267
where
6373-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
6268+
L: LedgerNonSnark,
63746269
{
63756270
use Transaction::*;
63766271
use UserCommand::*;
@@ -6430,7 +6325,7 @@ pub fn apply_transaction_second_pass<L>(
64306325
partial_transaction: TransactionPartiallyApplied<L>,
64316326
) -> Result<TransactionApplied, String>
64326327
where
6433-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
6328+
L: LedgerNonSnark,
64346329
{
64356330
use TransactionPartiallyApplied as P;
64366331

@@ -6481,7 +6376,7 @@ pub fn apply_transactions<L>(
64816376
txns: &[Transaction],
64826377
) -> Result<Vec<TransactionApplied>, String>
64836378
where
6484-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
6379+
L: LedgerNonSnark,
64856380
{
64866381
let first_pass: Vec<_> = txns
64876382
.iter()

ledger/src/staged_ledger/staged_ledger.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::{
3737
split_at, split_at_vec,
3838
staged_ledger::{pre_diff_info, resources::IncreaseBy, transaction_validator},
3939
verifier::{Verifier, VerifierError},
40-
zkapps::intefaces::LedgerInterface,
40+
zkapps::{intefaces::LedgerInterface, non_snark::LedgerNonSnark},
4141
Account, AccountId, BaseLedger, Mask, TokenId,
4242
};
4343

@@ -80,9 +80,7 @@ pub enum StagedLedgerError {
8080

8181
const ZKAPP_LIMIT_PER_BLOCK: Option<usize> = None;
8282

83-
pub struct PreStatement<
84-
L: LedgerInterface<W = (), Bool = bool, Account = Account, AccountUpdate = AccountUpdate>,
85-
> {
83+
pub struct PreStatement<L: LedgerNonSnark> {
8684
partially_applied_transaction: TransactionPartiallyApplied<L>,
8785
expected_status: TransactionStatus,
8886
accounts_accessed: Vec<AccountId>,

0 commit comments

Comments
 (0)