Skip to content

Commit

Permalink
Update evm to 0.39
Browse files Browse the repository at this point in the history
  • Loading branch information
tgmichel committed May 23, 2023
1 parent 0d1f026 commit 882b85e
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 119 deletions.
84 changes: 54 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
exclude = [ "bin/utils/moonkey" ]
exclude = ["bin/utils/moonkey"]
members = [
"bin/utils/moonkey",
"client/rpc/finality",
Expand Down Expand Up @@ -42,7 +42,7 @@ members = [
resolver = "2"

[workspace.package]
authors = [ "PureStake" ]
authors = ["PureStake"]
repository = "https://github.com/PureStake/moonbeam"

[workspace.dependencies]
Expand Down Expand Up @@ -226,11 +226,11 @@ ethereum = { version = "0.14.0", default-features = false, features = [
"with-codec",
] }
ethereum-types = { version = "0.14", default-features = false }
evm = { version = "0.37.0", default-features = false, features = [
evm = { version = "0.39.0", default-features = false, features = [
"with-codec",
] }
evm-gasometer = { version = "0.37.0", default-features = false }
evm-runtime = { version = "0.37.0", default-features = false }
evm-gasometer = { version = "0.39.0", default-features = false }
evm-runtime = { version = "0.39.0", default-features = false }
fp-ethereum = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
fp-evm = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
fp-rpc = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
Expand Down Expand Up @@ -333,7 +333,7 @@ serde = { version = "1.0.101", default-features = false }
sha3 = { version = "0.10", default-features = false }
slices = "0.2.0"
smallvec = "1.8.0"
strum = { version = "0.24", default-features = false, features = [ "derive" ] }
strum = { version = "0.24", default-features = false, features = ["derive"] }
strum_macros = "0.24"

# Other (client)
Expand All @@ -343,7 +343,7 @@ async-io = "1.3"
bip32 = { git = "https://github.com/purestake/crates", branch = "bip32-v0.4.0-fix", default-features = false, features = [
"bip39",
] }
clap = { version = "4.0.9", features = [ "derive" ] }
clap = { version = "4.0.9", features = ["derive"] }
exit-future = "0.2"
flume = "0.10.9"
futures = { version = "0.3.21" }
Expand Down
22 changes: 13 additions & 9 deletions precompiles/precompile-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ mod mock;
mod tests;

use core::marker::PhantomData;
use fp_evm::PrecompileSet;
use precompile_utils::{precompile_set::IsActivePrecompile, prelude::*};
use fp_evm::{ExitError, IsPrecompileResult, PrecompileFailure, PrecompileSet};
use precompile_utils::{precompile_set::{is_precompile_or_fail, IsActivePrecompile}, prelude::*};
use sp_core::Get;

const DUMMY_CODE: [u8; 5] = [0x60, 0x00, 0x60, 0x00, 0xfd];
Expand All @@ -41,9 +41,7 @@ where
fn is_precompile(handle: &mut impl PrecompileHandle, address: Address) -> EvmResult<bool> {
// We consider the precompile set is optimized to do at most one storage read.
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;

let active = <Runtime::PrecompilesValue>::get().is_precompile(address.0);
Ok(active)
is_precompile_or_fail::<Runtime>(address.0, handle.remaining_gas())
}

#[precompile::public("isActivePrecompile(address)")]
Expand All @@ -54,9 +52,15 @@ where
) -> EvmResult<bool> {
// We consider the precompile set is optimized to do at most one storage read.
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;

let active = <Runtime::PrecompilesValue>::get().is_active_precompile(address.0);
Ok(active)
match <Runtime::PrecompilesValue>::get().is_active_precompile(address.0, handle.remaining_gas()) {
IsPrecompileResult::Answer {
is_precompile,
..
} => Ok(is_precompile),
IsPrecompileResult::OutOfGas => Err(PrecompileFailure::Error {
exit_status: ExitError::OutOfGas
})
}
}

#[precompile::public("updateAccountCode(address)")]
Expand All @@ -68,7 +72,7 @@ where
handle.record_cost(RuntimeHelper::<Runtime>::db_write_gas_cost())?;

// Prevent touching addresses that are not precompiles.
if !<Runtime::PrecompilesValue>::get().is_precompile(address.0) {
if !is_precompile_or_fail::<Runtime>(address.0, handle.remaining_gas())? {
return Err(revert("provided address is not a precompile"));
}

Expand Down
6 changes: 3 additions & 3 deletions precompiles/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ pub struct EvmSubCall {
pub trait EvmProxyCallFilter: Sized + Send + Sync {
/// If returns `false`, then the subcall will not be executed and the evm transaction will
/// revert with error message "CallFiltered".
fn is_evm_proxy_call_allowed(&self, _call: &EvmSubCall, _recipient_has_code: bool) -> bool {
false
fn is_evm_proxy_call_allowed(&self, _call: &EvmSubCall, _recipient_has_code: bool, _gas: u64) -> EvmResult<bool> {
Ok(false)
}
}

Expand Down Expand Up @@ -352,7 +352,7 @@ where
// Apply proxy type filter
frame_support::ensure!(
def.proxy_type
.is_evm_proxy_call_allowed(&evm_subcall, recipient_has_code),
.is_evm_proxy_call_allowed(&evm_subcall, recipient_has_code, handle.remaining_gas())?,
revert("CallFiltered")
);

Expand Down
Loading

0 comments on commit 882b85e

Please sign in to comment.