Skip to content

Commit

Permalink
[chore] upgrade toolchain to nightly-2023-04-24 (privacy-scaling-expl…
Browse files Browse the repository at this point in the history
…orations#1373)

### Description

Upgrade toolchain to nightly-2023-04-24 for future compatibilities.

### Issue Link

N/A

### 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

### Contents

- Toolchain upgrade to nightly-2023-04-24
- Fix lint errors

### Rationale

The toolchain currently in use is outdated and lacks stable features.
Issue privacy-scaling-explorations#1372 requires GAT, which has been stabilized since version
`1.65.0`. Meanwhile, the current stable Rust version is `1.69.0`.

### How Has This Been Tested?

N/A
  • Loading branch information
lightsing authored Apr 26, 2023
1 parent 4e64bdb commit 757d1ee
Show file tree
Hide file tree
Showing 29 changed files with 50 additions and 70 deletions.
4 changes: 2 additions & 2 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ pub fn keccak_inputs_tx_circuit(
}

/// Retrieve the init_code from memory for {CREATE, CREATE2}
pub fn get_create_init_code<'a, 'b>(
pub fn get_create_init_code<'a>(
call_ctx: &'a CallContext,
step: &'b GethExecStep,
step: &GethExecStep,
) -> Result<&'a [u8], Error> {
let offset = step.stack.nth_last(1)?;
let length = step.stack.nth_last(2)?;
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/circuit_input_builder/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ pub fn gen_state_access_trace<TX>(
if call_stack.len() == 1 {
return Err(Error::InvalidGethExecStep(
"gen_state_access_trace: call stack will be empty",
step.clone(),
Box::new(step.clone()),
));
}
call_stack.pop().expect("call stack is empty");
Expand Down
10 changes: 5 additions & 5 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> {
_ => {
return Err(Error::UnexpectedExecStepError(
"call failure without return",
step.clone(),
Box::new(step.clone()),
));
}
});
Expand All @@ -1246,13 +1246,13 @@ impl<'a> CircuitInputStateRef<'a> {
} else {
return Err(Error::UnexpectedExecStepError(
"failure in RETURN from {CREATE, CREATE2}",
step.clone(),
Box::new(step.clone()),
));
}
} else {
return Err(Error::UnexpectedExecStepError(
"failure in RETURN",
step.clone(),
Box::new(step.clone()),
));
}
}
Expand All @@ -1272,7 +1272,7 @@ impl<'a> CircuitInputStateRef<'a> {
{
return Err(Error::UnexpectedExecStepError(
"success result without {RETURN, STOP, SELFDESTRUCT}",
step.clone(),
Box::new(step.clone()),
));
}

Expand Down Expand Up @@ -1314,7 +1314,7 @@ impl<'a> CircuitInputStateRef<'a> {

return Err(Error::UnexpectedExecStepError(
"*CALL*/CREATE* code not executed",
step.clone(),
Box::new(step.clone()),
));
}

Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ pub enum Error {
/// Code not found in the CodeDB
CodeNotFound(H256),
/// Unable to figure out error at a [`GethExecStep`]
UnexpectedExecStepError(&'static str, GethExecStep),
UnexpectedExecStepError(&'static str, Box<GethExecStep>),
/// Invalid [`eth_types::GethExecTrace`] due to an invalid/unexpected value
/// in it.
InvalidGethExecTrace(&'static str),
/// Invalid [`GethExecStep`] due to an invalid/unexpected value in it.
InvalidGethExecStep(&'static str, GethExecStep),
InvalidGethExecStep(&'static str, Box<GethExecStep>),
/// Eth type related error.
EthTypeError(eth_types::Error),
/// EVM Execution error
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/calldatacopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ mod calldatacopy_tests {
assert_eq!(copy_events[0].bytes.len(), size);

for (idx, (value, is_code)) in copy_events[0].bytes.iter().enumerate() {
assert_eq!(value, calldata.get(offset as usize + idx).unwrap_or(&0));
assert_eq!(value, calldata.get(offset + idx).unwrap_or(&0));
assert!(!is_code);
}
}
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/state_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl CodeDB {

/// Compute hash of given code.
pub fn hash(code: &[u8]) -> Hash {
H256(keccak256(&code))
H256(keccak256(code))
}

/// Code hash of empty code.
Expand Down
2 changes: 1 addition & 1 deletion circuit-benchmarks/src/exp_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod tests {
// Bench setup generation
let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree);
let start1 = start_timer!(|| setup_message);
let general_params = ParamsKZG::<Bn256>::setup(degree as u32, &mut rng);
let general_params = ParamsKZG::<Bn256>::setup(degree, &mut rng);
let verifier_params: ParamsVerifierKZG<Bn256> = general_params.verifier_params().clone();
end_timer!(start1);

Expand Down
2 changes: 1 addition & 1 deletion circuit-benchmarks/src/pi_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod tests {
// Bench setup generation
let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree);
let start1 = start_timer!(|| setup_message);
let general_params = ParamsKZG::<Bn256>::setup(degree as u32, &mut rng);
let general_params = ParamsKZG::<Bn256>::setup(degree, &mut rng);
let verifier_params: ParamsVerifierKZG<Bn256> = general_params.verifier_params().clone();
end_timer!(start1);

Expand Down
2 changes: 1 addition & 1 deletion circuit-benchmarks/src/tx_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod tests {
// Bench setup generation
let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree);
let start1 = start_timer!(|| setup_message);
let general_params = ParamsKZG::<Bn256>::setup(degree as u32, &mut rng);
let general_params = ParamsKZG::<Bn256>::setup(degree, &mut rng);
let verifier_params: ParamsVerifierKZG<Bn256> = general_params.verifier_params().clone();
end_timer!(start1);

Expand Down
6 changes: 3 additions & 3 deletions eth-types/src/evm_types/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,10 @@ mod memory_tests {
let first_usize = 64536usize;
// Parsing on both ways works.
assert_eq!(
MemoryAddress::from_le_bytes(&first_usize.to_le_bytes())?,
MemoryAddress::from_be_bytes(&first_usize.to_be_bytes())?
MemoryAddress::from_le_bytes(first_usize.to_le_bytes())?,
MemoryAddress::from_be_bytes(first_usize.to_be_bytes())?
);
let addr = MemoryAddress::from_le_bytes(&first_usize.to_le_bytes())?;
let addr = MemoryAddress::from_le_bytes(first_usize.to_le_bytes())?;
assert_eq!(addr, MemoryAddress::from(first_usize));

// Little endian export
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2022-08-23
nightly-2023-04-24
2 changes: 1 addition & 1 deletion testool/src/statetest/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn decompose_tags(expr: &str) -> HashMap<String, String> {
} else {
while !it.is_empty() {
if it.starts_with(':') {
let tag = &it[..it.find(&[' ', '\n']).expect("unable to find end tag")];
let tag = &it[..it.find([' ', '\n']).expect("unable to find end tag")];
it = &it[tag.len() + 1..];
let value_len = if tag == ":yul" || tag == ":solidity" || tag == ":asm" {
it.len()
Expand Down
2 changes: 1 addition & 1 deletion testool/src/statetest/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl<'a> YamlStateTestBuilder<'a> {
} else {
while !it.is_empty() {
if it.starts_with(':') {
let tag = &it[..it.find(&[' ', '\n']).expect("unable to find end tag")];
let tag = &it[..it.find([' ', '\n']).expect("unable to find end tag")];
it = &it[tag.len() + 1..];
let value_len = if tag == ":yul" || tag == ":solidity" {
it.len()
Expand Down
6 changes: 3 additions & 3 deletions testool/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn print_trace(trace: GethExecTrace) -> Result<()> {
format!("{}", step.gas.0),
format!("{}", step.gas_cost.0),
format!("{}", step.depth),
step.error.unwrap_or_else(|| "".to_string()),
step.error.unwrap_or_default(),
split(step.stack.0.iter().map(u256_to_str).collect(), 30),
split(step.memory.0.iter().map(ToString::to_string).collect(), 30),
split(kv(step.storage.0), 30)
Expand All @@ -146,7 +146,7 @@ pub fn print_trace(trace: GethExecTrace) -> Result<()> {

pub fn current_git_commit() -> Result<String> {
let output = Command::new("git")
.args(&["rev-parse", "HEAD"])
.args(["rev-parse", "HEAD"])
.output()
.unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
Expand All @@ -156,7 +156,7 @@ pub fn current_git_commit() -> Result<String> {

pub fn current_submodule_git_commit() -> Result<String> {
let git_cmd = Command::new("git")
.args(&["ls-tree", "HEAD"])
.args(["ls-tree", "HEAD"])
.stdout(Stdio::piped())
.output()?;

Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/bytecode_circuit/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl<F: Field> BytecodeCircuitConfig<F> {
push_data_left,
value_rlc,
length,
F::from(push_data_size as u64),
F::from(push_data_size),
)?;

trace!(
Expand Down Expand Up @@ -865,8 +865,8 @@ impl<F: Field> BytecodeCircuit<F> {
pub fn new_from_block_sized(block: &witness::Block<F>, bytecode_size: usize) -> Self {
let bytecodes: Vec<UnrolledBytecode<F>> = block
.bytecodes
.iter()
.map(|(_, b)| unroll(b.bytes.clone()))
.values()
.map(|b| unroll(b.bytes.clone()))
.collect();
Self::new(bytecodes, bytecode_size)
}
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<F: Field> ExecutionGadget<F> for CallDataCopyGadget<F> {
region,
offset,
length.as_u64(),
memory_expansion_gas_cost as u64,
memory_expansion_gas_cost,
)?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl<F: Field> ExecutionGadget<F> for ExtcodecopyGadget<F> {
region,
offset,
memory_length.as_u64(),
memory_expansion_gas_cost as u64,
memory_expansion_gas_cost,
)?;

Ok(())
Expand Down
7 changes: 2 additions & 5 deletions zkevm-circuits/src/evm_circuit/execution/msize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,8 @@ impl<F: Field> ExecutionGadget<F> for MsizeGadget<F> {
step: &ExecStep,
) -> Result<(), Error> {
self.same_context.assign_exec_step(region, offset, step)?;
self.value.assign(
region,
offset,
Some((step.memory_size as u64).to_le_bytes()),
)?;
self.value
.assign(region, offset, Some((step.memory_size).to_le_bytes()))?;

Ok(())
}
Expand Down
8 changes: 2 additions & 6 deletions zkevm-circuits/src/evm_circuit/execution/sha3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,8 @@ impl<F: Field> ExecutionGadget<F> for Sha3Gadget<F> {
step.memory_word_size(),
[memory_address],
)?;
self.memory_copier_gas.assign(
region,
offset,
size.as_u64(),
memory_expansion_gas_cost as u64,
)?;
self.memory_copier_gas
.assign(region, offset, size.as_u64(), memory_expansion_gas_cost)?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ impl<F: FieldExt> Step<F> {
self.state.program_counter.assign(
region,
offset,
Value::known(F::from(step.program_counter as u64)),
Value::known(F::from(step.program_counter)),
)?;
self.state.stack_pointer.assign(
region,
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl CellType {
}

/// Return the storage phase of phase
pub(crate) fn storage_for_phase<F: FieldExt>(phase: u8) -> CellType {
pub(crate) fn storage_for_phase(phase: u8) -> CellType {
match phase {
0 => CellType::StoragePhase1,
1 => CellType::StoragePhase2,
Expand All @@ -299,7 +299,7 @@ impl CellType {

/// Return the storage cell of the expression
pub(crate) fn storage_for_expr<F: FieldExt>(expr: &Expression<F>) -> CellType {
Self::storage_for_phase::<F>(Self::expr_phase::<F>(expr))
Self::storage_for_phase(Self::expr_phase::<F>(expr))
}
}

Expand Down
7 changes: 2 additions & 5 deletions zkevm-circuits/src/evm_circuit/util/common_gadget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@ impl<F: Field> SameContextGadget<F> {
self.opcode
.assign(region, offset, Value::known(F::from(opcode.as_u64())))?;

self.sufficient_gas_left.assign(
region,
offset,
F::from((step.gas_left - step.gas_cost) as u64),
)?;
self.sufficient_gas_left
.assign(region, offset, F::from(step.gas_left - step.gas_cost))?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/util/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ pub(crate) struct Instrument {
impl Instrument {
/// Collects `CellManager` stats from a compiled EVMCircuit in order to
/// extract metrics.
pub(crate) fn on_gadget_built<'a, F: FieldExt>(
pub(crate) fn on_gadget_built<F: FieldExt>(
&mut self,
execution_state: ExecutionState,
cb: &ConstraintBuilder<'a, F>,
cb: &ConstraintBuilder<'_, F>,
) {
let sizes = cb
.curr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<F: Field, const N: usize> BatchedIsZeroGadget<F, N> {
.max()
.expect("BatchedIsZeroGadget needs at least one expression");

let cell_type = CellType::storage_for_phase::<F>(max_values_phase);
let cell_type = CellType::storage_for_phase(max_values_phase);
let is_zero = cb.query_bool_with_type(cell_type);
let nonempty_witness = cb.query_cell_with_type(cell_type);

Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/evm_circuit/util/memory_gadget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl<F: Field, const N: usize, const N_BYTES_MEMORY_WORD_SIZE: usize>
.collect::<Result<Vec<_>, _>>()?;

// Calculate the next memory size
let mut next_memory_word_size = curr_memory_word_size as u64;
let mut next_memory_word_size = curr_memory_word_size;
for (max_memory_word_sizes, memory_word_size) in self
.max_memory_word_sizes
.iter()
Expand All @@ -304,7 +304,7 @@ impl<F: Field, const N: usize, const N_BYTES_MEMORY_WORD_SIZE: usize>
let (_, max) = max_memory_word_sizes.assign(
region,
offset,
F::from(next_memory_word_size as u64),
F::from(next_memory_word_size),
F::from(*memory_word_size),
)?;
next_memory_word_size = max.get_lower_128() as u64;
Expand All @@ -324,7 +324,7 @@ impl<F: Field, const N: usize, const N_BYTES_MEMORY_WORD_SIZE: usize>

// Calculate the gas cost for the expansian
let memory_cost = GasCost::MEMORY_EXPANSION_LINEAR_COEFF.as_u64()
* (next_memory_word_size - curr_memory_word_size as u64)
* (next_memory_word_size - curr_memory_word_size)
+ (next_quad_memory_cost - curr_quad_memory_cost) as u64;

// Return the new memory size and the memory expansion gas cost
Expand Down
12 changes: 2 additions & 10 deletions zkevm-circuits/src/keccak_circuit/cell_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ impl<F: FieldExt> Cell<F> {
}

pub(crate) fn assign(&self, region: &mut KeccakRegion<F>, offset: i32, value: F) {
region.assign(
self.column_idx,
((offset as i32) + self.rotation) as usize,
value,
);
region.assign(self.column_idx, (offset + self.rotation) as usize, value);
}

pub(crate) fn assign_value(&self, region: &mut KeccakRegion<F>, offset: i32, value: Value<F>) {
Expand All @@ -73,11 +69,7 @@ impl<F: FieldExt> Cell<F> {
// this shouldn't be needed.
let value_f = extract_field(value);

region.assign(
self.column_idx,
((offset as i32) + self.rotation) as usize,
value_f,
);
region.assign(self.column_idx, (offset + self.rotation) as usize, value_f);
}
}

Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/pi_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ impl<F: Field> SubCircuit<F> for PiCircuit<F> {
&mut region,
offset,
i + 1,
tx_id_next as usize,
tx_id_next,
index,
F::from(*byte as u64),
is_final,
Expand Down
4 changes: 1 addition & 3 deletions zkevm-circuits/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ impl<const NACC: usize, const NTX: usize> CircuitTestBuilder<NACC, NTX> {
.iter()
.filter(|rw| !matches!(rw, Rw::Start { .. }))
.count();
let rows = (params.max_rws - non_start_rows_len..params.max_rws)
.into_iter()
.collect();
let rows = (params.max_rws - non_start_rows_len..params.max_rws).collect();

self.state_checks.as_ref()(prover, &rows, &rows);
}
Expand Down
Loading

0 comments on commit 757d1ee

Please sign in to comment.