@@ -1541,7 +1541,7 @@ pub mod zkapp_command {
1541
1541
type B ;
1542
1542
1543
1543
/// zkapp check
1544
- fn zcheck ( & self , label : String , x : Self :: B ) -> Result < ( ) , String > ;
1544
+ fn zcheck < F : Fn ( ) -> String > ( & self , label : F , x : & Self :: B ) -> Result < ( ) , String > ;
1545
1545
}
1546
1546
1547
1547
impl < T > OutSnarkCheck for T
@@ -1552,11 +1552,11 @@ pub mod zkapp_command {
1552
1552
type B = T ;
1553
1553
1554
1554
/// zkapp check
1555
- fn zcheck ( & self , label : String , rhs : Self :: B ) -> Result < ( ) , String > {
1556
- if * self == rhs {
1555
+ fn zcheck < F : Fn ( ) -> String > ( & self , label : F , rhs : & Self :: B ) -> Result < ( ) , String > {
1556
+ if self == rhs {
1557
1557
Ok ( ( ) )
1558
1558
} else {
1559
- Err ( format ! ( "Equality check failed: {}" , label) )
1559
+ Err ( format ! ( "Equality check failed: {}" , label( ) ) )
1560
1560
}
1561
1561
}
1562
1562
}
@@ -1625,15 +1625,15 @@ pub mod zkapp_command {
1625
1625
type B = T ;
1626
1626
1627
1627
/// zkapp check
1628
- fn zcheck ( & self , label : String , rhs : Self :: B ) -> Result < ( ) , String > {
1628
+ fn zcheck < F : Fn ( ) -> String > ( & self , label : F , rhs : & Self :: B ) -> Result < ( ) , String > {
1629
1629
/*println!(
1630
1630
"bounds check lower {:?} rhs {:?} upper {:?}",
1631
1631
self.lower, rhs, self.upper
1632
1632
);*/
1633
- if self . lower <= rhs && rhs <= self . upper {
1633
+ if & self . lower <= rhs && rhs <= & self . upper {
1634
1634
Ok ( ( ) )
1635
1635
} else {
1636
- Err ( format ! ( "Bounds check failed: {}" , label) )
1636
+ Err ( format ! ( "Bounds check failed: {}" , label( ) ) )
1637
1637
}
1638
1638
}
1639
1639
}
@@ -1740,7 +1740,7 @@ pub mod zkapp_command {
1740
1740
T : OutSnarkCheck < A = T > ,
1741
1741
{
1742
1742
/// zkapp check
1743
- pub fn zcheck ( & self , label : String , rhs : T :: B ) -> Result < ( ) , String > {
1743
+ pub fn zcheck < F : Fn ( ) -> String > ( & self , label : F , rhs : & T :: B ) -> Result < ( ) , String > {
1744
1744
// println!("[rust] check {}, {:?}", label, ret);
1745
1745
match self {
1746
1746
Self :: Ignore => Ok ( ( ) ) ,
@@ -1806,9 +1806,12 @@ pub mod zkapp_command {
1806
1806
1807
1807
impl EpochLedger {
1808
1808
pub fn epoch_ledger ( & self , t : & protocol_state:: EpochLedger < Fp > ) -> Result < ( ) , String > {
1809
- self . hash . zcheck ( "epoch_ledger_hash" . to_string ( ) , t. hash ) ?;
1810
- self . total_currency
1811
- . zcheck ( "epoch_ledger_total_currency" . to_string ( ) , t. total_currency )
1809
+ self . hash
1810
+ . zcheck ( || "epoch_ledger_hash" . to_string ( ) , & t. hash ) ?;
1811
+ self . total_currency . zcheck (
1812
+ || "epoch_ledger_total_currency" . to_string ( ) ,
1813
+ & t. total_currency ,
1814
+ )
1812
1815
}
1813
1816
}
1814
1817
@@ -1913,15 +1916,15 @@ pub mod zkapp_command {
1913
1916
self . ledger . epoch_ledger ( & t. ledger ) ?;
1914
1917
// ignore seed
1915
1918
self . start_checkpoint . zcheck (
1916
- format ! ( "{}_{}" , label, "start_checkpoint" ) ,
1917
- t. start_checkpoint ,
1919
+ || format ! ( "{}_{}" , label, "start_checkpoint" ) ,
1920
+ & t. start_checkpoint ,
1918
1921
) ?;
1919
1922
self . lock_checkpoint . zcheck (
1920
- format ! ( "{}_{}" , label, "lock_checkpoint" ) ,
1921
- t. lock_checkpoint ,
1923
+ || format ! ( "{}_{}" , label, "lock_checkpoint" ) ,
1924
+ & t. lock_checkpoint ,
1922
1925
) ?;
1923
1926
self . epoch_length
1924
- . zcheck ( format ! ( "{}_{}" , label, "epoch_length" ) , t. epoch_length )
1927
+ . zcheck ( || format ! ( "{}_{}" , label, "epoch_length" ) , & t. epoch_length )
1925
1928
}
1926
1929
1927
1930
pub fn gen ( ) -> Self {
@@ -1956,16 +1959,16 @@ pub mod zkapp_command {
1956
1959
/// zkapp check
1957
1960
pub fn zcheck ( & self , s : & ProtocolStateView ) -> Result < ( ) , String > {
1958
1961
self . snarked_ledger_hash
1959
- . zcheck ( "snarker_ledger_hash" . to_string ( ) , s. snarked_ledger_hash ) ?;
1962
+ . zcheck ( || "snarker_ledger_hash" . to_string ( ) , & s. snarked_ledger_hash ) ?;
1960
1963
self . blockchain_length
1961
- . zcheck ( "blockchain_length" . to_string ( ) , s. blockchain_length ) ?;
1964
+ . zcheck ( || "blockchain_length" . to_string ( ) , & s. blockchain_length ) ?;
1962
1965
self . min_window_density
1963
- . zcheck ( "min_window_density" . to_string ( ) , s. min_window_density ) ?;
1966
+ . zcheck ( || "min_window_density" . to_string ( ) , & s. min_window_density ) ?;
1964
1967
self . total_currency
1965
- . zcheck ( "total_currency" . to_string ( ) , s. total_currency ) ?;
1968
+ . zcheck ( || "total_currency" . to_string ( ) , & s. total_currency ) ?;
1966
1969
self . global_slot_since_genesis . zcheck (
1967
- "global_slot_since_genesis" . to_string ( ) ,
1968
- s. global_slot_since_genesis ,
1970
+ || "global_slot_since_genesis" . to_string ( ) ,
1971
+ & s. global_slot_since_genesis ,
1969
1972
) ?;
1970
1973
self . staking_epoch_data
1971
1974
. epoch_data ( "staking_epoch_data" , & s. staking_epoch_data ) ?;
@@ -2188,31 +2191,31 @@ pub mod zkapp_command {
2188
2191
let mut ret = vec ! [
2189
2192
(
2190
2193
TransactionFailure :: AccountBalancePreconditionUnsatisfied ,
2191
- self . balance. zcheck( "balance" . to_string( ) , a. balance) ,
2194
+ self . balance. zcheck( || "balance" . to_string( ) , & a. balance) ,
2192
2195
) ,
2193
2196
(
2194
2197
TransactionFailure :: AccountNoncePreconditionUnsatisfied ,
2195
- self . nonce. zcheck( "nonce" . to_string( ) , a. nonce) ,
2198
+ self . nonce. zcheck( || "nonce" . to_string( ) , & a. nonce) ,
2196
2199
) ,
2197
2200
(
2198
2201
TransactionFailure :: AccountReceiptChainHashPreconditionUnsatisfied ,
2199
2202
self . receipt_chain_hash
2200
- . zcheck( "receipt_chain_hash" . to_string( ) , a. receipt_chain_hash. 0 ) ,
2203
+ . zcheck( || "receipt_chain_hash" . to_string( ) , & a. receipt_chain_hash. 0 ) ,
2201
2204
) ,
2202
2205
(
2203
2206
TransactionFailure :: AccountDelegatePreconditionUnsatisfied ,
2204
2207
self . delegate. zcheck(
2205
- "delegate" . to_string( ) ,
2206
- a. delegate. clone( ) . unwrap_or_else( invalid_public_key) ,
2208
+ || "delegate" . to_string( ) ,
2209
+ & a. delegate. clone( ) . unwrap_or_else( invalid_public_key) ,
2207
2210
) ,
2208
2211
) ,
2209
2212
(
2210
2213
TransactionFailure :: AccountActionStatePreconditionUnsatisfied ,
2211
- match zkapp
2212
- . action_state
2213
- . iter ( )
2214
- . find ( |state| self . action_state . zcheck ( "" . to_string ( ) , * * state ) . is_ok( ) )
2215
- {
2214
+ match zkapp. action_state . iter ( ) . find ( |state| {
2215
+ self . action_state
2216
+ . zcheck ( || "" . to_string ( ) , & * * state )
2217
+ . is_ok( )
2218
+ } ) {
2216
2219
None => Err ( "Action state mismatch" . to_string( ) ) ,
2217
2220
Some ( _) => Ok ( ( ) ) ,
2218
2221
} ,
@@ -2222,19 +2225,19 @@ pub mod zkapp_command {
2222
2225
for ( i, ( c, v) ) in self . state . iter ( ) . zip ( zkapp. app_state . iter ( ) ) . enumerate ( ) {
2223
2226
ret. push ( (
2224
2227
TransactionFailure :: AccountAppStatePreconditionUnsatisfied ( i as u64 ) ,
2225
- c. zcheck ( format ! ( "state[{}]" , i) , * v) ,
2228
+ c. zcheck ( || format ! ( "state[{}]" , i) , & * v) ,
2226
2229
) ) ;
2227
2230
}
2228
2231
2229
2232
let mut ret2 = vec ! [
2230
2233
(
2231
2234
TransactionFailure :: AccountProvedStatePreconditionUnsatisfied ,
2232
2235
self . proved_state
2233
- . zcheck( "proved_state" . to_string( ) , zkapp. proved_state) ,
2236
+ . zcheck( || "proved_state" . to_string( ) , & zkapp. proved_state) ,
2234
2237
) ,
2235
2238
(
2236
2239
TransactionFailure :: AccountIsNewPreconditionUnsatisfied ,
2237
- self . is_new. zcheck( "is_new" . to_string( ) , new_account) ,
2240
+ self . is_new. zcheck( || "is_new" . to_string( ) , & new_account) ,
2238
2241
) ,
2239
2242
] ;
2240
2243
@@ -5853,8 +5856,8 @@ where
5853
5856
Eff :: CheckValidWhilePrecondition ( valid_while, global_state) => PerformResult :: Bool (
5854
5857
valid_while
5855
5858
. zcheck (
5856
- "valid_while_precondition" . to_string ( ) ,
5857
- global_state. block_global_slot ,
5859
+ || "valid_while_precondition" . to_string ( ) ,
5860
+ & global_state. block_global_slot ,
5858
5861
)
5859
5862
. is_ok ( ) ,
5860
5863
) ,
0 commit comments