Skip to content

Commit

Permalink
Check exit_substate result before return (rust-ethereum#292)
Browse files Browse the repository at this point in the history
* check exit_result first, then set_code

* Fix call and precompiles
  • Loading branch information
boundless-forest authored Aug 12, 2024
1 parent d8991ec commit 879ffe2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "evm"
version = "0.41.1"
version = "0.41.2"
license = "Apache-2.0"
authors = ["Wei Tang <hi@that.world>", "Parity Technologies <admin@parity.io>"]
description = "SputnikVM - a Portable Blockchain Virtual Machine"
Expand Down
26 changes: 15 additions & 11 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
(reason, maybe_address, return_data)
}
RuntimeKind::Call(code_address) => {
let return_data = self.cleanup_for_call(
let (reason, return_data) = self.cleanup_for_call(
code_address,
&reason,
reason,
runtime.inner.machine().return_value(),
);
(reason, None, return_data)
Expand Down Expand Up @@ -931,7 +931,9 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
exit_status,
output,
}) => {
let _ = self.exit_substate(StackExitKind::Succeeded);
if let Err(e) = self.exit_substate(StackExitKind::Succeeded) {
return Capture::Exit((e.into(), Vec::new()));
}
Capture::Exit((ExitReason::Succeed(exit_status), output))
}
Err(PrecompileFailure::Error { exit_status }) => {
Expand Down Expand Up @@ -1017,10 +1019,10 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
return (e.into(), None, Vec::new());
}
let exit_result = self.exit_substate(StackExitKind::Succeeded);
self.state.set_code(address, out);
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 @@ -1049,27 +1051,29 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
fn cleanup_for_call(
&mut self,
code_address: H160,
reason: &ExitReason,
reason: ExitReason,
return_data: Vec<u8>,
) -> Vec<u8> {
) -> (ExitReason, Vec<u8>) {
log::debug!(target: "evm", "Call execution using address {}: {:?}", code_address, reason);
match reason {
ExitReason::Succeed(_) => {
let _ = self.exit_substate(StackExitKind::Succeeded);
return_data
if let Err(e) = self.exit_substate(StackExitKind::Succeeded) {
return (e.into(), Vec::new());
}
(reason, return_data)
}
ExitReason::Error(_) => {
let _ = self.exit_substate(StackExitKind::Failed);
Vec::new()
(reason, Vec::new())
}
ExitReason::Revert(_) => {
let _ = self.exit_substate(StackExitKind::Reverted);
return_data
(reason, return_data)
}
ExitReason::Fatal(_) => {
self.state.metadata_mut().gasometer.fail();
let _ = self.exit_substate(StackExitKind::Failed);
Vec::new()
(reason, Vec::new())
}
}
}
Expand Down

0 comments on commit 879ffe2

Please sign in to comment.