-
Notifications
You must be signed in to change notification settings - Fork 252
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
feat: deplete compute meter for vm errors #3751
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1473,6 +1473,24 @@ pub fn execute<'a, 'b: 'a>( | |
Err(Box::new(error) as Box<dyn std::error::Error>) | ||
} | ||
ProgramResult::Err(mut error) => { | ||
if invoke_context | ||
.get_feature_set() | ||
.is_active(&solana_feature_set::apply_cost_tracker_during_replay::id()) | ||
&& !matches!(error, EbpfError::SyscallError(_)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the exception for syscall errors? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is in the SIMD. Rational is that syscalls always interrupt a basic block so CU metering is required regardless. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. I left a comment in the SIMD PR |
||
{ | ||
// when an exception is thrown during the execution of a | ||
// Basic Block (e.g., a null memory dereference or other | ||
// faults), determining the exact number of CUs consumed | ||
// up to the point of failure requires additional effort | ||
// and is unnecessary since these cases are rare. | ||
// | ||
// In order to simplify CU tracking, simply consume all | ||
// remaining compute units so that the block cost | ||
// tracker uses the full requested compute unit cost for | ||
// this failed transaction. | ||
invoke_context.consume(invoke_context.get_remaining()); | ||
} | ||
|
||
if direct_mapping { | ||
if let EbpfError::AccessViolation( | ||
AccessType::Store, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "solana-sbf-rust-divide-by-zero" | ||
version = { workspace = true } | ||
description = { workspace = true } | ||
authors = { workspace = true } | ||
repository = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
edition = { workspace = true } | ||
|
||
[dependencies] | ||
solana-program = { workspace = true } | ||
|
||
[lib] | ||
crate-type = ["cdylib"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//! Example/test program to trigger vm error by dividing by zero | ||
#![feature(asm_experimental_arch)] | ||
|
||
extern crate solana_program; | ||
use { | ||
solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}, | ||
std::arch::asm, | ||
}; | ||
|
||
solana_program::entrypoint_no_alloc!(process_instruction); | ||
fn process_instruction( | ||
_program_id: &Pubkey, | ||
_accounts: &[AccountInfo], | ||
_instruction_data: &[u8], | ||
) -> ProgramResult { | ||
unsafe { | ||
asm!( | ||
" | ||
mov64 r0, 0 | ||
mov64 r1, 0 | ||
div64 r0, r1 | ||
" | ||
); | ||
} | ||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM