ziskos 1.1.0-alpha

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

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

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

#[derive(Debug)]
#[repr(C)]
pub struct SyscallArith384ModParams<'a> {
    pub a: &'a [u64; 6],
    pub b: &'a [u64; 6],
    pub c: &'a [u64; 6],
    pub module: &'a [u64; 6],
    pub d: &'a mut [u64; 6],
}

/// Executes the `Arith384Mod` operation, performing a modular 384-bit multiplication and addition:
/// `d = (a * b + c) mod module`.
///
/// `Arith384Mod` operates on arrays of six `u64` elements. The first parameter is a pointer to a structure
/// containing five values `a`, `b`, `c`, `module`, and the result `d`.
///
/// ### Safety
///
/// The caller must ensure that the data is aligned to a 64-bit boundary.
///
/// The caller must ensure that `module` is not zero.
///
/// The inputs `a`, `b`, and `c` are not required to be canonical modulo `module`.
///
/// The result `d` is always reduced modulo `module`
#[allow(unused_variables)]
#[cfg_attr(not(feature = "hints"), no_mangle)]
#[cfg_attr(feature = "hints", export_name = "hints_syscall_arith384_mod")]
pub extern "C" fn syscall_arith384_mod(
    params: &mut SyscallArith384ModParams,
    #[cfg(feature = "hints")] hints: &mut Vec<u64>,
) {
    #[cfg(zisk_guest)]
    ziskos_syscall!(zisk_definitions::SYSCALL_ARITH384_MOD_ID, params);
    #[cfg(not(zisk_guest))]
    {
        zisk_precomp_helpers::arith384_mod(params.a, params.b, params.c, params.module, params.d);
        #[cfg(feature = "hints")]
        {
            hints.extend_from_slice(params.d);
        }
    }
}