Skip to content

Commit 16adf43

Browse files
authored
chore: make clippy happy (#1755)
* chore(revm): elided lifetime has a name Signed-off-by: jsvisa <delweng@gmail.com> * clipy: map to inspect Signed-off-by: jsvisa <delweng@gmail.com> * fix all clippy warnings Signed-off-by: jsvisa <delweng@gmail.com> * typo Signed-off-by: jsvisa <delweng@gmail.com> --------- Signed-off-by: jsvisa <delweng@gmail.com>
1 parent d38ff45 commit 16adf43

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

crates/interpreter/src/function_stack.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ impl FunctionStack {
5151

5252
/// Pops a frame from the stack and sets current_code_idx to the popped frame's idx.
5353
pub fn pop(&mut self) -> Option<FunctionReturnFrame> {
54-
self.return_stack.pop().map(|frame| {
55-
self.current_code_idx = frame.idx;
56-
frame
57-
})
54+
self.return_stack
55+
.pop()
56+
.inspect(|frame| self.current_code_idx = frame.idx)
5857
}
5958

6059
/// Sets current_code_idx, this is needed for JUMPF opcode.

crates/interpreter/src/instructions/arithmetic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ pub fn exp<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, _host: &
6969
*op2 = op1.pow(*op2);
7070
}
7171

72+
/// Implements the `SIGNEXTEND` opcode as defined in the Ethereum Yellow Paper.
73+
///
7274
/// In the yellow paper `SIGNEXTEND` is defined to take two inputs, we will call them
7375
/// `x` and `y`, and produce one output. The first `t` bits of the output (numbering from the
7476
/// left, starting from 0) are equal to the `t`-th bit of `y`, where `t` is equal to

crates/precompile/src/hash.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ pub const RIPEMD160: PrecompileWithAddress = PrecompileWithAddress(
1111
Precompile::Standard(ripemd160_run),
1212
);
1313

14-
/// See: <https://ethereum.github.io/yellowpaper/paper.pdf>
15-
/// See: <https://docs.soliditylang.org/en/develop/units-and-global-variables.html#mathematical-and-cryptographic-functions>
16-
/// See: <https://etherscan.io/address/0000000000000000000000000000000000000002>
14+
/// Computes the SHA-256 hash of the input data.
15+
///
16+
/// This function follows specifications defined in the following references:
17+
/// - [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf)
18+
/// - [Solidity Documentation on Mathematical and Cryptographic Functions](https://docs.soliditylang.org/en/develop/units-and-global-variables.html#mathematical-and-cryptographic-functions)
19+
/// - [Address 0x02](https://etherscan.io/address/0000000000000000000000000000000000000002)
1720
pub fn sha256_run(input: &Bytes, gas_limit: u64) -> PrecompileResult {
1821
let cost = calc_linear_cost_u32(input.len(), 60, 12);
1922
if cost > gas_limit {
@@ -24,9 +27,12 @@ pub fn sha256_run(input: &Bytes, gas_limit: u64) -> PrecompileResult {
2427
}
2528
}
2629

27-
/// See: <https://ethereum.github.io/yellowpaper/paper.pdf>
28-
/// See: <https://docs.soliditylang.org/en/develop/units-and-global-variables.html#mathematical-and-cryptographic-functions>
29-
/// See: <https://etherscan.io/address/0000000000000000000000000000000000000003>
30+
/// Computes the RIPEMD-160 hash of the input data.
31+
///
32+
/// This function follows specifications defined in the following references:
33+
/// - [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf)
34+
/// - [Solidity Documentation on Mathematical and Cryptographic Functions](https://docs.soliditylang.org/en/develop/units-and-global-variables.html#mathematical-and-cryptographic-functions)
35+
/// - [Address 03](https://etherscan.io/address/0000000000000000000000000000000000000003)
3036
pub fn ripemd160_run(input: &Bytes, gas_limit: u64) -> PrecompileResult {
3137
let gas_used = calc_linear_cost_u32(input.len(), 600, 120);
3238
if gas_used > gas_limit {

crates/revm/src/context/context_precompiles.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<DB: Database> ContextPrecompiles<DB> {
9595

9696
/// Returns precompiles addresses.
9797
#[inline]
98-
pub fn addresses<'a>(&'a self) -> Box<dyn ExactSizeIterator<Item = &Address> + 'a> {
98+
pub fn addresses<'a>(&'a self) -> Box<dyn ExactSizeIterator<Item = &'a Address> + 'a> {
9999
match self.inner {
100100
PrecompilesCow::StaticRef(inner) => Box::new(inner.addresses()),
101101
PrecompilesCow::Owned(ref inner) => Box::new(inner.keys()),

crates/revm/src/db/states/account_status.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
/// AccountStatus represents the various states an account can be in after being loaded from the database.
2+
///
13
/// After account get loaded from database it can be in a lot of different states
24
/// while we execute multiple transaction and even blocks over account that is in memory.
35
/// This structure models all possible states that account can be in.
6+
///
7+
/// # Variants
8+
///
9+
/// - `LoadedNotExisting`: the account has been loaded but does not exist.
10+
/// - `Loaded`: the account has been loaded and exists.
11+
/// - `LoadedEmptyEIP161`: the account is loaded and empty, as per EIP-161.
12+
/// - `InMemoryChange`: there are changes in the account that exist only in memory.
13+
/// - `Changed`: the account has been modified.
14+
/// - `Destroyed`: the account has been destroyed.
15+
/// - `DestroyedChanged`: the account has been destroyed and then modified.
16+
/// - `DestroyedAgain`: the account has been destroyed again.
417
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Hash)]
518
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
619
pub enum AccountStatus {

crates/revm/src/evm.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,7 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {
199199
.handler
200200
.validation()
201201
.initial_tx_gas(&self.context.evm.env)
202-
.map_err(|e| {
203-
self.clear();
204-
e
205-
})?;
202+
.inspect_err(|_e| self.clear())?;
206203
let output = self.transact_preverified_inner(initial_gas_spend);
207204
let output = self.handler.post_execution().end(&mut self.context, output);
208205
self.clear();
@@ -228,10 +225,9 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {
228225
/// This function will validate the transaction.
229226
#[inline]
230227
pub fn transact(&mut self) -> EVMResult<DB::Error> {
231-
let initial_gas_spend = self.preverify_transaction_inner().map_err(|e| {
232-
self.clear();
233-
e
234-
})?;
228+
let initial_gas_spend = self
229+
.preverify_transaction_inner()
230+
.inspect_err(|_e| self.clear())?;
235231

236232
let output = self.transact_preverified_inner(initial_gas_spend);
237233
let output = self.handler.post_execution().end(&mut self.context, output);

0 commit comments

Comments
 (0)