use crate::{
ExecutionError, Felt, ONE,
errors::OperationError,
processor::{Processor, StackInterface, SystemInterface},
tracer::OperationHelperRegisters,
};
#[cfg(test)]
mod tests;
#[inline(always)]
pub(super) fn op_assert<P>(
processor: &mut P,
err_code: Felt,
) -> Result<OperationHelperRegisters, OperationError>
where
P: Processor,
{
if processor.stack().get(0) != ONE {
return Err(OperationError::FailedAssertion { err_code, err_msg: None });
}
processor.stack_mut().decrement_size()?;
Ok(OperationHelperRegisters::Empty)
}
#[inline(always)]
pub(super) fn op_sdepth<P>(processor: &mut P) -> Result<OperationHelperRegisters, ExecutionError>
where
P: Processor,
{
let depth = processor.stack().depth();
processor.stack_mut().increment_size()?;
processor.stack_mut().set(0, Felt::from_u32(depth));
Ok(OperationHelperRegisters::Empty)
}
#[expect(
clippy::unnecessary_wraps,
reason = "uniform return type with sibling op_* handlers dispatched in execute_op"
)]
#[inline(always)]
pub(super) fn op_caller<P: Processor>(
processor: &mut P,
) -> Result<OperationHelperRegisters, ExecutionError> {
let caller_hash = processor.system().caller_hash();
processor.stack_mut().set_word(0, &caller_hash);
Ok(OperationHelperRegisters::Empty)
}
#[inline(always)]
pub(super) fn op_clk<P>(processor: &mut P) -> Result<OperationHelperRegisters, ExecutionError>
where
P: Processor,
{
let clk: Felt = processor.system().clock().into();
processor.stack_mut().increment_size()?;
processor.stack_mut().set(0, clk);
Ok(OperationHelperRegisters::Empty)
}