> For the complete documentation index, see [llms.txt](https://thias-organization.gitbook.io/p256-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thias-organization.gitbook.io/p256-documentation/risc-zero-k256-accelerator/scalar.md).

# Scalar

The difference between scalar arithmetic and field arithmetic is mainly the modulus that we are working with. In `scalar.rs` the modulus is the order $$n$$ of the elliptic curve, while that of `field.rs` is the prime field $$p$$.

Again, some operations in `scalar.rs` are optimised using conditional compilation and `modmul_u256_denormalized`.&#x20;

```rust
/// Modulo multiplies two scalars.
pub fn mul(&self, rhs: &Scalar) -> Scalar {
    cfg_if::cfg_if! {
        if #[cfg(all(target_os = "zkvm", target_arch = "riscv32"))] {
            let result = Self(risc0::modmul_u256_denormalized(&self.0, &rhs.0, &ORDER));
            assert!(bool::from(result.0.ct_lt(&ORDER)));
            result
        } else {
            WideScalar::mul_wide(self, rhs).reduce()
        }
    }
}

fn mul_denormalized(&self, rhs: &Scalar) -> Scalar {
    cfg_if::cfg_if! {
        if #[cfg(all(target_os = "zkvm", target_arch = "riscv32"))] {
            Self(risc0::modmul_u256_denormalized(&self.0, &rhs.0, &ORDER))
        } else {
            WideScalar::mul_wide(self, rhs).reduce()
        }
    }
}
```
