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

Detect Solidity assert as a revert #1162

Merged
merged 2 commits into from
Sep 5, 2019
Merged
Changes from 1 commit
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
21 changes: 15 additions & 6 deletions datasource/ethereum/src/ethereum_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ where
// cannot be differentiated from random failures. However Solidity
// `revert` and `require` calls with a reason string can be detected.

// 0xfe is the "designated bad instruction" of the EVM, and Solidity
// uses it for asserts.
const PARITY_0xFE: &str = "Bad instruction fe";
const GANACHE_VM_EXECUTION_ERROR: i64 = -32000;
const GANACHE_REVERT_MESSAGE: &str =
"VM Exception while processing transaction: revert";
Expand Down Expand Up @@ -424,17 +427,23 @@ where
if rpc_error.code.code() == PARITY_VM_EXECUTION_ERROR =>
{
match rpc_error.data.as_ref().and_then(|d| d.as_str()) {
Some(data) if data.starts_with(PARITY_REVERT_PREFIX) => {
let payload =
data.trim_start_matches(PARITY_REVERT_PREFIX);
Err(EthereumContractCallError::Revert(
Some(data)
if data.starts_with(PARITY_REVERT_PREFIX)
|| data == PARITY_0xFE =>
{
let reason = if data == PARITY_0xFE {
PARITY_0xFE.to_owned()
} else {
let payload =
data.trim_start_matches(PARITY_REVERT_PREFIX);
hex::decode(payload)
.ok()
.and_then(|payload| {
as_solidity_revert_with_reason(&payload)
})
.unwrap_or("no reason".to_owned()),
))
.unwrap_or("no reason".to_owned())
};
Err(EthereumContractCallError::Revert(reason))
}

// The VM execution error was not identified as a revert.
Expand Down