From 16adf432ed65f55113d0202b2a81fbe95e443b38 Mon Sep 17 00:00:00 2001 From: Delweng Date: Mon, 9 Sep 2024 18:08:12 +0800 Subject: [PATCH] chore: make clippy happy (#1755) * chore(revm): elided lifetime has a name Signed-off-by: jsvisa * clipy: map to inspect Signed-off-by: jsvisa * fix all clippy warnings Signed-off-by: jsvisa * typo Signed-off-by: jsvisa --------- Signed-off-by: jsvisa --- crates/interpreter/src/function_stack.rs | 7 +++---- .../interpreter/src/instructions/arithmetic.rs | 2 ++ crates/precompile/src/hash.rs | 18 ++++++++++++------ crates/revm/src/context/context_precompiles.rs | 2 +- crates/revm/src/db/states/account_status.rs | 13 +++++++++++++ crates/revm/src/evm.rs | 12 ++++-------- 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/crates/interpreter/src/function_stack.rs b/crates/interpreter/src/function_stack.rs index 4c33aa911c..400283ccdb 100644 --- a/crates/interpreter/src/function_stack.rs +++ b/crates/interpreter/src/function_stack.rs @@ -51,10 +51,9 @@ impl FunctionStack { /// Pops a frame from the stack and sets current_code_idx to the popped frame's idx. pub fn pop(&mut self) -> Option { - self.return_stack.pop().map(|frame| { - self.current_code_idx = frame.idx; - frame - }) + self.return_stack + .pop() + .inspect(|frame| self.current_code_idx = frame.idx) } /// Sets current_code_idx, this is needed for JUMPF opcode. diff --git a/crates/interpreter/src/instructions/arithmetic.rs b/crates/interpreter/src/instructions/arithmetic.rs index 9b34aa14f9..da11b79b9c 100644 --- a/crates/interpreter/src/instructions/arithmetic.rs +++ b/crates/interpreter/src/instructions/arithmetic.rs @@ -69,6 +69,8 @@ pub fn exp(interpreter: &mut Interpreter, _host: & *op2 = op1.pow(*op2); } +/// Implements the `SIGNEXTEND` opcode as defined in the Ethereum Yellow Paper. +/// /// In the yellow paper `SIGNEXTEND` is defined to take two inputs, we will call them /// `x` and `y`, and produce one output. The first `t` bits of the output (numbering from the /// left, starting from 0) are equal to the `t`-th bit of `y`, where `t` is equal to diff --git a/crates/precompile/src/hash.rs b/crates/precompile/src/hash.rs index 9457302b1a..1ea5e73dfc 100644 --- a/crates/precompile/src/hash.rs +++ b/crates/precompile/src/hash.rs @@ -11,9 +11,12 @@ pub const RIPEMD160: PrecompileWithAddress = PrecompileWithAddress( Precompile::Standard(ripemd160_run), ); -/// See: -/// See: -/// See: +/// Computes the SHA-256 hash of the input data. +/// +/// This function follows specifications defined in the following references: +/// - [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf) +/// - [Solidity Documentation on Mathematical and Cryptographic Functions](https://docs.soliditylang.org/en/develop/units-and-global-variables.html#mathematical-and-cryptographic-functions) +/// - [Address 0x02](https://etherscan.io/address/0000000000000000000000000000000000000002) pub fn sha256_run(input: &Bytes, gas_limit: u64) -> PrecompileResult { let cost = calc_linear_cost_u32(input.len(), 60, 12); if cost > gas_limit { @@ -24,9 +27,12 @@ pub fn sha256_run(input: &Bytes, gas_limit: u64) -> PrecompileResult { } } -/// See: -/// See: -/// See: +/// Computes the RIPEMD-160 hash of the input data. +/// +/// This function follows specifications defined in the following references: +/// - [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf) +/// - [Solidity Documentation on Mathematical and Cryptographic Functions](https://docs.soliditylang.org/en/develop/units-and-global-variables.html#mathematical-and-cryptographic-functions) +/// - [Address 03](https://etherscan.io/address/0000000000000000000000000000000000000003) pub fn ripemd160_run(input: &Bytes, gas_limit: u64) -> PrecompileResult { let gas_used = calc_linear_cost_u32(input.len(), 600, 120); if gas_used > gas_limit { diff --git a/crates/revm/src/context/context_precompiles.rs b/crates/revm/src/context/context_precompiles.rs index f674093535..f3fa881a14 100644 --- a/crates/revm/src/context/context_precompiles.rs +++ b/crates/revm/src/context/context_precompiles.rs @@ -95,7 +95,7 @@ impl ContextPrecompiles { /// Returns precompiles addresses. #[inline] - pub fn addresses<'a>(&'a self) -> Box + 'a> { + pub fn addresses<'a>(&'a self) -> Box + 'a> { match self.inner { PrecompilesCow::StaticRef(inner) => Box::new(inner.addresses()), PrecompilesCow::Owned(ref inner) => Box::new(inner.keys()), diff --git a/crates/revm/src/db/states/account_status.rs b/crates/revm/src/db/states/account_status.rs index 5902ed9819..6f0d8e7f78 100644 --- a/crates/revm/src/db/states/account_status.rs +++ b/crates/revm/src/db/states/account_status.rs @@ -1,6 +1,19 @@ +/// AccountStatus represents the various states an account can be in after being loaded from the database. +/// /// After account get loaded from database it can be in a lot of different states /// while we execute multiple transaction and even blocks over account that is in memory. /// This structure models all possible states that account can be in. +/// +/// # Variants +/// +/// - `LoadedNotExisting`: the account has been loaded but does not exist. +/// - `Loaded`: the account has been loaded and exists. +/// - `LoadedEmptyEIP161`: the account is loaded and empty, as per EIP-161. +/// - `InMemoryChange`: there are changes in the account that exist only in memory. +/// - `Changed`: the account has been modified. +/// - `Destroyed`: the account has been destroyed. +/// - `DestroyedChanged`: the account has been destroyed and then modified. +/// - `DestroyedAgain`: the account has been destroyed again. #[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum AccountStatus { diff --git a/crates/revm/src/evm.rs b/crates/revm/src/evm.rs index b42abcdcf1..ab34469ce4 100644 --- a/crates/revm/src/evm.rs +++ b/crates/revm/src/evm.rs @@ -199,10 +199,7 @@ impl Evm<'_, EXT, DB> { .handler .validation() .initial_tx_gas(&self.context.evm.env) - .map_err(|e| { - self.clear(); - e - })?; + .inspect_err(|_e| self.clear())?; let output = self.transact_preverified_inner(initial_gas_spend); let output = self.handler.post_execution().end(&mut self.context, output); self.clear(); @@ -228,10 +225,9 @@ impl Evm<'_, EXT, DB> { /// This function will validate the transaction. #[inline] pub fn transact(&mut self) -> EVMResult { - let initial_gas_spend = self.preverify_transaction_inner().map_err(|e| { - self.clear(); - e - })?; + let initial_gas_spend = self + .preverify_transaction_inner() + .inspect_err(|_e| self.clear())?; let output = self.transact_preverified_inner(initial_gas_spend); let output = self.handler.post_execution().end(&mut self.context, output);