Skip to content

Commit 908e673

Browse files
authored
Merge pull request #748 from openmina/dedup-zkapp-logic
Deduplicate zkapp logic
2 parents 38d5c48 + 24d8406 commit 908e673

File tree

16 files changed

+1426
-2005
lines changed

16 files changed

+1426
-2005
lines changed

ledger/src/account/account.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@ impl ZkAppAccount {
884884
pub fn empty_action_state() -> Fp {
885885
cache_one!(Fp, { hash_noinputs("MinaZkappActionStateEmptyElt") })
886886
}
887+
888+
pub fn is_default(&self) -> bool {
889+
self == &Self::default()
890+
}
887891
}
888892

889893
/// An `AccountId` implementing `Ord` & `PartialOrd`, reproducing OCaml ordering.

ledger/src/generators/zkapp_command.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ use crate::{
3333
},
3434
Memo,
3535
},
36-
zkapp_logic::{self, ZkAppCommandElt},
36+
},
37+
zkapps::{
38+
non_snark::ZkappNonSnark,
39+
zkapp_logic::{update_action_state, ZkAppCommandElt},
3740
},
3841
Account, AccountId, AuthRequired, BaseLedger, ControlTag, Mask, MutableFp, MyCowMut,
3942
Permissions, ReceiptChainHash, SetVerificationKey, TokenId, VerificationKeyWire, VotingFor,
@@ -907,11 +910,12 @@ fn gen_account_update_body_components<A, B, C, D>(
907910
Some(ps) => ps.global_slot_since_genesis,
908911
};
909912

