Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
db01eb5
Add all forks to revm
rakita Aug 16, 2022
38bfb6d
Add all hardforks
rakita Aug 17, 2022
f2ff107
Merge remote-tracking branch 'origin/main' into main
rakita Aug 17, 2022
84739f1
EXTCODESIZE and EXTCODEHASH old hardfork gas fix
rakita Aug 17, 2022
fc1a81e
EXTCODECOPY fix gas hardfork
rakita Aug 17, 2022
daadfa2
fmt
rakita Aug 17, 2022
25f06a0
cleanups
rakita Aug 17, 2022
d10dfdf
EIP-161 is in SPURIOUS_DRAGON hardfork
rakita Aug 18, 2022
6e97f92
EIP-161 create nonce increment for SPURIOUS_DRAGON
rakita Aug 18, 2022
175aee5
Enable SPURIOUS_DRAGON tests
rakita Aug 18, 2022
c25fc75
Change database traits to return Result<Option<>>
rakita Aug 18, 2022
b1de572
80perc done transition
rakita Aug 20, 2022
0d68e72
db result compiled and new forks passing
rakita Aug 21, 2022
588d99d
not_existing, precompile perf is_cold
rakita Aug 22, 2022
4222270
fix for not_existing
rakita Aug 22, 2022
1d532dc
passing most of legact tests
rakita Aug 22, 2022
94bc2be
Remove spurious precompile hotfix for old forks
rakita Aug 22, 2022
61eebc8
EIP-2 OOG if crate bytecode can't be paid
rakita Aug 23, 2022
4859b12
Merge remote-tracking branch 'origin/main' into forks
rakita Aug 26, 2022
c8171a7
Add legacy tests to github ci, fmt,clippy
rakita Aug 26, 2022
2d1edcf
Merge remote-tracking branch 'origin/main' into forks
rakita Aug 26, 2022
b5c65f9
fmt
rakita Aug 26, 2022
4317474
Propagate FatalExternalError
rakita Aug 26, 2022
431fe68
Add Error associated type to Database.
rakita Aug 27, 2022
44f6ec1
Small cleanup
rakita Aug 29, 2022
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
Prev Previous commit
Next Next commit
cleanups
  • Loading branch information
