Upgrade sbf tests to use bpf loader v3 (#34691)

* 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 <haoran.yi@solana.com>
This commit is contained in:
HaoranYi 2024-01-14 19:20:01 -05:00 committed by GitHub
parent f92275bcaa
commit 8869d0c8a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 277 additions and 447 deletions

View File

@ -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);
@ -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);

View File

@ -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));

View File

@ -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,
@ -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);

File diff suppressed because it is too large Load Diff