# evm_modexp

Computes base^exp mod modulus over three fixed-width UINT256 values. Returns 0 when modulus is 0 or 1; for other moduli, exponent 0 returns 1. This is not the EVM MODEXP precompile byte interface: it does not accept length-prefixed byte sequences, produce variable-width output, or model gas. NULL input propagates to NULL.

Canonical HTML: <https://determica.com/docs/functions/evm_modexp>

- Kind: scalar function
- Category: [EVM utilities](/docs/category/evm-utilities.md)
- Tags: Types, EVM

Computes base^exp mod modulus over three fixed-width UINT256 values. Returns 0 when modulus is 0 or 1; for other moduli, exponent 0 returns 1. This is not the EVM MODEXP precompile byte interface: it does not accept length-prefixed byte sequences, produce variable-width output, or model gas. NULL input propagates to NULL.

## Overload 1: evm_modexp(UINT256, UINT256, UINT256)

```sql
evm_modexp(UINT256, UINT256, UINT256)
```

Fixed-width UINT256 modular exponentiation, returning a UINT256 residue.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `base` (UINT256; required; positional) — UINT256 base.
- `exp` (UINT256; required; positional) — UINT256 non-negative exponent.
- `mod` (UINT256; required; positional) — UINT256 modulus; 0 and 1 return zero.

### Returns

Modular residue

UINT256 base^exp mod modulus, or NULL when any input is NULL.

- `result` (UINT256)

Modular residue. UINT256 base^exp mod modulus, or NULL when any input is NULL.

### Examples

_Local SQL · Local_

```sql
SELECT evm_modexp(5::UINT256, 3::UINT256, 13::UINT256)::VARCHAR AS result;
-- => [{"result":"8"}]
```
