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 option to initiate a top-level DELEGATECALL #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
63 changes: 52 additions & 11 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,57 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
data: Vec<u8>,
gas_limit: u64,
access_list: Vec<(H160, Vec<H256>)>,
) -> (ExitReason, Vec<u8>) {
let context = Context {
caller,
address,
apparent_value: value,
};

let transfer = Some(Transfer {
source: caller,
target: address,
value,
});

self.transact_call_with_context(caller, address, data, gas_limit, access_list, context, transfer)
}

/// Execute a `DELEGATECALL` transaction with a given caller, address, value and
/// gas limit and data.
///
/// Takes in an additional `access_list` parameter for EIP-2930 which was
/// introduced in the Ethereum Berlin hard fork. If you do not wish to use
/// this functionality, just pass in an empty vector.
pub fn transact_delegatecall(
&mut self,
caller: H160,
address: H160,
value: U256,
data: Vec<u8>,
gas_limit: u64,
access_list: Vec<(H160, Vec<H256>)>,
) -> (ExitReason, Vec<u8>) {
let context = Context {
caller,
address: caller,
apparent_value: value,
};

let transfer = None;

self.transact_call_with_context(caller, address, data, gas_limit, access_list, context, transfer)
}

fn transact_call_with_context(
&mut self,
caller: H160,
address: H160,
data: Vec<u8>,
gas_limit: u64,
access_list: Vec<(H160, Vec<H256>)>,
context: Context,
transfer: Option<Transfer>,
) -> (ExitReason, Vec<u8>) {
event!(TransactCall {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change value to value: context.apparent_value in the event! macro. (it currently don't build with tracing feature).

caller,
Expand All @@ -509,19 +560,9 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>

self.state.inc_nonce(caller);

let context = Context {
caller,
address,
apparent_value: value,
};

match self.call_inner(
address,
Some(Transfer {
source: caller,
target: address,
value,
}),
transfer,
data,
Some(gas_limit),
false,
Expand Down