910-
let (action_state, _last_action_slot) = zkapp_logic::update_action_state(
911-
zk.action_state,
912-
actions.clone(),
913+
let (action_state, _last_action_slot) = update_action_state::<ZkappNonSnark<Mask>>(
914+
&zk.action_state,
915+
&actions,
913916
txn_global_slot,
914917
last_action_slot,
918+
&mut (),
915919
);
916920

917921
action_state

ledger/src/proofs/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4633,7 +4633,7 @@ pub(super) mod tests {
46334633
}
46344634

46354635
#[test]
4636-
fn test_zkapp_proof_sig() {
4636+
fn test_proof_zkapp_sig() {
46374637
let Ok(data) = std::fs::read(
46384638
Path::new(env!("CARGO_MANIFEST_DIR"))
46394639
.join(devnet_circuit_directory())

ledger/src/proofs/zkapp.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,12 @@ pub fn zkapp_command_witnesses_exn(
488488
zkapp_command,
489489
} = v;
490490

491-
let (txn_applied, states) = {
492-
let (partial_txn, states) = first_pass_ledger
491+
let mut states = Vec::with_capacity(16);
492+
let txn_applied = {
493+
let partial_txn = first_pass_ledger
493494
.clone()
494495
.apply_zkapp_first_pass_unchecked_with_states(
496+
&mut states,
495497
global_slot,
496498
&state_view,
497499
fee_excess,
@@ -503,7 +505,7 @@ pub fn zkapp_command_witnesses_exn(
503505

504506
second_pass_ledger
505507
.clone()
506-
.apply_zkapp_second_pass_unchecked_with_states(states, partial_txn)
508+
.apply_zkapp_second_pass_unchecked_with_states(&mut states, partial_txn)
507509
.unwrap()
508510
};
509511

@@ -745,8 +747,8 @@ pub fn zkapp_command_witnesses_exn(
745747
data: call_stack,
746748
hash: Fp::zero(), // TODO
747749
},
748-
transaction_commitment: TransactionCommitment(transaction_commitment.0),
749-
full_transaction_commitment: TransactionCommitment(full_transaction_commitment.0),
750+
transaction_commitment: TransactionCommitment(transaction_commitment),
751+
full_transaction_commitment: TransactionCommitment(full_transaction_commitment),
750752
excess,
751753
supply_increase,
752754
ledger,

ledger/src/scan_state/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub mod protocol_state;
99
pub mod scan_state;
1010
pub mod snark_work;
1111
pub mod transaction_logic;
12-
pub mod zkapp_logic;
1312
pub use parallel_scan::SpacePartition;
1413

1514
pub struct GenesisConstant {

ledger/src/scan_state/scan_state.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ use crate::{
3535
TransactionStatus,
3636
},
3737
},
38-
sparse_ledger::{LedgerIntf, SparseLedger},
38+
sparse_ledger::SparseLedger,
3939
staged_ledger::hash::AuxHash,
4040
verifier::Verifier,
41+
zkapps::non_snark::LedgerNonSnark,
4142
};
4243

4344
use self::transaction_snark::{InitStack, LedgerProof, OneOrTwo, Registers};
@@ -1434,7 +1435,7 @@ impl ScanState {
14341435
apply_first_pass_sparse_ledger: ApplyFirstSparse,
14351436
) -> Result<Pass, String>
14361437
where
1437-
L: LedgerIntf + Clone,
1438+
L: LedgerNonSnark,
14381439
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
14391440
ApplyFirst: Fn(
14401441
Slot,
@@ -1455,7 +1456,7 @@ impl ScanState {
14551456
let stop_at_first_pass = stop_at_first_pass.unwrap_or(false);
14561457

14571458
#[derive(Clone)]
1458-
enum PreviousIncompleteTxns<L: LedgerIntf + Clone> {
1459+
enum PreviousIncompleteTxns<L: LedgerNonSnark> {
14591460
Unapplied(Vec<Arc<TransactionWithWitness>>),
14601461
PartiallyApplied(Vec<(TransactionStatus, TransactionPartiallyApplied<L>)>),
14611462
}
@@ -1469,7 +1470,7 @@ impl ScanState {
14691470
get_protocol_state: F,
14701471
) -> Result<TransactionPartiallyApplied<L>, String>
14711472
where
1472-
L: LedgerIntf + Clone,
1473+
L: LedgerNonSnark,
14731474
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
14741475
Apply: Fn(
14751476
Slot,
@@ -1536,7 +1537,7 @@ impl ScanState {
15361537
apply_second_pass: ApplySecond,
15371538
) -> Result<(), String>
15381539
where
1539-
L: LedgerIntf + Clone,
1540+
L: LedgerNonSnark,
15401541
ApplySecond:
15411542
Fn(&mut L, TransactionPartiallyApplied<L>) -> Result<TransactionApplied, String>,
15421543
{
@@ -1568,7 +1569,7 @@ impl ScanState {
15681569
apply_txns_second_pass: ApplySecondPass,
15691570
) -> Result<R, String>
15701571
where
1571-
L: LedgerIntf + Clone,
1572+
L: LedgerNonSnark,
15721573
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
15731574
ApplySecondPass: Fn(Acc<L>) -> Result<R, String>,
15741575
ApplyFirstSparse: Fn(
@@ -1622,7 +1623,7 @@ impl ScanState {
16221623
block_global_slot: zkapp.global_state.block_global_slot,
16231624
};
16241625

1625-
let local_state = LocalStateEnv {
1626+
let local_state = LocalStateEnv::<L> {
16261627
stack_frame: zkapp.local_state.stack_frame,
16271628
call_stack: zkapp.local_state.call_stack,
16281629
transaction_commitment: zkapp.local_state.transaction_commitment,
@@ -1711,7 +1712,7 @@ impl ScanState {
17111712
apply_txns_second_pass: &'a impl Fn(Acc<L>) -> Result<(), String>,
17121713
) -> Result<Pass, String>
17131714
where
1714-
L: LedgerIntf + Clone + 'a,
1715+
L: LedgerNonSnark,
17151716
{
17161717
use PreviousIncompleteTxns::{PartiallyApplied, Unapplied};
17171718

@@ -1862,7 +1863,7 @@ impl ScanState {
18621863
apply_first_pass_sparse_ledger: ApplyFirstSparse,
18631864
) -> Result<Pass, String>
18641865
where
1865-
L: LedgerIntf + Clone,
1866+
L: LedgerNonSnark,
18661867
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
18671868
ApplyFirst: Fn(
18681869
Slot,
@@ -1899,7 +1900,7 @@ impl ScanState {
18991900
apply_first_pass_sparse_ledger: ApplyFirstSparse,
19001901
) -> Result<Pass, String>
19011902
where
1902-
L: LedgerIntf + Clone,
1903+
L: LedgerNonSnark,
19031904
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
19041905
ApplyFirst: Fn(
19051906
Slot,
@@ -1939,7 +1940,7 @@ impl ScanState {
19391940
apply_first_pass_sparse_ledger: ApplyFirstSparse,
19401941
) -> Result<Pass, String>
19411942
where
1942-
L: LedgerIntf + Clone,
1943+
L: LedgerNonSnark,
19431944
F: Fn(Fp) -> Result<MinaStateProtocolStateValueStableV2, String>,
19441945
ApplyFirst: Fn(
19451946
Slot,

0 commit comments

Comments
 (0)