Skip to content

EVM: Implement reverts correctly #864

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

Merged
merged 27 commits into from
Nov 23, 2022
Merged

EVM: Implement reverts correctly #864

merged 27 commits into from
Nov 23, 2022

Conversation

vyzo
Copy link
Contributor

@vyzo vyzo commented Nov 22, 2022

Adjust implementation so that

  • reverts properly propagate data (dude, where are my error messages?)
  • call correctly handles errors and converts them to reverts.

TBD:

  • test frameworks: implement exit
  • revert tests

Notes:
reverts for direct invocations are tested with a unit test; reverts in nested invocations are tested with the callvariants test in the integration test suite.

@vyzo vyzo requested review from Stebalien and mriise November 22, 2022 04:44
@vyzo vyzo changed the title Implement reverts correctly EVM: Implement reverts correctly Nov 22, 2022
@vyzo vyzo force-pushed the next-revert-proper branch from 7a1228b to da1cc9f Compare November 22, 2022 04:51
@vyzo vyzo marked this pull request as ready for review November 22, 2022 08:03
@codecov-commenter
Copy link

Codecov Report

Merging #864 (1501f44) into next (cd7cfce) will decrease coverage by 0.01%.
The diff coverage is 67.94%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             next     #864      +/-   ##
==========================================
- Coverage   87.32%   87.31%   -0.02%     
==========================================
  Files         125      125              
  Lines       22784    22896     +112     
==========================================
+ Hits        19897    19991      +94     
- Misses       2887     2905      +18     
Impacted Files Coverage Δ
runtime/src/runtime/mod.rs 84.21% <ø> (ø)
actors/evm/src/lib.rs 84.36% <50.00%> (+0.44%) ⬆️
runtime/src/actor_error.rs 74.41% <50.98%> (-12.95%) ⬇️
actors/evm/src/interpreter/instructions/call.rs 89.28% <65.21%> (-2.07%) ⬇️
test_vm/src/lib.rs 82.66% <89.18%> (+<0.01%) ⬆️
runtime/src/test_utils.rs 82.23% <90.47%> (+0.15%) ⬆️
actors/evm/src/interpreter/instructions/control.rs 88.88% <100.00%> (ø)
actors/evm/src/interpreter/output.rs 6.66% <0.00%> (-20.00%) ⬇️
... and 4 more

A::invoke_method(self, method_num, params)
}))
.unwrap_or_else(|panic| {
if self.actor_exit.borrow().is_some() {
Copy link
Member

Choose a reason for hiding this comment

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

Let's instead embed the exit inside the error, and cast with https://doc.rust-lang.org/std/any/trait.Any.html#method.downcast. That way, we can't accidentally swallow up a real panic.

Copy link
Member

Choose a reason for hiding this comment

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

Basically, we can use panic to "throw" the exit value.

Copy link
Contributor Author

@vyzo vyzo Nov 23, 2022

Choose a reason for hiding this comment

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

Does this even make sense here?

We set the exit and immediately panic, which lands here; any other panic will be resumed. So the mentioned condition is not really possible, and it is nicer to the eye in tests since cargo will still report these panics at runtime in the console.

Now, if this was prod code, i would definitely consider the fancy way.
Here, i dont think it adds anything but complexity, really.

Having said all that, if you feel overly strongly about that and insist, i will abide.

Copy link
Member

Choose a reason for hiding this comment

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

Eh, you're right. There's little benefit.

precompiles::Precompiles::call_precompile(system.rt, dst, input_data)
.map_err(|_| StatusCode::PrecompileFailure)?
match precompiles::Precompiles::call_precompile(system.rt, dst, input_data)
.map_err(|_| StatusCode::PrecompileFailure)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will need to be re-done when merging with #861, since there are cases where we want to return to a status code error and others where we have a precompile error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, i'll leave that up to you.

Copy link
Member

Choose a reason for hiding this comment

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

Well, it has already been merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah i noticed. I will rebase and we can discuss what do here when we are happy with the rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, merged, very little to do here other than resolve the conflict.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -634,7 +639,7 @@ pub fn trampoline<C: ActorCode>(params: u32) -> u32 {
let mut rt = FvmRuntime::default();
// Invoke the method, aborting if the actor returns an errored exit code.
let ret = C::invoke_method(&mut rt, method, &params)
.unwrap_or_else(|err| fvm::vm::abort(err.exit_code().value(), Some(err.msg())));
.unwrap_or_else(|err| fvm::vm::exit(err.exit_code().value(), err.data(), Some(err.msg())));
Copy link
Member

Choose a reason for hiding this comment

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

nice catch!

@vyzo vyzo force-pushed the next-revert-proper branch from 9c4e443 to 3f91e75 Compare November 23, 2022 04:11
@vyzo
Copy link
Contributor Author

vyzo commented Nov 23, 2022

rebased on next to merge the precompile/callactor work and did a very minor dedup simplification in 3f91e75.

@vyzo vyzo enabled auto-merge (squash) November 23, 2022 04:25
@vyzo vyzo merged commit 8e93725 into next Nov 23, 2022
@vyzo vyzo deleted the next-revert-proper branch November 23, 2022 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants