Skip to content

v2.2: Add SBPFv1 tests to the CI pipeline (backport of #5126) #6344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v2.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ci/test-stable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ test-stable-sbf)
# Install the platform tools
_ platform-tools-sdk/sbf/scripts/install.sh

# SBF program tests
# SBPFv0 program tests
_ make -C programs/sbf test-v0

# SBPFv1 program tests
_ make -C programs/sbf clean-all test-v1

exit 0
;;
test-docs)
Expand Down
18 changes: 16 additions & 2 deletions programs/sbf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@ SBF_SDK_PATH := ../../platform-tools-sdk/sbf
SRC_DIR := c/src
OUT_DIR := target/deploy

test-v0: all rust-v0
clean-all: clean
cargo clean

test:
SBF_OUT_DIR=$(OUT_DIR) cargo test --features="sbf_rust,sbf_c" $(TEST_ARGS)

test-v1:
SBPF_CPU=v1 $(MAKE) all ; \
$(MAKE) rust-v1 ; \
$(MAKE) test

test-v0: all rust-v0 test

rust-v0:
cargo +solana build --release --target sbpf-solana-solana --workspace ; \
cp -r target/sbpf-solana-solana/release/* target/deploy

.PHONY: rust
rust-v1:
cargo +solana build --release --target sbpfv1-solana-solana --workspace --features dynamic-frames ; \
cp -r target/sbpfv1-solana-solana/release/* target/deploy

.PHONY: rust-v0

include $(SBF_SDK_PATH)/c/sbf.mk
3 changes: 3 additions & 0 deletions programs/sbf/rust/invoke/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ crate-type = ["cdylib"]

[lints]
workspace = true

[features]
dynamic-frames = []
25 changes: 22 additions & 3 deletions programs/sbf/rust/invoke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#![allow(unreachable_code)]
#![allow(clippy::arithmetic_side_effects)]

#[cfg(feature = "dynamic-frames")]
use solana_program::program_memory::sol_memcmp;
use {
solana_program::{
account_info::AccountInfo,
Expand Down Expand Up @@ -1456,19 +1458,36 @@ fn process_instruction<'a>(
heap[8..pos].fill(42);

// Check that the stack is zeroed too.
//
let stack = unsafe {
slice::from_raw_parts_mut(
MM_STACK_START as *mut u8,
MAX_CALL_DEPTH * STACK_FRAME_SIZE,
)
};

#[cfg(not(feature = "dynamic-frames"))]
// We don't know in which frame we are now, so we skip a few (10) frames at the start
// which might have been used by the current call stack. We check that the memory for
// the 10..MAX_CALL_DEPTH frames is zeroed. Then we write a sentinel value, and in the
// next nested invocation check that it's been zeroed.
let stack =
unsafe { slice::from_raw_parts_mut(MM_STACK_START as *mut u8, 0x100000000) };
//
// When we don't have dynamic stack frames, the stack grows from lower addresses
// to higher addresses, so we compare accordingly.
for i in 10..MAX_CALL_DEPTH {
let stack = &mut stack[i * STACK_FRAME_SIZE..][..STACK_FRAME_SIZE];
assert!(stack == &ZEROS[..STACK_FRAME_SIZE], "stack not zeroed");
stack.fill(42);
}

#[cfg(feature = "dynamic-frames")]
// When we have dynamic frames, the stack grows from the higher addresses, so we
// compare from zero until the beginning of a function frame.
{
const ZEROED_BYTES_LENGTH: usize = (MAX_CALL_DEPTH - 2) * STACK_FRAME_SIZE;
assert_eq!(sol_memcmp(stack, &ZEROS, ZEROED_BYTES_LENGTH), 0);
stack[..ZEROED_BYTES_LENGTH].fill(42);
}

// Recurse to check that the stack and heap are zeroed.
//
// We recurse until we go over max CPI depth and error out. Stack and heap allocations
Expand Down
Loading