1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Arith256Mod system call interception
#[cfg(zisk_guest)]
use core::arch::asm;
#[cfg(zisk_guest)]
use crate::ziskos_syscall;
#[derive(Debug)]
#[repr(C)]
pub struct SyscallArith256ModParams<'a> {
pub a: &'a [u64; 4],
pub b: &'a [u64; 4],
pub c: &'a [u64; 4],
pub module: &'a [u64; 4],
pub d: &'a mut [u64; 4],
}
/// Executes the `Arith256Mod` operation, performing a modular 256-bit multiplication and addition:
/// `d = (a * b + c) mod module`.
///
///
/// `Arith256Mod` operates on arrays of four `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_arith256_mod")]
pub extern "C" fn syscall_arith256_mod(
params: &mut SyscallArith256ModParams,
#[cfg(feature = "hints")] hints: &mut Vec<u64>,
) {
#[cfg(zisk_guest)]
ziskos_syscall!(zisk_definitions::SYSCALL_ARITH256_MOD_ID, params);
#[cfg(not(zisk_guest))]
{
zisk_precomp_helpers::arith256_mod(params.a, params.b, params.c, params.module, params.d);
#[cfg(feature = "hints")]
if zisk_definitions::ARITH256MOD_RESULTS {
hints.extend_from_slice(params.d);
}
}
}