Skip to content

Commit

Permalink
Check whether caller is in whitelist before allowing creation
Browse files Browse the repository at this point in the history
  • Loading branch information
keithtensor committed Oct 28, 2024
1 parent 6c6e68f commit bcb814a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
T::CallOrigin::ensure_address_origin(&source, origin)?;

let whitelist = <WhitelistedCreators<T>>::get();
let is_transactional = true;
let validate = true;
let info = match T::Runner::create(
Expand All @@ -318,6 +319,7 @@ pub mod pallet {
max_priority_fee_per_gas,
nonce,
access_list,
whitelist,
is_transactional,
validate,
None,
Expand Down Expand Up @@ -394,6 +396,7 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
T::CallOrigin::ensure_address_origin(&source, origin)?;

let whitelist = <WhitelistedCreators<T>>::get();
let is_transactional = true;
let validate = true;
let info = match T::Runner::create2(
Expand All @@ -406,6 +409,7 @@ pub mod pallet {
max_priority_fee_per_gas,
nonce,
access_list,
whitelist,
is_transactional,
validate,
None,
Expand Down Expand Up @@ -516,6 +520,8 @@ pub mod pallet {
TransactionMustComeFromEOA,
/// Undefined error.
Undefined,
/// Origin is not allowed to perform the operation.
NotAllowed,
}

impl<T> From<TransactionValidationError> for Error<T> {
Expand Down
2 changes: 2 additions & 0 deletions frame/evm/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub trait Runner<T: Config> {
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
access_list: Vec<(H160, Vec<H256>)>,
whitelist: Vec<H160>,
is_transactional: bool,
validate: bool,
weight_limit: Option<Weight>,
Expand All @@ -90,6 +91,7 @@ pub trait Runner<T: Config> {
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
access_list: Vec<(H160, Vec<H256>)>,
whitelist: Vec<H160>,
is_transactional: bool,
validate: bool,
weight_limit: Option<Weight>,
Expand Down
16 changes: 16 additions & 0 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,21 @@ where
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
access_list: Vec<(H160, Vec<H256>)>,
whitelist: Vec<H160>,
is_transactional: bool,
validate: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
config: &evm::Config,
) -> Result<CreateInfo, RunnerError<Self::Error>> {
if validate {
if !whitelist.contains(&source) {
return Err(RunnerError {
error: Error::<T>::NotAllowed,
weight: Weight::zero(),
});
}

Self::validate(
source,
None,
Expand Down Expand Up @@ -517,13 +525,21 @@ where
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
access_list: Vec<(H160, Vec<H256>)>,
whitelist: Vec<H160>,
is_transactional: bool,
validate: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
config: &evm::Config,
) -> Result<CreateInfo, RunnerError<Self::Error>> {
if validate {
if !whitelist.contains(&source) {
return Err(RunnerError {
error: Error::<T>::NotAllowed,
weight: Weight::zero(),
});
}

Self::validate(
source,
None,
Expand Down

0 comments on commit bcb814a

Please sign in to comment.