Skip to content

Commit

Permalink
fix: clippy errors (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
han0110 authored Oct 10, 2023
1 parent 6713d8d commit 547ac24
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 36 deletions.
36 changes: 10 additions & 26 deletions src/codegen/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use halo2_proofs::{
};
use itertools::{chain, izip, Itertools};
use ruint::aliases::U256;
use std::{borrow::Borrow, cell::RefCell, cmp::Ordering, collections::HashMap, iter};
use std::{cell::RefCell, cmp::Ordering, collections::HashMap, iter};

#[derive(Debug)]
pub(crate) struct Evaluator<'a, F: PrimeField> {
Expand Down Expand Up @@ -319,34 +319,18 @@ fn u256_string(value: U256) -> String {
}

fn fixed_eval_var(fixed_query: FixedQuery) -> String {
let column_index = fixed_query.column_index();
let rotation = fixed_query.rotation().0;
match rotation.cmp(&0) {
Ordering::Less => {
format!("f_{}_prev_{}", column_index, rotation.abs())
}
Ordering::Equal => {
format!("f_{}", column_index)
}
Ordering::Greater => {
format!("f_{}_next_{}", column_index, rotation)
}
}
column_eval_var("f", fixed_query.column_index(), fixed_query.rotation().0)
}

fn advice_eval_var(advice_query: AdviceQuery) -> String {
let column_index = advice_query.column_index();
let rotation = advice_query.rotation().0;
column_eval_var("a", advice_query.column_index(), advice_query.rotation().0)
}

fn column_eval_var(prefix: &'static str, column_index: usize, rotation: i32) -> String {
match rotation.cmp(&0) {
Ordering::Less => {
format!("a_{}_prev_{}", column_index, rotation.abs())
}
Ordering::Equal => {
format!("a_{}", column_index)
}
Ordering::Greater => {
format!("a_{}_next_{}", column_index, rotation)
}
Ordering::Less => format!("{prefix}_{column_index}_prev_{}", rotation.abs()),
Ordering::Equal => format!("{prefix}_{column_index}"),
Ordering::Greater => format!("{prefix}_{column_index}_next_{rotation}"),
}
}

Expand All @@ -371,7 +355,7 @@ where
expr, constant, fixed, advice, instance, challenge, negated, sum, product, scaled,
)
};
match expression.borrow() {
match expression {
Expression::Constant(scalar) => constant(fe_to_u256(*scalar)),
Expression::Selector(_) => unreachable!(),
Expression::Fixed(query) => fixed(*query),
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/pcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ pub(crate) fn bdfg21_computations(meta: &ConstraintSystemMeta, data: &Data) -> V
for_loop(
[
format!("let mptr := 0x00"),
format!("let mptr_end := {}", second_batch_invert_end),
format!("let mptr_end := {second_batch_invert_end}"),
format!("let sum_mptr := {}", sums[0].ptr()),
],
"lt(mptr, mptr_end)",
Expand All @@ -451,7 +451,7 @@ pub(crate) fn bdfg21_computations(meta: &ConstraintSystemMeta, data: &Data) -> V
for_loop(
[
format!("let sum_inv_mptr := {}", second_batch_invert_end - 2),
format!("let sum_inv_mptr_end := {}", second_batch_invert_end),
format!("let sum_inv_mptr_end := {second_batch_invert_end}"),
format!("let r_eval_mptr := {}", r_evals[r_evals.len() - 2].ptr()),
],
"lt(sum_inv_mptr, sum_inv_mptr_end)",
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mod filters {
}

pub fn hex_padded(value: impl LowerHex, pad: usize) -> ::askama::Result<String> {
let string = format!("0x{value:0pad$x}", pad = pad);
let string = format!("0x{value:0pad$x}");
if string == "0x0" {
Ok(format!("0x{}", "0".repeat(pad)))
} else {
Expand Down
12 changes: 5 additions & 7 deletions src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,18 @@ pub(crate) mod test {
for (log_idx, log) in logs.iter().enumerate() {
println!("log#{log_idx}");
for (topic_idx, topic) in log.topics.iter().enumerate() {
println!(" topic{topic_idx}: {:?}", topic);
println!(" topic{topic_idx}: {topic:?}");
}
}
println!("--- end ---");
}
(gas_used, output)
}
ExecutionResult::Revert { gas_used, output } => panic!(
"Transaction reverts with gas_used {gas_used} and output {:#x}",
output
),
ExecutionResult::Revert { gas_used, output } => {
panic!("Transaction reverts with gas_used {gas_used} and output {output:#x}")
}
ExecutionResult::Halt { reason, gas_used } => panic!(
"Transaction halts unexpectedly with gas_used {gas_used} and reason {:?}",
reason
"Transaction halts unexpectedly with gas_used {gas_used} and reason {reason:?}"
),
}
}
Expand Down

0 comments on commit 547ac24

Please sign in to comment.