diff --git a/contracts/lib/MerklePatriciaProof.sol b/contracts/lib/MerklePatriciaProof.sol index febd8c05..bcf4a385 100644 --- a/contracts/lib/MerklePatriciaProof.sol +++ b/contracts/lib/MerklePatriciaProof.sol @@ -69,17 +69,16 @@ library MerklePatriciaProof { ); pathPtr += 1; } else if (currentNodeList.length == 2) { - // Alternative 1 start bytes memory nodeValue = RLPReader.toBytes(currentNodeList[0]); uint256 traversed = _nibblesToTraverse( nodeValue, path, pathPtr ); + //enforce correct nibble + bytes1 prefix = _getNthNibbleOfBytes(0, nodeValue); if (pathPtr + traversed == path.length) { //leaf node - //enforce correct nibble - bytes1 prefix = _getNthNibbleOfBytes(0, nodeValue); if ( keccak256(RLPReader.toBytes(currentNodeList[1])) == keccak256(value) && (prefix == bytes1(uint8(2)) || prefix == bytes1(uint8(3))) @@ -91,36 +90,12 @@ library MerklePatriciaProof { } //extension node - if (traversed == 0) { + if (traversed == 0 || (prefix != bytes1(uint8(0)) && prefix != bytes1(uint8(1)))) { return false; } pathPtr += traversed; nodeKey = bytes32(RLPReader.toUintStrict(currentNodeList[1])); - // Alternative 1 end - - // // Alternative 2 start - // bytes memory nodeValue = RLPReader.toBytes(currentNodeList[0]); - // bytes1 prefix = _getNthNibbleOfBytes(0, nodeValue); - // // Extension node - // if (prefix == bytes1(uint8(0)) || prefix == bytes1(uint8(1))) { - // uint256 traversed = _nibblesToTraverse( - // nodeValue, - // path, - // pathPtr - // ); - // if (traversed == 0) { - // return false; - // } - // pathPtr += traversed; - // nodeKey = bytes32(RLPReader.toUintStrict(currentNodeList[1])); - // // Leaf node - // } else if (prefix == bytes1(uint8(2)) || prefix == bytes1(uint8(3))){ - // return keccak256(RLPReader.toBytes(currentNodeList[1])) == keccak256(value); - // } else { - // return false; - // } - // // Alternative 2 end } else { return false; }