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

Update evm patch #2813

Merged
merged 2 commits into from
Sep 25, 2024
Merged
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
39 changes: 24 additions & 15 deletions modules/evm/src/runner/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
(reason, maybe_address, return_data)
}
RuntimeKind::Call(code_address) => {
let return_data =
self.cleanup_for_call(code_address, &reason, runtime.inner.machine().return_value());
let (reason, return_data) =
self.cleanup_for_call(code_address, reason, runtime.inner.machine().return_value());
(reason, None, return_data)
}
RuntimeKind::Execute => (reason, None, runtime.inner.machine().return_value()),
Expand Down Expand Up @@ -1070,9 +1070,9 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
}) {
return match result {
Ok(PrecompileOutput { exit_status, output }) => {
// let _ = self.exit_substate(StackExitKind::Succeeded);
let e = self.exit_substate(StackExitKind::Succeeded);
try_or_fail!(e);
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 @@ -1142,14 +1142,16 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu

match self.state.metadata_mut().gasometer.record_deposit(out.len()) {
Ok(()) => {
let code_len = out.len();
self.state.set_code(address, out);
let exit_result = self.exit_substate(StackExitKind::Succeeded);
if let Err(e) =
self.record_external_operation(crate::ExternalOperation::Write(U256::from(code_len)))
self.record_external_operation(crate::ExternalOperation::Write(U256::from(out.len())))
{
self.state.metadata_mut().gasometer.fail();
let _ = self.exit_substate(StackExitKind::Failed);
return (e.into(), None, Vec::new());
}
// Success requires storage to be collected successfully
self.state.set_code(address, out);
let exit_result = self.exit_substate(StackExitKind::Succeeded);
if let Err(e) = exit_result {
return (e.into(), None, Vec::new());
}
Expand Down Expand Up @@ -1178,25 +1180,32 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
}
}

fn cleanup_for_call(&mut self, code_address: H160, reason: &ExitReason, return_data: Vec<u8>) -> Vec<u8> {
fn cleanup_for_call(
&mut self,
code_address: H160,
reason: ExitReason,
return_data: 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
Loading