Skip to content

Commit f33d211

Browse files
committed
Return error in zkapp_logic when assertion fail
1 parent d995d82 commit f33d211

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

ledger/src/zkapps/zkapp_logic.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ pub enum ZkAppCommandElt {
4141
ZkAppCommandCommitment(crate::ReceiptChainHash),
4242
}
4343

44-
fn assert_<Z: ZkappApplication>(_b: Z::Bool) -> Result<(), String> {
44+
fn assert_<Z: ZkappApplication>(b: Z::Bool, s: &str) -> Result<(), String> {
4545
// Used only for circuit generation (add constraints)
4646
// https://github.com/MinaProtocol/mina/blob/e44ddfe1ca54b3855e1ed336d89f6230d35aeb8c/src/lib/transaction_logic/zkapp_command_logic.ml#L929
4747

48-
// TODO: In non-witness generation, we raise an exception
48+
if let Boolean::False = b.as_boolean() {
49+
return Err(s.to_string());
50+
}
51+
4952
Ok(())
5053
}
5154

@@ -345,8 +348,8 @@ where
345348
let is_empty_call_forest = local_state.stack_frame.calls().is_empty(w);
346349
match is_start {
347350
IsStart::Compute(_) => (),
348-
IsStart::Yes(_) => assert_::<Z>(is_empty_call_forest)?,
349-
IsStart::No => assert_::<Z>(is_empty_call_forest.neg())?,
351+
IsStart::Yes(_) => assert_::<Z>(is_empty_call_forest, "is_empty_call_forest")?,
352+
IsStart::No => assert_::<Z>(is_empty_call_forest.neg(), "is_empty_call_forest.neg()")?,
350353
};
351354
match is_start {
352355
IsStart::Yes(_) => Z::Bool::true_(),
@@ -566,16 +569,14 @@ where
566569
w,
567570
)
568571
};
569-
assert_::<Z>(Z::Bool::equal(
570-
proof_verifies,
571-
account_update.is_proved(),
572-
w,
573-
))?;
574-
assert_::<Z>(Z::Bool::equal(
575-
signature_verifies,
576-
account_update.is_signed(),
577-
w,
578-
))?;
572+
assert_::<Z>(
573+
Z::Bool::equal(proof_verifies, account_update.is_proved(), w),
574+
"not proved",
575+
)?;
576+
assert_::<Z>(
577+
Z::Bool::equal(signature_verifies, account_update.is_signed(), w),
578+
"not signed",
579+
)?;
579580

580581
Z::LocalState::add_check(
581582
local_state,
@@ -650,11 +651,14 @@ where
650651
SetOrKeep::Keep => a.get().timing.clone(),
651652
}
652653
});
653-
assert_::<Z>(Z::GlobalSlotSpan::greater_than(
654-
&timing.to_record().vesting_period,
655-
&SlotSpan::zero(),
656-
w,
657-
))?;
654+
assert_::<Z>(
655+
Z::GlobalSlotSpan::greater_than(
656+
&timing.to_record().vesting_period,
657+
&SlotSpan::zero(),
658+
w,
659+
),
660+
"vesting_period zero",
661+
)?;
658662
a.get_mut().timing = timing;
659663
((), ())
660664
};
@@ -1184,7 +1188,7 @@ where
11841188
Z::SignedAmount::is_non_neg(&local_delta),
11851189
w,
11861190
);
1187-
assert_::<Z>(Z::Bool::or(is_start2.neg(), first, w))?;
1191+
assert_::<Z>(Z::Bool::or(is_start2.neg(), first, w), "is_start2 or first")?;
11881192
let (new_local_fee_excess, overflow) =
11891193
Z::SignedAmount::add_flagged(&local_state.excess, &local_delta, w);
11901194
// We decompose this way because of OCaml evaluation order

0 commit comments

Comments
 (0)