evm
Version:
An ethereum virtual machine (EVM) bytecode decompiler
59 lines (54 loc) • 1.92 kB
text/typescript
import EVM from '../classes/evm.class';
import Opcode from '../interfaces/opcode.interface';
import * as BigNumber from '../../node_modules/big-integer';
import stringify from '../utils/stringify';
export class AND {
readonly name: string;
readonly type?: string;
readonly wrapped: boolean;
readonly left: any;
readonly right: any;
constructor(left: any, right: any) {
this.name = 'AND';
this.wrapped = true;
this.left = left;
this.right = right;
}
toString() {
return stringify(this.left) + ' && ' + stringify(this.right);
}
}
export default (opcode: Opcode, state: EVM): void => {
const left = state.stack.pop();
const right = state.stack.pop();
if (BigNumber.isInstance(left) && BigNumber.isInstance(right)) {
state.stack.push(left.and(right));
} else if (BigNumber.isInstance(left) && /^[f]+$/.test(left.toString(16))) {
right.size = left.toString(16).length;
state.stack.push(right);
} else if (BigNumber.isInstance(right) && /^[f]+$/.test(right.toString(16))) {
left.size = right.toString(16).length;
state.stack.push(left);
/*} else if (
BigNumber.isInstance(left) &&
left.equals('1461501637330902918203684832716283019655932542975')
) {*/
/* 2 ** 160 */
/* state.stack.push(right);
} else if (
BigNumber.isInstance(right) &&
right.equals('1461501637330902918203684832716283019655932542975')
) {*/
/* 2 ** 160 */
/* state.stack.push(left);*/
} else if (
BigNumber.isInstance(left) &&
right instanceof AND &&
BigNumber.isInstance(right.left) &&
left.equals(right.left)
) {
state.stack.push(right.right);
} else {
state.stack.push(new AND(left, right));
}
};