Skip to content

Commit 6564133

Browse files
committed
Add SBPFv1 tests to the CI pipeline (#5126)
* Add SBPFv1 to the CI pipeline * Tune instruction count * Check upper bound instead of fixed number of instructions * Verify zeroed stack with dynamic stack frames * Use constants to estimate length of zeroed bytes * Remove comment (cherry picked from commit b704875)
1 parent 7aff93a commit 6564133

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

ci/test-stable.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ test-stable-sbf)
5555
# Install the platform tools
5656
_ platform-tools-sdk/sbf/scripts/install.sh
5757

58-
# SBF program tests
58+
# SBPFv0 program tests
5959
_ make -C programs/sbf test-v0
6060

61+
# SBPFv1 program tests
62+
_ make -C programs/sbf clean-all test-v1
63+
6164
exit 0
6265
;;
6366
test-docs)

programs/sbf/Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@ SBF_SDK_PATH := ../../platform-tools-sdk/sbf
22
SRC_DIR := c/src
33
OUT_DIR := target/deploy
44

5-
test-v0: all rust-v0
5+
clean-all: clean
6+
cargo clean
7+
8+
test:
69
SBF_OUT_DIR=$(OUT_DIR) cargo test --features="sbf_rust,sbf_c" $(TEST_ARGS)
710

11+
test-v1:
12+
SBPF_CPU=v1 $(MAKE) all ; \
13+
$(MAKE) rust-v1 ; \
14+
$(MAKE) test
15+
16+
test-v0: all rust-v0 test
17+
818
rust-v0:
919
cargo +solana build --release --target sbpf-solana-solana --workspace ; \
1020
cp -r target/sbpf-solana-solana/release/* target/deploy
1121

12-
.PHONY: rust
22+
rust-v1:
23+
cargo +solana build --release --target sbpfv1-solana-solana --workspace --features dynamic-frames ; \
24+
cp -r target/sbpfv1-solana-solana/release/* target/deploy
25+
26+
.PHONY: rust-v0
1327

1428
include $(SBF_SDK_PATH)/c/sbf.mk

programs/sbf/rust/invoke/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ crate-type = ["cdylib"]
1919

2020
[lints]
2121
workspace = true
22+
23+
[features]
24+
dynamic-frames = []

programs/sbf/rust/invoke/src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#![allow(unreachable_code)]
44
#![allow(clippy::arithmetic_side_effects)]
55

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

14581460
// Check that the stack is zeroed too.
1459-
//
1461+
let stack = unsafe {
1462+
slice::from_raw_parts_mut(
1463+
MM_STACK_START as *mut u8,
1464+
MAX_CALL_DEPTH * STACK_FRAME_SIZE,
1465+
)
1466+
};
1467+
1468+
#[cfg(not(feature = "dynamic-frames"))]
14601469
// We don't know in which frame we are now, so we skip a few (10) frames at the start
14611470
// which might have been used by the current call stack. We check that the memory for
14621471
// the 10..MAX_CALL_DEPTH frames is zeroed. Then we write a sentinel value, and in the
14631472
// next nested invocation check that it's been zeroed.
1464-
let stack =
1465-
unsafe { slice::from_raw_parts_mut(MM_STACK_START as *mut u8, 0x100000000) };
1473+
//
1474+
// When we don't have dynamic stack frames, the stack grows from lower addresses
1475+
// to higher addresses, so we compare accordingly.
14661476
for i in 10..MAX_CALL_DEPTH {
14671477
let stack = &mut stack[i * STACK_FRAME_SIZE..][..STACK_FRAME_SIZE];
14681478
assert!(stack == &ZEROS[..STACK_FRAME_SIZE], "stack not zeroed");
14691479
stack.fill(42);
14701480
}
14711481

1482+
#[cfg(feature = "dynamic-frames")]
1483+
// When we have dynamic frames, the stack grows from the higher addresses, so we
1484+
// compare from zero until the beginning of a function frame.
1485+
{
1486+
const ZEROED_BYTES_LENGTH: usize = (MAX_CALL_DEPTH - 2) * STACK_FRAME_SIZE;
1487+
assert_eq!(sol_memcmp(stack, &ZEROS, ZEROED_BYTES_LENGTH), 0);
1488+
stack[..ZEROED_BYTES_LENGTH].fill(42);
1489+
}
1490+
14721491
// Recurse to check that the stack and heap are zeroed.
14731492
//
14741493
// We recurse until we go over max CPI depth and error out. Stack and heap allocations

0 commit comments

Comments
 (0)