From 075fa4ee5987d0754df4cd48bf5402681b441aab Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 23 May 2017 15:00:51 +0200 Subject: [PATCH] fix sha3 input extract --- src/web3Provider/web3VmProvider.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/web3Provider/web3VmProvider.js b/src/web3Provider/web3VmProvider.js index e1f23d4a86..079db3b622 100644 --- a/src/web3Provider/web3VmProvider.js +++ b/src/web3Provider/web3VmProvider.js @@ -213,11 +213,16 @@ function getSha3Input (stack, memory) { var memLengthDec = (new ethutil.BN(memoryLength.replace('0x', ''), 16).toString(10)) memoryLength = parseInt(memLengthDec) * 2 - var subMemoryIndex = Math.floor(memoryStart / 32) - var sha3Input = '' - while (sha3Input.length < memoryLength) { - sha3Input += memory[subMemoryIndex] - subMemoryIndex++ + var min = Math.floor(memoryStart / 32) + var fillLength = Math.floor(memoryLength / 32) + var sha3Input = memory[min].slice(memoryStart - 32 * min) + min++ + while (min < fillLength) { + sha3Input += memory[min] + min++ + } + if (sha3Input.length < memoryLength) { + sha3Input += memory[min].slice(0, memoryLength - sha3Input.length) } return sha3Input }