Commit c2113932 authored by yann300's avatar yann300

move sha3 function outside of solidity code

parent 668daa86
'use strict'
var ethutil = require('ethereumjs-util')
module.exports = {
/*
ints: IntArray
......@@ -115,7 +117,19 @@ module.exports = {
*/
findCall: findCall,
buildCallPath: buildCallPath
buildCallPath: buildCallPath,
/**
* sha3 the given @arg value
*
* @param {String} value - value to sha3
* @return {Object} - return sha3ied value
*/
sha3: function (value) {
var ret = ethutil.bufferToHex(ethutil.setLengthLeft(value, 32))
ret = ethutil.sha3(ret)
return ethutil.bufferToHex(ret)
}
}
/**
......
'use strict'
var util = require('./util')
var helper = require('../../helpers/util')
var BN = require('ethereumjs-util').BN
var RefType = require('./RefType')
......@@ -33,7 +34,7 @@ class ArrayType extends RefType {
}
if (this.arraySize === 'dynamic') {
size = util.toBN('0x' + slotValue)
currentLocation.slot = util.sha3(location.slot)
currentLocation.slot = helper.sha3(location.slot)
} else {
size = new BN(this.arraySize)
}
......
'use strict'
var util = require('./util')
var helper = require('../../helpers/util')
var BN = require('ethereumjs-util').BN
var RefType = require('./RefType')
......@@ -13,7 +14,7 @@ class DynamicByteArray extends RefType {
var bn = new BN(value, 16)
if (bn.testn(0)) {
var length = bn.div(new BN(2))
var dataPos = new BN(util.sha3(location.slot).replace('0x', ''), 16)
var dataPos = new BN(helper.sha3(location.slot).replace('0x', ''), 16)
var ret = ''
var currentSlot = await util.readFromStorage(dataPos, storageContent)
while (length.gt(ret.length) && ret.length < 32000) {
......
......@@ -7,7 +7,6 @@ module.exports = {
decodeIntFromHex: decodeIntFromHex,
extractHexValue: extractHexValue,
extractHexByteSlice: extractHexByteSlice,
sha3: sha3,
toBN: toBN,
add: add,
extractLocation: extractLocation,
......@@ -67,12 +66,6 @@ async function extractHexValue (location, storageContent, byteLength) {
return extractHexByteSlice(slotvalue, byteLength, location.offset)
}
function sha3 (slot) {
var remoteSlot = ethutil.bufferToHex(ethutil.setLengthLeft(slot, 32))
var key = ethutil.sha3(remoteSlot)
return ethutil.bufferToHex(key)
}
function toBN (value) {
if (value instanceof BN) {
return value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment