Skip to content

Commit 24d8406

Browse files
committed
Remove OutSnarkCheck
Replaced by `ZkappCheck`
1 parent eb36d2f commit 24d8406

File tree

2 files changed

+1
-205
lines changed

2 files changed

+1
-205
lines changed

ledger/src/scan_state/transaction_logic.rs

Lines changed: 1 addition & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ pub mod zkapp_command {
926926
use rand::{seq::SliceRandom, Rng};
927927

928928
use crate::{
929-
account, dummy, gen_compressed, gen_keypair, hash_noinputs,
929+
dummy, gen_compressed, gen_keypair, hash_noinputs,
930930
proofs::{
931931
field::{Boolean, ToBoolean},
932932
to_field_elements::ToFieldElements,
@@ -1536,33 +1536,6 @@ pub mod zkapp_command {
15361536
}
15371537
}
15381538

1539-
// TODO: Remove this. It's been replaced by `ZkappCheck`
1540-
pub trait OutSnarkCheck {
1541-
type A;
1542-
type B;
1543-
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>;
1547-
}
1548-
1549-
impl<T> OutSnarkCheck for T
1550-
where
1551-
T: Eq,
1552-
{
1553-
type A = T;
1554-
type B = T;
1555-
1556-
/// zkapp check
1557-
fn out_zcheck<F: Fn() -> String>(&self, label: F, rhs: &Self::B) -> Result<(), String> {
1558-
if self == rhs {
1559-
Ok(())
1560-
} else {
1561-
Err(format!("Equality check failed: {}", label()))
1562-
}
1563-
}
1564-
}
1565-
15661539
// TODO: This could be std::ops::Range ?
15671540
/// https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/mina_base/zkapp_precondition.ml#L23
15681541
#[derive(Debug, Clone, PartialEq)]
@@ -1619,27 +1592,6 @@ pub mod zkapp_command {
16191592
}
16201593
}
16211594

1622-
impl<T> OutSnarkCheck for ClosedInterval<T>
1623-
where
1624-
T: PartialOrd + std::fmt::Debug,
1625-
{
1626-
type A = ClosedInterval<T>;
1627-
type B = T;
1628-
1629-
/// zkapp check
1630-
fn out_zcheck<F: Fn() -> String>(&self, label: F, rhs: &Self::B) -> Result<(), String> {
1631-
/*println!(
1632-
"bounds check lower {:?} rhs {:?} upper {:?}",
1633-
self.lower, rhs, self.upper
1634-
);*/
1635-
if &self.lower <= rhs && rhs <= &self.upper {
1636-
Ok(())
1637-
} else {
1638-
Err(format!("Bounds check failed: {}", label()))
1639-
}
1640-
}
1641-
}
1642-
16431595
impl<T> ClosedInterval<T>
16441596
where
16451597
T: PartialOrd,
@@ -1737,20 +1689,6 @@ pub mod zkapp_command {
17371689
}
17381690
}
17391691

1740-
impl<T> OrIgnore<T>
1741-
where
1742-
T: OutSnarkCheck<A = T>,
1743-
{
1744-
/// zkapp check
1745-
pub fn out_zcheck<F: Fn() -> String>(&self, label: F, rhs: &T::B) -> Result<(), String> {
1746-
// println!("[rust] check {}, {:?}", label, ret);
1747-
match self {
1748-
Self::Ignore => Ok(()),
1749-
Self::Check(t) => t.out_zcheck(label, rhs),
1750-
}
1751-
}
1752-
}
1753-
17541692
impl<T> OrIgnore<T> {
17551693
/// https://github.com/MinaProtocol/mina/blob/d7d4aa4d650eb34b45a42b29276554802683ce15/src/lib/mina_base/zkapp_basic.ml#L239
17561694
pub fn gen<F>(mut fun: F) -> Self
@@ -1806,17 +1744,6 @@ pub mod zkapp_command {
18061744
pub total_currency: Numeric<Amount>,
18071745
}
18081746

1809-
impl EpochLedger {
1810-
pub fn epoch_ledger(&self, t: &protocol_state::EpochLedger<Fp>) -> Result<(), String> {
1811-
self.hash
1812-
.out_zcheck(|| "epoch_ledger_hash".to_string(), &t.hash)?;
1813-
self.total_currency.out_zcheck(
1814-
|| "epoch_ledger_total_currency".to_string(),
1815-
&t.total_currency,
1816-
)
1817-
}
1818-
}
1819-
18201747
/// https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/mina_base/zkapp_precondition.ml#L797
18211748
#[derive(Debug, Clone, PartialEq)]
18221749
pub struct EpochData {
@@ -1910,25 +1837,6 @@ pub mod zkapp_command {
19101837
}
19111838

19121839
impl EpochData {
1913-
pub fn epoch_data(
1914-
&self,
1915-
label: &str,
1916-
t: &protocol_state::EpochData<Fp>,
1917-
) -> Result<(), String> {
1918-
self.ledger.epoch_ledger(&t.ledger)?;
1919-
// ignore seed
1920-
self.start_checkpoint.out_zcheck(
1921-
|| format!("{}_{}", label, "start_checkpoint"),
1922-
&t.start_checkpoint,
1923-
)?;
1924-
self.lock_checkpoint.out_zcheck(
1925-
|| format!("{}_{}", label, "lock_checkpoint"),
1926-
&t.lock_checkpoint,
1927-
)?;
1928-
self.epoch_length
1929-
.out_zcheck(|| format!("{}_{}", label, "epoch_length"), &t.epoch_length)
1930-
}
1931-
19321840
pub fn gen() -> Self {
19331841
let mut rng = rand::thread_rng();
19341842

@@ -1958,26 +1866,6 @@ pub mod zkapp_command {
19581866
}
19591867

19601868
impl ZkAppPreconditions {
1961-
/// zkapp check
1962-
pub fn out_zcheck(&self, s: &ProtocolStateView) -> Result<(), String> {
1963-
self.snarked_ledger_hash
1964-
.out_zcheck(|| "snarker_ledger_hash".to_string(), &s.snarked_ledger_hash)?;
1965-
self.blockchain_length
1966-
.out_zcheck(|| "blockchain_length".to_string(), &s.blockchain_length)?;
1967-
self.min_window_density
1968-
.out_zcheck(|| "min_window_density".to_string(), &s.min_window_density)?;
1969-
self.total_currency
1970-
.out_zcheck(|| "total_currency".to_string(), &s.total_currency)?;
1971-
self.global_slot_since_genesis.out_zcheck(
1972-
|| "global_slot_since_genesis".to_string(),
1973-
&s.global_slot_since_genesis,
1974-
)?;
1975-
self.staking_epoch_data
1976-
.epoch_data("staking_epoch_data", &s.staking_epoch_data)?;
1977-
self.next_epoch_data
1978-
.epoch_data("next_epoch_data", &s.next_epoch_data)
1979-
}
1980-
19811869
pub fn zcheck<Ops: ZkappCheckOps>(
19821870
&self,
19831871
s: &ProtocolStateView,
@@ -2173,84 +2061,6 @@ pub mod zkapp_command {
21732061
}
21742062

21752063
impl Account {
2176-
/// zkapp check
2177-
pub fn out_zcheck<F>(&self, new_account: bool, mut check: F, a: &account::Account)
2178-
where
2179-
F: FnMut(TransactionFailure, bool),
2180-
{
2181-
self.out_zchecks(new_account, a)
2182-
.iter()
2183-
.for_each(|(failure, res)| check(failure.clone(), res.is_ok()))
2184-
}
2185-
2186-
fn out_zchecks(
2187-
&self,
2188-
new_account: bool,
2189-
a: &account::Account,
2190-
) -> Vec<(TransactionFailure, Result<(), String>)> {
2191-
let zkapp = match a.zkapp.as_ref() {
2192-
Some(zkapp) => MyCow::Borrow(&**zkapp),
2193-
None => MyCow::Own(ZkAppAccount::default()),
2194-
};
2195-
let mut ret = vec![
2196-
(
2197-
TransactionFailure::AccountBalancePreconditionUnsatisfied,
2198-
self.balance
2199-
.out_zcheck(|| "balance".to_string(), &a.balance),
2200-
),
2201-
(
2202-
TransactionFailure::AccountNoncePreconditionUnsatisfied,
2203-
self.nonce.out_zcheck(|| "nonce".to_string(), &a.nonce),
2204-
),
2205-
(
2206-
TransactionFailure::AccountReceiptChainHashPreconditionUnsatisfied,
2207-
self.receipt_chain_hash
2208-
.out_zcheck(|| "receipt_chain_hash".to_string(), &a.receipt_chain_hash.0),
2209-
),
2210-
(
2211-
TransactionFailure::AccountDelegatePreconditionUnsatisfied,
2212-
self.delegate.out_zcheck(
2213-
|| "delegate".to_string(),
2214-
&a.delegate.clone().unwrap_or_else(invalid_public_key),
2215-
),
2216-
),
2217-
(
2218-
TransactionFailure::AccountActionStatePreconditionUnsatisfied,
2219-
match zkapp.action_state.iter().find(|state| {
2220-
self.action_state
2221-
.out_zcheck(|| "".to_string(), &**state)
2222-
.is_ok()
2223-
}) {
2224-
None => Err("Action state mismatch".to_string()),
2225-
Some(_) => Ok(()),
2226-
},
2227-
),
2228-
];
2229-
2230-
for (i, (c, v)) in self.state.iter().zip(zkapp.app_state.iter()).enumerate() {
2231-
ret.push((
2232-
TransactionFailure::AccountAppStatePreconditionUnsatisfied(i as u64),
2233-
c.out_zcheck(|| format!("state[{}]", i), v),
2234-
));
2235-
}
2236-
2237-
let mut ret2 = vec![
2238-
(
2239-
TransactionFailure::AccountProvedStatePreconditionUnsatisfied,
2240-
self.proved_state
2241-
.out_zcheck(|| "proved_state".to_string(), &zkapp.proved_state),
2242-
),
2243-
(
2244-
TransactionFailure::AccountIsNewPreconditionUnsatisfied,
2245-
self.is_new
2246-
.out_zcheck(|| "is_new".to_string(), &new_account),
2247-
),
2248-
];
2249-
2250-
ret.append(&mut ret2);
2251-
ret
2252-
}
2253-
22542064
fn zchecks<Ops: ZkappCheckOps>(
22552065
&self,
22562066
account: &crate::Account,

ledger/src/zkapps/non_snark.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,6 @@ impl<L: LedgerNonSnark> ZkappHandler for NonSnarkHandler<L> {
165165
check,
166166
&mut w,
167167
);
168-
// let AccountPreconditions(precondition_account) = &account_update.body.preconditions.account;
169-
// let check = |failure, b| {
170-
// zkapp_logic::LocalState::<ZkappNonSnark<L>>::add_check(local_state, failure, b, w);
171-
// };
172-
// precondition_account.out_zcheck(new_account, check, account);
173168
}
174169

175170
fn check_protocol_state_precondition(
@@ -181,9 +176,6 @@ impl<L: LedgerNonSnark> ZkappHandler for NonSnarkHandler<L> {
181176
protocol_state_predicate
182177
.zcheck::<NonSnarkOps>(&global_state.protocol_state, &mut w)
183178
.as_bool()
184-
// protocol_state_predicate
185-
// .out_zcheck(&global_state.protocol_state)
186-
// .is_ok()
187179
}
188180

189181
fn check_valid_while_precondition(
@@ -196,12 +188,6 @@ impl<L: LedgerNonSnark> ZkappHandler for NonSnarkHandler<L> {
196188
(valid_while, ClosedInterval::min_max)
197189
.zcheck::<NonSnarkOps>(&global_state.block_global_slot, &mut w)
198190
.as_bool()
199-
// valid_while
200-
// .out_zcheck(
201-
// || "valid_while_precondition".to_string(),
202-
// &global_state.block_global_slot,
203-
// )
204-
// .is_ok()
205191
}
206192

207193
fn init_account(

0 commit comments

Comments
 (0)