Commit c2113932 authored by yann300's avatar yann300

move sha3 function outside of solidity code

parent 668daa86
'use strict' 'use strict'
var ethutil = require('ethereumjs-util')
module.exports = { module.exports = {
/* /*
ints: IntArray ints: IntArray
...@@ -115,7 +117,19 @@ module.exports = { ...@@ -115,7 +117,19 @@ module.exports = {
*/ */
findCall: findCall, 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' 'use strict'
var util = require('./util') var util = require('./util')
var helper = require('../../helpers/util')
var BN = require('ethereumjs-util').BN var BN = require('ethereumjs-util').BN
var RefType = require('./RefType') var RefType = require('./RefType')
...@@ -33,7 +34,7 @@ class ArrayType extends RefType { ...@@ -33,7 +34,7 @@ class ArrayType extends RefType {
} }
if (this.arraySize === 'dynamic') { if (this.arraySize === 'dynamic') {
size = util.toBN('0x' + slotValue) size = util.toBN('0x' + slotValue)
currentLocation.slot = util.sha3(location.slot) currentLocation.slot = helper.sha3(location.slot)
} else { } else {
size = new BN(this.arraySize) size = new BN(this.arraySize)
} }
......
'use strict' 'use strict'
var util = require('./util') var util = require('./util')
var helper = require('../../helpers/util')
var BN = require('ethereumjs-util').BN var BN = require('ethereumjs-util').BN
var RefType = require('./RefType') var RefType = require('./RefType')
...@@ -13,7 +14,7 @@ class DynamicByteArray extends RefType { ...@@ -13,7 +14,7 @@ class DynamicByteArray extends RefType {
var bn = new BN(value, 16) var bn = new BN(value, 16)
if (bn.testn(0)) { if (bn.testn(0)) {
var length = bn.div(new BN(2)) 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 ret = ''
var currentSlot = await util.readFromStorage(dataPos, storageContent) var currentSlot = await util.readFromStorage(dataPos, storageContent)
while (length.gt(ret.length) && ret.length < 32000) { while (length.gt(ret.length) && ret.length < 32000) {
......
...@@ -7,7 +7,6 @@ module.exports = { ...@@ -7,7 +7,6 @@ module.exports = {
decodeIntFromHex: decodeIntFromHex, decodeIntFromHex: decodeIntFromHex,
extractHexValue: extractHexValue, extractHexValue: extractHexValue,
extractHexByteSlice: extractHexByteSlice, extractHexByteSlice: extractHexByteSlice,
sha3: sha3,
toBN: toBN, toBN: toBN,
add: add, add: add,
extractLocation: extractLocation, extractLocation: extractLocation,
...@@ -67,12 +66,6 @@ async function extractHexValue (location, storageContent, byteLength) { ...@@ -67,12 +66,6 @@ async function extractHexValue (location, storageContent, byteLength) {
return extractHexByteSlice(slotvalue, byteLength, location.offset) 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) { function toBN (value) {
if (value instanceof BN) { if (value instanceof BN) {
return value 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