Commit Graph

749 Commits

Author SHA1 Message Date
mergify[bot] a829deae22
v2.0: SIMD-0118: fix `total_rewards` for recalculation (backport of #2780) (#2794)
* SIMD-0118: fix `total_rewards` for recalculation (#2780)

* Add new feature key

* Wrap existing code with new feature

* Extend test harness

* Make test fail

* Populate EpochRewards::total_rewards from PointValue

* Remove superfluous struct field

* Fixup tests

(cherry picked from commit 4470f6d96e)

# Conflicts:
#	programs/bpf_loader/src/syscalls/mod.rs
#	sdk/src/feature_set.rs

* Fix conflicts

---------

Co-authored-by: Tyera <tyera@anza.xyz>
2024-09-03 10:31:12 -06:00
Sammy Harris a9e3917082
Fix SyscallLogPubkey doc comment (#1805)
* Fix SyscallLogPubkey doc comment

* Update logging.rs
2024-06-20 11:22:16 -06:00
Alessandro Decina 2107adcf35
bpf_loader: use an explicit thread-local pool for stack and heap memory (#1370)
* Rename ComputeBudget::max_invoke_stack_height to max_instruction_stack_depth

The new name is consistent with the existing
ComputeBudget::max_instruction_trace_length.

Also expose compute_budget:MAX_INSTRUCTION_DEPTH.

* bpf_loader: use an explicit thread-local pool for stack and heap memory

Use a fixed thread-local pool to hold stack and heap memory. This
mitigates the long standing issue of jemalloc causing TLB shootdowns to
serve such frequent large allocations.

Because we need 1 stack and 1 heap region per instruction, and the
current max instruction nesting is hardcoded to 5, the pre-allocated
size is (MAX_STACK + MAX_HEAP) * 5 * NUM_THREADS. With the current
limits that's about 2.5MB per thread. Note that this is memory that
would eventually get allocated anyway, we're just pre-allocating it now.

* programs/sbf: add test for stack/heap zeroing

Add TEST_STACK_HEAP_ZEROED which tests that stack and heap regions are
zeroed across reuse from the memory pool.
2024-06-20 08:57:11 +07:00
Sean Young cd7f34ecfc
Ensure mapping of callee is updated with direct mapping (#1093)
Consider this scenario:

 - Program increases length of an account
 - Program start CPI and adds this account as a read-only account
 - In fn update_callee_account() we resize account, which may change
   the pointer
 - Once CPI finishes, the program continues and may read/write from
   the account. The mapping must be up-to-date else we use stale
   pointers.

Note that we always call callee_account.set_data_length(), which
may change the pointer. In testing I found that resizing a vector
from 10240 down to 127 sometimes changes its pointer. So, always
update the pointer.
2024-06-18 10:13:00 +01:00
Kevin Heavey b855bd0c54
Extract curve25519 crate from zk-token-sdk (#951)
* extract curve25519 crate

* remove obsolete comment

* fix Cargo.toml files

* fix imports

* update lock file

* remove unused deps from zk-token-sdk

* fmt

* add solana-curve25519 patch

* add missing override to programs/sbf/Cargo.toml

* copy over an allow()

* move new crate to curves dir

* use workspace version

* add back missing dev dep

* add missing dependencies to programs/sbf

* fmt

* move dep to the correct dependency table

* remove #[cfg(not(target_os = "solana"))] above errors mod
2024-06-18 14:08:57 +09:00
Lucas Ste ebd063eb79
Add Shuttle multithreading test infrastructure (#1634) 2024-06-17 19:24:43 -03:00
Joe C 3af8f0cfdb
Program Runtime: Unify transaction batch program caches (#1399)
* local program cache: add `modified_entries` field

* use `modified_entries` for modified program cache

* invoke context: make `program_cache_for_tx_batch` mutable

* invoke context: unify local program cache instances

* remove `find_program_in_cache` alias
2024-06-17 17:08:13 -05:00
Kevin Heavey 7e0688341e
remove superfluous usage of allow(dead_code) (#1669) 2024-06-13 22:52:49 +08:00
Joe C b1508010c0
Syscall: `GetEpochStake` (#1152)
* SVM: add `get_vote_accounts` callback

* program-runtime: invoke context: add `vote_accounts`

* sdk: add feature gate for sol-get-epoch-stake

* syscall: get-epoch-stake

* syscall: get-epoch-stake: tests

* drop `get_compute_meter`

* refactor for total stake

* refactor API for total stake
2024-06-11 09:28:31 -05:00
Alexander Meißner 475e918c18
Refactor - `SyscallInvokeSignedRust::translate_instruction()` (#1644)
* Reorders all translate_slice() to the beginning of SyscallInvokeSignedRust::translate_instruction().

* Uses the host slice instead the guest one.

* Reorders consume_compute_meter() to happen before heap allocation.
2024-06-11 10:20:57 +02:00
Joe C 62eb4cc068
Add Compute Budget Crate (#1121) 2024-06-01 01:38:19 -05:00
Alexander Meißner 6455a2a249
Fix - `ExecuteDetailsTimings::execute_us` (#1499)
Explicitly stops and restarts the execution timer during CPI
2024-05-31 10:25:06 +02:00
Kevin Heavey f954fba969
Extract solana-poseidon crate from solana-program (#999)
* extract solana-poseidon crate

* update imports and lock files

* remove now-unused light-poseidon dep from program crate

* add missing posiedon dep when target_os = "solana"

* set solana-poseidon version to 2.0.0

* sort workspace members

* use workspace version in Cargo.toml

Co-authored-by: Joe C <joecaulfield29@yahoo.com>

* move syscall definition to solana-poseidon crate

Co-authored-by: Joe C <joecaulfield29@yahoo.com>

* finish moving sol_poseidon defn to solana-poseidon crate

* update imports in examples

---------

Co-authored-by: Joe C <joecaulfield29@yahoo.com>
2024-05-30 13:34:23 -05:00
Yihau Chen 9a487a7630
test: remove unsafe call from mock_signers (#1431) 2024-05-24 18:09:43 +08:00
Yihau Chen 8f9fc2ada2
clippy: missing_transmute_annotations (#1343)
* clippy: missing_transmute_annotations

* Revert "clippy: missing_transmute_annotations"

This reverts commit 01b5fe5dabd8e8c860c8173840429204c4cca3b0.

* update types

* update types

* update types

* update types

* feedback

* add one more missing type

* Revert "feedback"

This reverts commit 420ee23489fe71b1b33a413e084d46204d7b8c9e.

* update types
2024-05-18 01:03:17 +08:00
hana d8e9da5b5d
implement SyscallGetSysvar (#1307)
generic mechanism to fetch arbitrary slices of account data for a specially selected list of sysvars
2024-05-16 15:08:15 -07:00
Yihau Chen ec9bd79849
clippy: fix legacy_numeric_constants (#1314)
clippy: legacy_numeric_constants
2024-05-15 11:29:19 +08:00
hana e3b55cf5ce
Rework SysvarCache implementation (#560)
program-runtime: modify sysvar cache impl

in prep for sol_sysvar_get, rework how SysvarCache stores data internally
we store account data directly, except also storing StakeHistory and SlotHashes as objects
these object representations can be removed after native programs are converted to bpf
2024-05-13 08:41:11 -07:00
Yihau Chen 9aebd8d7f6
remove unused TestContextObject (#1245) 2024-05-08 23:33:07 +08:00
Yihau Chen 3138baab18
clippy: allow dead_code for SerializeAccount (#1247) 2024-05-08 23:32:57 +08:00
Alessandro Decina f180b08873
Reduce deserialization allocations/copies (#1197)
* AccountSharedData::reserve: remove extra alloc + memcpy

Calling data_mut().reserve(additional) used to result in _two_ allocs
and memcpys: the first to unshare the underlying vector, and the second
upon calling reserve since Arc::make_mut clones so it uses capacity ==
len.

With this fix we manually "unshare" allocating with capacity = len +
additional, therefore saving on extra alloc and memcpy.

* AccountSharedData::set_data_from_slice: skip extra alloc + memcpy

We used call make_data_mut() from set_data_from_slice() from the days
when direct mapping couldn't deal with accounts getting shrunk. That
changed in https://github.com/solana-labs/solana/pull/32649 (see the
if callee_account.capacity() < min_capacity check in
cpi.rs:update_caller_account()).

With this change we don't call make_data_mut() anymore before
set_data_from_slice(), saving the cost of a memcpy since
set_data_from_slice() overrides the whole account content anyway.
2024-05-07 19:55:04 +08:00
Joe C 34b76ac580
Program-Runtime: Add `EnvironmentConfig` to `InvokeContext` (#1059)
* program-runtime: add `EnvironmentConfig` to `InvokeContext`

* move `blockhash` to `EnvironmentConfig`

* move `lamports_per_signature` to `EnvironmentConfig`

* move `feature_set` to `EnvironmentConfig`

* move `sysvar_cache` to `EnvironmentConfig`

* add `get_feature_set` getter
2024-05-01 15:22:43 -05:00
samkim-crypto 5b3390b99a
[SIMD-0137]: Return `SyscallError::InvalidAttribute` on invalid curve or op id on curve25519 syscalls (#412) 2024-04-30 07:34:34 +09:00
samkim-crypto 3e3b16c0c6
[syscalls] Clean-up curve25519 msm length feature gate check (#1066) 2024-04-27 06:08:49 +09:00
Alexander Meißner e43338f3d6
Refactor - Rename `LoadedProgram` to `ProgramCacheEntry` (#880)
LoadedProgramOwner => ProgramCacheEntryOwner.
LoadedProgramType => ProgramCacheEntryType.
LoadedProgram => ProgramCacheEntry.
LoadedProgramStats => ProgramCacheStats.
LoadedProgramMatchCriteria => ProgramCacheMatchCriteria.
LoadedProgramsForTxBatch => ProgramCacheForTxBatch.
2024-04-18 21:38:08 +02:00
Alexander Meißner ac36dbbc87
Refactor - `LoadedProgramType::Loaded` and `LoadedProgramOwner` (#606)
* Adds LoadedProgram::account_owner() and LoadedProgramOwner.
Merges LoadedProgramTypes LegacyV0, LegacyV1, Typed and TestLoaded into Loaded.

* Review feedback.
2024-04-17 17:48:14 +02:00
Emanuele Cesena 64260fc831
Simd 129: alt_bn128 syscalls - simplified error code (#294)
* alt_bn128: simplify errors in sycalls (alt_bn128, compress, poseidon)

* add TODO for feature gate. remove validate from compress

* add feature gate

* fix one more error case

* all changes under feature gate

* revert removing from()

* return unexpected errors in lib

* add comment to remove error types, once the feature gate is activated

* remove unnecessary/impossible error

* fix mispelled comments
2024-04-03 09:09:54 +09:00
Joe C 3f17532b11
Runtime: Core BPF Migration: Path to migrate a builtin to Core BPF (#408)
* runtime: core_bpf_migration: add migration path

* runtime: core_bpf_migration: add tests for migration path

* comments

* function name

* rent lamports

* bank operations ordering

* make migration method a bank method

* update deployment slot to current slot

* invoke loader deploy directly
2024-04-01 16:30:23 -05:00
Tyera ecb4f62887
Simd 118: extend EpochRewards sysvar (#428)
* Update EpochRewards sysvar

* Update Clone trait

* Update doctests

* Update bank to new sysvar fields

* Update runtime tests

* Update syscall test

* Update tests

* Clean up doctest EpochRewards construction
2024-03-27 19:24:06 -06:00
Pankaj Garg 91b1ee3df6
Fix: deploy program on last slot of epoch during environment change (#101)
* Fix: deploy program on last slot of epoch during environment change

* solana-runtime: deploy at last epoch slot test

* disable deployment of sol_alloc_free

* Move tx-batch-constructor to its own function

* use new_from_cache

---------

Co-authored-by: Alessandro Decina <alessandro.d@gmail.com>
2024-03-22 07:43:28 -07:00
HaoranYi 0f8f8cd970
Revert deprecate executable feature (#309)
* revert deprecate executable feature

* add native loader account transfer test

---------

Co-authored-by: HaoranYi <haoran.yi@solana.com>
2024-03-20 10:54:15 -05:00
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