Skip to content

Commit

Permalink
Bump solana_rbpf to version 0.2.13 (solana-labs#18068)
Browse files Browse the repository at this point in the history
* Moves syscall_registry into the rbpf Executable constructor.

* Adds the reject_unresolved_syscalls flag which is only set when deploying programs via the CLI.
  • Loading branch information
Lichtso committed Dec 3, 2021
1 parent 800ddfe commit 109f5bc
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 70 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ solana-config-program = { path = "../programs/config", version = "=1.8.7" }
solana-faucet = { path = "../faucet", version = "=1.8.7" }
solana-logger = { path = "../logger", version = "=1.8.7" }
solana-net-utils = { path = "../net-utils", version = "=1.8.7" }
solana_rbpf = "=0.2.12"
solana_rbpf = "=0.2.13"
solana-remote-wallet = { path = "../remote-wallet", version = "=1.8.7" }
solana-sdk = { path = "../sdk", version = "=1.8.7" }
solana-transaction-status = { path = "../transaction-status", version = "=1.8.7" }
Expand Down
10 changes: 8 additions & 2 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
clap::{App, AppSettings, Arg, ArgMatches, SubCommand},
log::*,
solana_account_decoder::{UiAccountEncoding, UiDataSliceConfig},
solana_bpf_loader_program::{BpfError, ThisInstructionMeter},
solana_bpf_loader_program::{syscalls::register_syscalls, BpfError, ThisInstructionMeter},
solana_clap_utils::{self, input_parsers::*, input_validators::*, keypair::*},
solana_cli_output::{
CliProgram, CliProgramAccountType, CliProgramAuthority, CliProgramBuffer, CliProgramId,
Expand Down Expand Up @@ -39,6 +39,7 @@ use {
message::Message,
native_token::Sol,
packet::PACKET_DATA_SIZE,
process_instruction::MockInvokeContext,
pubkey::Pubkey,
signature::{keypair_from_seed, read_keypair_file, Keypair, Signature, Signer},
system_instruction::{self, SystemError},
Expand Down Expand Up @@ -1985,12 +1986,17 @@ fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::e
let mut program_data = Vec::new();
file.read_to_end(&mut program_data)
.map_err(|err| format!("Unable to read program file: {}", err))?;
let mut invoke_context = MockInvokeContext::new(vec![]);

// Verify the program
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
&program_data,
Some(|x| verifier::check(x)),
Config::default(),
Config {
reject_unresolved_syscalls: true,
..Config::default()
},
register_syscalls(&mut invoke_context).unwrap(),
)
.map_err(|err| format!("ELF error: {}", err))?;

Expand Down
Binary file modified cli/tests/fixtures/noop.so
Binary file not shown.
8 changes: 4 additions & 4 deletions programs/bpf/Cargo.lock

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

2 changes: 1 addition & 1 deletion programs/bpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ solana-bpf-loader-program = { path = "../bpf_loader", version = "=1.8.7" }
solana-cli-output = { path = "../../cli-output", version = "=1.8.7" }
solana-logger = { path = "../../logger", version = "=1.8.7" }
solana-measure = { path = "../../measure", version = "=1.8.7" }
solana_rbpf = "=0.2.12"
solana_rbpf = "=0.2.13"
solana-runtime = { path = "../../runtime", version = "=1.8.7" }
solana-sdk = { path = "../../sdk", version = "=1.8.7" }
solana-transaction-status = { path = "../../transaction-status", version = "=1.8.7" }
Expand Down
36 changes: 23 additions & 13 deletions programs/bpf/benches/bpf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use solana_bpf_loader_program::{
ThisInstructionMeter,
};
use solana_measure::measure::Measure;
use solana_rbpf::vm::{Config, Executable, InstructionMeter};
use solana_rbpf::vm::{Config, Executable, InstructionMeter, SyscallRegistry};
use solana_runtime::{
bank::Bank,
bank_client::BankClient,
Expand Down Expand Up @@ -79,6 +79,7 @@ fn bench_program_create_executable(bencher: &mut Bencher) {
&elf,
None,
Config::default(),
SyscallRegistry::default(),
)
.unwrap();
});
Expand All @@ -97,10 +98,13 @@ fn bench_program_alu(bencher: &mut Bencher) {
let mut invoke_context = MockInvokeContext::new(vec![]);

let elf = load_elf("bench_alu").unwrap();
let mut executable =
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(&elf, None, Config::default())
.unwrap();
executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap());
let mut executable = <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
&elf,
None,
Config::default(),
register_syscalls(&mut invoke_context).unwrap(),
)
.unwrap();
executable.jit_compile().unwrap();
let compute_meter = invoke_context.get_compute_meter();
let mut instruction_meter = ThisInstructionMeter { compute_meter };
Expand Down Expand Up @@ -225,10 +229,13 @@ fn bench_create_vm(bencher: &mut Bencher) {
.unwrap();

let elf = load_elf("noop").unwrap();
let mut executable =
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(&elf, None, Config::default())
.unwrap();
executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap());
let executable = <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
&elf,
None,
Config::default(),
register_syscalls(&mut invoke_context).unwrap(),
)
.unwrap();

