Commit Graph

22 Commits

Author SHA1 Message Date
Alexander Meißner 9e703f85de
Upgrades Rust to 1.72.0 & nightly-2023-08-25 (#32961)
* allow pedantic invalid cast lint

* allow lint with false-positive triggered by `test-case` crate

* nightly `fmt` correction

* adapt to rust layout changes

* remove dubious test

* Use transmute instead of pointer cast and de/ref when check_aligned is false.

* Renames clippy::integer_arithmetic to clippy::arithmetic_side_effects.

* bump rust nightly to 2023-08-25

* Upgrades Rust to 1.72.0

---------

Co-authored-by: Trent Nelson <trent@solana.com>
2023-09-01 07:26:13 +00:00
steviez a4c8cc3ce0
Remove improper uses of &Arc<Bank> (#32802)
In most cases, either a &Bank or an Arc<Bank> is more proper.
- &Bank is used if the function only needs a momentary reference
- Arc<Bank> is used if the function needs its' own copy

This PR leaves several instances of &Arc<Bank> around; these instances
are situations where a clone may only happen conditionally.
2023-08-18 16:46:34 -05:00
Pankaj Garg a1a0829a8b
Initialize and store PRv2 environment in cache (#32812)
* Initialize and store PRv2 environment in cache

* address review comments
2023-08-11 18:58:22 +00:00
Alexander Meißner 9731331be4
Bump solana_rbpf to v0.6.0 (#32313) 2023-07-05 19:46:21 +02:00
Alexander Meißner 83f692ce67
Refactor - Share RBPF config and syscall registry globally (#31727)
* Adds LoadedPrograms::program_runtime_environment_v1.

* No need to explicitly remove precompiles from program_accounts_map.
2023-05-20 20:28:00 +02:00
Alexander Meißner 5c8b5a2a68
Bump solana_rbpf to v0.4.0 (#31594)
* Moves "disable_deploy_of_alloc_free_syscall" parameter inside create_loader().

* Removes the "is_abi_v2" flag.

* Bumps solana_rbpf to v0.4.0
2023-05-12 18:07:13 +02:00
Pankaj Garg cc24d2207c
Update SBF bench to account for delay visibility (#31501) 2023-05-04 17:17:02 -07:00
Alessandro Decina 117a194b73
Account data direct mapping (#28053)
* AccountSharedData: make data_mut() private

This ensures that the inner Vec is never handed out. This is in
preparation of enforcing that the capacity of the inner vec never
shrinks, which is required for direct mapping.

* Adds the feature bpf_account_data_direct_mapping.

* Remaps EbpfError::AccessViolation into InstructionError::ReadonlyDataModified.

* WIP: Memory regions for each instruction account in create_vm().

* Fix serialization benches, run both copy and !copy variants

* rbpf-cli: fix build

* BorrowedAccount: ensure that account capacity is never reduced

Accounts can be directly mapped in address space. Their capacity can't
be reduced mid transaction as that would create holes in vm address
space that point to invalid host memory.

* bpf_load: run serialization tests for both copy and !copy account data

* bpf_loader: add Serializer::write_account

* fix lints

* BorrowedAccount: make_data_mut is host only

* Fix unused import warning

* Fix lints

* cpi: add explicit direct_mapping arg to update_(callee|caller)_account

* cpi: rename account_data_or_only_realloc_padding to serialized_data

* cpi: add CallerAccount::original_data_len comment

* cpi: add update_callee_account direct_mapping test

* cpi: add test_update_caller_account_data_direct_mapping and fix bug

We used to have a bug in zeroing data when shrinking account, where we zeroed
the spare account capacity but not the realloc padding.

* cpi: add tests for mutated readonly accounts

* cpi: update_caller_account doesn't need to change .serialized_data when direct_mapping is on

* cpi: update_caller_account: ensure that account capacity is always enough

Introduce a better way to ensure that account capacity never goes below what
might be mapped in memory regions.

* cpi: zero account capacity using the newly introduced BorrowedAccount::spare_data_capacity_mut()

Before we were using BorrowedAccount::get_data_mut() to get the base pointer to
the account data, then we were slicing the spare capacity from it. Calling
get_data_mut() doesn't work if an account has been closed tho, since the
current program doesn't own the account anymore and therefore get_data_mut()
errors out.

* bpf_loader: fix same lint for the umpteenth time

* bpf_loader: map AccessViolation to ReadonlyDataModified only for account region violations

* programs/sbf: realloc: add test for large write after realloc

Add a test that after a realloc does a large write that spans the
original account length and the realloc area. This ensures that memory
mapping works correctly across the boundary.

* programs/sbf: run test_program_sbf_realloc with both direct_mapping on and off

By default test banks test with all features on. This ensures we keep
testing the existing code until the new feature is enabled.

* bpf_loader: tweak memcmp syscall

Split the actual memcmp code in a separate function. Remove check
indexing the slices since the slices are guaranteed to have the correct
length by construction.

* bpf_loader: tweak the memset syscall

Use slice::fill, which is effectively memset.

* bpf_loader: syscalls: update mem syscalls to work with non contiguous memory

With direct mapping enabled, accounts can now span multiple memory
regions.

* fix lint, rebase mem_ops

* Implement CoW for writable accounts

* Fix CI

* Move CoW to the MemoryMapping level

* Update after rbpf API change

* Fix merge screwup

* Add create_vm macro. Fix benches.

* cpi: simplify update_caller_account

Simplify the logic to update a caller's memory region when a callee
causes an account data pointer to change (eg during CoW)

* benches/bpf_loader: move serialization out of  create_vm bench

* benches/bpf_loader: don't copy accounts when direct mapping is on

* Fix review nits

* bpf_loader: mem_ops: handle u64 overflow in MemoryChunkIterator::new

When starting at u64::MAX, the chunk iterator would always return the
empty sequence (None on the first next()) call, instead of returning a
memory access violation.

Use checked instead of saturating arithmetic to detect the condition and
error out.

This commit also adds more tests around boundary conditions.

* Fix loader-v3 tests: data_mut => data_as_mut_slice

* Fix CI

* bpf_loader: fix tuner bench: account must be writable

With direct mapping on, invalid writes are caught early meaning the
tuner would fail on the first store and not consume the whole budget
like the benchmark expects.

---------

Co-authored-by: Alexander Meißner <AlexanderMeissner@gmx.net>
2023-04-29 06:54:39 +10:00
Alexander Meißner c05d1d5c51
Refactor - Moves bpf_loader registration into the runtime (#31345)
* Moves the registration of bpf_loader built-ins from the ledger into the runtime.

* Removes bpf_loader built-ins registration in tests and benchmarks.

* Removes declare_builtin!() of bpf_loader built-ins.

* Removes built-ins from the SDK.

* Adjusts tests.
2023-04-26 14:44:19 +02:00
Alexander Meißner 8eb31f6cfd
Refactor - Syscalls in RBPF CLI (#31109)
* Makes members of SyscallContext public.
Removes check_aligned and check_size from SyscallContext.

* Replaces InvokeContext::set_syscall_context() in tests with mock_create_vm!().

* Passes SyscallContext directly to InvokeContext::set_syscall_context().

* Merges TraceLogStackFrame into SyscallContext.

* Removes the create_vm!() macro.

* Moves BpfAllocator from bpf_loader into program_runtime.

* Frees BpfAllocator from Rc<RefCell<>>.

* Removes unused code from BpfAllocator.

* Consume CUs for heap before doing the allocation.

* Exposes syscalls in rbpf-cli.

* Adds debugging_features parameter to load_program_from_bytes() and load_program_from_account().

* Removes test_bpf_loader_non_terminating_program() as that is already tested in RBPF.

* Moves stack and heap allocation back onto the program runtime stack.
2023-04-14 15:20:08 +02:00
Alexander Meißner a0c7fde90e
Cleanup - mock InvokeContext (#31007)
* Turns with_mock_invoke_context() into a macro.

* Removes prepare_mock_invoke_context().

* Replaces InvokeContext::new_mock() with with_mock_invoke_context().

* Removes InvokeContext::new_mock().

* Removes Cow from InvokeContext::sysvar_cache.

* Removes override parameters from mock_process_instruction().

* cargo fmt
2023-04-03 17:23:24 +02:00
Tao Zhu 17ba051e1f
Revert "add default_cost as mandatory field for Builtin (#30639)" (#30749)
This reverts commit 7b95c8e698.
2023-03-16 11:21:06 -05:00
Ryo Onodera 7f58345dad
ci: test-checks.sh all sbf code & use nightly only (#30602) 2023-03-13 14:28:34 +09:00
Tao Zhu 7b95c8e698
add default_cost as mandatory field for Builtin (#30639)
* add default_cost as mandatory field for Builtin

* updated tests

* set zkp program default to VerifyTransfer CUs

---------

Co-authored-by: Jon Cinque <joncinque@pm.me>
2023-03-10 14:02:24 -06:00
Alessandro Decina 0335ea7249
Bump solana_rbpf to v0.2.40 (#30668)
Update to solana_rbpf v0.2.40
2023-03-10 19:05:29 +01:00
Alexander Meißner 9d1a0c52f8
Cleanup - `disable_deprecated_loader` (#29653)
* Removes the gating of disable_deprecated_loader.

* Adds create_program().
Renames create_deprecated_program() -> load_program().
Renames load_and_finalize_deprecated_program() -> load_and_finalize_program().

* Fixes test_sol_alloc_free_no_longer_deployable().
2023-01-14 13:02:10 +01:00
Alexander Meißner ab97d37e3d
Refactor - Simplify loader utils (#29699)
* Moves all the common code of tests and benches into loader utils.

* Removes write_sbf_program().

* Removes ignored test: test_program_sbf_test_use_latest_executor2().
2023-01-13 20:38:36 +01:00
Alexander Meißner 013f784e92
Bump solana_rbpf to v0.2.38 (#29137)
* Refactor register_syscalls() => create_loader().

* Bumps solana_rbpf to v0.2.38

* Replaces Config::encrypt_environment_registers by Config::runtime_environment_key.

* Adds pc parameter to MemoryMapping::map()

* Removes debugger from rbpf CLI.

* Adds debugger to rbpf CLI again.

* Renames vm.context_object => vm.env.context_object_pointer.

* Renames SyscallRegistry => BuiltInProgram.
Renames SyscallFunction => BuiltInFunction.
Renames register_syscall_by_name() => register_function_by_name().

* Removes ContextObject from Analysis.

* Renames Config::error_on_syscall_bpf_function_hash_collisions => Config::external_internal_function_hash_collision.
2022-12-12 08:47:09 +01:00
Alexander Meißner ff1ff587d1
Bump solana_rbpf to 0.2.36 (#28794)
* Bumps solana_rbpf to v0.2.36

* Removes ThisInstructionMeter.

* Removes one "unsafe" expression.

* Removes redundant call to solana_rbpf:🧝:register_bpf_function().

* Adjusts SyscallFunction and SyscallRegistry.

* Inlines ProgramEnvironment into EbpfVm.

* Refactors trait SyscallConsume into fn consume_compute_meter().

* Inlines ComputeMeter into InvokeContext.

* Removes solana-metrics dependency from bpf_loader.

* Replaces RBPF tracer functionality by the debugger.

* Take compute_units_consumed from execute_program().

* Merges execute_program_interpreted() and execute_program_jit().
2022-11-15 15:21:11 +01:00
Brooks Prumo 4d6653598b
Upgrades to Rust 1.65.0 (#28741) 2022-11-09 17:15:03 -05:00
Alexander Meißner 547f07526b
Refactor - create_executor() to be usable outside of bpf_loader (#28369)
* Moves disable_deploy_of_alloc_free_syscall parameter inside create_executor().

* Lets register_syscalls() take &FeatureSet only instead of the entire InvokeContext.

* Uses ic_logger_msg!() instead of ic_msg!() inside create_executor().
Inlines map_ebpf_error().

* Adds register_syscalls_us to executor_metrics::CreateMetrics.

* Moves timings accumulation into executor_metrics::CreateMetrics::submit_datapoint().

* Moves &invoke_context.feature_set into a variable.

* Lets create_executor() return executor_metrics::CreateMetrics via a mutable parameter.

* Dissolves invoke_context parameter in create_executor().

* Pulls assignment of create_executor_metrics.program_id outside of create_executor().

* Makes create_executor() take a byte slice instead of a BorrowedAccount.

* Adds create_executor_from_account().
2022-10-18 10:22:39 +02:00
Dmitri Makarov d6813b98d2 chore: move programs/bpf to programs/sbf 2022-10-13 11:40:40 -04:00