@@ -936,7 +936,7 @@ pub mod zkapp_command {
936
936
currency:: { MinMax , Sgn } ,
937
937
GenesisConstant , GENESIS_CONSTANT ,
938
938
} ,
939
- zkapps:: snark :: { zkapp_check :: InSnarkCheck , ZkappCheckOps } ,
939
+ zkapps:: checks :: { ZkappCheck , ZkappCheckOps } ,
940
940
AuthRequired , MutableFp , MyCow , Permissions , SetVerificationKey , ToInputs , TokenSymbol ,
941
941
VerificationKey , VerificationKeyWire , VotingFor , ZkAppAccount , ZkAppUri ,
942
942
} ;
@@ -1536,12 +1536,14 @@ pub mod zkapp_command {
1536
1536
}
1537
1537
}
1538
1538
1539
+ // TODO: Remove this. It's been replaced by `ZkappCheck`
1539
1540
pub trait OutSnarkCheck {
1540
1541
type A ;
1541
1542
type B ;
1542
1543
1543
- /// zkapp check
1544
- fn zcheck < F : Fn ( ) -> String > ( & self , label : F , x : & Self :: B ) -> Result < ( ) , String > ;
1544
+ /// zkapp check.
1545
+ // name is `out_zheck`, to differentiate with `zcheck`. It means out of snark
1546
+ fn out_zcheck < F : Fn ( ) -> String > ( & self , label : F , x : & Self :: B ) -> Result < ( ) , String > ;
1545
1547
}
1546
1548
1547
1549
impl < T > OutSnarkCheck for T
@@ -1552,7 +1554,7 @@ pub mod zkapp_command {
1552
1554
type B = T ;
1553
1555
1554
1556
/// zkapp check
1555
- fn zcheck < F : Fn ( ) -> String > ( & self , label : F , rhs : & Self :: B ) -> Result < ( ) , String > {
1557
+ fn out_zcheck < F : Fn ( ) -> String > ( & self , label : F , rhs : & Self :: B ) -> Result < ( ) , String > {
1556
1558
if self == rhs {
1557
1559
Ok ( ( ) )
1558
1560
} else {
@@ -1625,7 +1627,7 @@ pub mod zkapp_command {
1625
1627
type B = T ;
1626
1628
1627
1629
/// zkapp check
1628
- fn zcheck < F : Fn ( ) -> String > ( & self , label : F , rhs : & Self :: B ) -> Result < ( ) , String > {
1630
+ fn out_zcheck < F : Fn ( ) -> String > ( & self , label : F , rhs : & Self :: B ) -> Result < ( ) , String > {
1629
1631
/*println!(
1630
1632
"bounds check lower {:?} rhs {:?} upper {:?}",
1631
1633
self.lower, rhs, self.upper
@@ -1740,11 +1742,11 @@ pub mod zkapp_command {
1740
1742
T : OutSnarkCheck < A = T > ,
1741
1743
{
1742
1744
/// zkapp check
1743
- pub fn zcheck < F : Fn ( ) -> String > ( & self , label : F , rhs : & T :: B ) -> Result < ( ) , String > {
1745
+ pub fn out_zcheck < F : Fn ( ) -> String > ( & self , label : F , rhs : & T :: B ) -> Result < ( ) , String > {
1744
1746
// println!("[rust] check {}, {:?}", label, ret);
1745
1747
match self {
1746
1748
Self :: Ignore => Ok ( ( ) ) ,
1747
- Self :: Check ( t) => t. zcheck ( label, rhs) ,
1749
+ Self :: Check ( t) => t. out_zcheck ( label, rhs) ,
1748
1750
}
1749
1751
}
1750
1752
}
@@ -1807,8 +1809,8 @@ pub mod zkapp_command {
1807
1809
impl EpochLedger {
1808
1810
pub fn epoch_ledger ( & self , t : & protocol_state:: EpochLedger < Fp > ) -> Result < ( ) , String > {
1809
1811
self . hash
1810
- . zcheck ( || "epoch_ledger_hash" . to_string ( ) , & t. hash ) ?;
1811
- self . total_currency . zcheck (
1812
+ . out_zcheck ( || "epoch_ledger_hash" . to_string ( ) , & t. hash ) ?;
1813
+ self . total_currency . out_zcheck (
1812
1814
|| "epoch_ledger_total_currency" . to_string ( ) ,
1813
1815
& t. total_currency ,
1814
1816
)
@@ -1915,16 +1917,16 @@ pub mod zkapp_command {
1915
1917
) -> Result < ( ) , String > {
1916
1918
self . ledger . epoch_ledger ( & t. ledger ) ?;
1917
1919
// ignore seed
1918
- self . start_checkpoint . zcheck (
1920
+ self . start_checkpoint . out_zcheck (
1919
1921
|| format ! ( "{}_{}" , label, "start_checkpoint" ) ,
1920
1922
& t. start_checkpoint ,
1921
1923
) ?;
1922
- self . lock_checkpoint . zcheck (
1924
+ self . lock_checkpoint . out_zcheck (
1923
1925
|| format ! ( "{}_{}" , label, "lock_checkpoint" ) ,
1924
1926
& t. lock_checkpoint ,
1925
1927
) ?;
1926
1928
self . epoch_length
1927
- . zcheck ( || format ! ( "{}_{}" , label, "epoch_length" ) , & t. epoch_length )
1929
+ . out_zcheck ( || format ! ( "{}_{}" , label, "epoch_length" ) , & t. epoch_length )
1928
1930
}
1929
1931
1930
1932
pub fn gen ( ) -> Self {
@@ -1957,16 +1959,16 @@ pub mod zkapp_command {
1957
1959
1958
1960
impl ZkAppPreconditions {
1959
1961
/// zkapp check
1960
- pub fn zcheck ( & self , s : & ProtocolStateView ) -> Result < ( ) , String > {
1962
+ pub fn out_zcheck ( & self , s : & ProtocolStateView ) -> Result < ( ) , String > {
1961
1963
self . snarked_ledger_hash
1962
- . zcheck ( || "snarker_ledger_hash" . to_string ( ) , & s. snarked_ledger_hash ) ?;
1964
+ . out_zcheck ( || "snarker_ledger_hash" . to_string ( ) , & s. snarked_ledger_hash ) ?;
1963
1965
self . blockchain_length
1964
- . zcheck ( || "blockchain_length" . to_string ( ) , & s. blockchain_length ) ?;
1966
+ . out_zcheck ( || "blockchain_length" . to_string ( ) , & s. blockchain_length ) ?;
1965
1967
self . min_window_density
1966
- . zcheck ( || "min_window_density" . to_string ( ) , & s. min_window_density ) ?;
1968
+ . out_zcheck ( || "min_window_density" . to_string ( ) , & s. min_window_density ) ?;
1967
1969
self . total_currency
1968
- . zcheck ( || "total_currency" . to_string ( ) , & s. total_currency ) ?;
1969
- self . global_slot_since_genesis . zcheck (
1970
+ . out_zcheck ( || "total_currency" . to_string ( ) , & s. total_currency ) ?;
1971
+ self . global_slot_since_genesis . out_zcheck (
1970
1972
|| "global_slot_since_genesis" . to_string ( ) ,
1971
1973
& s. global_slot_since_genesis ,
1972
1974
) ?;
@@ -1976,7 +1978,7 @@ pub mod zkapp_command {
1976
1978
. epoch_data ( "next_epoch_data" , & s. next_epoch_data )
1977
1979
}
1978
1980
1979
- pub fn checked_zcheck < Ops : ZkappCheckOps > (
1981
+ pub fn zcheck < Ops : ZkappCheckOps > (
1980
1982
& self ,
1981
1983
s : & ProtocolStateView ,
1982
1984
w : & mut Witness < Fp > ,
@@ -2007,34 +2009,31 @@ pub mod zkapp_command {
2007
2009
lock_checkpoint,
2008
2010
epoch_length,
2009
2011
} = epoch_data;
2010
- // Reverse to match OCaml order of the list, while still executing `checked_zcheck `
2012
+ // Reverse to match OCaml order of the list, while still executing `zcheck `
2011
2013
// in correct order
2012
2014
[
2013
- ( epoch_length, ClosedInterval :: min_max)
2014
- . checked_zcheck :: < Ops > ( & view. epoch_length , w) ,
2015
- ( lock_checkpoint, Fp :: zero) . checked_zcheck :: < Ops > ( & view. lock_checkpoint , w) ,
2016
- ( start_checkpoint, Fp :: zero) . checked_zcheck :: < Ops > ( & view. start_checkpoint , w) ,
2015
+ ( epoch_length, ClosedInterval :: min_max) . zcheck :: < Ops > ( & view. epoch_length , w) ,
2016
+ ( lock_checkpoint, Fp :: zero) . zcheck :: < Ops > ( & view. lock_checkpoint , w) ,
2017
+ ( start_checkpoint, Fp :: zero) . zcheck :: < Ops > ( & view. start_checkpoint , w) ,
2017
2018
( total_currency, ClosedInterval :: min_max)
2018
- . checked_zcheck :: < Ops > ( & view. ledger . total_currency , w) ,
2019
- ( hash, Fp :: zero) . checked_zcheck :: < Ops > ( & view. ledger . hash , w) ,
2019
+ . zcheck :: < Ops > ( & view. ledger . total_currency , w) ,
2020
+ ( hash, Fp :: zero) . zcheck :: < Ops > ( & view. ledger . hash , w) ,
2020
2021
]
2021
2022
} ;
2022
2023
2023
2024
let next_epoch_data = epoch_data ( next_epoch_data, & s. next_epoch_data , w) ;
2024
2025
let staking_epoch_data = epoch_data ( staking_epoch_data, & s. staking_epoch_data , w) ;
2025
2026
2026
- // Reverse to match OCaml order of the list, while still executing `checked_zcheck `
2027
+ // Reverse to match OCaml order of the list, while still executing `zcheck `
2027
2028
// in correct order
2028
2029
let bools = [
2029
2030
( global_slot_since_genesis, ClosedInterval :: min_max)
2030
- . checked_zcheck :: < Ops > ( & s. global_slot_since_genesis , w) ,
2031
- ( total_currency, ClosedInterval :: min_max)
2032
- . checked_zcheck :: < Ops > ( & s. total_currency , w) ,
2031
+ . zcheck :: < Ops > ( & s. global_slot_since_genesis , w) ,
2032
+ ( total_currency, ClosedInterval :: min_max) . zcheck :: < Ops > ( & s. total_currency , w) ,
2033
2033
( min_window_density, ClosedInterval :: min_max)
2034
- . checked_zcheck :: < Ops > ( & s. min_window_density , w) ,
2035
- ( blockchain_length, ClosedInterval :: min_max)
2036
- . checked_zcheck :: < Ops > ( & s. blockchain_length , w) ,
2037
- ( snarked_ledger_hash, Fp :: zero) . checked_zcheck :: < Ops > ( & s. snarked_ledger_hash , w) ,
2034
+ . zcheck :: < Ops > ( & s. min_window_density , w) ,
2035
+ ( blockchain_length, ClosedInterval :: min_max) . zcheck :: < Ops > ( & s. blockchain_length , w) ,
2036
+ ( snarked_ledger_hash, Fp :: zero) . zcheck :: < Ops > ( & s. snarked_ledger_hash , w) ,
2038
2037
]
2039
2038
. into_iter ( )
2040
2039
. rev ( )
@@ -2175,16 +2174,16 @@ pub mod zkapp_command {
2175
2174
2176
2175
impl Account {
2177
2176
/// zkapp check
2178
- pub fn zcheck < F > ( & self , new_account : bool , mut check : F , a : & account:: Account )
2177
+ pub fn out_zcheck < F > ( & self , new_account : bool , mut check : F , a : & account:: Account )
2179
2178
where
2180
2179
F : FnMut ( TransactionFailure , bool ) ,
2181
2180
{
2182
- self . zchecks ( new_account, a)
2181
+ self . out_zchecks ( new_account, a)
2183
2182
. iter ( )
2184
2183
. for_each ( |( failure, res) | check ( failure. clone ( ) , res. is_ok ( ) ) )
2185
2184
}
2186
2185
2187
- fn zchecks (
2186
+ fn out_zchecks (
2188
2187
& self ,
2189
2188
new_account : bool ,
2190
2189
a : & account:: Account ,
@@ -2196,20 +2195,21 @@ pub mod zkapp_command {
2196
2195
let mut ret = vec ! [
2197
2196
(
2198
2197
TransactionFailure :: AccountBalancePreconditionUnsatisfied ,
2199
- self . balance. zcheck( || "balance" . to_string( ) , & a. balance) ,
2198
+ self . balance
2199
+ . out_zcheck( || "balance" . to_string( ) , & a. balance) ,
2200
2200
) ,
2201
2201
(
2202
2202
TransactionFailure :: AccountNoncePreconditionUnsatisfied ,
2203
- self . nonce. zcheck ( || "nonce" . to_string( ) , & a. nonce) ,
2203
+ self . nonce. out_zcheck ( || "nonce" . to_string( ) , & a. nonce) ,
2204
2204
) ,
2205
2205
(
2206
2206
TransactionFailure :: AccountReceiptChainHashPreconditionUnsatisfied ,
2207
2207
self . receipt_chain_hash
2208
- . zcheck ( || "receipt_chain_hash" . to_string( ) , & a. receipt_chain_hash. 0 ) ,
2208
+ . out_zcheck ( || "receipt_chain_hash" . to_string( ) , & a. receipt_chain_hash. 0 ) ,
2209
2209
) ,
2210
2210
(
2211
2211
TransactionFailure :: AccountDelegatePreconditionUnsatisfied ,
2212
- self . delegate. zcheck (
2212
+ self . delegate. out_zcheck (
2213
2213
|| "delegate" . to_string( ) ,
2214
2214
& a. delegate. clone( ) . unwrap_or_else( invalid_public_key) ,
2215
2215
) ,
@@ -2218,7 +2218,7 @@ pub mod zkapp_command {
2218
2218
TransactionFailure :: AccountActionStatePreconditionUnsatisfied ,
2219
2219
match zkapp. action_state. iter( ) . find( |state| {
2220
2220
self . action_state
2221
- . zcheck ( || "" . to_string( ) , & * * state)
2221
+ . out_zcheck ( || "" . to_string( ) , & * * state)
2222
2222
. is_ok( )
2223
2223
} ) {
2224
2224
None => Err ( "Action state mismatch" . to_string( ) ) ,
@@ -2230,27 +2230,28 @@ pub mod zkapp_command {
2230
2230
for ( i, ( c, v) ) in self . state . iter ( ) . zip ( zkapp. app_state . iter ( ) ) . enumerate ( ) {
2231
2231
ret. push ( (
2232
2232
TransactionFailure :: AccountAppStatePreconditionUnsatisfied ( i as u64 ) ,
2233
- c. zcheck ( || format ! ( "state[{}]" , i) , & * v) ,
2233
+ c. out_zcheck ( || format ! ( "state[{}]" , i) , v) ,
2234
2234
) ) ;
2235
2235
}
2236
2236
2237
2237
let mut ret2 = vec ! [
2238
2238
(
2239
2239
TransactionFailure :: AccountProvedStatePreconditionUnsatisfied ,
2240
2240
self . proved_state
2241
- . zcheck ( || "proved_state" . to_string( ) , & zkapp. proved_state) ,
2241
+ . out_zcheck ( || "proved_state" . to_string( ) , & zkapp. proved_state) ,
2242
2242
) ,
2243
2243
(
2244
2244
TransactionFailure :: AccountIsNewPreconditionUnsatisfied ,
2245
- self . is_new. zcheck( || "is_new" . to_string( ) , & new_account) ,
2245
+ self . is_new
2246
+ . out_zcheck( || "is_new" . to_string( ) , & new_account) ,
2246
2247
) ,
2247
2248
] ;
2248
2249
2249
2250
ret. append ( & mut ret2) ;
2250
2251
ret
2251
2252
}
2252
2253
2253
- fn checked_zchecks < Ops : ZkappCheckOps > (
2254
+ fn zchecks < Ops : ZkappCheckOps > (
2254
2255
& self ,
2255
2256
account : & crate :: Account ,
2256
2257
new_account : Boolean ,
@@ -2273,7 +2274,7 @@ pub mod zkapp_command {
2273
2274
let is_new = is_new. map ( ToBoolean :: to_boolean) ;
2274
2275
let proved_state = proved_state. map ( ToBoolean :: to_boolean) ;
2275
2276
2276
- // NOTE: Here we need to execute all `checked_zcheck ` in the exact same order than OCaml
2277
+ // NOTE: Here we need to execute all `zcheck ` in the exact same order than OCaml
2277
2278
// so we execute them in reverse order (compared to OCaml): OCaml evaluates from right
2278
2279
// to left.
2279
2280
// We then have to reverse the resulting vector, to match OCaml resulting list.
@@ -2282,12 +2283,12 @@ pub mod zkapp_command {
2282
2283
let mut checks: Vec < ( TransactionFailure , _ ) > = [
2283
2284
(
2284
2285
AccountIsNewPreconditionUnsatisfied ,
2285
- ( & is_new, || Boolean :: False ) . checked_zcheck :: < Ops > ( & new_account, w) ,
2286
+ ( & is_new, || Boolean :: False ) . zcheck :: < Ops > ( & new_account, w) ,
2286
2287
) ,
2287
2288
(
2288
2289
AccountProvedStatePreconditionUnsatisfied ,
2289
2290
( & proved_state, || Boolean :: False )
2290
- . checked_zcheck :: < Ops > ( & zkapp_account. proved_state . to_boolean ( ) , w) ,
2291
+ . zcheck :: < Ops > ( & zkapp_account. proved_state . to_boolean ( ) , w) ,
2291
2292
) ,
2292
2293
]
2293
2294
. into_iter ( )
@@ -2298,7 +2299,7 @@ pub mod zkapp_command {
2298
2299
. enumerate ( )
2299
2300
. rev ( )
2300
2301
. map ( |( i, ( s, account_s) ) | {
2301
- let b = ( s, Fp :: zero) . checked_zcheck :: < Ops > ( account_s, w) ;
2302
+ let b = ( s, Fp :: zero) . zcheck :: < Ops > ( account_s, w) ;
2302
2303
( AccountAppStatePreconditionUnsatisfied ( i as u64 ) , b)
2303
2304
} )
2304
2305
. collect :: < Vec < _ > > ( ) ;
@@ -2312,7 +2313,7 @@ pub mod zkapp_command {
2312
2313
. iter ( )
2313
2314
. map ( |account_s| {
2314
2315
( action_state, ZkAppAccount :: empty_action_state)
2315
- . checked_zcheck :: < Ops > ( account_s, w)
2316
+ . zcheck :: < Ops > ( account_s, w)
2316
2317
} )
2317
2318
. collect ( ) ;
2318
2319
(
@@ -2323,20 +2324,19 @@ pub mod zkapp_command {
2323
2324
(
2324
2325
AccountDelegatePreconditionUnsatisfied ,
2325
2326
( delegate, CompressedPubKey :: empty)
2326
- . checked_zcheck :: < Ops > ( & * account. delegate_or_empty ( ) , w) ,
2327
+ . zcheck :: < Ops > ( & * account. delegate_or_empty ( ) , w) ,
2327
2328
) ,
2328
2329
(
2329
2330
AccountReceiptChainHashPreconditionUnsatisfied ,
2330
- ( receipt_chain_hash, Fp :: zero)
2331
- . checked_zcheck :: < Ops > ( & account. receipt_chain_hash . 0 , w) ,
2331
+ ( receipt_chain_hash, Fp :: zero) . zcheck :: < Ops > ( & account. receipt_chain_hash . 0 , w) ,
2332
2332
) ,
2333
2333
(
2334
2334
AccountNoncePreconditionUnsatisfied ,
2335
- ( nonce, ClosedInterval :: min_max) . checked_zcheck :: < Ops > ( & account. nonce , w) ,
2335
+ ( nonce, ClosedInterval :: min_max) . zcheck :: < Ops > ( & account. nonce , w) ,
2336
2336
) ,
2337
2337
(
2338
2338
AccountBalancePreconditionUnsatisfied ,
2339
- ( balance, ClosedInterval :: min_max) . checked_zcheck :: < Ops > ( & account. balance , w) ,
2339
+ ( balance, ClosedInterval :: min_max) . zcheck :: < Ops > ( & account. balance , w) ,
2340
2340
) ,
2341
2341
] )
2342
2342
. collect :: < Vec < _ > > ( ) ;
@@ -2458,7 +2458,7 @@ pub mod zkapp_command {
2458
2458
MyCow :: Borrow ( & self . 0 )
2459
2459
}
2460
2460
2461
- pub fn checked_zcheck < Ops , Fun > (
2461
+ pub fn zcheck < Ops , Fun > (
2462
2462
& self ,
2463
2463
new_account : Boolean ,
2464
2464
account : & crate :: Account ,
@@ -2469,7 +2469,7 @@ pub mod zkapp_command {
2469
2469
Fun : FnMut ( TransactionFailure , Boolean , & mut Witness < Fp > ) ,
2470
2470
{
2471
2471
let this = self . to_full ( ) ;
2472
- for ( failure, passed) in this. checked_zchecks :: < Ops > ( account, new_account, w) {
2472
+ for ( failure, passed) in this. zchecks :: < Ops > ( account, new_account, w) {
2473
2473
check ( failure, passed, w) ;
2474
2474
}
2475
2475
}
@@ -5862,14 +5862,14 @@ where
5862
5862
match eff {
5863
5863
Eff :: CheckValidWhilePrecondition ( valid_while, global_state) => PerformResult :: Bool (
5864
5864
valid_while
5865
- . zcheck (
5865
+ . out_zcheck (
5866
5866
|| "valid_while_precondition" . to_string ( ) ,
5867
5867
& global_state. block_global_slot ,
5868
5868
)
5869
5869
. is_ok ( ) ,
5870
5870
) ,
5871
5871
Eff :: CheckProtocolStatePrecondition ( pred, global_state) => {
5872
- PerformResult :: Bool ( pred. zcheck ( & global_state. protocol_state ) . is_ok ( ) )
5872
+ PerformResult :: Bool ( pred. out_zcheck ( & global_state. protocol_state ) . is_ok ( ) )
5873
5873
}
5874
5874
Eff :: CheckAccountPrecondition ( account_update, account, new_account, local_state) => {
5875
5875
let local_state = {
@@ -5878,7 +5878,7 @@ where
5878
5878
let check = |failure, b| {
5879
5879
_local_state = _local_state. add_check ( failure, b) ;
5880
5880
} ;
5881
- precondition_account. zcheck ( new_account, check, & account) ;
5881
+ precondition_account. out_zcheck ( new_account, check, & account) ;
5882
5882
_local_state
5883
5883
} ;
5884
5884
PerformResult :: LocalState ( Box :: new ( local_state) )
0 commit comments