import { OpCode } from '.' ; import { EvmContext } from '../vm/evm-context' ; class SgtOp implements OpCode { public readonly code = 0x13 ; public readonly mnemonic = 'SGT' ; public readonly description = 'Signed greater-than comparison' ; public readonly gas = 3 ; public readonly bytes = 1 ; public toString ( params ) { return `${ this . mnemonic }` ; } public sgt ( x , y ) { const tt255 = BigInt ( 2 ) ** BigInt ( 255 ) ; const xSign = x - tt255 ; const ySign = y - tt255 ; if ( xSign >= 0 && ySign < 0 ) { return BigInt ( 0 ) ; } else if ( xSign < 0 && ySign >= 0 ) { return BigInt ( 1 ) ; } else { return x > y ? BigInt ( 1 ) : BigInt ( 0 ) ; } } public handle ( context ) { const x = context . stack . pop ( ) ! ; const y = context . stack . pop ( ) ! ; context . stack . push ( this . sgt ( x , y ) ) ; context . ip += this . bytes ; } } export const Sgt = new SgtOp ( ) ;