Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Commit db0d403

Browse files
Upgrade rust version (#1769)
### Description We've been using the version one year ago. Let's get a new year vibe. ### Issue Link ### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Refactor (no updates to logic) ### Contents Major clippy fix - Clippy now detect useless vector. It is a little bit [buggy](rust-lang/rust-clippy#12101), and it sometimes complains without giving the exact line.
1 parent cd5edab commit db0d403

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+335
-343
lines changed

Cargo.lock

+127-115
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bus-mapping/src/circuit_input_builder/access.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl From<Vec<Access>> for AccessSet {
7272
for access in list {
7373
match access.value {
7474
AccessValue::Account { address } => {
75-
state.entry(address).or_insert_with(HashSet::new);
75+
state.entry(address).or_default();
7676
}
7777
AccessValue::Storage { address, key } => match state.entry(address) {
7878
Entry::Vacant(entry) => {
@@ -85,7 +85,7 @@ impl From<Vec<Access>> for AccessSet {
8585
}
8686
},
8787
AccessValue::Code { address } => {
88-
state.entry(address).or_insert_with(HashSet::new);
88+
state.entry(address).or_default();
8989
code.insert(address);
9090
}
9191
}

bus-mapping/src/circuit_input_builder/input_state_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ impl<'a> CircuitInputStateRef<'a> {
12251225
) -> Result<(), Error> {
12261226
let call = self.call()?.clone();
12271227
let geth_step = steps
1228-
.get(0)
1228+
.first()
12291229
.ok_or(Error::InternalError("invalid index 0"))?;
12301230
let is_revert_or_return_call_success = (geth_step.op == OpcodeId::REVERT
12311231
|| geth_step.op == OpcodeId::RETURN)
@@ -1419,7 +1419,7 @@ impl<'a> CircuitInputStateRef<'a> {
14191419

14201420
let call = self.call()?;
14211421

1422-
if matches!(next_step, None) {
1422+
if next_step.is_none() {
14231423
// enumerating call scope successful cases
14241424
// case 1: call with normal halt opcode termination
14251425
if matches!(

bus-mapping/src/precompile.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ pub(crate) fn execute_precompiled(
3636

3737
#[cfg(not(target_arch = "wasm32"))]
3838
{
39-
let Some(Precompile::Standard(precompile_fn)) = Precompiles::berlin()
40-
.get(address.as_fixed_bytes()) else {
39+
let Some(Precompile::Standard(precompile_fn)) =
40+
Precompiles::berlin().get(address.as_fixed_bytes())
41+
else {
4142
panic!("calling non-exist precompiled contract address")
4243
};
4344
let (return_data, gas_cost, is_oog, is_ok) = match precompile_fn(input, gas) {

eth-types/src/bytecode.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! EVM byte code generator
22
use crate::{evm_types::OpcodeId, keccak256, Bytes, Hash, ToBigEndian, ToWord, Word};
3-
use std::{collections::HashMap, iter, str::FromStr};
4-
3+
use std::{collections::HashMap, fmt::Display, iter, str::FromStr};
54
/// Error type for Bytecode related failures
65
#[derive(Debug)]
76
pub enum Error {
@@ -254,12 +253,13 @@ impl FromStr for OpcodeWithData {
254253
}
255254
}
256255

257-
impl ToString for OpcodeWithData {
258-
fn to_string(&self) -> String {
259-
match self {
256+
impl Display for OpcodeWithData {
257+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
258+
let str = match self {
260259
OpcodeWithData::Opcode(opcode) => format!("{:?}", opcode),
261260
OpcodeWithData::PushWithData(n, word) => format!("PUSH{}({})", n, word),
262-
}
261+
};
262+
f.write_str(&str)
263263
}
264264
}
265265

@@ -576,6 +576,6 @@ mod tests {
576576
POP
577577
STOP
578578
};
579-
assert_eq!(Bytecode::try_from(code.code()).unwrap(), code);
579+
assert_eq!(Bytecode::from(code.code()), code);
580580
}
581581
}

eth-types/src/evm_types.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ mod gas_create {
3434
// [gasCreate2Eip3860](https://github.com/ethereum/go-ethereum/blob/eb83e7c54021573eaceb14236af3a7a8c64f6027/core/vm/gas_table.go#L321)
3535
// (similar for CREATE).
3636
// 1. size <= 49152 (MaxInitCodeSize)
37-
// 2. gasCost = memoryGasCost + (2 + 6) * ((size + 31) / 32) should not
38-
// overflow for Uint64.
37+
// 2. gasCost = memoryGasCost + (2 + 6) * ((size + 31) / 32) should not overflow for Uint64.
3938
// No need to constrain the second condition, since the maximum gas cost
4039
// cannot overflow for Uint64 (36028809887100925 calculated by
4140
// `memorySize = 0x1FFFFFFFE0` and `size = 49152`) if the first condition is

eth-types/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#![deny(missing_docs)]
99
//#![deny(unsafe_code)] Allowed now until we find a
1010
// better way to handle downcasting from Operation into it's variants.
11-
#![allow(clippy::upper_case_acronyms)] // Too pedantic
11+
12+
// Too pedantic
13+
#![allow(clippy::upper_case_acronyms)]
14+
// Clippy is buggy on this one. Remove after https://github.com/rust-lang/rust-clippy/issues/12101 is resolved.
15+
#![allow(clippy::useless_vec)]
1216

1317
#[macro_use]
1418
pub mod macros;

eth-types/src/sign_types.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ pub fn ct_option_ok_or<T, E>(v: CtOption<T>, err: E) -> Result<T, E> {
135135
/// Return a copy of the serialized public key with swapped Endianness.
136136
pub fn pk_bytes_swap_endianness<T: Clone>(pk: &[T]) -> [T; 64] {
137137
assert_eq!(pk.len(), 64);
138-
let mut pk_swap = <&[T; 64]>::try_from(pk)
139-
.map(|r| r.clone())
140-
.expect("pk.len() != 64");
138+
let mut pk_swap = <&[T; 64]>::try_from(pk).cloned().expect("pk.len() != 64");
141139
pk_swap[..32].reverse();
142140
pk_swap[32..].reverse();
143141
pk_swap

geth-utils/src/mpt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn get_witness(block_no: u64, mods: &[TrieModification], node_url: &str) ->
8686

8787
let json = serde_json::to_string(&req).expect("Invalid request");
8888
let c_config = CString::new(json).expect("invalid config");
89-
let result = unsafe { go::GetMptWitness(c_config.as_ptr() as *const i8) };
89+
let result = unsafe { go::GetMptWitness(c_config.as_ptr()) };
9090
let c_str = unsafe { CStr::from_ptr(result) };
9191
let json = c_str
9292
.to_str()

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2023-04-24
1+
nightly-2024-02-14

testool/src/compiler.rs

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ impl Cache {
4747
let entry = format!("{}={}\n", hex::encode(code_hash), hex::encode(&bytecode));
4848
std::fs::OpenOptions::new()
4949
.read(true)
50-
.write(true)
5150
.create(true)
5251
.append(true)
5352
.open(&self.path)?

testool/src/statetest/results.rs

-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ impl Results {
392392
if let Some(path) = &self.cache {
393393
let mut file = std::fs::OpenOptions::new()
394394
.read(true)
395-
.write(true)
396395
.create(true)
397396
.append(true)
398397
.open(path)?;
@@ -441,7 +440,6 @@ impl Results {
441440
if let Some(path) = &self.cache {
442441
std::fs::OpenOptions::new()
443442
.read(true)
444-
.write(true)
445443
.create(true)
446444
.append(true)
447445
.open(path)?

testool/src/statetest/yaml.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ impl<'a> YamlStateTestBuilder<'a> {
410410

411411
#[cfg(test)]
412412
mod test {
413+
use std::fmt::Display;
414+
413415
use super::*;
414416
use crate::{
415417
config::TestSuite,
@@ -524,9 +526,9 @@ arith:
524526
}
525527
}
526528
}
527-
impl ToString for Template {
528-
fn to_string(&self) -> String {
529-
TEMPLATE
529+
impl Display for Template {
530+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
531+
let str = TEMPLATE
530532
.replace("{{ gas_limit }}", &self.gas_limit)
531533
.replace("{{ pre_code }}", &self.pre_code)
532534
.replace("{{ res_storage }}", &self.res_storage)
@@ -540,7 +542,8 @@ arith:
540542
} else {
541543
"Istanbul"
542544
},
543-
)
545+
);
546+
f.write_str(&str)
544547
}
545548
}
546549

testool/src/utils.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,12 @@ pub fn current_submodule_git_commit() -> Result<String> {
181181

182182
pub fn bytecode_of(code: &str) -> anyhow::Result<Bytecode> {
183183
let bytecode = if let Ok(bytes) = hex::decode(code) {
184-
match Bytecode::try_from(bytes.clone()) {
185-
Ok(bytecode) => {
186-
for op in bytecode.iter() {
187-
info!("{}", op.to_string());
188-
}
189-
bytecode
190-
}
191-
Err(err) => {
192-
error!("Failed to parse bytecode {:?}", err);
193-
Bytecode::from_raw_unchecked(bytes)
194-
}
184+
let bytecode = Bytecode::from(bytes.clone());
185+
186+
for op in bytecode.iter() {
187+
info!("{}", op.to_string());
195188
}
189+
bytecode
196190
} else {
197191
let mut bytecode = Bytecode::default();
198192
for op in code.split(',') {

zkevm-circuits/src/bytecode_circuit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<F: Field> SubCircuitConfig<F> for BytecodeCircuitConfig<F> {
347347
is_byte(meta),
348348
]);
349349

350-
let lookup_columns = vec![value, push_data_size];
350+
let lookup_columns = [value, push_data_size];
351351

352352
let mut constraints = vec![];
353353

zkevm-circuits/src/circuit_tools/cell_manager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<F: Field, C: CellType> Eq for CellColumn<F, C> {}
239239

240240
impl<F: Field, C: CellType> PartialOrd for CellColumn<F, C> {
241241
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
242-
self.height.partial_cmp(&other.height)
242+
Some(self.cmp(other))
243243
}
244244
}
245245

zkevm-circuits/src/circuit_tools/constraint_builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl<F: Field, C: CellType> ConstraintBuilder<F, C> {
322322

323323
pub(crate) fn query_default(&mut self) -> Cell<F> {
324324
self.query_cells_dyn(C::default(), 1)
325-
.get(0)
325+
.first()
326326
.expect("No cell found")
327327
.clone()
328328
}
@@ -536,7 +536,7 @@ impl<F: Field, C: CellType> ConstraintBuilder<F, C> {
536536
));
537537
self.stored_expressions
538538
.entry(self.region_id)
539-
.or_insert_with(Vec::new)
539+
.or_default()
540540
.push(StoredExpression {
541541
name,
542542
cell: cell.clone(),

zkevm-circuits/src/copy_circuit.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
363363
0.expr(), // init_val_hi
364364
]
365365
.into_iter()
366-
.zip_eq(rw_table.table_exprs(meta).into_iter())
366+
.zip_eq(rw_table.table_exprs(meta))
367367
.map(|(arg, table)| (cond.clone() * arg, table))
368368
.collect()
369369
});
@@ -388,7 +388,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
388388
0.expr(), // init_val_hi
389389
]
390390
.into_iter()
391-
.zip_eq(rw_table.table_exprs(meta).into_iter())
391+
.zip_eq(rw_table.table_exprs(meta))
392392
.map(|(arg, table)| (cond.clone() * arg, table))
393393
.collect()
394394
});
@@ -406,7 +406,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
406406
meta.query_advice(value, Rotation::cur()),
407407
]
408408
.into_iter()
409-
.zip_eq(bytecode_table.table_exprs(meta).into_iter())
409+
.zip_eq(bytecode_table.table_exprs(meta))
410410
.map(|(arg, table)| (cond.clone() * arg, table))
411411
.collect()
412412
});
@@ -423,7 +423,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
423423
meta.query_advice(value, Rotation::cur()),
424424
]
425425
.into_iter()
426-
.zip(tx_table.table_exprs(meta).into_iter())
426+
.zip(tx_table.table_exprs(meta))
427427
.map(|(arg, table)| (cond.clone() * arg, table))
428428
.collect()
429429
});
@@ -807,7 +807,7 @@ impl<F: Field> CopyCircuit<F> {
807807
Self {
808808
copy_events,
809809
max_copy_rows,
810-
_marker: PhantomData::default(),
810+
_marker: PhantomData,
811811
external_data: ExternalData::default(),
812812
}
813813
}
@@ -821,7 +821,7 @@ impl<F: Field> CopyCircuit<F> {
821821
Self {
822822
copy_events,
823823
max_copy_rows,
824-
_marker: PhantomData::default(),
824+
_marker: PhantomData,
825825
external_data,
826826
}
827827
}

zkevm-circuits/src/evm_circuit/execution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ impl<F: Field> ExecutionConfig<F> {
974974
.txs
975975
.last()
976976
.map(|tx| tx.calls()[0].clone())
977-
.unwrap_or_else(Call::default);
977+
.unwrap_or_default();
978978
let end_block_not_last = &block.end_block_not_last;
979979
let end_block_last = &block.end_block_last;
980980
// Collect all steps

zkevm-circuits/src/evm_circuit/execution/error_oog_precompile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGPrecompileGadget<F> {
6363
});
6464

6565
// calculate required gas for precompile
66-
let precompiles_required_gas = vec![
66+
let precompiles_required_gas = [
6767
// (
6868
// addr_bits.value_equals(PrecompileCalls::ECRecover),
6969
// GasCost::PRECOMPILE_ECRECOVER_BASE.expr(),

zkevm-circuits/src/evm_circuit/execution/mulmod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ impl<F: Field> ExecutionGadget<F> for MulModGadget<F> {
6060
let d = cb.query_word32();
6161
let e = cb.query_word32();
6262

63-
// 1. k1 * n + a_reduced == a
63+
// 1. k1 * n + a_reduced == a
6464
let modword = ModGadget::construct(cb, [&a, &n, &a_reduced]);
6565

66-
// 2. a_reduced * b + 0 == d * 2^256 + e
66+
// 2. a_reduced * b + 0 == d * 2^256 + e
6767
let mul512_left = MulAddWords512Gadget::construct(cb, [&a_reduced, &b, &d, &e], None);
6868

69-
// 3. k2 * n + r == d * 2^256 + e
69+
// 3. k2 * n + r == d * 2^256 + e
7070
let mul512_right = MulAddWords512Gadget::construct(cb, [&k, &n, &d, &e], Some(&r));
7171

7272
// (r < n ) or n == 0

zkevm-circuits/src/evm_circuit/execution/shl_shr.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ impl<F: Field> ExecutionGadget<F> for ShlShrGadget<F> {
179179
let shf_lt256 = pop1
180180
.to_le_bytes()
181181
.iter()
182-
.fold(Some(0_u64), |acc, val| {
183-
acc.and_then(|acc| acc.checked_add(u64::from(*val)))
184-
})
182+
.try_fold(0u64, |acc, val| acc.checked_add(u64::from(*val)))
185183
.unwrap()
186184
- shf0;
187185
let divisor = if shf_lt256 == 0 {

zkevm-circuits/src/evm_circuit/execution/signextend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ mod test {
280280
let pos_extend = 0u8;
281281
let neg_extend = 0xFFu8;
282282

283-
for (value, byte_extend) in vec![(pos_value, pos_extend), (neg_value, neg_extend)].iter() {
283+
for (value, byte_extend) in [(pos_value, pos_extend), (neg_value, neg_extend)].iter() {
284284
for idx in 0..33 {
285285
test_ok(
286286
(idx as u64).into(),

zkevm-circuits/src/evm_circuit/step.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use halo2_proofs::{
2929
circuit::Value,
3030
plonk::{Advice, Column, ConstraintSystem, Error, Expression},
3131
};
32-
use std::{fmt::Display, iter};
32+
use std::{fmt::Display, iter, marker::ConstParamTy};
3333
use strum::IntoEnumIterator;
3434
use strum_macros::EnumIter;
3535

@@ -50,7 +50,7 @@ impl From<PrecompileCalls> for ExecutionState {
5050
}
5151

5252
#[allow(non_camel_case_types, missing_docs)]
53-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, EnumIter)]
53+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, EnumIter, ConstParamTy)]
5454
/// All the possible execution states that the computation of EVM can arrive.
5555
/// Some states are shared by multiple opcodes.
5656
pub enum ExecutionState {

zkevm-circuits/src/evm_circuit/util/constraint_builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ pub(crate) trait ConstrainBuilderCommon<F: Field> {
207207
.fold(1.expr(), |acc, item| acc * (value.clone() - item.clone())),
208208
);
209209
}
210-
210+
/// Under active development
211+
#[allow(dead_code)]
211212
fn add_constraints(&mut self, constraints: Vec<(&'static str, Expression<F>)>) {
212213
for (name, constraint) in constraints {
213214
self.add_constraint(name, constraint);

0 commit comments

Comments
 (0)