Skip to content

Commit

Permalink
Upgrade sbf tests to use bpf loader v3 (#34691)
Browse files Browse the repository at this point in the history
* update sbf test to use bpf_loader v2

* update test_program_sbf_invoke_sanity test

* update test bpf program owner

* update test_program_sbf_invoke_upgradeable_via_cpi

* update test_program_sbf_disguised_as_sbf_loader

* update test_program_reads_from_program_account

* update test_program_sbf_program_id_spoofing

* update test_program_sbf_caller_has_access_to_cpi_program

* update 3 more tests

* fix program buffer size in minimul for rent exempt calculation

* more test updates

* more update

* more test updates

* comments

* undo c format

* typo

* add sol_alloc_free not deployable and deployable tests

* comments

* review feedback - move buffer_keypair and program_keypair inside callee
fn.

* more refactor

* delete sof_alloc_free_syscall enabled tests

* revert lamport change

---------

Co-authored-by: HaoranYi <[email protected]>
(cherry picked from commit 8869d0c)

# Conflicts:
#	programs/sbf/tests/programs.rs
  • Loading branch information
HaoranYi authored and mergify[bot] committed Feb 9, 2024
1 parent 4ae690d commit 08dba4c
Show file tree
Hide file tree
Showing 4 changed files with 509 additions and 119 deletions.
11 changes: 6 additions & 5 deletions programs/sbf/c/src/invoked/invoked.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ extern uint64_t entrypoint(const uint8_t *input) {
static const int INVOKED_PROGRAM_DUP_INDEX = 3;
sol_assert(sol_deserialize(input, &params, 4));

SolPubkey sbf_loader_id =
(SolPubkey){.x = {2, 168, 246, 145, 78, 136, 161, 110, 57, 90, 225,
40, 148, 143, 250, 105, 86, 147, 55, 104, 24, 221,
71, 67, 82, 33, 243, 198, 0, 0, 0, 0}};
SolPubkey sbf_loader_upgradeable_id =
(SolPubkey){.x = {
2, 168, 246, 145, 78, 136, 161, 176, 226, 16, 21, 62,
247, 99, 174, 43, 0, 194, 185, 61, 22, 193, 36, 210, 192,
83, 122, 16, 4, 128, 0, 0}};

for (int i = 0; i < params.data_len; i++) {
sol_assert(params.data[i] == i);
Expand Down Expand Up @@ -63,7 +64,7 @@ extern uint64_t entrypoint(const uint8_t *input) {
sol_assert(
SolPubkey_same(accounts[INVOKED_PROGRAM_INDEX].key, params.program_id))
sol_assert(SolPubkey_same(accounts[INVOKED_PROGRAM_INDEX].owner,
&sbf_loader_id));
&sbf_loader_upgradeable_id));
sol_assert(!accounts[INVOKED_PROGRAM_INDEX].is_signer);
sol_assert(!accounts[INVOKED_PROGRAM_INDEX].is_writable);
sol_assert(accounts[INVOKED_PROGRAM_INDEX].rent_epoch == UINT64_MAX);
Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/c/src/read_program/read_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern uint64_t entrypoint(const uint8_t *input) {
return ERROR_INVALID_ARGUMENT;
}

char ka_data[] = {0x7F, 0x45, 0x4C, 0x46};
char ka_data[] = {0x02, 0x00, 0x00, 0x00};

sol_assert(params.ka_num == 1);
sol_assert(!sol_memcmp(params.ka[0].data, ka_data, 4));
Expand Down
7 changes: 5 additions & 2 deletions programs/sbf/rust/invoked/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
crate::instructions::*,
solana_program::{
account_info::AccountInfo,
bpf_loader,
bpf_loader_upgradeable,
entrypoint::{ProgramResult, MAX_PERMITTED_DATA_INCREASE},
log::sol_log_64,
msg,
Expand Down Expand Up @@ -70,7 +70,10 @@ fn process_instruction(
assert!(!accounts[INVOKED_ARGUMENT_INDEX].executable);

assert_eq!(accounts[INVOKED_PROGRAM_INDEX].key, program_id);
assert_eq!(accounts[INVOKED_PROGRAM_INDEX].owner, &bpf_loader::id());
assert_eq!(
accounts[INVOKED_PROGRAM_INDEX].owner,
&bpf_loader_upgradeable::id()
);
assert!(!accounts[INVOKED_PROGRAM_INDEX].is_signer);
assert!(!accounts[INVOKED_PROGRAM_INDEX].is_writable);
assert_eq!(accounts[INVOKED_PROGRAM_INDEX].rent_epoch, u64::MAX);
Expand Down
Loading

0 comments on commit 08dba4c

Please sign in to comment.