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

Commit

Permalink
Upgrade the toolchain to nightly (#181)
Browse files Browse the repository at this point in the history
* use nightly

* cargo fmt

* clippy happy

* rename to remove stable

* lint more

* handle unused fields in keccak

* fix doc

* specify exact nightly version
  • Loading branch information
ChihChengLiang authored Nov 18, 2021
1 parent ef6a070 commit 3bc897d
Show file tree
Hide file tree
Showing 47 changed files with 401 additions and 294 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

name: Stable lints
name: Lints

# We only run these lints on trial-merges of PRs to reduce noise.
on:
Expand Down
56 changes: 31 additions & 25 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This module contains the CircuitInputBuilder, which is an object that takes types from geth /
//! web3 and outputs the circuit inputs.
//! This module contains the CircuitInputBuilder, which is an object that takes
//! types from geth / web3 and outputs the circuit inputs.
use crate::eth_types::{self, Address, GethExecStep, GethExecTrace};
use crate::evm::GlobalCounter;
use crate::evm::OpcodeId;
Expand Down Expand Up @@ -88,7 +88,8 @@ impl Block {
}

#[derive(Debug)]
/// Context of a Call during a [`Transaction`] which can mutate in an [`ExecStep`].
/// Context of a Call during a [`Transaction`] which can mutate in an
/// [`ExecStep`].
pub struct CallContext {
address: Address,
}
Expand Down Expand Up @@ -133,7 +134,8 @@ impl Transaction {
}
}

/// Reference to the internal state of the CircuitInputBuilder in a particular [`ExecStep`].
/// Reference to the internal state of the CircuitInputBuilder in a particular
/// [`ExecStep`].
pub struct CircuitInputStateRef<'a> {
/// Block
pub block: &'a mut Block,
Expand All @@ -148,10 +150,10 @@ pub struct CircuitInputStateRef<'a> {
}

