#![no_std]
#![no_main]
extern crate loop_panic_handler;
#[cfg(target_arch = "bpf")]
#[inline(always)]
pub fn sol_memcmp_(a: *const u8, b: *const u8, n: usize) -> i32 {
let mut result = 0i32;
let sol_memcmp_: unsafe extern "C" fn(
a: *const u8,
b: *const u8,
n: usize,
result: *mut i32,
) -> i32 = unsafe { core::mem::transmute(0x5FDCDE31usize) };
unsafe {
sol_memcmp_(a, b, n, &mut result as *mut i32);
}
result
}
#[cfg(target_arch = "bpf")]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn memcmp(a: *const u8, b: *const u8, n: usize) -> i32 {
if n > 64 {
return sol_memcmp_(a, b, n);
}
let mut i = 0usize;
while i + 8 <= n {
let wa = unsafe { core::ptr::read_unaligned(a.add(i) as *const u64) };
let wb = unsafe { core::ptr::read_unaligned(b.add(i) as *const u64) };
if wa != wb {
return 1;
}
i += 8;
}
while i < n {
if unsafe { *a.add(i) } != unsafe { *b.add(i) } {
return 1;
}
i += 1;
}
0
}
#[cfg(inline_small)]
static SMALL_LEN: usize = 32;
#[cfg(helper_large)]
static LARGE_LEN: usize = 128;
#[cfg(inline_small)]
static SMALL_EXPECTED: [u8; 32] = [3u8; 32];
#[cfg(helper_large)]
static LARGE_EXPECTED: [u8; 128] = [3u8; 128];
#[unsafe(no_mangle)]
pub fn entrypoint(input: *mut u8) -> u64 {
#[cfg(inline_small)]
{
let pubkey =
unsafe { core::slice::from_raw_parts(input.add(16), SMALL_LEN) };
let expected = unsafe {
core::slice::from_raw_parts(SMALL_EXPECTED.as_ptr(), SMALL_LEN)
};
if pubkey.ne(expected) {
return 1;
}
return 0;
}
#[cfg(helper_large)]
{
let pubkey =
unsafe { core::slice::from_raw_parts(input.add(16), LARGE_LEN) };
let expected = unsafe {
core::slice::from_raw_parts(LARGE_EXPECTED.as_ptr(), LARGE_LEN)
};
if pubkey.ne(expected) {
return 1;
}
return 0;
}
0
}