Skip to content

Commit 8656d0b

Browse files
authored
plumb abiv2 and dm in syscall and ix harnesses (#374)
* remove outdated comments * wire up ABIv2 feature * wire up direct mapping and remove toggling
1 parent 3a3aae4 commit 8656d0b

File tree

4 files changed

+24
-45
lines changed

4 files changed

+24
-45
lines changed

src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,6 @@ static SUPPORTED_FEATURES: &[u64] = feature_list![
313313
account_data_direct_mapping,
314314
];
315315

316-
// If `TOGGLE_DIRECT_MAPPING=1` is set, the direct mapping feature will be inverted, testing with and without direct mapping.
317-
// In solfuzz, this can be done by copying the shared object and configuring the environment variable in one target e.g. `TARGET0_TOGGLE_DIRECT_MAPPING=1`.
318-
static mut TOGGLE_DIRECT_MAPPING: bool = false;
319-
320316
// If the `CORE_BPF_PROGRAM_ID` variable is set, declares the default compute
321317
// units used by the program's builtin version.
322318
//
@@ -1040,9 +1036,6 @@ impl TryFrom<proto::AcctState> for (Pubkey, Account) {
10401036
pub unsafe extern "C" fn sol_compat_init(_log_level: i32) {
10411037
env::set_var("SOLANA_RAYON_THREADS", "1");
10421038
env::set_var("RAYON_NUM_THREADS", "1");
1043-
if env::var("TOGGLE_DIRECT_MAPPING").is_ok() {
1044-
TOGGLE_DIRECT_MAPPING = true;
1045-
}
10461039
if env::var("ENABLE_SOLANA_LOGGER").is_ok() {
10471040
/* Pairs with RUST_LOG={trace,debug,info,etc} */
10481041
solana_logger::setup();

src/txn_fuzzer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::proto::{AcctState, TxnContext, TxnResult};
33
use crate::utils::program::common::{
44
build_versioned_message, get_dummy_bpf_native_programs, get_sysvar,
55
};
6-
// use crate::TOGGLE_DIRECT_MAPPING;
76
use agave_feature_set::*;
87
use agave_precompiles::get_precompile;
98
use ahash::AHashSet;

src/vm_interp.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
err_map,
55
vm::{mem_regions, HEAP_MAX, STACK_SIZE},
66
},
7-
InstrContext, TOGGLE_DIRECT_MAPPING,
7+
InstrContext,
88
};
99
// feature removed from feature set surface in 3.0; direct mapping toggled via SVMFeatureSet flags
1010
use bincode::Error;
@@ -189,12 +189,10 @@ pub fn execute_vm_interp(syscall_context: SyscallContext) -> Option<SyscallEffec
189189
.transaction_context
190190
.find_index_of_account(&instr_ctx.instruction.program_id)?;
191191

192-
let mut direct_mapping = false;
193-
unsafe {
194-
if TOGGLE_DIRECT_MAPPING {
195-
direct_mapping = !direct_mapping;
196-
}
197-
}
192+
let direct_mapping = invoke_ctx.get_feature_set().account_data_direct_mapping;
193+
let stricter_abi_and_runtime_constraints = invoke_ctx
194+
.get_feature_set()
195+
.stricter_abi_and_runtime_constraints;
198196
let mask_out_rent_epoch_in_vm_serialization = invoke_ctx
199197
.get_feature_set()
200198
.mask_out_rent_epoch_in_vm_serialization;
@@ -217,7 +215,7 @@ pub fn execute_vm_interp(syscall_context: SyscallContext) -> Option<SyscallEffec
217215
.unwrap();
218216
let (_aligned_memory, input_memory_regions, acc_metadatas) = serialize_parameters(
219217
&caller_instr_ctx,
220-
false,
218+
stricter_abi_and_runtime_constraints,
221219
direct_mapping,
222220
mask_out_rent_epoch_in_vm_serialization,
223221
)
@@ -315,7 +313,7 @@ pub fn execute_vm_interp(syscall_context: SyscallContext) -> Option<SyscallEffec
315313
sbpf_version,
316314
invoke_ctx
317315
.transaction_context
318-
.access_violation_handler(false, direct_mapping),
316+
.access_violation_handler(stricter_abi_and_runtime_constraints, direct_mapping),
319317
) else {
320318
return None;
321319
};

src/vm_syscalls.rs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
utils::vm::mem_regions,
55
utils::vm::HEAP_MAX,
66
utils::vm::STACK_SIZE,
7-
InstrContext, TOGGLE_DIRECT_MAPPING,
7+
InstrContext,
88
};
99
use prost::Message;
1010
use solana_compute_budget::compute_budget::SVMTransactionExecutionCost;
@@ -149,12 +149,10 @@ pub fn execute_vm_syscall(input: SyscallContext) -> Option<SyscallEffects> {
149149
// TransactionContext::configure_next_instruction_for_tests() crashes if program_idx > 255
150150
return None;
151151
}
152-
let mut direct_mapping = false;
153-
unsafe {
154-
if TOGGLE_DIRECT_MAPPING {
155-
direct_mapping = !direct_mapping;
156-
}
157-
};
152+
let direct_mapping = invoke_ctx.get_feature_set().account_data_direct_mapping;
153+
let stricter_abi_and_runtime_constraints = invoke_ctx
154+
.get_feature_set()
155+
.stricter_abi_and_runtime_constraints;
158156
let mask_out_rent_epoch_in_vm_serialization = invoke_ctx
159157
.get_feature_set()
160158
.mask_out_rent_epoch_in_vm_serialization;
@@ -183,9 +181,18 @@ pub fn execute_vm_syscall(input: SyscallContext) -> Option<SyscallEffects> {
183181
.transaction_context
184182
.get_current_instruction_context()
185183
.unwrap();
184+
// Memory regions.
185+
// In Agave all memory regions are AlignedMemory::<HOST_ALIGN> == AlignedMemory::<16>,
186+
// i.e. they're all 16-byte aligned in the host.
187+
// The memory regions are:
188+
// 1. program rodata
189+
// 2. stack
190+
// 3. heap
191+
// 4. input data aka accounts
192+
// The stack gap size is 0 iff direct mapping is enabled.
186193
let (_aligned_memory, input_memory_regions, acc_metadatas) = serialize_parameters(
187194
&caller_instr_ctx,
188-
false,
195+
stricter_abi_and_runtime_constraints,
189196
direct_mapping,
190197
mask_out_rent_epoch_in_vm_serialization,
191198
)
@@ -209,24 +216,6 @@ pub fn execute_vm_syscall(input: SyscallContext) -> Option<SyscallEffects> {
209216
return None;
210217
}
211218

212-
// Memory regions.
213-
// In Agave all memory regions are AlignedMemory::<HOST_ALIGN> == AlignedMemory::<16>,
214-
// i.e. they're all 16-byte aligned in the host.
215-
// The memory regions are:
216-
// 1. program rodata
217-
// 2. stack
218-
// 3. heap
219-
// 4. input data aka accounts
220-
// The stack gap is size is 0 iff direct mapping is enabled.
221-
// There's some extra quirks:
222-
// - heap size is MIN_HEAP_FRAME_BYTES..=MAX_HEAP_FRAME_BYTES
223-
// - input data (at least when direct mapping is off) is 1 single map of all
224-
// serialized accounts (and each account is serialized to a multiple of 16 bytes)
225-
// In this implementation, however:
226-
// - heap can be smaller than MIN_HEAP_FRAME_BYTES
227-
// - input data is made of multiple regions, and regions don't necessarily have
228-
// length multiple of 16, i.e. virtual addresses may be unaligned
229-
// These differences allow us to test more edge cases.
230219
let mut invoke_ctx = invoke_context.borrow_mut();
231220
let config = invoke_ctx
232221
.program_cache_for_tx_batch
@@ -286,7 +275,7 @@ pub fn execute_vm_syscall(input: SyscallContext) -> Option<SyscallEffects> {
286275
sbpf_version,
287276
invoke_ctx
288277
.transaction_context
289-
.access_violation_handler(false, direct_mapping),
278+
.access_violation_handler(stricter_abi_and_runtime_constraints, direct_mapping),
290279
) else {
291280
cleanup_static_ptrs(
292281
transaction_context_ptr,
@@ -301,7 +290,7 @@ pub fn execute_vm_syscall(input: SyscallContext) -> Option<SyscallEffects> {
301290
invoke_ctx
302291
.set_syscall_context(solana_program_runtime::invoke_context::SyscallContext {
303292
allocator: solana_program_runtime::invoke_context::BpfAllocator::new(vm_ctx.heap_max),
304-
accounts_metadata: acc_metadatas, // TODO: accounts metadata for direct mapping support
293+
accounts_metadata: acc_metadatas,
305294
trace_log: Vec::new(),
306295
})
307296
.unwrap();

0 commit comments

Comments
 (0)