impl<'a> CircuitInputStateRef<'a> {
/// Push an [`Operation`] into the [`OperationContainer`] with the next [`GlobalCounter`] and
/// then adds a reference to the stored operation ([`OperationRef`]) inside the bus-mapping
/// instance of the current [`ExecStep`]. Then increase the block_ctx [`GlobalCounter`] by
/// one.
/// Push an [`Operation`] into the [`OperationContainer`] with the next
/// [`GlobalCounter`] and then adds a reference to the stored operation
/// ([`OperationRef`]) inside the bus-mapping instance of the current
/// [`ExecStep`]. Then increase the block_ctx [`GlobalCounter`] by one.
pub fn push_op<T: Op>(&mut self, op: T) {
let op_ref = self
.block
Expand All @@ -162,22 +164,24 @@ impl<'a> CircuitInputStateRef<'a> {
}

#[derive(Debug)]
/// Builder to generate a complete circuit input from data gathered from a geth instance.
/// This structure is the centre of the crate and is intended to be the only
/// entry point to it. The `CircuitInputBuilder` works in several steps:
/// Builder to generate a complete circuit input from data gathered from a geth
/// instance. This structure is the centre of the crate and is intended to be
/// the only entry point to it. The `CircuitInputBuilder` works in several
/// steps:
///
/// 1. Take a [`eth_types::Block`] to build the circuit input associated with the block.
/// 2. For each [`eth_types::Transaction`] in the block, take the [`eth_types::GethExecTrace`] to
/// build the circuit input associated with each transaction, and the bus-mapping operations
/// associated with each `eth_types::GethExecStep`] in the [`eth_types::GethExecTrace`].
/// 1. Take a [`eth_types::Block`] to build the circuit input associated with
/// the block. 2. For each [`eth_types::Transaction`] in the block, take the
/// [`eth_types::GethExecTrace`] to build the circuit input associated with
/// each transaction, and the bus-mapping operations associated with each
/// `eth_types::GethExecStep`] in the [`eth_types::GethExecTrace`].
///
/// The generated bus-mapping operations are:
/// [`StackOp`](crate::operation::StackOp)s,
/// [`MemoryOp`](crate::operation::MemoryOp)s and
/// [`StorageOp`](crate::operation::StorageOp), which correspond to each
/// [`OpcodeId`](crate::evm::OpcodeId)s used in each `ExecTrace` step so that the State Proof
/// witnesses are already generated on a structured manner and ready to be added into the State
/// circuit.
/// [`OpcodeId`](crate::evm::OpcodeId)s used in each `ExecTrace` step so that
/// the State Proof witnesses are already generated on a structured manner and
/// ready to be added into the State circuit.
pub struct CircuitInputBuilder {
/// Block
pub block: Block,
Expand All @@ -186,7 +190,8 @@ pub struct CircuitInputBuilder {
}

impl<'a> CircuitInputBuilder {
/// Create a new CircuitInputBuilder from the given `eth_block` and `constants`.
/// Create a new CircuitInputBuilder from the given `eth_block` and
/// `constants`.
pub fn new<TX>(
eth_block: eth_types::Block<TX>,
constants: BlockConstants,
Expand All @@ -197,9 +202,9 @@ impl<'a> CircuitInputBuilder {
}
}

/// Obtain a mutable reference to the state that the `CircuitInputBuilder` maintains,
/// contextualized to a particular transaction and a particular execution step in that
/// transaction.
/// Obtain a mutable reference to the state that the `CircuitInputBuilder`
/// maintains, contextualized to a particular transaction and a
/// particular execution step in that transaction.
pub fn state_ref(
&'a mut self,
tx: &'a mut Transaction,
Expand All @@ -215,9 +220,10 @@ impl<'a> CircuitInputBuilder {
}
}

/// Handle a transaction with its corresponding execution trace to generate all the associated
/// operations. Each operation is registered in `self.block.container`, and each step stores
/// the [`OperationRef`] to each of the generated operations.
/// Handle a transaction with its corresponding execution trace to generate
/// all the associated operations. Each operation is registered in
/// `self.block.container`, and each step stores the [`OperationRef`] to
/// each of the generated operations.
pub fn handle_tx(
&mut self,
eth_tx: &eth_types::Transaction,
Expand Down
3 changes: 2 additions & 1 deletion bus-mapping/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub enum Error {
InvalidMemoryPointer,
/// Error while trying to access an invalid/empty Storage key.
InvalidStorageKey,
/// Error when an EvmWord is too big to be converted into a `MemoryAddress`.
/// Error when an EvmWord is too big to be converted into a
/// `MemoryAddress`.
WordToMemAddr,
/// Error while generating a trace.
TracingError,
Expand Down
32 changes: 18 additions & 14 deletions bus-mapping/src/eth_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ pub trait ToLittleEndian {
fn to_le_bytes(&self) -> [u8; 32];
}

// We use our own declaration of another U256 in order to implement a custom deserializer that can
// parse U256 when returned by structLogs fields in geth debug_trace* methods, which don't contain
// the `0x` prefix.
// We use our own declaration of another U256 in order to implement a custom
// deserializer that can parse U256 when returned by structLogs fields in geth
// debug_trace* methods, which don't contain the `0x` prefix.
#[allow(clippy::all)]
mod uint_types {
uint::construct_uint! {
Expand Down Expand Up @@ -153,8 +153,8 @@ struct GethExecStepInternal {
storage: HashMap<DebugU256, DebugU256>,
}

/// The execution step type returned by geth RPC debug_trace* methods. Corresponds to
/// `StructLogRes` in `go-ethereum/internal/ethapi/api.go`.
/// The execution step type returned by geth RPC debug_trace* methods.
/// Corresponds to `StructLogRes` in `go-ethereum/internal/ethapi/api.go`.
#[derive(Clone, Debug, Eq, PartialEq)]
#[doc(hidden)]
pub struct GethExecStep {
Expand Down Expand Up @@ -189,7 +189,7 @@ impl From<GethExecStep> for GethExecStepInternal {
.memory
.0
.chunks(32)
.map(|word| DebugU256::from_big_endian(word))
.map(DebugU256::from_big_endian)
.collect(),
storage: step
.storage
Expand All @@ -201,7 +201,8 @@ impl From<GethExecStep> for GethExecStepInternal {
}
}

// TODO: Tried `#[serde(into = "IntoType")]` feature but doesn't seem to work. Double check.
// TODO: Tried `#[serde(into = "IntoType")]` feature but doesn't seem to work.
// Double check.
impl Serialize for GethExecStep {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down Expand Up @@ -244,22 +245,24 @@ impl<'de> Deserialize<'de> for GethExecStep {
}
}

/// Helper type built to deal with the weird `result` field added between `GethExecutionTrace`s in
/// `debug_traceBlockByHash` and `debug_traceBlockByNumber` Geth JSON-RPC calls.
/// Helper type built to deal with the weird `result` field added between
/// `GethExecutionTrace`s in `debug_traceBlockByHash` and
/// `debug_traceBlockByNumber` Geth JSON-RPC calls.
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
#[doc(hidden)]
pub(crate) struct ResultGethExecTraces(pub(crate) Vec<ResultGethExecTrace>);

/// Helper type built to deal with the weird `result` field added between `GethExecutionTrace`s in
/// `debug_traceBlockByHash` and `debug_traceBlockByNumber` Geth JSON-RPC calls.
/// Helper type built to deal with the weird `result` field added between
/// `GethExecutionTrace`s in `debug_traceBlockByHash` and
/// `debug_traceBlockByNumber` Geth JSON-RPC calls.
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
#[doc(hidden)]
pub(crate) struct ResultGethExecTrace {
pub(crate) result: GethExecTrace,
}

/// The execution trace type returned by geth RPC debug_trace* methods. Corresponds to
/// `ExecutionResult` in `go-ethereum/internal/ethapi/api.go`.
/// The execution trace type returned by geth RPC debug_trace* methods.
/// Corresponds to `ExecutionResult` in `go-ethereum/internal/ethapi/api.go`.
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
#[doc(hidden)]
pub struct GethExecTrace {
Expand Down Expand Up @@ -290,7 +293,8 @@ macro_rules! word {
}

#[macro_export]
/// Create a [`Word`] to [`Word`] HashMap from pairs of hex strings. Panics on invalid input.
/// Create a [`Word`] to [`Word`] HashMap from pairs of hex strings. Panics on
/// invalid input.
macro_rules! word_map {
() => {
std::collections::HashMap::new()
Expand Down
3 changes: 2 additions & 1 deletion bus-mapping/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ impl GlobalCounter {
}
}

/// Defines the gas left to perate in a [`ExecStep`](crate::circuit_input_builder::ExecStep).
/// Defines the gas left to perate in a
/// [`ExecStep`](crate::circuit_input_builder::ExecStep).
#[derive(
Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize,
)]
Expand Down
16 changes: 10 additions & 6 deletions bus-mapping/src/evm/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,16 @@ impl From<Vec<Word>> for Memory {
impl Index<MemoryAddress> for Memory {
type Output = u8;
fn index(&self, index: MemoryAddress) -> &Self::Output {
// MemoryAddress is in base 16. Therefore since the vec is not, we need to shift the addr.
// MemoryAddress is in base 16. Therefore since the vec is not, we need
// to shift the addr.
&self.0[index.0 >> 5]
}
}

impl IndexMut<MemoryAddress> for Memory {
fn index_mut(&mut self, index: MemoryAddress) -> &mut Self::Output {
// MemoryAddress is in base 16. Therefore since the vec is not, we need to shift the addr.
// MemoryAddress is in base 16. Therefore since the vec is not, we need
// to shift the addr.
&mut self.0[index.0 >> 5]
}
}
Expand Down Expand Up @@ -219,10 +221,11 @@ impl Memory {
self.0.len().into()
}

/// Reads an entire [`Word`] which starts at the provided [`MemoryAddress`] `addr` and
/// finnishes at `addr + 32`.
/// Reads an entire [`Word`] which starts at the provided [`MemoryAddress`]
/// `addr` and finnishes at `addr + 32`.
pub fn read_word(&self, addr: MemoryAddress) -> Result<Word, Error> {
// Ensure that the memory is big enough to have values in the range `[addr, addr+32)`.
// Ensure that the memory is big enough to have values in the range
// `[addr, addr+32)`.
if self.0.len() < addr.0 + 32 {
return Err(Error::InvalidMemoryPointer);
}
Expand Down Expand Up @@ -287,7 +290,8 @@ mod memory_tests {
.collect(),
);

// At this point at position [0x40, 0x80) we've allocated the `0x80` value.
// At this point at position [0x40, 0x80) we've allocated the `0x80`
// value.

// If we read a word at addr `0x40` we should get `0x80`.
assert_eq!(
Expand Down
3 changes: 2 additions & 1 deletion bus-mapping/src/evm/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ impl OpcodeId {
}
}

/// Generate the associated operations according to the particular [`OpcodeId`].
/// Generate the associated operations according to the particular
/// [`OpcodeId`].
pub fn gen_associated_ops(
&self,
state: &mut CircuitInputStateRef,
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/evm/opcodes/dup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
Error,
};

/// Placeholder structure used to implement [`Opcode`] trait over it corresponding to the
/// `OpcodeId::DUP*` `OpcodeId`.
/// Placeholder structure used to implement [`Opcode`] trait over it
/// corresponding to the `OpcodeId::DUP*` `OpcodeId`.
#[derive(Debug, Copy, Clone)]
pub(crate) struct Dup<const N: usize>;

Expand Down
5 changes: 3 additions & 2 deletions bus-mapping/src/evm/opcodes/jumpdest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use crate::circuit_input_builder::CircuitInputStateRef;
use crate::eth_types::GethExecStep;
use crate::Error;

/// Placeholder structure used to implement [`Opcode`] trait over it corresponding to the
/// [`OpcodeId::JUMPDEST`](crate::evm::OpcodeId::JUMPDEST) `OpcodeId`.
/// Placeholder structure used to implement [`Opcode`] trait over it
/// corresponding to the [`OpcodeId::JUMPDEST`](crate::evm::OpcodeId::JUMPDEST)
/// `OpcodeId`.
#[derive(Debug, Copy, Clone)]
pub(crate) struct Jumpdest;

Expand Down
12 changes: 7 additions & 5 deletions bus-mapping/src/evm/opcodes/mload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ use crate::{
};
use core::convert::TryInto;

/// Placeholder structure used to implement [`Opcode`] trait over it corresponding to the
/// [`OpcodeId::MLOAD`](crate::evm::OpcodeId::MLOAD) `OpcodeId`.
/// This is responsible of generating all of the associated [`StackOp`]s and [`MemoryOp`]s and place them
/// inside the trace's [`OperationContainer`](crate::operation::OperationContainer).
/// Placeholder structure used to implement [`Opcode`] trait over it
/// corresponding to the [`OpcodeId::MLOAD`](crate::evm::OpcodeId::MLOAD)
/// `OpcodeId`. This is responsible of generating all of the associated
/// [`StackOp`]s and [`MemoryOp`]s and place them inside the trace's
/// [`OperationContainer`](crate::operation::OperationContainer).
#[derive(Debug, Copy, Clone)]
pub(crate) struct Mload;

Expand Down Expand Up @@ -118,7 +119,8 @@ mod mload_tests {
Word::from(0x80),
));

// Add the 32 MemoryOp generated from the Memory read at addr 0x40<->0x80 for each byte.
// Add the 32 MemoryOp generated from the Memory read at addr
// 0x40<->0x80 for each byte.
Word::from(0x80)
.to_be_bytes()
.iter()
Expand Down
11 changes: 7 additions & 4 deletions bus-mapping/src/evm/opcodes/mstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use crate::{
};
use core::convert::TryInto;

/// Placeholder structure used to implement [`Opcode`] trait over it corresponding to the
/// [`OpcodeId::MSTORE`](crate::evm::OpcodeId::MSTORE) `OpcodeId`.
/// Placeholder structure used to implement [`Opcode`] trait over it
/// corresponding to the [`OpcodeId::MSTORE`](crate::evm::OpcodeId::MSTORE)
/// `OpcodeId`.
#[derive(Debug, Copy, Clone)]
pub(crate) struct Mstore;

Expand Down Expand Up @@ -94,7 +95,8 @@ mod mstore_tests {
let mut state_ref =
test_builder.state_ref(&mut tx, &mut tx_ctx, &mut step);

// Add StackOps associated to the 0x100, 0x1234 reads starting from last stack position.
// Add StackOps associated to the 0x100, 0x1234 reads starting from last
// stack position.
state_ref.push_op(StackOp::new(
RW::READ,
StackAddress::from(1022),
Expand All @@ -106,7 +108,8 @@ mod mstore_tests {
Word::from(0x1234),
));

// Add the 32 MemoryOp generated from the Memory write at addr 0x100..0x120 for each byte.
// Add the 32 MemoryOp generated from the Memory write at addr
// 0x100..0x120 for each byte.
for (i, byte) in Word::from(0x1234).to_be_bytes().iter().enumerate() {
state_ref.push_op(MemoryOp::new(
RW::WRITE,
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/evm/opcodes/pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
Error,
};

/// Placeholder structure used to implement [`Opcode`] trait over it corresponding to the
/// [`OpcodeId::PC`](crate::evm::OpcodeId::PC) `OpcodeId`.
/// Placeholder structure used to implement [`Opcode`] trait over it
/// corresponding to the [`OpcodeId::PC`](crate::evm::OpcodeId::PC) `OpcodeId`.
#[derive(Debug, Copy, Clone)]
pub(crate) struct Pc;

Expand Down
12 changes: 7 additions & 5 deletions bus-mapping/src/evm/opcodes/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use crate::{
Error,
};

/// Placeholder structure used to implement [`Opcode`] trait over it corresponding to the
/// `OpcodeId::PUSH*` `OpcodeId`.
/// This is responsible of generating all of the associated [`StackOp`]s and place them
/// inside the trace's [`OperationContainer`](crate::operation::OperationContainer).
/// Placeholder structure used to implement [`Opcode`] trait over it
/// corresponding to the `OpcodeId::PUSH*` `OpcodeId`.
/// This is responsible of generating all of the associated [`StackOp`]s and
/// place them inside the trace's
/// [`OperationContainer`](crate::operation::OperationContainer).
#[derive(Debug, Copy, Clone)]
pub(crate) struct Push<const N: usize>;

Expand All @@ -21,7 +22,8 @@ impl<const N: usize> Opcode for Push<N> {
let step = &steps[0];
state.push_op(StackOp::new(
RW::WRITE,
// Get the value and addr from the next step. Being the last position filled with an element in the stack
// Get the value and addr from the next step. Being the last
// position filled with an element in the stack
step.stack.last_filled().map(|a| a - 1),
steps[1].stack.last()?,
));
Expand Down
Loading

0 comments on commit 3bc897d

Please sign in to comment.