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

Fix: change error code for revert #11

Open
wants to merge 1 commit into
base: unique-polkadot-v0.9.30
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion client/rpc/src/eth/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ use crate::{

/// Default JSONRPC error code return by geth
pub const JSON_RPC_ERROR_DEFAULT: i32 = -32000;
/// JSONRPC error code for a revertal.
pub const REVERT_CODE: i32 = 3;

impl<B, C, P, CT, BE, H: ExHashT, A: ChainApi> Eth<B, C, P, CT, BE, H, A>
where
Expand Down Expand Up @@ -670,7 +672,13 @@ pub fn error_on_execution_failure(reason: &ExitReason, data: &[u8]) -> Result<()
))
}
ExitReason::Revert(_) => {
const OFFSET_START: usize = 4;

let mut message = "VM Exception while processing transaction: revert".to_string();
// If error has no selector
if data.len() < OFFSET_START {
Copy link
Member

Choose a reason for hiding this comment

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

Не должно ли это срабатывать при data.len <=68?

return Err(crate::err(JSON_RPC_ERROR_DEFAULT, message, Some(data)));
}
// A minimum size of error function selector (4) + offset (32) + string length (32)
// should contain a utf-8 encoded revert reason.
if data.len() > 68 {
Expand All @@ -682,7 +690,7 @@ pub fn error_on_execution_failure(reason: &ExitReason, data: &[u8]) -> Result<()
}
}
}
Err(crate::internal_err_with_data(message, data))
Err(crate::err(REVERT_CODE, message, Some(data)))
}
ExitReason::Fatal(e) => Err(crate::internal_err_with_data(
format!("evm fatal: {:?}", e),
Expand Down