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

Upgrade rust version #1769

Merged
merged 7 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 127 additions & 115 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bus-mapping/src/circuit_input_builder/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl From<Vec<Access>> for AccessSet {
for access in list {
match access.value {
AccessValue::Account { address } => {
state.entry(address).or_insert_with(HashSet::new);
state.entry(address).or_default();
}
AccessValue::Storage { address, key } => match state.entry(address) {
Entry::Vacant(entry) => {
Expand All @@ -85,7 +85,7 @@ impl From<Vec<Access>> for AccessSet {
}
},
AccessValue::Code { address } => {
state.entry(address).or_insert_with(HashSet::new);
state.entry(address).or_default();
code.insert(address);
}
}
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ impl<'a> CircuitInputStateRef<'a> {
) -> Result<(), Error> {
let call = self.call()?.clone();
let geth_step = steps
.get(0)
.first()
.ok_or(Error::InternalError("invalid index 0"))?;
let is_revert_or_return_call_success = (geth_step.op == OpcodeId::REVERT
|| geth_step.op == OpcodeId::RETURN)
Expand Down Expand Up @@ -1419,7 +1419,7 @@ impl<'a> CircuitInputStateRef<'a> {

let call = self.call()?;

if matches!(next_step, None) {
if next_step.is_none() {
// enumerating call scope successful cases
// case 1: call with normal halt opcode termination
if matches!(
Expand Down
5 changes: 3 additions & 2 deletions bus-mapping/src/precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ pub(crate) fn execute_precompiled(

#[cfg(not(target_arch = "wasm32"))]
{
let Some(Precompile::Standard(precompile_fn)) = Precompiles::berlin()
.get(address.as_fixed_bytes()) else {
let Some(Precompile::Standard(precompile_fn)) =
Precompiles::berlin().get(address.as_fixed_bytes())
else {
panic!("calling non-exist precompiled contract address")
};
let (return_data, gas_cost, is_oog, is_ok) = match precompile_fn(input, gas) {
Expand Down
14 changes: 7 additions & 7 deletions eth-types/src/bytecode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! EVM byte code generator
use crate::{evm_types::OpcodeId, keccak256, Bytes, Hash, ToBigEndian, ToWord, Word};
use std::{collections::HashMap, iter, str::FromStr};

use std::{collections::HashMap, fmt::Display, iter, str::FromStr};
/// Error type for Bytecode related failures
#[derive(Debug)]
pub enum Error {
Expand Down Expand Up @@ -254,12 +253,13 @@ impl FromStr for OpcodeWithData {
}
}

impl ToString for OpcodeWithData {
fn to_string(&self) -> String {
match self {
impl Display for OpcodeWithData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self {
OpcodeWithData::Opcode(opcode) => format!("{:?}", opcode),
OpcodeWithData::PushWithData(n, word) => format!("PUSH{}({})", n, word),
}
};
f.write_str(&str)
}
}

Expand Down Expand Up @@ -576,6 +576,6 @@ mod tests {
POP
STOP
};
assert_eq!(Bytecode::try_from(code.code()).unwrap(), code);
assert_eq!(Bytecode::from(code.code()), code);
}
}
3 changes: 1 addition & 2 deletions eth-types/src/evm_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ mod gas_create {
// [gasCreate2Eip3860](https://github.com/ethereum/go-ethereum/blob/eb83e7c54021573eaceb14236af3a7a8c64f6027/core/vm/gas_table.go#L321)
// (similar for CREATE).
// 1. size <= 49152 (MaxInitCodeSize)
// 2. gasCost = memoryGasCost + (2 + 6) * ((size + 31) / 32) should not
// overflow for Uint64.
// 2. gasCost = memoryGasCost + (2 + 6) * ((size + 31) / 32) should not overflow for Uint64.
// No need to constrain the second condition, since the maximum gas cost
// cannot overflow for Uint64 (36028809887100925 calculated by
// `memorySize = 0x1FFFFFFFE0` and `size = 49152`) if the first condition is
Expand Down
6 changes: 5 additions & 1 deletion eth-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#![deny(missing_docs)]
//#![deny(unsafe_code)] Allowed now until we find a
// better way to handle downcasting from Operation into it's variants.
#![allow(clippy::upper_case_acronyms)] // Too pedantic

// Too pedantic
#![allow(clippy::upper_case_acronyms)]
// Clippy is buggy on this one. Remove after https://github.com/rust-lang/rust-clippy/issues/12101 is resolved.
#![allow(clippy::useless_vec)]

#[macro_use]
pub mod macros;
Expand Down
4 changes: 1 addition & 3 deletions eth-types/src/sign_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ pub fn ct_option_ok_or<T, E>(v: CtOption<T>, err: E) -> Result<T, E> {
/// Return a copy of the serialized public key with swapped Endianness.
pub fn pk_bytes_swap_endianness<T: Clone>(pk: &[T]) -> [T; 64] {
assert_eq!(pk.len(), 64);
let mut pk_swap = <&[T; 64]>::try_from(pk)
.map(|r| r.clone())
.expect("pk.len() != 64");
let mut pk_swap = <&[T; 64]>::try_from(pk).cloned().expect("pk.len() != 64");
pk_swap[..32].reverse();
pk_swap[32..].reverse();
pk_swap
Expand Down
2 changes: 1 addition & 1 deletion geth-utils/src/mpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn get_witness(block_no: u64, mods: &[TrieModification], node_url: &str) ->

let json = serde_json::to_string(&req).expect("Invalid request");
let c_config = CString::new(json).expect("invalid config");
let result = unsafe { go::GetMptWitness(c_config.as_ptr() as *const i8) };
let result = unsafe { go::GetMptWitness(c_config.as_ptr()) };
let c_str = unsafe { CStr::from_ptr(result) };
let json = c_str
.to_str()
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2023-04-24
nightly-2024-02-14
1 change: 0 additions & 1 deletion testool/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ impl Cache {
let entry = format!("{}={}\n", hex::encode(code_hash), hex::encode(&bytecode));
std::fs::OpenOptions::new()
.read(true)
.write(true)
.create(true)
.append(true)
.open(&self.path)?
Expand Down
2 changes: 0 additions & 2 deletions testool/src/statetest/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ impl Results {
if let Some(path) = &self.cache {
let mut file = std::fs::OpenOptions::new()
.read(true)
.write(true)
.create(true)
.append(true)
.open(path)?;
Expand Down Expand Up @@ -441,7 +440,6 @@ impl Results {
if let Some(path) = &self.cache {
std::fs::OpenOptions::new()
.read(true)
.write(true)
.create(true)
.append(true)
.open(path)?
Expand Down
11 changes: 7 additions & 4 deletions testool/src/statetest/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ impl<'a> YamlStateTestBuilder<'a> {

#[cfg(test)]
mod test {
use std::fmt::Display;

use super::*;
use crate::{
config::TestSuite,
Expand Down Expand Up @@ -524,9 +526,9 @@ arith:
}
}
}
impl ToString for Template {
fn to_string(&self) -> String {
TEMPLATE
impl Display for Template {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = TEMPLATE
.replace("{{ gas_limit }}", &self.gas_limit)
.replace("{{ pre_code }}", &self.pre_code)
.replace("{{ res_storage }}", &self.res_storage)
Expand All @@ -540,7 +542,8 @@ arith:
} else {
"Istanbul"
},
)
);
f.write_str(&str)
}
}

Expand Down
16 changes: 5 additions & 11 deletions testool/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,12 @@ pub fn current_submodule_git_commit() -> Result<String> {

pub fn bytecode_of(code: &str) -> anyhow::Result<Bytecode> {
let bytecode = if let Ok(bytes) = hex::decode(code) {
match Bytecode::try_from(bytes.clone()) {
Ok(bytecode) => {
for op in bytecode.iter() {
info!("{}", op.to_string());
}
bytecode
}
Err(err) => {
error!("Failed to parse bytecode {:?}", err);
Bytecode::from_raw_unchecked(bytes)
}
let bytecode = Bytecode::from(bytes.clone());

for op in bytecode.iter() {
info!("{}", op.to_string());
}
bytecode
} else {
let mut bytecode = Bytecode::default();
for op in code.split(',') {
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/bytecode_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<F: Field> SubCircuitConfig<F> for BytecodeCircuitConfig<F> {
is_byte(meta),
]);

let lookup_columns = vec![value, push_data_size];
let lookup_columns = [value, push_data_size];

let mut constraints = vec![];

Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/circuit_tools/cell_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<F: Field, C: CellType> Eq for CellColumn<F, C> {}

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

Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/circuit_tools/constraint_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl<F: Field, C: CellType> ConstraintBuilder<F, C> {

pub(crate) fn query_default(&mut self) -> Cell<F> {
self.query_cells_dyn(C::default(), 1)
.get(0)
.first()
.expect("No cell found")
.clone()
}
Expand Down Expand Up @@ -536,7 +536,7 @@ impl<F: Field, C: CellType> ConstraintBuilder<F, C> {
));
self.stored_expressions
.entry(self.region_id)
.or_insert_with(Vec::new)
.or_default()
.push(StoredExpression {
name,
cell: cell.clone(),
Expand Down
12 changes: 6 additions & 6 deletions zkevm-circuits/src/copy_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
0.expr(), // init_val_hi
]
.into_iter()
.zip_eq(rw_table.table_exprs(meta).into_iter())
.zip_eq(rw_table.table_exprs(meta))
.map(|(arg, table)| (cond.clone() * arg, table))
.collect()
});
Expand All @@ -388,7 +388,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
0.expr(), // init_val_hi
]
.into_iter()
.zip_eq(rw_table.table_exprs(meta).into_iter())
.zip_eq(rw_table.table_exprs(meta))
.map(|(arg, table)| (cond.clone() * arg, table))
.collect()
});
Expand All @@ -406,7 +406,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
meta.query_advice(value, Rotation::cur()),
]
.into_iter()
.zip_eq(bytecode_table.table_exprs(meta).into_iter())
.zip_eq(bytecode_table.table_exprs(meta))
.map(|(arg, table)| (cond.clone() * arg, table))
.collect()
});
Expand All @@ -423,7 +423,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
meta.query_advice(value, Rotation::cur()),
]
.into_iter()
.zip(tx_table.table_exprs(meta).into_iter())
.zip(tx_table.table_exprs(meta))
.map(|(arg, table)| (cond.clone() * arg, table))
.collect()
});
Expand Down Expand Up @@ -807,7 +807,7 @@ impl<F: Field> CopyCircuit<F> {
Self {
copy_events,
max_copy_rows,
_marker: PhantomData::default(),
_marker: PhantomData,
external_data: ExternalData::default(),
}
}
Expand All @@ -821,7 +821,7 @@ impl<F: Field> CopyCircuit<F> {
Self {
copy_events,
max_copy_rows,
_marker: PhantomData::default(),
_marker: PhantomData,
external_data,
}
}
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ impl<F: Field> ExecutionConfig<F> {
.txs
.last()
.map(|tx| tx.calls()[0].clone())
.unwrap_or_else(Call::default);
.unwrap_or_default();
let end_block_not_last = &block.end_block_not_last;
let end_block_last = &block.end_block_last;
// Collect all steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGPrecompileGadget<F> {
});

// calculate required gas for precompile
let precompiles_required_gas = vec![
let precompiles_required_gas = [
// (
// addr_bits.value_equals(PrecompileCalls::ECRecover),
// GasCost::PRECOMPILE_ECRECOVER_BASE.expr(),
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/mulmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ impl<F: Field> ExecutionGadget<F> for MulModGadget<F> {
let d = cb.query_word32();
let e = cb.query_word32();

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

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

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

// (r < n ) or n == 0
Expand Down
4 changes: 1 addition & 3 deletions zkevm-circuits/src/evm_circuit/execution/shl_shr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ impl<F: Field> ExecutionGadget<F> for ShlShrGadget<F> {
let shf_lt256 = pop1
.to_le_bytes()
.iter()
.fold(Some(0_u64), |acc, val| {
acc.and_then(|acc| acc.checked_add(u64::from(*val)))
})
.try_fold(0u64, |acc, val| acc.checked_add(u64::from(*val)))
.unwrap()
- shf0;
let divisor = if shf_lt256 == 0 {
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/signextend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ mod test {
let pos_extend = 0u8;
let neg_extend = 0xFFu8;

for (value, byte_extend) in vec![(pos_value, pos_extend), (neg_value, neg_extend)].iter() {
for (value, byte_extend) in [(pos_value, pos_extend), (neg_value, neg_extend)].iter() {
for idx in 0..33 {
test_ok(
(idx as u64).into(),
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use halo2_proofs::{
circuit::Value,
plonk::{Advice, Column, ConstraintSystem, Error, Expression},
};
use std::{fmt::Display, iter};
use std::{fmt::Display, iter, marker::ConstParamTy};
use strum::IntoEnumIterator;
use strum_macros::EnumIter;

Expand All @@ -50,7 +50,7 @@ impl From<PrecompileCalls> for ExecutionState {
}

#[allow(non_camel_case_types, missing_docs)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, EnumIter)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, EnumIter, ConstParamTy)]
/// All the possible execution states that the computation of EVM can arrive.
/// Some states are shared by multiple opcodes.
pub enum ExecutionState {
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/evm_circuit/util/constraint_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ pub(crate) trait ConstrainBuilderCommon<F: Field> {
.fold(1.expr(), |acc, item| acc * (value.clone() - item.clone())),
);
}

/// Under active development
#[allow(dead_code)]
fn add_constraints(&mut self, constraints: Vec<(&'static str, Expression<F>)>) {
for (name, constraint) in constraints {
self.add_constraint(name, constraint);
Expand Down
Loading