Skip to content

Commit 643dda2

Browse files
committed
wip
1 parent e183aef commit 643dda2

File tree

7 files changed

+27
-21
lines changed

7 files changed

+27
-21
lines changed

ledger/src/proofs/block.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use crate::{
3535
transaction_logic::protocol_state::{EpochLedger, ProtocolStateView},
3636
},
3737
staged_ledger::hash::StagedLedgerHash,
38+
zkapps::intefaces::{SignedAmountBranchParam, SignedAmountInterface},
3839
Inputs, ToInputs,
3940
};
4041

@@ -1637,10 +1638,14 @@ fn block_main<'a>(
16371638
txn_statement_ledger_hashes_equal(s1, &s2, w)
16381639
};
16391640

1640-
let supply_increase = w.exists_no_check(match txn_stmt_ledger_hashes_didn_t_change {
1641-
Boolean::True => CheckedSigned::zero(),
1642-
Boolean::False => txn_snark.supply_increase.to_checked(),
1643-
});
1641+
let supply_increase = CheckedSigned::on_if(
1642+
txn_stmt_ledger_hashes_didn_t_change.var(),
1643+
SignedAmountBranchParam {
1644+
on_true: &CheckedSigned::zero(),
1645+
on_false: &txn_snark.supply_increase.to_checked(),
1646+
},
1647+
w,
1648+
);
16441649

16451650
let (updated_consensus_state, consensus_state) = consensus::next_state_checked(
16461651
previous_state,

ledger/src/proofs/numbers/currency.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ where
9393
}
9494
}
9595

96+
// https://github.com/MinaProtocol/mina/blob/ca9c8c86aa21d3c346d28ea0be7ad4cb0c22bf7f/src/lib/transaction_snark/transaction_snark.ml#L1891-L1892
97+
// https://github.com/MinaProtocol/mina/blob/ca9c8c86aa21d3c346d28ea0be7ad4cb0c22bf7f/src/lib/currency/currency.ml#L579
98+
pub fn constant_zero() -> Self {
99+
Self {
100+
magnitude: T::zero(),
101+
sgn: CircuitVar::Constant(Sgn::Pos),
102+
value: Cell::new(Some(T::zero().to_field())),
103+
}
104+
}
105+
96106
pub fn negate(self) -> Self {
97107
Self {
98108
magnitude: self.magnitude,

ledger/src/proofs/to_field_elements.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use crate::{
3232

3333
use super::{
3434
field::{Boolean, CircuitVar, FieldWitness, GroupAffine},
35-
numbers::currency::{CheckedCurrency, CheckedSigned},
3635
step::PerProofWitness,
3736
transaction::{
3837
field_to_bits, InnerCurve, PlonkVerificationKeyEvals, StepMainProofState, StepMainStatement,
@@ -799,13 +798,6 @@ impl<F: FieldWitness, T: ToFieldElements<F>> ToFieldElements<F> for &T {
799798
}
800799
}
801800

802-
impl<F: FieldWitness, T: CheckedCurrency<F>> ToFieldElements<F> for CheckedSigned<F, T> {
803-
fn to_field_elements(&self, fields: &mut Vec<F>) {
804-
self.sgn.to_field_elements(fields);
805-
self.magnitude.to_field_elements(fields);
806-
}
807-
}
808-
809801
impl<F: FieldWitness> ToFieldElements<F> for InnerCurve<F> {
810802
fn to_field_elements(&self, fields: &mut Vec<F>) {
811803
let GroupAffine::<F> { x, y, .. } = self.to_affine();

ledger/src/proofs/zkapp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,8 @@ fn zkapp_main(
10751075
ledger: witness.global_second_pass_ledger.clone(),
10761076
hash: statement.source.second_pass_ledger,
10771077
},
1078-
fee_excess: CheckedSigned::zero(),
1079-
supply_increase: CheckedSigned::zero(),
1078+
fee_excess: CheckedSigned::constant_zero(),
1079+
supply_increase: CheckedSigned::constant_zero(),
10801080
protocol_state: state_body.view(),
10811081
block_global_slot,
10821082
};

ledger/src/zkapps/intefaces.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ where
142142
fn negate(&self) -> Self;
143143
fn add_flagged(&self, other: &Self, w: &mut Self::W) -> (Self, Self::Bool);
144144
fn of_unsigned(unsigned: Self::Amount) -> Self;
145-
fn on_if<'a>(b: Self::Bool, param: SignedAmountBranchParam<&'a Self>, w: &mut Self::W) -> Self;
145+
fn on_if(b: Self::Bool, param: SignedAmountBranchParam<&Self>, w: &mut Self::W) -> Self;
146146
}
147147

148148
pub trait BalanceInterface
@@ -580,8 +580,7 @@ where
580580
>;
581581
type SignedAmount: SignedAmountInterface<W = Self::WitnessGenerator, Bool = Self::Bool, Amount = Self::Amount>
582582
+ std::fmt::Debug
583-
+ Clone
584-
+ ToFieldElements<Fp>;
583+
+ Clone;
585584
type Amount: AmountInterface<W = Self::WitnessGenerator, Bool = Self::Bool> + Clone;
586585
type Balance: BalanceInterface<
587586
W = Self::WitnessGenerator,

ledger/src/zkapps/non_snark.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,11 @@ impl SignedAmountInterface for Signed<Amount> {
401401
fn of_unsigned(unsigned: Self::Amount) -> Self {
402402
Self::of_unsigned(unsigned)
403403
}
404-
fn on_if<'a>(b: Self::Bool, param: SignedAmountBranchParam<&'a Self>, w: &mut Self::W) -> Self {
404+
fn on_if(b: Self::Bool, param: SignedAmountBranchParam<&Self>, w: &mut Self::W) -> Self {
405405
let SignedAmountBranchParam { on_true, on_false } = param;
406406
match b {
407-
true => on_true.clone(),
408-
false => on_false.clone(),
407+
true => *on_true,
408+
false => *on_false,
409409
}
410410
}
411411
}

ledger/src/zkapps/snark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl SignedAmountInterface for CheckedSigned<Fp, CheckedAmount<Fp>> {
210210
fn of_unsigned(unsigned: Self::Amount) -> Self {
211211
Self::of_unsigned(unsigned)
212212
}
213-
fn on_if<'a>(b: Self::Bool, param: SignedAmountBranchParam<&'a Self>, w: &mut Self::W) -> Self {
213+
fn on_if(b: Self::Bool, param: SignedAmountBranchParam<&Self>, w: &mut Self::W) -> Self {
214214
let SignedAmountBranchParam { on_true, on_false } = param;
215215

216216
let amount = match b.as_boolean() {

0 commit comments

Comments
 (0)