Skip to content

Commit

Permalink
Prevent delegateCall on EVM
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystalin committed May 27, 2022
1 parent 65a27aa commit 015aaf2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("moonbase"),
impl_name: create_runtime_str!("moonbase"),
authoring_version: 3,
spec_version: 1502,
spec_version: 1503,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down
11 changes: 10 additions & 1 deletion runtime/moonbase/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::asset_config::{ForeignAssetInstance, LocalAssetInstance};
use crowdloan_rewards_precompiles::CrowdloanRewardsWrapper;
use fp_evm::Context;
use fp_evm::{Context, ExitRevert, PrecompileFailure};
use moonbeam_relay_encoder::westend::WestendEncoder;
use pallet_author_mapping_precompiles::AuthorMappingWrapper;
use pallet_democracy_precompiles::DemocracyWrapper;
Expand Down Expand Up @@ -121,6 +121,15 @@ where
context: &Context,
is_static: bool,
) -> Option<PrecompileResult> {
// Filter known precompile addresses except Ethereum officials
if address > hash(9) && context.address != address {
return Some(Err(PrecompileFailure::Revert {
exit_status: ExitRevert::Reverted,
output: b"cannot be called with DELEGATECALL or CALLCODE".to_vec(),
cost: 0,
}));
}

match address {
// Ethereum precompiles :
a if a == hash(1) => Some(ECRecover::execute(input, target_gas, context, is_static)),
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("moonbeam"),
impl_name: create_runtime_str!("moonbeam"),
authoring_version: 3,
spec_version: 1502,
spec_version: 1503,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down
11 changes: 10 additions & 1 deletion runtime/moonbeam/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::asset_config::{ForeignAssetInstance, LocalAssetInstance};
use crowdloan_rewards_precompiles::CrowdloanRewardsWrapper;
use fp_evm::Context;
use fp_evm::{Context, ExitRevert, PrecompileFailure};
use moonbeam_relay_encoder::polkadot::PolkadotEncoder;
use pallet_author_mapping_precompiles::AuthorMappingWrapper;
use pallet_democracy_precompiles::DemocracyWrapper;
Expand Down Expand Up @@ -121,6 +121,15 @@ where
context: &Context,
is_static: bool,
) -> Option<PrecompileResult> {
// Filter known precompile addresses except Ethereum officials
if address > hash(9) && context.address != address {
return Some(Err(PrecompileFailure::Revert {
exit_status: ExitRevert::Reverted,
output: b"cannot be called with DELEGATECALL or CALLCODE".to_vec(),
cost: 0,
}));
}

match address {
// Ethereum precompiles :
a if a == hash(1) => Some(ECRecover::execute(input, target_gas, context, is_static)),
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("moonriver"),
impl_name: create_runtime_str!("moonriver"),
authoring_version: 3,
spec_version: 1502,
spec_version: 1503,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down
11 changes: 10 additions & 1 deletion runtime/moonriver/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::asset_config::{ForeignAssetInstance, LocalAssetInstance};
use crowdloan_rewards_precompiles::CrowdloanRewardsWrapper;
use fp_evm::Context;
use fp_evm::{Context, ExitRevert, PrecompileFailure};
use moonbeam_relay_encoder::kusama::KusamaEncoder;
use pallet_author_mapping_precompiles::AuthorMappingWrapper;
use pallet_democracy_precompiles::DemocracyWrapper;
Expand Down Expand Up @@ -121,6 +121,15 @@ where
context: &Context,
is_static: bool,
) -> Option<PrecompileResult> {
// Filter known precompile addresses except Ethereum officials
if address > hash(9) && context.address != address {
return Some(Err(PrecompileFailure::Revert {
exit_status: ExitRevert::Reverted,
output: b"cannot be called with DELEGATECALL or CALLCODE".to_vec(),
cost: 0,
}));
}

match address {
// Ethereum precompiles :
a if a == hash(1) => Some(ECRecover::execute(input, target_gas, context, is_static)),
Expand Down

0 comments on commit 015aaf2

Please sign in to comment.