Commit Graph

718 Commits

Author SHA1 Message Date
Brooks aaf3a91a95
Removes redundant imports (#193) 2024-03-12 14:25:59 +08:00
Lucas Steuernagel 85cfe23b46
Add tests for `svm/transaction_processor.rs` (#112) 2024-03-07 12:26:31 -03:00
Alexander Meißner d472725a12
Cleanup - `disable_bpf_loader_instructions` (#35164)
* Cleans up disable_bpf_loader_instructions.

* fix test_program_sbf_disguised_as_sbf_loader

* remove bpf loader execute bench

* Revert "remove bpf loader execute bench"

This reverts commit f3042ee3e1d6e0208df7d7f80f61e14294f108a8.

* move test utility functions out of test file

* update bench to loader v3

* clippy

* fix dev-context build

* fix dev-context import

* dev-context-util

* move dev-context-util attr to module level for loader_utils

---------

Co-authored-by: HaoranYi <haoran.yi@solana.com>
2024-02-15 13:46:00 +01:00
Justin Starry 2d09e4965e
clean feature: enable_bpf_loader_extend_program_ix (#35194) 2024-02-14 18:33:20 +08:00
Alexander Meißner 070a5a36b8
Cleanup - Removes `LoadedProgram::maybe_expiration_slot` (#35023)
Removes LoadedProgram::maybe_expiration_slot.
2024-02-07 01:38:21 +00:00
Alexander Meißner 8e5cf13352
Cleanup - feature gate of `stop_truncating_strings_in_syscalls` (#34842)
Cleanup feature gate of stop_truncating_strings_in_syscalls.
2024-01-19 15:28:45 +01:00
Alexander Meißner 9d132441fd
Cleanup - feature gate of `remove_bpf_loader_incorrect_program_id` (#34843)
Cleanup feature gate of remove_bpf_loader_incorrect_program_id.
2024-01-19 09:07:41 +01:00
Alexander Meißner b5b829111c
Cleanup - feature gate of `stop_sibling_instruction_search_at_parent` (#34841)
Cleanup feature gate of stop_sibling_instruction_search_at_parent.
2024-01-19 09:07:30 +01:00
samkim-crypto 73218595c6
[zk-token-sdk] Restrict Edwards and Ristretto multiscalar multiplication vector length to at most 512 (#34763)
* restrict curve25519 multiscalar multiplication vector length to 512

* add syscall tests for msm vector length

* add new feature gate `curve25519_restrict_msm_length`

* update tests for feature new gate

* Update programs/bpf_loader/src/syscalls/mod.rs

Co-authored-by: Trent Nelson <trent.a.b.nelson@gmail.com>

* remove length guard on the multisicalar mult lib function

---------

Co-authored-by: Trent Nelson <trent.a.b.nelson@gmail.com>
2024-01-19 08:40:42 +09:00
Tao Zhu 51eaa2b9cc
cleanup feature code after activation (#34695)
cleanup feature checking code
2024-01-12 14:28:50 -06:00
Alessandro Decina 917e242e7f
bpf_loader: fix clippy::blocks_in_conditions lint (#34643)
See https://github.com/solana-labs/solana/issues/34626
2024-01-04 11:58:10 +11:00
HaoranYi 5a3a10e847
Deprecate account meta executable read/update in bpf loaders (#34194)
* use PROGRAM_OWNER + program data for account executable

mock account data with executable_meta in precompiled program and update
test_bank_hash_consistency test

pr: return const slice and add comments

pr: use ReadableAccount

use const to get rid of magic number

add featuregate disable_bpf_loader_instructions to disable bpf loader management instructions, and deprecate_executable_meta_update_in_bpf_loader to deprecate executable flag update in bpf loader

deprecate usage of executable in Account

fix a test

fix sbp bench

fix sbf program tests

add feature gate to account and borrowed account apis

fix tests

more test fixes

* restore bpf_loader v2 tests

---------

Co-authored-by: HaoranYi <haoran.yi@solana.com>
2024-01-03 15:11:48 -06:00
HaoranYi 531d69fd10
pass feature_set to BorrowedAccount (#34542)
Co-authored-by: HaoranYi <haoran.yi@solana.com>
2023-12-21 20:03:17 +01:00
Pankaj Garg 6f0133bd43
Improve cache eviction policy for LoadedPrograms (#34391)
* Use 2's random selection to evict program cache

* implement decaying of usage counter

* replace RwLock with AtomicU64

* address review comments

* remove -> swap_remove
2023-12-18 14:51:36 -08:00
Tao Zhu d836cf175e
cleanup feature code after activated everywhere (#34408) 2023-12-13 09:15:29 -06:00
Andrew Fitzgerald 2294801954
Do not derive Copy for EpochSchedule and Rent (#32767) 2023-12-01 07:57:25 -08:00
Alessandro Decina a0df9def91
direct_mapping: disable stack frame gaps (#34254)
Gaps don't work with direct mapping which assumes a 1:1 mapping between virtual
and host addresses.
2023-11-29 09:54:48 +11:00
Alessandro Decina 09088822e7
direct_mapping: fix iter_memory_pair_chunks in reverse mode (#34204)
iter_memory_pair_chunks was iterating regions in reverse, but not memory
_within_ regions in reverse.

This commit fixes the issue and simplifies the implementation by removing
nested loops which made control flow hard to reason about.
2023-11-28 08:46:20 +11:00
Alessandro Decina d9147d7a77
cpi: direct_mapping: always zero spare capacity if account alloc changes (#34141)
If the vector holding an account is reallocated during execution of a callee,
we must zero the spare capacity regardless of whether the account size changed,
because the underlying vector might contain uninitialized memory in the spare
capacity.
2023-11-20 23:07:35 +11:00
Alexander Meißner f349d71605
Cleanup - Feature gate of `disable_cpi_setting_executable_and_rent_epoch` (#34086)
Cleans up feature gate of disable_cpi_setting_executable_and_rent_epoch.
2023-11-16 10:02:56 +01:00
Justin Starry 2573b7acc9
clean feature: libsecp256k1_0_5_upgrade_enabled (#34080) 2023-11-16 09:59:53 +08:00
Alexander Meißner 061883ebce
Cleanup - Feature gate of `enable_program_redeployment_cooldown` (#34088)
Cleans up feature gate of enable_program_redeployment_cooldown.
2023-11-15 23:15:14 +01:00
Alexander Meißner 7ea4b2dbf7
Cleanup - Feature gate of `move_serialized_len_ptr_in_cpi` (#34082)
Cleans up feature gate of move_serialized_len_ptr_in_cpi.
2023-11-15 20:58:30 +01:00
Alexander Meißner b168cadeea
Cleanup - Feature gate of `check_slice_translation_size` (#34084)
Cleans up feature gate of check_slice_translation_size.
2023-11-15 20:58:10 +01:00
Alexander Meißner ffa462dd3a
Cleanup - Feature gate of `delay_visibility_of_program_deployment` (#34087)
* Cleans up feature gate of delay_visibility_of_program_deployment.

* Removes programs_updated_only_for_global_cache.
2023-11-15 18:29:31 +01:00
Alexander Meißner d93280c287
Cleanup - Feature gate of `limit_max_instruction_trace_length` (#34085)
Cleans up feature gate of limit_max_instruction_trace_length.
2023-11-15 17:51:10 +01:00
Alessandro Decina d009d7304a
cpi: fix capacity check in update_caller_account (#34064)
reserve(additional) reserves additional bytes on top of the current _length_
not capacity. Before this fix we could potentially reserve less capacity than
required.
2023-11-15 22:42:12 +11:00
Brooks 725ab37bf4
clippy: Replaces .get(0) with .first() (#34048) 2023-11-13 17:22:17 -05:00
Alexander Meißner a5c7c999e2
Bump solana_rbpf to v0.8.0 (#33679)
* Bumps solana_rbpf to v0.8.0

* Adjustments:
Replaces declare_syscall!() with declare_builtin_function!().
Removes Config::encrypt_runtime_environment.
Simplifies error propagation.
2023-10-20 21:39:50 +02:00
Brooks c1353e172c
Removes cap_accounts_data_allocations_per_transaction featurization (#33754) 2023-10-19 07:01:15 -04:00
Justin Starry 3bfa0d291a
feature flag cleanup: cap_bpf_program_instruction_accounts (#33746) 2023-10-19 08:15:35 +08:00
Sanjay Singh a60d1857bf
updated inner_call for hashing fn to follow generic approach (#33128)
* updated inner_call for hashing fn to follow generic approach

* different hash compute budget values for all digests

* fixed conflicts

* reverted changes to compute_budget.rs and added 3method to trait to get compute budget values

* updated type for result fn for HasherImpl

* using Hash directly in result fn, got rid of HASH_BYTES and removed comment form compute_budget

* updated import statement

* cargo fmt -all

* removed unused import and reference related warning

* oops forgot semicolon

* removed trailing white space
2023-10-13 14:53:19 -06:00
Alexander Meißner cb695c7b32
Cleanup - Feature Gate of `enable_early_verification_of_account_modifications` (#33579)
Cleans up the feature gate of enable_early_verification_of_account_modifications:
- Removes PreAccount
- Removes InvokeContext::pre_accounts and InvokeContext::rent
- Removes InvokeContext::verify() and InvokeContext::verify_and_update()
- Removes TransactionContext::is_early_verification_of_account_modifications_enabled()
- Removes TransactionAccounts::is_early_verification_of_account_modifications_enabled
- No longer optional: TransactionContext::rent
2023-10-10 17:26:17 +02:00
Alexander Meißner 1262ff7589
Fix - CPI interface `bool` masking (#33623)
Adds masking of booleans in CPI interface to disable_cpi_setting_executable_and_rent_epoch.
2023-10-10 16:09:12 +02:00
Alexander Meißner 01c71e7555
Reloads deployments with `environments.program_runtime_v1` (#33412)
Reloads deployments with environments.program_runtime_v1.
2023-09-26 20:43:41 +02:00
Tao Zhu 57e78a16dc
heap_size type to be consistent with request instruction (#33354)
* heap_size type to be consistent with request instruction

* update tests
2023-09-25 13:11:26 -05:00
Alexander Meißner 7ff797bcef
Refactor - Remove parameter `feature_set` from `load_program_from_bytes()` (#33395)
Replaces parameter feature_set with delay_visibility_of_program_deployment in load_program_from_bytes().
2023-09-25 17:16:31 +02:00
ananas-block 997aa0a3f8
Feat(syscall): add altbn128 g1 & g2 compression (#32870)
* solana-program - altbn128: add g1 & g2 compression

still fixing tests for point of infinity

feat: proof compression syscall working

add rust test to ci

remove prints

added c test

added sycall pricing

* fixed ci checks

* refactored altbn128 and compression
2023-09-25 05:43:34 -07:00
Tao Zhu a2ad820309
compute_budget heap_size does not have to be optional (#33313) 2023-09-21 09:24:47 -05:00
Christian Kamm 525e59f01a
sdk, programs/bpf_loader: add sol_remaining_compute_units syscall (#31640)
bpf_loader: add sol_remaining_compute_units syscall

Co-authored-by: jonch <9093549+jon-chuang@users.noreply.github.com>
2023-09-13 08:57:08 -06:00
Pankaj Garg 5562f79cc5
Do not unnecessarily re-verify unloaded program (#32722)
* Do not unnecessarily re-verify unloaded program

* clippy fixes

* new unit test for extract

* fixes after rebase

* fixes after rebase

* address review comments

* fix clippy
2023-09-13 06:25:56 -07:00
Alexander Meißner 424666e341
Bump solana_rbpf to v0.7.0 (#33104)
* Upgrades RBPF in Cargo.toml

* Adjustments to updated interfaces.
2023-09-06 10:54:15 +02:00
Alexander Meißner 05622c17da
Refactor - Minor fixes in the error handling of executing tombstones (#33145)
Minor fixes in the error handling of executing tombstones.
2023-09-05 23:57:25 +02:00
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
behzad nouri 4ec5ea6f7b
replaces assert!(matches!(...)) with assert_matches!(...) (#33068)
assert_matches!(...) provides more informative error message when it
fails and it is part of nightly rust:
https://doc.rust-lang.org/std/assert_matches/macro.assert_matches.html
2023-08-30 13:48:27 -04:00
vadorovsky e6dc3dac45
feat(sbf): Add Poseidon syscall (#32680)
Computing Poseidon[0] hashes is too expensive to be done in a Solana
program in one transaction. Poseidon is a zero-knowlege proof friendly
hash function, used by the majority of ZK-based projects, including the
ones built on top of Solana.

This change introduces the `sol_poseidon` syscall which takes 2D byte
slice as an input and then calculates a Poseidon hash using a BN254
curve and the following Poseidon parameters:

* x^5 S-boxes
* width - 2 ≤ t ≤ 13
* inputs - 1 ≤ n ≤ 12
* 8 full rounds and partial rounds depending on t: [56, 57, 56, 60, 60,
  63, 64, 63, 60, 66, 60, 65]

Computation of Poseidon hashes is done with the light-poseidon[1]
crate, which is audited[2] and compatible with Circom[3] (BN254 curve,
the same parameters and constants).

Proposed compute costs depend on number of inputs and are based on
light-poseidon benchmarks[4].

[0] https://www.poseidon-hash.info/
[1] https://crates.io/crates/light-poseidon
[2] https://github.com/Lightprotocol/light-poseidon/blob/main/assets/audit.pdf
[3] https://docs.circom.io/
[4] https://github.com/Lightprotocol/light-poseidon/tree/main#performance
2023-08-30 09:43:31 -07:00
Alessandro Decina 0f41719918
direct mapping: misc fixes (#32649)
* transaction_context: update make_data_mut comment

* bpf_loader: cpi: pass SerializeAccountMetadata to CallerAccount::from*

We now have a way to provide CallerAccount with trusted values coming
from our internal serialization code and not from untrusted vm space

* bpf_loader: direct_mapping: enforce account info pointers to be immutable

When direct mapping is enabled, we might need to update account data
memory regions across CPI calls. Since the only way we have to retrieve
the regions is based on their vm addresses, we enforce vm addresses to
be stable.  Accounts can still be mutated and resized of course, but it
must be done in place.

This also locks all other AccountInfo pointers, since there's no legitimate
reason to make them point to anything else.

* bpf_loader: cpi: access ref_to_len_in_vm through VmValue

Direct mapping needs to translate vm values at each access since
permissions of the underlying memory might have changed.

* direct mapping: improve memory permission tracking across CPI calls

Ensure that the data and realloc regions of an account always track the
account's permissions. In order to do this, we also need to split
realloc regions in their own self contained regions, where before we
had:

[account fields][account data][account realloc + more account fields + next account fields][next account data][...]

we now have:

[account fields][account data][account realloc][more account fields + next account fields][next account data][...]

Tested in TEST_[FORBID|ALLOW]_WRITE_AFTER_OWNERSHIP_CHANGE*

Additionally when direct mapping is on, we must update all perms at once before
doing account data updates. Otherwise, updating an account might write into
another account whose perms we haven't updated yet. Tested in
TEST_FORBID_LEN_UPDATE_AFTER_OWNERSHIP_CHANGE.

* bpf_loader: serialization: address review comment don't return vm_addr from push_account_region

* bpf_loader: rename push_account_region to push_account_data_region

* cpi: fix slow edge case zeroing extra account capacity after shrinking an account

When returning from CPI we need to zero all the account memory up to the
original length only if we know we're potentially dealing with uninitialized
memory.

When we know that the spare capacity has deterministic content, we only need to
zero new_len..prev_len.

This fixes a slow edge case that was triggerable by the following scenario:

- load a large account (say 10MB) into the vm
- shrink to 10 bytes - would memset 10..10MB
- shrink to 9 bytes - would memset 9..10MB
- shrink to 8 bytes - would memset 8..10MB
- ...

Now instead in the scenario above the following will happen:

- load a large account (say 10MB) into the vm
- shrink to 10 bytes - memsets 10..10MB
- shrink to 9 bytes - memsets 9..10
- shrink to 8 bytes - memset 8..9
- ...

* bpf_loader: add account_data_region_memory_state helper

Shared between serialization and CPI to figure out the MemoryState of an
account.

* cpi: direct_mapping: error out if ref_to_len_in_vm points to account memory

If ref_to_len_in_vm is allowed to be in account memory, calles could mutate it,
essentially letting callees directly mutate callers memory.

* bpf_loader: direct_mapping: map AccessViolation -> InstructionError

Return the proper ReadonlyDataModified / ExecutableDataModified /
ExternalAccountDataModified depending on where the violation occurs

* bpf_loader: cpi: remove unnecessary infallible slice::get call
2023-08-30 16:57:24 +07:00
Alexander Meißner 150a798d32
Fix - Upcoming `arithmetic_side_effects` lints (#33000)
* dereplicode address alignment check

* Uses `checked_div` and `checked_rem` in built-in loaders.

* Uses `checked_div` and `checked_rem`.

* sdk: replace sub() with saturating_sub()

* eliminate `String` "arithmetic"

* allow arithmetic side-effects in tests and benches and on types we don't control

---------

Co-authored-by: Trent Nelson <trent@solana.com>
2023-08-29 20:58:53 +02:00
Alexander Meißner 67d6d688cc
Refactor - Demotes `Arc` to `Rc`. (#32982)
Demotes `Arc` to `Rc`.
2023-08-25 00:54:06 +02:00
Alexander Meißner a8be70fa7a
General cleanup (#32980)
* Fixes `cargo::` in build.rs

* Fixes overshadowing reexports.

* Removes unnecessary `as *const u8`.

* Removes unnecessary `.into_iter()`.

* cargo clippy
2023-08-24 21:44:19 +02:00