Commit Graph

49 Commits

Author SHA1 Message Date
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
Alessandro Decina f6fee4ac3a
Serialization refactor (#28251)
* Use infallible, unchecked methods to write into the serialization buffer

We serialize in two steps: first we compute the size of the buffer, then
we write into it. Therefore there's no need to check if each individual
write fits the buffer - we know it does we just computed the required
size.

* serialize_parameters: remove extra loop/borrows

Remove one extra loop over accounts to gather account lengths. Also
gather all accounts at once and avoid temporary borrows.

* Move creating MemoryRegions for serialized parameters from create_vm to serialize_parameters

This is in preparation of using multiple MemoryRegions once we land direct account mapping.

* bpf_loader: introduce internal API to build serialization buffer/regions

This is prep work for landing the direct_mapping feature, which maps account
data in their own memory regions.

* serialization: fix after API changes
2022-10-07 07:45:05 +01:00
Alexander Meißner 30b0a13ba9
Bump solana_rbpf to 0.2.34 (#28198)
* Bumps solana_rbpf to 0.2.34

* Removes generic UserError from EbpfError.

* Uses ProgramResult for syscalls.
Removes use sites of the question_mark! macro by wrapping the call method of SyscallObjects.

* Uses InvokeContext as syscall context object directly.

* Replaces bind_syscall_context_object() by a parameter in the constructor.

* Inlines bind_syscall_context_objects() at its only call site.
2022-10-06 20:31:58 +02:00
behzad nouri 9a57c64f21
patches clippy errors from new rust nightly release (#27996) 2022-09-22 22:23:03 +00:00
Alexander Meißner 0b94d5af18
Refactor: `InstructionContext::configure()` (#27400)
* Replaces InstructionContext::new() by InstructionContext::configure().
Adds TransactionContext::get_next_instruction_context().

* Switch back to using references as parameters.

* Hoists InstructionContext::configure() from TransactionContext::push() into InvokeContext::push().

* Moves InstructionContext::config() to the beginning of InvokeContext::push().

* Hoists InstructionContext::configure() from InvokeContext::push() into InvokeContext::process_instruction().

* Review feedback: Updates docu comments.
2022-09-03 10:34:57 +02:00
Richard Patel 2fc888d864 rbpf-cli: capture log 2022-07-31 15:55:15 -07:00
Justin Starry f8e9af5f1e
Cap the number of accounts passed to a bpf program ix (#26630)
* Cap the number of accounts passed to a bpf program ix

* update bank abi hash

* fix ci failures
2022-07-20 14:12:43 +02:00
Alexander Meißner 038da82b6f
Feature: Early verification of account modifications in `BorrowedAccount` (#25899)
* Adjusts test cases for stricter requirements.

* Removes account reset in deserialization test.

* Removes verify related test cases.

* Replicates account modification verification logic of PreAccount in BorrowedAccount.

* Adds TransactionContext::account_touched_flags.

* Adds account modification verification to the BPF ABIv0 and ABIv1 deserialization, CPI syscall and program-test.

* Replicates the total sum of all lamports verification of PreAccounts in InstructionContext

* Check that the callers instruction balance is maintained during a call / push.

* Replicates PreAccount statistics in TransactionContext.

* Disable verify() and verify_and_update() if the feature enable_early_verification_of_account_modifications is enabled.

* Moves Option<Rent> of enable_early_verification_of_account_modifications into TransactionContext::new().

* Relaxes AccountDataMeter related test cases.

* Don't touch the account if nothing changes.

* Adds two tests to trigger InstructionError::UnbalancedInstruction.

Co-authored-by: Justin Starry <justin@solana.com>
2022-07-15 09:31:34 +02:00
Brooks Prumo 78b8a8a6db
Remove `get_total_resize_remaining()` and `total_resize_limit` from `TransactionContext` (#26504) 2022-07-08 20:26:54 +02:00
Alexander Meißner 06ebfa1eb2
Replicates `AccountsDataMeter` in `TransactionContext` (#26438)
Replicates AccountsDataMeter in TransactionContext.
2022-07-06 19:27:42 +02:00
Jack May 363d8d1539
Bump rBPF (#25593) 2022-06-07 04:45:07 -07:00
Dmitri Makarov 108795755b Revert "rbpf-cli: add coverage flag"
This reverts commit 506ee0014a.
2022-05-22 06:38:07 -07:00
Jack May 851958f77a
Disallow deployment of deprecated _sol_alloc_free syscall (#25179) 2022-05-20 13:19:41 -07:00
Jack May 83c0dd3637
Fix alignment check (#25351) 2022-05-19 15:14:28 -07:00
Jack May 8902a66b20
Revert "Disallow deployment of deprecated _sol_alloc_free syscall (#24986)" (#25170)
This reverts commit 8f1d4c1665.
2022-05-12 17:58:17 -05:00
Jack May 8f1d4c1665
Disallow deployment of deprecated _sol_alloc_free syscall (#24986)
* Disallow deployment of deprecated _sol_alloc_free syscall

* remove cli argument
2022-05-11 05:22:49 +00:00
Alexander Meißner 7f987722bf
Bump solana_rbpf to v0.2.28 (#24800) 2022-04-30 10:58:12 +02:00
Jack May 224e0b27a1
Simplify register and bind (#24724)
* Revert "Bumps solana_rbpf to v0.2.27 (#24694)"

This reverts commit f3d27cc400.

* Simplify syscall register and bind (#24546)

* declare syscalls with macro (#24564)
2022-04-28 10:24:42 +02:00
Richard Patel 506ee0014a rbpf-cli: add coverage flag
- adds DWARF parser using gimli
- adds coverage module to derive an execution trace to line numbers
- adds a gcov module to export a coverage profile to gcov intermediate JSON format
- add basic CLI logger
2022-04-26 10:03:13 -07:00
Alexander Meißner f3d27cc400
Bumps solana_rbpf to v0.2.27 (#24694) 2022-04-26 17:58:55 +02:00
Jack May 8a754d45b3
Singlular syscall context (#24204) 2022-04-11 16:05:09 -07:00
klykov cc55684f5f update clap to v3: rbpf-cli 2022-03-09 17:53:06 +01:00
Richard Patel 56e23432b0
rbpf-cli: only run static analysis when needed (#23110) 2022-02-16 02:35:05 +00:00
Richard Patel bf689303d4 rbpf-cli: support json output 2022-02-15 11:44:33 -08:00
dependabot[bot] 66b44b48a4
chore: remove time dep (#22665)
* chore: bump time from 0.3.5 to 0.3.6

Bumps [time](https://github.com/time-rs/time) from 0.3.5 to 0.3.6.
- [Release notes](https://github.com/time-rs/time/releases)
- [Changelog](https://github.com/time-rs/time/blob/main/CHANGELOG.md)
- [Commits](https://github.com/time-rs/time/compare/v0.3.5...v0.3.6)

---
updated-dependencies:
- dependency-name: time
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Remove separate time dependency

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tyera Eulberg <tyera@solana.com>
2022-01-25 16:30:21 -07:00
Alexander Meißner b448472037
Refactor: Move `InstructionRecorder` into `TransactionContext` (#22578)
* Moves InstructionRecorder into TransactionContext.

* Adds assertions for number_of_instructions_at_transaction_level.
2022-01-19 22:40:09 +01:00
Alexander Meißner 73e6038986
Refactor: Remove `KeyedAccount` from program runtime (#22226)
* Makes error handling in BorrowedAccount optional.
Adds BorrowedAccount ::get_rent_epoch().
Exposes InstructionContext::get_index_in_transaction().
Turns accounts and account_keys into pinned boxed slices.

* Introduces "unsafe" to InvokeContext::push().

* Turns &TransactionContext into &mut TransactionContext in InvokeContext.

* Push and pop InstructionContext in InvokeContext.
Makes test_process_cross_program and test_native_invoke symmetric.
Removes the borrow check from test_invoke_context_verify.

* Removes keyed_accounts from prepare_instruction()

* Removes usage of invoke_stack.

* Removes keyed_accounts from program-test.

* Removes caller_write_privileges.

* Removes keyed_accounts from BPF parameter (de-)serialization.
2022-01-03 23:30:56 +01:00
Alexander Meißner edb20d6909
Splits index of InstructionAccount into index_in_transaction and index_in_caller. (#22165) 2021-12-30 15:46:36 +01:00
Alexander Meißner a06646631c
Feature: TransactionContext, InstructionContext and BorrowedAccount (#21706)
* Adds TransactionContext, InstructionContext and BorrowedAccount.

* Redirects the usage of accounts in InvokeContext through TransactionContext.
Also use the types declared in transaction_context.rs everywhere.

* Adjusts all affected tests.
2021-12-27 18:49:32 +01:00
Alexander Meißner 2ab4f34c02
Refactor: Remove `Message` and `CompiledInstruction` from `InvokeContext` interfaces (#22102)
* Introduces InstructionAccount which is like AccountMeta but uses an index instead of a Pubkey

* Renames InvokeContext::create_message() to InvokeContext::prepare_instruction()

* Removes Message and CompiledInstruction from InvokeContext interfaces.

* Resolves TODOs of sol_invoke_signed() in program-test.

* Moves CompiledInstruction::visit_each_account() into invoke_context.rs
2021-12-24 16:17:55 +01:00
Alexander Meißner 66fa8f9667
Refactor: Removes `Rc` from `Refcell<AccountSharedData>` in the program-runtime (#21927)
* Removes Rc from Rc<RefCell<AccountSharedData>> in the program-runtime.

* Adjusts tests in bpf_loader, system_instruction_processor, config_processor, vote_instruction and stake_instruction
2021-12-17 14:01:12 +01:00
Jack May 509bcd2e74
Bump rbpf to v0.2.19 (#21880)
* Bump rbpf to v0.2.19

Co-authored-by: Alexander Meißner <AlexanderMeissner@gmx.net>
2021-12-14 16:51:23 +01:00
Alexander Meißner 1df88837c8
- Implicitly fixes invoke_context.return_data not being reset between instructions in process_message. (#21671)
- Lets InvokeContext::process_cross_program_instruction() handle the first invocation depth too.
- Marks InvokeContext::verify(), InvokeContext::verify_and_update() and InvokeContext::process_executable_chain() private.
- Renames InvokeContext::process_cross_program_instruction() to InvokeContext::process_instruction().
- Removes InvokeContext::new_mock_with_sysvars().
2021-12-07 23:00:04 +01:00
Michael Vines b8837c04ec Reformat imports to a consistent style for imports
rustfmt.toml configuration:
  imports_granularity = "One"
  group_imports = "One"
2021-12-03 09:19:13 -08:00
Alexander Meißner 015250f96c
Feature gates for rbpf v0.2.16 (#21590)
- Adds feature reject_section_virtual_address_file_offset_mismatch.
- Adds feature start_verify_shift32_imm.
- Enables enable_symbol_and_section_labels only in the rbpf-cli.
2021-12-03 15:45:25 +01:00
Alexander Meißner bfdb775ffc
Unifies ThisInvokeContext and dyn trait InvokeContext. (#21563) 2021-12-02 18:47:16 +01:00
Alexander Meißner 6330cbcf33
Refactor: Use InvokeContext in all Syscalls (#21545)
* Adds ComputeMeter::mock_set_remaining().

* Adds InvokeContext::get_loader()

* Adds a LogCollector to InvokeContext::new_mock().

* Adds "invoke_context: Rc<RefCell<&'a mut dyn InvokeContext>>,"
to all SyscallObjects.

* Adds LogCollector::get_recorded_content().

* Removes loader_id parameter from bind_syscall_context_objects() and create_vm().
2021-12-02 08:58:02 +01:00
Alexander Meißner c9aa7ed5ca
Bumps solana_rbpf to v0.2.16 (#21492) 2021-11-30 16:26:36 +01:00
Alexander Meißner e540b1cf3c
Refactor: Move sdk::process_instruction in program-runtime-crate (#21180)
* Moves the Executor dyn Trait to instruction_processor.rs

* Moves the Logger dyn Trait as well as the ic_msg and ic_logger_msg macros to log_collector.rs,
and moves the stable_log to stable_log.rs

* Moves the ComputeMeter dyn Trait to invoke_context.rs

* Moves the InvokeContext dyn Trait and the ProcessInstructionWithContext type to invoke_context.rs

* Updates cargo files.

* Re-export InvokeContext in program-test

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
2021-11-17 19:35:07 +01:00
Alexander Meißner 7200c5106e
Replaces MockInvokeContext by ThisInvokeContext in tests (#20881)
* Replaces MockInvokeContext by ThisInvokeContext in BpfLoader, SystemInstructionProcessor, CLIs, ConfigProcessor, StakeProcessor and VoteProcessor.

* Finally, removes MockInvokeContext, MockComputeMeter and MockLogger.

* Adjusts assert_instruction_count test.

* Moves ThisInvokeContext to the program-runtime crate.
2021-11-04 21:47:32 +01:00
Alexander Meißner f30f3bddbb
Refactor: Remove program_id from process_instruction() (#20540)
* Replaces usage of program_id parameter by invoke_context.get_caller()?.

* Removes "pubkey: &Pubkey" parameter from "process_instruction()".
2021-10-10 22:29:18 +02:00
Jack May 4e27543415
Allow programs to realloc their accounts within limits (#19475) 2021-09-28 01:13:03 -07:00
Alexander Meißner 36f46e1c31
CPI Account Reuse (#19762)
* Removes two account copy steps from InstructionProcessor::native_invoke().

* Moves gathering of keyed_accounts, caller_write_privileges and program_indices into InstructionProcessor::create_message().

* Explicitly routes the serialized account lengths to enable sharing of existing account structures.

* Recycles existing account structs in CPI syscall.
2021-09-18 08:09:47 +02:00
Alexander Meißner 0a63f65c03
Bumps solana_rbpf to v0.2.14 (#18869)
* Bumps solana_rbpf to v0.2.14

* Feature gate for verify_mul64_imm_nonzero as discussed in #17520.
2021-08-04 09:50:28 +02:00
Dmitri Makarov 9ed1f24188
Make jit mode default in rbpf-cli (#18671) 2021-07-14 20:30:38 +00:00
Dmitri Makarov 278a6917f9
Add vm execution time reporting to rbpf-cli (#18650) 2021-07-14 02:00:56 +00:00
Alexander Meißner 8d5c04e257
Bump solana_rbpf to version 0.2.13 (#18068)
* Moves syscall_registry into the rbpf Executable constructor.

* Adds the reject_unresolved_syscalls flag which is only set when deploying programs via the CLI.
2021-07-07 09:50:11 +02:00
Alexander Meißner 6514096a67 chore: cargo +nightly clippy --fix -Z unstable-options 2021-06-18 10:42:46 -07:00
Dmitri Makarov b8897df515
Add rbpf-cli tool (#17378)
* Add rbpf-cli tool

* Replace explicit file type specification by required positional arg

- the type of file is determined automatically.  If ELF magic found,
  the program file is considered to be an executable ELF file, and
  an assembly input file otherwise.

* Add a note about tool's limitations and input format description
2021-05-28 11:28:30 +00:00