bencher.iter(|| {
let _ = create_vm(
Expand Down Expand Up @@ -273,10 +280,13 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
.unwrap();

let elf = load_elf("tuner").unwrap();
let mut executable =
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(&elf, None, Config::default())
.unwrap();
executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap());
let executable = <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
&elf,
None,
Config::default(),
register_syscalls(&mut invoke_context).unwrap(),
)
.unwrap();
let compute_meter = invoke_context.get_compute_meter();
let mut instruction_meter = ThisInstructionMeter { compute_meter };
let mut vm = create_vm(
Expand Down
14 changes: 8 additions & 6 deletions programs/bpf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,16 @@ fn run_program(
let mut instruction_meter = ThisInstructionMeter { compute_meter };

let config = Config {
max_call_depth: 20,
stack_frame_size: 4096,
enable_instruction_meter: true,
enable_instruction_tracing: true,
..Config::default()
};
let mut executable =
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(&data, None, config).unwrap();
executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap());
let mut executable = <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
&data,
None,
config,
register_syscalls(&mut invoke_context).unwrap(),
)
.unwrap();
executable.jit_compile().unwrap();

let mut instruction_count = 0;
Expand Down
2 changes: 1 addition & 1 deletion programs/bpf_loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sha3 = "0.9.1"
solana-measure = { path = "../../measure", version = "=1.8.7" }
solana-runtime = { path = "../../runtime", version = "=1.8.7" }
solana-sdk = { path = "../../sdk", version = "=1.8.7" }
solana_rbpf = "=0.2.12"
solana_rbpf = "=0.2.13"
thiserror = "1.0"

[dev-dependencies]
Expand Down
14 changes: 10 additions & 4 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,27 @@ pub fn create_executor(
let config = Config {
max_call_depth: bpf_compute_budget.max_call_depth,
stack_frame_size: bpf_compute_budget.stack_frame_size,
enable_instruction_meter: true,
enable_instruction_tracing: log_enabled!(Trace),
..Config::default()
};
let mut executable = {
let keyed_accounts = invoke_context.get_keyed_accounts()?;
let program = keyed_account_at_index(keyed_accounts, program_account_index)?;
let account = program.try_account_ref()?;
let data = &account.data()[program_data_offset..];
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(data, None, config)
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
data,
None,
config,
syscall_registry,
)
}
.map_err(|e| map_ebpf_error(invoke_context, e))?;
let (_, elf_bytes) = executable
.get_text_bytes()
.map_err(|e| map_ebpf_error(invoke_context, e))?;
verifier::check(elf_bytes)
.map_err(|e| map_ebpf_error(invoke_context, EbpfError::UserError(e.into())))?;
executable.set_syscall_registry(syscall_registry);
if use_jit {
if let Err(err) = executable.jit_compile() {
ic_msg!(invoke_context, "Failed to compile program {:?}", err);
Expand Down Expand Up @@ -1004,6 +1008,7 @@ mod tests {
use {
super::*,
rand::Rng,
solana_rbpf::vm::SyscallRegistry,
solana_runtime::{bank::Bank, bank_client::BankClient},
solana_sdk::{
account::{
Expand Down Expand Up @@ -1057,9 +1062,10 @@ mod tests {
solana_rbpf::elf::register_bpf_function(&mut bpf_functions, 0, "entrypoint").unwrap();
let program = <dyn Executable<BpfError, TestInstructionMeter>>::from_text_bytes(
program,
bpf_functions,
None,
Config::default(),
SyscallRegistry::default(),
bpf_functions,
)
.unwrap();
let mut vm =
Expand Down
Loading

0 comments on commit 109f5bc

Please sign in to comment.