1- pragma solidity ^ 0.4.24 ;
1+ pragma solidity >= 0.5.0 < 0.6.0 ;
22
33import {Utils} from "./utils.sol " ;
44import {D} from "./data.sol " ;
@@ -27,7 +27,13 @@ library PartialMerkleTree {
2727 tree.root = root;
2828 }
2929
30- function commitBranch (Tree storage tree , bytes key , bytes value , uint branchMask , bytes32 [] siblings ) internal {
30+ function commitBranch (
31+ Tree storage tree ,
32+ bytes memory key ,
33+ bytes memory value ,
34+ uint branchMask ,
35+ bytes32 [] memory siblings
36+ ) internal {
3137 D.Label memory k = D.Label (keccak256 (key), 256 );
3238 D.Edge memory e;
3339 e.node = keccak256 (value);
@@ -66,11 +72,11 @@ library PartialMerkleTree {
6672
6773 function commitBranchOfNonInclusion (
6874 Tree storage tree ,
69- bytes key ,
75+ bytes memory key ,
7076 bytes32 potentialSiblingLabel ,
7177 bytes32 potentialSiblingValue ,
7278 uint branchMask ,
73- bytes32 [] siblings
79+ bytes32 [] memory siblings
7480 ) internal {
7581 D.Label memory k = D.Label (keccak256 (key), 256 );
7682 D.Edge memory e;
@@ -114,7 +120,11 @@ library PartialMerkleTree {
114120 tree.rootEdge = e;
115121 }
116122
117- function insert (Tree storage tree , bytes key , bytes value ) internal {
123+ function insert (
124+ Tree storage tree ,
125+ bytes memory key ,
126+ bytes memory value
127+ ) internal {
118128 D.Label memory k = D.Label (keccak256 (key), 256 );
119129 bytes32 valueHash = keccak256 (value);
120130 tree.values[valueHash] = value;
@@ -134,18 +144,18 @@ library PartialMerkleTree {
134144 tree.rootEdge = e;
135145 }
136146
137- function get (Tree storage tree , bytes key ) internal view returns (bytes ) {
147+ function get (Tree storage tree , bytes memory key ) internal view returns (bytes memory ) {
138148 return getValue (tree, _findNode (tree, key));
139149 }
140150
141- function safeGet (Tree storage tree , bytes key ) internal view returns (bytes value ) {
151+ function safeGet (Tree storage tree , bytes memory key ) internal view returns (bytes memory value ) {
142152 bytes32 valueHash = _findNode (tree, key);
143153 require (valueHash != bytes32 (0 ));
144154 value = getValue (tree, valueHash);
145155 require (valueHash == keccak256 (value));
146156 }
147157
148- function doesInclude (Tree storage tree , bytes key ) internal view returns (bool ) {
158+ function doesInclude (Tree storage tree , bytes memory key ) internal view returns (bool ) {
149159 return doesIncludeHashedKey (tree, keccak256 (key));
150160 }
151161
@@ -154,7 +164,7 @@ library PartialMerkleTree {
154164 return (valueHash != bytes32 (0 ));
155165 }
156166
157- function getValue (Tree storage tree , bytes32 valueHash ) internal view returns (bytes ) {
167+ function getValue (Tree storage tree , bytes32 valueHash ) internal view returns (bytes memory ) {
158168 return tree.values[valueHash];
159169 }
160170
@@ -181,11 +191,11 @@ library PartialMerkleTree {
181191 // - uint branchMask - bitmask with high bits at the positions in the key
182192 // where we have branch nodes (bit in key denotes direction)
183193 // - bytes32[] hashes - hashes of sibling edges
184- function getProof (Tree storage tree , bytes key ) internal view returns (uint branchMask , bytes32 [] _siblings ) {
194+ function getProof (Tree storage tree , bytes memory key ) internal view returns (uint branchMask , bytes32 [] memory _siblings ) {
185195 return getProofWithHashedKey (tree, keccak256 (key));
186196 }
187197
188- function getProofWithHashedKey (Tree storage tree , bytes32 hashedKey ) internal view returns (uint branchMask , bytes32 [] _siblings ) {
198+ function getProofWithHashedKey (Tree storage tree , bytes32 hashedKey ) internal view returns (uint branchMask , bytes32 [] memory _siblings ) {
189199 D.Label memory k = D.Label (hashedKey, 256 );
190200 D.Edge memory e = tree.rootEdge;
191201 bytes32 [256 ] memory siblings;
@@ -218,11 +228,11 @@ library PartialMerkleTree {
218228 }
219229 }
220230
221- function getNonInclusionProof (Tree storage tree , bytes key ) internal view returns (
231+ function getNonInclusionProof (Tree storage tree , bytes memory key ) internal view returns (
222232 bytes32 potentialSiblingLabel ,
223233 bytes32 potentialSiblingValue ,
224234 uint branchMask ,
225- bytes32 [] _siblings
235+ bytes32 [] memory _siblings
226236 ) {
227237 return getNonInclusionProofWithHashedKey (tree, keccak256 (key));
228238 }
@@ -231,7 +241,7 @@ library PartialMerkleTree {
231241 bytes32 potentialSiblingLabel ,
232242 bytes32 potentialSiblingValue ,
233243 uint branchMask ,
234- bytes32 [] _siblings
244+ bytes32 [] memory _siblings
235245 ){
236246 uint length;
237247 uint numSiblings;
@@ -275,7 +285,13 @@ library PartialMerkleTree {
275285 }
276286 }
277287
278- function verifyProof (bytes32 rootHash , bytes key , bytes value , uint branchMask , bytes32 [] siblings ) public pure {
288+ function verifyProof (
289+ bytes32 rootHash ,
290+ bytes memory key ,
291+ bytes memory value ,
292+ uint branchMask ,
293+ bytes32 [] memory siblings
294+ ) public pure {
279295 D.Label memory k = D.Label (keccak256 (key), 256 );
280296 D.Edge memory e;
281297 e.node = keccak256 (value);
@@ -294,7 +310,14 @@ library PartialMerkleTree {
294310 require (rootHash == edgeHash (e));
295311 }
296312
297- function verifyNonInclusionProof (bytes32 rootHash , bytes key , bytes32 potentialSiblingLabel , bytes32 potentialSiblingValue , uint branchMask , bytes32 [] siblings ) public pure {
313+ function verifyNonInclusionProof (
314+ bytes32 rootHash ,
315+ bytes memory key ,
316+ bytes32 potentialSiblingLabel ,
317+ bytes32 potentialSiblingValue ,
318+ uint branchMask ,
319+ bytes32 [] memory siblings
320+ ) public pure {
298321 D.Label memory k = D.Label (keccak256 (key), 256 );
299322 D.Edge memory e;
300323 for (uint i = 0 ; branchMask != 0 ; i++ ) {
@@ -317,12 +340,12 @@ library PartialMerkleTree {
317340 require (rootHash == edgeHash (e));
318341 }
319342
320- function newEdge (bytes32 node , D.Label label ) internal pure returns (D.Edge memory e ){
343+ function newEdge (bytes32 node , D.Label memory label ) internal pure returns (D.Edge memory e ){
321344 e.node = node;
322345 e.label = label;
323346 }
324347
325- function _insertAtNode (Tree storage tree , bytes32 nodeHash , D.Label key , bytes32 value ) private returns (bytes32 ) {
348+ function _insertAtNode (Tree storage tree , bytes32 nodeHash , D.Label memory key , bytes32 value ) private returns (bytes32 ) {
326349 // require(key.length > 1);
327350 D.Node memory n = tree.nodes[nodeHash];
328351 uint head;
@@ -332,7 +355,7 @@ library PartialMerkleTree {
332355 return _replaceNode (tree, nodeHash, n);
333356 }
334357
335- function _insertAtEdge (Tree storage tree , D.Edge e , D.Label key , bytes32 value ) private returns (D.Edge) {
358+ function _insertAtEdge (Tree storage tree , D.Edge memory e , D.Label memory key , bytes32 value ) private returns (D.Edge memory ) {
336359 // require(e.hasNode());
337360 require (key.length >= e.label.length );
338361 D.Label memory prefix;
@@ -370,7 +393,7 @@ library PartialMerkleTree {
370393 return _insertNode (tree, n);
371394 }
372395
373- function _findNode (Tree storage tree , bytes key ) private view returns (bytes32 ) {
396+ function _findNode (Tree storage tree , bytes memory key ) private view returns (bytes32 ) {
374397 return _findNodeWithHashedKey (tree, keccak256 (key));
375398 }
376399
@@ -383,7 +406,7 @@ library PartialMerkleTree {
383406 }
384407 }
385408
386- function _findAtNode (Tree storage tree , bytes32 nodeHash , D.Label key ) private view returns (bytes32 ) {
409+ function _findAtNode (Tree storage tree , bytes32 nodeHash , D.Label memory key ) private view returns (bytes32 ) {
387410 require (key.length > 1 );
388411 D.Node memory n = tree.nodes[nodeHash];
389412 uint head;
@@ -392,7 +415,7 @@ library PartialMerkleTree {
392415 return _findAtEdge (tree, n.children[head], tail);
393416 }
394417
395- function _findAtEdge (Tree storage tree , D.Edge e , D.Label key ) private view returns (bytes32 ){
418+ function _findAtEdge (Tree storage tree , D.Edge memory e , D.Label memory key ) private view returns (bytes32 ){
396419 require (key.length >= e.label.length );
397420 D.Label memory prefix;
398421 D.Label memory suffix;
0 commit comments