From bcaf7a8f6c9d93f32736879f68e4bae9eb876e3e Mon Sep 17 00:00:00 2001 From: Lucas Steuernagel <38472950+LucasSte@users.noreply.github.com> Date: Fri, 22 Mar 2024 20:26:46 -0300 Subject: [PATCH] Sysvar example (#399) --- .../example-programs/clock-sysvar/Cargo.toml | 12 ++ .../clock-sysvar/clock_sysvar_program.so | Bin 0 -> 44168 bytes .../example-programs/clock-sysvar/src/lib.rs | 18 +++ svm/tests/integration_test.rs | 111 +++++++++++++++++- 4 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 svm/tests/example-programs/clock-sysvar/Cargo.toml create mode 100755 svm/tests/example-programs/clock-sysvar/clock_sysvar_program.so create mode 100644 svm/tests/example-programs/clock-sysvar/src/lib.rs diff --git a/svm/tests/example-programs/clock-sysvar/Cargo.toml b/svm/tests/example-programs/clock-sysvar/Cargo.toml new file mode 100644 index 0000000000..082c29bbfe --- /dev/null +++ b/svm/tests/example-programs/clock-sysvar/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "clock-sysvar-program" +version = "2.0.0" +edition = "2021" + +[dependencies] +solana-program = { path = "../../../../sdk/program", version = "=2.0.0" } + +[lib] +crate-type = ["cdylib", "rlib"] + +[workspace] \ No newline at end of file diff --git a/svm/tests/example-programs/clock-sysvar/clock_sysvar_program.so b/svm/tests/example-programs/clock-sysvar/clock_sysvar_program.so new file mode 100755 index 0000000000000000000000000000000000000000..dee43a1e38b28684312760f0b81203605ae79c6c GIT binary patch literal 44168 zcmeHw3wTu5b?!Mcb2K9%81Wbo0-+I4Au}L>UdYA<+t@%HBLib$8;k~NEM(AggvIgP z#3PJt?9_?;i0wE{iZC|BX=9wW!Fe=8+Sn%PO-$}>5|TEJlFw*&l8*pBbl@5}wZZkyR>?Y;KeYp=c5+Rt-z&-xp#^O>e0!EgN90JJv9DQk7chUfJI zMQe=)BS63TMo8gWlor(_ym8OHTux%6h+&}T(Z8WX4141X(>PsXcewy%H9W=n-uTQ^ zPM289`6wCn9e$GYz41v-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0y1JTn(A(hF{(zum<@_}$}y4}0Jt5B!t|KH`DTdf*Wce6BQ? zzflj|RF<2+#{+LK&&|(x;3M;M^Ur%=V_|OoSv{W>`JAiG&EHd(3$NAlL&0xo$ju*F zmkV##^C!VS?SVr(a`7`ebKxpIKa%pHmfZXi4}9*9-28?+bKxNmoYC_cp`X$78G+Ax z;3_@8ko*=8Jmi62((?hquhQecz^Bu>{8j1kRPtLq@HxFcL_U_*JudwMeBjVHJuHof zT=sya>sgmQV5z$2-f?_o%FFwc2l|cWZ8k1fQLIjnlKYnTbsNk3D5ea~wL4Xu=5eQ9s9wBi9gzXC6@-fN-?^6EolZ-6!NnKXjC*@_&Y7yn5t9=?z_U$B= zeKeE@pHjY9 ProgramResult { + + let time_now = Clock::get().unwrap().unix_timestamp; + let return_data = time_now.to_be_bytes(); + set_return_data(&return_data); + Ok(()) +} diff --git a/svm/tests/integration_test.rs b/svm/tests/integration_test.rs index b414281267..e435ce0939 100644 --- a/svm/tests/integration_test.rs +++ b/svm/tests/integration_test.rs @@ -3,7 +3,8 @@ use { crate::mock_bank::MockBankCallback, solana_bpf_loader_program::syscalls::{ - SyscallAbort, SyscallInvokeSignedRust, SyscallLog, SyscallMemcpy, SyscallMemset, + SyscallAbort, SyscallGetClockSysvar, SyscallInvokeSignedRust, SyscallLog, SyscallMemcpy, + SyscallMemset, SyscallSetReturnData, }, solana_program_runtime::{ compute_budget::ComputeBudget, @@ -21,7 +22,7 @@ use { solana_sdk::{ account::{AccountSharedData, ReadableAccount, WritableAccount}, bpf_loader, - clock::{Epoch, Slot}, + clock::{Clock, Epoch, Slot, UnixTimestamp}, epoch_schedule::EpochSchedule, fee::FeeStructure, hash::Hash, @@ -30,12 +31,15 @@ use { native_loader, pubkey::Pubkey, signature::Signature, + sysvar::SysvarId, transaction::{SanitizedTransaction, Transaction}, }, solana_svm::{ account_loader::TransactionCheckResult, transaction_error_metrics::TransactionErrorMetrics, - transaction_processor::{ExecutionRecordingConfig, TransactionBatchProcessor}, + transaction_processor::{ + ExecutionRecordingConfig, TransactionBatchProcessor, TransactionProcessingCallback, + }, }, std::{ cmp::Ordering, @@ -43,6 +47,7 @@ use { fs::{self, File}, io::Read, sync::{Arc, RwLock}, + time::{SystemTime, UNIX_EPOCH}, }, }; @@ -115,6 +120,14 @@ fn create_custom_environment<'a>() -> BuiltinProgram> { .register_function_hashed(*b"sol_invoke_signed_rust", SyscallInvokeSignedRust::vm) .expect("Registration failed"); + function_registry + .register_function_hashed(*b"sol_set_return_data", SyscallSetReturnData::vm) + .expect("Registration failed"); + + function_registry + .register_function_hashed(*b"sol_get_clock_sysvar", SyscallGetClockSysvar::vm) + .expect("Registration failed"); + BuiltinProgram::new_loader(vm_config, function_registry) } @@ -172,6 +185,25 @@ fn create_executable_environment( program_cache.fork_graph = Some(Arc::new(RwLock::new(MockForkGraph {}))); + // We must fill in the sysvar cache entries + let time_now = SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("Time went backwards") + .as_secs() as i64; + let clock = Clock { + slot: DEPLOYMENT_SLOT, + epoch_start_timestamp: time_now.saturating_sub(10) as UnixTimestamp, + epoch: DEPLOYMENT_EPOCH, + leader_schedule_epoch: DEPLOYMENT_EPOCH, + unix_timestamp: time_now as UnixTimestamp, + }; + + let mut account_data = AccountSharedData::default(); + account_data.set_data(bincode::serialize(&clock).unwrap()); + mock_bank + .account_shared_data + .insert(Clock::id(), account_data); + // Inform SVM of the registered builins let registered_built_ins = vec![bpf_loader::id(), solana_system_program::id()]; (program_cache, registered_built_ins) @@ -319,8 +351,53 @@ fn prepare_transactions( // The program account is set in `create_executable_environment` + // A program that utilizes a Sysvar + let program_account = Pubkey::new_unique(); + let fee_payer = Pubkey::new_unique(); + let message = Message { + account_keys: vec![fee_payer, program_account], + header: MessageHeader { + num_required_signatures: 1, + num_readonly_signed_accounts: 0, + num_readonly_unsigned_accounts: 0, + }, + instructions: vec![CompiledInstruction { + program_id_index: 1, + accounts: vec![], + data: vec![], + }], + recent_blockhash: Hash::default(), + }; + + let transaction = Transaction { + signatures: vec![Signature::new_unique()], + message, + }; + let sanitized_transaction = + SanitizedTransaction::try_from_legacy_transaction(transaction).unwrap(); + all_transactions.push(sanitized_transaction); + transaction_checks.push((Ok(()), None, Some(20))); + + let mut account_data = AccountSharedData::default(); + account_data.set_lamports(80000); + mock_bank + .account_shared_data + .insert(fee_payer, account_data); + + let buffer = load_program("clock-sysvar".to_string()); + + // The program account must have funds and hold the executable binary + let mut account_data = AccountSharedData::default(); + // The executable account owner must be one of the loaders. + account_data.set_owner(bpf_loader::id()); + account_data.set_data(buffer); + account_data.set_executable(true); + account_data.set_lamports(25); + mock_bank + .account_shared_data + .insert(program_account, account_data); + // TODO: Include these examples as well: - // An example with a sysvar // A transaction that fails // A transaction whose verification has already failed @@ -342,10 +419,21 @@ fn svm_integration() { program_cache.clone(), ); + // The sysvars must be put in the cache + batch_processor + .sysvar_cache + .write() + .unwrap() + .fill_missing_entries(|pubkey, callback| { + if let Some(account) = mock_bank.get_account_shared_data(pubkey) { + callback(account.data()); + } + }); + let mut error_counter = TransactionErrorMetrics::default(); let recording_config = ExecutionRecordingConfig { enable_log_recording: true, - enable_return_data_recording: false, + enable_return_data_recording: true, enable_cpi_recording: false, }; let mut timings = ExecuteTimings::default(); @@ -363,7 +451,7 @@ fn svm_integration() { false, ); - assert_eq!(result.execution_results.len(), 2); + assert_eq!(result.execution_results.len(), 3); assert!(result.execution_results[0] .details() .unwrap() @@ -394,4 +482,15 @@ fn svm_integration() { .find(|key| key.0 == recipient_key) .unwrap(); assert_eq!(recipient_data.1.lamports(), 900010); + + let return_data = result.execution_results[2] + .details() + .unwrap() + .return_data + .as_ref() + .unwrap(); + let time = i64::from_be_bytes(return_data.data[0..8].try_into().unwrap()); + let clock_data = mock_bank.get_account_shared_data(&Clock::id()).unwrap(); + let clock_info: Clock = bincode::deserialize(clock_data.data()).unwrap(); + assert_eq!(clock_info.unix_timestamp, time); }