use crate::{
ExecutionError, Felt, ONE,
errors::OperationError,
mast::MastForest,
processor::{Processor, StackInterface, SystemInterface},
tracer::OperationHelperRegisters,
};
#[cfg(test)]
mod tests;
#[inline(always)]
pub(super) fn op_assert<P>(
processor: &mut P,
err_code: Felt,
program: &MastForest,
) -> Result<OperationHelperRegisters, OperationError>
where
P: Processor,
{
if processor.stack().get(0) != ONE {
let err_msg = program.resolve_error_message(err_code);
return Err(OperationError::FailedAssertion { err_code, err_msg });
}
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)
}
#[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)
}