From 4bbdf55251ee75dabc24d2038e1a08b4c4058abd Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 23 Jul 2018 20:36:39 +0100 Subject: [PATCH] Implement SAR --- lib/opFns.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/opFns.js b/lib/opFns.js index f5fc1a83267..9e5b9b8bf87 100644 --- a/lib/opFns.js +++ b/lib/opFns.js @@ -179,15 +179,19 @@ module.exports = { if (!runState._common.gteHardfork('constantinople')) { trap(ERROR.INVALID_OPCODE) } - b = b.fromTwos(256) if (a.gten(256)) { - if (b.ltn(0)) { + if (b.fromTwos(256).ltn(0)) { return new BN(-1).toTwos(256) } else { return new BN(0) } } - // FIXME: implement + var c = b.shrn(a.toNumber()) + if (b.testn(255)) { + return c.iand(utils.MAX_INTEGER) + } else { + return c + } }, // 0x20 range - crypto SHA3: function (offset, length, runState) {