Skip to content

Commit 7affc04

Browse files
feliperodriJonathanWoollett-Light
authored andcommitted
Adds stub for read_be_u16 to Kani harnesses
The current implementation of read_be_u16 function leads to a significant performance degradation given a necessary loop unrolling. Using this stub, we read the same information from the buffer while avoiding the loop, thus, notably improving performance. Signed-off-by: Felipe R. Monteiro <felisous@amazon.com>
1 parent 87e857a commit 7affc04

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/dumbo/src/pdu/ethernet.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ mod tests {
238238
}
239239

240240
#[cfg(kani)]
241+
#[allow(dead_code)] // Avoid warning when using stubs.
241242
mod kani_proofs {
242243
use utils::net::mac::MAC_ADDR_LEN;
243244

@@ -253,6 +254,16 @@ mod kani_proofs {
253254
}
254255
}
255256

257+
mod stubs {
258+
// The current implementation of read_be_u16 function leads to a significant
259+
// performance degradation given a necessary loop unrolling. Using this stub,
260+
// we read the same information from the buffer while avoiding the loop, thus,
261+
// notably improving performance.
262+
pub fn read_be_u16(input: &[u8]) -> u16 {
263+
u16::from_be_bytes([input[0], input[1]])
264+
}
265+
}
266+
256267
// We consider the MMDS Network Stack spec for all postconditions in the harnesses.
257268
// See https://github.com/firecracker-microvm/firecracker/blob/main/docs/mmds/mmds-design.md#mmds-network-stack
258269

@@ -502,8 +513,8 @@ mod kani_proofs {
502513
}
503514

504515
#[kani::proof]
505-
#[kani::unwind(1515)]
506516
#[kani::solver(cadical)]
517+
#[kani::stub(utils::byte_order::read_be_u16, stubs::read_be_u16)]
507518
fn verify_with_payload_len_unchecked() {
508519
// Create non-deterministic stream of bytes up to MAX_FRAME_SIZE
509520
let mut bytes: [u8; MAX_FRAME_SIZE] = kani::Arbitrary::any_array::<MAX_FRAME_SIZE>();

0 commit comments

Comments
 (0)