rakita committed Aug 17, 2022
commit 25f06a05acd1b4ddba1fc65a0fae1448294bcb1d
14 changes: 5 additions & 9 deletions crates/revm/src/gas/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,14 @@ pub fn sstore_cost<SPEC: Spec>(

pub fn selfdestruct_cost<SPEC: Spec>(res: SelfDestructResult) -> u64 {
let should_charge_topup = if SPEC::enabled(ISTANBUL) {
res.had_value && !res.exists
res.had_value && !res.target_exists
} else {
!res.exists
!res.target_exists
};

let selfdestruct_gas_topup = if should_charge_topup {
if SPEC::enabled(TANGERINE) {
//EIP-150: Gas cost changes for IO-heavy operations
25000
} else {
0
}
let selfdestruct_gas_topup = if SPEC::enabled(TANGERINE) && should_charge_topup {
//EIP-150: Gas cost changes for IO-heavy operations
25000
} else {
0
};
Expand Down
13 changes: 9 additions & 4 deletions crates/revm/src/journaled_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl JournaledState {
target: H160,
db: &mut DB,
) -> SelfDestructResult {
let (is_cold, exists) = self.load_account_exist(target, db);
let (is_cold, target_exists) = self.load_account_exist(target, db);
// transfer all the balance
let acc = self.state.get_mut(&address).unwrap();
let balance = mem::take(&mut acc.info.balance);
Expand Down Expand Up @@ -445,7 +445,7 @@ impl JournaledState {
SelfDestructResult {
had_value: !balance.is_zero(),
is_cold,
exists,
target_exists,
previously_destroyed,
}
}
Expand Down Expand Up @@ -474,8 +474,13 @@ impl JournaledState {
if acc.is_existing_precompile {
(false, true)
} else {
let exists = !acc.is_empty();
(is_cold, exists)
// check
//if address == H160::zero() {
// (is_cold, true)
//} else {
let exists = !acc.is_empty();
(is_cold, exists)
//}
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ pub struct Log {
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SelfDestructResult {
pub had_value: bool,
pub exists: bool,
pub target_exists: bool,
pub is_cold: bool,
pub previously_destroyed: bool,
}
Expand Down
92 changes: 2 additions & 90 deletions crates/revm_precompiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,12 @@ impl SpecId {
}

impl Precompiles {
//TODO refactor this
pub fn new<const SPEC_ID: u8>() -> Self {
let mut fun: Vec<(Address, Precompile)> = Vec::new();
if SpecId::HOMESTEAD.enabled(SPEC_ID) {
fun.push(secp256k1::ECRECOVER);
fun.push(hash::SHA256);
fun.push(hash::RIPED160);
fun.push(secp256k1::ECRECOVER);
fun.push(identity::FUN);
}

Expand Down Expand Up @@ -144,40 +143,6 @@ impl Precompiles {
}
}

/// Matches the address given to Homestead precompiles.
// impl<'backend, 'config> executor::Precompiles<AuroraStackState<'backend, 'config>> for Precompiles {
// fn run(
// &self,
// address: Address,
// input: &[u8],
// target_gas: Option<u64>,
// context: &CallContext,
// state: &mut AuroraStackState,
// is_static: bool,
// ) -> Option<EvmPrecompileResult> {
// let target_gas = match target_gas {
// Some(t) => t,
// None => return Some(EvmPrecompileResult::Err(Return::OutOfGas)),
// };

// let output = self.get_fun(&address).map(|fun| {
// let mut res = (fun)(input, target_gas, context, is_static);
// if let Ok(output) = &mut res {
// if let Some(promise) = output.promise.take() {
// state.add_promise(promise)
// }
// }
// res
// });

// output.map(|res| res.map(Into::into))
// }

// fn addresses(&self) -> &[Address] {
// &self.addresses
// }
// }

/// const fn for making an address by concatenating the bytes from two given numbers,
/// Note that 32 + 128 = 160 = 20 bytes (the length of an address). This function is used
/// as a convenience for specifying the addresses of the various precompiles.
Expand Down Expand Up @@ -213,57 +178,4 @@ pub fn u256_to_arr(value: &U256) -> [u8; 32] {
let mut result = [0u8; 32];
value.to_big_endian(&mut result);
result
}

/*
#[cfg(test)]
mod tests {
use crate::precompiles::{Byzantium, Istanbul};
use crate::prelude::Address;
use rand::Rng;

#[test]
fn test_precompile_addresses() {
assert_eq!(super::secp256k1::ECRecover::ADDRESS, u8_to_address(1));
assert_eq!(super::hash::SHA256::ADDRESS, u8_to_address(2));
assert_eq!(super::hash::RIPEMD160::ADDRESS, u8_to_address(3));
assert_eq!(super::identity::Identity::ADDRESS, u8_to_address(4));
assert_eq!(super::ModExp::<Byzantium>::ADDRESS, u8_to_address(5));
assert_eq!(super::Bn128Add::<Istanbul>::ADDRESS, u8_to_address(6));
assert_eq!(super::Bn128Mul::<Istanbul>::ADDRESS, u8_to_address(7));
assert_eq!(super::Bn128Pair::<Istanbul>::ADDRESS, u8_to_address(8));
assert_eq!(super::blake2::Blake2F::ADDRESS, u8_to_address(9));
}

#[test]
fn test_make_address() {
for i in 0..u8::MAX {
assert_eq!(super::make_address(0, i as u128), u8_to_address(i));
}

let mut rng = rand::thread_rng();
for _ in 0..u8::MAX {
let address: Address = Address(rng.gen());
let (x, y) = split_address(address);
assert_eq!(address, super::make_address(x, y))
}
}

fn u8_to_address(x: u8) -> Address {
let mut bytes = [0u8; 20];
bytes[19] = x;
Address(bytes)
}

// Inverse function of `super::make_address`.
fn split_address(a: Address) -> (u32, u128) {
let mut x_bytes = [0u8; 4];
let mut y_bytes = [0u8; 16];

x_bytes.copy_from_slice(&a[0..4]);
y_bytes.copy_from_slice(&a[4..20]);

(u32::from_be_bytes(x_bytes), u128::from_be_bytes(y_bytes))
}
}
*/
}