@@ -25,7 +25,7 @@ use crate::{
25
25
Account , AccountId , ReceiptChainHash , Timing , TokenId ,
26
26
} ;
27
27
28
- use self :: zkapp_command:: { AccessedOrNot , Numeric } ;
28
+ use self :: zkapp_command:: AccessedOrNot ;
29
29
use self :: {
30
30
local_state:: { CallStack , LocalStateEnv , StackFrame } ,
31
31
protocol_state:: { GlobalState , ProtocolStateView } ,
@@ -35,7 +35,7 @@ use self::{
35
35
TransactionApplied , ZkappCommandApplied ,
36
36
} ,
37
37
transaction_union_payload:: TransactionUnionPayload ,
38
- zkapp_command:: { AccountUpdate , WithHash , ZkAppCommand , ZkAppPreconditions } ,
38
+ zkapp_command:: { AccountUpdate , WithHash , ZkAppCommand } ,
39
39
} ;
40
40
41
41
use super :: currency:: SlotSpan ;
@@ -5806,18 +5806,18 @@ pub mod local_state {
5806
5806
5807
5807
fn step_all < A , L > (
5808
5808
_constraint_constants : & ConstraintConstants ,
5809
- f : & impl Fn ( A , ( & GlobalState < L > , & LocalStateEnv < L > ) ) -> A ,
5810
- mut user_acc : A ,
5809
+ f : & impl Fn ( & mut A , & GlobalState < L > , & LocalStateEnv < L > ) ,
5810
+ user_acc : & mut A ,
5811
5811
( g_state, l_state) : ( & mut GlobalState < L > , & mut LocalStateEnv < L > ) ,
5812
- ) -> Result < ( A , Vec < Vec < TransactionFailure > > ) , String >
5812
+ ) -> Result < Vec < Vec < TransactionFailure > > , String >
5813
5813
where
5814
5814
L : LedgerNonSnark ,
5815
5815
{
5816
5816
while !l_state. stack_frame . calls . is_empty ( ) {
5817
5817
zkapps:: non_snark:: step ( g_state, l_state) ?;
5818
- user_acc = f ( user_acc, ( g_state, l_state) ) ;
5818
+ f ( user_acc, g_state, l_state) ;
5819
5819
}
5820
- Ok ( ( user_acc , l_state. failure_status_tbl . clone ( ) ) )
5820
+ Ok ( l_state. failure_status_tbl . clone ( ) )
5821
5821
}
5822
5822
5823
5823
/// apply zkapp command fee payer's while stubbing out the second pass ledger
@@ -5827,16 +5827,16 @@ pub fn apply_zkapp_command_first_pass_aux<A, F, L>(
5827
5827
constraint_constants : & ConstraintConstants ,
5828
5828
global_slot : Slot ,
5829
5829
state_view : & ProtocolStateView ,
5830
- init : A ,
5830
+ init : & mut A ,
5831
5831
f : F ,
5832
5832
fee_excess : Option < Signed < Amount > > ,
5833
5833
supply_increase : Option < Signed < Amount > > ,
5834
5834
ledger : & mut L ,
5835
5835
command : & ZkAppCommand ,
5836
- ) -> Result < ( ZkappCommandPartiallyApplied < L > , A ) , String >
5836
+ ) -> Result < ZkappCommandPartiallyApplied < L > , String >
5837
5837
where
5838
5838
L : LedgerNonSnark ,
5839
- F : Fn ( A , ( & GlobalState < L > , & LocalStateEnv < L > ) ) -> A ,
5839
+ F : Fn ( & mut A , & GlobalState < L > , & LocalStateEnv < L > ) ,
5840
5840
{
5841
5841
let fee_excess = fee_excess. unwrap_or_else ( Signed :: zero) ;
5842
5842
let supply_increase = supply_increase. unwrap_or_else ( Signed :: zero) ;
@@ -5882,7 +5882,7 @@ where
5882
5882
} ,
5883
5883
) ;
5884
5884
5885
- let user_acc = f ( init, ( & global_state, & local_state) ) ;
5885
+ f ( init, & global_state, & local_state) ;
5886
5886
let account_updates = command. all_account_updates ( ) ;
5887
5887
5888
5888
zkapps:: non_snark:: start (
@@ -5911,7 +5911,7 @@ where
5911
5911
local_state,
5912
5912
} ;
5913
5913
5914
- Ok ( ( res, user_acc ) )
5914
+ Ok ( res)
5915
5915
}
5916
5916
5917
5917
fn apply_zkapp_command_first_pass < L > (
@@ -5926,12 +5926,13 @@ fn apply_zkapp_command_first_pass<L>(
5926
5926
where
5927
5927
L : LedgerNonSnark ,
5928
5928
{
5929
- let ( partial_stmt, _user_acc) = apply_zkapp_command_first_pass_aux (
5929
+ let mut acc = ( ) ;
5930
+ let partial_stmt = apply_zkapp_command_first_pass_aux (
5930
5931
constraint_constants,
5931
5932
global_slot,
5932
5933
state_view,
5933
- None ,
5934
- |_acc, ( g , l ) | Some ( ( g . clone ( ) , l . clone ( ) ) ) ,
5934
+ & mut acc ,
5935
+ |_acc, _g , _l| { } ,
5935
5936
fee_excess,
5936
5937
supply_increase,
5937
5938
ledger,
@@ -5943,14 +5944,14 @@ where
5943
5944
5944
5945
pub fn apply_zkapp_command_second_pass_aux < A , F , L > (
5945
5946
constraint_constants : & ConstraintConstants ,
5946
- init : A ,
5947
+ init : & mut A ,
5947
5948
f : F ,
5948
5949
ledger : & mut L ,
5949
5950
c : ZkappCommandPartiallyApplied < L > ,
5950
- ) -> Result < ( ZkappCommandApplied , A ) , String >
5951
+ ) -> Result < ZkappCommandApplied , String >
5951
5952
where
5952
5953
L : LedgerNonSnark ,
5953
- F : Fn ( A , ( & GlobalState < L > , & LocalStateEnv < L > ) ) -> A ,
5954
+ F : Fn ( & mut A , & GlobalState < L > , & LocalStateEnv < L > ) ,
5954
5955
{
5955
5956
// let perform = |eff: Eff<L>| Env::perform(eff);
5956
5957
@@ -6041,10 +6042,10 @@ where
6041
6042
}
6042
6043
} ;
6043
6044
6044
- let acc = f ( init, ( & global_state, & local_state) ) ;
6045
+ f ( init, & global_state, & local_state) ;
6045
6046
let start = ( & mut global_state, & mut local_state) ;
6046
6047
6047
- let ( user_acc , reversed_failure_status_tbl) = step_all ( constraint_constants, & f, acc , start) ?;
6048
+ let reversed_failure_status_tbl = step_all ( constraint_constants, & f, init , start) ?;
6048
6049
6049
6050
let failure_status_tbl = reversed_failure_status_tbl
6050
6051
. into_iter ( )
@@ -6091,21 +6092,18 @@ where
6091
6092
6092
6093
let new_accounts_is_empty = new_accounts. is_empty ( ) ;
6093
6094
6094
- let valid_result = Ok ( (
6095
- ZkappCommandApplied {
6096
- accounts : accounts ( ) ,
6097
- command : WithStatus {
6098
- data : c. command ,
6099
- status : if successfully_applied {
6100
- TransactionStatus :: Applied
6101
- } else {
6102
- TransactionStatus :: Failed ( failure_status_tbl)
6103
- } ,
6095
+ let valid_result = Ok ( ZkappCommandApplied {
6096
+ accounts : accounts ( ) ,
6097
+ command : WithStatus {
6098
+ data : c. command ,
6099
+ status : if successfully_applied {
6100
+ TransactionStatus :: Applied
6101
+ } else {
6102
+ TransactionStatus :: Failed ( failure_status_tbl)
6104
6103
} ,
6105
- new_accounts,
6106
6104
} ,
6107
- user_acc ,
6108
- ) ) ;
6105
+ new_accounts ,
6106
+ } ) ;
6109
6107
6110
6108
if successfully_applied {
6111
6109
valid_result
@@ -6137,27 +6135,32 @@ fn apply_zkapp_command_second_pass<L>(
6137
6135
where
6138
6136
L : LedgerNonSnark ,
6139
6137
{
6140
- let ( x, _) =
6141
- apply_zkapp_command_second_pass_aux ( constraint_constants, ( ) , |a, _| a, ledger, c) ?;
6138
+ let x = apply_zkapp_command_second_pass_aux (
6139
+ constraint_constants,
6140
+ & mut ( ) ,
6141
+ |_, _, _| { } ,
6142
+ ledger,
6143
+ c,
6144
+ ) ?;
6142
6145
Ok ( x)
6143
6146
}
6144
6147
6145
6148
fn apply_zkapp_command_unchecked_aux < A , F , L > (
6146
6149
constraint_constants : & ConstraintConstants ,
6147
6150
global_slot : Slot ,
6148
6151
state_view : & ProtocolStateView ,
6149
- init : A ,
6152
+ init : & mut A ,
6150
6153
f : F ,
6151
6154
fee_excess : Option < Signed < Amount > > ,
6152
6155
supply_increase : Option < Signed < Amount > > ,
6153
6156
ledger : & mut L ,
6154
6157
command : & ZkAppCommand ,
6155
- ) -> Result < ( ZkappCommandApplied , A ) , String >
6158
+ ) -> Result < ZkappCommandApplied , String >
6156
6159
where
6157
6160
L : LedgerNonSnark ,
6158
- F : Fn ( A , ( & GlobalState < L > , & LocalStateEnv < L > ) ) -> A ,
6161
+ F : Fn ( & mut A , & GlobalState < L > , & LocalStateEnv < L > ) ,
6159
6162
{
6160
- let ( partial_stmt, user_acc ) = apply_zkapp_command_first_pass_aux (
6163
+ let partial_stmt = apply_zkapp_command_first_pass_aux (
6161
6164
constraint_constants,
6162
6165
global_slot,
6163
6166
state_view,
@@ -6169,7 +6172,7 @@ where
6169
6172
command,
6170
6173
) ?;
6171
6174
6172
- apply_zkapp_command_second_pass_aux ( constraint_constants, user_acc , f, ledger, partial_stmt)
6175
+ apply_zkapp_command_second_pass_aux ( constraint_constants, init , & f, ledger, partial_stmt)
6173
6176
}
6174
6177
6175
6178
fn apply_zkapp_command_unchecked < L > (
@@ -6192,10 +6195,13 @@ where
6192
6195
command,
6193
6196
) ?;
6194
6197
6195
- let ( account_update_applied, state_res) = apply_zkapp_command_second_pass_aux (
6198
+ let mut state_res = None ;
6199
+ let account_update_applied = apply_zkapp_command_second_pass_aux (
6196
6200
constraint_constants,
6197
- None ,
6198
- |_acc, ( global_state, local_state) | Some ( ( local_state. clone ( ) , global_state. fee_excess ) ) ,
6201
+ & mut state_res,
6202
+ |acc, global_state, local_state| {
6203
+ * acc = Some ( ( local_state. clone ( ) , global_state. fee_excess ) )
6204
+ } ,
6199
6205
ledger,
6200
6206
zkapp_partially_applied,
6201
6207
) ?;
0 commit comments