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

Bring changes set code #312

Open
wants to merge 3 commits into
base: v0.x
Choose a base branch
from
Open
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
25 changes: 18 additions & 7 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ pub trait StackState<'config>: Backend {
fn log(&mut self, address: H160, topics: Vec<H256>, data: Vec<u8>);
fn set_deleted(&mut self, address: H160);
fn set_created(&mut self, address: H160);
fn set_code(&mut self, address: H160, code: Vec<u8>);
fn set_code(
&mut self,
address: H160,
code: Vec<u8>,
caller: Option<H160>,
) -> Result<(), ExitError>;
fn transfer(&mut self, transfer: Transfer) -> Result<(), ExitError>;
fn reset_balance(&mut self, address: H160);
fn touch(&mut self, address: H160);
Expand Down Expand Up @@ -327,14 +332,15 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
kind: RuntimeKind::Execute,
inner: MaybeBorrowed::Borrowed(runtime),
});
let (reason, _, _) = self.execute_with_call_stack(&mut call_stack);
let (reason, _, _) = self.execute_with_call_stack(&mut call_stack, None);
reason
}

/// Execute using Runtimes on the call_stack until it returns.
fn execute_with_call_stack(
&mut self,
call_stack: &mut Vec<TaggedRuntime<'_>>,
caller: Option<H160>,
) -> (ExitReason, Option<H160>, Vec<u8>) {
// This `interrupt_runtime` is used to pass the runtime obtained from the
// `Capture::Trap` branch in the match below back to the top of the call stack.
Expand Down Expand Up @@ -378,6 +384,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
created_address,
reason,
runtime.inner.machine().return_value(),
caller,
);
(reason, maybe_address, return_data)
}
Expand Down Expand Up @@ -486,7 +493,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
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);
let (s, _, v) = self.execute_with_call_stack(&mut cs, None);
emit_exit!(s, v)
}
}
Expand Down Expand Up @@ -544,7 +551,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
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);
let (s, _, v) = self.execute_with_call_stack(&mut cs, None);
emit_exit!(s, v)
}
}
Expand Down Expand Up @@ -675,7 +682,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
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);
let (s, _, v) = self.execute_with_call_stack(&mut cs, Some(caller));
emit_exit!(s, v)
}
}
Expand Down Expand Up @@ -1028,6 +1035,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
created_address: H160,
reason: ExitReason,
return_data: Vec<u8>,
caller: Option<H160>,
) -> (ExitReason, Option<H160>, Vec<u8>) {
fn check_first_byte(config: &Config, code: &[u8]) -> Result<(), ExitError> {
if config.disallow_executable_format && Some(&Opcode::EOFMAGIC.as_u8()) == code.first()
Expand Down Expand Up @@ -1073,10 +1081,13 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
return (e.into(), None, Vec::new());
}
let exit_result = self.exit_substate(StackExitKind::Succeeded);
let set_code_result = self.state.set_code(address, out, caller);
if let Err(e) = set_code_result {
return (e.into(), None, Vec::new());
}
if let Err(e) = exit_result {
return (e.into(), None, Vec::new());
}
self.state.set_code(address, out);
(ExitReason::Succeed(s), Some(address), Vec::new())
}
Err(e) => {
Expand Down Expand Up @@ -1523,7 +1534,7 @@ impl<'config, S: StackState<'config>, P: PrecompileSet> PrecompileHandle
let mut call_stack = Vec::with_capacity(DEFAULT_CALL_STACK_CAPACITY);
call_stack.push(rt.0);
let (reason, _, return_data) =
self.executor.execute_with_call_stack(&mut call_stack);
self.executor.execute_with_call_stack(&mut call_stack, None);
emit_exit!(reason, return_data)
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/executor/stack/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,14 @@ impl<'config, B: Backend> StackState<'config> for MemoryStackState<'_, 'config,
self.substate.set_created(address)
}

fn set_code(&mut self, address: H160, code: Vec<u8>) {
fn set_code(
&mut self,
address: H160,
code: Vec<u8>,
_caller: Option<H160>,
) -> Result<(), ExitError> {
self.substate.set_code(address, code, self.backend);
Ok(())
}

fn transfer(&mut self, transfer: Transfer) -> Result<(), ExitError> {
Expand Down