ziskos 1.1.0-alpha

Guest runtime and entrypoint for programs targeting the ZisK zkVM
//! Add256 system call interception

#[cfg(zisk_guest)]
use core::arch::asm;

#[cfg(zisk_guest)]
use crate::ziskos_syscall_ret_u64;

#[derive(Debug)]
#[repr(C)]
pub struct SyscallAdd256Params<'a> {
    pub a: &'a [u64; 4],
    pub b: &'a [u64; 4],
    pub cin: u64,
    pub c: &'a mut [u64; 4],
}

/// Executes the `Add256` operation, performing a 256-bit addition:
/// `a + b + cin = cout | c`.
///
/// `Add256` operates on arrays of four `u64` elements. The first parameter is a pointer to a structure
/// containing four values: `a`, `b`, `cin`, and the result `c`. The carry-out `cout` is returned as the syscall result (0 or 1).
///
/// ### Safety
///
/// The caller must ensure that the data is aligned to a 64-bit boundary.
#[allow(unused_variables)]
#[cfg_attr(not(feature = "hints"), no_mangle)]
#[cfg_attr(feature = "hints", export_name = "hints_syscall_add256")]
pub extern "C" fn syscall_add256(
    params: &mut SyscallAdd256Params,
    #[cfg(feature = "hints")] hints: &mut Vec<u64>,
) -> u64 {
    #[cfg(not(zisk_guest))]
    {
        let cout = zisk_precomp_helpers::add256(params.a, params.b, params.cin, params.c);
        #[cfg(feature = "hints")]
        {
            hints.extend_from_slice(params.c);
            hints.push(cout);
        }
        cout
    }
    #[cfg(zisk_guest)]
    ziskos_syscall_ret_u64!(zisk_definitions::SYSCALL_ADD256_ID, params)
}