import { toBigIntBE , toBufferBE } from 'bigint-buffer' ; import BN from 'bn.js' ; import { OpCode } from '.' ; import { EvmContext } from '../vm/evm-context' ; const TWO_POW256 = new BN ( '10000000000000000000000000000000000000000000000000000000000000000' , 16 ) ; class ExpOp implements OpCode { public readonly code = 0x0a ; public readonly mnemonic = 'EXP' ; public readonly description = 'Exponential operation' ; public readonly gas = 10 ; public readonly bytes = 1 ; public toString ( params ) { return `${ this . mnemonic }` ; } public handle ( context ) { const [ base , exponent ] = context . stack . popN ( 2 ) ; const m = BN . red ( TWO_POW256 ) ; const bnBase = new BN ( toBufferBE ( base , 32 ) ) . toRed ( m ) ; const bnExponent = new BN ( toBufferBE ( exponent , 32 ) ) ; const r = bnBase . redPow ( bnExponent ) ; context . stack . push ( toBigIntBE ( r . toArrayLike ( Buffer , 'be' , 32 ) ) ) ; context . ip += this . bytes ; } } export const Exp = new ExpOp ( ) ;