Skip to content
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
2 changes: 1 addition & 1 deletion crates/interpreter/src/host/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Host for DummyHost {
fn tload(&mut self, _address: B160, index: U256) -> U256 {
self.transient_storage
.get(&index)
.cloned()
.copied()
.unwrap_or_default()
}

Expand Down
8 changes: 4 additions & 4 deletions crates/primitives/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use hashbrown::HashMap;
#[derive(Debug, Clone, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Account {
/// Balance of the account.
/// Balance, nonce, and code.
pub info: AccountInfo,
/// storage cache
/// Storage cache
pub storage: HashMap<U256, StorageSlot>,
// Account status flags.
/// Account status flags.
pub status: AccountStatus,
}

Expand Down Expand Up @@ -173,7 +173,7 @@ pub struct AccountInfo {
/// code hash,
pub code_hash: B256,
/// code: if None, `code_by_hash` will be used to fetch it if code needs to be loaded from
/// inside of revm.
/// inside of `revm`.
pub code: Option<Bytecode>,
}

Expand Down
7 changes: 3 additions & 4 deletions crates/revm/src/db/states/account_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ pub enum AccountStatus {
}

impl AccountStatus {
/// Transition to other state while preserving
/// invariance of this state.
/// Transition to other state while preserving invariance of this state.
///
/// It this account was Destroyed and other account is not:
/// we should mark extended account as destroyed too.
Expand All @@ -26,7 +25,7 @@ impl AccountStatus {
/// If both account are not destroyed and if this account is in memory:
/// this means that extended account is in memory too.
///
/// otherwise if both are destroyed or other is destroyed:
/// Otherwise, if both are destroyed or other is destroyed:
/// set other status to extended account.
pub fn transition(&mut self, other: Self) {
*self = match (self.was_destroyed(), other.was_destroyed()) {
Expand Down Expand Up @@ -69,7 +68,7 @@ impl AccountStatus {
}

/// Account is modified but not destroyed.
/// This means that some of storage values can be found in both
/// This means that some storage values can be found in both
/// memory and database.
pub fn modified_but_not_destroyed(&self) -> bool {
matches!(self, AccountStatus::Changed | AccountStatus::InMemoryChange)
Expand Down
4 changes: 2 additions & 2 deletions crates/revm/src/db/states/bundle_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ impl BundleAccount {
1 + self.storage.len()
}

/// Return storage slot if it exist.
/// Return storage slot if it exists.
///
/// In case we know that account is destroyed return `Some(U256::ZERO)`
/// In case we know that account is newly created or destroyed, return `Some(U256::ZERO)`
pub fn storage_slot(&self, slot: U256) -> Option<U256> {
let slot = self.storage.get(&slot).map(|s| s.present_value);
if slot.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/db/states/bundle_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ mod tests {
}

#[test]
fn extend_on_destoyed_values() {
fn extend_on_destroyed_values() {
let base_bundle1 = test_bundle1();
let base_bundle2 = test_bundle2();

Expand Down
8 changes: 4 additions & 4 deletions crates/revm/src/db/states/cache_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ impl CacheAccount {
})
}

/// Touche empty account, related to EIP-161 state clear.
/// Touch empty account, related to EIP-161 state clear.
///
/// This account returns Transition that is used to create the BundleState.
/// This account returns the Transition that is used to create the BundleState.
pub fn touch_empty_eip161(&mut self) -> Option<TransitionAccount> {
let previous_status = self.status;

Expand All @@ -169,7 +169,7 @@ impl CacheAccount {
AccountStatus::InMemoryChange
| AccountStatus::Destroyed
| AccountStatus::LoadedEmptyEIP161 => {
// account can be created empty them touched.
// account can be created empty then touched.
AccountStatus::Destroyed
}
AccountStatus::LoadedNotExisting => {
Expand Down Expand Up @@ -344,7 +344,7 @@ impl CacheAccount {
)
}

/// Drain balance from account and return transition and drained amount
/// Drain balance from account and return drained amount and transition.
///
/// Used for DAO hardfork transition.
pub fn drain_balance(&mut self) -> (u128, TransitionAccount) {
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/db/states/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl<DB: Database> Database for State<DB> {
}

fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
// block number is never biger then u64::MAX.
// block number is never bigger then u64::MAX.
let u64num: u64 = number.to();
match self.block_hashes.entry(u64num) {
btree_map::Entry::Occupied(entry) => Ok(*entry.get()),
Expand Down
6 changes: 3 additions & 3 deletions crates/revm/src/db/states/transition_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::db::AccountStatus;
use revm_interpreter::primitives::{hash_map, AccountInfo, Bytecode, B256};

/// Account Created when EVM state is merged to cache state.
/// And it is send to Block state.
/// And it is sent to Block state.
///
/// It is used when block state gets merged to bundle state to
/// create needed Reverts.
Expand Down Expand Up @@ -53,8 +53,8 @@ impl TransitionAccount {
None
}

/// Update new values of transition. Don't override old values
/// both account info and old storages need to be left intact.
/// Update new values of transition. Don't override old values.
/// Both account info and old storages need to be left intact.
pub fn update(&mut self, other: Self) {
self.info = other.info.clone();
self.status = other.status;
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/inspector/customprinter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ mod test {
balance: "0x100c5d668240db8e00".parse().unwrap(),
code_hash: crate::primitives::keccak256(&code),
code: Some(crate::primitives::Bytecode::new_raw(code.clone())),
nonce: "1".parse().unwrap(),
nonce: 1,
};
let callee = hex_literal::hex!("5fdcca53617f4d2b9134b29090c87d01058e27e9");
database.insert_account_info(crate::primitives::B160(callee), acc_info);
Expand Down
6 changes: 3 additions & 3 deletions crates/revm/src/journaled_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl JournaledState {
had_balance,
} => {
let account = state.get_mut(&address).unwrap();
// set previous ste of selfdestructed flag. as there could be multiple
// set previous state of selfdestructed flag, as there could be multiple
// selfdestructs in one transaction.
if was_destroyed {
// flag is still selfdestructed
Expand All @@ -373,7 +373,7 @@ impl JournaledState {
}
}
JournalEntry::BalanceTransfer { from, to, balance } => {
// we don't need to check overflow and underflow when adding sub subtracting the balance.
// we don't need to check overflow and underflow when adding and subtracting the balance.
let from = state.get_mut(&from).unwrap();
from.info.balance += balance;
let to = state.get_mut(&to).unwrap();
Expand Down Expand Up @@ -717,7 +717,7 @@ impl JournaledState {
pub fn tload(&mut self, address: B160, key: U256) -> U256 {
self.transient_storage
.get(&(address, key))
.cloned()
.copied()
.unwrap_or_default()
}

Expand Down
1 change: 0 additions & 1 deletion documentation/src/crates/interpreter.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Modules:
- [instruction_result](./interpreter/instruction_result.md): This module contains definitions related to the result of instruction execution.
- [instructions](./interpreter/instructions.md): This module includes the definitions of the EVM opcodes (instructions).


External Crates:

- [alloc](https://doc.rust-lang.org/alloc/): The alloc crate is used to provide the ability to allocate memory on the heap. It's a part of Rust's standard library that can be used in environments without a full host OS.
Expand Down
2 changes: 1 addition & 1 deletion documentation/src/crates/primitives/environment.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Environment

A significant module that manages the execution environment of the EVM. The module containts objects and methods associated with processing transactions and blocks within such a blockchain environment. It defines several structures: `Env`, `BlockEnv`, `TxEnv`, `CfgEnv`, `TransactTo`, and `CreateScheme`. These structures contain various fields representing the block data, transaction data, environmental configurations, transaction recipient details, and the method of contract creation respectively.
A significant module that manages the execution environment of the EVM. The module contains objects and methods associated with processing transactions and blocks within such a blockchain environment. It defines several structures: `Env`, `BlockEnv`, `TxEnv`, `CfgEnv`, `TransactTo`, and `CreateScheme`. These structures contain various fields representing the block data, transaction data, environmental configurations, transaction recipient details, and the method of contract creation respectively.

The `Env` structure, which encapsulates the environment of the EVM, contains methods for calculating effective gas prices and for validating block and transaction data. It also checks transactions against the current state of the associated account, which is necessary to validate the transaction's nonce and the account balance. Various Ethereum Improvement Proposals (EIPs) are also considered in these validations, such as [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) for the base fee, [EIP-3607](https://eips.ethereum.org/EIPS/eip-3607) for rejecting transactions from senders with deployed code, and [EIP-3298](https://eips.ethereum.org/EIPS/eip-3298) for disabling gas refunds. The code is structured to include optional features and to allow for changes in the EVM specifications.
6 changes: 3 additions & 3 deletions documentation/src/crates/revm/host_trait.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ The [`EVMImpl`](./evm_impl.md) struct implements this `Host` trait.

This method retrieves the balance of an Ethereum account given its address. It returns a tuple containing the balance and a boolean indicating whether the account was "cold" (accessed for the first time in the current transaction).

- `code`
- `code`

This method retrieves the bytecode of a given address. It returns a tuple containing the bytecode and a boolean indicating whether the account was "cold".

- `code_hash`
- `code_hash`

This method retrieves the code_hash at a given address. It returns a tuple containing the hash and a boolean indicating whether the account was "cold".

Expand All @@ -44,7 +44,7 @@ The [`EVMImpl`](./evm_impl.md) struct implements this `Host` trait.

This method is used to create log entries, which are a way for contracts to produce output that external observers (like dapps or the frontend of a blockchain explorer) can listen for and react to.

- `selfdestruct`
- `selfdestruct`

The selfdestruct method attempts to terminate the specified address, transferring its remaining balance to a given target address. If the INSPECT constant is true, the self-destruction event is observed or logged via an inspector. The method returns an Option<SelfDestructResult>, encapsulating the outcome of the operation: Some(SelfDestructResult) on success and None if an error occurs, with the error being stored internally for later reference.

Expand Down
4 changes: 2 additions & 2 deletions documentation/src/crates/revm/journaled_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The [EIP-161](https://eips.ethereum.org/EIPS/eip-161) aims to optimize Ethereum'

- Account Creation: During the creation of an account (whether by transactions or the `CREATE` operation), the nonce of the new account is incremented by one before the execution of the initialization code. For most networks, the starting value is 1, but this may vary for test networks with non-zero default starting nonces.

- Call and Suicide Charges: Prior to [EIP-161](https://eips.ethereum.org/EIPS/eip-161), a gas charge of 25,000 was levied for `CALL` and `SUICIDE` operations if the destination account did not exist. With [EIP-161](https://eips.ethereum.org/EIPS/eip-161), this charge is only applied if the operation transfers more than zero value and the destination account is dead (non-existent or empty).
- CALL and SELFDESTRUCT Charges: Prior to [EIP-161](https://eips.ethereum.org/EIPS/eip-161), a gas charge of 25,000 was levied for `CALL` and `SELFDESTRUCT` operations if the destination account did not exist. With [EIP-161](https://eips.ethereum.org/EIPS/eip-161), this charge is only applied if the operation transfers more than zero value and the destination account is dead (non-existent or empty).

- Existence of Empty Accounts: An account cannot change its state from non-existent to existent-but-empty. If an operation would result in this, the account remains non-existent.

Expand All @@ -99,7 +99,7 @@ These rules have an impact on how state is managed within the [EIP-161](https://

The rationale behind [EIP-161](https://eips.ethereum.org/EIPS/eip-161) is to optimize the Ethereum state management by getting rid of unnecessary data. Prior to this change, it was possible for the state trie to become bloated with empty accounts. This bloating resulted in increased storage requirements and slower processing times for Ethereum nodes.

By removing these empty accounts, the size of the state trie can be reduced, leading to improvements in the performance of Ethereum nodes. Additionally, the changes regarding the gas costs for `CALL` and `SUICIDE` operations add a new level of nuance to the Ethereum gas model, further optimizing transaction processing.
By removing these empty accounts, the size of the state trie can be reduced, leading to improvements in the performance of Ethereum nodes. Additionally, the changes regarding the gas costs for `CALL` and `SELFDESTRUCT` operations add a new level of nuance to the Ethereum gas model, further optimizing transaction processing.

[EIP-161](https://eips.ethereum.org/EIPS/eip-161) has a significant impact on the state management of Ethereum, and thus is highly relevant to the JournaledState module of the revm crate. The operations defined in this module, such as loading accounts, self-destructing accounts, and changing storage, must all conform to the rules defined in [EIP-161](https://eips.ethereum.org/EIPS/eip-161).

Expand Down