Skip to content

Commit ddb5ac0

Browse files
committed
Fixed lint issues
1 parent 2f812e5 commit ddb5ac0

File tree

13 files changed

+38
-36
lines changed

13 files changed

+38
-36
lines changed

ledger/src/account/account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl TokenSymbol {
128128

129129
let value = FromBytes::read(&s[..]).expect("Shoudn't fail");
130130
let bigint = BigInteger256::new(value);
131-
F::try_from(bigint).unwrap() // Never fail, `self` contain 6 bytes at most
131+
F::from(bigint) // Never fail, `self` contain 6 bytes at most
132132
}
133133
}
134134

ledger/src/proofs/block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ mod floating_point {
501501

502502
pub fn constant(value: &BigInteger256, precision: usize) -> anyhow::Result<Self> {
503503
Ok(Self {
504-
value: (*value).try_into()?,
504+
value: (*value).into(),
505505
precision,
506506
})
507507
}
@@ -1881,10 +1881,10 @@ pub(super) fn generate_block_proof(
18811881
};
18821882

18831883
let dlog_plonk_index = super::merge::dlog_plonk_index(block_wrap_prover);
1884-
let verifier_index = &*block_wrap_prover.index.verifier_index.as_ref().unwrap();
1884+
let verifier_index = block_wrap_prover.index.verifier_index.as_ref().unwrap();
18851885

18861886
let tx_dlog_plonk_index = super::merge::dlog_plonk_index(tx_wrap_prover);
1887-
let tx_verifier_index = &*tx_wrap_prover.index.verifier_index.as_ref().unwrap();
1887+
let tx_verifier_index = tx_wrap_prover.index.verifier_index.as_ref().unwrap();
18881888

18891889
let dlog_plonk_index_cvar = dlog_plonk_index.to_cvar(CircuitVar::Var);
18901890
let tx_dlog_plonk_index_cvar = tx_dlog_plonk_index.to_cvar(CircuitVar::Constant);

ledger/src/proofs/caching.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ where
224224
.map(|(key, value)| {
225225
(
226226
*key,
227-
value.iter().map(|poly| PolyComm::from(poly)).collect(),
227+
value.iter().map(PolyComm::from).collect(),
228228
)
229229
})
230230
.collect();
@@ -452,7 +452,6 @@ impl From<&VerifierIndexCached> for VerifierIndex<Fq> {
452452
domain: domain.into(),
453453
max_poly_size: *max_poly_size,
454454
srs: {
455-
let srs = srs;
456455
let s: SRS<_> = SRS::from(srs);
457456
Arc::new(s)
458457
},

ledger/src/proofs/field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl FromFpFq for Fq {
143143
fn from_fp(fp: Fp) -> Self {
144144
// `Fp` is smaller than `Fq`, so the conversion is fine
145145
let bigint: BigInteger256 = fp.into();
146-
bigint.try_into().unwrap()
146+
Self::from(bigint)
147147
}
148148
fn from_fq(fq: Fq) -> Self {
149149
fq

ledger/src/proofs/merge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn merge_main(
9595
}
9696

9797
pub fn dlog_plonk_index(wrap_prover: &Prover<Fq>) -> PlonkVerificationKeyEvals<Fp> {
98-
PlonkVerificationKeyEvals::from(&*wrap_prover.index.verifier_index.as_ref().unwrap())
98+
PlonkVerificationKeyEvals::from(wrap_prover.index.verifier_index.as_ref().unwrap())
9999
}
100100

101101
impl From<&v2::PicklesProofProofsVerified2ReprStableV2StatementProofStateDeferredValuesPlonkFeatureFlags> for crate::proofs::step::FeatureFlags::<bool> {
@@ -260,7 +260,7 @@ pub(super) fn generate_merge_proof(
260260

261261
let dlog_plonk_index = dlog_plonk_index(wrap_prover);
262262
let dlog_plonk_index_cvar = dlog_plonk_index.to_cvar(CircuitVar::Var);
263-
let verifier_index = &*wrap_prover.index.verifier_index.as_ref().unwrap();
263+
let verifier_index = wrap_prover.index.verifier_index.as_ref().unwrap();
264264

265265
let tx_data = make_step_transaction_data(&dlog_plonk_index_cvar);
266266
let for_step_datas = [&tx_data, &tx_data];

ledger/src/proofs/public_input/prepared_statement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl PreparedStatement {
9191

9292
let to_fq = |fp: Fp| -> Fq {
9393
let bigint: BigInteger256 = fp.into();
94-
bigint.try_into().unwrap() // Never fail, `Fq` is larger than `Fp`
94+
Fq::from(bigint) // Never fail, `Fq` is larger than `Fp`
9595
};
9696

9797
// Fp
@@ -226,7 +226,7 @@ impl PreparedStatement {
226226

227227
let to_fq = |fp: Fp| -> Fq {
228228
let bigint: BigInteger256 = fp.into();
229-
bigint.try_into().unwrap() // Never fail, `Fq` is larger than `Fp`
229+
Fq::from(bigint) // Never fail, `Fq` is larger than `Fp`
230230
};
231231

232232
let var = |x| Packed::Field(CircuitVar::Var(x));

ledger/src/proofs/public_input/scalars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ where
5050

5151
let value = FromBytes::read(&bytes[..]).expect("Should not fail");
5252
let bigint = BigInteger256::new(value);
53-
bigint.try_into().unwrap() // Never fail, we hardcode them with string literals
53+
F::from(bigint) // Never fail, we hardcode them with string literals
5454
}
5555

5656
fn field<F: FieldWitness>(s: &str) -> F {

ledger/src/proofs/step.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ pub mod step_verifier {
10671067
let v = if s_odd { s - F2::one() } else { s };
10681068
// TODO: Remove this ugly hack
10691069
let v: BigInteger256 = (v / F2::from(2u64)).into();
1070-
(F::try_from(v).unwrap(), s_odd.to_boolean()) // `unwrap` never fail
1070+
(F::from(v), s_odd.to_boolean()) // `unwrap` never fail
10711071
});
10721072

10731073
scale_fast2(g, s_parts, num_bits, w)

ledger/src/proofs/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3686,7 +3686,7 @@ pub fn messages_for_next_wrap_proof_padding() -> Fp {
36863686
old_bulletproof_challenges: vec![], // Filled with padding, in `hash()` below
36873687
};
36883688
let hash: [u64; 4] = msg.hash();
3689-
Fp::try_from(BigInteger256::new(hash)).unwrap() // Never fail
3689+
Fp::from(BigInteger256::new(hash)) // Never fail
36903690
})
36913691
}
36923692

@@ -4247,7 +4247,7 @@ pub(super) fn generate_tx_proof(
42474247
let statement_with_sok = statement.with_digest(sok_digest);
42484248

42494249
let dlog_plonk_index =
4250-
PlonkVerificationKeyEvals::from(&*tx_wrap_prover.index.verifier_index.as_ref().unwrap());
4250+
PlonkVerificationKeyEvals::from(tx_wrap_prover.index.verifier_index.as_ref().unwrap());
42514251

42524252
let statement_with_sok = Rc::new(w.exists(statement_with_sok));
42534253
transaction_snark::main(&statement_with_sok, tx_witness, w)?;

ledger/src/proofs/wrap.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ pub fn create_oracle_with_public_input<F: FieldWitness>(
200200
use poly_commitment::commitment::shift_scalar;
201201

202202
// TODO: Don't clone the SRS here
203-
let mut srs = (*verifier_index.srs).clone();
203+
let srs = (*verifier_index.srs).clone();
204204
let log_size_of_group = verifier_index.domain.log_size_of_group;
205-
let lgr_comm = make_lagrange::<F>(&mut srs, log_size_of_group);
205+
let lgr_comm = make_lagrange::<F>(&srs, log_size_of_group);
206206

207207
let lgr_comm: Vec<PolyComm<F::OtherCurve>> =
208208
lgr_comm.into_iter().take(public_input.len()).collect();
@@ -501,20 +501,21 @@ fn make_public_input(
501501
unfinalized_proofs.to_field_elements(&mut fields);
502502
}
503503

504-
let to_fp = |v: [u64; 4]| Fp::try_from(BigInteger256::new(v)).unwrap(); // Never fail, `messages_for_next_step_proof_hash` was a `Fp`
504+
let to_fp = |v: [u64; 4]| Fp::from(BigInteger256::new(v)); // Never fail, `messages_for_next_step_proof_hash` was a `Fp`
505505
to_fp(messages_for_next_step_proof_hash).to_field_elements(&mut fields);
506506

507507
// `messages_for_next_wrap_proof_hash` were `Fq` previously, so we have to
508508
// build a `Fp` from them with care: they can overflow
509509
let to_fp = |v: [u64; 4]| {
510-
match Fp::try_from(BigInteger256::new(v)) {
511-
Ok(fp) => fp, // fast-path: we get the `Fp` without modulo/reducing
512-
Err(_) => {
513-
// slow path: we build the `Fp` bit by bit, so it will reduce it
514-
let bits = crate::proofs::transaction::bigint_to_bits::<255>(BigInteger256::new(v));
515-
super::util::field_of_bits(&bits)
516-
}
517-
}
510+
// match Fp::try_from(BigInteger256::new(v)) {
511+
// Ok(fp) => fp, // fast-path: we get the `Fp` without modulo/reducing
512+
// Err(_) => {
513+
// // slow path: we build the `Fp` bit by bit, so it will reduce it
514+
// let bits = crate::proofs::transaction::bigint_to_bits::<255>(BigInteger256::new(v));
515+
// super::util::field_of_bits(&bits)
516+
// }
517+
// }
518+
Fp::from(BigInteger256::new(v))
518519
};
519520
for msg in messages_for_next_wrap_proof_hash.iter().copied().map(to_fp) {
520521
msg.to_field_elements(&mut fields);
@@ -687,7 +688,7 @@ pub fn wrap<C: ProofConstants + ForWrapData>(
687688
prover_index: step_prover_index,
688689
});
689690

690-
let to_fq = |[a, b]: [u64; 2]| Fq::try_from(BigInteger256::new([a, b, 0, 0])).unwrap(); // Never fail with 2 limbs
691+
let to_fq = |[a, b]: [u64; 2]| Fq::from(BigInteger256::new([a, b, 0, 0])); // Never fail with 2 limbs
691692
let to_fqs = |v: &[[u64; 2]]| v.iter().copied().map(to_fq).collect::<Vec<_>>();
692693

693694
let messages_for_next_wrap_proof = MessagesForNextWrapProof {
@@ -845,7 +846,7 @@ impl Check<Fq> for ShiftedValue<Fp> {
845846
let shifted: Fq = {
846847
let ShiftedValue { shifted } = self.clone();
847848
let f: BigInteger256 = shifted.into();
848-
f.try_into().unwrap() // Never fail, `Fq` is larger than `Fp`
849+
f.into() // Never fail, `Fq` is larger than `Fp`
849850
};
850851
field::equal(shifted, forbidden, w)
851852
});
@@ -2178,7 +2179,7 @@ pub mod wrap_verifier {
21782179

21792180
let combined_inner_product: Fq = {
21802181
let bigint: BigInteger256 = advice.combined_inner_product.shifted.into();
2181-
bigint.try_into().unwrap() // Never fail, `Fq` is larger than `Fp`
2182+
bigint.into() // Never fail, `Fq` is larger than `Fp`
21822183
};
21832184
sponge.absorb(&[combined_inner_product], w);
21842185

0 commit comments

Comments
 (0)