@tevm/voltaire / crypto/ModExp
crypto/ModExp
Variables
ModExp
Defined in: src/crypto/ModExp/ModExp.js:35 ModExp - Modular Exponentiation Computes base^exp mod modulus for arbitrary-precision integers. Used by MODEXP precompile (0x05) per EIP-198/EIP-2565.constModExp: (base,exp,modulus) =>bigint&object
Type Declaration
calculateGas()
calculateGas: (Calculate gas cost for MODEXP operation per EIP-2565 Gas formula: max(200, floor(mult_complexity * iteration_count / 3))baseLen,expLen,modLen,expHead) =>bigint
Parameters
baseLen
bigint
Length of base in bytes
expLen
bigint
Length of exponent in bytes
modLen
bigint
Length of modulus in bytes
expHead
bigint
First 32 bytes of exponent as BigInt (for leading zeros calc)
Returns
bigint
Gas cost
See
https://eips.ethereum.org/EIPS/eip-2565Since
0.0.0Example
modexp()
modexp: (Modular exponentiation: base^exp mod modulus Computes arbitrary-precision modular exponentiation using native BigInt. Used by MODEXP precompile (0x05) per EIP-198. WARNING: This implementation is for general use. For cryptographic applications, consider timing attack resistance.base,exp,modulus) =>bigint
Parameters
base
bigint
Base value
exp
bigint
Exponent value
modulus
bigint
Modulus value (must be > 0)
Returns
bigint
Result of base^exp mod modulus
See
https://eips.ethereum.org/EIPS/eip-198Since
0.0.0Throws
If modulus is zeroExample
modexpBytes()
modexpBytes: (Modular exponentiation with byte array inputs/outputs Computes base^exp mod modulus where inputs are big-endian byte arrays. Output is padded to modulus length per EIP-198 spec.baseBytes,expBytes,modBytes) =>Uint8Array<ArrayBufferLike>
Parameters
baseBytes
Uint8Array<ArrayBufferLike>
Base as big-endian bytes
expBytes
Uint8Array<ArrayBufferLike>
Exponent as big-endian bytes
modBytes
Uint8Array<ArrayBufferLike>
Modulus as big-endian bytes
Returns
Uint8Array<ArrayBufferLike>
Result as big-endian bytes, padded to modulus length
See
https://eips.ethereum.org/EIPS/eip-198Since
0.0.0Throws
If modulus is zeroExample
See
- https://eips.ethereum.org/EIPS/eip-198 - ModExp precompile
- https://eips.ethereum.org/EIPS/eip-2565 - Gas cost repricing
Since
0.0.0Example
Functions
calculateGas()
calculateGas(Defined in: src/crypto/ModExp/calculateGas.js:22 Calculate gas cost for MODEXP operation per EIP-2565 Gas formula: max(200, floor(mult_complexity * iteration_count / 3))baseLen,expLen,modLen,expHead):bigint
Parameters
baseLen
bigint
Length of base in bytes
expLen
bigint
Length of exponent in bytes
modLen
bigint
Length of modulus in bytes
expHead
bigint
First 32 bytes of exponent as BigInt (for leading zeros calc)
Returns
bigint
Gas cost
See
https://eips.ethereum.org/EIPS/eip-2565Since
0.0.0Example
modexp()
modexp(Defined in: src/crypto/ModExp/compute.js:29 Modular exponentiation: base^exp mod modulus Computes arbitrary-precision modular exponentiation using native BigInt. Used by MODEXP precompile (0x05) per EIP-198. WARNING: This implementation is for general use. For cryptographic applications, consider timing attack resistance.base,exp,modulus):bigint
Parameters
base
bigint
Base value
exp
bigint
Exponent value
modulus
bigint
Modulus value (must be > 0)
Returns
bigint
Result of base^exp mod modulus
See
https://eips.ethereum.org/EIPS/eip-198Since
0.0.0Throws
If modulus is zeroExample
modexpBytes()
modexpBytes(Defined in: src/crypto/ModExp/modexpBytes.js:28 Modular exponentiation with byte array inputs/outputs Computes base^exp mod modulus where inputs are big-endian byte arrays. Output is padded to modulus length per EIP-198 spec.baseBytes,expBytes,modBytes):Uint8Array<ArrayBufferLike>
Parameters
baseBytes
Uint8Array<ArrayBufferLike>
Base as big-endian bytes
expBytes
Uint8Array<ArrayBufferLike>
Exponent as big-endian bytes
modBytes
Uint8Array<ArrayBufferLike>
Modulus as big-endian bytes
Returns
Uint8Array<ArrayBufferLike>
Result as big-endian bytes, padded to modulus length

