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

add transact_create_force_address #309

Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ std = [
"evm-gasometer/std",
"evm-runtime/std",
]
allow_explicit_address = []
with-codec = [
"scale-codec",
"scale-info",
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
* written in Rust, can be used as a binary, cargo crate or shared
library

### Feature Flags

SputnikVM provides optional feature flags to enable specific functionalities:

- `allow_explicit_address`
Enables the `transact_create_force_address` method, allowing contract creation with a predefined address.
- `with-codec`
- `with-serde`
- `tracing`
- `force-debug`

## Dependencies

Ensure you have at least `rustc 1.51.0 (2fd73fabe 2021-03-23)`. Rust 1.50.0 and
Expand Down
49 changes: 49 additions & 0 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,55 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
}
}

/// Execute a `CREATE` transaction that force the contract address
#[cfg(feature = "allow_explicit_address")]
pub fn transact_create_force_address(
&mut self,
caller: H160,
value: U256,
init_code: Vec<u8>,
gas_limit: u64,
access_list: Vec<(H160, Vec<H256>)>, // See EIP-2930
contract_address: H160,
) -> (ExitReason, Vec<u8>) {
event!(TransactCreate {
caller,
value,
init_code: &init_code,
gas_limit,
address: self.create_address(CreateScheme::Fixed(contract_address)),
});

if let Some(limit) = self.config.max_initcode_size {
if init_code.len() > limit {
self.state.metadata_mut().gasometer.fail();
return emit_exit!(ExitError::CreateContractLimit.into(), Vec::new());
}
}

if let Err(e) = self.record_create_transaction_cost(&init_code, &access_list) {
return emit_exit!(e.into(), Vec::new());
}
self.initialize_with_access_list(access_list);

match self.create_inner(
caller,
CreateScheme::Fixed(contract_address),
value,
init_code,
Some(gas_limit),
false,
) {
Capture::Exit((s, _, v)) => emit_exit!(s, v),
Capture::Trap(rt) => {
let mut cs = Vec::with_capacity(DEFAULT_CALL_STACK_CAPACITY);
cs.push(rt.0);
let (s, _, v) = self.execute_with_call_stack(&mut cs);
emit_exit!(s, v)
}
}
}

/// Execute a `CALL` transaction with a given caller, address, value and
/// gas limit and data.
///
Expand Down