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

v2.1: feat: deplete compute meter for vm errors (backport of #3751) #3955

Open
wants to merge 5 commits into
base: v2.1
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,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(_))
{
// 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,
Expand Down
7 changes: 7 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions programs/sbf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ members = [
"rust/custom_heap",
"rust/dep_crate",
"rust/deprecated_loader",
"rust/divide_by_zero",
"rust/dup_accounts",
"rust/error_handling",
"rust/external_spend",
Expand Down
15 changes: 15 additions & 0 deletions programs/sbf/rust/divide_by_zero/Cargo.toml
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"]
27 changes: 27 additions & 0 deletions programs/sbf/rust/divide_by_zero/src/lib.rs
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(())
}
Loading
Loading