Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support create to a fixed address #221

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions Cargo.lock

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

89 changes: 61 additions & 28 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pub mod pallet {
Self::validate_transaction_in_block(source, &transaction).expect(
"pre-block transaction verification failed; the block cannot be built",
);
let (r, _) = Self::apply_validated_transaction(source, transaction)
let (r, _) = Self::apply_validated_transaction(source, transaction, None)
.expect("pre-block apply transaction failed; the block cannot be built");

weight = weight.saturating_add(r.actual_weight.unwrap_or_default());
Expand Down Expand Up @@ -298,7 +298,7 @@ pub mod pallet {
"pre log already exists; block is invalid",
);

Self::apply_validated_transaction(source, transaction).map(|(post_info, _)| post_info)
Self::apply_validated_transaction(source, transaction, None).map(|(post_info, _)| post_info)
}
}

Expand Down Expand Up @@ -582,8 +582,9 @@ impl<T: Config> Pallet<T> {
fn apply_validated_transaction(
source: H160,
transaction: Transaction,
maybe_force_create_address: Option<H160>,
) -> Result<(PostDispatchInfo, CallOrCreateInfo), DispatchErrorWithPostInfo> {
let (to, _, info) = Self::execute(source, &transaction, None)?;
let (to, _, info) = Self::execute(source, &transaction, None, maybe_force_create_address)?;

catch_exec_info::fill_exec_info(&info);

Expand Down Expand Up @@ -739,6 +740,7 @@ impl<T: Config> Pallet<T> {
from: H160,
transaction: &Transaction,
config: Option<evm::Config>,
maybe_force_create_address: Option<H160>,
) -> Result<(Option<H160>, Option<H160>, CallOrCreateInfo), DispatchErrorWithPostInfo> {
let transaction_data: TransactionData = transaction.into();
let (weight_limit, proof_size_base_cost) = Self::transaction_weight(&transaction_data);
Expand Down Expand Up @@ -838,30 +840,60 @@ impl<T: Config> Pallet<T> {
Ok((Some(target), None, CallOrCreateInfo::Call(res)))
}
ethereum::TransactionAction::Create => {
let res = match T::Runner::create(
from,
input,
value,
gas_limit.unique_saturated_into(),
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
access_list,
is_transactional,
validate,
weight_limit,
proof_size_base_cost,
config.as_ref().unwrap_or_else(|| T::config()),
) {
Ok(res) => res,
Err(e) => {
return Err(DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
actual_weight: Some(e.weight),
pays_fee: Pays::Yes,
},
error: e.error.into(),
})
let res = if let Some(force_address) = maybe_force_create_address {
match T::Runner::create_force_address(
from,
input,
value,
gas_limit.unique_saturated_into(),
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
access_list,
is_transactional,
validate,
weight_limit,
proof_size_base_cost,
config.as_ref().unwrap_or_else(|| T::config()),
force_address,
) {
Ok(res) => res,
Err(e) => {
return Err(DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
actual_weight: Some(e.weight),
pays_fee: Pays::Yes,
},
error: e.error.into(),
})
}
}
} else {
match T::Runner::create(
from,
input,
value,
gas_limit.unique_saturated_into(),
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
access_list,
is_transactional,
validate,
weight_limit,
proof_size_base_cost,
config.as_ref().unwrap_or_else(|| T::config()),
) {
Ok(res) => res,
Err(e) => {
return Err(DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
actual_weight: Some(e.weight),
pays_fee: Pays::Yes,
},
error: e.error.into(),
})
}
}
};

Expand Down Expand Up @@ -1004,8 +1036,9 @@ impl<T: Config> ValidatedTransactionT for ValidatedTransaction<T> {
fn apply(
source: H160,
transaction: Transaction,
maybe_force_create_address: Option<H160>,
) -> Result<(PostDispatchInfo, CallOrCreateInfo), DispatchErrorWithPostInfo> {
Pallet::<T>::apply_validated_transaction(source, transaction)
Pallet::<T>::apply_validated_transaction(source, transaction, maybe_force_create_address)
}
}

Expand Down
17 changes: 17 additions & 0 deletions frame/evm/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,21 @@ pub trait Runner<T: Config> {
proof_size_base_cost: Option<u64>,
config: &evm::Config,
) -> Result<CreateInfo, RunnerError<Self::Error>>;

fn create_force_address(
source: H160,
init: Vec<u8>,
value: U256,
gas_limit: u64,
max_fee_per_gas: Option<U256>,
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
access_list: Vec<(H160, Vec<H256>)>,
is_transactional: bool,
validate: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
config: &evm::Config,
contract_address: H160,
) -> Result<CreateInfo, RunnerError<Self::Error>>;
}
55 changes: 55 additions & 0 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,61 @@ where
},
)
}


fn create_force_address(
source: H160,
init: Vec<u8>,
value: U256,
gas_limit: u64,
max_fee_per_gas: Option<U256>,
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
access_list: Vec<(H160, Vec<H256>)>,
is_transactional: bool,
validate: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
config: &evm::Config,
contract_address: H160,
) -> Result<CreateInfo, RunnerError<Self::Error>> {
if validate {
Self::validate(
source,
None,
init.clone(),
value,
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
access_list.clone(),
is_transactional,
weight_limit,
proof_size_base_cost,
config,
)?;
}
let precompiles = T::PrecompilesValue::get();
Self::execute(
source,
value,
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
config,
&precompiles,
is_transactional,
weight_limit,
proof_size_base_cost,
|executor| {
T::OnCreate::on_create(source, contract_address);
let (reason, _) =
executor.transact_create_force_address(source, value, init, gas_limit, access_list, contract_address);
RomarQ marked this conversation as resolved.
Show resolved Hide resolved
(reason, contract_address)
},
)
}
}

struct SubstrateStackSubstate<'config> {
Expand Down
1 change: 1 addition & 0 deletions primitives/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub trait ValidatedTransaction {
fn apply(
source: H160,
transaction: Transaction,
maybe_force_create_address: Option<H160>,
) -> Result<(PostDispatchInfo, CallOrCreateInfo), DispatchErrorWithPostInfo>;
}

Expand Down